dune-fem 2.12-git
Loading...
Searching...
No Matches
femscheme.hh
Go to the documentation of this file.
1#ifndef DUNE_FEM_SCHEMES_FEMSCHEME_HH
2#define DUNE_FEM_SCHEMES_FEMSCHEME_HH
3
9
10namespace Dune
11{
12 namespace Fem
13 {
14
15// FemScheme
16//----------
17
18template < class Op, class DF, typename = void >
20{
21 static const bool value = false;
23};
24template < class Op, class DF>
25struct AddDirichletBC<Op,DF,std::enable_if_t<std::is_void< decltype( std::declval<const Op>().
26 setConstraints( std::declval<DF&>() ) )>::value > >
27{
28 static const bool value = true;
29 using DirichletBlockVector = typename Op::DirichletBlockVector;
30};
31
32template< class Operator, class LinearInverseOperator,
33 class InverseOperator = Dune::Fem::NewtonInverseOperator< typename Operator::JacobianOperatorType,
34 LinearInverseOperator > >
36{
37public:
39 typedef typename Operator::ModelType ModelType;
44 typedef typename DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
45 typedef LinearInverseOperator LinearInverseOperatorType;
46
48 typedef typename ModelType::GridPartType GridPartType;
50 "GridPart of Space has to be identical to GridPart of Model class" );
51
53 typedef typename GridPartType::GridType GridType;
54
56 typedef typename DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType;
57
58 typedef typename Operator::JacobianOperatorType JacobianOperatorType;
59 typedef typename Operator::JacobianOperatorType LinearOperatorType;
60
61 // type of inverse operator (could be nonlinear or linear depending on the derived class)
63
64 typedef typename InverseOperatorType::ErrorMeasureType ErrorMeasureType;
65
67 typename LinearOperatorType::RangeFunctionType,
68 typename LinearOperatorType::DomainFunctionType > PreconditionerFunctionWrapperType;
69 // std::function to represents the Python function passed as potential preconditioner
71
72 typedef typename FunctionSpaceType::RangeType RangeType;
73 static const int dimRange = FunctionSpaceType::dimRange;
76 /*********************************************************/
77
79 typedef typename InverseOperatorType::SolverInfoType SolverInfoType;
80
84 : space_( space ),
85 // the full discretized operator
88 // create inverse operator to invert the operator
89 invOp_( parameter )
90 {}
91
93 template < class... Models >
94 FemScheme ( const DiscreteFunctionSpaceType &space, // discrete function space
95 const Dune::Fem::ParameterReader &parameter, // parameters
96 Models &&... models ) // list of models, could be more than one
97 : space_( space ),
98 // the full discretized operator
99 fullOpPtr_( new DifferentiableOperatorType( space, space, std::forward< Models >( models )... )),
101 // create inverse operator to invert the operator
102 invOp_( parameter )
103 {}
104
107 const Dune::Fem::ParameterReader &parameter) // parameters
108 : space_( fullOp.space() ),
109 fullOpPtr_(), // empty here since fullOp reference is provided
110 // the full discretized operator
111 fullOperator_( fullOp ),
112 // create inverse operator to invert the operator
113 invOp_( parameter )
114 {}
115
118
119 std::size_t gridSizeInterior () const { return fullOperator().gridSizeInterior(); }
120
121 template <typename O = DifferentiableOperatorType>
122 auto setQuadratureOrders(unsigned int interior, unsigned int surface)
123 -> Dune::void_t< decltype( std::declval< O >().setQuadratureOrders(0,0) ) >
124 {
125 fullOperator().setQuadratureOrders(interior,surface);
126 }
127
129 {
131 fullOperator().setConstraints( u );
132 }
134 {
136 fullOperator().setConstraints( u,v );
137 }
138 template <class GridFunctionType>
139 void setConstraints( const GridFunctionType &u, DiscreteFunctionType &v ) const
140 {
142 fullOperator().setConstraints( u, v );
143 }
144 void setConstraints( const RangeType &value, DiscreteFunctionType &u ) const
145 {
147 fullOperator().setConstraints( value, u );
148 }
150 {
152 fullOperator().setConstraints( lin );
153 }
155 {
157 fullOperator().subConstraints( u, v );
158 }
160 {
162 fullOperator().subConstraints( v );
163 }
165 {
167 fullOperator().addConstraints( u, v );
168 }
170 {
172 fullOperator().addConstraints( v );
173 }
174 const auto &dirichletBlocks() const
175 {
177 return fullOperator().dirichletBlocks();
178 }
179
181 {
182 fullOperator()( arg, dest );
183 }
184 template <class GridFunction>
185 auto operator() ( const GridFunction &arg, DiscreteFunctionType &dest ) const
187 {
188 fullOperator()( arg, dest );
189 }
190 void setErrorMeasure(ErrorMeasureType &errorMeasure) const
191 {
192 invOp_.setErrorMeasure(errorMeasure);
193 }
194
196 {
197 invOp_.bind(fullOperator());
198 _solve(rhs,solution);
199 invOp_.unbind();
200 return invOp_.info();
201 }
203 {
205 invOp_.bind(fullOperator(), pre);
206 _solve(rhs,solution);
207 invOp_.unbind();
208 return invOp_.info();
209 }
211 {
212 DiscreteFunctionType zero( solution );
213 zero.clear();
214 return solve(zero,solution);
215 }
217 {
218 DiscreteFunctionType zero( solution );
219 zero.clear();
220 return solve(zero,solution,p);
221 }
222
223 template< class GridFunction, std::enable_if_t<
224 std::is_same< decltype(
227 )
228 ), void >::value, int> i = 0
229 >
230 void jacobian( const GridFunction &ubar, JacobianOperatorType &linOp ) const
231 {
232 fullOperator().jacobian(ubar, linOp);
233 }
234
235 const GridPartType &gridPart () const { return space().gridPart(); }
236 const DiscreteFunctionSpaceType &space( ) const { return space_; }
237
238 const ModelType &model() const
239 {
240 return fullOperator().model();
241 }
243 {
244 return fullOperator().model();
245 }
246protected:
248 { // setup for Newton scheme
249 setConstraints(solution); // sol=g on bnd
250 addConstraints(rhs,solution); // sol=g+rhs on bnd
251 invOp_( rhs, solution );
252 return invOp_.info();
253 }
254
255 const DiscreteFunctionSpaceType &space_; // discrete function space
257 DifferentiableOperatorType& fullOperator_; // reference to fullOperator (could be provided by derived class)
258 mutable InverseOperatorType invOp_; // non linear solver
259};
260} // end namespace Fem
261
262} // end namespace Dune
263#endif // #ifndef DUNE_FEM_SCHEMES_FEMSCHEME_HH
void pre(Domain &x, Range &b)
Y & rhs()
typename Impl::voider< Types... >::type void_t
constexpr auto models()
virtual void operator()()=0
STL namespace.
static ParameterContainer & container()
Definition io/parameter.hh:199
abstract operator
Definition operator.hh:34
DomainFunction DomainFunctionType
type of discrete function in the operator's domain
Definition operator.hh:36
RangeFunction RangeFunctionType
type of discrete function in the operator's range
Definition operator.hh:38
Definition femscheme.hh:20
void DirichletBlockVector
Definition femscheme.hh:22
static const bool value
Definition femscheme.hh:21
Definition femscheme.hh:36
FunctionSpaceType::RangeType RangeType
Definition femscheme.hh:72
void setConstraints(const GridFunctionType &u, DiscreteFunctionType &v) const
Definition femscheme.hh:139
void setConstraints(JacobianOperatorType &lin) const
Definition femscheme.hh:149
std::shared_ptr< DifferentiableOperatorType > fullOpPtr_
Definition femscheme.hh:256
DiscreteFunctionSpaceType::FunctionSpaceType FunctionSpaceType
type of function space (scalar functions,
Definition femscheme.hh:56
ModelType & model()
Definition femscheme.hh:242
DiscreteFunctionType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
Definition femscheme.hh:44
std::size_t gridSizeInterior() const
Definition femscheme.hh:119
SolverInfoType solve(const DiscreteFunctionType &rhs, DiscreteFunctionType &solution, const PreconditionerFunctionType &p) const
Definition femscheme.hh:202
FemScheme(const DiscreteFunctionSpaceType &space, ModelType &model, const Dune::Fem::ParameterReader &parameter=Dune::Fem::Parameter::container())
constructor with one model
Definition femscheme.hh:82
const DiscreteFunctionSpaceType & space() const
Definition femscheme.hh:236
InverseOperatorType::SolverInfoType SolverInfoType
type of solver statistics reported (defined in inverseoperatorinterface.hh)
Definition femscheme.hh:79
PreconditionerFunctionWrapperType::PreconditionerFunctionType PreconditionerFunctionType
Definition femscheme.hh:70
Operator::JacobianOperatorType LinearOperatorType
Definition femscheme.hh:59
InverseOperatorType::ErrorMeasureType ErrorMeasureType
Definition femscheme.hh:64
Operator::ModelType ModelType
type of the mathematical model
Definition femscheme.hh:39
void setConstraints(DomainFunctionType &u) const
Definition femscheme.hh:128
void subConstraints(const DiscreteFunctionType &u, DiscreteFunctionType &v) const
Definition femscheme.hh:154
void jacobian(const GridFunction &ubar, JacobianOperatorType &linOp) const
Definition femscheme.hh:230
void addConstraints(DiscreteFunctionType &v) const
Definition femscheme.hh:169
static const int dimRange
Definition femscheme.hh:73
Operator::RangeFunctionType RangeFunctionType
Definition femscheme.hh:41
FemScheme(const DiscreteFunctionSpaceType &space, const Dune::Fem::ParameterReader &parameter, Models &&... models)
constructor for derived classes (GalerkinScheme and MassLumpingScheme) with a list of models
Definition femscheme.hh:94
SolverInfoType _solve(const DiscreteFunctionType &rhs, DiscreteFunctionType &solution) const
Definition femscheme.hh:247
const DifferentiableOperatorType & fullOperator() const
Definition femscheme.hh:116
const ModelType & model() const
Definition femscheme.hh:238
Dune::Fem::PreconditionerFunctionWrapper< typename LinearOperatorType::RangeFunctionType, typename LinearOperatorType::DomainFunctionType > PreconditionerFunctionWrapperType
Definition femscheme.hh:68
FemScheme(DifferentiableOperatorType &fullOp, const Dune::Fem::ParameterReader &parameter)
constructor for derived classes (LinearScheme and LinearizedScheme)
Definition femscheme.hh:106
Operator::DomainFunctionType DomainFunctionType
Definition femscheme.hh:40
DifferentiableOperatorType & fullOperator_
Definition femscheme.hh:257
InverseOperator InverseOperatorType
Definition femscheme.hh:62
ModelType::GridPartType GridPartType
grid view (e.g. leaf grid view) provided in the template argument list
Definition femscheme.hh:48
InverseOperatorType invOp_
Definition femscheme.hh:258
Operator DifferentiableOperatorType
Definition femscheme.hh:43
const GridPartType & gridPart() const
Definition femscheme.hh:235
Operator::RangeFunctionType DiscreteFunctionType
Definition femscheme.hh:42
void subConstraints(DiscreteFunctionType &v) const
Definition femscheme.hh:159
SolverInfoType solve(DiscreteFunctionType &solution) const
Definition femscheme.hh:210
void addConstraints(const DiscreteFunctionType &u, DiscreteFunctionType &v) const
Definition femscheme.hh:164
void setErrorMeasure(ErrorMeasureType &errorMeasure) const
Definition femscheme.hh:190
auto setQuadratureOrders(unsigned int interior, unsigned int surface) -> Dune::void_t< decltype(std::declval< O >().setQuadratureOrders(0, 0)) >
Definition femscheme.hh:122
LinearInverseOperator LinearInverseOperatorType
Definition femscheme.hh:45
Operator::JacobianOperatorType JacobianOperatorType
Definition femscheme.hh:58
typename AddDirichletBC< Operator, DomainFunctionType >::DirichletBlockVector DirichletBlockVector
Definition femscheme.hh:75
void setConstraints(const RangeType &value, DiscreteFunctionType &u) const
Definition femscheme.hh:144
const auto & dirichletBlocks() const
Definition femscheme.hh:174
void setConstraints(const DiscreteFunctionType &u, DiscreteFunctionType &v) const
Definition femscheme.hh:133
DifferentiableOperatorType & fullOperator()
Definition femscheme.hh:117
const DiscreteFunctionSpaceType & space_
Definition femscheme.hh:255
GridPartType::GridType GridType
type of underlying hierarchical grid needed for data output
Definition femscheme.hh:53
SolverInfoType solve(const DiscreteFunctionType &rhs, DiscreteFunctionType &solution) const
Definition femscheme.hh:195
static constexpr bool addDirichletBC
Definition femscheme.hh:74
SolverInfoType solve(DiscreteFunctionType &solution, const PreconditionerFunctionType &p) const
Definition femscheme.hh:216
inverse operator based on a newton scheme
Definition newtoninverseoperator.hh:426
Wrapper for functions passed from Python side that implements a preconditioner.
Definition preconditionfunctionwrapper.hh:23
T forward(T... args)