ug4
subset_handler_multi_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_MULTI_GRID__
34 #define __H__LIBGRID__SUBSET_HANDLER_MULTI_GRID__
35 
36 #include <vector>
37 #include <cassert>
38 #include "lib_grid/multi_grid.h"
41 #include "../lib_grid_messages.h"
42 
43 namespace ug
44 {
45 
50 // MultiGridSubsetHandler
52 
60 {
61  public:
63 
64  public:
65  MultiGridSubsetHandler(uint supportedElements = SHE_ALL);
66  MultiGridSubsetHandler(MultiGrid& mg, uint supportedElements = SHE_ALL);
70  virtual ~MultiGridSubsetHandler();
71 
72  void assign_grid(MultiGrid& mg);
73  inline MultiGrid* multi_grid() {return m_pMG;}
74  inline const MultiGrid* multi_grid() const {return m_pMG;}
75 
77  inline void level_required(int level);
78 
80  inline uint num_levels() const {return (uint)m_levels.size();}
81 
83  template <class TGeomObj>
84  inline uint get_level(TGeomObj* obj) const {return m_pMG->get_level(obj);}
85 
87  // implementation of public virtual methdos of ISubsetHandler.
89 
90  void assign_subset(Vertex* elem, int subsetIndex);
91 
93 
94  void assign_subset(Edge* elem, int subsetIndex);
95 
97 
98  void assign_subset(Face* elem, int subsetIndex);
99 
101 
102  void assign_subset(Volume* elem, int subsetIndex);
103 
105  // element-access
107 
108  template <class TElem>
110  begin(int subsetIndex, int level);
111 
113 
114  template <class TElem>
116  end(int subsetIndex, int level);
117 
119 
121  template <class TElem>
123  begin(int subsetIndex, int level) const;
124 
126 
128  template <class TElem>
130  end(int subsetIndex, int level) const;
131 
133  template <class TElem>
134  uint num() const;
135 
137  template <class TElem>
138  uint num(int subsetIndex) const;
139 
141  template <class TElem>
142  uint num(int subsetIndex, int level) const;
143 
145  template <class TElem>
146  void clear_subset_elements(int subsetIndex);
147 
149  template <class TElem>
150  void clear_subset_elements(int subsetIndex, int level);
151 
153 
156  get_grid_objects(int subsetIndex, int level) const;
157 
159 
162  get_grid_objects_in_subset(int subsetIndex) const;
163 
165 
169  get_grid_objects_in_level(int level) const;
170 
172 
177  //virtual size_t collect_subset_elements(std::vector<Vertex*>& vrtsOut, int subsetIndex) const;
178 
180 
185  //virtual size_t collect_subset_elements(std::vector<Edge*>& edgesOut, int subsetIndex) const;
186 
188 
193  //virtual size_t collect_subset_elements(std::vector<Face*>& facesOut, int subsetIndex) const;
194 
196 
201  //virtual size_t collect_subset_elements(std::vector<Volume*>& volsOut, int subsetIndex) const;
202 
204  virtual bool contains_vertices(int subsetIndex) const {return num<Vertex>(subsetIndex) > 0;}
205 
207  virtual bool contains_edges(int subsetIndex) const {return num<Edge>(subsetIndex) > 0;}
208 
210  virtual bool contains_faces(int subsetIndex) const {return num<Face>(subsetIndex) > 0;}
211 
213  virtual bool contains_volumes(int subsetIndex) const {return num<Volume>(subsetIndex) > 0;}
214 
215 
217  virtual void grid_to_be_destroyed(Grid* grid);
218 
219  protected:
221  inline uint num_subsets_in_list() const {return m_numSubsets;}
222 
224  void detach_data();
225 
227  // implementation of protected virtual methdos of ISubsetHandler.
229  virtual void erase_subset_lists();
230 
232  void erase_subset_lists_impl();
233 
235  void clear_subset_lists(int index);
236 
238 
241  void change_subset_indices(int indOld, int indNew);
242 
243 
245  void add_required_subset_lists(int maxIndex);
246 
248  void erase_subset_lists(int index);
249 
251  void swap_subset_lists(int ind1, int ind2);
252 
254  void move_subset_lists(int indexFrom, int indexTo);
255 
257  virtual void join_subset_lists(int target, int src1, int src2);
258 
260  //void register_subset_elements_at_pipe();
261 
263  // protected helper methods
265  template<class TElem>
266  void assign_subset_impl(TElem* elem, int subsetIndex);
267 
269  template<class TElem>
270  void change_elem_subset_indices(int indOld, int indNew);
271 
273  inline void level_required(int level) const;
274 
275  void add_level();
276  void add_subset_to_all_levels();
277 
279  template <class TElem>
280  size_t collect_subset_elements_impl(std::vector<TElem*>& elemsOut, int subsetIndex) const;
281 
282  protected:
287 
292 
293  struct Subset
294  {
299  };
300 
301  typedef std::vector<Subset*> SubsetVec;
302  typedef std::vector<SubsetVec> LevelVec;
303 
305  inline Subset* subset(int si, int level) {return m_levels[level][si];}
306  inline const Subset* subset(int si, int level) const {return m_levels[level][si];}
307 
309  Subset* new_subset();
310 
311  void cleanup();
312 
314 
317  inline VertexSectionContainer::iterator
319  {
320  assert((get_subset_index(o) >= 0) && "invalid subset.");
321  return subset(get_subset_index(o), m_pMG->get_level(o))->
322  m_vertices.get_container().get_iterator(o);
323  }
324 
325  inline EdgeSectionContainer::iterator
327  {
328  assert((get_subset_index(o) >= 0) && "invalid subset.");
329  return subset(get_subset_index(o), m_pMG->get_level(o))->
330  m_edges.get_container().get_iterator(o);
331  }
332 
333  inline FaceSectionContainer::iterator
335  {
336  assert((get_subset_index(o) >= 0) && "invalid subset.");
337  return subset(get_subset_index(o), m_pMG->get_level(o))->
338  m_faces.get_container().get_iterator(o);
339  }
340 
341  inline VolumeSectionContainer::iterator
343  {
344  assert((get_subset_index(o) >= 0) && "invalid subset.");
345  return subset(get_subset_index(o), m_pMG->get_level(o))->
346  m_volumes.get_container().get_iterator(o);
347  }
351  template <class TElem> inline
353  section_container(int si, int lvl);
354 
356  template <class TElem> inline
358  section_container(int si, int lvl) const;
359 
361  void multigrid_changed(const GridMessage_MultiGridChanged& gm);
362 
363  protected:
367 
368  // callback-id (automatically unregisters callback, when the selector is deleted).
370 
375 };
376 
378 
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 message sent by the MultiGrid, if something special happened.
Definition: lib_grid_messages.h:51
a helper class that holds a collection of possibly unconnected geometric-objects.
Definition: grid_object_collection.h:96
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
Definition: multi_grid.h:72
Handles subsets on a per level basis.
Definition: subset_handler_multi_grid.h:60
uint num_subsets_in_list() const
returns the number of subsets in the local list
Definition: subset_handler_multi_grid.h:221
const MultiGrid * multi_grid() const
Definition: subset_handler_multi_grid.h:74
virtual bool contains_vertices(int subsetIndex) const
collects all vertices that are in the given subset.
Definition: subset_handler_multi_grid.h:204
AttachedFaceList::AEntry m_aSharedEntryFACE
Definition: subset_handler_multi_grid.h:373
FaceSectionContainer::iterator get_list_iterator(Face *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_multi_grid.h:334
size_t collect_subset_elements_impl(std::vector< TElem * > &elemsOut, int subsetIndex) const
helper for collect_subset_elements
MultiGrid * m_pMG
Definition: subset_handler_multi_grid.h:364
AttachedEdgeList::AEntry m_aSharedEntryEDGE
Definition: subset_handler_multi_grid.h:372
const Subset * subset(int si, int level) const
Definition: subset_handler_multi_grid.h:306
LevelVec m_levels
Definition: subset_handler_multi_grid.h:365
MessageHub::SPCallbackId m_callbackId
Definition: subset_handler_multi_grid.h:369
virtual bool contains_edges(int subsetIndex) const
returns true if the subset contains edges
Definition: subset_handler_multi_grid.h:207
MultiGrid * multi_grid()
Definition: subset_handler_multi_grid.h:73
AttachedVolumeList::AEntry m_aSharedEntryVOL
Definition: subset_handler_multi_grid.h:374
Subset * subset(int si, int level)
returns the subset with index si on the given level
Definition: subset_handler_multi_grid.h:305
virtual bool contains_volumes(int subsetIndex) const
returns true if the subset contains volumes
Definition: subset_handler_multi_grid.h:213
AttachedVertexList::AEntry m_aSharedEntryVRT
Definition: subset_handler_multi_grid.h:371
VolumeSectionContainer::iterator get_list_iterator(Volume *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_multi_grid.h:342
uint get_level(TGeomObj *obj) const
returns the level in which an element is located
Definition: subset_handler_multi_grid.h:84
VertexSectionContainer::iterator get_list_iterator(Vertex *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_multi_grid.h:318
uint num_levels() const
returns the number of levels
Definition: subset_handler_multi_grid.h:80
virtual bool contains_faces(int subsetIndex) const
returns true if the subset contains faces
Definition: subset_handler_multi_grid.h:210
std::vector< Subset * > SubsetVec
Definition: subset_handler_multi_grid.h:301
EdgeSectionContainer::iterator get_list_iterator(Edge *o)
returns the iterator at which the given element lies in the section container
Definition: subset_handler_multi_grid.h:326
std::vector< SubsetVec > LevelVec
Definition: subset_handler_multi_grid.h:302
int m_numSubsets
Definition: subset_handler_multi_grid.h:366
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
MultiGridSubsetHandler MGSubsetHandler
Definition: subset_handler_multi_grid.h:377
Definition: subset_handler_multi_grid.h:294
VolumeSectionContainer m_volumes
Definition: subset_handler_multi_grid.h:298
FaceSectionContainer m_faces
Definition: subset_handler_multi_grid.h:297
EdgeSectionContainer m_edges
Definition: subset_handler_multi_grid.h:296
VertexSectionContainer m_vertices
Definition: subset_handler_multi_grid.h:295