Hermes2D  3.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/exact_solution.h"
20 
21 namespace Hermes
22 {
23  namespace Hermes2D
24  {
25 #pragma region forward-declarations
26  class RefMap;
27  template<typename Scalar> class DiscreteProblem;
28  template<typename Scalar> class DiscreteProblemSelectiveAssembler;
29  template<typename Scalar> class DiscreteProblemIntegrationOrderCalculator;
30  template<typename Scalar> class RungeKutta;
31  template<typename Scalar> class Space;
32  template<typename Scalar> class MeshFunction;
33  struct SurfPos;
34 
35  class Element;
36  class Shapeset;
37  template<typename T> class Func;
38  template<typename T> class DiscontinuousFunc;
39  template<typename T> class InterfaceGeom;
40  template<typename T> class GeomVol;
41  template<typename T> class GeomSurf;
42 
43  template<typename Scalar> class Form;
44  template<typename Scalar> class OGProjection;
45  template<typename Scalar> class MatrixFormVol;
46  template<typename Scalar> class VectorFormVol;
47  template<typename Scalar> class MatrixFormSurf;
48  template<typename Scalar> class VectorFormSurf;
49  template<typename Scalar> class MatrixFormDG;
50  template<typename Scalar> class VectorFormDG;
51 #pragma endregion
52 
54  template<typename Scalar>
55  class HERMES_API WeakFormSharedPtr : public std::tr1::shared_ptr < Hermes::Hermes2D::WeakForm<Scalar> >
56  {
57  public:
59 
61 
62  void operator=(const WeakFormSharedPtr<Scalar>& other);
63  };
64 
75  template<typename Scalar>
76  class HERMES_API WeakForm : public Hermes::Mixins::IntegrableWithGlobalOrder, public Hermes::Mixins::Loggable
77  {
78  public:
84  WeakForm(unsigned int neq = 1, bool mat_free = false);
85 
87  virtual ~WeakForm();
88 
89  enum FormIntegrationDimension
90  {
91  FormVol = 0,
92  FormSurf = 1
93  };
94 
95  enum FormEquationSide
96  {
97  MatrixForm = 0,
98  VectorForm = 1
99  };
100 
102  void add_matrix_form(MatrixFormVol<Scalar>* mfv);
103 
105  void add_matrix_form_surf(MatrixFormSurf<Scalar>* mfs);
106 
108  void add_matrix_form_DG(MatrixFormDG<Scalar>* mfDG);
109 
111  void add_vector_form(VectorFormVol<Scalar>* vfv);
112 
114  void add_vector_form_surf(VectorFormSurf<Scalar>* vfs);
115 
117  void add_vector_form_DG(VectorFormDG<Scalar>* vfDG);
118 
123  virtual void set_active_state(Element** e);
124 
129  virtual void set_active_edge_state(Element** e, unsigned char isurf);
130 
135  virtual void set_active_DG_state(Element** e, unsigned char isurf);
136 
138  inline unsigned char get_neq() const { return neq; }
139 
141  bool is_matrix_free() const { return is_matfree; }
142 
145  void set_current_time(double time);
146 
149  void set_current_time_step(double time_step);
150 
153  virtual double get_current_time() const;
154 
157  virtual double get_current_time_step() const;
158 
162  void set_u_ext_fn(UExtFunctionSharedPtr<Scalar> ext);
163 
167  void set_ext(MeshFunctionSharedPtr<Scalar> ext);
168 
172  void set_u_ext_fn(std::vector<UExtFunctionSharedPtr<Scalar> > ext);
173 
177  void set_ext(std::vector<MeshFunctionSharedPtr<Scalar> > ext);
178 
181  std::vector<MeshFunctionSharedPtr<Scalar> > get_ext() const;
182 
184  virtual WeakForm* clone() const;
185 
186  // Checks presence of DG forms.
187  bool is_DG() const;
188 
190  std::vector<Form<Scalar> *> get_forms() const;
191  std::vector<MatrixFormVol<Scalar> *> get_mfvol() const;
192  std::vector<MatrixFormSurf<Scalar> *> get_mfsurf() const;
193  std::vector<MatrixFormDG<Scalar> *> get_mfDG() const;
194  std::vector<VectorFormVol<Scalar> *> get_vfvol() const;
195  std::vector<VectorFormSurf<Scalar> *> get_vfsurf() const;
196  std::vector<VectorFormDG<Scalar> *> get_vfDG() const;
197 
199  void delete_all();
200 
201  protected:
203  std::vector<MeshFunctionSharedPtr<Scalar> > ext;
204  std::vector<UExtFunctionSharedPtr<Scalar> > u_ext_fn;
205 
206  double current_time;
207  double current_time_step;
208 
210  unsigned int neq;
211 
213  unsigned int original_neq;
214 
215  bool is_matfree;
216 
218  std::vector<Form<Scalar> *> forms;
219 
221  std::vector<MatrixFormVol<Scalar> *> mfvol;
222 
224  std::vector<MatrixFormSurf<Scalar> *> mfsurf;
225 
227  std::vector<MatrixFormDG<Scalar> *> mfDG;
228 
230  std::vector<VectorFormVol<Scalar> *> vfvol;
231 
233  std::vector<VectorFormSurf<Scalar> *> vfsurf;
234 
236  std::vector<VectorFormDG<Scalar> *> vfDG;
237 
238  bool** get_blocks(bool force_diagonal_blocks) const;
239 
240  friend class DiscreteProblem < Scalar > ;
241  friend class Form < Scalar > ;
242  friend class DiscreteProblemDGAssembler < Scalar > ;
243  friend class DiscreteProblemThreadAssembler < Scalar > ;
244  friend class DiscreteProblemIntegrationOrderCalculator < Scalar > ;
245  friend class DiscreteProblemSelectiveAssembler < Scalar > ;
246  friend class RungeKutta < Scalar > ;
247  friend class OGProjection < Scalar > ;
248  friend class Hermes::Preconditioners::Precond < Scalar > ;
249 
250  // Internal.
251  virtual void cloneMembers(const WeakFormSharedPtr<Scalar>& other_wf);
252  // Internal.
253  void cloneMemberExtFunctions(std::vector<MeshFunctionSharedPtr<Scalar> > source_ext, std::vector<MeshFunctionSharedPtr<Scalar> >& cloned_ext);
254 
255  // Internal - processes markers, translates from strings to ints.
256  template<typename FormType>
257  void processFormMarkers(const std::vector<SpaceSharedPtr<Scalar> > spaces, bool surface, std::vector<FormType> forms_to_process);
258  void processFormMarkers(const std::vector<SpaceSharedPtr<Scalar> > spaces);
259 
260  private:
261  void free_ext();
262  };
263 
269  template<typename Scalar>
270  class HERMES_API Form
271  {
272  public:
274  Form(int i = 0);
275  virtual ~Form();
276 
279  void set_area(std::string area);
280  void set_areas(std::vector<std::string> areas);
281  std::vector<std::string> getAreas() const;
282 
288  void set_ext(MeshFunctionSharedPtr<Scalar> ext);
289  void set_u_ext_fn(UExtFunctionSharedPtr<Scalar> ext);
290 
293  void set_ext(std::vector<MeshFunctionSharedPtr<Scalar> > ext);
294  void set_u_ext_fn(std::vector<UExtFunctionSharedPtr<Scalar> > ext);
295  std::vector<MeshFunctionSharedPtr<Scalar> > get_ext() const;
296 
298  void setScalingFactor(double scalingFactor);
299 
300  unsigned int i;
301 
302  protected:
304  void set_weakform(WeakForm<Scalar>* wf);
305 
307  std::vector<std::string> areas;
308 
310  std::vector<int> areas_internal;
311 
315 
321 
326 
328  std::vector<MeshFunctionSharedPtr<Scalar> > ext;
329  std::vector<UExtFunctionSharedPtr<Scalar> > u_ext_fn;
330 
331  double get_current_stage_time() const;
332 
333  WeakForm<Scalar>* wf;
334  private:
335  double stage_time;
336  void set_uExtOffset(int u_ext_offset);
338  double scaling_factor;
341  void set_current_stage_time(double time);
343  void copy_base(Form<Scalar>* other_form);
344  friend class WeakForm < Scalar > ;
345  friend class RungeKutta < Scalar > ;
346  friend class DiscreteProblem < Scalar > ;
347  friend class DiscreteProblemDGAssembler < Scalar > ;
348  friend class DiscreteProblemIntegrationOrderCalculator < Scalar > ;
349  friend class DiscreteProblemSelectiveAssembler < Scalar > ;
350  friend class DiscreteProblemThreadAssembler < Scalar > ;
351  };
352 
356  template<typename Scalar>
357  class HERMES_API MatrixForm : public Form < Scalar >
358  {
359  public:
361  MatrixForm(unsigned int i, unsigned int j);
362 
363  virtual ~MatrixForm();
364 
365  unsigned int j;
366 
367  SymFlag sym;
368 
369  protected:
370  friend class DiscreteProblem < Scalar > ;
371  };
372 
374  template<typename Scalar>
375  class HERMES_API MatrixFormVol : public MatrixForm < Scalar >
376  {
377  public:
379  MatrixFormVol(unsigned int i, unsigned int j);
380 
381  void setSymFlag(SymFlag sym);
382  SymFlag getSymFlag() const;
383 
384  virtual ~MatrixFormVol();
385 
386  virtual Scalar value(int n, double *wt, Func<Scalar> **u_ext, Func<double> *u, Func<double> *v,
387  GeomVol<double> *e, Func<Scalar> **ext) const;
388 
389  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> **u_ext, Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
390  GeomVol<Hermes::Ord> *e, Func<Ord> **ext) const;
391 
392  virtual MatrixFormVol* clone() const;
393  };
394 
396  template<typename Scalar>
397  class HERMES_API MatrixFormSurf : public MatrixForm < Scalar >
398  {
399  public:
401  MatrixFormSurf(unsigned int i, unsigned int j);
402 
403  virtual ~MatrixFormSurf();
404 
405  virtual Scalar value(int n, double *wt, Func<Scalar> **u_ext, Func<double> *u, Func<double> *v,
406  GeomSurf<double> *e, Func<Scalar> **ext) const;
407 
408  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> **u_ext, Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
409  GeomSurf<Hermes::Ord> *e, Func<Ord> **ext) const;
410 
411  virtual MatrixFormSurf* clone() const;
412  };
413 
415  template<typename Scalar>
416  class HERMES_API MatrixFormDG : public Form < Scalar >
417  {
418  public:
420  MatrixFormDG(unsigned int i, unsigned int j);
421 
422  virtual ~MatrixFormDG();
423 
424  unsigned int j;
425 
426  virtual Scalar value(int n, double *wt, DiscontinuousFunc<Scalar> **u_ext, DiscontinuousFunc<double> *u, DiscontinuousFunc<double> *v,
427  InterfaceGeom<double> *e, DiscontinuousFunc<Scalar> **ext) const;
428 
429  virtual Hermes::Ord ord(int n, double *wt, DiscontinuousFunc<Hermes::Ord> **u_ext, DiscontinuousFunc<Hermes::Ord> *u, DiscontinuousFunc<Hermes::Ord> *v,
430  InterfaceGeom<Hermes::Ord> *e, DiscontinuousFunc<Ord> **ext) const;
431 
432  virtual MatrixFormDG* clone() const;
433  protected:
434  friend class DiscreteProblem < Scalar > ;
435  };
436 
438  template<typename Scalar>
439  class VectorForm : public Form < Scalar >
440  {
441  public:
443  VectorForm(unsigned int i);
444 
445  virtual ~VectorForm();
446 
447  protected:
448  friend class DiscreteProblem < Scalar > ;
449  };
450 
452  template<typename Scalar>
453  class VectorFormVol : public VectorForm < Scalar >
454  {
455  public:
457  VectorFormVol(unsigned int i);
458 
459  virtual ~VectorFormVol();
460 
461  virtual Scalar value(int n, double *wt, Func<Scalar> **u_ext, Func<double> *v,
462  GeomVol<double> *e, Func<Scalar> **ext) const;
463 
464  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> **u_ext, Func<Hermes::Ord> *v, GeomVol<Hermes::Ord> *e,
465  Func<Ord> **ext) const;
466 
467  virtual VectorFormVol* clone() const;
468  };
469 
471  template<typename Scalar>
472  class VectorFormSurf : public VectorForm < Scalar >
473  {
474  public:
476  VectorFormSurf(unsigned int i);
477 
478  virtual ~VectorFormSurf();
479 
480  virtual Scalar value(int n, double *wt, Func<Scalar> **u_ext, Func<double> *v,
481  GeomSurf<double> *e, Func<Scalar> **ext) const;
482 
483  virtual Hermes::Ord ord(int n, double *wt, Func<Hermes::Ord> **u_ext, Func<Hermes::Ord> *v, GeomSurf<Hermes::Ord> *e,
484  Func<Ord> **ext) const;
485 
486  virtual VectorFormSurf* clone() const;
487  };
488 
490  template<typename Scalar>
491  class VectorFormDG : public Form < Scalar >
492  {
493  public:
495  VectorFormDG(unsigned int i);
496 
497  virtual ~VectorFormDG();
498 
499  virtual Scalar value(int n, double *wt, DiscontinuousFunc<Scalar> **u_ext, Func<double> *v,
500  InterfaceGeom<double> *e, DiscontinuousFunc<Scalar> **ext) const;
501 
502  virtual Hermes::Ord ord(int n, double *wt, DiscontinuousFunc<Hermes::Ord> **u_ext, Func<Hermes::Ord> *v, InterfaceGeom<Hermes::Ord> *e,
503  DiscontinuousFunc<Ord> **ext) const;
504 
505  virtual VectorFormDG* clone() const;
506  protected:
507  friend class DiscreteProblem < Scalar > ;
508  };
509  }
510 }
511 #endif
VectorFormSurf(unsigned int i)
Constructor with coordinates.
Definition: weakform.cpp:565
VectorFormDG(unsigned int i)
Constructor with coordinates.
Definition: weakform.cpp:599
std::vector< MatrixFormSurf< Scalar > * > mfsurf
Holds surface matrix forms.
Definition: weakform.h:224
Geometry - volumetric - for order calculation.
Definition: forms.h:90
unsigned int original_neq
Original number of equations in case this is a Runge-Kutta enlarged system.
Definition: weakform.h:213
std::vector< MeshFunctionSharedPtr< Scalar > > ext
External solutions.
Definition: weakform.h:328
Definition: adapt.h:24
Abstract, base class for vector form - i.e. a single integral in the linear form on the right hand si...
Definition: weakform.h:439
Stores one element of a mesh.
Definition: element.h:107
This class represents a function with jump discontinuity on an interface of two elements.
Definition: forms.h:335
unsigned int neq
Number of equations.
Definition: weakform.h:210
Represents a function defined on a mesh.
Definition: mesh_function.h:56
Provides capabilities to (re-)assemble a matrix / vector only where necessary. See also Solver::keep_...
Class for (global) orthogonal projecting. If the projection is not necessary (if a solution belongs t...
Definition: ogprojection.h:29
std::vector< int > areas_internal
Internal - this structure is being filled anew with every assembling.
Definition: weakform.h:310
Used to pass the instances of Space around.
Definition: space.h:34
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
VectorFormVol(unsigned int i)
Constructor with coordinates.
Definition: weakform.cpp:531
std::vector< VectorFormSurf< Scalar > * > vfsurf
Holds surface vector forms.
Definition: weakform.h:233
Abstract, base class for vector Surface form - i.e. VectorForm, where the integration is with respect...
Definition: weakform.h:48
std::vector< Form< Scalar > * > forms
Holds all forms.
Definition: weakform.h:218
Determines the position on an element surface (edge in 2D and Face in 3D).
Definition: traverse.h:30
Abstract, base class for vector DG form - i.e. linear Form, where the integration is with respect to ...
Definition: weakform.h:50
Abstract, base class for any form - i.e. integral in the weak formulation of (a system of) PDE By de...
Definition: weakform.h:43
Abstract, base class for matrix Surface form - i.e. MatrixForm, where the integration is with respect...
Definition: weakform.h:47
SymFlag
Bilinear form symmetry flag, see WeakForm::add_matrix_form.
Definition: global.h:156
Represents the weak formulation of a PDE problem.
Definition: global.h:86
unsigned char get_neq() const
Returns the number of equations.
Definition: weakform.h:138
Abstract, base class for matrix form - i.e. a single integral in the bilinear form on the left hand s...
Definition: weakform.h:357
Used to pass the instances of WeakForm around.
Definition: weakform.h:55
Should be exactly the same as is the count of enum ShapesetType.
Definition: shapeset.h:95
Calculated function values (from the class Function) on an element for assembling.
Definition: forms.h:214
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Abstract, base class for matrix Volumetric form - i.e. MatrixForm, where the integration is with resp...
Definition: weakform.h:45
This class is a one-thread (non-DG) assembly worker.
unsigned int previous_iteration_space_index
Definition: weakform.h:325
Represents a finite element space over a domain.
Definition: api2d.h:34
std::vector< MatrixFormDG< Scalar > * > mfDG
Holds DG matrix forms.
Definition: weakform.h:227
std::vector< std::string > areas
Markers of the areas where this form will be assembled.
Definition: weakform.h:307
Abstract, base class for matrix DG form - i.e. bilinear form, where the integration is with respect t...
Definition: weakform.h:49
std::vector< VectorFormDG< Scalar > * > vfDG
Holds DG vector forms.
Definition: weakform.h:236
std::vector< MeshFunctionSharedPtr< Scalar > > ext
External solutions.
Definition: weakform.h:203
std::vector< MatrixFormVol< Scalar > * > mfvol
Holds volumetric matrix forms.
Definition: weakform.h:221
bool is_matrix_free() const
This weakform is matrix-free.
Definition: weakform.h:141
VectorForm(unsigned int i)
Constructor with coordinates.
Definition: weakform.cpp:519
std::vector< VectorFormVol< Scalar > * > vfvol
Holds volumetric vector forms.
Definition: weakform.h:230
Abstract, base class for vector Volumetric form - i.e. VectorForm, where the integration is with resp...
Definition: weakform.h:46