Line data Source code
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 : ////////////////////////////////////////////////////////////////////////
34 : ////////////////////////////////////////////////////////////////////////
35 : // ...
36 : ////////////////////////////////////////////////////////////////////////
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
48 : Selector::get_section_index() const
49 : {
50 : return geometry_traits<TElem>::CONTAINER_SECTION;
51 : }
52 :
53 : template <class TElem>
54 : inline void
55 0 : Selector::clear()
56 : {
57 0 : if(m_pGrid){
58 : // mark all elements as deselected
59 : typename geometry_traits<TElem>::iterator iter;
60 0 : 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 0 : section_container<TElem>().clear();
67 : else
68 : section_container<TElem>().clear_section(sInd);
69 : }
70 0 : }
71 :
72 : template <class TElem>
73 : inline size_t
74 0 : Selector::num() const
75 : {
76 : const int sInd = get_section_index<TElem>();
77 : if(sInd < 0)
78 0 : return section_container<TElem>().num_elements();
79 : else
80 0 : return section_container<TElem>().num_elements(sInd);
81 : }
82 :
83 : inline size_t
84 : Selector::num() const
85 : {
86 0 : return num<Vertex>() + num<Edge>() + num<Face>() + num<Volume>();
87 : }
88 :
89 : // empty
90 : inline bool
91 : Selector::empty() const
92 : {
93 : return num() == 0;
94 : }
95 :
96 : template <class TElem>
97 : inline bool
98 : Selector::empty() const
99 : {
100 : return num<TElem>() == 0;
101 : }
102 :
103 : // begin
104 : template <class TElem>
105 : inline typename geometry_traits<TElem>::iterator
106 : Selector::begin()
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>
119 : inline typename geometry_traits<TElem>::const_iterator
120 : Selector::begin() const
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
134 : Selector::end()
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>
147 : inline typename geometry_traits<TElem>::const_iterator
148 : Selector::end() const
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*
161 : Selector::front()
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*
169 : Selector::back()
170 : {
171 : const int sInd = get_section_index<TElem>();
172 : return static_cast<TElem*>(section_container<TElem>().back(sInd));
173 : }
174 :
175 : ////////////////////////////////////////
176 : // for compatibility with MGSelector
177 :
178 :
179 : inline size_t Selector::
180 : num_levels() const
181 : {
182 : return 1;
183 : }
184 :
185 : inline uint Selector::
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
213 : Selector::begin(size_t)
214 : {
215 0 : return begin<TElem>();
216 : }
217 :
218 : // end
219 : /// calls end<TElem>();
220 : template <class TElem>
221 : inline typename geometry_traits<TElem>::iterator
222 : Selector::end(size_t)
223 : {
224 : return end<TElem>();
225 : }
226 :
227 : template <class TElem>
228 : typename Grid::traits<TElem>::SectionContainer&
229 : Selector::
230 : section_container()
231 : {
232 : return SectionContainerSelector<typename geometry_traits<TElem>::grid_base_object>::
233 0 : section_container(m_vertices, m_edges, m_faces, m_volumes);
234 : }
235 :
236 :
237 : template <class TElem>
238 : const typename Grid::traits<TElem>::SectionContainer&
239 : Selector::
240 : section_container() const
241 : {
242 : return SectionContainerSelector<typename geometry_traits<TElem>::grid_base_object>::
243 : section_container(m_vertices, m_edges, m_faces, m_volumes);
244 : }
245 :
246 : }// end of namespace
247 :
248 : #endif
|