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, typename Operator::RangeDiscreteFunctionSpaceType >
24 >
25struct DirichletWrapperOperator
26: public Dune::Fem::DifferentiableOperator< typename Operator::JacobianOperatorType >
27{
28 typedef typename Operator::DomainFunctionType DomainFunctionType;
29 typedef typename Operator::RangeFunctionType RangeFunctionType;
30 typedef typename Operator::ModelType ModelType;
31 typedef typename Operator::DirichletModelType DirichletModelType;
32 typedef typename DomainFunctionType::DiscreteFunctionSpaceType DomainDiscreteFunctionSpaceType;
33 typedef typename RangeFunctionType::DiscreteFunctionSpaceType RangeDiscreteFunctionSpaceType;
34 typedef typename Operator::JacobianOperatorType JacobianOperatorType;
35 typedef typename RangeDiscreteFunctionSpaceType::RangeType DomainRangeType;
36 typedef Constraints ConstraintsType;
37 typedef typename ConstraintsType::DirichletBlockVector DirichletBlockVector;
38
39 template <class... Args>
40 DirichletWrapperOperator ( Args&... args )
41 : op_( std::forward<Args&>(args)... ) , constraints_( op_.model(), op_.rangeSpace() )
42 {}
43
44 void setConstraints( DomainFunctionType &u ) const
45 {
46 // set boundary values for solution from model
47 constraints()( u );
48 }
49 void setConstraints( const DomainRangeType &value, DomainFunctionType &u ) const
50 {
51 // set values for solution to a given constant value
52 constraints()( value, u );
53 }
54 template <class GF>
55 void setConstraints( const GF &u, RangeFunctionType &w ) const
56 {
57 // set boundary values for solution from a general grid function
58 constraints()( u, w, ConstraintsType::Operation::set );
59 }
60 template <class GF>
61 void subConstraints( const GF &u, RangeFunctionType &w ) const
62 {
63 // subtract boundary values from solution
64 constraints()( u, w, ConstraintsType::Operation::sub );
65 }
66 void subConstraints( RangeFunctionType &w ) const
67 {
68 // subtract boundary values from solution
69 constraints()( w, ConstraintsType::Operation::sub );
70 }
71 template <class GF>
72 void addConstraints( const GF &u, RangeFunctionType &w ) const
73 {
74 // add boundary values to solution
75 constraints()( u, w, ConstraintsType::Operation::add );
76 }
77 void addConstraints( RangeFunctionType &w ) const
78 {
79 // add boundary values to solution
80 constraints()( w, ConstraintsType::Operation::add );
81 }
82 const auto &dirichletBlocks() const
83 {
84 return constraints().dirichletBlocks();
85 }
86
87 // return true if operator is based on nonlinear model
88 virtual bool nonlinear () const { return op_.nonlinear(); }
89
91 virtual void operator() ( const DomainFunctionType &u, RangeFunctionType &w ) const
92 {
93 op_(u,w);
94 subConstraints( u, w );
95 }
96 template <class GF>
97 auto operator()( const GF &u, RangeFunctionType &w ) const
99 {
100 op_(u,w);
101 subConstraints( u, w );
102 }
103
104 void jacobian ( const DomainFunctionType &u, JacobianOperatorType &jOp ) const
105 {
106 op_.jacobian(u,jOp);
107 constraints().applyToOperator( jOp );
108 jOp.flushAssembly();
109 }
110 template <class GridFunctionType>
111 auto jacobian ( const GridFunctionType &u, JacobianOperatorType &jOp ) const
113 {
114 op_.jacobian(u,jOp);
115 constraints().applyToOperator( jOp );
116 jOp.flushAssembly();
117 }
118
119 const DomainDiscreteFunctionSpaceType& domainSpace() const
120 {
121 return op_.domainSpace();
122 }
123 const RangeDiscreteFunctionSpaceType& rangeSpace() const
124 {
125 return op_.rangeSpace();
126 }
127
128 std::size_t gridSizeInterior () const
129 {
130 return op_.gridSizeInterior();
131 }
132
133 template <typename O = Operator>
134 auto setCommunicate ( const bool commuicate )
135 -> Dune::void_t< decltype( std::declval< O >().setCommunicate(true) ) >
136 {
137 op_.setCommunicate(commuicate);
138 }
139
140 template <typename O = Operator>
141 auto setQuadratureOrders(unsigned int interior, unsigned int surface)
142 -> Dune::void_t< decltype( std::declval< O >().setQuadratureOrders(0,0) ) >
143 {
144 return op_.setQuadratureOrders(interior,surface);
145 }
146
147 ModelType &model () const { return op_.model(); }
148 const ConstraintsType &constraints () const { return constraints_; }
149 const auto& impl() const { return op_.impl(); }
150
151
152private:
153 Operator op_;
154 ConstraintsType constraints_;
155};
156#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 (Jul 27, 22:29, 2024)