Hermes2D  2.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 
75  template<typename Scalar>
76  class HERMES_API Solution : public MeshFunction<Scalar>, public Hermes2D::Mixins::XMLParsing
77  {
78  public:
79  Solution();
80  Solution(const Mesh *mesh);
81  Solution (Space<Scalar>* s, Vector<Scalar>* coeff_vec);
82  Solution (Space<Scalar>* s, Scalar* coeff_vec);
83  virtual ~Solution();
84 
86  inline std::string getClassName() const { return "Solution"; }
87 
88  void assign(Solution* sln);
89  inline Solution& operator = (Solution& sln) { assign(&sln); return *this; }
90 
91  virtual void copy(const Solution<Scalar>* sln);
92 
94  void set_dirichlet_lift(const Space<Scalar>* space, PrecalcShapeset* pss = NULL);
95 
98  virtual void save(const char* filename) const;
99 
102  void load(const char* filename, Space<Scalar>* space);
103 
108  Scalar get_ref_value(Element* e, double xi1, double xi2, int component = 0, int item = 0);
109 
115  Scalar get_ref_value_transformed(Element* e, double xi1, double xi2, int a, int b);
116 
122  virtual Func<Scalar>* get_pt_value(double x, double y);
123 
125  void multiply(Scalar coef);
126 
128  inline SolutionType get_type() const { return sln_type; };
129 
130  inline SpaceType get_space_type() const { return space_type; };
131 
133  static void vector_to_solutions(const Scalar* solution_vector, Hermes::vector<const Space<Scalar> *> spaces,
134  Hermes::vector<Solution<Scalar>*> solutions,
135  Hermes::vector<bool> add_dir_lift = Hermes::vector<bool>(),
136  Hermes::vector<int> start_indices = Hermes::vector<int>());
137 
138  static void vector_to_solution(const Scalar* solution_vector, const Space<Scalar>* space, Solution<Scalar>* solution,
139  bool add_dir_lift = true, int start_index = 0);
140 
141  static void vector_to_solutions(const Vector<Scalar>* vec, Hermes::vector<const Space<Scalar> *> spaces,
142  Hermes::vector<Solution<Scalar>*> solutions,
143  Hermes::vector<bool> add_dir_lift = Hermes::vector<bool>(),
144  Hermes::vector<int> start_indices = Hermes::vector<int>());
145 
146  static void vector_to_solutions_common_dir_lift(const Vector<Scalar>* vec, Hermes::vector<const Space<Scalar> *> spaces,
147  Hermes::vector<Solution<Scalar>*> solutions,
148  bool add_dir_lift = false);
149 
150  static void vector_to_solutions_common_dir_lift(const Scalar* solution_vector, Hermes::vector<const Space<Scalar> *> spaces,
151  Hermes::vector<Solution<Scalar>*> solutions,
152  bool add_dir_lift = false);
153 
154  static void vector_to_solution(const Vector<Scalar>* vec, const Space<Scalar>* space, Solution<Scalar>* solution,
155  bool add_dir_lift = true, int start_index = 0);
156 
157  static void vector_to_solutions(const Scalar* solution_vector, Hermes::vector<const Space<Scalar> *> spaces,
158  Hermes::vector<Solution<Scalar>*> solutions, Hermes::vector<PrecalcShapeset *> pss,
159  Hermes::vector<bool> add_dir_lift = Hermes::vector<bool>(),
160  Hermes::vector<int> start_indices = Hermes::vector<int>());
161 
162  static void vector_to_solution(const Scalar* solution_vector, const Space<Scalar>* space, Solution<Scalar>* solution,
163  PrecalcShapeset* pss, bool add_dir_lift = true, int start_index = 0);
164 
166  virtual void set_active_element(Element* e);
167 
168  virtual MeshFunction<Scalar>* clone() const;
169 
170  static void set_static_verbose_output(bool verbose);
171 
172  protected:
173  static bool static_verbose_output;
174 
175  virtual int get_edge_fn_order(int edge) { return MeshFunction<Scalar>::get_edge_fn_order(edge); }
176 
181  void enable_transform(bool enable = true);
182 
183  virtual void init();
184 
185  virtual void free();
186 
188  virtual void set_coeff_vector(const Space<Scalar>* space, const Vector<Scalar>* vec, bool add_dir_lift, int start_index);
189 
190  virtual void set_coeff_vector(const Space<Scalar>* space, PrecalcShapeset* pss, const Scalar* coeffs, bool add_dir_lift, int start_index);
191 
192  virtual void set_coeff_vector(const Space<Scalar>* space, const Scalar* coeffs, bool add_dir_lift, int start_index);
193 
194  SolutionType sln_type;
195  SpaceType space_type;
196 
197  bool transform;
198 
207  std::map<uint64_t, LightArray<struct Function<Scalar>::Node*>*>* tables[H2D_MAX_QUADRATURES][H2D_SOLUTION_ELEMENT_CACHE_SIZE];
208 
209  Element* elems[H2D_MAX_QUADRATURES][H2D_SOLUTION_ELEMENT_CACHE_SIZE];
210  int cur_elem, oldest[H2D_SOLUTION_ELEMENT_CACHE_SIZE];
211 
212  Scalar* mono_coeffs;
213  int* elem_coeffs[H2D_MAX_SOLUTION_COMPONENTS];
214 
216  int num_coeffs, num_elems;
217  int num_dofs;
218 
219  void transform_values(int order, struct Function<Scalar>::Node* node, int newmask, int oldmask, int np);
220 
221  virtual void precalculate(int order, int mask);
222 
223  Scalar* dxdy_coeffs[H2D_MAX_SOLUTION_COMPONENTS][6];
224 
225  Scalar* dxdy_buffer;
226 
227  double** calc_mono_matrix(int o, int*& perm);
228 
229  void init_dxdy_buffer();
230 
231  void free_tables();
232 
234 
235  friend class RefMap;
236  template<typename T> friend class KellyTypeAdapt;
237  template<typename T> friend class CalculationContinuity;
238  template<typename T> friend class OGProjection;
239  template<typename T> friend class OGProjectionNOX;
240  template<typename T> friend class Adapt;
241  template<typename T> friend class Func;
242  template<typename T> friend class DiscontinuousFunc;
243  template<typename T> friend class DiscreteProblem;
244  template<typename T> friend class DiscreteProblemLinear;
245  template<typename T> friend class NeighborSearch;
246  template<typename T> friend HERMES_API Func<T>* init_fn(Solution<T>*fu, const int order);
247  template<typename T> friend class RefinementSelectors::ProjBasedSelector;
248  template<typename T> friend class RefinementSelectors::H1ProjBasedSelector;
249  template<typename T> friend class RefinementSelectors::L2ProjBasedSelector;
250  template<typename T> friend class RefinementSelectors::HcurlProjBasedSelector;
251  };
252  }
253 }
254 
255 #endif