DUNE-FEM (unstable)

operator.hh
1 #ifndef DUNE_FEM_OPERATOR_HH
2 #define DUNE_FEM_OPERATOR_HH
3 
4 #include <cassert>
5 #include <typeindex>
6 #include <cassert>
7 
9 
10 #include <dune/fem/version.hh>
12 #include <dune/fem/operator/common/mapping.hh>
13 
14 namespace Dune
15 {
16 
17  namespace Fem
18  {
19 
32  template< class DomainFunction, class RangeFunction = DomainFunction >
33  struct Operator
34  {
36  typedef DomainFunction DomainFunctionType;
38  typedef RangeFunction RangeFunctionType;
39 
41  typedef typename DomainFunction::RangeFieldType DomainFieldType;
43  typedef typename RangeFunction::RangeFieldType RangeFieldType;
44 
45  virtual ~Operator ()
46  {}
47 
55  virtual void operator() ( const DomainFunctionType &u, RangeFunctionType &w ) const = 0;
56 
61  virtual void finalize () {}
62  };
63 
84  template< class DomainFunction, class RangeFunction = DomainFunction >
86  : public virtual Operator<DomainFunction, RangeFunction>
87  {
89  virtual bool symmetric() const
90  {
91  return false;
92  }
94  virtual bool positiveDefinite() const
95  {
96  return false;
97  }
98  };
99 
121  template< class DomainFunction, class RangeFunction = DomainFunction >
123  : public virtual LinearOperator<DomainFunction, RangeFunction>
124  {
125  public:
127  virtual void flushAssembly() {}
128 
132  template< class AssembleOperation >
134  {
135  const std::type_index id( typeid( AssembleOperation ) );
136  if( assembleOperation_ != id )
137  {
138  if( assembleOperation_ != std::type_index( typeid( void ) ) )
139  DUNE_THROW( InvalidStateException, "Another assemble operation in progress" );
140  assembleOperation_ = id;
141  assert( assembleCount_ == 0 );
142  AssembleOperation::begin( *this );
143  }
144  ++assembleCount_;
145  }
146 
150  template< class AssembleOperation >
151  void endAssemble ()
152  {
153  const std::type_index id( typeid( AssembleOperation ) );
154  if( assembleOperation_ != id )
155  DUNE_THROW( InvalidStateException, "Assemble operation not in progress" );
156  assert( assembleCount_ > 0 );
157  if( --assembleCount_ == 0 )
158  {
159  AssembleOperation::end( *this );
160  assembleOperation_ = std::type_index( typeid( void ) );
161  }
162  }
163 
164  protected:
165  std::type_index assembleOperation_ = std::type_index( typeid( void ) );
166  std::size_t assembleCount_ = 0;
167  };
168 
169 
170  // Is*Operator
171  // -----------
172 
173  namespace Impl
174  {
175 
176  template< class T >
177  using DomainFunctionType_t = typename T::DomainFunctionType;
178 
179  template< class T >
180  using RangeFunctionType_t = typename T::RangeFunctionType;
181 
182  template< class T >
183  using IsOperatorImpl = std::is_base_of< ::Dune::Fem::Operator< DomainFunctionType_t< T >, RangeFunctionType_t< T > >, T >;
184 
185  template< class T >
186  using IsLinearOperatorImpl = std::is_base_of< ::Dune::Fem::LinearOperator< DomainFunctionType_t< T >, RangeFunctionType_t< T > >, T >;
187 
188  template< class T >
189  using IsAssembledOperatorImpl = std::is_base_of< ::Dune::Fem::AssembledOperator< DomainFunctionType_t< T >, RangeFunctionType_t< T > >, T >;
190 
191  } // namespace Impl
192 
193  template< class T >
194  using IsOperator = Impl::IsOperatorImpl< std::decay_t< T > >;
195 
196  template< class T >
197  using IsLinearOperator = Impl::IsOperatorImpl< std::decay_t< T > >;
198 
199  template< class T >
200  using IsAssembledOperator = Impl::IsAssembledOperatorImpl< std::decay_t< T > >;
201 
202  } // namespace Fem
203 
204 
205 
224  template <typename DFieldType, typename RFieldType,
225  typename DType , typename RType>
226  class Operator
227  : public Fem::Mapping < DFieldType, RFieldType, DType, RType >,
228  public virtual Fem::Operator< DType, RType >
229  {
231 
232  protected:
235 
236  public:
237  //- remember template parameters for derived classes
238  typedef DType DomainType;
239  typedef RType RangeType;
240  typedef DFieldType DomainFieldType;
241  typedef RFieldType RangeFieldType;
242 
243  using BaseType::operator();
244  using BaseType::finalize;
245 
246  protected:
253  virtual void apply (const DomainType& arg, RangeType& dest) const
254  {
255  this->operator() (arg, dest);
256  }
257  }; // class Operator
258 
260 
261 } // namespace Dune
262 
263 #endif // #ifndef DUNE_FEM_OPERATOR_HH
abstract matrix operator
Definition: operator.hh:124
virtual void flushAssembly()
commit intermediate states of linear operator assembly
Definition: operator.hh:127
void beginAssemble()
Initiate the assemble of values using the LocalContribution concept.
Definition: operator.hh:133
void endAssemble()
Finalize the assemble of values using the LocalContribution concept.
Definition: operator.hh:151
A mapping from one vector space into another This class describes a general mapping from the domain v...
Definition: mapping.hh:47
DFieldType DomainFieldType
type of field the domain vector space, i.e. double
Definition: mapping.hh:66
RFieldType RangeFieldType
type of field the range vector space, i.e. double
Definition: mapping.hh:69
DType DomainType
domain vector space (for usage in derived classes) This can either be for example a discrete function...
Definition: mapping.hh:57
RType RangeType
range vector space (for usage in derived classes) This can either be for example a discrete function ...
Definition: mapping.hh:63
void operator()(const DomainType &arg, RangeType &dest) const
Application operator that applies all operators in the linear combination stack.
Definition: mapping.hh:112
Default exception if a function was called while the object is not in a valid state for that function...
Definition: exceptions.hh:281
An abstract operator Interface class for Operators. Operators are applied to Functions and the result...
Definition: operator.hh:229
virtual void apply(const DomainType &arg, RangeType &dest) const
The method apply calls the application operator. The method has to be implemented here,...
Definition: operator.hh:253
Fem::Mapping< DFieldType, RFieldType, DType, RType > MappingType
type of mapping base class
Definition: operator.hh:234
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Dune namespace.
Definition: alignedallocator.hh:13
abstract affine-linear operator
Definition: operator.hh:87
virtual bool symmetric() const
Definition: operator.hh:89
virtual bool positiveDefinite() const
Definition: operator.hh:94
abstract operator
Definition: operator.hh:34
virtual void finalize()
finalization of operator
Definition: operator.hh:61
DomainFunction DomainFunctionType
type of discrete function in the operator's domain
Definition: operator.hh:36
RangeFunction::RangeFieldType RangeFieldType
field type of the operator's range
Definition: operator.hh:43
virtual void operator()(const DomainFunctionType &u, RangeFunctionType &w) const =0
application operator
DomainFunction::RangeFieldType DomainFieldType
field type of the operator's domain
Definition: operator.hh:41
RangeFunction RangeFunctionType
type of discrete function in the operator's range
Definition: operator.hh:38
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 9, 22:29, 2024)