Hermes2D  2.0
weakform.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 Licenserix
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_WEAKFORM_H
17 #define __H2D_WEAKFORM_H
18 
19 #include "../function/solution.h"
20 #include <string>
21 
22 namespace Hermes
23 {
24  namespace Hermes2D
25  {
27  enum GeomType
28  {
29  HERMES_PLANAR = 0, // Planar problem.
30  HERMES_AXISYM_X = 1, // Axisymmetric problem where x-axis is the axis of symmetry.
31  HERMES_AXISYM_Y = 2 // Axisymmetric problem where y-axis is the axis of symmetry.
32  };
33 
34  class RefMap;
35  template<typename Scalar> class DiscreteProblem;
36  template<typename Scalar> class DiscreteProblemLinear;
37  template<typename Scalar> class RungeKutta;
38  template<typename Scalar> class Space;
39  template<typename Scalar> class MeshFunction;
40  struct SurfPos;
41 
42  class Element;
43  class Shapeset;
44  template<typename T> class Func;
45  template<typename T> class Geom;
46 
47  template<typename Scalar> class Form;
48  template<typename Scalar> class OGProjection;
49  template<typename Scalar> class MatrixFormVol;
50  template<typename Scalar> class VectorFormVol;
51  template<typename Scalar> class MatrixFormSurf;
52  template<typename Scalar> class VectorFormSurf;
53  template<typename Scalar> class MatrixFormDG;
54  template<typename Scalar> class VectorFormDG;
55 
57  enum SymFlag
58  {
59  HERMES_ANTISYM = -1,
60  HERMES_NONSYM = 0,
61  HERMES_SYM = 1
62  };
63 
74  template<typename Scalar>
75  class HERMES_API WeakForm : public Hermes::Mixins::IntegrableWithGlobalOrder, public Hermes::Mixins::Loggable
76  {
77  public:
83  WeakForm(unsigned int neq = 1, bool mat_free = false);
84 
86  ~WeakForm();
87 
89  void add_matrix_form(MatrixFormVol<Scalar>* mfv);
90 
92  void add_matrix_form_surf(MatrixFormSurf<Scalar>* mfs);
93 
95  void add_matrix_form_DG(MatrixFormDG<Scalar>* mfDG);
96 
98  void add_vector_form(VectorFormVol<Scalar>* vfv);
99 
101  void add_vector_form_surf(VectorFormSurf<Scalar>* vfs);
102 
104  void add_vector_form_DG(VectorFormDG<Scalar>* vfDG);
105 
107  unsigned int get_neq() const { return neq; }
108 
109  bool is_matrix_free() const { return is_matfree; }
110 
112  void set_current_time(double time);
113  void set_current_time_step(double time_step);
114 
115  virtual double get_current_time() const;
116  virtual double get_current_time_step() const;
117 
118  Hermes::vector<Form<Scalar> *> get_forms() const;
119 
120  Hermes::vector<MatrixFormVol<Scalar> *> get_mfvol() const;
121  Hermes::vector<MatrixFormSurf<Scalar> *> get_mfsurf() const;
122  Hermes::vector<MatrixFormDG<Scalar> *> get_mfDG() const;
123 
124  Hermes::vector<VectorFormVol<Scalar> *> get_vfvol() const;
125  Hermes::vector<VectorFormSurf<Scalar> *> get_vfsurf() const;
126  Hermes::vector<VectorFormDG<Scalar> *> get_vfDG() const;
127 
129  void delete_all();
130 
132  void set_ext(MeshFunction<Scalar>* ext);
133  void set_ext(Hermes::vector<MeshFunction<Scalar>*> ext);
134  Hermes::vector<MeshFunction<Scalar>*> get_ext() const;
135 
136  virtual WeakForm* clone() const;
137 
138  protected:
140  Hermes::vector<MeshFunction<Scalar>*> ext;
141 
142  double current_time;
143  double current_time_step;
144 
145  unsigned int neq;
146 
147  bool is_matfree;
148 
150  Hermes::vector<Form<Scalar> *> forms;
151 
153  Hermes::vector<MatrixFormVol<Scalar> *> mfvol;
154 
156  Hermes::vector<MatrixFormSurf<Scalar> *> mfsurf;
157 
159  Hermes::vector<MatrixFormDG<Scalar> *> mfDG;
160 
162  Hermes::vector<VectorFormVol<Scalar> *> vfvol;
163 
165  Hermes::vector<VectorFormSurf<Scalar> *> vfsurf;
166 
168  Hermes::vector<VectorFormDG<Scalar> *> vfDG;
169 
170  bool** get_blocks(bool force_diagonal_blocks) const;
171 
172  friend class DiscreteProblem<Scalar>;
173  friend class DiscreteProblemLinear<Scalar>;
174  friend class RungeKutta<Scalar>;
175  friend class OGProjection<Scalar>;
176  friend class Hermes::Preconditioners::Precond<Scalar>;
177 
178  bool warned_nonOverride;
179 
180  // internal.
181  private:
182  void free_ext();
183  void cloneMembers(const WeakForm<Scalar>* otherWf);
184  };
185 
191  template<typename Scalar>
192  class HERMES_API Form
193  {
194  public:
196  Form();
197  virtual ~Form();
198 
201  void set_area(std::string area);
202  void set_areas(Hermes::vector<std::string> areas);
203  Hermes::vector<std::string> getAreas() const;
204 
208  void set_ext(MeshFunction<Scalar>* ext);
209  void set_ext(Hermes::vector<MeshFunction<Scalar>*> ext);
210  Hermes::vector<MeshFunction<Scalar>*> get_ext() const;
211 
212  protected:
214  inline void set_weakform(WeakForm<Scalar>* wf) { this->wf = wf; }
215 
217  Hermes::vector<std::string> areas;
218 
224 
226  Hermes::vector<MeshFunction<Scalar>*> ext;
227 
230  void set_current_stage_time(double time);
231 
232  double get_current_stage_time() const;
233 
236 
237  WeakForm<Scalar>* wf;
238  double stage_time;
239  void setScalingFactor(double scalingFactor);
240  void set_uExtOffset(int u_ext_offset);
241  friend class WeakForm<Scalar>;
242  friend class RungeKutta<Scalar>;
243  friend class DiscreteProblem<Scalar>;
244  friend class DiscreteProblemLinear<Scalar>;
245  };
246 
250  template<typename Scalar>
251  class HERMES_API MatrixForm : public Form<Scalar>
252  {
253  public:
255  MatrixForm(unsigned int i, unsigned int j);
256 
257  virtual ~MatrixForm();
258 
259  unsigned int i;
260  unsigned int j;
261  unsigned int previous_iteration_space_index;
262 
263  SymFlag sym;
264 
265  typedef Scalar valueFunction(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
266  Geom<double> *e, Func<Scalar> **ext) const;
267 
268  virtual Scalar value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
269  Geom<double> *e, Func<Scalar> **ext) const;
270 
271  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
272  Geom<Hermes::Ord> *e, Func<Ord> **ext) const;
273 
274  protected:
275  friend class DiscreteProblem<Scalar>;
276  };
277 
279  template<typename Scalar>
280  class HERMES_API MatrixFormVol : public MatrixForm<Scalar>
281  {
282  public:
284  MatrixFormVol(unsigned int i, unsigned int j);
285 
286  void setSymFlag(SymFlag sym);
287  SymFlag getSymFlag() const;
288 
289  virtual ~MatrixFormVol();
290 
291  virtual MatrixFormVol* clone() const;
292  };
293 
295  template<typename Scalar>
296  class HERMES_API MatrixFormSurf : public MatrixForm<Scalar>
297  {
298  public:
300  MatrixFormSurf(unsigned int i, unsigned int j);
301 
302  virtual ~MatrixFormSurf();
303 
304  virtual MatrixFormSurf* clone() const;
305  };
306 
308  template<typename Scalar>
309  class HERMES_API MatrixFormDG : public MatrixForm<Scalar>
310  {
311  public:
313  MatrixFormDG(unsigned int i, unsigned int j);
314 
315  virtual ~MatrixFormDG();
316 
317  virtual MatrixFormDG* clone() const;
318  };
319 
321  template<typename Scalar>
322  class VectorForm : public Form<Scalar>
323  {
324  public:
326  VectorForm(unsigned int i);
327 
328  virtual ~VectorForm();
329 
330  virtual Scalar value(int n, double *wt, Func<Scalar> *u_ext[], Func<double> *v,
331  Geom<double> *e, Func<Scalar> **ext) const;
332 
333  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *v, Geom<Hermes::Ord> *e,
334  Func<Ord> **ext) const;
335  unsigned int i;
336 
337  protected:
338  friend class DiscreteProblem<Scalar>;
339  };
340 
342  template<typename Scalar>
343  class VectorFormVol : public VectorForm<Scalar>
344  {
345  public:
347  VectorFormVol(unsigned int i);
348 
349  virtual ~VectorFormVol();
350 
351  virtual VectorFormVol* clone() const;
352  };
353 
355  template<typename Scalar>
356  class VectorFormSurf : public VectorForm<Scalar>
357  {
358  public:
360  VectorFormSurf(unsigned int i);
361 
362  virtual ~VectorFormSurf();
363 
364  virtual VectorFormSurf* clone() const;
365  };
366 
368  template<typename Scalar>
369  class VectorFormDG : public VectorForm<Scalar>
370  {
371  public:
373  VectorFormDG(unsigned int i);
374 
375  virtual ~VectorFormDG();
376 
377  virtual VectorFormDG* clone() const;
378  };
379  }
380 }
381 #endif