DUNE-ACFEM (2.5.1)

probleminterface.hh
1 #ifndef _DUNE_ACFEM_POISSON_PROBLEMINTERFACE_HH_
2 #define _DUNE_ACFEM_POISSON_PROBLEMINTERFACE_HH_
3 
4 #include <cassert>
5 #include <cmath>
6 
7 #include <dune/common/exceptions.hh>
8 #include <dune/fem/function/common/function.hh>
9 #include "timeview.hh"
10 
11 namespace Dune {
12 
13  namespace ACFem {
14 
62  template <class FunctionSpace>
64  {
65  public:
66  // type of function space
67  typedef FunctionSpace FunctionSpaceType;
68 
69  enum { dimRange = FunctionSpaceType::dimRange };
70  enum { dimDomain = FunctionSpaceType::dimDomain };
71 
72  typedef typename FunctionSpaceType::RangeFieldType RangeFieldType;
73 
74  typedef typename FunctionSpaceType::RangeType RangeType;
75  typedef typename FunctionSpaceType::DomainType DomainType;
76 
77  typedef typename FunctionSpaceType::JacobianRangeType JacobianRangeType;
78  typedef typename FunctionSpaceType::HessianRangeType HessianRangeType;
79 
80  enum OperatorParts {
81  SecondOrderCoefficient,
82  FirstOrderCoefficient,
83  ZeroOrderCoefficient,
84  RightHandSide,
85  DirichletBoundary,
86  NeumannBoundary,
87  RobinBoundary,
88  ExactSolution,
89  };
90  typedef enum OperatorParts OperatorPartsType;
91 
92  virtual ~ProblemInterface() {}
93 
104  virtual bool has(OperatorPartsType what) const
105  {
106  switch (what) {
107  case SecondOrderCoefficient: return true;
108  case FirstOrderCoefficient: return false;
109  case ZeroOrderCoefficient: return false;
110  case RightHandSide: return true;
111  case DirichletBoundary: return true;
112  case NeumannBoundary: return false;
113  case RobinBoundary: return false;
114  case ExactSolution: return true;
115  }
116  return false;
117  }
118 
120  virtual void f(const DomainType& x,
121  RangeType& value) const
122  {
123  value = 0;
124  }
125 
127  virtual void u(const DomainType& x,
128  RangeType& value) const
129  {
130  value = 0;
131  }
132 
134  virtual void uJacobian(const DomainType& x,
135  JacobianRangeType& value) const
136  {
137  value = 0;
138  }
139 
150  virtual bool isDirichletSegment(const int bndId, const DomainType& center) const {
151  return true;
152  }
153 
165  virtual bool isNeumannSegment(const int bndId, const DomainType& center) const {
166  return false;
167  }
168 
180  virtual bool isRobinSegment(const int bndId, const DomainType& center) const {
181  return false;
182  }
183 
190  virtual void dirichletData(const DomainType& x,
191  RangeType& value) const
192  {
193  u(x, value);
194  }
195 
203  virtual void neumannData(const DomainType& x,
204  RangeType& value) const
205  {
206  value = 0;
207  }
208 
224  virtual void robinData(const DomainType& x,
225  const RangeType& u,
226  RangeType& value) const
227  {
228  value = 0;
229  }
230 
231 
232 
244  virtual void secondOrderCoefficient(const DomainType& x,
245  const JacobianRangeType& gradient,
246  JacobianRangeType& result) const
247  {
248  // default implementation is Laplace
249  result = gradient ;
250  }
251 
265  virtual void secondOrderCoefficient(const DomainType &x,
266  const JacobianRangeType &Du,
267  const HessianRangeType &D2u,
268  RangeType &result) const
269  {
270  // default implementation is Laplace
271  for (int i = 0; i < dimRange; ++i) {
272  result[i] = 0;
273  for (int j = 0; j < dimDomain; ++j) {
274  result[i] -= D2u[i][j][j];
275  }
276  }
277  }
278 
293  virtual void firstOrderCoefficient(const DomainType& x,
294  const RangeType& u,
295  const JacobianRangeType& Du,
296  RangeType& result) const
297  {
298  result = 0;
299  }
300 
301 
309  virtual void zeroOrderCoefficient(const DomainType& x,
310  const RangeType& u,
311  RangeType& result) const
312  {
313  result = 0;
314  }
315 
316  enum FunctionId { exact, rhs, dirichlet, neumann };
317 
318  template <FunctionId id>
319  class FunctionWrapper : public Dune::Fem::Function<FunctionSpaceType, FunctionWrapper<id> >
320  {
321  const ProblemInterface& impl_;
322 
323  public:
324  FunctionWrapper(const ProblemInterface& impl)
325  : impl_(impl)
326  {
327  //std::cout << "ctor impl: " << impl_ << " " << &impl_ << " " << this << std::endl;
328  }
329 
331  void evaluate(const DomainType& x, RangeType& ret) const
332  {
333  //std::cout << "eval impl: " << impl_ << " " << &impl_ << " " << this << std::endl;
334  switch (id) {
335  case exact: // call exact solution of implementation
336  impl_.u(x, ret);
337  break;
338  case rhs: // call right hand side of implementation
339  impl_.f(x, ret);
340  break;
341  case dirichlet: // call dirichlet boudary data of implementation
342  impl_.dirichletData(x, ret);
343  break;
344  case neumann: // call neumann boundary data of implementation
345  impl_.neumannData(x, ret);
346  break;
347  default:
348  DUNE_THROW(Dune::NotImplemented,"FunctionId not implemented");
349  break;
350  }
351  }
352 
354  void jacobian(const DomainType& x, JacobianRangeType& jac) const
355  {
356  switch (id) {
357  case exact:
358  impl_.uJacobian(x, jac);
359  break;
360  default:
361  DUNE_THROW(Dune::NotImplemented,"Jacobian for FunctionId not implemented");
362  break;
363  }
364  }
365  };
366 
367  typedef FunctionWrapper<exact> ExactSolutionType;
368  // return Fem::Function for exact solution
369  ExactSolutionType exactSolution() const
370  {
371  return ExactSolutionType(*this);
372  }
373 
374  typedef FunctionWrapper<rhs> RightHandSideType;
375  // return Fem::Function for right hand side
376  RightHandSideType rightHandSide() const
377  {
378  return RightHandSideType(*this);
379  }
380 
381  typedef FunctionWrapper<dirichlet> DirichletBoundaryType;
382  // return Fem::Function for Dirichlet boundary values
383  DirichletBoundaryType dirichletBoundary() const
384  {
385  return DirichletBoundaryType(*this);
386  }
387 
388  typedef FunctionWrapper<neumann> NeumannBoundaryType;
389  // return Fem::Function for Neumann boundary values
390  NeumannBoundaryType neumannBoundary() const
391  {
392  return NeumannBoundaryType(*this);
393  }
394  };
395 
400  template <class FunctionSpace, class TimeProvider>
402  : public ProblemInterface<FunctionSpace>
403  {
406  public:
407  typedef FunctionSpace FunctionSpaceType;
408  typedef TimeProvider TimeProviderType;
410 
412  TransientProblemInterface(const TimeProviderType& timeProvider, double theta = 0.0)
413  : timeView_(timeProvider, theta)
414  {}
415 
416  typedef typename BaseType::ExactSolutionType InitialValueType;
417 
418  // return Fem::Function for initial
419  InitialValueType initialValue() const
420  {
421  return InitialValueType(*this);
422  }
423 
425  double time() const
426  {
427  return timeView_.time();
428  }
429 
431  double deltaT() const
432  {
433  return timeView_.deltaT() ;
434  }
435 
437  const TimeViewType& timeView() const
438  {
439  return timeView_;
440  }
441 
444  {
445  return timeView_;
446  }
447  protected:
448  TimeViewType timeView_;
449  };
450 
452 
454 
455  } // ACFem::
456 
457 } // Dune::
458 
459 #endif // #ifndef ELLIPTC_PROBLEMINTERFACE_HH
460 
Problem interface which describes a second order elliptic boundary problem:
Definition: probleminterface.hh:64
problem interface class for time dependent problem descriptions, i.e.
Definition: probleminterface.hh:403
virtual void secondOrderCoefficient(const DomainType &x, const JacobianRangeType &Du, const HessianRangeType &D2u, RangeType &result) const
This method has to implement the second order term for the point-wise operator.
Definition: probleminterface.hh:265
virtual void uJacobian(const DomainType &x, JacobianRangeType &value) const
the jacobian of the exact solution (default = 0)
Definition: probleminterface.hh:134
TimeViewType & timeView()
return reference to Problem's time provider
Definition: probleminterface.hh:443
double deltaT() const
return current time step size ( )
Definition: probleminterface.hh:431
virtual void secondOrderCoefficient(const DomainType &x, const JacobianRangeType &gradient, JacobianRangeType &result) const
This method has to implement the second order term for the weak formulation, it needs to compute.
Definition: probleminterface.hh:244
virtual void firstOrderCoefficient(const DomainType &x, const RangeType &u, const JacobianRangeType &Du, RangeType &result) const
First order term with derivative on u.
Definition: probleminterface.hh:293
void evaluate(const DomainType &x, RangeType &ret) const
evaluate function
Definition: probleminterface.hh:331
virtual bool isDirichletSegment(const int bndId, const DomainType &center) const
Classification of the kind of boundary conditions which applies to a boundary segment with the given ...
Definition: probleminterface.hh:150
virtual bool isRobinSegment(const int bndId, const DomainType &center) const
Classification of the kind of boundary conditions which applies to a boundary segment with the given ...
Definition: probleminterface.hh:180
TransientProblemInterface(const TimeProviderType &timeProvider, double theta=0.0)
constructor taking time provider
Definition: probleminterface.hh:412
virtual void dirichletData(const DomainType &x, RangeType &value) const
The Dirichlet boundary data.
Definition: probleminterface.hh:190
virtual void robinData(const DomainType &x, const RangeType &u, RangeType &value) const
The Robin boundary data.
Definition: probleminterface.hh:224
const TimeViewType & timeView() const
return reference to Problem's time provider
Definition: probleminterface.hh:437
virtual void neumannData(const DomainType &x, RangeType &value) const
The Neumann boundary data.
Definition: probleminterface.hh:203
void jacobian(const DomainType &x, JacobianRangeType &jac) const
jacobian of the function
Definition: probleminterface.hh:354
virtual void zeroOrderCoefficient(const DomainType &x, const RangeType &u, RangeType &result) const
Zero order coefficient.
Definition: probleminterface.hh:309
virtual void f(const DomainType &x, RangeType &value) const
the right hand side data (default = 0)
Definition: probleminterface.hh:120
virtual bool has(OperatorPartsType what) const
May be used for optimizations during assembly.
Definition: probleminterface.hh:104
double time() const
return current simulation time
Definition: probleminterface.hh:425
virtual bool isNeumannSegment(const int bndId, const DomainType &center) const
Classification of the kind of boundary conditions which applies to a boundary segment with the given ...
Definition: probleminterface.hh:165
virtual void u(const DomainType &x, RangeType &value) const
the exact solution (default = 0)
Definition: probleminterface.hh:127
LocalFunctionWrapper< LocalGradientAdapter< GridFunction >, typename GridFunction::GridPartType > gradient(const Fem::Function< typename GridFunction::FunctionSpaceType, GridFunction > &f_, const std::string &name="")
Take the gradient of a given function.
Definition: basicfunctions.hh:145
double time() const
Return the absolute point in time.
Definition: timeview.hh:41
double deltaT() const
Return the current time step size.
Definition: timeview.hh:44
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (May 13, 22:30, 2024)