Hermes2D  3.0
space.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_SPACE_H
17 #define __H2D_SPACE_H
18 
19 #include "../shapeset/shapeset.h"
20 #include "asmlist.h"
21 #include "../boundary_conditions/essential_boundary_conditions.h"
22 #include "../mesh/traverse.h"
23 #include "../quadrature/quad_all.h"
24 #include "algebra/dense_matrix_operations.h"
25 
27 
28 namespace Hermes
29 {
30  namespace Hermes2D
31  {
33  template<typename Scalar>
34  class HERMES_API SpaceSharedPtr : public std::tr1::shared_ptr < Hermes::Hermes2D::Space<Scalar> >
35  {
36  public:
38 
40 
41  void operator=(const SpaceSharedPtr<Scalar>& other);
42  };
43 
44  namespace Mixins
45  {
48  template<typename Scalar>
49  class HERMES_API SettableSpaces
50  {
51  public:
53  virtual void set_spaces(std::vector<SpaceSharedPtr<Scalar> > spaces) = 0;
54  virtual void set_space(SpaceSharedPtr<Scalar> space);
56  virtual std::vector<SpaceSharedPtr<Scalar> > get_spaces();
57  virtual SpaceSharedPtr<Scalar> get_space(int n);
58  };
59  }
60 
61  template<typename Scalar> class Adapt;
62  template<typename Scalar> class DiscreteProblem;
63  template<typename Scalar> class DiscreteProblemDGAssembler;
64  template<typename Scalar> class DiscreteProblemThreadAssembler;
65  template<typename Scalar> class DiscreteProblemIntegrationOrderCalculator;
66  namespace Views
67  {
68  template<typename Scalar> class BaseView;
69  template<typename Scalar> class VectorBaseView;
70  class Orderizer;
71  class OrderView;
72  };
73  class Shapeset;
74 
75  template<typename Scalar> class L2Space;
76  template<typename Scalar> class H1Space;
77  template<typename Scalar> class HcurlSpace;
78  template<typename Scalar> class HdivSpace;
79 
131  template<typename Scalar>
132  class HERMES_API Space : public Hermes::Mixins::Loggable, public Hermes::Mixins::StateQueryable, public Hermes::Hermes2D::Mixins::XMLParsing
133  {
134  public:
135  Space();
136  Space(MeshSharedPtr mesh, Shapeset* shapeset, EssentialBCs<Scalar>* essential_bcs);
137 
139  void init();
140 
142  virtual void init(Shapeset* shapeset, int p_init, bool assign_dofs_init = true) = 0;
143 
145  virtual ~Space();
146 
148  void free();
150  void free_bc_data();
151 
152 #pragma region Getters
153  inline int get_element_order(int id) const {
155  return edata[id].order;
156  }
157 
159  int get_num_dofs() const;
160 
162  static int get_num_dofs(std::vector<SpaceSharedPtr<Scalar> > spaces);
163 
165  static int get_num_dofs(SpaceSharedPtr<Scalar> space);
166 
167  MeshSharedPtr get_mesh() const;
168 
170  virtual SpaceType get_type() const = 0;
171 
174  int get_vertex_functions_count();
176  int get_edge_functions_count();
178  int get_bubble_functions_count();
179 
181  int get_seq() const;
182 
184  EssentialBCs<Scalar>* get_essential_bcs() const;
185 
187  virtual void get_element_assembly_list(Element* e, AsmList<Scalar>* al) const;
188 
190  virtual int get_edge_order(Element* e, int edge) const;
191 
193  int get_max_dof() const;
194 
196  void get_boundary_assembly_list(Element* e, int surf_num, AsmList<Scalar>* al) const;
197 
198  Shapeset* get_shapeset() const;
199 #pragma endregion
200 
201 #pragma region Setters
202  virtual void set_shapeset(Shapeset* shapeset, bool clone = false) = 0;
204 
206  void set_mesh(MeshSharedPtr mesh);
207 
209  void set_mesh_seq(int seq);
210 
212  void set_essential_bcs(EssentialBCs<Scalar>* essential_bcs);
213 #pragma endregion
214 
215 #pragma region Order setting
216  virtual void set_element_order(int id, int order, int order_v = -1);
219 
222  void set_uniform_order(int order, std::string marker = HERMES_ANY);
223 
226  void adjust_element_order(int order_change, int min_order);
227 
229  void adjust_element_order(int horizontal_order_change, int vertical_order_change, unsigned int horizontal_min_order, unsigned int vertical_min_order);
230 
233  void set_uniform_order_internal(int order, int marker);
234 
241  virtual int assign_dofs(int first_dof = 0);
242 
244  static int assign_dofs(std::vector<SpaceSharedPtr<Scalar> > spaces);
245 #pragma endregion
246 
247 #pragma region Mesh handling
248  void unrefine_all_mesh_elements(bool keep_initial_refinements = true);
253 
256  static void unrefine_all_mesh_elements(std::vector<SpaceSharedPtr<Scalar> > spaces, bool keep_initial_refinements = true);
257 #pragma endregion
258 
259 #pragma region Boundary conditions
260  virtual Scalar* get_bc_projection(SurfPos* surf_pos, int order, EssentialBoundaryCondition<Scalar> *bc) = 0;
261 
264  void update_essential_bc_values();
265 
266  static void update_essential_bc_values(std::vector<SpaceSharedPtr<Scalar> > spaces, double time);
267 
268  static void update_essential_bc_values(SpaceSharedPtr<Scalar> space, double time);
269 #pragma endregion
270 
271 #pragma region Save & Load
272  void save(const char *filename) const;
274 #ifdef WITH_BSON
275  void save_bson(const char* filename) const;
276 #endif
277 
279  static SpaceSharedPtr<Scalar> load(const char *filename, MeshSharedPtr mesh, bool validate = false, EssentialBCs<Scalar>* essential_bcs = nullptr, Shapeset* shapeset = nullptr);
281  void load(const char *filename);
282 
283 #ifdef WITH_BSON
284  static SpaceSharedPtr<Scalar> load_bson(const char *filename, MeshSharedPtr mesh, EssentialBCs<Scalar>* essential_bcs = nullptr, Shapeset* shapeset = nullptr);
287  void load_bson(const char *filename);
288 #endif
289 #pragma endregion
290 
293  virtual void copy(SpaceSharedPtr<Scalar> space, MeshSharedPtr new_mesh);
294 
296  class HERMES_API ReferenceSpaceCreator
297  {
298  public:
301  ReferenceSpaceCreator(unsigned int order_increase = 1);
306  ReferenceSpaceCreator(SpaceSharedPtr<Scalar> coarse_space, MeshSharedPtr ref_mesh, unsigned int order_increase = 1);
307 
310  virtual void handle_orders(SpaceSharedPtr<Scalar> ref_space);
311 
313  virtual SpaceSharedPtr<Scalar> create_ref_space(bool assign_dofs = true);
314  virtual SpaceSharedPtr<Scalar> create_ref_space(SpaceSharedPtr<Scalar> coarse_space, MeshSharedPtr ref_mesh, bool assign_dofs = true);
315 
316  private:
318  SpaceSharedPtr<Scalar> init_construction_l2();
319  SpaceSharedPtr<Scalar> init_construction_h1();
320  SpaceSharedPtr<Scalar> init_construction_hcurl();
321  SpaceSharedPtr<Scalar> init_construction_hdiv();
322 
324  virtual void finish_construction(SpaceSharedPtr<Scalar> ref_space);
325 
327  SpaceSharedPtr<Scalar> coarse_space;
328  MeshSharedPtr ref_mesh;
329  unsigned int order_increase;
330  };
331 
332  protected:
333 
336  virtual void set_element_order_internal(int id, int order, int order_v = -1);
337 
339  void distribute_orders(MeshSharedPtr mesh, int* parents);
340 
342  bool is_up_to_date() const;
343 
344  static Node* get_mid_edge_vertex_node(Element* e, unsigned char i, unsigned char j);
345 
347  virtual bool isOkay() const;
348  inline std::string getClassName() const { return "Space"; }
349 
351  int ndof;
352 
354  static const int H2D_UNASSIGNED_DOF = -2;
356  static const int H2D_CONSTRAINED_DOF = -1;
357 
358  Shapeset* shapeset;
361 
364 
366  MeshSharedPtr mesh;
367 
369  int vertex_functions_count, edge_functions_count, bubble_functions_count;
370 
372  int first_dof, next_dof;
373 
375  unsigned int seq;
377  unsigned int seq_assigned;
379  int mesh_seq;
380 
382  {
383  int dof;
384  Scalar coef;
385  };
386 
387  union NodeData
388  {
389  struct // regular node
390  {
391  int dof;
392  union {
393  Scalar* edge_bc_proj;
394  Scalar* vertex_bc_coef;
395  };
398  short n;
399  };
400  struct // constrained vertex node
401  {
402  BaseComponent* baselist;
403  int ncomponents;
404  };
405  struct // constrained edge node
406  {
407  Node* base;
408  int part;
409  };
410  NodeData() : dof(0), edge_bc_proj(nullptr) {}
411  };
412 
414  {
415  public:
416  ElementData() : changed_in_last_adaptation(true) {};
417  short order;
418  int bdof;
419  short n;
420  bool changed_in_last_adaptation;
421  };
422 
426  int nsize;
430  int esize;
431 
433  virtual int get_edge_order_internal(Node* en) const;
434 
441  void unrefine_all_mesh_elements_internal(bool keep_initial_refinements, bool only_unrefine_space_data);
442 
450  virtual void resize_tables();
451 
452  void update_orders_recurrent(Element* e, int order);
453 
455  virtual void reset_dof_assignment();
456  virtual void assign_vertex_dofs() = 0;
457  virtual void assign_edge_dofs() = 0;
458  virtual void assign_bubble_dofs() = 0;
459 
460  virtual void get_vertex_assembly_list(Element* e, int iv, AsmList<Scalar>* al) const = 0;
461  virtual void get_boundary_assembly_list_internal(Element* e, int surf_num, AsmList<Scalar>* al) const = 0;
462  virtual void get_bubble_assembly_list(Element* e, AsmList<Scalar>* al) const;
463 
464  double** proj_mat;
465  double* chol_p;
466 
468  std::vector<Scalar*> bc_data_projections;
469  std::vector<typename Space<Scalar>::BaseComponent*> bc_data_base_components;
470 
471  void precalculate_projection_matrix(int nv, double**& mat, double*& p);
472  void update_edge_bc(Element* e, SurfPos* surf_pos);
473 
477  virtual void update_constraints();
478 
481  virtual void post_assign();
482 
486  static SpaceSharedPtr<Scalar> init_empty_space(SpaceType spaceType, MeshSharedPtr mesh, Shapeset* shapeset);
487 
488  struct EdgeInfo
489  {
490  Node* node;
491  int part;
492  int ori;
493  double lo, hi;
494  };
495 
496  template<typename T> friend class OGProjection;
497  template<typename T> friend class NewtonSolver;
498  template<typename T> friend class PicardSolver;
499  template<typename T> friend class LinearSolver;
500  template<typename T> friend class OGProjectionNOX;
501  template<typename T> friend class Solution;
502  template<typename T> friend class RungeKutta;
503  template<typename T> friend class ExactSolution;
504  template<typename T> friend class NeighborSearch;
505  template<typename T> friend class ExactSolutionScalar;
506  template<typename T> friend class ExactSolutionVector;
507  template<typename T> friend class Views::BaseView;
508  friend class Views::Orderizer;
509  friend class Views::OrderView;
510  template<typename T> friend class Views::VectorBaseView;
511  friend class Adapt < Scalar > ;
512  friend class DiscreteProblem < Scalar > ;
513  friend class DiscreteProblemDGAssembler < Scalar > ;
514  friend class DiscreteProblemThreadAssembler < Scalar > ;
515  friend class DiscreteProblemIntegrationOrderCalculator < Scalar > ;
516  };
517  }
518 }
519 #endif
::xsd::cxx::tree::id< char, ncname > id
C++ type corresponding to the ID XML Schema built-in type.
int first_dof
For equation systems.
Definition: space.h:372
Definition: adapt.h:24
int ndof
Number of degrees of freedom (dimension of the space).
Definition: space.h:351
int vertex_functions_count
For statistics.
Definition: space.h:369
int mesh_seq
Tracking changes - mesh.
Definition: space.h:379
Stores one element of a mesh.
Definition: element.h:107
Class for (global) orthogonal projecting. If the projection is not necessary (if a solution belongs t...
Definition: ogprojection.h:29
std::vector< Scalar * > bc_data_projections
Used for bc projection.
Definition: space.h:468
Used to pass the instances of Space around.
Definition: space.h:34
Stores one node of a mesh.
Definition: element.h:45
::xsd::cxx::tree::time< char, simple_type > time
C++ type corresponding to the time XML Schema built-in type.
bool own_shapeset
true if default shapeset is created in the constructor, false if shapeset is supplied by user...
Definition: space.h:360
Determines the position on an element surface (edge in 2D and Face in 3D).
Definition: traverse.h:30
Visualizes the basis functions of a space.
Definition: space.h:68
unsigned int seq_assigned
Tracking changes - mark call to assign_dofs().
Definition: space.h:377
NodeData * ndata
node data table
Definition: space.h:424
Should be exactly the same as is the count of enum ShapesetType.
Definition: shapeset.h:95
Represents an exact solution of a PDE.
int esize
element data table size
Definition: space.h:430
Class for creating reference space.
Definition: space.h:296
ElementData * edata
element data table
Definition: space.h:428
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Displays the polynomial degrees of elements.
Definition: order_view.h:36
This class is a one-thread (non-DG) assembly worker.
Represents a finite element space over a domain.
Definition: api2d.h:34
MeshSharedPtr mesh
FE mesh.
Definition: space.h:366
This class characterizes a neighborhood of a given edge in terms of adjacent elements and provides me...
EssentialBCs< Scalar > * essential_bcs
Boundary conditions.
Definition: space.h:363
Represents the solution of a PDE.
Definition: api2d.h:35
unsigned int seq
Tracking changes.
Definition: space.h:375
int nsize
node data table size
Definition: space.h:426