1#ifndef DUNE_FEM_SCHEMES_LINEARIZED_HH
2#define DUNE_FEM_SCHEMES_LINEARIZED_HH
11#include <dune/fem/operator/common/operator.hh>
12#include <dune/fem/space/common/interpolate.hh>
13#include <dune/fem/io/parameter.hh>
14#include <dune/fem/schemes/femscheme.hh>
51 template<
class Scheme >
52 struct LinearScheme :
public Scheme::LinearOperatorType,
53 public FemScheme< Scheme, typename Scheme::LinearInverseOperatorType, typename Scheme::LinearInverseOperatorType >
55 typedef Scheme SchemeType;
56 typedef typename SchemeType::LinearInverseOperatorType LinearInverseOperatorType;
59 typedef typename SchemeType::LinearOperatorType BaseType;
60 typedef FemScheme< SchemeType, LinearInverseOperatorType, LinearInverseOperatorType > FSBaseType;
63 typedef typename SchemeType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
64 typedef typename SchemeType::GridPartType GridPartType;
65 typedef typename LinearInverseOperatorType::SolverParameterType ParameterType;
66 typedef typename SchemeType::ModelType ModelType;
68 typedef typename SchemeType::JacobianOperatorType JacobianOperatorType;
69 typedef typename SchemeType::DomainFunctionType DomainFunctionType;
70 typedef typename SchemeType::RangeFunctionType RangeFunctionType;
72 typedef typename SchemeType::DirichletBlockVector DirichletBlockVector;
76 typedef typename PreconditionerFunctionWrapperType::PreconditionerFunctionType PreconditionerFunctionType;
78 using FSBaseType :: fullOperator;
79 using FSBaseType :: setConstraints;
80 using FSBaseType :: space;
83 typedef typename LinearInverseOperatorType::SolverInfoType SolverInfoType ;
86 LinearScheme ( SchemeType &scheme,
87 Dune::Fem::ParameterReader parameter = Dune::Fem::Parameter::container() )
88 : BaseType(
"linearized Op", scheme.space(), scheme.space() ),
89 FSBaseType( scheme, parameter ),
91 parameter_(
std::move( parameter ) ),
92 tmp_(
"LS::tmp", scheme.space() )
98 Dune::Fem::ParameterReader parameter = Dune::Fem::Parameter::container() )
99 : BaseType(
"linearized Op", scheme.space(), scheme.space() ),
100 FSBaseType( scheme, parameter ),
102 parameter_(
std::move( parameter ) ),
103 tmp_(
"LS::tmp", scheme.space() )
105 fullOperator().jacobian(ubar,*
this);
112 void setErrorMeasure()
const {}
114 using BaseType::clear;
115 virtual void clear()
override
125 BaseType::operator()(u,w);
128 template <
class Gr
idFunction>
145 setConstraints(rhs, solution);
146 invOp_(rhs, solution );
147 return invOp_.info();
155 PreconditionerFunctionWrapperType pre( p );
156 invOp_.bind(*
this, pre);
158 auto info = solve( rhs, solution );
181 invOp_( zero, solution );
182 return invOp_.info();
185 const SchemeType &scheme()
const {
return fullOperator(); }
186 const ParameterReader& parameter ()
const {
return parameter_; }
190 using FSBaseType :: invOp_;
191 mutable bool isBound_;
192 Dune::Fem::ParameterReader parameter_;
198 template<
class Scheme >
199 struct LinearizedScheme
200 :
public Dune::Fem::Operator<typename Scheme::DomainFunctionType, typename Scheme::RangeFunctionType>
202 typedef Scheme SchemeType;
204 typedef typename SchemeType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
205 typedef typename SchemeType::GridPartType GridPartType;
206 typedef typename SchemeType::LinearInverseOperatorType LinearInverseOperatorType;
207 typedef typename SchemeType::ModelType ModelType;
209 typedef typename SchemeType::JacobianOperatorType JacobianOperatorType;
210 typedef typename SchemeType::DomainFunctionType DomainFunctionType;
211 typedef typename SchemeType::RangeFunctionType RangeFunctionType;
213 typedef typename SchemeType::DirichletBlockVector DirichletBlockVector;
215 typedef typename LinearOperatorType::SolverInfoType SolverInfoType;
221 typedef typename PreconditionerFunctionWrapperType::PreconditionerFunctionType PreconditionerFunctionType;
223 LinearizedScheme ( SchemeType &scheme,
224 const Dune::Fem::ParameterReader& parameter = Dune::Fem::Parameter::container() )
225 : linOp_( scheme, parameter ),
226 rhs_(
"affine shift", scheme.space() ),
227 ubar_(
"ubar", scheme.space() )
232 const Dune::Fem::ParameterReader& parameter = Dune::Fem::Parameter::container() )
233 : linOp_( scheme, ubar, parameter ),
234 rhs_(
"affine shift", scheme.space() ),
235 ubar_(
"ubar", scheme.space() )
246 template <
class Gr
idFunction>
247 void setup(
const GridFunction &ubar)
262 void setErrorMeasure()
const {}
263 void setConstraints( DomainFunctionType &u )
const
265 linOp_.setConstraints(u);
269 linOp_.setConstraints(value, u);
273 linOp_.setConstraints(u, v);
275 template <
class GridFunctionType,
276 typename = std::enable_if_t< std::is_base_of<Dune::Fem::HasLocalFunction, GridFunctionType>::value > >
279 linOp_.setConstraints(u, v);
283 linOp_.subConstraints(u, v);
287 linOp_.subConstraints(v);
291 linOp_.addConstraints(u, v);
295 linOp_.addConstraints(v);
297 const auto& dirichletBlocks()
const
299 return linOp_.dirichletBlocks();
307 template <
class Gr
idFunction>
316 return _solve(rhs, solution,
nullptr );
322 return _solve( rhs, solution, &p );
336 return linOp_.solve( rhs_, solution );
339 const GridPartType &gridPart ()
const {
return linOp_.gridPart(); }
340 const DiscreteFunctionSpaceType &space()
const {
return linOp_.space(); }
341 const SchemeType &scheme() {
return linOp_.scheme(); }
342 const ParameterReader& parameter ()
const {
return linOp_.parameter(); }
354 return linOp_.solve( sumRhs, solution, *p);
356 return linOp_.solve( sumRhs, solution);
359 void setup_(
bool isZero=
false)
368 scheme()( ubar_, tmp );
373 linOp_( ubar_, rhs_ );
void clear()
set all degrees of freedom to zero
Definition: discretefunction.hh:731
DiscreteFunctionSpaceType::RangeType RangeType
type of range vector
Definition: discretefunction.hh:614
void assign(const DiscreteFunctionInterface< DFType > &g)
Definition: discretefunction_inline.hh:132
void jacobian(const DomainType &x, JacobianRangeType &jacobian) const
evaluate the Jacobian of the function
Definition: discretefunction.hh:845
Wrapper for functions passed from Python side that implements a preconditioner.
Definition: preconditionfunctionwrapper.hh:23
forward declaration
Definition: discretefunction.hh:51
static void interpolate(const GridFunction &u, DiscreteFunction &v)
perform native interpolation of a discrete function space
Definition: interpolate.hh:54
Dune namespace.
Definition: alignedallocator.hh:13
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
SparseRowLinearOperator.
Definition: spoperator.hh:25