Hermes2D  3.0
space_l2.cpp
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 #include "global.h"
17 #include "space_l2.h"
18 #include "matrix.h"
19 #include "quad_all.h"
20 #include "shapeset/shapeset_l2_all.h"
21 #include "boundary_conditions/essential_boundary_conditions.h"
22 
23 namespace Hermes
24 {
25  namespace Hermes2D
26  {
27  template<typename Scalar>
28  L2Space<Scalar>::L2Space() : Space<Scalar>()
29  {
30  }
31 
32  template<typename Scalar>
33  void L2Space<Scalar>::init(Shapeset* shapeset, int p_init, bool assign_dofs_init)
34  {
35  if (shapeset == nullptr)
36  {
37  this->shapeset = new L2Shapeset;
38  this->own_shapeset = true;
39  }
40 
41  // enumerate basis functions
42  if (assign_dofs_init)
43  {
44  // set uniform poly order in elements
45  if (p_init < 0)
46  throw Hermes::Exceptions::Exception("P_INIT must be >= 0 in an L2 space.");
47  else
48  this->set_uniform_order_internal(p_init, HERMES_ANY_INT);
49 
50  this->assign_dofs();
51  }
52  }
53 
54  template<typename Scalar>
55  L2Space<Scalar>::L2Space(MeshSharedPtr mesh, int p_init, Shapeset* shapeset)
56  : Space<Scalar>(mesh, shapeset, nullptr)
57  {
58  init(shapeset, p_init);
59  }
60 
61  template<typename Scalar>
62  L2Space<Scalar>::~L2Space()
63  {
64  }
65 
66  template<typename Scalar>
67  void L2Space<Scalar>::copy(SpaceSharedPtr<Scalar> space, MeshSharedPtr new_mesh)
68  {
69  this->set_shapeset(space->get_shapeset(), true);
70 
71  Space<Scalar>::copy(space, new_mesh);
72  }
73 
74  template<typename Scalar>
75  void L2Space<Scalar>::set_shapeset(Shapeset *shapeset, bool clone)
76  {
77  if (!(shapeset->get_id() < 40 && shapeset->get_id() > 29))
78  throw Hermes::Exceptions::Exception("Wrong shapeset type in L2Space<Scalar>::set_shapeset()");
79 
80  if (clone)
81  {
82  if (this->own_shapeset)
83  delete this->shapeset;
84 
85  this->shapeset = shapeset->clone();
86  }
87  else
88  {
89  this->shapeset = shapeset;
90  this->own_shapeset = false;
91  }
92  }
93 
94  template<typename Scalar>
96  {
97  Element* e;
98  this->bubble_functions_count = 0;
99  for_all_active_elements(e, this->mesh)
100  {
101  typename Space<Scalar>::ElementData* ed = &this->edata[e->id];
102  ed->bdof = this->next_dof;
103  //FIXME: this function might return invalid value because retrieved bubble functions for non-uniform orders might be invalid for the given order.
104  ed->n = this->shapeset->get_num_bubbles(ed->order, e->get_mode());
105  this->next_dof += ed->n;
106  this->bubble_functions_count += ed->n;
107  }
108  }
109 
110  template<typename Scalar>
111  void L2Space<Scalar>::get_vertex_assembly_list(Element* e, int iv, AsmList<Scalar>* al) const
112  {}
113 
114  template<typename Scalar>
116  {
117  // add bubble functions to the assembly list
118  al->cnt = 0;
119  get_bubble_assembly_list(e, al);
120  }
121 
122  template<typename Scalar>
124  {
125  typename Space<Scalar>::ElementData* ed = &this->edata[e->id];
126  if (!ed->n) return;
127 
128  short* indices = this->shapeset->get_bubble_indices(ed->order, e->get_mode());
129  for (unsigned short i = 0, dof = ed->bdof; i < ed->n; i++, dof++)
130  {
131  //printf("triplet: %d, %d, %f\n", *indices, dof, 1.0);
132  al->add_triplet(*indices++, dof, 1.0);
133  }
134  }
135 
136  template<typename Scalar>
137  void L2Space<Scalar>::get_boundary_assembly_list_internal(Element* e, int surf_num, AsmList<Scalar>* al) const
138  {
139  this->get_bubble_assembly_list(e, al);
140  }
141 
142  template<typename Scalar>
143  Scalar* L2Space<Scalar>::get_bc_projection(SurfPos* surf_pos, int order, EssentialBoundaryCondition<Scalar> *bc)
144  {
145  throw Hermes::Exceptions::Exception("Method get_bc_projection() called from an L2Space.");
146  return nullptr;
147  }
148 
149  template<typename Scalar>
150  L2MarkerWiseConstSpace<Scalar>::L2MarkerWiseConstSpace(MeshSharedPtr mesh) : L2Space<Scalar>(mesh, 0)
151  {
152  }
153 
154  template<typename Scalar>
155  void L2MarkerWiseConstSpace<Scalar>::assign_bubble_dofs()
156  {
157  Element* e;
158  this->bubble_functions_count = 0;
159  int max_marker = 0;
160  for_all_active_elements(e, this->mesh)
161  {
162  typename Space<Scalar>::ElementData* ed = &this->edata[e->id];
163  ed->bdof = this->next_dof + e->marker - 1;
164  ed->n = 1;
165  max_marker = std::max(max_marker, e->marker);
166  }
167  this->next_dof += max_marker;
168  this->bubble_functions_count = max_marker;
169  }
170 
171  template HERMES_API class L2Space < double > ;
172  template HERMES_API class L2Space < std::complex<double> > ;
173 
174  template HERMES_API class L2MarkerWiseConstSpace < double > ;
175  template HERMES_API class L2MarkerWiseConstSpace < std::complex<double> > ;
176  }
177 }
Definition: adapt.h:24
int id
element id number
Definition: element.h:112
virtual void set_shapeset(Shapeset *shapeset, bool clone=false)
Sets the shapeset.
Definition: space_l2.cpp:75
Stores one element of a mesh.
Definition: element.h:107
void init()
Common code for constructors.
Definition: space.cpp:85
void add_triplet(int i, int d, Scalar c)
Adds a record for one basis function (shape functions index, basis functions index, coefficient).
Definition: asmlist.cpp:62
Used to pass the instances of Space around.
Definition: space.h:34
Common definitions for Hermes2D.
virtual void copy(SpaceSharedPtr< Scalar > space, MeshSharedPtr new_mesh)
Copy from Space instance 'space'.
Definition: space_l2.cpp:67
virtual void copy(SpaceSharedPtr< Scalar > space, MeshSharedPtr new_mesh)
Definition: space.cpp:243
virtual void get_element_assembly_list(Element *e, AsmList< Scalar > *al) const
Obtains an assembly list for the given element.
Definition: space_l2.cpp:115
unsigned short cnt
the number of items in the arrays idx, dof and coef
Definition: asmlist.h:54
virtual unsigned char get_id() const =0
Should be exactly the same as is the count of enum ShapesetType.
Definition: shapeset.h:95
Represents a finite element space over a domain.
Definition: api2d.h:34
L2ShapesetLegendre L2Shapeset
This is the default shapeset typedef.