Line data Source code
1 : /*
2 : * Copyright (c) 2011-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__UG__element_storage__
34 : #define __H__UG__element_storage__
35 :
36 : #include "grid_base_objects.h"
37 : #include "common/util/section_container.h"
38 :
39 : namespace ug
40 : {
41 : /// This struct is used to hold GridObjects and their attachment pipes.
42 : template <class TElem>
43 : class ElementStorage
44 : {
45 : public:
46 : typedef ug::AttachmentPipe<TElem*, ElementStorage<TElem> > AttachmentPipe;
47 : typedef ug::AttachedElementList<AttachmentPipe> AttachedElementList;
48 : typedef ug::SectionContainer<TElem*, AttachedElementList >
49 : SectionContainer;
50 :
51 4 : ElementStorage() : m_attachmentPipe(this)
52 : {
53 4 : m_sectionContainer.get_container().set_pipe(&m_attachmentPipe);
54 4 : }
55 : // the destructor is important, since destruction order is undefined
56 : // and since the AttachedElementList in SectionContainer tries to
57 : // unregister itself fomt the assigned pipe.
58 4 : ~ElementStorage(){
59 4 : m_sectionContainer.get_container().set_pipe(NULL);
60 4 : }
61 :
62 : SectionContainer m_sectionContainer;/// holds elements
63 : AttachmentPipe m_attachmentPipe;/// holds the data of the stored elements.
64 : };
65 :
66 :
67 : ////////////////////////////////////////////////////////////////////////////////
68 : template<>
69 : class attachment_traits<Vertex*, ElementStorage<Vertex> >
70 : {
71 : public:
72 : typedef Vertex*& ElemRef;
73 : typedef Vertex* ElemPtr;
74 : typedef const Vertex* ConstElemPtr;
75 : typedef ElementStorage<Vertex>* ElemHandlerPtr;
76 : typedef const ElementStorage<Vertex>* ConstElemHandlerPtr;
77 : typedef ElementStorage<Vertex>::SectionContainer::iterator element_iterator;
78 :
79 : static inline element_iterator elements_begin(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.begin();}
80 : static inline element_iterator elements_end(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.end();}
81 : static inline uint get_data_index(ConstElemHandlerPtr pHandler, ConstElemPtr elem) {return elem->grid_data_index();}
82 : static inline void set_data_index(ElemHandlerPtr pHandler, ElemPtr elem, uint index){elem->set_grid_data_index(index);}
83 : };
84 :
85 : template<>
86 : class attachment_traits<Edge*, ElementStorage<Edge> >
87 : {
88 : public:
89 : typedef Edge*& ElemRef;
90 : typedef Edge* ElemPtr;
91 : typedef const Edge* ConstElemPtr;
92 : typedef ElementStorage<Edge>* ElemHandlerPtr;
93 : typedef const ElementStorage<Edge>* ConstElemHandlerPtr;
94 : typedef ElementStorage<Edge>::SectionContainer::iterator element_iterator;
95 :
96 : static inline element_iterator elements_begin(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.begin();}
97 : static inline element_iterator elements_end(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.end();}
98 : static inline uint get_data_index(ConstElemHandlerPtr pHandler, ConstElemPtr elem) {return elem->grid_data_index();}
99 : static inline void set_data_index(ElemHandlerPtr pHandler, ElemPtr elem, uint index){elem->set_grid_data_index(index);}
100 : };
101 :
102 : template<>
103 : class attachment_traits<Face*, ElementStorage<Face> >
104 : {
105 : public:
106 : typedef Face*& ElemRef;
107 : typedef Face* ElemPtr;
108 : typedef const Face* ConstElemPtr;
109 : typedef ElementStorage<Face>* ElemHandlerPtr;
110 : typedef const ElementStorage<Face>* ConstElemHandlerPtr;
111 : typedef ElementStorage<Face>::SectionContainer::iterator element_iterator;
112 :
113 : static inline element_iterator elements_begin(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.begin();}
114 : static inline element_iterator elements_end(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.end();}
115 : static inline uint get_data_index(ConstElemHandlerPtr pHandler, ConstElemPtr elem) {return elem->grid_data_index();}
116 : static inline void set_data_index(ElemHandlerPtr pHandler, ElemPtr elem, uint index){elem->set_grid_data_index(index);}
117 : };
118 :
119 : template<>
120 : class attachment_traits<Volume*, ElementStorage<Volume> >
121 : {
122 : public:
123 : typedef Volume*& ElemRef;
124 : typedef Volume* ElemPtr;
125 : typedef const Volume* ConstElemPtr;
126 : typedef ElementStorage<Volume>* ElemHandlerPtr;
127 : typedef const ElementStorage<Volume>* ConstElemHandlerPtr;
128 : typedef ElementStorage<Volume>::SectionContainer::iterator element_iterator;
129 :
130 : static inline element_iterator elements_begin(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.begin();}
131 : static inline element_iterator elements_end(ElemHandlerPtr pHandler) {return pHandler->m_sectionContainer.end();}
132 : static inline uint get_data_index(ConstElemHandlerPtr pHandler, ConstElemPtr elem) {return elem->grid_data_index();}
133 : static inline void set_data_index(ElemHandlerPtr pHandler, ElemPtr elem, uint index){elem->set_grid_data_index(index);}
134 : };
135 :
136 :
137 :
138 : typedef ElementStorage<Vertex> VertexElementStorage;
139 : typedef ElementStorage<Edge> EdgeElementStorage;
140 : typedef ElementStorage<Face> FaceElementStorage;
141 : typedef ElementStorage<Volume> VolumeElementStorage;
142 :
143 :
144 :
145 : ////////////////////////////////////////////////////////////////////////////////
146 : /// Helper class to access the correct element storage from its element type
147 : template <class TElem>
148 : struct ElementStorageSelector{
149 : static inline ElementStorage<TElem>& element_storage(VertexElementStorage& vrts,
150 : EdgeElementStorage& edges, FaceElementStorage& faces,
151 : VolumeElementStorage& vols);
152 :
153 : static inline const ElementStorage<TElem>& element_storage(
154 : const VertexElementStorage& vrts, const EdgeElementStorage& edges,
155 : const FaceElementStorage& faces, const VolumeElementStorage& vols);
156 : };
157 :
158 : template <>
159 : struct ElementStorageSelector<Vertex>{
160 : static inline ElementStorage<Vertex>& element_storage(VertexElementStorage& vrts,
161 : EdgeElementStorage& edges, FaceElementStorage& faces, VolumeElementStorage& vols)
162 : {return vrts;}
163 :
164 : static inline const ElementStorage<Vertex>& element_storage(
165 : const VertexElementStorage& vrts, const EdgeElementStorage& edges,
166 : const FaceElementStorage& faces, const VolumeElementStorage& vols)
167 : {return vrts;}
168 : };
169 :
170 : template <>
171 : struct ElementStorageSelector<Edge>{
172 : static inline ElementStorage<Edge>& element_storage(VertexElementStorage& vrts,
173 : EdgeElementStorage& edges, FaceElementStorage& faces, VolumeElementStorage& vols)
174 : {return edges;}
175 :
176 : static inline const ElementStorage<Edge>& element_storage(
177 : const VertexElementStorage& vrts, const EdgeElementStorage& edges,
178 : const FaceElementStorage& faces, const VolumeElementStorage& vols)
179 : {return edges;}
180 : };
181 :
182 : template <>
183 : struct ElementStorageSelector<Face>{
184 : static inline ElementStorage<Face>& element_storage(VertexElementStorage& vrts,
185 : EdgeElementStorage& edges, FaceElementStorage& faces, VolumeElementStorage& vols)
186 : {return faces;}
187 :
188 : static inline const ElementStorage<Face>& element_storage(
189 : const VertexElementStorage& vrts, const EdgeElementStorage& edges,
190 : const FaceElementStorage& faces, const VolumeElementStorage& vols)
191 : {return faces;}
192 : };
193 :
194 : template <>
195 : struct ElementStorageSelector<Volume>{
196 : static inline ElementStorage<Volume>& element_storage(VertexElementStorage& vrts,
197 : EdgeElementStorage& edges, FaceElementStorage& faces, VolumeElementStorage& vols)
198 : {return vols;}
199 :
200 : static inline const ElementStorage<Volume>& element_storage(
201 : const VertexElementStorage& vrts, const EdgeElementStorage& edges,
202 : const FaceElementStorage& faces, const VolumeElementStorage& vols)
203 : {return vols;}
204 : };
205 :
206 :
207 : ////////////////////////////////////////////////////////////////////////////////
208 : /// Helper class to access the correct element storage from its element type
209 : template <class TElem>
210 : struct SectionContainerSelector{
211 : static inline typename ElementStorage<TElem>::SectionContainer& section_container(
212 : VertexElementStorage::SectionContainer& vrts,
213 : EdgeElementStorage::SectionContainer& edges,
214 : FaceElementStorage::SectionContainer& faces,
215 : VolumeElementStorage::SectionContainer& vols);
216 :
217 : static inline const typename ElementStorage<TElem>::SectionContainer& section_container(
218 : const VertexElementStorage::SectionContainer& vrts,
219 : const EdgeElementStorage::SectionContainer& edges,
220 : const FaceElementStorage::SectionContainer& faces,
221 : const VolumeElementStorage::SectionContainer& vols);
222 :
223 : static inline typename ElementStorage<TElem>::SectionContainer* section_container(
224 : VertexElementStorage::SectionContainer* vrts,
225 : EdgeElementStorage::SectionContainer* edges,
226 : FaceElementStorage::SectionContainer* faces,
227 : VolumeElementStorage::SectionContainer* vols);
228 :
229 : static inline const typename ElementStorage<TElem>::SectionContainer* section_container(
230 : const VertexElementStorage::SectionContainer* vrts,
231 : const EdgeElementStorage::SectionContainer* edges,
232 : const FaceElementStorage::SectionContainer* faces,
233 : const VolumeElementStorage::SectionContainer* vols);
234 : };
235 :
236 : template <>
237 : struct SectionContainerSelector<Vertex>{
238 : static inline ElementStorage<Vertex>::SectionContainer& section_container(
239 : VertexElementStorage::SectionContainer& vrts,
240 : EdgeElementStorage::SectionContainer& edges,
241 : FaceElementStorage::SectionContainer& faces,
242 : VolumeElementStorage::SectionContainer& vols)
243 : {return vrts;}
244 :
245 : static inline const ElementStorage<Vertex>::SectionContainer& section_container(
246 : const VertexElementStorage::SectionContainer& vrts,
247 : const EdgeElementStorage::SectionContainer& edges,
248 : const FaceElementStorage::SectionContainer& faces,
249 : const VolumeElementStorage::SectionContainer& vols)
250 : {return vrts;}
251 :
252 : static inline ElementStorage<Vertex>::SectionContainer* section_container(
253 : VertexElementStorage::SectionContainer* vrts,
254 : EdgeElementStorage::SectionContainer* edges,
255 : FaceElementStorage::SectionContainer* faces,
256 : VolumeElementStorage::SectionContainer* vols)
257 : {return vrts;}
258 :
259 : static inline const ElementStorage<Vertex>::SectionContainer* section_container(
260 : const VertexElementStorage::SectionContainer* vrts,
261 : const EdgeElementStorage::SectionContainer* edges,
262 : const FaceElementStorage::SectionContainer* faces,
263 : const VolumeElementStorage::SectionContainer* vols)
264 : {return vrts;}
265 : };
266 :
267 : template <>
268 : struct SectionContainerSelector<Edge>{
269 : static inline ElementStorage<Edge>::SectionContainer& section_container(
270 : VertexElementStorage::SectionContainer& vrts,
271 : EdgeElementStorage::SectionContainer& edges,
272 : FaceElementStorage::SectionContainer& faces,
273 : VolumeElementStorage::SectionContainer& vols)
274 : {return edges;}
275 :
276 : static inline const ElementStorage<Edge>::SectionContainer& section_container(
277 : const VertexElementStorage::SectionContainer& vrts,
278 : const EdgeElementStorage::SectionContainer& edges,
279 : const FaceElementStorage::SectionContainer& faces,
280 : const VolumeElementStorage::SectionContainer& vols)
281 : {return edges;}
282 :
283 : static inline ElementStorage<Edge>::SectionContainer* section_container(
284 : VertexElementStorage::SectionContainer* vrts,
285 : EdgeElementStorage::SectionContainer* edges,
286 : FaceElementStorage::SectionContainer* faces,
287 : VolumeElementStorage::SectionContainer* vols)
288 : {return edges;}
289 :
290 : static inline const ElementStorage<Edge>::SectionContainer* section_container(
291 : const VertexElementStorage::SectionContainer* vrts,
292 : const EdgeElementStorage::SectionContainer* edges,
293 : const FaceElementStorage::SectionContainer* faces,
294 : const VolumeElementStorage::SectionContainer* vols)
295 : {return edges;}
296 : };
297 :
298 : template <>
299 : struct SectionContainerSelector<Face>{
300 : static inline ElementStorage<Face>::SectionContainer& section_container(
301 : VertexElementStorage::SectionContainer& vrts,
302 : EdgeElementStorage::SectionContainer& edges,
303 : FaceElementStorage::SectionContainer& faces,
304 : VolumeElementStorage::SectionContainer& vols)
305 : {return faces;}
306 :
307 : static inline const ElementStorage<Face>::SectionContainer& section_container(
308 : const VertexElementStorage::SectionContainer& vrts,
309 : const EdgeElementStorage::SectionContainer& edges,
310 : const FaceElementStorage::SectionContainer& faces,
311 : const VolumeElementStorage::SectionContainer& vols)
312 : {return faces;}
313 :
314 : static inline ElementStorage<Face>::SectionContainer* section_container(
315 : VertexElementStorage::SectionContainer* vrts,
316 : EdgeElementStorage::SectionContainer* edges,
317 : FaceElementStorage::SectionContainer* faces,
318 : VolumeElementStorage::SectionContainer* vols)
319 : {return faces;}
320 :
321 : static inline const ElementStorage<Face>::SectionContainer* section_container(
322 : const VertexElementStorage::SectionContainer* vrts,
323 : const EdgeElementStorage::SectionContainer* edges,
324 : const FaceElementStorage::SectionContainer* faces,
325 : const VolumeElementStorage::SectionContainer* vols)
326 : {return faces;}
327 : };
328 :
329 : template <>
330 : struct SectionContainerSelector<Volume>{
331 : static inline ElementStorage<Volume>::SectionContainer& section_container(
332 : VertexElementStorage::SectionContainer& vrts,
333 : EdgeElementStorage::SectionContainer& edges,
334 : FaceElementStorage::SectionContainer& faces,
335 : VolumeElementStorage::SectionContainer& vols)
336 : {return vols;}
337 :
338 : static inline const ElementStorage<Volume>::SectionContainer& section_container(
339 : const VertexElementStorage::SectionContainer& vrts,
340 : const EdgeElementStorage::SectionContainer& edges,
341 : const FaceElementStorage::SectionContainer& faces,
342 : const VolumeElementStorage::SectionContainer& vols)
343 : {return vols;}
344 :
345 : static inline ElementStorage<Volume>::SectionContainer* section_container(
346 : VertexElementStorage::SectionContainer* vrts,
347 : EdgeElementStorage::SectionContainer* edges,
348 : FaceElementStorage::SectionContainer* faces,
349 : VolumeElementStorage::SectionContainer* vols)
350 : {return vols;}
351 :
352 : static inline const ElementStorage<Volume>::SectionContainer* section_container(
353 : const VertexElementStorage::SectionContainer* vrts,
354 : const EdgeElementStorage::SectionContainer* edges,
355 : const FaceElementStorage::SectionContainer* faces,
356 : const VolumeElementStorage::SectionContainer* vols)
357 : {return vols;}
358 : };
359 :
360 : }// end of namespace
361 :
362 : #endif
|