Line data Source code
1 : /*
2 : * Copyright (c) 2009-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__LIBGRID__GRID_OBSERVERS__
34 : #define __H__LIBGRID__GRID_OBSERVERS__
35 :
36 : #include "common/types.h"
37 :
38 : namespace ug
39 : {
40 : ////////////////////////////////////////////////////////////////////////
41 : // predeclarations
42 : class Grid;
43 : class Vertex;
44 : class Edge;
45 : class Face;
46 : class Volume;
47 :
48 :
49 : ////////////////////////////////////////////////////////////////////////
50 : // Observer types
51 : enum ObserverType
52 : {
53 : OT_NONE = 0,
54 : OT_GRID_OBSERVER = 1,
55 : OT_VERTEX_OBSERVER = 2,
56 : OT_EDGE_OBSERVER = 4,
57 : OT_FACE_OBSERVER = 8,
58 : OT_VOLUME_OBSERVER = 16,
59 : OT_FULL_OBSERVER = OT_GRID_OBSERVER | OT_VERTEX_OBSERVER | OT_EDGE_OBSERVER |
60 : OT_FACE_OBSERVER | OT_VOLUME_OBSERVER
61 : };
62 :
63 : ////////////////////////////////////////////////////////////////////////
64 : // GridObserver
65 : /**
66 : * The grid observer defines an interface that can be specialized by
67 : * classes that want to be informed about changes in a grid.
68 : * If a class derives from GridObserver, it can be registered at a grid.
69 : * Registration is usually performed through a member function of the
70 : * observer class itself.
71 : * Most observers can only be registered at one grid at a time.
72 : *
73 : * Please note that methods of different observers are called in the
74 : * order in which they were registered at the grid. The only exception
75 : * are the vertex_to_be_erased, edge_to_be_erased, face_to_be_erased and
76 : * volume_to_be_erased. Those method are called in reverse order of
77 : * registration.
78 : */
79 : class UG_API GridObserver
80 : {
81 : public:
82 0 : virtual ~GridObserver() {}
83 :
84 : // grid callbacks
85 0 : virtual void grid_to_be_destroyed(Grid* grid) {}
86 0 : virtual void elements_to_be_cleared(Grid* grid) {}
87 :
88 : // creation callbacks
89 : /**
90 : * \brief Notified whenever a new element of the given type is created
91 : * in the given grid.
92 : *
93 : * Creation callbacks are called in the order in which the GridObservers
94 : * were registered at the given grid.
95 : *
96 : * If replacesParent is true, then pParent is of the same base type as the
97 : * created object (e.g. in case of edge_created, the parent is an Edge*).
98 : * This case usually appears, when a contraining object is replaced by a
99 : * regular grid object if the same base type during refinement.
100 : * The method is called with replacesParent == true by
101 : * Grid::create_and_replace methods.
102 : *
103 : * Please note: If replacesParent == true, then a call to
104 : * OBJECT_to_be_erased(grid, pParent, obj) will follow (OBJECT
105 : * and obj are pseudonyms for the concrete type).*/
106 : /// \{
107 0 : virtual void vertex_created(Grid* grid, Vertex* vrt,
108 : GridObject* pParent = NULL,
109 0 : bool replacesParent = false) {}
110 :
111 0 : virtual void edge_created(Grid* grid, Edge* e,
112 : GridObject* pParent = NULL,
113 0 : bool replacesParent = false) {}
114 :
115 0 : virtual void face_created(Grid* grid, Face* f,
116 : GridObject* pParent = NULL,
117 0 : bool replacesParent = false) {}
118 :
119 0 : virtual void volume_created(Grid* grid, Volume* vol,
120 : GridObject* pParent = NULL,
121 0 : bool replacesParent = false) {}
122 : /// \}
123 :
124 :
125 : // erase callbacks
126 : /// Notified whenever an element of the given type is erased from the given grid.
127 : /** Erase callbacks are called in reverse order in which the GridObservers
128 : * were registered at the given grid.
129 : *
130 : * if replacedBy != NULL the erased object is only replaced by another
131 : * grid object of the same base type. This usually happens when constraining
132 : * objects are replaced by regular objects in refinements. (E.g. a constraining
133 : * edge by become a regular Edge; note that both objects are of type
134 : * Edge*).
135 : *
136 : * \{ */
137 0 : virtual void vertex_to_be_erased(Grid* grid, Vertex* vrt,
138 0 : Vertex* replacedBy = NULL) {}
139 :
140 0 : virtual void edge_to_be_erased(Grid* grid, Edge* e,
141 0 : Edge* replacedBy = NULL) {}
142 :
143 0 : virtual void face_to_be_erased(Grid* grid, Face* f,
144 0 : Face* replacedBy = NULL) {}
145 :
146 0 : virtual void volume_to_be_erased(Grid* grid, Volume* vol,
147 0 : Volume* replacedBy = NULL) {}
148 :
149 : /** \} */
150 :
151 : // merge callbacks
152 : /// Notified when two elements of the same type are going to be merged.
153 : /** Note that this method is invoked by Grid::objects_will_be_merged, which
154 : * is called from outside the grid class. Implementors of algorithms in
155 : * which objects are merged are thus responsible to call
156 : * Grid::objects_will_be_merged.
157 : *
158 : * This callback is called in addition to ..._created and ..._to_be_erased
159 : * callbacks and should thus only be used if small adjustments have to be
160 : * made during a merge.
161 : *
162 : * Note that target may be identical to elem1 or elem2.
163 : *
164 : * \{ */
165 0 : virtual void vertices_to_be_merged(Grid* grid, Vertex* target,
166 0 : Vertex* elem1, Vertex* elem2) {}
167 :
168 0 : virtual void edges_to_be_merged(Grid* grid, Edge* target,
169 0 : Edge* elem1, Edge* elem2) {}
170 :
171 0 : virtual void faces_to_be_merged(Grid* grid, Face* target,
172 0 : Face* elem1, Face* elem2) {}
173 :
174 0 : virtual void volumes_to_be_merged(Grid* grid, Volume* target,
175 0 : Volume* elem1, Volume* elem2) {}
176 :
177 : /** \} */
178 : };
179 :
180 : }// end of namespace
181 :
182 : #endif
|