dune-fem  2.8-git
dirichletwrapper.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_DIRICHLETWRAPPER_HH
2 #define DUNE_FEM_DIRICHLETWRAPPER_HH
3 
4 #include <cstddef>
5 
6 #include <dune/common/fmatrix.hh>
7 
11 
15 
17 
19 #include <dune/fem/io/parameter.hh>
20 
21 
22 template< class Operator,
24  >
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 
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
65  }
66  const auto &dirichletBlocks() const
67  {
68  return constraints().dirichletBlocks();
69  }
70 
72  virtual void operator() ( const DomainFunctionType &u, RangeFunctionType &w ) const
73  {
74  op_(u,w);
75  subConstraints( u, w );
76  }
77  template <class GF>
78  auto operator()( const GF &u, RangeFunctionType &w ) const
79  -> Dune::void_t<decltype(std::declval<const Operator&>()(u,w))>
80  {
81  op_(u,w);
82  subConstraints( u, w );
83  }
84 
85  void jacobian ( const DomainFunctionType &u, JacobianOperatorType &jOp ) const
86  {
87  op_.jacobian(u,jOp);
88  constraints().applyToOperator( jOp );
89  jOp.flushAssembly();
90  }
91  template <class GridFunctionType>
92  auto jacobian ( const GridFunctionType &u, JacobianOperatorType &jOp ) const
93  -> Dune::void_t<decltype(std::declval<const Operator&>().jacobian(u,jOp))>
94  {
95  op_.jacobian(u,jOp);
96  constraints().applyToOperator( jOp );
97  jOp.flushAssembly();
98  }
99 
101  {
102  return op_.domainSpace();
103  }
105  {
106  return op_.rangeSpace();
107  }
108 
109  template <typename O = Operator>
110  auto setCommunicate ( const bool commuicate )
111  -> Dune::void_t< decltype( std::declval< O >().setCommunicate(true) ) >
112  {
113  op_.setCommunicate(commuicate);
114  }
115 
116  template <typename O = Operator>
117  auto setQuadratureOrders(unsigned int interior, unsigned int surface)
118  -> Dune::void_t< decltype( std::declval< O >().setQuadratureOrders(0,0) ) >
119  {
120  return op_.setQuadratureOrders(interior,surface);
121  }
122 
123  ModelType &model () const { return op_.model(); }
124  const ConstraintsType &constraints () const { return constraints_; }
125 
126 private:
127  Operator op_;
128  ConstraintsType constraints_;
129 };
130 #endif // #ifndef DUNE_FEM_CONSTRAINTSWRAPPER_HH
static constexpr T sub(T a)
Definition: utility.hh:61
abstract differentiable operator
Definition: differentiableoperator.hh:29
Definition: dirichletwrapper.hh:27
void setConstraints(const GF &u, RangeFunctionType &w) const
Definition: dirichletwrapper.hh:55
DirichletWrapperOperator(Args &... args)
Definition: dirichletwrapper.hh:40
auto operator()(const GF &u, RangeFunctionType &w) const -> Dune::void_t< decltype(std::declval< const Operator & >()(u, w))>
Definition: dirichletwrapper.hh:78
ModelType & model() const
Definition: dirichletwrapper.hh:123
auto jacobian(const GridFunctionType &u, JacobianOperatorType &jOp) const -> Dune::void_t< decltype(std::declval< const Operator & >().jacobian(u, jOp))>
Definition: dirichletwrapper.hh:92
Operator::JacobianOperatorType JacobianOperatorType
Definition: dirichletwrapper.hh:34
void subConstraints(const GF &u, RangeFunctionType &w) const
Definition: dirichletwrapper.hh:61
Operator::DirichletModelType DirichletModelType
Definition: dirichletwrapper.hh:31
RangeFunctionType::DiscreteFunctionSpaceType RangeDiscreteFunctionSpaceType
Definition: dirichletwrapper.hh:33
const RangeDiscreteFunctionSpaceType & rangeSpace() const
Definition: dirichletwrapper.hh:104
void setConstraints(const DomainRangeType &value, DomainFunctionType &u) const
Definition: dirichletwrapper.hh:49
const auto & dirichletBlocks() const
Definition: dirichletwrapper.hh:66
auto setCommunicate(const bool commuicate) -> Dune::void_t< decltype(std::declval< O >().setCommunicate(true)) >
Definition: dirichletwrapper.hh:110
const ConstraintsType & constraints() const
Definition: dirichletwrapper.hh:124
Operator::RangeFunctionType RangeFunctionType
Definition: dirichletwrapper.hh:29
virtual void operator()(const DomainFunctionType &u, RangeFunctionType &w) const
application operator
Definition: dirichletwrapper.hh:72
RangeDiscreteFunctionSpaceType::RangeType DomainRangeType
Definition: dirichletwrapper.hh:35
ConstraintsType::DirichletBlockVector DirichletBlockVector
Definition: dirichletwrapper.hh:37
auto setQuadratureOrders(unsigned int interior, unsigned int surface) -> Dune::void_t< decltype(std::declval< O >().setQuadratureOrders(0, 0)) >
Definition: dirichletwrapper.hh:117
DomainFunctionType::DiscreteFunctionSpaceType DomainDiscreteFunctionSpaceType
Definition: dirichletwrapper.hh:32
Operator::ModelType ModelType
Definition: dirichletwrapper.hh:30
const DomainDiscreteFunctionSpaceType & domainSpace() const
Definition: dirichletwrapper.hh:100
void setConstraints(DomainFunctionType &u) const
Definition: dirichletwrapper.hh:44
Constraints ConstraintsType
Definition: dirichletwrapper.hh:36
void jacobian(const DomainFunctionType &u, JacobianOperatorType &jOp) const
Definition: dirichletwrapper.hh:85
Operator::DomainFunctionType DomainFunctionType
Definition: dirichletwrapper.hh:28