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 template <class GF>
66 void subConstraints( const GF &u, RangeFunctionType &w ) const
67 {
68 // subtract boundary values from solution
69 constraints()( u, w, ConstraintsType::Operation::sub );
70 }
71 void subConstraints( RangeFunctionType &w ) const
72 {
73 // subtract boundary values from solution
74 constraints()( w, ConstraintsType::Operation::sub );
75 }
76 template <class GF>
77 void addConstraints( const GF &u, RangeFunctionType &w ) const
78 {
79 // add boundary values to solution
80 constraints()( u, w, ConstraintsType::Operation::add );
81 }
82 void addConstraints( RangeFunctionType &w ) const
83 {
84 // add boundary values to solution
85 constraints()( w, ConstraintsType::Operation::add );
86 }
87 const auto &dirichletBlocks() const
88 {
89 return constraints().dirichletBlocks();
90 }
91
92 // return true if operator is based on nonlinear model
93 virtual bool nonlinear () const { return op_.nonlinear(); }
94
96 virtual void operator() ( const DomainFunctionType &u, RangeFunctionType &w ) const
97 {
98 op_(u,w);
99 subConstraints( u, w );
100 }
101 template <class GF>
102 auto operator()( const GF &u, RangeFunctionType &w ) const
104 {
105 op_(u,w);
106 subConstraints( u, w );
107 }
108
109 void jacobian ( const DomainFunctionType &u, JacobianOperatorType &jOp ) const
110 {
111 op_.jacobian(u,jOp);
112 constraints().applyToOperator( jOp );
113 jOp.flushAssembly();
114 }
115 template <class GridFunctionType>
116 auto jacobian ( const GridFunctionType &u, JacobianOperatorType &jOp ) const
118 {
119 op_.jacobian(u,jOp);
120 constraints().applyToOperator( jOp );
121 jOp.flushAssembly();
122 }
123
124 const DomainDiscreteFunctionSpaceType& domainSpace() const
125 {
126 return op_.domainSpace();
127 }
128 const RangeDiscreteFunctionSpaceType& rangeSpace() const
129 {
130 return op_.rangeSpace();
131 }
132
133 std::size_t gridSizeInterior () const
134 {
135 return op_.gridSizeInterior();
136 }
137
138 template <typename O = Operator>
139 auto setCommunicate ( const bool commuicate )
140 -> Dune::void_t< decltype( std::declval< O >().setCommunicate(true) ) >
141 {
142 op_.setCommunicate(commuicate);
143 }
144
145 template <typename O = Operator>
146 auto setQuadratureOrders(unsigned int interior, unsigned int surface)
147 -> Dune::void_t< decltype( std::declval< O >().setQuadratureOrders(0,0) ) >
148 {
149 return op_.setQuadratureOrders(interior,surface);
150 }
151
152 ModelType &model () const { return op_.model(); }
153 const ConstraintsType &constraints () const { return constraints_; }
154 const auto& impl() const { return op_.impl(); }
155
156
157private:
158 Operator op_;
159 ConstraintsType constraints_;
160};
161#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  |  generated with Hugo v0.111.3 (Nov 21, 23:30, 2024)