DUNE-FEM (unstable)

spaceoperatorif.hh
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
11 #include <dune/fem/operator/common/automaticdifferenceoperator.hh>
12 #include <dune/fem/operator/common/objpointer.hh>
13 #include <dune/fem/function/adaptivefunction.hh>
14 
15 namespace Dune
16 {
17 
18  namespace Fem
19  {
34  template< class DiscreteFunction,
35  class JacobianOperator = Fem::AutomaticDifferenceOperator< DiscreteFunction > >
37  : public JacobianOperator
38  {
41 
42  public:
44  typedef DiscreteFunction DestinationType;
45 
47  typedef typename DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType;
50 
53 
54  using BaseType::operator ();
55 
57  virtual const DiscreteFunctionSpaceType& space() const = 0;
58 
60  virtual int size () const { return space().size(); }
61 
65  virtual void initializeTimeStepSize ( const DestinationType& U0 ) const;
66 
71  virtual bool hasLimiter () const { return false ; }
72 
76  virtual void setTime ( const double time ) {}
77 
86  virtual double timeStepEstimate () const
87  {
89  }
90 
97  virtual void limit (const DestinationType& arg, DestinationType& dest) const
98  {
99  // if this method is not overloaded then hasLimiter should return false
100  assert( ! hasLimiter () );
101  // default operation is copy arg to dest
102  dest.assign( arg );
103  }
104 
110  virtual void applyLimiter ( DestinationType& U ) const
111  {
112  if( hasLimiter() )
113  {
114  if( ! uTmp_ )
115  uTmp_.reset( new DestinationType( "SpaceOpIF::uTmp_", space() ) );
116 
117  assert( uTmp_ );
118  uTmp_->assign( U );
119  limit( *uTmp_, U );
120  }
121  }
122 
124  virtual const DestinationType* destination() const { return nullptr; }
125 
126  protected:
127  mutable std::unique_ptr< DestinationType > uTmp_;
128  };
129 
131  template <class OperatorType>
133  : public ObjPointerStorage
134  {
137  SpaceOperatorStorage& operator = (const SpaceOperatorStorage& org);
138 
139  protected:
140  // operator storage
141  mutable OperatorType* op_;
142  // model storage
143  ObjPointerStorage* model_;
144 
145  public:
147  SpaceOperatorStorage(OperatorType * op)
148  : op_(op), model_(0)
149  {}
150 
152  SpaceOperatorStorage(OperatorType * op, ObjPointerStorage* model)
153  : op_(op), model_(model)
154  {}
155 
158  {
159  // delete operator before destructor of base class is called
160  delete op_; op_ = 0;
161  delete model_; model_ = 0;
162  }
163 
165  OperatorType& pass() const
166  {
167  assert( op_ );
168  return (*op_);
169  }
170  };
171 
173  template <class OperatorType>
175  : public SpaceOperatorStorage< OperatorType >,
176  public SpaceOperatorInterface<typename OperatorType::DestinationType>
177  {
180 
181  protected:
182  // use pass method of base
183  using BaseType :: pass;
184  private:
185 
187  typedef typename OperatorType::DestinationType DestinationType;
188 
190  typedef typename DestinationType :: DiscreteFunctionSpaceType SpaceType;
191 
194  SpaceOperatorPtr& operator = (const SpaceOperatorPtr& org);
195 
196  public:
198  SpaceOperatorPtr(OperatorType * op)
199  : BaseType(op)
200  {}
201 
203  SpaceOperatorPtr(OperatorType * op, ObjPointerStorage* model)
204  : BaseType(op,model)
205  {}
206 
208  virtual ~SpaceOperatorPtr() {}
209 
211  virtual void operator () (const DestinationType& arg, DestinationType& dest) const
212  {
213  // this method should not be called
214  assert(false);
215  abort();
216  }
217 
219  const SpaceType& space() const { return pass().space(); }
220 
222  void setTime(const double time) { pass().setTime(time); }
223 
225  double timeStepEstimate () const { return pass().timeStepEstimate(); }
226 
228  const DestinationType* destination() const
229  {
230  pass().allocateLocalMemory();
231  return & (pass().destination());
232  }
233  };
234 
236  template <class OperatorType>
238  : public SpaceOperatorPtr< OperatorType >
239  {
242 
243  // use pass method of base
244  using BaseType :: pass;
245 
248  SpaceOperatorWrapper& operator = (const SpaceOperatorWrapper& org);
249  public:
251  typedef typename OperatorType::DestinationType DestinationType;
253  typedef typename DestinationType :: DiscreteFunctionSpaceType SpaceType;
254 
256  SpaceOperatorWrapper(OperatorType * op)
257  : BaseType(op)
258  {}
259 
261  SpaceOperatorWrapper(OperatorType * op, ObjPointerStorage* model)
262  : BaseType(op,model)
263  {}
264 
266  void operator () (const DestinationType& arg, DestinationType& dest) const
267  {
268  pass()(arg,dest);
269  }
270  };
271 
272 
273  // Implementation of SpaceOperatorInterface
274  // ----------------------------------------
275 
276  template< class DiscreteFunction, class JacobianOperator >
279  {
280  // create temporary variable
281  DestinationType tmp( U0 );
282  // call operator
283  (*this)( U0, tmp );
284  }
285 
286  } // namespace Fem
287 
288 } // namespace Dune
289 
290 #endif // #ifndef DUNE_FEM_SPACEOPERATORIF_HH
Definition: objpointer.hh:42
interface for time evolution operators
Definition: spaceoperatorif.hh:38
virtual ~SpaceOperatorInterface()
destructor
Definition: spaceoperatorif.hh:52
DestinationType::DiscreteFunctionSpaceType DiscreteFunctionSpaceType
type of discrete function space
Definition: spaceoperatorif.hh:47
virtual void applyLimiter(DestinationType &U) const
limiter application operator
Definition: spaceoperatorif.hh:110
virtual void setTime(const double time)
set time for operators
Definition: spaceoperatorif.hh:76
DiscreteFunctionSpaceType SpaceType
convenience typedef for space type
Definition: spaceoperatorif.hh:49
virtual void limit(const DestinationType &arg, DestinationType &dest) const
limiter application operator
Definition: spaceoperatorif.hh:97
virtual const DiscreteFunctionSpaceType & space() const =0
return reference to space (needed by ode solvers)
virtual bool hasLimiter() const
return true if limit method is implemented
Definition: spaceoperatorif.hh:71
virtual int size() const
return size of discrete function space, i.e. number of unknowns
Definition: spaceoperatorif.hh:60
virtual const DestinationType * destination() const
return reference to pass's local memory
Definition: spaceoperatorif.hh:124
virtual void initializeTimeStepSize(const DestinationType &U0) const
call operator once to calculate initial time step size
Definition: spaceoperatorif.hh:278
virtual double timeStepEstimate() const
estimate maximum time step
Definition: spaceoperatorif.hh:86
DiscreteFunction DestinationType
type of argument and destination
Definition: spaceoperatorif.hh:44
only for keeping the pointer
Definition: spaceoperatorif.hh:177
virtual void operator()(const DestinationType &arg, DestinationType &dest) const
application operator does nothing here
Definition: spaceoperatorif.hh:211
SpaceOperatorPtr(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:203
const SpaceType & space() const
return reference to space
Definition: spaceoperatorif.hh:219
SpaceOperatorPtr(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:198
virtual ~SpaceOperatorPtr()
destructor
Definition: spaceoperatorif.hh:208
const DestinationType * destination() const
return reference to pass's local memory
Definition: spaceoperatorif.hh:228
void setTime(const double time)
set time for operators
Definition: spaceoperatorif.hh:222
double timeStepEstimate() const
estimate maximum time step
Definition: spaceoperatorif.hh:225
only for keeping the pointer
Definition: spaceoperatorif.hh:134
SpaceOperatorStorage(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:147
OperatorType & pass() const
return reference to pass
Definition: spaceoperatorif.hh:165
SpaceOperatorStorage(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:152
~SpaceOperatorStorage()
destructor deletes operator
Definition: spaceoperatorif.hh:157
apply wrapper
Definition: spaceoperatorif.hh:239
SpaceOperatorWrapper(OperatorType *op, ObjPointerStorage *model)
constructor storing pointer
Definition: spaceoperatorif.hh:261
OperatorType::DestinationType DestinationType
type of Argument and Destination
Definition: spaceoperatorif.hh:251
DestinationType ::DiscreteFunctionSpaceType SpaceType
type of discrete function space
Definition: spaceoperatorif.hh:253
SpaceOperatorWrapper(OperatorType *op)
constructor storing pointer
Definition: spaceoperatorif.hh:256
void operator()(const DestinationType &arg, DestinationType &dest) const
call application operator of internal operator
Definition: spaceoperatorif.hh:266
constexpr auto max
Function object that returns the greater of the given values.
Definition: hybridutilities.hh:484
Dune namespace.
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 15, 22:30, 2024)