refineable_quad_mesh.h
Go to the documentation of this file.
1// LIC// ====================================================================
2// LIC// This file forms part of oomph-lib, the object-oriented,
3// LIC// multi-physics finite-element library, available
4// LIC// at http://www.oomph-lib.org.
5// LIC//
6// LIC// Copyright (C) 2006-2025 Matthias Heil and Andrew Hazel
7// LIC//
8// LIC// This library is free software; you can redistribute it and/or
9// LIC// modify it under the terms of the GNU Lesser General Public
10// LIC// License as published by the Free Software Foundation; either
11// LIC// version 2.1 of the License, or (at your option) any later version.
12// LIC//
13// LIC// This library is distributed in the hope that it will be useful,
14// LIC// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// LIC// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16// LIC// Lesser General Public License for more details.
17// LIC//
18// LIC// You should have received a copy of the GNU Lesser General Public
19// LIC// License along with this library; if not, write to the Free Software
20// LIC// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21// LIC// 02110-1301 USA.
22// LIC//
23// LIC// The authors may be contacted at oomph-lib@maths.man.ac.uk.
24// LIC//
25// LIC//====================================================================
26#ifndef OOMPH_GENERIC_REFINEABLE_QUAD_MESH_HEADER
27#define OOMPH_GENERIC_REFINEABLE_QUAD_MESH_HEADER
28
29#include <limits.h>
30
31#include "quad_mesh.h"
32#include "refineable_mesh.h"
34
35namespace oomph
36{
37 //=======================================================================
38 /// Intermediate mesh class that implements the mesh adaptation functions
39 /// specified in the TreeBasedRefineableMesh class for meshes that contain the
40 /// refineable variant of QElement s [The class ELEMENT provided
41 /// as the template parameter must be of type
42 /// RefineableQElement<2>].
43 ///
44 /// Mesh adaptation/refinement is implemented by QuadTree
45 /// procedures and any concrete implementation of this class needs to
46 /// provide a QuadTreeForest representation of the initial (coarse) mesh.
47 //=======================================================================
48 template<class ELEMENT>
49 class RefineableQuadMesh : public virtual TreeBasedRefineableMesh<ELEMENT>,
50 public virtual QuadMeshBase
51 {
52 public:
53 /// Constructor: Setup static quadtree data
55 {
56 // QuadTree static data needs to be setup before quadtree-based mesh
57 // refinement works
59 }
60
61 /// Broken copy constructor
63
64 /// Broken assignment operator
65 // Commented out broken assignment operator because this can lead to a
66 // conflict warning when used in the virtual inheritence hierarchy.
67 // Essentially the compiler doesn't realise that two separate
68 // implementations of the broken function are the same and so, quite
69 // rightly, it shouts.
70 /*void operator=(const RefineableQuadMesh&) = delete;*/
71
72 /// Destructor:
74
75
76 /// Set up the tree forest associated with the Mesh.
77 /// Forwards call to setup_quadtree_forest()
78 virtual void setup_tree_forest()
79 {
81 }
82
83 /// Set up QuadTreeForest. Wipes any existing tree structure below
84 /// the minimum refinement level and regards the elements at that level
85 /// as the root trees in the forest.
87 {
88 // A forst pointer is setup at least once when the mesh is initially
89 // created in serial and stays around
90 if (this->Forest_pt != 0)
91 {
92 // Get all the tree nodes
94 this->Forest_pt->stick_all_tree_nodes_into_vector(all_tree_nodes_pt);
95
96 // Get min and max refinement level from the tree
97 unsigned local_min_ref = 0;
98 unsigned local_max_ref = 0;
99 this->get_refinement_levels(local_min_ref, local_max_ref);
100
101#ifdef OOMPH_HAS_MPI
102
103 // Reconcile between processors: If (e.g. following
104 // distribution/pruning) the mesh has no elements on this processor)
105 // then ignore its contribution to the poll of max/min refinement levels
107
108 if (this->nelement() == 0)
109 {
110 int_local_min_ref = INT_MAX;
111 }
112
113 int int_min_ref = 0;
116 1,
117 MPI_INT,
118 MPI_MIN,
119 Comm_pt->mpi_comm());
120
121 unsigned min_ref = unsigned(int_min_ref);
122
123#else
124
125 unsigned min_ref = local_min_ref;
126
127#endif
128
129 // If we have no elements there's nothing more to be done --
130 // we only came in here to participate in the communication
131 if (this->nelement() == 0)
132 {
133 // Flush the Forest's current trees
134 this->Forest_pt->flush_trees();
135
136 // Delete the old Forest
137 delete this->Forest_pt;
138
139 // Empty dummy vector to build empty forest
141
142 // Make a new (empty) Forest
143 this->Forest_pt = new QuadTreeForest(trees_pt);
144 return;
145 }
146
147 // Vector to store trees for new Forest
149
150 // Loop over tree nodes (e.g. elements)
152 for (unsigned e = 0; e < n_tree_nodes; e++)
153 {
154 Tree* tree_pt = all_tree_nodes_pt[e];
155
156 // If the object_pt has been flushed then we don't want to keep
157 // this tree
158 if (tree_pt->object_pt() != 0)
159 {
160 // Get the refinement level of the current tree node
162 dynamic_cast<RefineableElement*>(tree_pt->object_pt());
163 unsigned level = el_pt->refinement_level();
164
165 // If we are below the minimum refinement level, remove tree
166 if (level < min_ref)
167 {
168 // Flush sons for this tree
169 tree_pt->flush_sons();
170
171 // Delete the tree (no recursion)
172 delete tree_pt;
173
174 // Delete the element
175 delete el_pt;
176 }
177 else if (level == min_ref)
178 {
179 // Get the sons (if there are any) and store them
180 unsigned n_sons = tree_pt->nsons();
182 for (unsigned i_son = 0; i_son < n_sons; i_son++)
183 {
184 backed_up_sons[i_son] = tree_pt->son_pt(i_son);
185 }
186
187 // Make the element into a new tree-root
189
190 // Pass sons
191 tree_root_pt->set_son_pt(backed_up_sons);
192
193 // Loop over sons and make the new treeroot their father
194 for (unsigned i_son = 0; i_son < n_sons; i_son++)
195 {
196 Tree* son_pt = backed_up_sons[i_son];
197
198 // Tell the son about its new father (which is also the root)
200 son_pt->root_pt() = tree_root_pt;
201
202 // ...and then tell all the descendants too
205 unsigned n = all_sons_pt.size();
206 for (unsigned i = 0; i < n; i++)
207 {
208 all_sons_pt[i]->root_pt() = tree_root_pt;
209 }
210 }
211
212 // Add tree-root to the trees_pt vector
213 trees_pt.push_back(tree_root_pt);
214
215 // Now kill the original (non-root) tree: First
216 // flush sons for this tree
217 tree_pt->flush_sons();
218
219 // ...then delete the tree (no recursion)
220 delete tree_pt;
221 }
222 }
223 else // tree_pt->object_pt() is null, so delete tree
224 {
225 // Flush sons for this tree
226 tree_pt->flush_sons();
227
228 // Delete the tree (no recursion)
229 delete tree_pt;
230 }
231 }
232
233 // Flush the Forest's current trees
234 this->Forest_pt->flush_trees();
235
236 // Delete the old Forest
237 delete this->Forest_pt;
238
239 // Make a new Forest with the trees_pt roots created earlier
240 this->Forest_pt = new QuadTreeForest(trees_pt);
241 }
242 else // Create a new Forest from scratch in the "usual" uniform way
243 {
244 // Each finite element in the coarse base mesh gets associated
245 // with (the root of) a QuadTree. Store QuadTreeRoots in vector:
247
248 // Loop over all elements, build corresponding QuadTree
249 // and store QuadTreeRoots in vector:
250 unsigned n_element = this->nelement();
251 for (unsigned e = 0; e < n_element; e++)
252 {
253 // Get pointer to full element type
254 ELEMENT* el_pt = dynamic_cast<ELEMENT*>(this->element_pt(e));
255
256 // Build associated quadtree(root) -- pass pointer to corresponding
257 // finite element and add the pointer to vector of quadtree (roots):
258 trees_pt.push_back(new QuadTreeRoot(el_pt));
259 }
260
261 // Plant QuadTreeRoots in QuadTreeForest
262 this->Forest_pt = new QuadTreeForest(trees_pt);
263 }
264 }
265 };
266
267} // namespace oomph
268
269#endif
e
Definition cfortran.h:571
cstr elem_len * i
Definition cfortran.h:603
double size() const
Calculate the size of the element (length, area, volume,...) in Eulerian computational coordinates....
Definition elements.cc:4320
OomphCommunicator * Comm_pt
Pointer to communicator – set to NULL if mesh is not distributed.
Definition mesh.h:119
const Vector< GeneralisedElement * > & element_pt() const
Return reference to the Vector of elements.
Definition mesh.h:464
unsigned long nelement() const
Return number of elements in the mesh.
Definition mesh.h:598
Base class for quad meshes (meshes made of 2D quad elements).
Definition quad_mesh.h:57
A QuadTreeForest consists of a collection of QuadTreeRoots. Each member tree can have neighbours to i...
Definition quadtree.h:409
QuadTreeRoot is a QuadTree that forms the root of a (recursive) quadtree. The "root node" is special ...
Definition quadtree.h:293
static void setup_static_data()
Setup the static data, rotation and reflection schemes, etc.
Definition quadtree.cc:120
RefineableElements are FiniteElements that may be subdivided into children to provide a better local ...
Intermediate mesh class that implements the mesh adaptation functions specified in the TreeBasedRefin...
virtual ~RefineableQuadMesh()
Broken assignment operator.
RefineableQuadMesh(const RefineableQuadMesh &dummy)=delete
Broken copy constructor.
RefineableQuadMesh()
Constructor: Setup static quadtree data.
void setup_quadtree_forest()
Set up QuadTreeForest. Wipes any existing tree structure below the minimum refinement level and regar...
virtual void setup_tree_forest()
Set up the tree forest associated with the Mesh. Forwards call to setup_quadtree_forest()
TAdvectionDiffusionReactionElement<NREAGENT,DIM,NNODE_1D> elements are isoparametric triangular DIM-d...
virtual void get_refinement_levels(unsigned &min_refinement_level, unsigned &max_refinement_level)
Get max/min refinement levels in mesh.
TreeForest * Forest_pt
Forest representation of the mesh.
Templated base class for refineable meshes. The use of the template parameter is required only for cr...
void flush_trees()
Flush trees from forest.
Definition tree.h:472
void stick_all_tree_nodes_into_vector(Vector< Tree * > &all_forest_nodes)
Traverse forest and stick pointers to all "nodes" into Vector.
Definition tree.cc:405
A generalised tree base class that abstracts the common functionality between the quad- and octrees u...
Definition tree.h:74
void stick_all_tree_nodes_into_vector(Vector< Tree * > &)
Traverse and stick pointers to all "nodes" into Vector.
Definition tree.cc:277
unsigned nsons() const
Return number of sons (zero if it's a leaf node)
Definition tree.h:129
TreeRoot *& root_pt()
Return pointer to root of the tree.
Definition tree.h:141
void flush_sons()
Flush the sons.
Definition tree.h:135
RefineableElement * object_pt() const
Return the pointer to the object (RefineableElement) represented by the tree.
Definition tree.h:88
Tree * son_pt(const int &son_index) const
Return pointer to the son for a given index. Note that to aid code readability specific enums have be...
Definition tree.h:103
void set_father_pt(Tree *const &father_pt)
Set the father.
Definition tree.h:241
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).