ug4
refiner_interface.h
Go to the documentation of this file.
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__REFINER_INTERFACE__
34 #define __H__UG__REFINER_INTERFACE__
35 
36 #include <string>
38 
39 namespace ug
40 {
43 
45 // Make sure not to use refinement marks with a value of 128 or higher! Those
46 
49  RM_NONE = 0,
50  RM_CLOSURE = 1,
53  RM_LOCAL = 1 << 1,
54  RM_FULL = 1 << 2,
56  RM_COARSEN = 1 << 3,
57  RM_DUMMY = 1 << 4,
58  RM_MAX
59 };
60 
62 
66 class IRefiner
67 {
68  public:
71  m_adaptionIsActive(false), m_debuggingEnabled(false) {}
72 
73  virtual ~IRefiner() {}
74 
77 
79  {return m_projector;}
80 
82  virtual Grid* get_associated_grid() = 0;
84 
85  virtual Grid* grid() = 0;
86 
88  virtual void clear_marks() {}
89 
91 
92  virtual bool adaptivity_supported() const = 0;
93 
95 
96  virtual bool coarsening_supported() const = 0;
97 
99  virtual bool local_marks_supported() const {return false;}
100 
102 
103  virtual bool mark(Vertex* v, RefinementMark refMark = RM_REFINE) {return false;}
104  virtual bool mark(Edge* e, RefinementMark refMark = RM_REFINE) {return false;}
105  virtual bool mark(Face* f, RefinementMark refMark = RM_REFINE) {return false;}
106  virtual bool mark(Volume* v, RefinementMark refMark = RM_REFINE) {return false;}
110 
112  virtual bool mark(GridObject* o, RefinementMark refMark = RM_REFINE);
113 
114 
115  template <class TElem>
116  inline bool marked_closure(TElem* elem) const
117  {
118  return (get_mark(elem) == RM_CLOSURE);
119  }
120 
121  template <class TElem>
122  inline bool marked_local(TElem* elem) const
123  {
124  return (get_mark(elem) == RM_LOCAL);
125  }
126 
127  template <class TElem>
128  inline bool marked_full(TElem* elem) const
129  {
130  return (get_mark(elem) == RM_FULL);
131  }
132 
134 
142  virtual void mark_local(Face* e, int mark) {UG_THROW("mark_local not supported by this refiner!");}
143  virtual void mark_local(Volume* e, int mark) {UG_THROW("mark_local not supported by this refiner!");}
147 
150  virtual int get_local_mark(Face* e) const {return 0;}
151  virtual int get_local_mark(Volume* e) const {return 0;}
156 
159  int get_local_edge_mark(Face* f, Edge* e) const;
160 
162 
165  int get_local_edge_mark(Volume* vol, Edge* e) const;
166 
168 
171  int get_local_face_mark(Volume* vol, Face* f) const;
172 
173 
175 
179  void mark_neighborhood(size_t numIterations)
180  {mark_neighborhood(numIterations, RM_NONE, false);}
181 
183 
191  virtual void mark_neighborhood(
192  size_t numIterations,
193  RefinementMark refMark,
194  bool sideNbrsOnly) {}
195 
197 
198  virtual RefinementMark get_mark(Vertex* v) const {return RM_REFINE;}
199  virtual RefinementMark get_mark(Edge* e) const {return RM_REFINE;}
200  virtual RefinementMark get_mark(Face* f) const {return RM_REFINE;}
201  virtual RefinementMark get_mark(Volume* v) const {return RM_REFINE;}
205 
207  virtual RefinementMark get_mark(GridObject* o) const;
208 
210 
212  template <class TIterator>
213  void mark(const TIterator& iterBegin, const TIterator& iterEnd,
214  RefinementMark refMark = RM_REFINE)
215  {
216  TIterator iter = iterBegin;
217  while(iter != iterEnd){
218  mark(*iter, refMark);
219  ++iter;
220  }
221  }
222 
223 
225 
228  void adaption_begins();
229  void adaption_ends();
233 
234  void refine();
235 
237 
245  bool coarsen();
246 
247 
249  size_t num_marked_edges(std::vector<int>& numMarkedEdgesOut);
251  size_t num_marked_faces(std::vector<int>& numMarkedFacesOut);
253  size_t num_marked_volumes(std::vector<int>& numMarkedVolsOut);
255  size_t num_marked_elements(std::vector<int>& numMarkedElemsOut);
256 
258  size_t num_marked_edges() {std::vector<int> t; return num_marked_edges(t);}
260  size_t num_marked_faces() {std::vector<int> t; return num_marked_faces(t);}
262  size_t num_marked_volumes() {std::vector<int> t; return num_marked_volumes(t);}
264  size_t num_marked_elements() {std::vector<int> t; return num_marked_elements(t);}
265 
267 
269  virtual bool save_marks_to_file(const char* filename) = 0;
270 
272 
274  void set_adjusted_marks_debug_filename(const char* filename);
275 
276  void enable_debugging(bool enable) {m_debuggingEnabled = enable;}
277  bool debugging_enabled() const {return m_debuggingEnabled;}
278 
279  protected:
281 
283  void set_message_hub(SPMessageHub msgHub);
284 
286  virtual void perform_refinement() = 0;
287 
289 
290  virtual bool perform_coarsening() {return false;}
291 
293  virtual void num_marked_edges_local(std::vector<int>& numMarkedEdgesOut) = 0;
295  virtual void num_marked_faces_local(std::vector<int>& numMarkedFacesOut) = 0;
297  virtual void num_marked_volumes_local(std::vector<int>& numMarkedVolsOut) = 0;
298 
299  protected:
306 };
307 
309 
310 }// end of namespace
311 
312 #endif
Base-class for edges.
Definition: grid_base_objects.h:397
Faces are 2-dimensional objects.
Definition: grid_base_objects.h:510
Manages the elements of a grid and their interconnection.
Definition: grid.h:132
The base class for all geometric objects, such as vertices, edges, faces, volumes,...
Definition: grid_base_objects.h:157
The refiner interface allows to mark elements for refinement and to call refine.
Definition: refiner_interface.h:67
void mark(const TIterator &iterBegin, const TIterator &iterEnd, RefinementMark refMark=RM_REFINE)
marks all elements between iterBegin and iterEnd.
Definition: refiner_interface.h:213
virtual bool perform_coarsening()
Called by coarsen(). Derived classes sould implement their coarsen algorithm here.
Definition: refiner_interface.h:290
bool coarsen()
Performs coarsening on the elements marked RM_COARSEN.
Definition: refiner_interface.cpp:162
SPMessageHub m_messageHub
Definition: refiner_interface.h:300
virtual bool local_marks_supported() const
returns true, if the refiner supports local marks.
Definition: refiner_interface.h:99
size_t num_marked_elements()
returns the number of (globally) marked grid-objects of highest dimension
Definition: refiner_interface.h:264
virtual void num_marked_edges_local(std::vector< int > &numMarkedEdgesOut)=0
returns the number of locally marked edges on all levels of the hierarchy
virtual bool mark(Vertex *v, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:103
virtual void perform_refinement()=0
called by refine(). Derived classes should implement their refinement algorithm here.
virtual void clear_marks()
clears all marks. Default implementation is empty
Definition: refiner_interface.h:88
virtual void num_marked_volumes_local(std::vector< int > &numMarkedVolsOut)=0
returns the number of locally marked volumes on all levels of the hierarchy
void adaption_begins()
notifies all listeners of the associated message-hub, that adaption begins / ends.
Definition: refiner_interface.cpp:69
size_t num_marked_faces()
returns the number of (globally) marked faces on all levels of the hierarchy
Definition: refiner_interface.h:260
void adaption_ends()
notifies all listeners of the associated message-hub, that adaption begins / ends.
Definition: refiner_interface.cpp:85
size_t num_marked_edges()
returns the number of (globally) marked edges on all levels of the hierarchy
Definition: refiner_interface.h:258
int get_local_face_mark(Volume *vol, Face *f) const
returns the local mark of the specified face of the given volume
Definition: refiner_interface.cpp:266
virtual void mark_neighborhood(size_t numIterations, RefinementMark refMark, bool sideNbrsOnly)
marks the neighborhood of currently marked elements.
Definition: refiner_interface.h:191
virtual Grid * grid()=0
Returns the grid associated with the refiner.
virtual bool mark(Face *f, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:105
void enable_debugging(bool enable)
Definition: refiner_interface.h:276
bool marked_local(TElem *elem) const
Definition: refiner_interface.h:122
SPRefinementProjector projector()
Definition: refiner_interface.h:78
void set_projector(SPRefinementProjector projector)
Definition: refiner_interface.h:75
virtual void mark_local(Face *e, int mark)
Marks a face or volume for local refinement.
Definition: refiner_interface.h:142
bool marked_closure(TElem *elem) const
Definition: refiner_interface.h:116
virtual int get_local_mark(Volume *e) const
returns the local mark of the specified face or volume.
Definition: refiner_interface.h:151
void set_adjusted_marks_debug_filename(const char *filename)
sets a filename to which adjusted marks are saved during refinement / coarsening
Definition: refiner_interface.cpp:217
virtual bool save_marks_to_file(const char *filename)=0
Writes the associated grid and marks to a file. Pure virtual.
virtual bool adaptivity_supported() const =0
returns whether the refiner is able to perform adaptive refinement
virtual RefinementMark get_mark(Face *f) const
Returns the mark of a given element. Default returns RM_REFINE.
Definition: refiner_interface.h:200
bool m_adaptionIsActive
Definition: refiner_interface.h:303
void set_message_hub(SPMessageHub msgHub)
sets the message hub.
Definition: refiner_interface.cpp:212
virtual int get_local_mark(Face *e) const
returns the local mark of the specified face or volume.
Definition: refiner_interface.h:150
virtual void mark_local(Volume *e, int mark)
Marks a face or volume for local refinement.
Definition: refiner_interface.h:143
bool m_debuggingEnabled
Definition: refiner_interface.h:304
virtual bool coarsening_supported() const =0
returns true, if the refiner supports coarsening.
bool marked_full(TElem *elem) const
Definition: refiner_interface.h:128
virtual Grid * get_associated_grid()=0
DEPRECIATED! Use grid(). Has to return the associated grid. Pure virtual.
int m_msgIdAdaption
Definition: refiner_interface.h:301
void mark_neighborhood(size_t numIterations)
marks the neighborhood of currently marked elements.
Definition: refiner_interface.h:179
IRefiner(SPRefinementProjector projector=SPNULL)
Definition: refiner_interface.h:69
SPRefinementProjector m_projector
Definition: refiner_interface.h:302
bool debugging_enabled() const
Definition: refiner_interface.h:277
virtual bool mark(Edge *e, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:104
void refine()
Performs refinement on the marked elements.
Definition: refiner_interface.cpp:100
virtual bool mark(Volume *v, RefinementMark refMark=RM_REFINE)
Marks an element for refinement. Default implementation is empty.
Definition: refiner_interface.h:106
size_t num_marked_volumes()
returns the number of (globally) marked volumes on all levels of the hierarchy
Definition: refiner_interface.h:262
std::string m_adjustedMarksDebugFilename
Definition: refiner_interface.h:305
virtual ~IRefiner()
Definition: refiner_interface.h:73
virtual RefinementMark get_mark(Edge *e) const
Returns the mark of a given element. Default returns RM_REFINE.
Definition: refiner_interface.h:199
virtual RefinementMark get_mark(Volume *v) const
Returns the mark of a given element. Default returns RM_REFINE.
Definition: refiner_interface.h:201
virtual void num_marked_faces_local(std::vector< int > &numMarkedFacesOut)=0
returns the number of locally marked faces on all levels of the hierarchy
virtual RefinementMark get_mark(Vertex *v) const
Returns the mark of a given element. Default returns RM_REFINE.
Definition: refiner_interface.h:198
int get_local_edge_mark(Face *f, Edge *e) const
returns the local mark of the specified edge of the given face
Definition: refiner_interface.cpp:227
Base-class for all vertex-types.
Definition: grid_base_objects.h:231
Volumes are 3-dimensional objects.
Definition: grid_base_objects.h:754
RefinementMark
refinement-marks allow to specify how an element shall be processed during refinement.
Definition: refiner_interface.h:48
@ RM_COARSEN
the element is coarsened (only valid for adaptive multi-grid refinement)
Definition: refiner_interface.h:56
@ RM_NONE
no refinement is performed
Definition: refiner_interface.h:49
@ RM_COPY
DEPRECATED. Use RM_CLOSURE or RM_LOCAL with localMark = 0 instead.
Definition: refiner_interface.h:51
@ RM_REFINE
DEPRECATED. Use RM_FULL instead.
Definition: refiner_interface.h:55
@ RM_CLOSURE
Refines elements according to associated marked edges.
Definition: refiner_interface.h:50
@ RM_MAX
the highest constant in RefinementMark. Should always be smaller than 128!
Definition: refiner_interface.h:58
@ RM_ANISOTROPIC
DEPRECATED. Use RM_CLOSURE instead.
Definition: refiner_interface.h:52
@ RM_LOCAL
Refines elements according to a local refinement mark (use 'mark_local')
Definition: refiner_interface.h:53
@ RM_DUMMY
used internally during mark-adjustment
Definition: refiner_interface.h:57
@ RM_FULL
Fully refines an element and all associated sides and edges.
Definition: refiner_interface.h:54
const NullSmartPtr SPNULL
The equivalent to NULL for smart pointers.
Definition: smart_pointer.h:90
#define UG_THROW(msg)
Definition: error.h:57
the ug namespace