dune-fem  2.4.1-rc
spaceoperatorif.hh
Go to the documentation of this file.
1 #ifndef DUNE_FEM_SPACEOPERATORIF_HH
2 #define DUNE_FEM_SPACEOPERATORIF_HH
3 
4 //- system includes
5 #include <cassert>
6 #include <cstdlib>
7 #include <limits>
8 #include <utility>
9 
10 //-Dune fem includes
14 
15 namespace Dune
16 {
17 
18  namespace Fem
19  {
20 
27  template <class DestinationImp>
29  {
30  protected:
31  // only allow derived class to call this constructor
33 
34  public:
36  typedef DestinationImp DestinationType;
37 
40 
42  virtual int size () const = 0 ;
43 
47  virtual void initializeTimeStepSize ( const DestinationType& U0 ) const = 0;
48 
53  virtual void operator() ( const double *u, double *f ) const = 0;
54 
59  virtual void limit ( const double *u, double *f ) const { }
60 
65  virtual bool hasLimiter () const { return false ; }
66 
70  virtual void setTime ( const double time ) {}
71 
80  virtual double timeStepEstimate () const
81  {
83  }
84  };
85 
100  template< class DiscreteFunction >
102  : public Fem::AutomaticDifferenceOperator< DiscreteFunction >,
103  public PARDGSpaceOperatorInterface< DiscreteFunction >
104  {
107 
108  public:
110  typedef DiscreteFunction DestinationType;
111 
113  typedef typename DestinationType::DiscreteFunctionSpaceType SpaceType;
114 
115  protected:
116  template < class Op, class DF, class Field >
118  {
119  static inline void apply( const Op& op, const double* u, double* f )
120  {
121  std::cerr << "ERROR: SpaceOperatorInterface::operator()( const double*, double* ) only works for RangeFieldType double" << std::endl;
122  abort();
123  }
124 
125  static inline void limit( const Op& op, const double* u, double* f )
126  {
127  std::cerr << "ERROR: SpaceOperatorInterface::limit( const double*, double* ) only works for RangeFieldType double" << std::endl;
128  abort();
129  }
130  };
131 
132  // this only works if the DestinationType is AdaptiveDiscreteFunction and the
133  // DofType is double
134  template < class Op >
135  struct CallDoubleOperator< Op, AdaptiveDiscreteFunction< SpaceType >, double >
136  {
137  static inline void apply( const Op& op, const double* u, double* f )
138  {
139  typedef AdaptiveDiscreteFunction< SpaceType > Destination ;
140  // get space instance
141  const SpaceType &spc = op.space();
142 
143  // convert arguments to discrete function
144  const Destination arg( "SpaceOperatorIF::ARG", spc, u );
145  Destination dest( "SpaceOperatorIF::DEST", spc, f );
146 
147  // call operator apply
148  op( arg, dest );
149  }
150 
151  static inline void limit( const Op& op, const double* u, double* f )
152  {
153  typedef AdaptiveDiscreteFunction< SpaceType > Destination ;
154  // get space instance
155  const SpaceType &spc = op.space();
156 
157  // convert arguments to discrete function
158  const Destination arg( "SpaceOperatorIF::limitARG", spc, u );
159  Destination dest( "SpaceOperatorIF::limitDEST", spc, f );
160 
161  // call operator apply
162  op.limit( arg, dest );
163  }
164  };
165  public:
168 
169  using BaseType::operator ();
170 
172  virtual const SpaceType &space() const = 0;
173 
175  virtual int size () const { return space().size(); }
176 
177  //- \copydoc Dune::Fem::PARDGSpaceOperatorInterface::operator()(const double*,double*) const
182  virtual void operator() ( const double *u, double *f ) const;
183 
188  virtual void limit ( const double *u, double *f ) const;
189 
191  virtual bool hasLimiter () const { return false ; }
192 
197  virtual void limit (const DestinationType& arg, DestinationType& dest) const
198  {
199  // default operation is the identiy
200  dest.assign( arg );
201  }
202 
204  virtual void initializeTimeStepSize ( const DestinationType &U0 ) const;
205 
207  virtual const DestinationType* destination() const { return 0; }
208  };
209 
211  template <class OperatorType>
213  : public ObjPointerStorage
214  {
217  SpaceOperatorStorage& operator = (const SpaceOperatorStorage& org);
218 
219  protected:
220  // operator storage
221  mutable OperatorType* op_;
222  // model storage
224 
225  public:
227  SpaceOperatorStorage(OperatorType * op)
228  : op_(op), model_(0)
229  {}
230 
232  SpaceOperatorStorage(OperatorType * op, ObjPointerStorage* model)
233  : op_(op), model_(model)
234  {}
235 
238  {
239  // delete operator before destructor of base class is called
240  delete op_; op_ = 0;
241  delete model_; model_ = 0;
242  }
243 
245  OperatorType& pass() const
246  {
247  assert( op_ );
248  return (*op_);
249  }
250  };
251 
253  template <class OperatorType>
255  : public SpaceOperatorStorage< OperatorType >,
256  public SpaceOperatorInterface<typename OperatorType::DestinationType>
257  {
260 
261  protected:
262  // use pass method of base
263  using BaseType :: pass;
264  private:
265 
267  typedef typename OperatorType::DestinationType DestinationType;
268 
270  typedef typename DestinationType :: DiscreteFunctionSpaceType SpaceType;
271 
274  SpaceOperatorPtr& operator = (const SpaceOperatorPtr& org);
275 
276  public:
278  SpaceOperatorPtr(OperatorType * op)
279  : BaseType(op)
280  {}
281 
283  SpaceOperatorPtr(OperatorType * op, ObjPointerStorage* model)
284  : BaseType(op,model)
285  {}
286 
288  virtual ~SpaceOperatorPtr() {}
289 
291  virtual void operator () (const DestinationType& arg, DestinationType& dest) const
292  {
293  // this method should not be called
294  assert(false);
295  abort();
296  }
297 
299  const SpaceType& space() const { return pass().space(); }
300 
302  void setTime(const double time) { pass().setTime(time); }
303 
305  double timeStepEstimate () const { return pass().timeStepEstimate(); }
306 
308  const DestinationType* destination() const
309  {
310  pass().allocateLocalMemory();
311  return & (pass().destination());
312  }
313  };
314 
316  template <class OperatorType>
318  : public SpaceOperatorPtr< OperatorType >
319  {
322 
323  // use pass method of base
324  using BaseType :: pass;
325 
328  SpaceOperatorWrapper& operator = (const SpaceOperatorWrapper& org);
329  public:
331  typedef typename OperatorType::DestinationType DestinationType;
333  typedef typename DestinationType :: DiscreteFunctionSpaceType SpaceType;
334 
336  SpaceOperatorWrapper(OperatorType * op)
337  : BaseType(op)
338  {}
339 
341  SpaceOperatorWrapper(OperatorType * op, ObjPointerStorage* model)
342  : BaseType(op,model)
343  {}
344 
346  void operator () (const DestinationType& arg, DestinationType& dest) const
347  {
348  pass()(arg,dest);
349  }
350  };
351 
352 
353  // Implementation of SpaceOperatorInterface
354  // ----------------------------------------
355 
356  template< class DiscreteFunction >
358  ::operator() ( const double *u, double *f ) const
359  {
361  DiscreteFunction,
362  typename DiscreteFunction :: RangeFieldType >::apply( *this, u, f );
363  }
364 
365  template< class DiscreteFunction >
367  ::limit ( const double *u, double *f ) const
368  {
370  DiscreteFunction,
371  typename DiscreteFunction :: RangeFieldType >::limit( *this, u, f );
372  }
373 
374  template< class DiscreteFunction >
377  {
378  // create temporary variable
379  DestinationType tmp( U0 );
380  // call operator
381  (*this)( U0, tmp );
382  }
383 
384  } // namespace Fem
385 
386 } // namespace Dune
387 
388 #endif // #ifndef DUNE_FEM_SPACEOPERATORIF_HH
virtual void operator()(const double *u, double *f) const =0
application operator to apply right hand side
ODESpaceOperatorInterface for Operators that work with PARDG ODE solvers of the type where is a dis...
Definition: spaceoperatorif.hh:28
const DestinationType * destination() const
return reference to pass&#39;s local memory
Definition: spaceoperatorif.hh:308
operator providing a Jacobian through automatic differentiation
Definition: automaticdifferenceoperator.hh:22
apply wrapper
Definition: spaceoperatorif.hh:317
only for keeping the pointer
Definition: spaceoperatorif.hh:254
OperatorType * op_
Definition: spaceoperatorif.hh:221
DestinationType::DiscreteFunctionSpaceType SpaceType
type of discrete function space
Definition: spaceoperatorif.hh:113
SpaceOperatorStorage(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:232
SpaceOperatorPtr(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:283
static void apply(const Op &op, const double *u, double *f)
Definition: spaceoperatorif.hh:137
static constexpr T max(T a)
Definition: utility.hh:65
Definition: adaptivefunction/adaptivefunction.hh:34
SpaceOperatorStorage(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:227
virtual const DestinationType * destination() const
return reference to pass&#39;s local memory
Definition: spaceoperatorif.hh:207
DiscreteFunction DestinationType
type of argument and destination
Definition: spaceoperatorif.hh:110
virtual ~PARDGSpaceOperatorInterface()
destructor
Definition: spaceoperatorif.hh:39
virtual void limit(const DestinationType &arg, DestinationType &dest) const
limiter application operator
Definition: spaceoperatorif.hh:197
void setTime(const double time)
set time for operators
Definition: spaceoperatorif.hh:302
const SpaceType & space() const
return reference to space
Definition: spaceoperatorif.hh:299
virtual int size() const
return size of discrete function space, i.e. number of unknowns
Definition: spaceoperatorif.hh:175
virtual ~SpaceOperatorPtr()
destructor
Definition: spaceoperatorif.hh:288
virtual void initializeTimeStepSize(const DestinationType &U0) const
call operator once to calculate initial time step size
Definition: spaceoperatorif.hh:376
OperatorType & pass() const
return reference to pass
Definition: spaceoperatorif.hh:245
virtual ~SpaceOperatorInterface()
destructor
Definition: spaceoperatorif.hh:167
ObjPointerStorage * model_
Definition: spaceoperatorif.hh:223
abstract operator
Definition: operator.hh:25
Definition: objpointer.hh:37
interface for time evolution operators
Definition: spaceoperatorif.hh:101
virtual void limit(const double *u, double *f) const
apply limiter to u and store result in f
Definition: spaceoperatorif.hh:59
static void limit(const Op &op, const double *u, double *f)
Definition: spaceoperatorif.hh:125
DestinationType::DiscreteFunctionSpaceType SpaceType
type of discrete function space
Definition: spaceoperatorif.hh:333
SpaceOperatorWrapper(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:336
Definition: coordinate.hh:4
virtual bool hasLimiter() const
return true if explicit limiter is available
Definition: spaceoperatorif.hh:191
SpaceOperatorWrapper(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:341
PARDGSpaceOperatorInterface()
Definition: spaceoperatorif.hh:32
double timeStepEstimate() const
estimate maximum time step
Definition: spaceoperatorif.hh:305
virtual int size() const =0
return size of discrete function space, i.e. number of unknowns
SpaceOperatorPtr(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:278
virtual double timeStepEstimate() const
estimate maximum time step
Definition: spaceoperatorif.hh:80
virtual void setTime(const double time)
set time for operators
Definition: spaceoperatorif.hh:70
static void limit(const Op &op, const double *u, double *f)
Definition: spaceoperatorif.hh:151
DestinationImp DestinationType
type of argument and destination
Definition: spaceoperatorif.hh:36
virtual void limit(const double *u, double *f) const
limiter application operator
Definition: spaceoperatorif.hh:367
virtual void initializeTimeStepSize(const DestinationType &U0) const =0
call operator once to calculate initial time step size
~SpaceOperatorStorage()
destructor deletes operator
Definition: spaceoperatorif.hh:237
static void apply(const Op &op, const double *u, double *f)
Definition: spaceoperatorif.hh:119
virtual bool hasLimiter() const
return true if limit method is implemented
Definition: spaceoperatorif.hh:65
virtual void operator()(const double *u, double *f) const
application operator to apply right hand side
Definition: spaceoperatorif.hh:358
only for keeping the pointer
Definition: spaceoperatorif.hh:212
const DiscreteFunctionSpaceType & space() const
obtain a reference to the corresponding DiscreteFunctionSpace
Definition: discretefunction.hh:704
OperatorType::DestinationType DestinationType
type of Argument and Destination
Definition: spaceoperatorif.hh:331