ug4
subset_handler_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 
33 #ifndef __H__LIBGRID__SUBSET_HANDLER_GRID__
34 #define __H__LIBGRID__SUBSET_HANDLER_GRID__
35 
36 #include <vector>
37 #include <cassert>
38 #include "lib_grid/grid/grid.h"
41 
42 namespace ug
43 {
44 
49 // GridSubsetHandler
51 
53 {
54  public:
56 
57  public:
58  GridSubsetHandler(uint supportedElements = SHE_ALL);
59  GridSubsetHandler(Grid& grid, uint supportedElements = SHE_ALL);
64 
65  GridSubsetHandler& operator = (const GridSubsetHandler& sh);
66  GridSubsetHandler& operator = (const ISubsetHandler& sh);
67 
68  void assign_grid(Grid* grid);
69  void assign_grid(Grid& grid);
70 
72  // implementation of public virtual methdos of ISubsetHandler.
74 
75  void assign_subset(Vertex* elem, int subsetIndex);
76 
78 
79  void assign_subset(Edge* elem, int subsetIndex);
80 
82 
83  void assign_subset(Face* elem, int subsetIndex);
84 
86 
87  void assign_subset(Volume* elem, int subsetIndex);
88 
90  // element-access
92 
93  template <class TElem>
95  begin(int subsetIndex);
96 
98 
99  template <class TElem>
101  end(int subsetIndex);
102 
104 
105  template <class TElem>
107  begin(int subsetIndex) const;
108 
110 
111  template <class TElem>
113  end(int subsetIndex) const;
114 
116  template <class TElem>
117  uint num_elements(int subsetIndex) const;
118 
120  template <class TElem>
121  uint num() const;
122 
124  template <class TElem>
125  uint num(int subsetIndex) const;
126 
128  template <class TElem> inline
129  bool empty() const;
130 
132  inline bool empty() const;
133 
134  template <class TElem> inline
135  bool empty(int subsetIndex) const;
136 
138  inline bool empty(int subsetIndex) const;
139 
141  template <class TElem>
142  void clear_subset_elements(int subsetIndex);
143 
144  // geometric-object-collection
145  virtual GridObjectCollection
146  get_grid_objects_in_subset(int subsetIndex) const;
147 
148  // multi-level-geometric-object-collection
150  get_grid_objects() const;
151 
153 
158  //virtual size_t collect_subset_elements(std::vector<Vertex*>& vrtsOut, int subsetIndex) const;
159 
161 
166  //virtual size_t collect_subset_elements(std::vector<Edge*>& edgesOut, int subsetIndex) const;
167 
169 
174  //virtual size_t collect_subset_elements(std::vector<Face*>& facesOut, int subsetIndex) const;
175 
177 
182  //virtual size_t collect_subset_elements(std::vector<Volume*>& volsOut, int subsetIndex) const;
183 
185  virtual bool contains_vertices(int subsetIndex) const {return num<Vertex>(subsetIndex) > 0;}
186 
188  virtual bool contains_edges(int subsetIndex) const {return num<Edge>(subsetIndex) > 0;}
189 
191  virtual bool contains_faces(int subsetIndex) const {return num<Face>(subsetIndex) > 0;}
192 
194  virtual bool contains_volumes(int subsetIndex) const {return num<Volume>(subsetIndex) > 0;}
195 
197  template <class TElem>
198  bool perform_self_tests();
199 
201  // for compatibility with MGSubsetHandler
203 
204  uint num_levels() const {return 1;}
205 
207 
210  template <class TElem>
212  begin(int subsetIndex, size_t) const {return begin<TElem>(subsetIndex);}
213 
215 
218  template <class TElem>
220  end(int subsetIndex, size_t) const {return end<TElem>(subsetIndex);}
221 
223 
225  template <class TElem>
226  uint num_elements(int subsetIndex, size_t) const {return num_elements<TElem>();}
227 
229 
231  template <class TElem>
232  uint num(int subsetIndex, size_t) const {return num<TElem>();}
233 
234 
236  virtual void grid_to_be_destroyed(Grid* grid);
237 
238  protected:
243 
248 
250  inline uint num_subsets_in_list() const {return (uint)m_subsets.size();}
251 
253  void detach_data();
254 
256  // implementation of protected virtual methdos of ISubsetHandler.
258  virtual void erase_subset_lists();
259 
261  void erase_subset_lists_impl();
262 
264  virtual void clear_subset_lists(int index);
265 
267 
270  virtual void change_subset_indices(int indOld, int indNew);
271 
272 
274  void add_required_subset_lists(int maxIndex);
275 
277  void erase_subset_lists(int index);
278 
280  void swap_subset_lists(int ind1, int ind2);
281 
283  void move_subset_lists(int indexFrom, int indexTo);
284 
286  void join_subset_lists(int target, int src1, int src2);
287 
289  //void register_subset_elements_at_pipe();
290 
292  // protected helper methods
294  template<class TElem> inline
295  void assign_subset_impl(TElem* elem, int subsetIndex);
296 
298  template<class TElem>
299  void change_elem_subset_indices(int indOld, int indNew);
300 
302  //template <class TElem>
303  //size_t collect_subset_elements_impl(std::vector<TElem*>& elemsOut, int subsetIndex) const;
304 
306  void cleanup();
307 
309 
312  inline VertexSectionContainer::iterator
314  {
315  assert((get_subset_index(o) >= 0) && "invalid subset.");
316  return section_container<Vertex>(get_subset_index(o)).
317  get_container().get_iterator(o);
318  }
319 
320  inline EdgeSectionContainer::iterator
322  {
323  assert((get_subset_index(o) >= 0) && "invalid subset.");
324  return section_container<Edge>(get_subset_index(o)).
325  get_container().get_iterator(o);
326  }
327 
328  inline FaceSectionContainer::iterator
330  {
331  assert((get_subset_index(o) >= 0) && "invalid subset.");
332  return section_container<Face>(get_subset_index(o)).
333  get_container().get_iterator(o);
334  }
335 
336  inline VolumeSectionContainer::iterator
338  {
339  assert((get_subset_index(o) >= 0) && "invalid subset.");
340  return section_container<Volume>(get_subset_index(o)).
341  get_container().get_iterator(o);
342  }
346  template <class TElem> inline
348  section_container(int si);
349 
351  template <class TElem> inline
353  section_container(int si) const;
354 
355  protected:
356  struct Subset
357  {
362  };
363 
364  typedef std::vector<Subset*> SubsetVec;
365 
366  protected:
368  // we use a shared attachment for the entry-lists of all section containers
373 };
374 
375 
377 
380 }// end of namespace
381 
382 // include implementation
384 
385 #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
Partitions elements of a grid into several subsets.
Definition: subset_handler_grid.h:53
VertexSectionContainer::iterator get_list_iterator(Vertex *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_grid.h:313
std::vector< Subset * > SubsetVec
Definition: subset_handler_grid.h:364
virtual bool contains_volumes(int subsetIndex) const
returns true if the subset contains volumes
Definition: subset_handler_grid.h:194
AttachedVertexList::AEntry m_aSharedEntryVRT
Definition: subset_handler_grid.h:369
uint num(int subsetIndex, size_t) const
returns the number of elements in the given subset
Definition: subset_handler_grid.h:232
uint num_levels() const
returns number of levels (always 1)
Definition: subset_handler_grid.h:204
virtual bool contains_edges(int subsetIndex) const
returns true if the subset contains edges
Definition: subset_handler_grid.h:188
AttachedFaceList::AEntry m_aSharedEntryFACE
Definition: subset_handler_grid.h:371
EdgeSectionContainer::iterator get_list_iterator(Edge *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_grid.h:321
SubsetVec m_subsets
Definition: subset_handler_grid.h:367
virtual bool contains_faces(int subsetIndex) const
returns true if the subset contains faces
Definition: subset_handler_grid.h:191
FaceSectionContainer::iterator get_list_iterator(Face *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_grid.h:329
AttachedVolumeList::AEntry m_aSharedEntryVOL
Definition: subset_handler_grid.h:372
AttachedEdgeList::AEntry m_aSharedEntryEDGE
Definition: subset_handler_grid.h:370
uint num_subsets_in_list() const
returns the number of subsets in the local list
Definition: subset_handler_grid.h:250
VolumeSectionContainer::iterator get_list_iterator(Volume *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_grid.h:337
geometry_traits< TElem >::const_iterator begin(int subsetIndex, size_t) const
returns the begin-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_grid.h:212
virtual bool contains_vertices(int subsetIndex) const
collects all vertices that are in the given subset.
Definition: subset_handler_grid.h:185
uint num_elements(int subsetIndex, size_t) const
returns the number of elements in the given subset
Definition: subset_handler_grid.h:226
geometry_traits< TElem >::const_iterator end(int subsetIndex, size_t) const
returns the end-iterator for the elements of type TElem in the given subset.
Definition: subset_handler_grid.h:220
Definition: subset_handler_interface.h:223
Grid::traits< Edge >::SectionContainer EdgeSectionContainer
Definition: subset_handler_interface.h:562
Grid::traits< Edge >::AttachedElementList AttachedEdgeList
Definition: subset_handler_interface.h:557
Grid::traits< Vertex >::SectionContainer VertexSectionContainer
Definition: subset_handler_interface.h:561
Grid::traits< Vertex >::AttachedElementList AttachedVertexList
enable subset-attachment support
Definition: subset_handler_interface.h:556
void assign_subset(TIterator iterBegin, TIterator iterEnd, int subsetIndex)
Definition: subset_handler_interface_impl.hpp:170
Grid::traits< Face >::AttachedElementList AttachedFaceList
Definition: subset_handler_interface.h:558
Grid::traits< Volume >::AttachedElementList AttachedVolumeList
Definition: subset_handler_interface.h:559
Grid::traits< Face >::SectionContainer FaceSectionContainer
Definition: subset_handler_interface.h:563
Grid::traits< Volume >::SectionContainer VolumeSectionContainer
Definition: subset_handler_interface.h:564
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
@ SHE_ALL
Definition: subset_handler_interface.h:66
#define UG_API
Definition: ug_config.h:65
unsigned int uint
Definition: types.h:114
size_t target(SM_edge< typename T::value_type > const &e, ug::BidirectionalMatrix< T > const &m)
Definition: bidirectional_boost.h:100
the ug namespace
GridSubsetHandler SubsetHandler
Definition: subset_handler_grid.h:376
Definition: subset_handler_grid.h:357
EdgeSectionContainer m_edges
Definition: subset_handler_grid.h:359
FaceSectionContainer m_faces
Definition: subset_handler_grid.h:360
VertexSectionContainer m_vertices
Definition: subset_handler_grid.h:358
VolumeSectionContainer m_volumes
Definition: subset_handler_grid.h:361