ug4
selector_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_GRID_IMPL__
39 #define __H__LIBGRID__SELECTOR_GRID_IMPL__
40 
41 #include <cassert>
42 
43 namespace ug
44 {
45 
46 template <class TElem>
47 inline int
49 {
51 }
52 
53 template <class TElem>
54 inline void
56 {
57  if(m_pGrid){
58  // mark all elements as deselected
60  for(iter = begin<TElem>(); iter != end<TElem>(); ++iter)
61  mark_deselected(*iter);
62 
63  // clear the section
64  const int sInd = get_section_index<TElem>();
65  if(sInd < 0)
66  section_container<TElem>().clear();
67  else
68  section_container<TElem>().clear_section(sInd);
69  }
70 }
71 
72 template <class TElem>
73 inline size_t
75 {
76  const int sInd = get_section_index<TElem>();
77  if(sInd < 0)
78  return section_container<TElem>().num_elements();
79  else
80  return section_container<TElem>().num_elements(sInd);
81 }
82 
83 inline size_t
85 {
86  return num<Vertex>() + num<Edge>() + num<Face>() + num<Volume>();
87 }
88 
89 // empty
90 inline bool
92 {
93  return num() == 0;
94 }
95 
96 template <class TElem>
97 inline bool
99 {
100  return num<TElem>() == 0;
101 }
102 
103 // begin
104 template <class TElem>
105 inline typename geometry_traits<TElem>::iterator
107 {
108  const int sInd = get_section_index<TElem>();
109  if(sInd < 0)
110  return iterator_cast<typename geometry_traits<TElem>::iterator>(
111  section_container<TElem>().begin());
112  else
113  return iterator_cast<typename geometry_traits<TElem>::iterator>(
114  section_container<TElem>().section_begin(sInd));
115 }
116 
117 // const begin
118 template <class TElem>
121 {
122  const int sInd = get_section_index<TElem>();
123  if(sInd < 0)
124  return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
125  section_container<TElem>().begin());
126  else
127  return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
128  section_container<TElem>().section_begin(sInd));
129 }
130 
131 // end
132 template <class TElem>
133 inline typename geometry_traits<TElem>::iterator
135 {
136  const int sInd = get_section_index<TElem>();
137  if(sInd < 0)
138  return iterator_cast<typename geometry_traits<TElem>::iterator>(
139  section_container<TElem>().end());
140  else
141  return iterator_cast<typename geometry_traits<TElem>::iterator>(
142  section_container<TElem>().section_end(sInd));
143 }
144 
145 // const end
146 template <class TElem>
149 {
150  const int sInd = get_section_index<TElem>();
151  if(sInd < 0)
152  return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
153  section_container<TElem>().end());
154  else
155  return iterator_cast<typename geometry_traits<TElem>::const_iterator>(
156  section_container<TElem>().section_end(sInd));
157 }
158 
159 template <class TElem>
160 TElem*
162 {
163  const int sInd = get_section_index<TElem>();
164  return static_cast<TElem*>(section_container<TElem>().front(sInd));
165 }
166 
167 template <class TElem>
168 TElem*
170 {
171  const int sInd = get_section_index<TElem>();
172  return static_cast<TElem*>(section_container<TElem>().back(sInd));
173 }
174 
176 // for compatibility with MGSelector
177 
178 
179 inline size_t Selector::
180 num_levels() const
181 {
182  return 1;
183 }
184 
186 num(size_t) const
187 {
188  return (uint)num();
189 }
190 
191 template <class TElem>
192 inline size_t Selector::
193 num(size_t) const
194 {
195  return num<TElem>();
196 }
197 
198 inline bool Selector::
199 empty(size_t) const
200 {
201  return empty();
202 }
203 
204 template <class TElem>
205 inline bool Selector::
206 empty(size_t) const
207 {
208  return empty<TElem>();
209 }
210 
211 template <class TElem>
212 inline typename geometry_traits<TElem>::iterator
214 {
215  return begin<TElem>();
216 }
217 
218 // end
220 template <class TElem>
221 inline typename geometry_traits<TElem>::iterator
223 {
224  return end<TElem>();
225 }
226 
227 template <class TElem>
231 {
234 }
235 
236 
237 template <class TElem>
240 section_container() const
241 {
244 }
245 
246 }// end of namespace
247 
248 #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()
returns the section container for the given type, subset and level
Definition: selector_grid_impl.hpp:230
geometry_traits< TElem >::iterator end()
Definition: selector_grid_impl.hpp:134
bool empty() const
Definition: selector_grid_impl.hpp:91
TElem * front()
returns the first selected element of the given type.
Definition: selector_grid_impl.hpp:161
virtual void clear()
Definition: selector_grid.cpp:155
FaceSectionContainer m_faces
Definition: selector_grid.h:316
int get_section_index() const
Definition: selector_grid_impl.hpp:48
EdgeSectionContainer m_edges
Definition: selector_grid.h:315
TElem * back()
returns the last selected element of the given type.
Definition: selector_grid_impl.hpp:169
size_t num() const
Definition: selector_grid_impl.hpp:74
VolumeSectionContainer m_volumes
Definition: selector_grid.h:317
geometry_traits< TElem >::iterator begin()
Definition: selector_grid_impl.hpp:106
size_t num_levels() const
always returns 1
Definition: selector_grid_impl.hpp:180
VertexSectionContainer m_vertices
Copy Constructor not yet implemented!
Definition: selector_grid.h:311
Definition: grid_base_object_traits.h:68
unsigned int uint
Definition: types.h:114
the ug namespace
Helper class to access the correct element storage from its element type.
Definition: element_storage.h:210