ug4
multi_grid_child_info.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Author: Sebastian Reiter
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__multi_grid_child_info__
34 #define __H__UG__multi_grid_child_info__
35 
36 #include <vector>
37 #include "common/error.h"
38 #include "common/assert.h"
40 namespace ug{
41 
42 
43 // Predeclaration
44 class MultiGrid;
45 
46 // The following constants define the maximum number of children
47 // for edges amd faces.
48 // Note that no constants are defined for volumes since the range of
49 // possible children is too high (especially during adaptive refinement)
53 
55 
63 {
64  MGVertexInfo() : m_pParent(NULL), m_pVrtChild(NULL) {}
65  inline void clear_children() {m_pVrtChild = NULL;}
66  inline bool has_children() const {return m_pVrtChild != NULL;}
67  inline void add_child(Vertex* elem) {assert(!m_pVrtChild); m_pVrtChild = elem;}
68  inline void add_child(Edge*) {UG_THROW("INVALID OPERATION!");}//dummy...
69  inline void add_child(Face*) {UG_THROW("INVALID OPERATION!");}//dummy...
70  inline void add_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
71  inline void remove_child(Vertex* elem) {m_pVrtChild = NULL;}
72  inline void remove_child(Edge*) {UG_THROW("INVALID OPERATION!");}//dummy...
73  inline void remove_child(Face*) {UG_THROW("INVALID OPERATION!");}//dummy...
74  inline void remove_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
75  inline void replace_child(Vertex* elem, Vertex* child) {assert(child == m_pVrtChild); m_pVrtChild = elem;}
77  size_t num_child_vertices() const {return m_pVrtChild ? 1 : 0;}
78 
79  Vertex* child_vertex() const {return m_pVrtChild;}
80 
82 private:
84 };
85 
87 
94 struct MGEdgeInfo
95 {
97  inline void clear_children() {m_pVrtChild = NULL; m_numEdgeChildren = 0;}
98  inline bool has_children() const {return m_pVrtChild || m_numEdgeChildren;}
99  inline void add_child(Vertex* elem) {assert(!m_pVrtChild); m_pVrtChild = elem;}
101  inline void add_child(Face*) {UG_THROW("INVALID OPERATION!");}//dummy...
102  inline void add_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
103  inline void remove_child(Vertex* elem) {m_pVrtChild = NULL;}
105  inline void remove_child(Face*) {UG_THROW("INVALID OPERATION!");}//dummy...
106  inline void remove_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
107  inline void replace_child(Vertex* elem, Vertex* child) {assert(child == m_pVrtChild); m_pVrtChild = elem;}
108  inline void replace_child(Edge* elem, Edge* child) {ArrayReplaceEntry(m_pEdgeChild, elem, child, m_numEdgeChildren);}
110  size_t num_child_vertices() const {return m_pVrtChild ? 1 : 0;}
111  size_t num_child_edges() const {return m_numEdgeChildren;}
112 
113  Vertex* child_vertex() const {return m_pVrtChild;}
114  Edge* child_edge(size_t i) const {assert(i < num_child_edges()); return m_pEdgeChild[i];}
115 
117 private:
121 };
122 
124 
126 {
129  inline bool has_children() const {return m_pVrtChild || m_numEdgeChildren || m_numFaceChildren;}
130  inline void add_child(Vertex* elem) {assert(!m_pVrtChild); m_pVrtChild = elem;}
133  inline void add_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
134  inline void remove_child(Vertex* elem) {m_pVrtChild = NULL;}
137  inline void remove_child(Volume*) {UG_THROW("INVALID OPERATION!");}//dummy...
138  inline void replace_child(Vertex* elem, Vertex* child) {assert(child == m_pVrtChild); m_pVrtChild = elem;}
139  inline void replace_child(Edge* elem, Edge* child) {ArrayReplaceEntry(m_pEdgeChild, elem, child, m_numEdgeChildren);}
140  inline void replace_child(Face* elem, Face* child) {ArrayReplaceEntry(m_pFaceChild, elem, child, m_numFaceChildren);}
142 
143  size_t num_child_vertices() const {return m_pVrtChild ? 1 : 0;}
144  size_t num_child_edges() const {return m_numEdgeChildren;}
145  size_t num_child_faces() const {return m_numFaceChildren;}
146 
147  Vertex* child_vertex() const {return m_pVrtChild;}
148  Edge* child_edge(size_t i) const {assert(i < num_child_edges()); return m_pEdgeChild[i];}
149  Face* child_face(size_t i) const {assert(i < num_child_faces()); return m_pFaceChild[i];}
150 
151 private:
157 };
158 
160 
162 {
164  inline void clear_children() {m_pVrtChild = NULL; m_edgeChildren.clear(); m_faceChildren.clear(); m_volumeChildren.clear();}
165  inline bool has_children() const {return m_pVrtChild || !(m_edgeChildren.empty() && m_faceChildren.empty() && m_volumeChildren.empty());}
166  inline void add_child(Vertex* elem) {assert(!m_pVrtChild); m_pVrtChild = elem;}
167  inline void add_child(Edge* elem) {m_edgeChildren.push_back(elem);}
168  inline void add_child(Face* elem) {m_faceChildren.push_back(elem);}
169  inline void add_child(Volume* elem) {m_volumeChildren.push_back(elem);}
170  inline void remove_child(Vertex* elem) {m_pVrtChild = NULL;}
171  inline void remove_child(Edge* elem) {ArraySwapWithLast(&m_edgeChildren.front(), elem, m_edgeChildren.size()); m_edgeChildren.pop_back();}
172  //{m_numEdgeChildren = ArrayEraseEntry(m_pEdgeChild, elem, m_numEdgeChildren);}
173  inline void remove_child(Face* elem) {ArraySwapWithLast(&m_faceChildren.front(), elem, m_faceChildren.size()); m_faceChildren.pop_back();}
174  //{m_numFaceChildren = ArrayEraseEntry(m_pFaceChild, elem, m_numFaceChildren);}
175  inline void remove_child(Volume* elem) {ArraySwapWithLast(&m_volumeChildren.front(), elem, m_volumeChildren.size()); m_volumeChildren.pop_back();}
176  //{m_numVolChildren = ArrayEraseEntry(m_pVolChild, elem, m_numVolChildren);}
177  inline void replace_child(Vertex* elem, Vertex* child) {assert(child == m_pVrtChild); m_pVrtChild = elem;}
178  inline void replace_child(Edge* elem, Edge* child) {ArrayReplaceEntry(&m_edgeChildren.front(), elem, child, m_edgeChildren.size());}
179  inline void replace_child(Face* elem, Face* child) {ArrayReplaceEntry(&m_faceChildren.front(), elem, child, m_faceChildren.size());}
180  inline void replace_child(Volume* elem, Volume* child) {ArrayReplaceEntry(&m_volumeChildren.front(), elem, child, m_volumeChildren.size());}
182 
183  size_t num_child_vertices() const {return m_pVrtChild ? 1 : 0;}
184  size_t num_child_edges() const {return m_edgeChildren.size();}
185  size_t num_child_faces() const {return m_faceChildren.size();}
186  size_t num_child_volumes() const {return m_volumeChildren.size();}
187 
188  Vertex* child_vertex() const {return m_pVrtChild;}
189  Edge* child_edge(size_t i) const {assert(i < num_child_edges()); return m_edgeChildren[i];}
190  Face* child_face(size_t i) const {assert(i < num_child_faces()); return m_faceChildren[i];}
191  Volume* child_volume(size_t i) const {assert(i < num_child_volumes()); return m_volumeChildren[i];}
192 
193 private:
195  std::vector<Edge*> m_edgeChildren;
196  std::vector<Face*> m_faceChildren;
197  std::vector<Volume*> m_volumeChildren;
198 };
199 
201 
205 template <class TElem> class mginfo_traits{};
206 
208 template <> class mginfo_traits<Vertex>
209 {
210  public:
212 };
213 
215 template <> class mginfo_traits<Edge>
216 {
217  public:
219 };
220 
222 template <> class mginfo_traits<Face>
223 {
224  public:
226 };
227 
229 template <> class mginfo_traits<Volume>
230 {
231  public:
233 };
234 
235 }// end of namespace
236 
237 #endif
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
Definition: multi_grid.h:72
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
MGEdgeInfo info_type
Definition: multi_grid_child_info.h:218
MGFaceInfo info_type
Definition: multi_grid_child_info.h:225
MGVertexInfo info_type
Definition: multi_grid_child_info.h:211
MGVolumeInfo info_type
Definition: multi_grid_child_info.h:232
access to connected types. used internally
Definition: multi_grid_child_info.h:205
void ArraySwapWithLast(TType *array, const TType &entry, size_t size)
Swaps the first entry with the given value with the last entry in the list.
Definition: array_util.h:81
bool ArrayReplaceEntry(TType *array, const TType &newEntry, const TType &oldEntry, size_t size)
replaces the first occurance of oldEntry with newEntry
Definition: array_util.h:106
int ArrayEraseEntry(TType *array, const TType &entry, size_t size)
removes the first occurance of the specified entry.
Definition: array_util.h:52
#define UG_THROW(msg)
Definition: error.h:57
the ug namespace
const int MG_FACE_MAX_EDGE_CHILDREN
maximal number of edges that can be children of a face.
Definition: multi_grid_child_info.h:51
const int MG_FACE_MAX_FACE_CHILDREN
maximal number of faces that can be children of a face.
Definition: multi_grid_child_info.h:52
const int MG_EDGE_MAX_EDGE_CHILDREN
maximal number of edges that can be children of an edge.
Definition: multi_grid_child_info.h:50
Holds information about edge relations. Used internally.
Definition: multi_grid_child_info.h:95
void add_child(Volume *)
Definition: multi_grid_child_info.h:102
size_t num_child_edges() const
Definition: multi_grid_child_info.h:111
void add_child(Vertex *elem)
Definition: multi_grid_child_info.h:99
void remove_child(Volume *)
Definition: multi_grid_child_info.h:106
Vertex * child_vertex() const
Definition: multi_grid_child_info.h:113
byte m_numEdgeChildren
Definition: multi_grid_child_info.h:120
GridObject * m_pParent
Definition: multi_grid_child_info.h:116
void remove_child(Vertex *elem)
Definition: multi_grid_child_info.h:103
void remove_child(Edge *elem)
Definition: multi_grid_child_info.h:104
Edge * child_edge(size_t i) const
Definition: multi_grid_child_info.h:114
void unregister_from_children(MultiGrid &mg)
Definition: multi_grid.cpp:601
Edge * m_pEdgeChild[MG_EDGE_MAX_EDGE_CHILDREN]
Definition: multi_grid_child_info.h:119
void clear_children()
Definition: multi_grid_child_info.h:97
MGEdgeInfo()
Definition: multi_grid_child_info.h:96
void add_child(Edge *elem)
Definition: multi_grid_child_info.h:100
bool has_children() const
Definition: multi_grid_child_info.h:98
void remove_child(Face *)
Definition: multi_grid_child_info.h:105
void add_child(Face *)
Definition: multi_grid_child_info.h:101
void replace_child(Edge *elem, Edge *child)
Definition: multi_grid_child_info.h:108
void replace_child(Vertex *elem, Vertex *child)
Definition: multi_grid_child_info.h:107
size_t num_child_vertices() const
Definition: multi_grid_child_info.h:110
Vertex * m_pVrtChild
Definition: multi_grid_child_info.h:118
Holds information about face relations. Used internally.
Definition: multi_grid_child_info.h:126
void remove_child(Edge *elem)
Definition: multi_grid_child_info.h:135
byte m_numFaceChildren
Definition: multi_grid_child_info.h:156
void replace_child(Face *elem, Face *child)
Definition: multi_grid_child_info.h:140
void add_child(Face *elem)
Definition: multi_grid_child_info.h:132
void add_child(Vertex *elem)
Definition: multi_grid_child_info.h:130
void remove_child(Vertex *elem)
Definition: multi_grid_child_info.h:134
void unregister_from_children(MultiGrid &mg)
Definition: multi_grid.cpp:610
void replace_child(Vertex *elem, Vertex *child)
Definition: multi_grid_child_info.h:138
void clear_children()
Definition: multi_grid_child_info.h:128
Edge * child_edge(size_t i) const
Definition: multi_grid_child_info.h:148
size_t num_child_vertices() const
Definition: multi_grid_child_info.h:143
void remove_child(Volume *)
Definition: multi_grid_child_info.h:137
Vertex * child_vertex() const
Definition: multi_grid_child_info.h:147
void remove_child(Face *elem)
Definition: multi_grid_child_info.h:136
MGFaceInfo()
Definition: multi_grid_child_info.h:127
bool has_children() const
Definition: multi_grid_child_info.h:129
byte m_numEdgeChildren
Definition: multi_grid_child_info.h:155
void add_child(Edge *elem)
Definition: multi_grid_child_info.h:131
Face * child_face(size_t i) const
Definition: multi_grid_child_info.h:149
Edge * m_pEdgeChild[MG_FACE_MAX_EDGE_CHILDREN]
Definition: multi_grid_child_info.h:153
void add_child(Volume *)
Definition: multi_grid_child_info.h:133
Vertex * m_pVrtChild
Definition: multi_grid_child_info.h:152
size_t num_child_faces() const
Definition: multi_grid_child_info.h:145
size_t num_child_edges() const
Definition: multi_grid_child_info.h:144
void replace_child(Edge *elem, Edge *child)
Definition: multi_grid_child_info.h:139
Face * m_pFaceChild[MG_FACE_MAX_FACE_CHILDREN]
Definition: multi_grid_child_info.h:154
Holds information about vertex relations. Used internally.
Definition: multi_grid_child_info.h:63
void unregister_from_children(MultiGrid &mg)
Definition: multi_grid.cpp:594
void replace_child(Vertex *elem, Vertex *child)
Definition: multi_grid_child_info.h:75
void add_child(Volume *)
Definition: multi_grid_child_info.h:70
void clear_children()
Definition: multi_grid_child_info.h:65
Vertex * child_vertex() const
Definition: multi_grid_child_info.h:79
void remove_child(Volume *)
Definition: multi_grid_child_info.h:74
Vertex * m_pVrtChild
Definition: multi_grid_child_info.h:83
MGVertexInfo()
Definition: multi_grid_child_info.h:64
size_t num_child_vertices() const
Definition: multi_grid_child_info.h:77
void remove_child(Face *)
Definition: multi_grid_child_info.h:73
void add_child(Face *)
Definition: multi_grid_child_info.h:69
void add_child(Vertex *elem)
Definition: multi_grid_child_info.h:67
bool has_children() const
Definition: multi_grid_child_info.h:66
void remove_child(Edge *)
Definition: multi_grid_child_info.h:72
GridObject * m_pParent
Definition: multi_grid_child_info.h:81
void remove_child(Vertex *elem)
Definition: multi_grid_child_info.h:71
void add_child(Edge *)
Definition: multi_grid_child_info.h:68
Holds information about volume relations. Used internally.
Definition: multi_grid_child_info.h:162
Face * child_face(size_t i) const
Definition: multi_grid_child_info.h:190
std::vector< Face * > m_faceChildren
Definition: multi_grid_child_info.h:196
void replace_child(Face *elem, Face *child)
Definition: multi_grid_child_info.h:179
size_t num_child_vertices() const
Definition: multi_grid_child_info.h:183
bool has_children() const
Definition: multi_grid_child_info.h:165
void add_child(Edge *elem)
Definition: multi_grid_child_info.h:167
size_t num_child_volumes() const
Definition: multi_grid_child_info.h:186
void remove_child(Volume *elem)
Definition: multi_grid_child_info.h:175
Vertex * child_vertex() const
Definition: multi_grid_child_info.h:188
void unregister_from_children(MultiGrid &mg)
Definition: multi_grid.cpp:621
void remove_child(Edge *elem)
Definition: multi_grid_child_info.h:171
void replace_child(Volume *elem, Volume *child)
Definition: multi_grid_child_info.h:180
void remove_child(Vertex *elem)
Definition: multi_grid_child_info.h:170
void add_child(Volume *elem)
Definition: multi_grid_child_info.h:169
size_t num_child_faces() const
Definition: multi_grid_child_info.h:185
void replace_child(Vertex *elem, Vertex *child)
Definition: multi_grid_child_info.h:177
void add_child(Face *elem)
Definition: multi_grid_child_info.h:168
size_t num_child_edges() const
Definition: multi_grid_child_info.h:184
void remove_child(Face *elem)
Definition: multi_grid_child_info.h:173
Edge * child_edge(size_t i) const
Definition: multi_grid_child_info.h:189
std::vector< Volume * > m_volumeChildren
Definition: multi_grid_child_info.h:197
Volume * child_volume(size_t i) const
Definition: multi_grid_child_info.h:191
std::vector< Edge * > m_edgeChildren
Definition: multi_grid_child_info.h:195
Vertex * m_pVrtChild
Definition: multi_grid_child_info.h:194
void add_child(Vertex *elem)
Definition: multi_grid_child_info.h:166
void replace_child(Edge *elem, Edge *child)
Definition: multi_grid_child_info.h:178
MGVolumeInfo()
Definition: multi_grid_child_info.h:163
void clear_children()
Definition: multi_grid_child_info.h:164