Hermes2D  3.0
forms.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 
17 
18 #ifndef __H2D_FORMS_H
19 #define __H2D_FORMS_H
20 
21 #include "global.h"
22 #include "quadrature/quad.h"
23 #include "function/function.h"
24 #include "function/exact_solution.h"
25 #include "mesh/refmap.h"
26 #include "mesh/traverse.h"
27 
28 namespace Hermes
29 {
30  namespace Hermes2D
31  {
32  static const char* ERR_UNDEFINED_NEIGHBORING_ELEMENTS =
33  "Neighboring elements are not defined and so are not function traces on their interface. "
34  "Did you forget setting H2D_ANY_INNER_EDGE in add_matrix/vector_form?";
35 
36 #pragma region Geometry
37 
39  template<typename T>
40  class HERMES_API Geom
41  {
42  public:
44  T x[H2D_MAX_INTEGRATION_POINTS_COUNT];
46  T y[H2D_MAX_INTEGRATION_POINTS_COUNT];
47 
50  };
51 
53  template<typename T>
54  class HERMES_API GeomVol : public Geom < T >
55  {
56  public:
58  int id;
59 
61  T get_diam_approximation(unsigned char n);
63  T get_area(unsigned char n, double* wt);
64  };
65 
67  template<typename T>
68  class HERMES_API GeomSurf : public Geom < T >
69  {
70  public:
71  T nx[H2D_MAX_INTEGRATION_POINTS_COUNT];
72  T ny[H2D_MAX_INTEGRATION_POINTS_COUNT];
73  T tx[H2D_MAX_INTEGRATION_POINTS_COUNT];
74  T ty[H2D_MAX_INTEGRATION_POINTS_COUNT];
75 
77  unsigned char isurf;
78 
81 
86  };
87 
89  template<>
90  class HERMES_API GeomVol < Hermes::Ord >
91  {
92  public:
93  GeomVol()
94  {
95  x[0] = y[0] = Hermes::Ord(1);
96  }
97  Hermes::Ord x[1];
98  Hermes::Ord y[1];
99 
102 
104  Hermes::Ord get_diam_approximation(unsigned char n) { return Hermes::Ord(1); };
106  Hermes::Ord get_area(unsigned char n, double* wt) { return Hermes::Ord(1); };
107  };
108 
110  template<>
111  class HERMES_API GeomSurf < Hermes::Ord >
112  {
113  public:
114  GeomSurf()
115  {
116  x[0] = y[0] = tx[0] = ty[0] = nx[0] = ny[0] = Hermes::Ord(1);
117  }
118  Hermes::Ord x[1];
119  Hermes::Ord y[1];
120  Hermes::Ord tx[1];
121  Hermes::Ord ty[1];
122  Hermes::Ord nx[1];
123  Hermes::Ord ny[1];
124 
126  unsigned char np;
127  };
128 
133  template<typename T>
134  class HERMES_API InterfaceGeom
135  {
136  public:
138  InterfaceGeom(GeomSurf<T>* geom, Element* central_el, Element* neighb_el);
139  T* x;
140  T* y;
141  T* nx;
142  T* ny;
143  T* tx;
144  T* ty;
145  Element* central_el;
146  Element* neighb_el;
147 
152 
157 
159  unsigned char isurf;
160 
162  T get_diam_approximation(unsigned char n);
164  T get_area(unsigned char n, double* wt);
165 
166  private:
167  GeomSurf<T>* wrapped_geom;
168  template<typename Scalar> friend class KellyTypeAdapt;
169  };
170 
172  template<>
173  class HERMES_API InterfaceGeom < Hermes::Ord >
174  {
175  public:
178  {
179  x[0] = y[0] = tx[0] = ty[0] = nx[0] = ny[0] = Hermes::Ord(1);
180  }
181  Hermes::Ord x[1];
182  Hermes::Ord y[1];
183  Hermes::Ord tx[1];
184  Hermes::Ord ty[1];
185  Hermes::Ord nx[1];
186  Hermes::Ord ny[1];
187 
189  Hermes::Ord get_diam_approximation(unsigned char n) { return Hermes::Ord(1); };
191  Hermes::Ord get_area(unsigned char n, double* wt) { return Hermes::Ord(1); };
192  };
193 
195  HERMES_API GeomVol<double>* init_geom_vol(RefMap *rm, const int order);
197  HERMES_API void init_geom_vol_allocated(GeomVol<double>& geom, RefMap *rm, const int order);
199  HERMES_API GeomSurf<double>* init_geom_surf(RefMap *rm, unsigned char isurf, int marker, const int order, double3*& tan);
201  HERMES_API void init_geom_surf_allocated(GeomSurf<double>& geom, RefMap *rm, unsigned char isurf, int marker, const int order, double3*& tan);
202 #pragma endregion
203 
204 #pragma region Func
205  template<typename Scalar>
208  class HERMES_API Func
209  {
210  };
211 
213  template<>
214  class HERMES_API Func < double >
215  {
216  public:
218  Func();
220 
222  Func(int np, int nc);
223  union
224  {
225  double val[H2D_MAX_INTEGRATION_POINTS_COUNT];
226  double val0[H2D_MAX_INTEGRATION_POINTS_COUNT];
227  };
228 
229  union
230  {
231  double dx[H2D_MAX_INTEGRATION_POINTS_COUNT];
232  double val1[H2D_MAX_INTEGRATION_POINTS_COUNT];
233  };
234 
235  union
236  {
237  double dy[H2D_MAX_INTEGRATION_POINTS_COUNT];
238  double curl[H2D_MAX_INTEGRATION_POINTS_COUNT];
239  };
240 
241  union
242  {
243  double laplace[H2D_MAX_INTEGRATION_POINTS_COUNT];
244  double div[H2D_MAX_INTEGRATION_POINTS_COUNT];
245  };
246 
248  int np;
250  int nc;
252 
253  void subtract(Func<double>* func);
255  void subtract(double* attribute, double* other_attribute);
257 
258  void add(Func<double>* func);
260  void add(double* attribute, double* other_attribute);
261  };
262 
264  template<>
265  class HERMES_API Func < std::complex<double> >
266  {
267  public:
269  Func();
271 
273  Func(int np, int nc);
274 
275  std::complex<double> val[H2D_MAX_INTEGRATION_POINTS_COUNT];
276  std::complex<double> val0[H2D_MAX_INTEGRATION_POINTS_COUNT];
277 
278  std::complex<double> dx[H2D_MAX_INTEGRATION_POINTS_COUNT];
279  std::complex<double> val1[H2D_MAX_INTEGRATION_POINTS_COUNT];
280 
281  std::complex<double> dy[H2D_MAX_INTEGRATION_POINTS_COUNT];
282  std::complex<double> curl[H2D_MAX_INTEGRATION_POINTS_COUNT];
283 
284  std::complex<double> laplace[H2D_MAX_INTEGRATION_POINTS_COUNT];
285  std::complex<double> div[H2D_MAX_INTEGRATION_POINTS_COUNT];
286 
288  int np;
290  int nc;
292 
293  void subtract(Func<std::complex<double> >* func);
295  void subtract(std::complex<double> * attribute, std::complex<double> * other_attribute);
297 
298  void add(Func<std::complex<double> >* func);
300  void add(std::complex<double> * attribute, std::complex<double> * other_attribute);
301  };
302 
303  template<>
304  class HERMES_API Func < Ord >
305  {
306  public:
307  Func(const int order);
308  const int order;
309  Ord val;
310  Ord dx;
311  Ord dy;
312  Ord laplace;
313 
314  Ord val0;
315  Ord val1;
316  Ord curl;
317  Ord div;
318  void subtract(Func<Ord>* func);
319  };
320 
334  template<typename T>
335  class HERMES_API DiscontinuousFunc : public Func < T >
336  {
337  public:
342 
344  T *val;
346  T *dx, *dy;
350  T *dx_neighbor, *dy_neighbor;
351 
358  DiscontinuousFunc(Func<T>* fn, bool support_on_neighbor, bool reverse = false);
359 
366  DiscontinuousFunc(Func<T>* fn_c, Func<T>* fn_n, bool reverse = false);
367 
368  virtual ~DiscontinuousFunc();
369  void free();
370 
371  using Func<T>::subtract;
372  void subtract(const DiscontinuousFunc<T>& func);
373 
378  static T zero;
379  };
380 
381  template<>
382  class HERMES_API DiscontinuousFunc<Ord> : public Func < Ord >
383  {
384  public:
389 
390  Ord val;
391  Ord dx, dy;
392  Ord val_neighbor;
393  Ord dx_neighbor, dy_neighbor;
394 
401  DiscontinuousFunc(Func<Ord>* fn, bool support_on_neighbor, bool reverse = false);
402 
409  DiscontinuousFunc(Func<Ord>* fn_c, Func<Ord>* fn_n, bool reverse = false);
410 
411  using Func<Ord>::subtract;
412  void subtract(const DiscontinuousFunc<Ord>& func);
413 
418  static Ord zero;
419  };
420 
422  HERMES_API Func<double>* init_fn(PrecalcShapeset *fu, RefMap *rm, const int order);
424  template<typename Scalar>
425  HERMES_API Func<Scalar>* init_fn(MeshFunction<Scalar>* fu, const int order);
426 
428  template<typename Scalar>
429  HERMES_API Func<Scalar>* preallocate_fn(pj_pool_t* memoryPool = nullptr);
430 
432  HERMES_API void init_fn_preallocated(Func<double>* u, PrecalcShapeset *fu, RefMap *rm, const int order);
434  template<typename Scalar>
435  HERMES_API void init_fn_preallocated(Func<Scalar>* u, MeshFunction<Scalar>* fu, const int order);
437  template<typename Scalar>
438  HERMES_API void init_fn_preallocated(Func<Scalar>* u, UExtFunction<Scalar>* fu, Func<Scalar>** ext, Func<Scalar>** u_ext, const int order, Geom<double>* geometry, ElementMode2D mode);
439 
442  template<typename Scalar>
443  HERMES_API Func<Scalar>* init_zero_fn(ElementMode2D mode, int order, Quad2D* quad_2d = nullptr, int nc = 1);
444 
446  template<typename Scalar>
447  HERMES_API Func<Scalar>* init_fn(UExtFunction<Scalar>* fu, Func<Scalar>** ext, Func<Scalar>** u_ext, const int order, Geom<double>* geometry, ElementMode2D mode);
448 #pragma endregion
449  }
450 }
451 #endif
Definition: adapt.h:24
T * dx
First-order partial derivatives.
Definition: forms.h:346
Function operating on previous nonlinear solutions in assembling (u_ext)
T * dx_neighbor
First-order partial derivatives.
Definition: forms.h:350
HERMES_API void init_geom_surf_allocated(GeomSurf< double > &geom, RefMap *rm, unsigned char isurf, int marker, const int order, double3 *&tan)
Init element geometry for surface integrals.
Definition: forms.cpp:444
Hermes::Ord get_diam_approximation(unsigned char n)
Element diameter approximation.
Definition: forms.h:104
Stores one element of a mesh.
Definition: element.h:107
bool reverse_neighbor_side
True if values from the neighbor have to be retrieved in reverse order.
Definition: forms.h:375
Caches precalculated shape function values.
Definition: precalc.h:32
int id
ID number of the element.
Definition: forms.h:58
This class represents a function with jump discontinuity on an interface of two elements.
Definition: forms.h:335
int elem_marker
Element marker (for both volumetric and surface forms).
Definition: forms.h:49
Geometry (coordinates, normals, tangents) of either an element or an edge.
Definition: forms.h:40
int elem_marker
Element marker (for both volumetric and surface forms).
Definition: forms.h:101
int nc
Number of components. Currently accepted values are 1 (H1, L2 space) and 2 (Hcurl, Hdiv space).
Definition: forms.h:290
Represents a function defined on a mesh.
Definition: mesh_function.h:56
T * val_neighbor
Function values. If T == Hermes::Ord and orders vary with direction, this returns max(h_order...
Definition: forms.h:348
HERMES_API void init_geom_vol_allocated(GeomVol< double > &geom, RefMap *rm, const int order)
Init element geometry for volumetric integrals.
Definition: forms.cpp:425
Hermes::Ord get_area(unsigned char n, double *wt)
Element area.
Definition: forms.h:106
Common definitions for Hermes2D.
Func< T > * fn_neighbor
Neighbor element's component.
Definition: forms.h:341
Func< T > * fn_central
Central element's component.
Definition: forms.h:339
HERMES_API Func< double > * init_fn(PrecalcShapeset *fu, RefMap *rm, const int order)
Init the shape function for the evaluation of the volumetric/surface integral (transformation of valu...
Definition: forms.cpp:469
unsigned char isurf
Internal number of an edge of the element.
Definition: forms.h:159
T * val
Function values. If T == Hermes::Ord and orders vary with direction, this returns max(h_order...
Definition: forms.h:344
int edge_marker
Edge marker.
Definition: forms.h:80
HERMES_API Func< Scalar > * preallocate_fn(pj_pool_t *memoryPool=nullptr)
Preallocate the Func (all we need is np & nc).
Definition: forms.cpp:489
unsigned char isurf
Internal number of an edge of the element.
Definition: forms.h:77
int np
Number of integration points used by this intance.
Definition: forms.h:288
HERMES_API GeomSurf< double > * init_geom_surf(RefMap *rm, unsigned char isurf, int marker, const int order, double3 *&tan)
Init element geometry for surface integrals.
Definition: forms.cpp:437
HERMES_API void init_fn_preallocated(Func< double > *u, PrecalcShapeset *fu, RefMap *rm, const int order)
Init the shape function for the evaluation of the volumetric/surface integral (transformation of valu...
Definition: forms.cpp:497
int np
Number of integration points used by this intance.
Definition: forms.h:248
int elem_marker
Element marker (for both volumetric and surface forms).
Definition: forms.h:149
int edge_marker
Edge marker.
Definition: forms.h:151
HERMES_API GeomVol< double > * init_geom_vol(RefMap *rm, const int order)
Init element geometry for volumetric integrals.
Definition: forms.cpp:418
Calculated function values (from the class Function) on an element for assembling.
Definition: forms.h:214
Hermes::Ord get_area(unsigned char n, double *wt)
Element area.
Definition: forms.h:191
Func< Ord > * fn_central
Central element's component.
Definition: forms.h:386
Represents the reference mapping.
Definition: refmap.h:40
unsigned char np
For InterfaceGeom purposes.
Definition: forms.h:126
bool reverse_neighbor_side
True if values from the neighbor have to be retrieved in reverse order.
Definition: forms.h:415
Hermes::Ord get_diam_approximation(unsigned char n)
Element diameter approximation.
Definition: forms.h:189
int nc
Number of components. Currently accepted values are 1 (H1, L2 space) and 2 (Hcurl, Hdiv space).
Definition: forms.h:250
HERMES_API Func< Scalar > * init_zero_fn(ElementMode2D mode, int order, Quad2D *quad_2d=nullptr, int nc=1)
Definition: forms.cpp:733
Func< Ord > * fn_neighbor
Neighbor element's component.
Definition: forms.h:388