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 );
151 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
152 fullOperator().subConstraints( u, v );
156 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
157 fullOperator().subConstraints( v );
161 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
162 fullOperator().addConstraints( u, v );
166 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
167 fullOperator().addConstraints( v );
169 const auto &dirichletBlocks()
const
171 if constexpr (AddDirichletBC<Operator,DomainFunctionType>::value)
172 return fullOperator().dirichletBlocks();
177 fullOperator()( arg, dest );
179 template <
class Gr
idFunction>
183 fullOperator()( arg, dest );
185 void setErrorMeasure(ErrorMeasureType &errorMeasure)
const
187 invOp_.setErrorMeasure(errorMeasure);
192 invOp_.bind(fullOperator());
193 _solve(rhs,solution);
195 return invOp_.info();
199 PreconditionerFunctionWrapperType pre( p );
200 invOp_.bind(fullOperator(), pre);
201 _solve(rhs,solution);
203 return invOp_.info();
209 return solve(zero,solution);
211 SolverInfoType solve (
DiscreteFunctionType &solution,
const PreconditionerFunctionType& p )
const
215 return solve(zero,solution,p);
218 template<
class GridFunction, std::enable_if_t<
219 std::is_same<
decltype(
220 std::declval< const DifferentiableOperatorType >().jacobian(
221 std::declval< const GridFunction& >(), std::declval< JacobianOperatorType& >()
223 ),
void >::value,
int> i = 0
225 void jacobian(
const GridFunction &ubar, JacobianOperatorType &linOp )
const
227 fullOperator().jacobian(ubar, linOp);
230 const GridPartType &gridPart ()
const {
return space().gridPart(); }
231 const DiscreteFunctionSpaceType &space( )
const {
return space_; }
233 const ModelType &model()
const
235 return fullOperator().model();
239 return fullOperator().model();
244 setConstraints(solution);
245 addConstraints(rhs,solution);
246 invOp_( rhs, solution );
247 return invOp_.info();
250 const DiscreteFunctionSpaceType &space_;
251 std::shared_ptr< DifferentiableOperatorType > fullOpPtr_;
252 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, ...