3 #ifndef DUNE_FOAMGRID_ELEMENTS_HH
4 #define DUNE_FOAMGRID_ELEMENTS_HH
8 #include <dune/common/fmatrix.hh>
9 #include <dune/common/function.hh>
17 template <
int dimgr
id,
int dimworld,
class ctype>
21 template <
int dimworld,
class ctype>
35 int level,
unsigned int id)
39 sons_{{
nullptr,
nullptr}},
40 nSons_(0), father_(
nullptr),
41 refinementIndex_(-1), markState_(DO_NOTHING), isNew_(
false),
42 coarseningBlocked_(
false),
43 growthInsertionIndex_(-1)
48 int level,
unsigned int id,
54 sons_{{
nullptr,
nullptr}},
55 nSons_(0), father_(father),
56 refinementIndex_(-1), markState_(DO_NOTHING), isNew_(
false),
57 coarseningBlocked_(
false),
58 growthInsertionIndex_(-1)
63 vertex_{{
nullptr,
nullptr}},
64 facet_{{
nullptr,
nullptr}},
65 sons_{{
nullptr,
nullptr}},
69 markState_(DO_NOTHING), isNew_(
false),
70 coarseningBlocked_(
false),
71 growthInsertionIndex_(-1)
76 return sons_[0]==
nullptr &&
87 return markState_==COARSEN;
95 GeometryType
type()
const {
96 return Dune::GeometryTypes::simplex(1);
101 return father_!=
nullptr;
109 FieldVector<ctype, dimworld>
corner(
int i)
const {
110 assert(i < this->corners());
111 assert(
int(vertex_.size())==this->corners());
112 assert(vertex_[i]!=
nullptr);
113 return vertex_[i]->pos_;
117 return InteriorEntity;
125 FieldVector<ctype, 1>
globalToLocal(
const FieldVector<ctype, dimworld>& coord)
const
127 const auto diff = vertex_[1]->pos_ - vertex_[0]->pos_;
128 const ctype eps = diff.two_norm()*std::numeric_limits<ctype>::epsilon();
131 for (std::size_t dimIdx = 0; dimIdx < dimworld; ++dimIdx)
132 if (abs(diff[dimIdx]) > eps)
133 return (coord[dimIdx] - vertex_[0]->pos_[dimIdx]) / diff[dimIdx];
135 DUNE_THROW(Dune::GridError,
"Global to local mapping failed because element is degenerated.");
141 assert(0<=codim && codim<=1);
144 return this->levelIndex_;
146 return vertex_[i]->levelIndex_;
148 DUNE_THROW(GridError,
"Non-existing codimension requested!");
154 assert(0<=codim && codim<=1);
157 return this->leafIndex_;
159 return vertex_[i]->leafIndex_;
161 DUNE_THROW(GridError,
"Non-existing codimension requested!");
164 std::array<FoamGridEntityImp<0, dimgrid, dimworld, ctype>*, 2>
vertex_;
169 std::array<FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>*, 2>
sons_;
199 template <
int dimworld,
class ctype>
213 refinementIndex_(-1),
215 sons_{{
nullptr,
nullptr,
nullptr,
nullptr}},
216 facet_{{
nullptr,
nullptr,
nullptr}},
217 vertex_{{
nullptr,
nullptr,
nullptr}},
218 markState_(DO_NOTHING), isNew_(
false),
220 coarseningBlocked_(
false),
221 growthInsertionIndex_(-1)
230 return GeometryTypes::simplex(2);
236 return father_!=
nullptr;
241 return markState_==COARSEN;
245 return sons_[0] ==
nullptr &&
246 sons_[1] ==
nullptr &&
247 sons_[2] ==
nullptr &&
266 FieldVector<ctype,2>
globalToLocal(
const FieldVector<ctype, dimworld>& coord)
const
277 FieldMatrix<ctype,2,2> mat;
280 for(std::size_t i=0; i <dimworld; ++i)
282 mat[0][0]+=(vertex_[1]->pos_[i]-vertex_[0]->pos_[i])*(vertex_[1]->pos_[i]-vertex_[0]->pos_[i]);
284 for(std::size_t i=0; i <dimworld; ++i)
286 mat[1][0]+=(vertex_[2]->pos_[i]-vertex_[0]->pos_[i])*(vertex_[1]->pos_[i]-vertex_[0]->pos_[i]);
289 for(std::size_t i=0; i <dimworld; ++i)
291 mat[1][1]+=(vertex_[2]->pos_[i]-vertex_[0]->pos_[i])*(vertex_[2]->pos_[i]-vertex_[0]->pos_[i]);
294 FieldVector<ctype, 2> b, x;
296 for(std::size_t i=0; i <dimworld; ++i)
298 b[0]+=(vertex_[1]->pos_[i]-vertex_[0]->pos_[i])*(coord[i]-vertex_[0]->pos_[i]);
299 b[1]+=(vertex_[2]->pos_[i]-vertex_[0]->pos_[i])*(coord[i]-vertex_[0]->pos_[i]);
303 FieldVector<ctype, dimworld> test(vertex_[0]->pos_);
304 test.axpy(x[0], vertex_[1]->pos_);
305 test.axpy(-x[0], vertex_[0]->pos_);
306 test.axpy(x[1], vertex_[2]->pos_);
307 test.axpy(-x[1], vertex_[0]->pos_);
308 assert((test-coord).two_norm()< std::numeric_limits<ctype>::epsilon()*8);
316 assert(0<=codim && codim<=2);
319 return this->levelIndex_;
321 return facet_[i]->levelIndex_;
323 return vertex_[i]->levelIndex_;
325 DUNE_THROW(GridError,
"Non-existing codimension requested!");
331 assert(0<=codim && codim<=2);
334 return this->leafIndex_;
336 return facet_[i]->leafIndex_;
338 return vertex_[i]->leafIndex_;
340 DUNE_THROW(GridError,
"Non-existing codimension requested!");
354 std::array<FoamGridEntityImp<dimgrid, dimgrid, dimworld, ctype>*, 4>
sons_;
358 std::array<FoamGridEntityImp<0, dimgrid, dimworld, ctype>*, 3>
vertex_;
Element specialization of FoamGridEntityImp. Element is a grid entity of topological codimension 0 an...
Definition: foamgridelements.hh:18
std::array< FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > *, 2 > sons_
links to refinements of this edge
Definition: foamgridelements.hh:169
bool isLeaf() const
Definition: foamgridelements.hh:75
GeometryType type() const
Definition: foamgridelements.hh:95
int corners() const
Number of corners (==2)
Definition: foamgridelements.hh:105
unsigned int nSons_
The number of refined edges (0 or 2).
Definition: foamgridelements.hh:172
std::shared_ptr< VirtualFunction< FieldVector< ctype, dimgrid >, FieldVector< ctype, dimworld > > > elementParametrization_
The element parametrization.
Definition: foamgridelements.hh:184
int growthInsertionIndex_
If this element was created in a growth step this will be the index of insertion So if this is the fi...
Definition: foamgridelements.hh:195
std::array< FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *, 2 > vertex_
Definition: foamgridelements.hh:164
bool hasFather() const
Definition: foamgridelements.hh:99
MarkState markState_
Definition: foamgridelements.hh:179
bool coarseningBlocked_
This flag is set by postGrow() if the element looses its right to coarsen because it contains a bifur...
Definition: foamgridelements.hh:188
MarkState
The different ways to mark an element for grid changes.
Definition: foamgridelements.hh:31
@ REFINE
Definition: foamgridelements.hh:31
std::array< FoamGridEntityImp< dimgrid-1, dimgrid, dimworld, ctype > *, 2 > facet_
Definition: foamgridelements.hh:166
FoamGridEntityImp(FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *v0, FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *v1, int level, unsigned int id)
Definition: foamgridelements.hh:33
int refinementIndex_
Definition: foamgridelements.hh:177
FoamGridEntityImp(int level, unsigned int id)
Definition: foamgridelements.hh:61
bool mightVanish() const
Definition: foamgridelements.hh:85
FoamGridEntityImp(FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *v0, FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *v1, int level, unsigned int id, FoamGridEntityImp *father)
Definition: foamgridelements.hh:46
unsigned int nSons() const
Definition: foamgridelements.hh:81
int subLeafIndex(int i, unsigned int codim) const
Return leaf index of sub entity with codim = cc and local number i.
Definition: foamgridelements.hh:153
bool isNew() const
Definition: foamgridelements.hh:90
FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > * father_
Pointer to father element.
Definition: foamgridelements.hh:175
bool isNew_
Definition: foamgridelements.hh:181
PartitionType partitionType() const
Definition: foamgridelements.hh:116
FieldVector< ctype, 1 > globalToLocal(const FieldVector< ctype, dimworld > &coord) const
Compute local cordinates from global ones.
Definition: foamgridelements.hh:125
int subLevelIndex(int i, unsigned int codim) const
Return level index of sub entity with codim = cc and local number i.
Definition: foamgridelements.hh:140
FieldVector< ctype, dimworld > corner(int i) const
Definition: foamgridelements.hh:109
bool isLeaf() const
Definition: foamgridelements.hh:244
unsigned int nSons_
Definition: foamgridelements.hh:352
GeometryType type() const
Definition: foamgridelements.hh:229
std::array< FoamGridEntityImp< 0, dimgrid, dimworld, ctype > *, 3 > vertex_
Definition: foamgridelements.hh:358
MarkState markState_
Stores requests for refinement and coarsening.
Definition: foamgridelements.hh:361
int subLevelIndex(int i, unsigned int codim) const
Return level index of sub entity with codim = cc and local number i.
Definition: foamgridelements.hh:315
bool isNew_
This flag is set by adapt() if this element has been newly created.
Definition: foamgridelements.hh:364
bool mightVanish() const
Definition: foamgridelements.hh:239
FoamGridEntityImp< dimgrid, dimgrid,dimworld, ctype > * father_
Definition: foamgridelements.hh:366
FieldVector< ctype, 2 > globalToLocal(const FieldVector< ctype, dimworld > &coord) const
Compute local cordinates from global ones.
Definition: foamgridelements.hh:266
std::array< FoamGridEntityImp< dimgrid-1, dimgrid, dimworld, ctype > *, 3 > facet_
Definition: foamgridelements.hh:356
std::shared_ptr< VirtualFunction< FieldVector< ctype, dimgrid >, FieldVector< ctype, dimworld > > > elementParametrization_
The element parametrization.
Definition: foamgridelements.hh:369
int corners() const
Definition: foamgridelements.hh:225
int subLeafIndex(int i, unsigned int codim) const
Return leaf index of sub entity with codim = cc and local number i.
Definition: foamgridelements.hh:330
bool hasFather() const
Definition: foamgridelements.hh:234
bool isNew() const
Definition: foamgridelements.hh:251
FoamGridEntityImp(int level, unsigned int id)
Definition: foamgridelements.hh:211
unsigned int nSons() const
Definition: foamgridelements.hh:257
int refinementIndex_
index of the refined element in the father
Definition: foamgridelements.hh:350
int growthInsertionIndex_
If this element was created in a growth step this will be the index of insertion So if this is the fi...
Definition: foamgridelements.hh:380
bool coarseningBlocked_
This flag is set by postGrow() if the element looses its right to coarsen because it contains a bifur...
Definition: foamgridelements.hh:373
MarkState
The different ways to mark an element for grid changes.
Definition: foamgridelements.hh:209
@ REFINE
Definition: foamgridelements.hh:209
std::array< FoamGridEntityImp< dimgrid, dimgrid, dimworld, ctype > *, 4 > sons_
Definition: foamgridelements.hh:354
Base class for FoamGrid entity implementation classes.
Definition: foamgridvertex.hh:16
The actual entity implementation.
Definition: foamgridvertex.hh:47
Vertex specialization of FoamGridEntityImp.
Definition: foamgridvertex.hh:53