Hermes2D  3.0
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_SOLUTION_H
17 #define __H2D_SOLUTION_H
18 
19 #include "../function/mesh_function.h"
20 #include "../space/space.h"
21 #include "../mesh/refmap.h"
22 #include "exceptions.h"
23 
24 namespace Hermes
25 {
26  namespace Hermes2D
27  {
32  class Quad2DCheb;
33 
34  enum SolutionType {
35  HERMES_UNDEF = -1,
36  HERMES_SLN = 0,
37  HERMES_EXACT = 1
38  };
39 
74  template<typename Scalar>
75  class HERMES_API Solution :
76  public MeshFunction<Scalar>,
77  public Hermes2D::Mixins::XMLParsing
78  {
79  public:
80  Solution();
81  Solution(MeshSharedPtr mesh);
82  Solution(SpaceSharedPtr<Scalar> s, Vector<Scalar>* coeff_vec);
83  Solution(SpaceSharedPtr<Scalar> s, Scalar* coeff_vec);
84  virtual ~Solution();
85 
87  virtual bool isOkay() const;
88  virtual inline std::string getClassName() const { return "Solution"; }
89 
90  virtual void copy(const MeshFunction<Scalar>* sln);
91 
93  void set_dirichlet_lift(SpaceSharedPtr<Scalar> space);
94 
97  virtual void save(const char* filename) const;
98 #ifdef WITH_BSON
99  virtual void save_bson(const char* filename) const;
100 #endif
101 
104  void load(const char* filename, SpaceSharedPtr<Scalar> space);
105 #ifdef WITH_BSON
106  void load_bson(const char* filename, SpaceSharedPtr<Scalar> space);
107 #endif
108 
113  Scalar get_ref_value(Element* e, double xi1, double xi2, int component = 0, int item = 0);
114 
120  Scalar get_ref_value_transformed(Element* e, double xi1, double xi2, int a, int b);
121 
126  Scalar** get_ref_values_transformed(Element* e, double x, double y);
127 
133  virtual Func<Scalar>* get_pt_value(double x, double y, bool use_MeshHashGrid = false, Element* e = nullptr);
134 
137  virtual void add(MeshFunctionSharedPtr<Scalar>& other_mesh_function, SpaceSharedPtr<Scalar> target_space);
138 
140  virtual void multiply(Scalar coef);
141 
143  inline SolutionType get_type() const { return sln_type; };
144 
145  inline SpaceType get_space_type() const { return space_type; };
146 
148  virtual void set_active_element(Element* e);
149 
150  virtual MeshFunction<Scalar>* clone() const;
151 
152  void set_type(SolutionType type) { sln_type = type; };
153 
154  virtual void free();
155 
157  Scalar* mono_coeffs;
158 
162  protected:
163 
168  void enable_transform(bool enable = true);
169 
170  virtual void init();
171 
173  virtual void set_coeff_vector(SpaceSharedPtr<Scalar> space, const Vector<Scalar>* vec, bool add_dir_lift, int start_index);
174 
175  virtual void set_coeff_vector(SpaceSharedPtr<Scalar> space, const Scalar* coeffs, bool add_dir_lift, int start_index);
176 
177  SolutionType sln_type;
178  SpaceType space_type;
179 
180  bool transform;
181 
183  int* elem_coeffs[H2D_MAX_SOLUTION_COMPONENTS];
184  int num_coeffs, num_elems;
185  int num_dofs;
186 
187  void transform_values(int order, int mask, int np);
188 
189  virtual void precalculate(unsigned short order, unsigned short mask);
190 
191  Scalar* dxdy_coeffs[H2D_MAX_SOLUTION_COMPONENTS][H2D_NUM_FUNCTION_VALUES];
192 
193  Scalar* dxdy_buffer;
194 
195  double** calc_mono_matrix(int mode, unsigned char o);
196 
197  void init_dxdy_buffer();
198 
200  void check_space_type_compliance(const char* space_type_to_check) const;
201 
203  void load_exact_solution(int number_of_components, SpaceSharedPtr<Scalar> space, bool complexness,
204  double x_real, double y_real, double x_complex, double y_complex);
205 
207  Scalar x[H2D_MAX_INTEGRATION_POINTS_COUNT], y[H2D_MAX_INTEGRATION_POINTS_COUNT], tx[H2D_MAX_INTEGRATION_POINTS_COUNT];
208 
209 #pragma region friends
210  friend class RefMap;
211  template<typename T> friend class KellyTypeAdapt;
212  template<typename T> friend class Views::BaseView;
213  template<typename T> friend class Views::VectorBaseView;
214  template<typename T> friend class OGProjectionNOX;
215  template<typename T> friend class Adapt;
216  template<typename T> friend class Func;
217  template<typename T> friend class DiscontinuousFunc;
218  template<typename T> friend class DiscreteProblem;
219  template<typename T> friend class DiscreteProblemIntegrationOrderCalculator;
220  template<typename T> friend class NeighborSearch;
221  template<typename T> friend class RefinementSelectors::ProjBasedSelector;
222  template<typename T> friend class RefinementSelectors::H1ProjBasedSelector;
223  template<typename T> friend class RefinementSelectors::L2ProjBasedSelector;
224  template<typename T> friend class RefinementSelectors::HcurlProjBasedSelector;
225 #pragma endregion
226 
227 #pragma region static
228  public:
229  static bool static_verbose_output;
230 
231  // Calculate derivative wrt. x of mono into result.
232  static void make_dx_coeffs(int mode, int o, Scalar* mono, Scalar* result);
233  // Calculate derivative wrt. y of mono into result.
234  static void make_dy_coeffs(int mode, int o, Scalar* mono, Scalar* result);
235 
236  static void set_static_verbose_output(bool verbose);
237 
239  static void vector_to_solutions(const Scalar* solution_vector, std::vector<SpaceSharedPtr<Scalar> > spaces,
240  std::vector<MeshFunctionSharedPtr<Scalar> > solutions,
241  std::vector<bool> add_dir_lift = std::vector<bool>(),
242  std::vector<int> start_indices = std::vector<int>());
243 
244  static void vector_to_solution(const Scalar* solution_vector, SpaceSharedPtr<Scalar> space, MeshFunctionSharedPtr<Scalar> solution,
245  bool add_dir_lift = true, int start_index = 0);
246 
247  static void vector_to_solution(const Scalar* solution_vector, SpaceSharedPtr<Scalar> space, Solution<Scalar>* solution,
248  bool add_dir_lift = true, int start_index = 0);
249 
250  static void vector_to_solutions(const Vector<Scalar>* vec, std::vector<SpaceSharedPtr<Scalar> > spaces,
251  std::vector<MeshFunctionSharedPtr<Scalar> > solutions,
252  std::vector<bool> add_dir_lift = std::vector<bool>(),
253  std::vector<int> start_indices = std::vector<int>());
254 
255  static void vector_to_solutions_common_dir_lift(const Vector<Scalar>* vec, std::vector<SpaceSharedPtr<Scalar> > spaces,
256  std::vector<MeshFunctionSharedPtr<Scalar> > solutions,
257  bool add_dir_lift = false);
258 
259  static void vector_to_solutions_common_dir_lift(const Scalar* solution_vector, std::vector<SpaceSharedPtr<Scalar> > spaces,
260  std::vector<MeshFunctionSharedPtr<Scalar> > solutions,
261  bool add_dir_lift = false);
262 
263  static void vector_to_solution(const Vector<Scalar>* vec, SpaceSharedPtr<Scalar> space, MeshFunctionSharedPtr<Scalar> solution,
264  bool add_dir_lift = true, int start_index = 0);
265 
266 #pragma endregion
267  };
268  }
269 }
270 
271 #endif
Definition: adapt.h:24
A projection-based selector for Hcurl space.
Definition: function.h:36
This class represents a function with jump discontinuity on an interface of two elements.
Definition: forms.h:335
Scalar * mono_coeffs
Monomial coefficient array.
Definition: solution.h:157
Used to pass the instances of Space around.
Definition: space.h:34
A projection-based selector for H1 space.
Definition: function.h:35
::xsd::cxx::tree::type type
C++ type corresponding to the anyType XML Schema built-in type.
A general projection-based selector.
Definition: function.h:33
Visualizes the basis functions of a space.
Definition: space.h:68
SolutionType get_type() const
Returns solution type.
Definition: solution.h:143
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Represents the reference mapping.
Definition: refmap.h:40
This class characterizes a neighborhood of a given edge in terms of adjacent elements and provides me...
A projection-based selector for L2 space.
Definition: function.h:34
Represents the solution of a PDE.
Definition: api2d.h:35