ug4
creator_grid_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2015: G-CSC, Goethe University Frankfurt
3  * Authors: Sebastian Reiter, Andreas Vogel, Jan Friebertshäuser
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__LIB_GRID__TOOLS__CREATOR_GRID_UTIL__
34 #define __H__UG__LIB_GRID__TOOLS__CREATOR_GRID_UTIL__
35 
36 // other lib_discretization headers
37 
38 
39 namespace ug{
41 
45 template<typename TPosition>
47 {
48  RegularVertex* vrt = *grid.create<RegularVertex>();
49 
50  if(vrt){
51  aaPos[vrt] = pos;
52  }
53 
54  return vrt;
55 }
56 
57 
58 
59 Edge* CreateEdge(Grid& grid, Vertex* vrts[], const size_t, numVrts){
60  //uniquify vrts by hash_value: no
61  //The vrts can't be simply uniquified by hash_values since it will change the orientation of vrts.
62  // Hence,it should be generated by aaPos before using this function.
63  RegularEdge* e = NULL;
64 
65  switch(numVrts){
66  case 2:{// create edge
67  if(!grid.get_edge(vrts[0], vrts[1]))
68  e = *grid.create<ug::RegularEdge>(ug::EdgeDescriptor(vrts[0], vrts[1]));
69  else{
70  UG_LOG("Can't create edge: RegularEdge already exists.\n");
71  }
72  }break;
73 
74  default:
75  UG_LOG("Can't create edge: Bad number of vertices. 2 are required.\n");
76  break;
77  }
78  return e;
79 
80 }
81 
82 Edge* CreateEdge(Grid& grid, Vertex* vrt0, Vertex* vrt1)
83 {
84  RegularEdge* e = NULL;
85 
86  uint32 hash0=vrt0->get_hash_value();
87  uint32 hash1=vrt1->get_hash_value();
88  UG_ASSERT(hash0!=hash1, "Can't create edge: they are identical vertices.");
89 
90  Vertex* vrts[2];
91  vrts[0]=vrt0;
92  vrts[1]=vrt1;
93  // create edge
94  return CreateEdge(grid, vrts, 2);
95 }
96 
97 /*Edge* CreateEdge(Grid& grid, std::vector<Vertex*> vrts){
98  size_t numVrts = vrts.num_vertices();
99  // vector -> array
100  for(size_t i=0; i<numVrts; ++i){
101  }
102  //return CreateEdge(grid, avrts, numVrts);
103 }*/
104 
105 Face* CreateFace(Grid& grid, Vertex* vrts[], const size_t numVrts){
106  //if(numVrts < 3 || numVrts > 4){
107  UG_ASSERT(numVrts>2 || numVrts<5,"Bad number of vertices! Can't create a face element from " << numVrts << " vertices.");
108  //return NULL;
109  //}
110 
111  FaceDescriptor fd(numVrts);
112  for(size_t i = 0; i < numVrts; ++i)
113  fd.set_vertex(i, vrts[i]);
114 
115  if(grid.get_face(fd)){
116  UG_LOG("A face connecting the given vertices already exists. Won't create a new one!");
117  return NULL;
118  }
119 
120  Face* f = NULL;
121  switch(numVrts){
122  case 3:{// create triangle
123  f = *grid.create<Triangle>(TriangleDescriptor(vrts[0], vrts[1], vrts[2]));
124  }break;
125 
126  case 4:{// create quadrilateral
127  f = *grid.create<Quadrilateral>(QuadrilateralDescriptor(vrts[0], vrts[1],
128  vrts[2], vrts[3]));
129  }break;
130 
131  default:
132  UG_LOG("Can't create face: Bad number of vertices. 3 or 4 are supported.\n");
133  break;
134  }
135 
136  return f;
137 }
138 
139 /*Face* CreateFace(Grid& grid, std::vector<Vertex*> vrts){
140  size_t numVrts = vrts.num_vertices();
141  // vector -> array
142  for(size_t i=0; i<numVrts; ++i){
143  }
144  //return CreateFace(grid, avrts, numVrts);
145 }*/
146 
147 Volume* CreateVolume(Grid& grid, Vertex* vrts, const size_t numVrts){
148 //if(numVrts < 4 || numVrts > 8){
149  UG_ASSERT(numVrts>3 || numVrts<9,"Bad number of vertices! Can't create a volume element from " << numVrts << " vertices.");
150 
151  VolumeDescriptor vd(numVrts);
152  for(size_t i = 0; i < numVrts; ++i)
153  vd.set_vertex(i, vrts[i]);
154 
155  if(grid.get_volume(vd)){
156  UG_LOG("A volume connecting the given vertices already exists. Won't create a new one!");
157  return NULL;
158  }
159 
160  Volume* v = NULL;
161  switch(numVrts){
162  case 4:{// create tetrahedron
163  v = *grid.create<Tetrahedron>(TetrahedronDescriptor(vrts[0], vrts[1],
164  vrts[2], vrts[3]));
165  }break;
166 
167  case 5:{// create pyramid
168  v = *grid.create<Pyramid>(PyramidDescriptor(vrts[0], vrts[1],
169  vrts[2], vrts[3], vrts[4]));
170  }break;
171 
172  case 6:{// create prism
173  v = *grid.create<Prism>(PrismDescriptor(vrts[0], vrts[1], vrts[2],
174  vrts[3], vrts[4], vrts[5]));
175  }break;
176 
177  case 8:{// create hexahedron
178  v = *grid.create<Hexahedron>(HexahedronDescriptor(vrts[0], vrts[1], vrts[2], vrts[3],
179  vrts[4], vrts[5], vrts[6], vrts[7]));
180  }break;
181 
182  default:
183  UG_LOG("Can't create volume: Bad number of vertices. 4, 5, 6, and 8 are supported.\n");
184  break;
185  }
186 
187  return v;
188 }
189 
190 /*Volume* CreateVolume(Grid& grid, std::vector<Vertex*> vrts){
191  size_t numVrts = vrts.num_vertices();
192  // vector -> array
193  for(size_t i=0; i<numVrts; ++i){
194  }
195  //return CreateVolume(grid, avrts, numVrts);
196 }*/
197 
198 /*
199 template<typename TElem, typename TPosition> //for edges, faces, Volumes. constexpr(TElem:HAS_SIDES)
200 TElem* CreateGridObject(Grid& grid,
201 int vrt_indices[],
202 const size_t numVrts, Grid::VertexAttachmentAccessor<Attachment<TPosition> >& aaPOS)
203 */
204 
205 //pos: 0: upLeft,1:lowLeft, 2: lowRight, 3. upRight
206 template<typename TPosition>
207 void CreatePlane(Grid& grid,
208  const TPosition& upLeft,
209  const TPosition& upRight,
210  const TPosition& lowLeft,
211  const TPosition& lowRight,
213  bool fill)
214 {
215  Vertex* vrts[4];
216  for(size_t i = 0; i < 4; ++i)
217  vrts[i] = *grid.create<RegularVertex>();
218 
219  aaPos[vrts[0]] = upLeft;
220  aaPos[vrts[1]] = lowLeft;
221  aaPos[vrts[2]] = lowRight;
222  aaPos[vrts[3]] = upRight;
223 
224  if(fill){
225  CreateFace(grid, vrts, 4);
226  }else{
227  for(size_t i = 0; i < 4; ++i){
228  int i0 = i;
229  int i1 = (i + 1) % 4;
230  grid.create<RegularEdge>(EdgeDescriptor(vrts[i0], vrts[i1]));
231  }
232  }
233 }
234 
235 
236 }
237 
238 #endif /* __H__UG__LIB_GRID__TOOLS__CREATOR_GRID_UTIL__*/
A generic specialization of IAttachment.
Definition: attachment_pipe.h:263
Can be used to store information about an edge and to construct an edge.
Definition: grid_base_objects.h:464
Base-class for edges.
Definition: grid_base_objects.h:397
Can be queried for the edges and vertices of a face.
Definition: grid_base_objects.h:684
void set_vertex(uint index, Vertex *vrt)
Definition: grid_base_objects.h:706
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
Edge * get_edge(Vertex *v1, Vertex *v2)
returns the edge between v1 and v2, if it exists. Returns NULL if not.
Definition: grid.cpp:1069
Face * get_face(const FaceVertices &fv)
returns the face that is described by fv.
Definition: grid.cpp:1135
Volume * get_volume(const VolumeVertices &vv)
returns the volume that is described by ev.
Definition: grid.cpp:1163
geometry_traits< TGeomObj >::iterator create(GridObject *pParent=NULL)
create a custom element.
Definition: grid_impl.hpp:69
only used to initialize a hexahedron. for all other tasks you should use VolumeDescriptor.
Definition: grid_objects_3d.h:203
A volume element with 6 quadrilateral sides.
Definition: grid_objects_3d.h:227
only used to initialize a prism. for all other tasks you should use VolumeDescripor.
Definition: grid_objects_3d.h:336
A volume element with 2 triangle and 3 quadrilateral sides.
Definition: grid_objects_3d.h:360
only used to initialize a pyramids. for all other tasks you should use VolumeDescripor.
Definition: grid_objects_3d.h:469
A volume element with 4 triangle and 1 quadrilateral sides.
Definition: grid_objects_3d.h:493
only used to initialize a quadrilateral. for all other tasks you should use FaceDescriptor.
Definition: grid_objects_2d.h:220
a face with four points.
Definition: grid_objects_2d.h:323
Edges connect two vertices.
Definition: grid_objects_1d.h:66
A basic vertex-type.
Definition: grid_objects_0d.h:62
only used to initialize a tetrahedron. for all other tasks you should use VolumeDescripor.
Definition: grid_objects_3d.h:68
the most simple volume-element.
Definition: grid_objects_3d.h:91
only used to initialize a triangle. for all other tasks you should use FaceDescriptor.
Definition: grid_objects_2d.h:78
the most simple form of a face
Definition: grid_objects_2d.h:174
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
uint32 get_hash_value() const
returns a value that can be used for hashing.
Definition: grid_base_objects.h:272
Holds a set of vertices which represent the corners of a volume element.
Definition: grid_base_objects.h:951
void set_vertex(uint index, Vertex *vrt)
Definition: grid_base_objects.h:967
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
function util fill(N, c)
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
ugtypes::uint32_t uint32
Definition: types.h:116
#define UG_LOG(msg)
Definition: log.h:367
the ug namespace
Edge * CreateEdge(Grid &grid, Vertex *vrts[], const size_t, numVrts)
Definition: creator_grid_util.h:59
void CreatePlane(Grid &grid, const TPosition &upLeft, const TPosition &upRight, const TPosition &lowLeft, const TPosition &lowRight, Grid::VertexAttachmentAccessor< Attachment< TPosition > > &aaPos bool fill)
Definition: creator_grid_util.h:207
Volume * CreateVolume(Grid &grid, Vertex *vrts, const size_t numVrts)
Definition: creator_grid_util.h:147
Face * CreateFace(Grid &grid, Vertex *vrts[], const size_t numVrts)
Definition: creator_grid_util.h:105
Vertex * CreateVertex(Grid &grid, const TPosition &pos, Grid::VertexAttachmentAccessor< Attachment< TPosition > > &aaPos)
Definition: creator_grid_util.h:46