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 template <
typename O = DifferentiableOperatorType>
120 auto setQuadratureOrders(
unsigned int interior,
unsigned int surface)
123 fullOperator().setQuadratureOrders(interior,surface);
126 void setConstraints( DomainFunctionType &u )
const
128 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
129 fullOperator().setConstraints( u );
133 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
134 fullOperator().setConstraints( u,v );
136 template <
class Gr
idFunctionType>
139 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
140 fullOperator().setConstraints( u, v );
144 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
145 fullOperator().setConstraints( value, u );
149 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
150 fullOperator().subConstraints( u, v );
154 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
155 fullOperator().subConstraints( v );
159 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
160 fullOperator().addConstraints( u, v );
164 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
165 fullOperator().addConstraints( v );
167 const auto &dirichletBlocks()
const
169 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
170 return fullOperator().dirichletBlocks();
175 fullOperator()( arg, dest );
177 template <
class Gr
idFunction>
181 fullOperator()( arg, dest );
183 void setErrorMeasure(ErrorMeasureType &errorMeasure)
const
185 invOp_.setErrorMeasure(errorMeasure);
190 invOp_.bind(fullOperator());
191 _solve(rhs,solution);
193 return invOp_.info();
197 PreconditionerFunctionWrapperType pre( p );
198 invOp_.bind(fullOperator(), pre);
199 _solve(rhs,solution);
201 return invOp_.info();
207 return solve(zero,solution);
209 SolverInfoType solve (
DiscreteFunctionType &solution,
const PreconditionerFunctionType& p )
const
213 return solve(zero,solution,p);
216 template<
class GridFunction, std::enable_if_t<
217 std::is_same<
decltype(
218 std::declval< const DifferentiableOperatorType >().jacobian(
219 std::declval< const GridFunction& >(), std::declval< JacobianOperatorType& >()
221 ),
void >::value,
int> i = 0
223 void jacobian(
const GridFunction &ubar, JacobianOperatorType &linOp )
const
225 fullOperator().jacobian(ubar, linOp);
228 const GridPartType &gridPart ()
const {
return space().gridPart(); }
229 const DiscreteFunctionSpaceType &space( )
const {
return space_; }
231 const ModelType &model()
const
233 return fullOperator().model();
237 return fullOperator().model();
242 setConstraints(solution);
243 addConstraints(rhs,solution);
244 invOp_( rhs, solution );
245 return invOp_.info();
248 const DiscreteFunctionSpaceType &space_;
249 std::shared_ptr< DifferentiableOperatorType > fullOpPtr_;
250 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, ...