Hermes2D  3.0
exact_solution.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_EXACT_SOLUTION_H
17 #define __H2D_EXACT_SOLUTION_H
18 
19 #include "solution.h"
20 
21 namespace Hermes
22 {
23  namespace Hermes2D
24  {
25  template<typename T> class Geom;
26 
32  template<typename Scalar>
33  class HERMES_API ExactSolution : public Solution < Scalar >
34  {
35  public:
36  ExactSolution(MeshSharedPtr mesh);
37  virtual ~ExactSolution() {};
38 
40  virtual unsigned int get_dimension() const = 0;
41 
42  virtual MeshFunction<Scalar>* clone() const;
43 
44  std::string getClassName() const;
45 
47  virtual void save(const char* filename) const;
48 #ifdef WITH_BSON
49  virtual void save_bson(const char* filename) const;
50 #endif
51  virtual Hermes::Ord ord(double x, double y) const = 0;
54 
55  protected:
58  template<typename T> friend class Solution;
59  };
60 
63  template<typename Scalar>
64  class HERMES_API ExactSolutionScalar : public ExactSolution < Scalar >
65  {
66  public:
67  ExactSolutionScalar(MeshSharedPtr mesh);
68  virtual ~ExactSolutionScalar() {};
69 
71  virtual unsigned int get_dimension() const;
72 
74  virtual Scalar value(double x, double y) const = 0;
75 
77  virtual void derivatives(double x, double y, Scalar& dx, Scalar& dy) const = 0;
78 
80  Scalar exact_function(double x, double y, Scalar& dx, Scalar& dy) const {
81  derivatives(x, y, dx, dy);
82  return value(x, y);
83  };
84  };
85 
88  template<typename Scalar, typename ValueType>
89  class HERMES_API ExactSolutionConstantArray : public ExactSolutionScalar < Scalar >
90  {
91  public:
94  ExactSolutionConstantArray(MeshSharedPtr mesh, ValueType* valueArray, bool deleteArray = false);
95  virtual ~ExactSolutionConstantArray();
96 
97  virtual MeshFunction<Scalar>* clone() const;
98 
100  virtual Scalar value(double x, double y) const;
101  virtual Ord ord(double x, double y) const;
102 
104  virtual void derivatives(double x, double y, Scalar& dx, Scalar& dy) const;
105 
106  inline std::string getClassName() const { return "ExactSolutionConstantArray"; }
107 
108  void setArray(ValueType* valueArray);
109 
110  protected:
112  ValueType* valueArray;
113 
116 
117  template<typename T> friend class Solution;
118  };
119 
120  template<typename Scalar>
121  class HERMES_API ExactSolutionVector : public ExactSolution < Scalar >
122  {
123  public:
124  ExactSolutionVector(MeshSharedPtr mesh);
125  virtual ~ExactSolutionVector() {};
126 
128  virtual unsigned int get_dimension() const;
129 
131  virtual Scalar2<Scalar> value(double x, double y) const = 0;
132 
134  virtual void derivatives(double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const = 0;
135 
137  virtual Scalar2<Scalar> exact_function(double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const {
138  derivatives(x, y, dx, dy);
139  return value(x, y);
140  };
141  };
142 
143  template<typename Scalar>
144  class HERMES_API ConstantSolution : public ExactSolutionScalar < Scalar >
145  {
146  public:
147  ConstantSolution(MeshSharedPtr mesh, Scalar constant);
148  virtual ~ConstantSolution() {};
149 
150  virtual Scalar value(double x, double y) const;
151 
152  virtual void derivatives(double x, double y, Scalar& dx, Scalar& dy) const;
153 
154  virtual Ord ord(double x, double y) const;
155  virtual MeshFunction<Scalar>* clone() const;
156 
158  void save(const char* filename) const;
159 #ifdef WITH_BSON
160  void save_bson(const char* filename) const;
161 #endif
162 
163  protected:
164  Scalar constant;
165  };
166 
167  template<typename Scalar>
168  class HERMES_API ZeroSolution : public ExactSolutionScalar < Scalar >
169  {
170  public:
171  ZeroSolution(MeshSharedPtr mesh);
172  virtual ~ZeroSolution() {};
173 
174  virtual Scalar value(double x, double y) const;
175 
176  virtual void derivatives(double x, double y, Scalar& dx, Scalar& dy) const;
177 
178  virtual Ord ord(double x, double y) const;
179  virtual MeshFunction<Scalar>* clone() const;
180  };
181 
182  template<typename Scalar>
183  class HERMES_API ConstantSolutionVector : public ExactSolutionVector < Scalar >
184  {
185  public:
186  ConstantSolutionVector(MeshSharedPtr mesh, Scalar constantX, Scalar constantY);
187  virtual ~ConstantSolutionVector() {};
188 
189  virtual Scalar2<Scalar> value(double x, double y) const;
190 
191  virtual void derivatives(double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const;
192 
193  virtual Ord ord(double x, double y) const;
194  virtual MeshFunction<Scalar>* clone() const;
195 
197  void save(const char* filename) const;
198 #ifdef WITH_BSON
199  void save_bson(const char* filename) const;
200 #endif
201  protected:
202  Scalar constantX;
203  Scalar constantY;
204  };
205 
206  template<typename Scalar>
207  class HERMES_API ZeroSolutionVector : public ExactSolutionVector < Scalar >
208  {
209  public:
210  ZeroSolutionVector(MeshSharedPtr mesh);
211  virtual ~ZeroSolutionVector() {};
212 
213  virtual Scalar2<Scalar> value(double x, double y) const;
214 
215  virtual void derivatives(double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const;
216 
217  virtual Ord ord(double x, double y) const;
218  virtual MeshFunction<Scalar>* clone() const;
219  };
220 
222  class HERMES_API ExactSolutionEggShell : public ExactSolutionScalar < double >
223  {
224  public:
227  ExactSolutionEggShell(MeshSharedPtr mesh, int polynomialOrder);
228  virtual ~ExactSolutionEggShell() {};
229 
231  virtual double value(double x, double y) const;
232 
234  virtual void derivatives(double x, double y, double& dx, double& dy) const;
235 
238  virtual Hermes::Ord ord(double x, double y) const;
239 
240  MeshFunction<double>* clone() const;
241  };
242 
244  template<typename Scalar>
245  class HERMES_API UExtFunction : public Function < Scalar >
246  {
247  public:
250  UExtFunction();
251  virtual ~UExtFunction() {};
252 
254  virtual void value(int n, Func<Scalar>** ext, Func<Scalar>** u_ext, Func<Scalar>* result, Geom<double>* geometry) const = 0;
255  virtual void ord(Func<Hermes::Ord>** ext, Func<Hermes::Ord>** u_ext, Func<Hermes::Ord>* result) const = 0;
256 
257  virtual Func<Scalar>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
258  void free(void);
259  virtual void precalculate(unsigned short order, unsigned short mask);
260  };
261 
262  template<typename Scalar>
263  class HERMES_API UExtFunctionSharedPtr : public std::tr1::shared_ptr < UExtFunction<Scalar> >
264  {
265  public:
267 
269 
270  void operator=(const UExtFunctionSharedPtr<Scalar>& other);
271  };
272  }
273 }
274 #endif
Definition: adapt.h:24
Function operating on previous nonlinear solutions in assembling (u_ext)
Stores one element of a mesh.
Definition: element.h:107
Geometry (coordinates, normals, tangents) of either an element or an edge.
Definition: forms.h:40
Represents a function defined on a mesh.
Definition: mesh_function.h:56
ValueType * valueArray
Array of the values.
virtual Scalar2< Scalar > exact_function(double x, double y, Scalar2< Scalar > &dx, Scalar2< Scalar > &dy) const
Function returning the value and derivatives.
Scalar exact_function(double x, double y, Scalar &dx, Scalar &dy) const
Function returning the value and derivatives.
Represents an arbitrary function defined on an element.
Definition: function.h:106
Scalar exact_multiplicator
For scaling of the solution.
Represents an exact solution of a PDE.
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Represents the solution of a PDE.
Definition: api2d.h:35