ug4
selector_grid.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-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 
35 // ...
37 
38 #ifndef __H__LIBGRID__SELECTOR_GRID__
39 #define __H__LIBGRID__SELECTOR_GRID__
40 
41 #include <cassert>
42 #include "selector_interface.h"
43 
44 namespace ug
45 {
46 
52 // Selector
54 
95 class UG_API Selector : public ISelector
96 {
97  public:
99  typedef Grid grid_type;
100 
102  template <class TElem>
103  struct traits{
108  };
109 
110  public:
111  Selector(uint supportedElements = SE_ALL);
112  Selector(Grid& grid, uint supportedElements = SE_ALL);
113  virtual ~Selector();
114 
115  void assign_grid(Grid& grid);
116  void assign_grid(Grid* grid);
117 
119 
121  // forwards to protected ISelector method. This rather complicated setup
122  // is required to avoid virtual method calls during construction.
123  void set_supported_elements(uint shElements);
124 
126 
127  // forwards to protected ISelector method. This rather complicated setup
128  // is required to avoid virtual method calls during construction.
129  void enable_element_support(uint shElements);
130 
132 
133  // forwards to protected ISelector method. This rather complicated setup
134  // is required to avoid virtual method calls during construction.
135  void disable_element_support(uint shElements);
136 
137  virtual void clear();
138 
139  template <class TElem>
140  inline void clear();
141 
142  template <class TElem>
143  inline size_t num() const;
144 
145  inline size_t num() const;
146 
147  // empty
148  inline bool empty() const;
149 
150  template <class TElem>
151  inline bool empty() const;
152 
153  // begin
154  template <class TElem>
155  inline typename geometry_traits<TElem>::iterator
156  begin();
157 
158  template <class TElem>
160  begin() const;
161 
162  // end
163  template <class TElem>
164  inline typename geometry_traits<TElem>::iterator
165  end();
166 
167  template <class TElem>
169  end() const;
170 
171  // convenience begin and end
172  inline VertexIterator vertices_begin() {return begin<Vertex>();}
173  inline VertexIterator vertices_end() {return end<Vertex>();}
174  inline EdgeIterator edges_begin() {return begin<Edge>();}
175  inline EdgeIterator edges_end() {return end<Edge>();}
176  inline FaceIterator faces_begin() {return begin<Face>();}
177  inline FaceIterator faces_end() {return end<Face>();}
178  inline VolumeIterator volumes_begin() {return begin<Volume>();}
179  inline VolumeIterator volumes_end() {return end<Volume>();}
180 
182 
184  template <class TElem> TElem* front();
185 
187 
189  template <class TElem> TElem* back();
190 
191  // geometric-object-collection
192  virtual GridObjectCollection get_grid_objects() const;
193 
194  // callbacks that allows us to clean-up
195  // derived from GridObserver
196  //virtual void unregistered_from_grid(Grid* grid);
197  virtual void grid_to_be_destroyed(Grid* grid);
198 
200  // for compatibility with MGSelector
202  inline size_t num_levels() const;
203 
205  inline uint num(size_t) const;
207  template <class TElem> inline size_t num(size_t) const;
208 
209  // empty
211  inline bool empty(size_t) const;
212  // calls empty<TElem>();
213  template <class TElem>
214  inline bool empty(size_t) const;
215 
216  // begin
218  template <class TElem>
219  inline typename geometry_traits<TElem>::iterator
220  begin(size_t);
221 
222  // end
224  template <class TElem>
225  inline typename geometry_traits<TElem>::iterator
226  end(size_t);
227 
229  virtual bool contains_vertices() const {return num<Vertex>() > 0;}
230 
232  virtual bool contains_edges() const {return num<Edge>() > 0;}
233 
235  virtual bool contains_faces() const {return num<Face>() > 0;}
236 
238  virtual bool contains_volumes() const {return num<Volume>() > 0;}
239 
240  protected:
245 
250 
251  protected:
252  void clear_lists();
253 
254  virtual void add_to_list(Vertex* elem);
255  virtual void add_to_list(Edge* elem);
256  virtual void add_to_list(Face* elem);
257  virtual void add_to_list(Volume* elem);
258 
259  virtual void erase_from_list(Vertex* elem);
260  virtual void erase_from_list(Edge* elem);
261  virtual void erase_from_list(Face* elem);
262  virtual void erase_from_list(Volume* elem);
263 
265 
268  inline VertexSectionContainer::iterator
270  {
271  assert(is_selected(o) && "object not selected.");
272  return section_container<Vertex>().get_container().get_iterator(o);
273  }
274 
275  inline EdgeSectionContainer::iterator
277  {
278  assert(is_selected(o) && "object not selected");
279  return section_container<Edge>().get_container().get_iterator(o);
280  }
281 
282  inline FaceSectionContainer::iterator
284  {
285  assert(is_selected(o) && "object not selected");
286  return section_container<Face>().get_container().get_iterator(o);
287  }
288 
289  inline VolumeSectionContainer::iterator
291  {
292  assert(is_selected(o) && "object not selected");
293  return section_container<Volume>().get_container().get_iterator(o);
294  }
298  template <class TElem> inline
300  section_container();
301 
303  template <class TElem> inline
305  section_container() const;
306 
307  template <class TElem>
308  inline int get_section_index() const;
309 
310  private:
311  Selector(const Selector& sel){};
312 
313  protected:
318 };
319 
321 }// end of namespace
322 
324 // include implementation
325 #include "selector_grid_impl.hpp"
326 
327 #endif
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
base-implementation of a selector
Definition: selector_interface.h:126
Grid::traits< Face >::SectionContainer FaceSectionContainer
Definition: selector_interface.h:325
Grid::traits< Edge >::AttachedElementList AttachedEdgeList
Definition: selector_interface.h:319
Grid::traits< Vertex >::AttachedElementList AttachedVertexList
Definition: selector_interface.h:318
Grid::traits< Edge >::SectionContainer EdgeSectionContainer
Definition: selector_interface.h:324
Grid::traits< Face >::AttachedElementList AttachedFaceList
Definition: selector_interface.h:320
Grid::traits< Vertex >::SectionContainer VertexSectionContainer
Definition: selector_interface.h:323
Grid::traits< Volume >::SectionContainer VolumeSectionContainer
Definition: selector_interface.h:326
Grid::traits< Volume >::AttachedElementList AttachedVolumeList
Definition: selector_interface.h:321
specialization of ISelector for a grid of class Grid.
Definition: selector_grid.h:96
Selector(const Selector &sel)
Definition: selector_grid.h:311
Grid grid_type
Definition: selector_grid.h:99
EdgeSectionContainer::iterator get_iterator(Edge *o)
returns the iterator at which the given element lies in the section container
Definition: selector_grid.h:276
virtual bool contains_faces() const
returns true if the selector contains faces
Definition: selector_grid.h:235
VertexIterator vertices_end()
Definition: selector_grid.h:173
FaceSectionContainer m_faces
Definition: selector_grid.h:316
VolumeSectionContainer::iterator get_iterator(Volume *o)
returns the iterator at which the given element lies in the section container
Definition: selector_grid.h:290
FaceSectionContainer::iterator get_iterator(Face *o)
returns the iterator at which the given element lies in the section container
Definition: selector_grid.h:283
virtual bool contains_edges() const
returns true if the selector contains edges
Definition: selector_grid.h:232
VertexSectionContainer::iterator get_iterator(Vertex *o)
returns the iterator at which the given element lies in the section container
Definition: selector_grid.h:269
virtual bool contains_vertices() const
returns true if the selector contains vertices
Definition: selector_grid.h:229
EdgeSectionContainer m_edges
Definition: selector_grid.h:315
VolumeIterator volumes_end()
Definition: selector_grid.h:179
VolumeIterator volumes_begin()
Definition: selector_grid.h:178
VolumeSectionContainer m_volumes
Definition: selector_grid.h:317
VertexIterator vertices_begin()
Definition: selector_grid.h:172
EdgeIterator edges_end()
Definition: selector_grid.h:175
EdgeIterator edges_begin()
Definition: selector_grid.h:174
FaceIterator faces_end()
Definition: selector_grid.h:177
ISelector BaseClass
Definition: selector_grid.h:98
virtual bool contains_volumes() const
returns true if the selector contains volumes
Definition: selector_grid.h:238
VertexSectionContainer m_vertices
Copy Constructor not yet implemented!
Definition: selector_grid.h:311
FaceIterator faces_begin()
Definition: selector_grid.h:176
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
Definition: grid_base_object_traits.h:68
@ SE_ALL
Definition: selector_interface.h:63
#define UG_API
Definition: ug_config.h:65
unsigned int uint
Definition: types.h:114
the ug namespace
ElementStorage< Vertex >::SectionContainer::iterator VertexIterator
This Iterator will be used as base-class for iterators of specialized geometric objects.
Definition: grid_base_object_traits.h:73
ElementStorage< Face >::SectionContainer::iterator FaceIterator
Definition: grid_base_object_traits.h:79
ElementStorage< Edge >::SectionContainer::iterator EdgeIterator
Definition: grid_base_object_traits.h:76
ElementStorage< Volume >::SectionContainer::iterator VolumeIterator
Definition: grid_base_object_traits.h:82
The traits class holds some important types for each element-type.
Definition: selector_grid.h:103
geometry_traits< TElem >::const_iterator const_level_iterator
Definition: selector_grid.h:107
geometry_traits< TElem >::iterator iterator
Definition: selector_grid.h:104
geometry_traits< TElem >::const_iterator const_iterator
Definition: selector_grid.h:105
geometry_traits< TElem >::iterator level_iterator
Definition: selector_grid.h:106