KASKADE 7 development version
discrete_bridge.hh
Go to the documentation of this file.
1#ifndef DISCRETE_BRIDGE_HH
2#define DISCRETE_BRIDGE_HH
3
4#include <memory>
5#include "newton_bridge.hh"
6#include "dune/common/fmatrix.hh"
7#include "dune/istl/bvector.hh"
8
9
10namespace Bridge
11{
12
13//--------------------------------------------------------------------------------
15
22template<class Functional>
24{
25public:
26 typedef typename Functional::RT RT;
29 typedef Functional Implementation;
30 class Empty{ public: typedef ImageElement range_type; typedef DomainElement domain_type; }; typedef Empty OperatorType;
31
32// typedef Functional Linearization;
33
34 FixedSystemLinearization(Functional& fu_, AbstractFunctionSpaceElement const& x_)
35 : x(x_.clone()), fu(fu_), mat(rows(0,nColBlocks()),cols(0,nColBlocks())), mflushed(true)
36 {
37 fu.setOrigin(getImpl<DomainElement>(*x));
38 rhs.resize(0);
39 }
40
42
43 int cols(int cbegin, int cend) const { if(cbegin<cend) return std::min(cend,nColBlocks())-std::max(cbegin,0); return 0;}
44 int rows(int rbegin, int rend) const { if(rbegin<rend) return std::min(rend,nRowBlocks())-std::max(rbegin,0); return 0;}
45
46 void precompute()
47 {
48 createLinearizedSystem();
49 }
50
51 virtual void getMatrixBlocks(MatrixAsTriplet<RT>& mat_, int rbegin, int rend, int cbegin, int cend) const
52 {
53 createLinearizedSystem();
54 for(int i=rbegin; i<rend; i++)
55 for(int j=cbegin; j<cend; j++)
56 mat_.addEntry(i-rbegin,j-cbegin,mat[i][j]);
57 }
58 virtual void getRHSBlocks(std::vector<RT>& rhs_, int rbegin, int rend) const
59 {
60 createRHS();
61 rhs_.resize(rend-rbegin);
62 for(int i=0; i<rend-rbegin;++i)
63 rhs_[i] = rhs[i+rbegin];
64 }
65
66 virtual int nColBlocks() const { return fu.size();}
67
68 virtual int nRowBlocks() const { return fu.size();}
69
70 double getValue() const { return fu.d0();}
71
72 AbstractFunctionSpaceElement const& getOrigin() const {return *x;}
73
74 void flush() { mflushed=true; rhs.resize(0); mat*=0.0;}
75
77Implementation const& getLinImpl() const {return fu; }
78
79private:
80 void createLinearizedSystem() const
81 {
82 createRHS();
83 if(!mflushed)
84 {
85 return;
86 }
87 fu.d2(mat);
88 mflushed=false;
89 }
90
91 void createRHS() const
92 {
93 rhs.resize(cols(0,nColBlocks()));
94 fu.d1(rhs);
95 }
96
97 mutable std::vector<RT> rhs;
98 std::std::unique_ptr<AbstractFunctionSpaceElement > x;
99 Functional& fu;
100 mutable typename Functional::Matrix mat;
101 mutable bool mflushed;
102};
103
104 template<class T, class Functional>
105 class LinearizationTraits<Dune::BlockVector<T>, Functional>
106 {
107 public:
109 };
110
111}
112
113
114#endif
Linearization Implementation for a fixed system, i.e. an inherently finite dimensional system,...
Implementation const & getLinImpl() const
return the implementation
virtual void getMatrixBlocks(MatrixAsTriplet< RT > &mat_, int rbegin, int rend, int cbegin, int cend) const
virtual void getRHSBlocks(std::vector< RT > &rhs_, int rbegin, int rend) const
int rows(int rbegin, int rend) const
int cols(int cbegin, int cend) const
AbstractFunctionSpaceElement const & getOrigin() const
FixedSystemLinearization(Functional &fu_, AbstractFunctionSpaceElement const &x_)
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition: fixdune.hh:110
Dune::FieldVector< T, n > min(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise minimum.
Definition: fixdune.hh:122
Dune::BlockVector< Dune::FieldVector< Scalar, n >, Allocator > BlockVector
Dune::FieldVector< Scalar, dim > Vector
Bridge classes that connect low level FE algorithms to higher level algorithms.