Hermes2D  2.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  {
31  template<typename Scalar>
32  class HERMES_API ExactSolution : public Solution<Scalar>
33  {
34  public:
35  ExactSolution(const Mesh* mesh);
36 
38  virtual unsigned int get_dimension() const = 0;
39 
40  virtual MeshFunction<Scalar>* clone() const;
41 
42  inline std::string getClassName() const { return "ExactSolution"; }
43 
44  protected:
47  template<typename T> friend class Solution;
48  };
49 
53  template<typename Scalar>
54  class HERMES_API ExactSolutionScalar : public ExactSolution<Scalar>
55  {
56  public:
57  ExactSolutionScalar(const Mesh* mesh);
58 
60  virtual unsigned int get_dimension() const;
61 
63  virtual Scalar value (double x, double y) const = 0;
64 
66  virtual void derivatives (double x, double y, Scalar& dx, Scalar& dy) const = 0;
67 
69  Scalar exact_function (double x, double y, Scalar& dx, Scalar& dy) const {
70  derivatives (x, y, dx, dy);
71  return value (x, y);
72  };
73 
76  virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const = 0;
77  };
78 
80  template<typename Scalar>
81  class HERMES_API ExactSolutionVector : public ExactSolution<Scalar>
82  {
83  public:
84  ExactSolutionVector(const Mesh* mesh);
85 
87  virtual unsigned int get_dimension() const;
88 
90  virtual Scalar2<Scalar> value (double x, double y) const = 0;
91 
93  virtual void derivatives (double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const = 0;
94 
96  virtual Scalar2<Scalar> exact_function(double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const {
97  derivatives (x, y, dx, dy);
98  return value (x, y);
99  };
100 
103  virtual Hermes::Ord ord(Hermes::Ord x, Hermes::Ord y) const = 0;
104  };
105 
107  template<typename Scalar>
108  class HERMES_API ConstantSolution : public ExactSolutionScalar<Scalar>
109  {
110  public:
111  ConstantSolution(const Mesh* mesh, Scalar constant);
112 
113  virtual Scalar value (double x, double y) const;
114 
115  virtual void derivatives (double x, double y, Scalar& dx, Scalar& dy) const;
116 
117  virtual Ord ord(Ord x, Ord y) const;
118  virtual MeshFunction<Scalar>* clone() const;
119 
121  void save(const char* filename) const;
122 
123  protected:
124  Scalar constant;
125  };
126 
128  template<typename Scalar>
129  class HERMES_API ZeroSolution : public ExactSolutionScalar<Scalar>
130  {
131  public:
132  ZeroSolution(const Mesh* mesh);
133 
134  virtual Scalar value (double x, double y) const;
135 
136  virtual void derivatives (double x, double y, Scalar& dx, Scalar& dy) const;
137 
138  virtual Ord ord(Ord x, Ord y) const;
139  virtual MeshFunction<Scalar>* clone() const;
140 
142  void save(const char* filename) const;
143  };
144 
146  template<typename Scalar>
147  class HERMES_API ConstantSolutionVector : public ExactSolutionVector<Scalar>
148  {
149  public:
150  ConstantSolutionVector(const Mesh* mesh, Scalar constantX, Scalar constantY);
151 
152  virtual Scalar2<Scalar> value (double x, double y) const;
153 
154  virtual void derivatives (double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const;
155 
156  virtual Ord ord(Ord x, Ord y) const;
157  virtual MeshFunction<Scalar>* clone() const;
158 
160  void save(const char* filename) const;
161  protected:
162  Scalar constantX;
163  Scalar constantY;
164  };
165 
167  template<typename Scalar>
168  class HERMES_API ZeroSolutionVector : public ExactSolutionVector<Scalar>
169  {
170  public:
171  ZeroSolutionVector(const Mesh* mesh);
172 
173  virtual Scalar2<Scalar> value (double x, double y) const;
174 
175  virtual void derivatives (double x, double y, Scalar2<Scalar>& dx, Scalar2<Scalar>& dy) const;
176 
177  virtual Ord ord(Ord x, Ord y) const;
178  virtual MeshFunction<Scalar>* clone() const;
179 
181  void save(const char* filename) const;
182  };
183  }
184 }
185 #endif