Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
subset_handler_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
33#ifndef __H__LIBGRID__SUBSET_HANDLER_GRID_IMPL__
34#define __H__LIBGRID__SUBSET_HANDLER_GRID_IMPL__
35
36#include <cassert>
37
38namespace ug
39{
40
41template <class TElem>
42typename geometry_traits<TElem>::iterator
44begin(int subsetIndex)
45{
46 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
47
48 if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
49 return iterator_cast<typename geometry_traits<TElem>::iterator>(
51
52 if(sectionInd < 0)
53 return iterator_cast<typename geometry_traits<TElem>::iterator>(
54 section_container<TElem>(subsetIndex).begin());
55 else
56 return iterator_cast<typename geometry_traits<TElem>::iterator>(
57 section_container<TElem>(subsetIndex).section_begin(sectionInd));
58}
59
60template <class TElem>
63end(int subsetIndex)
64{
65 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
66
67 if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
68 return iterator_cast<typename geometry_traits<TElem>::iterator>(
70
71 if(sectionInd < 0)
72 return iterator_cast<typename geometry_traits<TElem>::iterator>(
73 section_container<TElem>(subsetIndex).end());
74 else
75 return iterator_cast<typename geometry_traits<TElem>::iterator>(
76 section_container<TElem>(subsetIndex).section_end(sectionInd));
77}
78
79template <class TElem>
82begin(int subsetIndex) const
83{
84 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
85
86 if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
87 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
89
90 if(sectionInd < 0)
91 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
92 section_container<TElem>(subsetIndex).begin());
93 else
94 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
95 section_container<TElem>(subsetIndex).section_begin(sectionInd));
96}
97
98template <class TElem>
101end(int subsetIndex) const
102{
103 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
104
105 if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
106 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
108
109 if(sectionInd < 0)
110 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
111 section_container<TElem>(subsetIndex).end());
112 else
113 return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
114 section_container<TElem>(subsetIndex).section_end(sectionInd));
115}
116
117
118template <class TElem>
119void
121clear_subset_elements(int subsetIndex)
122{
123 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
124
125 if(subsetIndex < 0 || subsetIndex >= (int)num_subsets_in_list())
126 return;
127
128// iterate through the elements of type TElem and erase them from the subsets list.
129 if(m_pGrid != NULL)
130 {
132 section_container<TElem>(subsetIndex);
133
134 typename geometry_traits<TElem>::iterator iter = begin<TElem>(subsetIndex);
135 while(iter != end<TElem>(subsetIndex))
136 {
137 typename geometry_traits<TElem>::iterator iterErase = iter++;
138 alter_subset_index(*iterErase) = -1;
139 secCon.erase(iterErase, sectionInd);
140 }
141 }
142}
143
144template <class TElem>
145uint
147num_elements(int subsetIndex) const
148{
149 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
150
151 if((subsetIndex < 0) || (subsetIndex >= (int)num_subsets_in_list()))
152 return 0;
153
154 if(sectionInd < 0)
155 return section_container<TElem>(subsetIndex).num_elements();
156 else
157 return section_container<TElem>(subsetIndex).num_elements(sectionInd);
158}
159
160template <class TElem>
161uint
163num(int subsetIndex) const
164{
165 const int sectionInd = geometry_traits<TElem>::CONTAINER_SECTION;
166
167 if((subsetIndex < 0) || (subsetIndex >= (int)num_subsets_in_list()))
168 return 0;
169
170 if(sectionInd < 0)
171 return section_container<TElem>(subsetIndex).num_elements();
172 else
173 return section_container<TElem>(subsetIndex).num_elements(sectionInd);
174}
175
176template <class TElem>
177uint
179num() const
180{
181 uint n = 0;
182 for(uint i = 0; i < num_subsets_in_list(); ++i)
183 n += num<TElem>(i);
184
185 return n;
186}
187
188template <class TElem> inline
190empty() const
191{
192 return num<TElem>() == 0;
193}
194
196empty() const
197{
198 return empty<Vertex>() && empty<Edge>()
199 && empty<Face>() && empty<Volume>();
200}
201
202template <class TElem> inline
204empty(int subsetIndex) const
205{
206 return num<TElem>(subsetIndex) == 0;
207}
208
210empty(int subsetIndex) const
211{
212 return empty<Vertex>(subsetIndex) && empty<Edge>(subsetIndex)
213 && empty<Face>(subsetIndex) && empty<Volume>(subsetIndex);
214}
215
216template<class TElem>
218change_elem_subset_indices(int indOld, int indNew)
219{
220 typedef typename geometry_traits<TElem>::iterator iterator;
221 for(iterator iter = begin<TElem>(indOld);
222 iter != end<TElem>(indOld); iter++){
224 }
225}
226
227template <class TElem>
229{
230 typedef typename geometry_traits<TElem>::iterator iterator;
231
232 bool bSuccess = true;
233
234 LOG("performing self tests on GridSubsetHandler\n");
235 LOG(" num subets: " << num_subsets_in_list() << std::endl);
236
237// iterate through the subsets and check whether the assigned
238// elements have the correct subset index
239 LOG(" checking subset indices\n");
240 for(size_t i = 0; i < num_subsets_in_list(); ++i){
241 LOG(" checking subset " << i);
242 for(iterator iter = begin<TElem>(i); iter != end<TElem>(i); ++iter)
243 {
244 if(get_subset_index(*iter) != i){
245 LOG(" bad element subset index: "
246 << get_subset_index(*iter));
247 bSuccess = false;
248 break;
249 }
250 }
251 LOG("\n");
252 }
253
254 return bSuccess;
255}
256
257template <class TElem>
266
267
268template <class TElem>
277
278}// end of namespace
279
280#endif
281
bool empty() const
returns true if the subset-handler contains no elements of the given type.
Definition subset_handler_grid_impl.hpp:190
Grid::traits< TElem >::SectionContainer & section_container(int si)
returns the section container for the given type, subset and level
Definition subset_handler_grid_impl.hpp:260
void change_elem_subset_indices(int indOld, int indNew)
helper for change_subset_indices
Definition subset_handler_grid_impl.hpp:218
geometry_traits< TElem >::iterator end(int subsetIndex)
returns the end-iterator for the elements of type TElem in the given subset.
Definition subset_handler_grid_impl.hpp:63
SubsetVec m_subsets
Definition subset_handler_grid.h:367
uint num_subsets_in_list() const
returns the number of subsets in the local list
Definition subset_handler_grid.h:250
void clear_subset_elements(int subsetIndex)
removes all elements of type TElem from the specified subset.
Definition subset_handler_grid_impl.hpp:121
geometry_traits< TElem >::iterator begin(int subsetIndex)
returns the begin-iterator for the elements of type TElem in the given subset.
Definition subset_handler_grid_impl.hpp:44
bool perform_self_tests()
only for debug purposes
Definition subset_handler_grid_impl.hpp:228
uint num_elements(int subsetIndex) const
returns the number of elements in the given subset
Definition subset_handler_grid_impl.hpp:147
uint num() const
returns the total number of elements
Definition subset_handler_grid_impl.hpp:179
Grid * m_pGrid
Definition subset_handler_interface.h:736
void alter_subset_index(Vertex *v, int subsetIndex)
Definition subset_handler_interface.h:599
int get_subset_index(GridObject *elem) const
Definition subset_handler_interface.cpp:560
void erase(const iterator &iter, int sectionIndex)
Definition section_container.hpp:296
Definition grid_base_object_traits.h:68
#define LOG(msg)
Definition common.h:60
unsigned int uint
Definition types.h:114
the ug namespace
The traits class holds some important types for each element-type.
Definition grid.h:136
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
Helper class to access the correct element storage from its element type.
Definition element_storage.h:210