Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
selector_multi_grid_impl.hpp
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_MULTI_GRID_IMPL__
39#define __H__LIBGRID__SELECTOR_MULTI_GRID_IMPL__
40
41#include <cassert>
42
43namespace ug
44{
45
46template <class TElem>
47inline int
52
53inline void
55{
56// create new SectionContainers and push them to the list,
57// until there are enough of them.
58 while((int)m_levels.size() <= level){
59 add_level();
60 }
61}
62
63template <class TElem>
64inline void
66{
67 if(m_pGrid){
68 // mark all elements as deselected
70 for(iter = begin<TElem>(level); iter != end<TElem>(level); ++iter)
71 mark_deselected(*iter);
72
73 // clear the section
74 const int sInd = get_section_index<TElem>();
75 if(sInd < 0)
76 section_container<TElem>(level).clear();
77 else
78 section_container<TElem>(level).clear_section(sInd);
79 }
80}
81
82template <class TElem>
83inline void
85{
86 if(m_pGrid){
87 for(size_t i = 0; i < num_levels(); ++i)
88 clear<TElem>(i);
89 }
90}
91
92template <class TElem>
93inline size_t
94MGSelector::num(int level) const
95{
96 const int sInd = get_section_index<TElem>();
97 if(level < (int)num_levels()){
98 if(sInd < 0)
99 return section_container<TElem>(level).num_elements();
100 else
101 return section_container<TElem>(level).num_elements(sInd);
102 }
103 return 0;
104}
105
106inline size_t
107MGSelector::num(int level) const
108{
109 return num<Vertex>(level) + num<Edge>(level)
110 + num<Face>(level) + num<Volume>(level);
111}
112
113template <class TElem>
114inline size_t
116{
117 size_t n = 0;
118 for(size_t i = 0; i < num_levels(); ++i)
119 n += num<TElem>((int)i);
120 return n;
121}
122
123inline size_t
125{
126 return num<Vertex>() + num<Edge>()
127 + num<Face>() + num<Volume>();
128}
129
130// empty
131inline bool
132MGSelector::empty(int level) const
133{
134 return num(level) == 0;
135}
136
137template <class TElem>
138inline bool
139MGSelector::empty(int level) const
140{
141 return num<TElem>(level) == 0;
142}
143
144inline bool
146{
147 return num() == 0;
148}
149
150template <class TElem>
151inline bool
153{
154 return num<TElem>() == 0;
155}
156
157// begin
158template <class TElem>
161{
162// get the begin iterator of the first level which is not empty.
163// if all levels are empty the returned iterator is equal to the end iterator
164// of the top-level.
165 size_t lvl = 0;
166 while(empty<TElem>(lvl) && (lvl < top_level()))
167 ++lvl;
168
169 return typename MGSelector::traits<TElem>::iterator(this, lvl, begin<TElem>(lvl));
170}
171
172template <class TElem>
175{
176 // get the begin iterator of the first level which is not empty.
177// if all levels are empty the returned iterator is equal to the end iterator
178// of the top-level.
179 size_t lvl = 0;
180 while(empty<TElem>(lvl) && (lvl < top_level()))
181 ++lvl;
182
183 return typename MGSelector::traits<TElem>::const_iterator(this, lvl, begin<TElem>(lvl));
184}
185
186template <class TElem>
189{
190 const int sInd = get_section_index<TElem>();
191
192 if(sInd < 0)
193 return iterator_cast<typename geometry_traits<TElem>::iterator>(
194 section_container<TElem>(level).begin());
195 else
196 return iterator_cast<typename geometry_traits<TElem>::iterator>(
197 section_container<TElem>(level).section_begin(sInd));
198}
199
200template <class TElem>
202MGSelector::begin(int level) const
203{
204 const int sInd = get_section_index<TElem>();
205
206 if(sInd < 0)
207 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
208 section_container<TElem>(level).begin());
209 else
210 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
211 section_container<TElem>(level).section_begin(sInd));
212}
213
214
215template <class TElem>
218{
219 size_t l = top_level();
220 return typename MGSelector::traits<TElem>::iterator(this, l, end<TElem>(l));
221}
222
223template <class TElem>
226{
227 size_t l = top_level();
228 return typename MGSelector::traits<TElem>::const_iterator(this, l, end<TElem>(l));
229}
230
231template <class TElem>
234{
235 const int sInd = get_section_index<TElem>();
236
237 if(sInd < 0)
238 return iterator_cast<typename geometry_traits<TElem>::iterator>(
239 section_container<TElem>(level).end());
240 else
241 return iterator_cast<typename geometry_traits<TElem>::iterator>(
242 section_container<TElem>(level).section_end(sInd));
243}
244
245template <class TElem>
247MGSelector::end(int level) const
248{
249 const int sInd = get_section_index<TElem>();
250
251 if(sInd < 0)
252 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
253 section_container<TElem>(level).end());
254 else
255 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
256 section_container<TElem>(level).section_end(sInd));
257}
258
259template <class TElem>
260TElem*
262{
263 const int sInd = get_section_index<TElem>();
264 return static_cast<TElem*>(section_container<TElem>(level).front(sInd));
265}
266
267template <class TElem>
268TElem*
270{
271 const int sInd = get_section_index<TElem>();
272 return static_cast<TElem*>(section_container<TElem>(level).back(sInd));
273}
274
275template <class TElem>
278section_container(int level)
279{
280 assert(level >= 0 && "bad level index.");
281 level_required(level);
282 Level* lev = m_levels[level];
285}
286
287
288template <class TElem>
291section_container(int level) const
292{
293 assert((level >= 0) && (level < (int)m_levels.size()) && "bad level index.");
294 const Level* lev = m_levels[level];
297}
298
299}// end of namespace
300
301#endif
void mark_deselected(Vertex *elem)
Definition selector_interface.h:368
Grid * m_pGrid
Definition selector_interface.h:388
Grid::traits< TElem >::SectionContainer & section_container(int level)
returns the section container for the given type, subset and level
Definition selector_multi_grid_impl.hpp:278
void level_required(int newSize)
Definition selector_multi_grid_impl.hpp:54
virtual void clear()
Definition selector_multi_grid.cpp:224
size_t top_level() const
Definition selector_multi_grid.h:231
LevelVec m_levels
Definition selector_multi_grid.h:445
TElem * front(int level)
returns the first selected element of the given type on the specified level.
Definition selector_multi_grid_impl.hpp:261
traits< TElem >::iterator begin()
Definition selector_multi_grid_impl.hpp:160
bool empty() const
Definition selector_multi_grid_impl.hpp:145
void add_level()
Definition selector_multi_grid.cpp:197
traits< TElem >::iterator end()
Definition selector_multi_grid_impl.hpp:217
size_t num() const
Definition selector_multi_grid_impl.hpp:115
TElem * back(int level)
returns the last selected element of the given type on the specified level.
Definition selector_multi_grid_impl.hpp:269
size_t num_levels() const
Definition selector_multi_grid.h:230
int get_section_index() const
Definition selector_multi_grid_impl.hpp:48
Definition grid_base_object_traits.h:68
the ug namespace
Definition selector_multi_grid.h:372
FaceSectionContainer m_faces
Definition selector_multi_grid.h:375
VolumeSectionContainer m_volumes
Definition selector_multi_grid.h:376
VertexSectionContainer m_vertices
Definition selector_multi_grid.h:373
EdgeSectionContainer m_edges
Definition selector_multi_grid.h:374
geometry_traits< TElem >::const_iterator const_level_iterator
Definition selector_multi_grid.h:195
MGSelectionIterator< TElem, MGSelector, level_iterator > iterator
Definition selector_multi_grid.h:197
MGSelectionIterator< TElem, const MGSelector, const_level_iterator > const_iterator
Definition selector_multi_grid.h:199
geometry_traits< TElem >::iterator level_iterator
Definition selector_multi_grid.h:194
Helper class to access the correct element storage from its element type.
Definition element_storage.h:210