DUNE-FEM (unstable)

dirichletwrapper.hh
1#ifndef DUNE_FEM_DIRICHLETWRAPPER_HH
2#define DUNE_FEM_DIRICHLETWRAPPER_HH
3
4#include <cstddef>
5
7
8#include <dune/fem/quadrature/cachingquadrature.hh>
9#include <dune/fem/operator/common/operator.hh>
10#include <dune/fem/operator/common/stencil.hh>
11
12#include <dune/fem/common/bindguard.hh>
13#include <dune/fem/function/common/localcontribution.hh>
14#include <dune/fem/function/localfunction/const.hh>
15
16#include <dune/fem/operator/common/differentiableoperator.hh>
17
18#include <dune/fem/schemes/dirichletconstraints.hh>
19#include <dune/fem/io/parameter.hh>
20
21
22template< class Operator,
23 class Constraints = Dune::DirichletConstraints< typename Operator::ModelType,
24 typename Operator::RangeDiscreteFunctionSpaceType,
25 std::is_same_v<typename Operator::DomainFunctionType::DiscreteFunctionSpaceType,
26 typename Operator::RangeFunctionType::DiscreteFunctionSpaceType >
27 >
28 >
29struct DirichletWrapperOperator
30: public Dune::Fem::DifferentiableOperator< typename Operator::JacobianOperatorType >
31{
32 typedef typename Operator::DomainFunctionType DomainFunctionType;
33 typedef typename Operator::RangeFunctionType RangeFunctionType;
34 typedef typename Operator::ModelType ModelType;
35 typedef typename Operator::DirichletModelType DirichletModelType;
36 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainDiscreteFunctionSpaceType;
37 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeDiscreteFunctionSpaceType;
38 typedef typename Operator::JacobianOperatorType JacobianOperatorType;
39 typedef typename DomainDiscreteFunctionSpaceType::RangeType DomainRangeType;
40 typedef Constraints ConstraintsType;
41 typedef typename ConstraintsType::DirichletBlockVector DirichletBlockVector;
42
43 template <class... Args>
44 DirichletWrapperOperator ( Args&... args )
45 : op_( std::forward<Args&>(args)... ) ,
46 constraints_( op_.model(), op_.rangeSpace() )
47 {}
48
49 void setConstraints( DomainFunctionType &u ) const
50 {
51 // set boundary values for solution from model
52 constraints()( u );
53 }
54 void setConstraints( const DomainRangeType &value, DomainFunctionType &u ) const
55 {
56 // set values for solution to a given constant value
57 constraints()( value, u );
58 }
59 template <class GF>
60 void setConstraints( const GF &u, RangeFunctionType &w ) const
61 {
62 // set boundary values for solution from a general grid function
63 constraints()( u, w, ConstraintsType::Operation::set );
64 }
65 void setConstraints( JacobianOperatorType &lin ) const
66 {
67 // set boundary values for solution from a general grid function
68 constraints().applyToOperator(lin);
69 }
70 template <class GF>
71 void subConstraints( const GF &u, RangeFunctionType &w ) const
72 {
73 // subtract boundary values from solution
74 constraints()( u, w, ConstraintsType::Operation::sub );
75 }
76 void subConstraints( RangeFunctionType &w ) const
77 {
78 // subtract boundary values from solution
79 constraints()( w, ConstraintsType::Operation::sub );
80 }
81 template <class GF>
82 void addConstraints( const GF &u, RangeFunctionType &w ) const
83 {
84 // add boundary values to solution
85 constraints()( u, w, ConstraintsType::Operation::add );
86 }
87 void addConstraints( RangeFunctionType &w ) const
88 {
89 // add boundary values to solution
90 constraints()( w, ConstraintsType::Operation::add );
91 }
92 const auto &dirichletBlocks() const
93 {
94 return constraints().dirichletBlocks();
95 }
96
97 // return true if operator is based on nonlinear model
98 virtual bool nonlinear () const { return op_.nonlinear(); }
99
101 virtual void operator() ( const DomainFunctionType &u, RangeFunctionType &w ) const
102 {
103 op_(u,w);
104 subConstraints( u, w );
105 }
106 template <class GF>
107 auto operator()( const GF &u, RangeFunctionType &w ) const
109 {
110 op_(u,w);
111 subConstraints( u, w );
112 }
113
114 void jacobian ( const DomainFunctionType &u, JacobianOperatorType &jOp ) const
115 {
116 op_.jacobian(u,jOp);
117 constraints().applyToOperator( jOp );
118 jOp.flushAssembly();
119 }
120 template <class GridFunctionType>
121 auto jacobian ( const GridFunctionType &u, JacobianOperatorType &jOp ) const
123 {
124 op_.jacobian(u,jOp);
125 constraints().applyToOperator( jOp );
126 jOp.flushAssembly();
127 }
128
129 const DomainDiscreteFunctionSpaceType& domainSpace() const
130 {
131 return op_.domainSpace();
132 }
133 const RangeDiscreteFunctionSpaceType& rangeSpace() const
134 {
135 return op_.rangeSpace();
136 }
137
138 std::size_t gridSizeInterior () const
139 {
140 return op_.gridSizeInterior();
141 }
142
143 template <typename O = Operator>
144 auto setCommunicate ( const bool commuicate )
145 -> Dune::void_t< decltype( std::declval< O >().setCommunicate(true) ) >
146 {
147 op_.setCommunicate(commuicate);
148 }
149
150 template <typename O = Operator>
151 auto setQuadratureOrders(unsigned int interior, unsigned int surface)
152 -> Dune::void_t< decltype( std::declval< O >().setQuadratureOrders(0,0) ) >
153 {
154 return op_.setQuadratureOrders(interior,surface);
155 }
156
157 ModelType &model () const { return op_.model(); }
158 const ConstraintsType &constraints () const { return constraints_; }
159 const auto& impl() const { return op_.impl(); }
160
161
162private:
163 Operator op_;
164 ConstraintsType constraints_;
165};
166#endif // #ifndef DUNE_FEM_CONSTRAINTSWRAPPER_HH
abstract differentiable operator
Definition: differentiableoperator.hh:29
BaseType::RangeFunctionType RangeFunctionType
type of discrete function in the operator's range
Definition: differentiableoperator.hh:40
JacobianOperator JacobianOperatorType
type of linear operator modelling the operator's Jacobian
Definition: differentiableoperator.hh:35
BaseType::DomainFunctionType DomainFunctionType
type of discrete function in the operator's domain
Definition: differentiableoperator.hh:38
virtual void jacobian(const DomainFunctionType &u, JacobianOperatorType &jOp) const =0
obtain linearization
Implements a matrix constructed from a given type representing a field and compile-time given number ...
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
STL namespace.
virtual void operator()(const DomainFunctionType &u, RangeFunctionType &w) const=0
application operator
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Sep 5, 22:35, 2025)