ug4
grid_objects_1d.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-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__grid_objects_1d__
34 #define __H__UG__grid_objects_1d__
35 
36 #include "../grid/grid.h"
37 #include "common/math/ugmath.h"
38 #include "common/assert.h"
39 #include "grid_objects_0d.h"
40 
41 namespace ug
42 {
43 
46 
48 {
53 };
54 
55 
56 
58 // RegularEdge
60 
65 class UG_API RegularEdge : public Edge
66 {
67  friend class Grid;
68  public:
69  inline static bool type_match(GridObject* pObj) {return dynamic_cast<RegularEdge*>(pObj) != NULL;}
70 
73  {
74  m_vertices[0] = v1;
75  m_vertices[1] = v2;
76  }
77 
78  RegularEdge(const EdgeDescriptor& descriptor)
79  {
80  m_vertices[0] = descriptor.vertex(0);
81  m_vertices[1] = descriptor.vertex(1);
82  }
83 
84  virtual ~RegularEdge() {}
85 
86  virtual GridObject* create_empty_instance() const {return new RegularEdge;}
87 
88  virtual int container_section() const {return CSEDGE_REGULAR_EDGE;}
90 
92 
96  virtual bool refine(std::vector<Edge*>& vNewEdgesOut,
97  Vertex* newVertex,
98  Vertex** pSubstituteVrts = NULL);
99 
100 //TODO: Think about this method. It is not safe!
102 
106  bool refine(std::vector<RegularEdge*>& vNewEdgesOut,
107  Vertex* newVertex,
108  Vertex** pSubstituteVrts = NULL);
109 };
110 
111 template <>
113 {
114  public:
118 
121 
122  enum
123  {
124  CONTAINER_SECTION = CSEDGE_REGULAR_EDGE,
125  BASE_OBJECT_ID = EDGE
126  };
127  static const ReferenceObjectID REFERENCE_OBJECT_ID = ROID_EDGE;
128 };
129 
132 
133 
134 
136 // ConstrainedEdge
138 
146 {
147  friend class Grid;
148  public:
149  inline static bool type_match(GridObject* pObj) {return dynamic_cast<ConstrainedEdge*>(pObj) != NULL;}
150 
151  ConstrainedEdge() : m_pConstrainingObject(NULL), m_parentBaseObjectId(-1) {}
153  m_pConstrainingObject(NULL),
154  m_parentBaseObjectId(-1)
155  {
156  m_vertices[0] = v1;
157  m_vertices[1] = v2;
158  }
159 
160  ConstrainedEdge(const EdgeDescriptor& descriptor) :
161  m_pConstrainingObject(NULL),
162  m_parentBaseObjectId(-1)
163  {
164  m_vertices[0] = descriptor.vertex(0);
165  m_vertices[1] = descriptor.vertex(1);
166  }
167 
169  {
170  if(m_pConstrainingObject)
171  m_pConstrainingObject->remove_constraint_link(this);
172  }
173 
174  virtual GridObject* create_empty_instance() const {return new ConstrainedEdge;}
175 
176  virtual int container_section() const {return CSEDGE_CONSTRAINED_EDGE;}
178 
179  virtual bool is_constrained() const {return true;}
180 
181  virtual void remove_constraint_link(const Edge* e)
182  {
183  if(m_pConstrainingObject == static_cast<const GridObject*>(e)){
184  m_pConstrainingObject = NULL;
185  }
186  }
187 
188  virtual void remove_constraint_link(const Face* f)
189  {
190  if(m_pConstrainingObject == static_cast<const GridObject*>(f)){
191  m_pConstrainingObject = NULL;
192  }
193  }
194 
196 
202  virtual bool refine(std::vector<Edge*>& vNewEdgesOut,
203  Vertex* newVertex,
204  Vertex** pSubstituteVrts = NULL);
205 
206 //TODO: Think about this method. It is not safe!
208 
214  bool refine(std::vector<ConstrainedEdge*>& vNewEdgesOut,
215  Vertex* newVertex,
216  Vertex** pSubstituteVrts = NULL);
217 
219  {
220  m_pConstrainingObject = pObj;
221  if(pObj)
222  m_parentBaseObjectId = pObj->base_object_id();
223  }
224 
225  inline GridObject* get_constraining_object() {return m_pConstrainingObject;}
226 
227  inline int get_parent_base_object_id() {return m_parentBaseObjectId;}
228  inline void set_parent_base_object_id(int id)
229  {
230  if((m_parentBaseObjectId != -1) && (m_parentBaseObjectId != id)){
231  UG_THROW("Bad parent base object id specified! The given id"
232  " has to match the id of the constraining object if that"
233  " is present. Call this method only, if no constraining"
234  " object has been set!");
235  }
236  m_parentBaseObjectId = id;
237  }
238 
239 
240  protected:
243 };
244 
245 template <>
247 {
248  public:
252 
255 
256  enum
257  {
258  CONTAINER_SECTION = CSEDGE_CONSTRAINED_EDGE,
259  BASE_OBJECT_ID = EDGE
260  };
261  static const ReferenceObjectID REFERENCE_OBJECT_ID = ROID_EDGE;
262 };
263 
266 
267 
268 
270 // ConstrainingEdge
272 
279 {
280  friend class Grid;
281  public:
282  inline static bool type_match(GridObject* pObj) {return dynamic_cast<ConstrainingEdge*>(pObj) != NULL;}
283 
286  {
287  m_vertices[0] = v1;
288  m_vertices[1] = v2;
289  m_constrainedVertices.reserve(1);
290  m_constrainedEdges.reserve(2);
291  }
292 
293  ConstrainingEdge(const EdgeDescriptor& descriptor)
294  {
295  m_vertices[0] = descriptor.vertex(0);
296  m_vertices[1] = descriptor.vertex(1);
297  m_constrainedVertices.reserve(1);
298  m_constrainedEdges.reserve(2);
299  }
300 
302  {
303  for(size_t i = 0; i < m_constrainedVertices.size(); ++i){
304  m_constrainedVertices[i]->remove_constraint_link(this);
305  }
306 
307  for(size_t i = 0; i < m_constrainedEdges.size(); ++i){
308  m_constrainedEdges[i]->remove_constraint_link(this);
309  }
310  }
311 
312  virtual GridObject* create_empty_instance() const {return new ConstrainingEdge;}
313 
314  virtual int container_section() const {return CSEDGE_CONSTRAINING_EDGE;}
316 
317  virtual bool is_constraining() const {return true;}
318 
319 
320  virtual void remove_constraint_link(const Vertex* vrt)
321  {
322  unconstrain_object(vrt);
323  }
324 
325  virtual void remove_constraint_link(const Edge* e)
326  {
327  unconstrain_object(e);
328  }
329 
330 
332 
337  virtual bool refine(std::vector<Edge*>& vNewEdgesOut,
338  Vertex* newVertex,
339  Vertex** pSubstituteVrts = NULL);
340 
341 //TODO: Think about this method. It is not safe!
343 
348  bool refine(std::vector<ConstrainingEdge*>& vNewEdgesOut,
349  Vertex* newVertex,
350  Vertex** pSubstituteVrts = NULL);
351 
352 
353  inline void add_constrained_object(Vertex* pObj)
354  {
355  UG_ASSERT(!is_constrained_object(pObj), "vertex is already constrained by this edge.");
356  m_constrainedVertices.push_back(pObj);
357  }
358 
359  inline void add_constrained_object(Edge* pObj)
360  {
361  UG_ASSERT(!is_constrained_object(pObj), "edge is already constrained by this edge.");
362  m_constrainedEdges.push_back(pObj);
363  }
364 
365  inline bool is_constrained_object(Vertex* vrt)
366  {
367  std::vector<Vertex*>::iterator iter = find(m_constrainedVertices.begin(),
368  m_constrainedVertices.end(), vrt);
369  return iter != m_constrainedVertices.end();
370  }
371 
372  inline bool is_constrained_object(Edge* edge)
373  {
374  std::vector<Edge*>::iterator iter = find(m_constrainedEdges.begin(),
375  m_constrainedEdges.end(), edge);
376  return iter != m_constrainedEdges.end();
377  }
378 
379  inline void unconstrain_object(const Vertex* vrt)
380  {
381  std::vector<Vertex*>::iterator iter = find(m_constrainedVertices.begin(),
382  m_constrainedVertices.end(), vrt);
383  if(iter != m_constrainedVertices.end())
384  m_constrainedVertices.erase(iter);
385  }
386 
387  inline void unconstrain_object(const Edge* edge)
388  {
389  std::vector<Edge*>::iterator iter = find(m_constrainedEdges.begin(),
390  m_constrainedEdges.end(), edge);
391  if(iter != m_constrainedEdges.end())
392  m_constrainedEdges.erase(iter);
393  }
394 
395  inline void clear_constrained_vertices() {m_constrainedVertices.clear();}
396  inline void clear_constrained_edges() {m_constrainedEdges.clear();}
398  {
399  clear_constrained_vertices();
400  clear_constrained_edges();
401  }
402 
403  // NUMBER OF CONSTRAINED ELEMENTS
404  inline size_t num_constrained_vertices() const {return m_constrainedVertices.size();}
405  inline size_t num_constrained_edges() const {return m_constrainedEdges.size();}
406 
407  template <class TElem> size_t num_constrained() const;
408 
409 
410  // ACCESS TO CONSTRAINED ELEMENTS
411  Vertex* constrained_vertex(size_t ind) const
412  {
413  UG_ASSERT(ind < m_constrainedVertices.size(), "bad index");
414  return m_constrainedVertices[ind];
415  }
416 
417  Edge* constrained_edge(size_t ind) const
418  {
419  UG_ASSERT(ind < m_constrainedEdges.size(), "bad index");
420  return m_constrainedEdges[ind];
421  }
422 
423  template <class TElem> TElem* constrained(size_t ind) const;
424 
425  protected:
426  std::vector<Vertex*> m_constrainedVertices;
427  std::vector<Edge*> m_constrainedEdges;
428 };
429 
430 template <>
432 {
433  public:
437 
440 
441  enum
442  {
443  CONTAINER_SECTION = CSEDGE_CONSTRAINING_EDGE,
444  BASE_OBJECT_ID = EDGE
445  };
446  static const ReferenceObjectID REFERENCE_OBJECT_ID = ROID_EDGE;
447 };
448 
451 
452 }// end of namespace
453 
454 #endif
Use this class as a tool to create const_iterators to your own geometric objects.
Definition: generic_grid_object_iterator.h:70
This edge is a sub-edge of a.
Definition: grid_objects_1d.h:146
GridObject * get_constraining_object()
Definition: grid_objects_1d.h:225
static bool type_match(GridObject *pObj)
Definition: grid_objects_1d.h:149
int get_parent_base_object_id()
Definition: grid_objects_1d.h:227
GridObject * m_pConstrainingObject
Definition: grid_objects_1d.h:241
ConstrainedEdge(const EdgeDescriptor &descriptor)
Definition: grid_objects_1d.h:160
virtual ~ConstrainedEdge()
Definition: grid_objects_1d.h:168
virtual void remove_constraint_link(const Edge *e)
removes a constraint link to the grid object.
Definition: grid_objects_1d.h:181
virtual ReferenceObjectID reference_object_id() const
Definition: grid_objects_1d.h:177
void set_parent_base_object_id(int id)
Definition: grid_objects_1d.h:228
ConstrainedEdge()
Definition: grid_objects_1d.h:151
virtual void remove_constraint_link(const Face *f)
removes a constraint link to the grid object.
Definition: grid_objects_1d.h:188
virtual int container_section() const
Definition: grid_objects_1d.h:176
int m_parentBaseObjectId
Definition: grid_objects_1d.h:242
ConstrainedEdge(Vertex *v1, Vertex *v2)
Definition: grid_objects_1d.h:152
void set_constraining_object(GridObject *pObj)
Definition: grid_objects_1d.h:218
virtual GridObject * create_empty_instance() const
create an instance of the derived type
Definition: grid_objects_1d.h:174
virtual bool is_constrained() const
returns true if the object is constrained by other objects.
Definition: grid_objects_1d.h:179
contains elements of type
Definition: grid_objects_1d.h:279
void add_constrained_object(Edge *pObj)
Definition: grid_objects_1d.h:359
bool is_constrained_object(Vertex *vrt)
Definition: grid_objects_1d.h:365
ConstrainingEdge()
Definition: grid_objects_1d.h:284
void add_constrained_object(Vertex *pObj)
Definition: grid_objects_1d.h:353
virtual bool is_constraining() const
returns the id of the reference-object.
Definition: grid_objects_1d.h:317
Vertex * constrained_vertex(size_t ind) const
Definition: grid_objects_1d.h:411
TElem * constrained(size_t ind) const
virtual GridObject * create_empty_instance() const
create an instance of the derived type
Definition: grid_objects_1d.h:312
void unconstrain_object(const Vertex *vrt)
Definition: grid_objects_1d.h:379
virtual void remove_constraint_link(const Vertex *vrt)
removes a constraint link to the grid object.
Definition: grid_objects_1d.h:320
void unconstrain_object(const Edge *edge)
Definition: grid_objects_1d.h:387
ConstrainingEdge(const EdgeDescriptor &descriptor)
Definition: grid_objects_1d.h:293
virtual ReferenceObjectID reference_object_id() const
Definition: grid_objects_1d.h:315
size_t num_constrained_vertices() const
Definition: grid_objects_1d.h:404
std::vector< Edge * > m_constrainedEdges
Definition: grid_objects_1d.h:427
virtual int container_section() const
Definition: grid_objects_1d.h:314
bool is_constrained_object(Edge *edge)
Definition: grid_objects_1d.h:372
virtual void remove_constraint_link(const Edge *e)
removes a constraint link to the grid object.
Definition: grid_objects_1d.h:325
void clear_constrained_edges()
Definition: grid_objects_1d.h:396
size_t num_constrained() const
std::vector< Vertex * > m_constrainedVertices
Definition: grid_objects_1d.h:426
void clear_constrained_vertices()
Definition: grid_objects_1d.h:395
Edge * constrained_edge(size_t ind) const
Definition: grid_objects_1d.h:417
ConstrainingEdge(Vertex *v1, Vertex *v2)
Definition: grid_objects_1d.h:285
virtual ~ConstrainingEdge()
Definition: grid_objects_1d.h:301
static bool type_match(GridObject *pObj)
Definition: grid_objects_1d.h:282
void clear_constrained_objects()
Definition: grid_objects_1d.h:397
size_t num_constrained_edges() const
Definition: grid_objects_1d.h:405
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
virtual Vertex * vertex(size_t index) const
Definition: grid_base_objects.h:366
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Use this class as a tool to create iterators to your own geometric objects.
Definition: generic_grid_object_iterator.h:44
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
virtual int base_object_id() const =0
Edges connect two vertices.
Definition: grid_objects_1d.h:66
virtual int container_section() const
Definition: grid_objects_1d.h:88
RegularEdge(Vertex *v1, Vertex *v2)
Definition: grid_objects_1d.h:72
static bool type_match(GridObject *pObj)
Definition: grid_objects_1d.h:69
virtual GridObject * create_empty_instance() const
create an instance of the derived type
Definition: grid_objects_1d.h:86
RegularEdge()
Definition: grid_objects_1d.h:71
virtual ReferenceObjectID reference_object_id() const
Definition: grid_objects_1d.h:89
RegularEdge(const EdgeDescriptor &descriptor)
Definition: grid_objects_1d.h:78
virtual ~RegularEdge()
Definition: grid_objects_1d.h:84
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
GenericGridObjectIterator< ConstrainedEdge *, EdgeIterator > iterator
Definition: grid_objects_1d.h:249
ConstGenericGridObjectIterator< ConstrainedEdge *, EdgeIterator, ConstEdgeIterator > const_iterator
Definition: grid_objects_1d.h:251
Edge grid_base_object
Definition: grid_objects_1d.h:254
EdgeDescriptor Descriptor
Definition: grid_objects_1d.h:253
ConstGenericGridObjectIterator< ConstrainingEdge *, EdgeIterator, ConstEdgeIterator > const_iterator
Definition: grid_objects_1d.h:436
GenericGridObjectIterator< ConstrainingEdge *, EdgeIterator > iterator
Definition: grid_objects_1d.h:434
EdgeDescriptor Descriptor
Definition: grid_objects_1d.h:438
Edge grid_base_object
Definition: grid_objects_1d.h:439
ConstGenericGridObjectIterator< RegularEdge *, EdgeIterator, ConstEdgeIterator > const_iterator
Definition: grid_objects_1d.h:117
GenericGridObjectIterator< RegularEdge *, EdgeIterator > iterator
Definition: grid_objects_1d.h:115
Edge grid_base_object
Definition: grid_objects_1d.h:120
EdgeDescriptor Descriptor
Definition: grid_objects_1d.h:119
Definition: grid_base_object_traits.h:68
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_THROW(msg)
Definition: error.h:57
#define UG_API
Definition: ug_config.h:65
the ug namespace
IndexLayout::Interface::iterator find(IndexLayout::Interface &interface, size_t i)
Definition: parallel_index_layout.h:77
geometry_traits< ConstrainedEdge >::const_iterator ConstConstrainedEdgeIterator
Definition: grid_objects_1d.h:265
ReferenceObjectID
these ids are used to identify the shape of a geometric object.
Definition: grid_base_objects.h:74
@ ROID_EDGE
Definition: grid_base_objects.h:77
ElementStorage< Edge >::SectionContainer::iterator EdgeIterator
Definition: grid_base_object_traits.h:76
ElementStorage< Edge >::SectionContainer::const_iterator ConstEdgeIterator
Definition: grid_base_object_traits.h:77
geometry_traits< RegularEdge >::iterator RegularEdgeIterator
Definition: grid_objects_1d.h:130
geometry_traits< RegularEdge >::const_iterator ConstRegularEdgeIterator
Definition: grid_objects_1d.h:131
@ EDGE
Definition: grid_base_objects.h:61
geometry_traits< ConstrainingEdge >::iterator ConstrainingEdgeIterator
Definition: grid_objects_1d.h:449
geometry_traits< ConstrainedEdge >::iterator ConstrainedEdgeIterator
Definition: grid_objects_1d.h:264
EdgeContainerSections
These numbers define where in the edge-section-container an edge will be stored.
Definition: grid_objects_1d.h:48
@ CSEDGE_REGULAR_EDGE
Definition: grid_objects_1d.h:50
@ CSEDGE_CONSTRAINING_EDGE
Definition: grid_objects_1d.h:52
@ CSEDGE_CONSTRAINED_EDGE
Definition: grid_objects_1d.h:51
@ CSEDGE_NONE
Definition: grid_objects_1d.h:49
geometry_traits< ConstrainingEdge >::const_iterator ConstConstrainingEdgeIterator
Definition: grid_objects_1d.h:450