Hermes2D  2.0
function.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_FUNCTION_H
17 #define __H2D_FUNCTION_H
18 
19 #include "transformable.h"
20 #include "../quadrature/quad.h"
21 #include "exceptions.h"
22 
23 namespace Hermes
24 {
25  namespace Hermes2D
26  {
27  struct SurfPos;
28  class PrecalcShapeset;
29  namespace RefinementSelectors{
30  template<typename Scalar> class Selector;
31  template<typename Scalar> class HOnlySelector;
32  template<typename Scalar> class POnlySelector;
33  template<typename Scalar> class OptimumSelector;
34  template<typename Scalar> class ProjBasedSelector;
35  template<typename Scalar> class L2ProjBasedSelector;
36  template<typename Scalar> class H1ProjBasedSelector;
37  template<typename Scalar> class HcurlProjBasedSelector;
38  };
39  template<typename Scalar> class Geom;
40 
41  namespace Views{
42  class Orderizer;
43  class Linearizer;
44  class Vectorizer;
45  };
46 
48  enum
49  {
50  H2D_FN_VAL_0 = 0x0001, H2D_FN_VAL_1 = 0x0040, // Function values
51  H2D_FN_DX_0 = 0x0002, H2D_FN_DX_1 = 0x0080, // First derivative
52  H2D_FN_DY_0 = 0x0004, H2D_FN_DY_1 = 0x0100, // First derivative
53  H2D_FN_DXX_0 = 0x0008, H2D_FN_DXX_1 = 0x0200, // Second derivative
54  H2D_FN_DYY_0 = 0x0010, H2D_FN_DYY_1 = 0x0400, // Second derivative
55  H2D_FN_DXY_0 = 0x0020, H2D_FN_DXY_1 = 0x0800 // Second mixed derivative
56  };
57 
59  const int H2D_FN_VAL = H2D_FN_VAL_0 | H2D_FN_VAL_1;
60  const int H2D_FN_DX = H2D_FN_DX_0 | H2D_FN_DX_1;
61  const int H2D_FN_DY = H2D_FN_DY_0 | H2D_FN_DY_1;
62  const int H2D_FN_DXX = H2D_FN_DXX_0 | H2D_FN_DXX_1;
63  const int H2D_FN_DYY = H2D_FN_DYY_0 | H2D_FN_DYY_1;
64  const int H2D_FN_DXY = H2D_FN_DXY_0 | H2D_FN_DXY_1;
65 
66  const int H2D_FN_DEFAULT = H2D_FN_VAL | H2D_FN_DX | H2D_FN_DY;
67  const int H2D_FN_ALL = H2D_FN_DEFAULT | H2D_FN_DXX | H2D_FN_DYY | H2D_FN_DXY;
68 
69  const int H2D_FN_COMPONENT_0 = H2D_FN_VAL_0 | H2D_FN_DX_0 | H2D_FN_DY_0 | H2D_FN_DXX_0 | H2D_FN_DYY_0 | H2D_FN_DXY_0;
70  const int H2D_FN_COMPONENT_1 = H2D_FN_VAL_1 | H2D_FN_DX_1 | H2D_FN_DY_1 | H2D_FN_DXX_1 | H2D_FN_DYY_1 | H2D_FN_DXY_1;
71 
97  template<typename Scalar>
98  class HERMES_API Function : public Transformable
99  {
100  public:
101 
103  Function();
104 
107  virtual ~Function();
108 
110  int get_num_components() const;
111 
115  Scalar* get_fn_values(int component = 0);
116 
120  Scalar* get_dx_values(int component = 0);
121 
125  Scalar* get_dy_values(int component = 0);
126 
132  void get_dx_dy_values(Scalar*& dx, Scalar*& dy, int component = 0);
133 
137  Scalar* get_dxx_values(int component = 0);
138 
142  Scalar* get_dyy_values(int component = 0);
143 
147  Scalar* get_dxy_values(int component = 0);
148 
150  Quad2D* get_quad_2d() const;
151 
158  void set_quad_order(unsigned int order, int mask = H2D_FN_DEFAULT);
159 
160  Scalar* get_values(int a, int b);
161 
163  int get_fn_order() const;
164 
165  protected:
171  virtual void set_quad_2d(Quad2D* quad_2d);
172 
174  virtual void free() = 0;
175 
176  struct Node
177  {
178  int mask;
179 
180  int size;
181 
182  Scalar* values[H2D_MAX_SOLUTION_COMPONENTS][6];
183 
184  Scalar data[1];
185 
186  private:
187  Node(const Node& org) {};
188 
189  Node& operator=(const Node& other) { return *this; };
190  };
191 
194  virtual int get_edge_fn_order(int edge) const;
195 
197  virtual void precalculate(int order, int mask) = 0;
198 
199  int order;
200 
202 
204  std::map<uint64_t, LightArray<Node*>*>* sub_tables;
205 
207  LightArray<Node*>* nodes;
208 
211 
213  LightArray<Node*>* overflow_nodes;
214 
217  void update_nodes_ptr();
218 
220  void force_transform(uint64_t sub_idx, Trf* ctm);
221 
222  Quad2D* quads[8];
223 
224  int cur_quad;
225 
226  int total_mem;
227 
228  int max_mem;
229 
230  Node* new_node(int mask, int num_points);
231 
232  virtual void handle_overflow_idx() = 0;
233 
234  void replace_cur_node(Node* node);
235 
236  static void check_params(int component, Node* cur_node, int num_components);
237 
238  static void check_table(int component, Node* cur_node, int n, const char* msg);
239 
240  static int idx2mask[6][2];
241  template<typename T> friend class KellyTypeAdapt;
242  template<typename T> friend class RefinementSelectors::H1ProjBasedSelector;
243  template<typename T> friend class RefinementSelectors::L2ProjBasedSelector;
244  template<typename T> friend class RefinementSelectors::HcurlProjBasedSelector;
245  template<typename T> friend class Adapt;
246  friend class Views::Orderizer;
247  friend class Views::Vectorizer;
248  friend class Views::Linearizer;
249 
250  template<typename T> friend class DiscontinuousFunc;
251  template<typename T> friend class DiscreteProblem;
252  template<typename T> friend class DiscreteProblemLinear;
253  template<typename T> friend class Global;
254  friend class CurvMap;
255 
256  template<typename T> friend class Func;
257  template<typename T> friend class Geom;
258  template<typename T> friend class Filter;
259  template<typename T> friend class SimpleFilter;
260  template<typename T> friend class DXDYFilter;
261  friend class ComplexFilter;
262  friend class VonMisesFilter;
263  friend HERMES_API Geom<double>* init_geom_vol(RefMap *rm, const int order);
264  friend HERMES_API Geom<double>* init_geom_surf(RefMap *rm, SurfPos* surf_pos, const int order);
265  friend HERMES_API Func<double>* init_fn(PrecalcShapeset *fu, RefMap *rm, const int order);
266  template<typename T> friend HERMES_API Func<T>* init_fn(MeshFunction<T>*fu, const int order);
267  };
268  }
269 }
270 #endif