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 : #include <cassert>
34 : #include "selector_grid.h"
35 :
36 : namespace ug
37 : {
38 :
39 : ////////////////////////////////////////////////////////////////////////
40 0 : Selector::Selector(uint supportedElements) :
41 0 : ISelector(supportedElements)
42 : {
43 0 : }
44 :
45 0 : Selector::Selector(Grid& grid, uint supportedElements) :
46 0 : ISelector(supportedElements)
47 : {
48 0 : assign_grid(&grid);
49 0 : }
50 :
51 0 : Selector::~Selector()
52 : {
53 0 : if(m_pGrid){
54 : // release the attachments in the current grid
55 0 : if(elements_are_supported(SE_VERTEX))
56 0 : section_container<Vertex>().get_container().set_pipe(NULL);
57 :
58 0 : if(elements_are_supported(SE_EDGE))
59 0 : section_container<Edge>().get_container().set_pipe(NULL);
60 :
61 0 : if(elements_are_supported(SE_FACE))
62 0 : section_container<Face>().get_container().set_pipe(NULL);
63 :
64 0 : if(elements_are_supported(SE_VOLUME))
65 0 : section_container<Volume>().get_container().set_pipe(NULL);
66 : }
67 0 : }
68 :
69 0 : void Selector::assign_grid(Grid& grid)
70 : {
71 0 : assign_grid(&grid);
72 0 : }
73 :
74 0 : void Selector::assign_grid(Grid* grid)
75 : {
76 0 : if(grid != m_pGrid){
77 0 : uint elementSupport = m_supportedElements;
78 :
79 0 : if(m_pGrid){
80 : // release the attachments in the current grid
81 0 : disable_element_support(elementSupport);
82 : }
83 :
84 0 : m_supportedElements = SE_NONE;
85 0 : BaseClass::set_grid(grid);
86 :
87 0 : if(m_pGrid){
88 : // initialize attachment lists
89 0 : enable_element_support(elementSupport);
90 : }
91 : }
92 0 : }
93 :
94 0 : void Selector::set_supported_elements(uint shElements)
95 : {
96 : // do this in two steps:
97 : // 1: disable the element-support that is no longer required.
98 : // 2: enable the element-support that was not already enabled.
99 : // disable the elements that shall be disabled.
100 :
101 : // (the ones which shall not be set, but are currently active.)
102 0 : disable_element_support((~shElements) & m_supportedElements);
103 :
104 : // enable the elements that are not already enabled
105 0 : enable_element_support(shElements & (~m_supportedElements));
106 0 : }
107 :
108 0 : void Selector::enable_element_support(uint shElements)
109 : {
110 0 : if((shElements & SE_VERTEX) && (!elements_are_supported(SE_VERTEX)))
111 : section_container<Vertex>().get_container().
112 0 : set_pipe(&m_pGrid->get_attachment_pipe<Vertex>());
113 :
114 0 : if((shElements & SE_EDGE) && (!elements_are_supported(SE_EDGE)))
115 : section_container<Edge>().get_container().
116 : set_pipe(&m_pGrid->get_attachment_pipe<Edge>());
117 :
118 0 : if((shElements & SE_FACE) && (!elements_are_supported(SE_FACE)))
119 : section_container<Face>().get_container().
120 0 : set_pipe(&m_pGrid->get_attachment_pipe<Face>());
121 :
122 0 : if((shElements & SE_VOLUME) && (!elements_are_supported(SE_VOLUME)))
123 : section_container<Volume>().get_container().
124 0 : set_pipe(&m_pGrid->get_attachment_pipe<Volume>());
125 :
126 0 : ISelector::enable_element_support(shElements);
127 0 : }
128 :
129 0 : void Selector::disable_element_support(uint shElements)
130 : {
131 : // release the attachments in the current grid
132 0 : if((shElements & SE_VERTEX) && elements_are_supported(SE_VERTEX))
133 0 : section_container<Vertex>().get_container().set_pipe(NULL);
134 :
135 0 : if((shElements & SE_EDGE) && elements_are_supported(SE_EDGE))
136 0 : section_container<Edge>().get_container().set_pipe(NULL);
137 :
138 0 : if((shElements & SE_FACE) && elements_are_supported(SE_FACE))
139 0 : section_container<Face>().get_container().set_pipe(NULL);
140 :
141 0 : if((shElements & SE_VOLUME) && elements_are_supported(SE_VOLUME))
142 0 : section_container<Volume>().get_container().set_pipe(NULL);
143 :
144 0 : ISelector::disable_element_support(shElements);
145 0 : }
146 :
147 0 : void Selector::clear_lists()
148 : {
149 0 : section_container<Vertex>().clear();
150 0 : section_container<Edge>().clear();
151 0 : section_container<Face>().clear();
152 0 : section_container<Volume>().clear();
153 0 : }
154 :
155 0 : void Selector::clear()
156 : {
157 0 : clear<Vertex>();
158 0 : clear<Edge>();
159 0 : clear<Face>();
160 0 : clear<Volume>();
161 0 : }
162 :
163 0 : void Selector::add_to_list(Vertex* elem)
164 : {
165 0 : section_container<Vertex>().insert(elem,
166 0 : elem->container_section());
167 0 : }
168 :
169 0 : void Selector::add_to_list(Edge* elem)
170 : {
171 0 : section_container<Edge>().insert(elem,
172 0 : elem->container_section());
173 0 : }
174 :
175 0 : void Selector::add_to_list(Face* elem)
176 : {
177 0 : section_container<Face>().insert(elem,
178 0 : elem->container_section());
179 0 : }
180 :
181 0 : void Selector::add_to_list(Volume* elem)
182 : {
183 0 : section_container<Volume>().insert(elem,
184 0 : elem->container_section());
185 0 : }
186 :
187 0 : void Selector::erase_from_list(Vertex* elem)
188 : {
189 0 : section_container<Vertex>().erase(get_iterator(elem),
190 0 : elem->container_section());
191 0 : }
192 0 : void Selector::erase_from_list(Edge* elem)
193 : {
194 0 : section_container<Edge>().erase(get_iterator(elem),
195 0 : elem->container_section());
196 0 : }
197 0 : void Selector::erase_from_list(Face* elem)
198 : {
199 0 : section_container<Face>().erase(get_iterator(elem),
200 0 : elem->container_section());
201 0 : }
202 :
203 0 : void Selector::erase_from_list(Volume* elem)
204 : {
205 0 : section_container<Volume>().erase(get_iterator(elem),
206 0 : elem->container_section());
207 0 : }
208 :
209 : // geometric-object-collection
210 0 : GridObjectCollection Selector::get_grid_objects() const
211 : {
212 : //TODO: ugly casts! GenericElementSelector should store its selected elements
213 : // in a GridObjectSectionContainer!
214 0 : return GridObjectCollection(const_cast<VertexSectionContainer*>(&m_vertices),
215 0 : const_cast<EdgeSectionContainer*>(&m_edges),
216 0 : const_cast<FaceSectionContainer*>(&m_faces),
217 0 : const_cast<VolumeSectionContainer*>(&m_volumes));
218 : }
219 :
220 : /*
221 : void Selector::unregistered_from_grid(Grid* grid)
222 : {
223 : clear_lists();
224 : }
225 : */
226 0 : void Selector::grid_to_be_destroyed(Grid* grid)
227 : {
228 0 : ISelector::grid_to_be_destroyed(grid);
229 0 : clear_lists();
230 0 : }
231 :
232 : }// end of namespace
|