Hermes2D  2.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/solution.h"
25 #include "mesh/refmap.h"
26 #include "mesh/traverse.h"
27 #include <complex>
28 
29 namespace Hermes
30 {
31  namespace Hermes2D
32  {
33  static const char* ERR_UNDEFINED_NEIGHBORING_ELEMENTS =
34  "Neighboring elements are not defined and so are not function traces on their interface. "
35  "Did you forget setting H2D_ANY_INNER_EDGE in add_matrix/vector_form?";
36 
37  template<typename Scalar> class OGProjection;
38 
41  template<typename T>
42  class HERMES_API Func
43  {
44  public:
46 
48  Func(int num_gip, int num_comps);
49 
50  T *val;
51  T *dx, *dy;
52  T *laplace;
53  T *val0, *val1;
54  T *dx0, *dx1;
55  T *dy0, *dy1;
56  T *curl;
57  T *div;
58 
60  virtual T& get_val_central(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
62  virtual T& get_val_neighbor(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
64  virtual T& get_dx_central(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
66  virtual T& get_dx_neighbor(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
68  virtual T& get_dy_central(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
70  virtual T& get_dy_neighbor(int k) const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
72  virtual T& get_laplace_central(int k) { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
74  virtual T& get_laplace_neighbor(int k) { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return * new T; }
75 
77  virtual void free_ord();
78 
80  virtual void free_fn();
81 
87  virtual ~Func() { };
88 
89  void subtract(Func<T>* func);
90  void add(T* attribute, T* other_attribute);
91 
92  int get_num_gip() const;
93 
94  protected:
95  const int num_gip;
96  const int nc;
97 
99 
100  void subtract(T* attribute, T* other_attribute);
101 
103 
104  void add(Func<T>* func);
105 
106  friend Func<Hermes::Ord>* init_fn_ord(const int order);
107  friend Func<double>* init_fn(PrecalcShapeset *fu, RefMap *rm, const int order);
108  template<typename Scalar> friend Func<Scalar>* init_fn(MeshFunction<Scalar>*fu, const int order);
109  template<typename Scalar> friend Func<Scalar>* init_fn(Solution<Scalar>*fu, const int order);
110 
111  template<typename Scalar> friend class DiscontinuousFunc;
112  template<typename Scalar> friend class Adapt;
113  template<typename Scalar> friend class KellyTypeAdapt;
114  template<typename Scalar> friend class DiscreteProblem;
115  template<typename Scalar> friend class DiscreteProblemLinear;
116  template<typename Scalar> friend class BasicKellyAdapt;
117  template<typename Scalar> friend class Hermes::Hermes2D::OGProjection;
118  friend class ErrorEstimatorFormKelly;
119  };
120 
122 
135  template<typename T>
136  class HERMES_API DiscontinuousFunc : public Func<T>
137  {
138  public:
141 
143  virtual T& get_val_central(int k) const;
145  virtual T& get_val_neighbor(int k) const;
147  virtual T& get_dx_central(int k) const;
149  virtual T& get_dx_neighbor(int k) const;
151  virtual T& get_dy_central(int k) const;
153  virtual T& get_dy_neighbor(int k) const;
155  virtual T& get_laplace_central(int k);
157  virtual T& get_laplace_neighbor(int k);
158 
165  DiscontinuousFunc(Func<T>* fn, bool support_on_neighbor = false, bool reverse = false);
166 
173  DiscontinuousFunc(Func<T>* fn_c, Func<T>* fn_n, bool reverse = false);
174 
175  private:
176  void subtract(const DiscontinuousFunc<T>& func);
177 
181  virtual void free_fn();
182 
183  virtual void free_ord();
184 
185  bool reverse_neighbor_side;
186 
187  static T zero;
188  template<typename Scalar> friend class DiscreteProblem;
189  template<typename Scalar> friend class DiscreteProblemLinear;
190  template<typename Scalar> friend class KellyTypeAdapt;
191  template<typename Scalar> friend class Adapt;
192  template<typename Scalar> friend class NeighborSearch;
193  };
194 
197  template<typename T>
198  class HERMES_API Geom
199  {
200  public:
202  Geom();
203 
204  T diam;
205  T area;
206  T *x, *y;
207  T *nx, *ny;
208 
209 
210  T *tx, *ty;
211  int id;
212  int isurf;
213 
215  virtual int get_neighbor_marker() const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return -1; }
217  virtual int get_neighbor_id() const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return -1; }
219  virtual T get_neighbor_diam() const { throw Hermes::Exceptions::Exception(ERR_UNDEFINED_NEIGHBORING_ELEMENTS); return T(); }
220 
222  virtual ~Geom() {};
223 
225  virtual void free();
226  virtual void free_ord() {};
227  int elem_marker;
229 
230  protected:
231  int orientation;
232 
233 
234 
236  friend Geom<double>* init_geom_vol(RefMap *rm, const int order);
237  friend Geom<double>* init_geom_surf(RefMap *rm, int isurf, int marker, const int order, double3*& tan);
238 
239  template<typename Scalar> friend class DiscreteProblem;
240  template<typename Scalar> friend class DiscreteProblemLinear;
241  template<typename Scalar> friend class InterfaceGeom;
242  template<typename Scalar> friend class KellyTypeAdapt;
243  template<typename Scalar> friend class BasicKellyAdapt;
244  friend class ErrorEstimatorFormKelly;
245  template<typename Scalar> friend class Adapt;
246  };
247 
255  template<typename T>
256  class HERMES_API InterfaceGeom : public Geom<T>
257  {
258  public:
259  int neighb_id;
260  T neighb_diam;
261  int get_neighbor_marker() const;
262  int get_neighbor_id() const;
263  T get_neighbor_diam() const;
264 
265  private:
267  InterfaceGeom(Geom<T>* geom, int n_marker, int n_id, T n_diam);
268  Geom<T>* wrapped_geom;
269 
270  virtual void free();
271  virtual void free_ord();
272 
273  int neighb_marker;
274  template<typename Scalar> friend class DiscreteProblem;
275  template<typename Scalar> friend class DiscreteProblemLinear;
276  template<typename Scalar> friend class KellyTypeAdapt;
277  template<typename Scalar> friend class Adapt;
278  };
279 
281  HERMES_API Geom<Hermes::Ord>* init_geom_ord();
283  HERMES_API Geom<double>* init_geom_vol(RefMap *rm, const int order);
285  HERMES_API Geom<double>* init_geom_surf(RefMap *rm, int isurf, int marker, const int order, double3*& tan);
286 
288  HERMES_API Func<Hermes::Ord>* init_fn_ord(const int order);
290  HERMES_API Func<double>* init_fn(PrecalcShapeset *fu, RefMap *rm, const int order);
292  template<typename Scalar>
293  HERMES_API Func<Scalar>* init_fn(MeshFunction<Scalar>*fu, const int order);
295  template<typename Scalar>
296  HERMES_API Func<Scalar>* init_fn(Solution<Scalar>*fu, const int order);
297  }
298 }
299 #endif