Line data Source code
1 : /*
2 : * Copyright (c) 2012-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 "bool_marker.h"
34 :
35 : namespace ug{
36 :
37 0 : BoolMarker::BoolMarker() :
38 0 : m_pGrid(NULL),
39 0 : m_defaultMark(false),
40 0 : m_markInheritanceEnabled(true),
41 0 : m_strictInheritanceEnabled(false)
42 : {
43 0 : }
44 :
45 0 : BoolMarker::BoolMarker(Grid& g) :
46 0 : m_pGrid(NULL),
47 0 : m_defaultMark(false),
48 0 : m_markInheritanceEnabled(true),
49 0 : m_strictInheritanceEnabled(false)
50 : {
51 0 : assign_grid(&g);
52 0 : }
53 :
54 0 : BoolMarker::~BoolMarker()
55 : {
56 0 : assign_grid(NULL);
57 0 : }
58 :
59 0 : void BoolMarker::assign_grid(Grid* g)
60 : {
61 0 : if(m_pGrid == g)
62 : return;
63 :
64 0 : if(m_pGrid){
65 0 : m_pGrid->detach_from_all(m_aBool);
66 0 : m_pGrid->unregister_observer(this);
67 : m_aaMarkVRT.invalidate();
68 : m_aaMarkEDGE.invalidate();
69 : m_aaMarkFACE.invalidate();
70 : m_aaMarkVOL.invalidate();
71 : }
72 :
73 0 : m_pGrid = g;
74 0 : if(g){
75 0 : g->register_observer(this, OT_GRID_OBSERVER | OT_VERTEX_OBSERVER | OT_EDGE_OBSERVER |
76 : OT_FACE_OBSERVER | OT_VOLUME_OBSERVER);
77 0 : g->attach_to_all(m_aBool);
78 0 : m_aaMarkVRT.access(*g, m_aBool);
79 : m_aaMarkEDGE.access(*g, m_aBool);
80 : m_aaMarkFACE.access(*g, m_aBool);
81 : m_aaMarkVOL.access(*g, m_aBool);
82 : }
83 : }
84 :
85 :
86 0 : bool BoolMarker::is_marked(GridObject* e) const
87 : {
88 0 : switch(e->base_object_id()){
89 0 : case VERTEX: return is_marked(static_cast<Vertex*>(e));
90 0 : case EDGE: return is_marked(static_cast<Edge*>(e));
91 0 : case FACE: return is_marked(static_cast<Face*>(e));
92 0 : case VOLUME: return is_marked(static_cast<Volume*>(e));
93 : default: return false;
94 : }
95 : }
96 :
97 :
98 :
99 :
100 0 : void BoolMarker::grid_to_be_destroyed(Grid* grid)
101 : {
102 0 : assign_grid(NULL);
103 0 : }
104 :
105 0 : void BoolMarker::clear()
106 : {
107 : assert(m_pGrid);
108 0 : unmark(m_pGrid->begin<Vertex>(), m_pGrid->end<Vertex>());
109 0 : unmark(m_pGrid->begin<Edge>(), m_pGrid->end<Edge>());
110 0 : unmark(m_pGrid->begin<Face>(), m_pGrid->end<Face>());
111 0 : unmark(m_pGrid->begin<Volume>(), m_pGrid->end<Volume>());
112 0 : }
113 :
114 :
115 0 : void BoolMarker::
116 : vertex_created(Grid* grid, Vertex* vrt, GridObject* pParent,
117 : bool replacesParent)
118 : {
119 0 : if(!pParent){
120 : mark(vrt, default_mark());
121 0 : return;
122 : }
123 :
124 0 : if(strict_inheritance_enabled() && (pParent->base_object_id() != VERTEX)){
125 : mark(vrt, default_mark());
126 0 : return;
127 : }
128 :
129 0 : if(mark_inheritance_enabeld())
130 0 : mark(vrt, is_marked(pParent));
131 :
132 : mark(vrt, default_mark());
133 : }
134 :
135 0 : void BoolMarker::
136 : edge_created(Grid* grid, Edge* e, GridObject* pParent,
137 : bool replacesParent)
138 : {
139 0 : if(!pParent){
140 : mark(e, default_mark());
141 0 : return;
142 : }
143 :
144 0 : if(strict_inheritance_enabled() && (pParent->base_object_id() != EDGE)){
145 : mark(e, default_mark());
146 0 : return;
147 : }
148 :
149 0 : if(mark_inheritance_enabeld())
150 0 : mark(e, is_marked(pParent));
151 :
152 : mark(e, default_mark());
153 : }
154 :
155 0 : void BoolMarker::
156 : face_created(Grid* grid, Face* f, GridObject* pParent,
157 : bool replacesParent)
158 : {
159 0 : if(!pParent){
160 : mark(f, default_mark());
161 0 : return;
162 : }
163 :
164 0 : if(strict_inheritance_enabled() && (pParent->base_object_id() != FACE)){
165 : mark(f, default_mark());
166 0 : return;
167 : }
168 :
169 0 : if(mark_inheritance_enabeld())
170 0 : mark(f, is_marked(pParent));
171 :
172 : mark(f, default_mark());
173 : }
174 :
175 0 : void BoolMarker::
176 : volume_created(Grid* grid, Volume* vol, GridObject* pParent,
177 : bool replacesParent)
178 : {
179 0 : if(!pParent){
180 : mark(vol, default_mark());
181 0 : return;
182 : }
183 :
184 0 : if(strict_inheritance_enabled() && (pParent->base_object_id() != VOLUME)){
185 : mark(vol, default_mark());
186 0 : return;
187 : }
188 :
189 0 : if(mark_inheritance_enabeld())
190 0 : mark(vol, is_marked(pParent));
191 :
192 : mark(vol, default_mark());
193 : }
194 :
195 0 : void BoolMarker::
196 : vertices_to_be_merged(Grid* grid, Vertex* target,
197 : Vertex* elem1, Vertex* elem2)
198 : {
199 0 : mark(target, is_marked(elem1) || is_marked(elem2));
200 0 : }
201 :
202 0 : void BoolMarker::
203 : edges_to_be_merged(Grid* grid, Edge* target,
204 : Edge* elem1, Edge* elem2)
205 : {
206 0 : mark(target, is_marked(elem1) || is_marked(elem2));
207 0 : }
208 :
209 0 : void BoolMarker::
210 : faces_to_be_merged(Grid* grid, Face* target,
211 : Face* elem1, Face* elem2)
212 : {
213 0 : mark(target, is_marked(elem1) || is_marked(elem2));
214 0 : }
215 :
216 0 : void BoolMarker::
217 : volumes_to_be_merged(Grid* grid, Volume* target,
218 : Volume* elem1, Volume* elem2)
219 : {
220 0 : mark(target, is_marked(elem1) || is_marked(elem2));
221 0 : }
222 :
223 : }// end of namespace
|