1#ifndef DUNE_FEM_SCHEMES_FEMSCHEME_HH
2#define DUNE_FEM_SCHEMES_FEMSCHEME_HH
5#include <dune/fem/operator/common/differentiableoperator.hh>
6#include <dune/fem/io/parameter/reader.hh>
7#include <dune/fem/solver/newtoninverseoperator.hh>
8#include <dune/fem/solver/preconditionfunctionwrapper.hh>
18template <
class Op,
class DF,
typename =
void >
21 static const bool value =
false;
22 using DirichletBlockVector = void;
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 > >
28 static const bool value =
true;
29 using DirichletBlockVector =
typename Op::DirichletBlockVector;
32template<
class Operator,
class LinearInverseOperator,
34 LinearInverseOperator > >
39 typedef typename Operator::ModelType ModelType;
43 typedef Operator DifferentiableOperatorType;
45 typedef LinearInverseOperator LinearInverseOperatorType;
48 typedef typename ModelType::GridPartType GridPartType;
49 static_assert( std::is_same< typename DiscreteFunctionSpaceType::GridPartType, GridPartType >::value,
50 "GridPart of Space has to be identical to GridPart of Model class" );
53 typedef typename GridPartType::GridType GridType;
58 typedef typename Operator::JacobianOperatorType JacobianOperatorType;
64 typedef typename InverseOperatorType::ErrorMeasureType ErrorMeasureType;
70 typedef typename PreconditionerFunctionWrapperType::PreconditionerFunctionType PreconditionerFunctionType ;
74 static constexpr bool addDirichletBC = AddDirichletBC<Operator,DomainFunctionType>::value;
75 using DirichletBlockVector =
typename AddDirichletBC<Operator,DomainFunctionType>::DirichletBlockVector;
79 typedef typename InverseOperatorType::SolverInfoType SolverInfoType;
82 FemScheme (
const DiscreteFunctionSpaceType &space, ModelType &model,
83 const Dune::Fem::ParameterReader ¶meter = Dune::Fem::Parameter::container() )
86 fullOpPtr_( new DifferentiableOperatorType(space, space, model, parameter) ),
87 fullOperator_( *fullOpPtr_ ),
93 template <
class... Models >
94 FemScheme (
const DiscreteFunctionSpaceType &space,
95 const Dune::Fem::ParameterReader ¶meter,
99 fullOpPtr_( new DifferentiableOperatorType( space, space,
std::forward< Models >(
models )... )),
100 fullOperator_( *fullOpPtr_ ),
106 FemScheme ( DifferentiableOperatorType& fullOp,
107 const Dune::Fem::ParameterReader ¶meter)
108 : space_( fullOp.space() ),
111 fullOperator_( fullOp ),
116 const DifferentiableOperatorType &fullOperator()
const {
return fullOperator_; }
117 DifferentiableOperatorType &fullOperator() {
return fullOperator_; }
119 std::size_t gridSizeInterior ()
const {
return fullOperator().gridSizeInterior(); }
121 template <
typename O = DifferentiableOperatorType>
122 auto setQuadratureOrders(
unsigned int interior,
unsigned int surface)
125 fullOperator().setQuadratureOrders(interior,surface);
128 void setConstraints( DomainFunctionType &u )
const
130 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
131 fullOperator().setConstraints( u );
135 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
136 fullOperator().setConstraints( u,v );
138 template <
class Gr
idFunctionType>
141 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
142 fullOperator().setConstraints( u, v );
146 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
147 fullOperator().setConstraints( value, u );
149 void setConstraints( JacobianOperatorType &lin )
const
151 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
152 fullOperator().setConstraints( lin );
156 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
157 fullOperator().subConstraints( u, v );
161 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
162 fullOperator().subConstraints( v );
166 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
167 fullOperator().addConstraints( u, v );
171 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
172 fullOperator().addConstraints( v );
174 const auto &dirichletBlocks()
const
176 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
177 return fullOperator().dirichletBlocks();
182 fullOperator()( arg, dest );
184 template <
class Gr
idFunction>
188 fullOperator()( arg, dest );
190 void setErrorMeasure(ErrorMeasureType &errorMeasure)
const
192 invOp_.setErrorMeasure(errorMeasure);
197 invOp_.bind(fullOperator());
198 _solve(rhs,solution);
200 return invOp_.info();
204 PreconditionerFunctionWrapperType pre( p );
205 invOp_.bind(fullOperator(), pre);
206 _solve(rhs,solution);
208 return invOp_.info();
214 return solve(zero,solution);
216 SolverInfoType solve (
DiscreteFunctionType &solution,
const PreconditionerFunctionType& p )
const
220 return solve(zero,solution,p);
223 template<
class GridFunction, std::enable_if_t<
224 std::is_same<
decltype(
225 std::declval< const DifferentiableOperatorType >().jacobian(
226 std::declval< const GridFunction& >(), std::declval< JacobianOperatorType& >()
228 ),
void >::value,
int> i = 0
230 void jacobian(
const GridFunction &ubar, JacobianOperatorType &linOp )
const
232 fullOperator().jacobian(ubar, linOp);
235 const GridPartType &gridPart ()
const {
return space().gridPart(); }
236 const DiscreteFunctionSpaceType &space( )
const {
return space_; }
238 const ModelType &model()
const
240 return fullOperator().model();
244 return fullOperator().model();
249 setConstraints(solution);
250 addConstraints(rhs,solution);
251 invOp_( rhs, solution );
252 return invOp_.info();
255 const DiscreteFunctionSpaceType &space_;
256 std::shared_ptr< DifferentiableOperatorType > fullOpPtr_;
257 DifferentiableOperatorType& fullOperator_;
Inverse operator base on CG method. Uses a runtime parameter fem.preconditioning which enables diagon...
Definition: cginverseoperator.hh:408
Traits::FunctionSpaceType FunctionSpaceType
type of function space
Definition: discretefunctionspace.hh:194
FunctionSpaceTraits::RangeType RangeType
Type of range vector (using type of range field) has a Dune::FieldVector type interface.
Definition: functionspaceinterface.hh:71
@ dimRange
dimension of range vector space
Definition: functionspaceinterface.hh:48
A vector valued function space.
Definition: functionspace.hh:60
inverse operator based on a newton scheme
Definition: newtoninverseoperator.hh:357
Wrapper for functions passed from Python side that implements a preconditioner.
Definition: preconditionfunctionwrapper.hh:23
forward declaration
Definition: discretefunction.hh:51
TupleDiscreteFunctionSpace< typename DiscreteFunctions::DiscreteFunctionSpaceType ... > DiscreteFunctionSpaceType
type for the discrete function space this function lives in
Definition: discretefunction.hh:69
constexpr auto models()
Check if concept is modeled by given types.
Definition: concept.hh:184
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
Dune namespace.
Definition: alignedallocator.hh:13
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
SparseRowLinearOperator.
Definition: spoperator.hh:25
Utilities for type computations, constraining overloads, ...