refineable_brick_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_REFINEABLE_BRICK_MESH_HEADER
27#define OOMPH_REFINEABLE_BRICK_MESH_HEADER
28
29
30// Config header
31#ifdef HAVE_CONFIG_H
32#include <oomph-lib-config.h>
33#endif
34
35#include <limits.h>
36
37
38// ooomph-lib includes
39#include "brick_mesh.h"
40#include "refineable_mesh.h"
42
43namespace oomph
44{
45 //=======================================================================
46 /// Intermediate mesh class that implements the mesh adaptation functions
47 /// specified in the TreeBasedRefineableMesh class for meshes that contain the
48 /// refineable variant of QElement s [The class ELEMENT provided
49 /// as the template parameter must be of type
50 /// RefineableQElement<3>].
51 ///
52 /// Mesh adaptation/refinement is implemented by OcTree
53 /// procedures and any concrete implementation of this class needs to
54 /// provide a OcTreeForest representation of the initial (coarse) mesh.
55 //=======================================================================
56 template<class ELEMENT>
58 public virtual BrickMeshBase
59 {
60 public:
61 /// Constructor: Setup static octree data
63 {
64 // OcTree static data needs to be setup before octree-based mesh
65 // refinement works
67 }
68
69 /// Broken copy constructor
71
72 /// Broken assignment operator
73 void operator=(const RefineableBrickMesh&) = delete;
74
75 /// Destructor:
77
78 /// Set up the tree forest associated with the Mesh.
79 /// Forwards call to setup_octree_forest()
80 virtual void setup_tree_forest()
81 {
83 }
84
85 /// Do what it says...
87 {
88 if (this->Forest_pt != 0)
89 {
90 // Get all the tree nodes
92 this->Forest_pt->stick_all_tree_nodes_into_vector(all_tree_nodes_pt);
93
94 // Get min and max refinement level from the tree
95 unsigned local_min_ref = 0;
96 unsigned local_max_ref = 0;
97 this->get_refinement_levels(local_min_ref, local_max_ref);
98
99 unsigned min_ref = local_min_ref;
100#ifdef OOMPH_HAS_MPI
101 if (Comm_pt != 0)
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
106 // levels
108 if (this->nelement() == 0)
109 {
110 int_local_min_ref = INT_MAX;
111 }
112 int int_min_ref = 0;
115 1,
116 MPI_INT,
117 MPI_MIN,
118 Comm_pt->mpi_comm());
120 }
121#endif
122
123 // If we have no elements there's nothing more to be done --
124 // we only came in here to participate in the communication
125 if (this->nelement() == 0)
126 {
127 // Flush the Forest's current trees
128 this->Forest_pt->flush_trees();
129
130 // Delete the old Forest
131 delete this->Forest_pt;
132
133 // Empty dummy vector to build empty forest
135
136 // Make a new (empty) Forest
137 this->Forest_pt = new OcTreeForest(trees_pt);
138
139 return;
140 }
141
142
143 // Vector to store trees for new Forest
145
146 // Loop over tree nodes (e.g. elements)
148 for (unsigned e = 0; e < n_tree_nodes; e++)
149 {
150 Tree* tree_pt = all_tree_nodes_pt[e];
151
152 // If the object_pt has been flushed then we don't want to keep
153 // this tree
154 if (tree_pt->object_pt() != 0)
155 {
156 // Get the refinement level of the current tree node
158 dynamic_cast<RefineableElement*>(tree_pt->object_pt());
159 unsigned level = el_pt->refinement_level();
160
161 // If we are below the minimum refinement level, remove tree
162 if (level < min_ref)
163 {
164 // Flush sons for this tree
165 tree_pt->flush_sons();
166
167 // Delete the tree (no recursion)
168 delete tree_pt;
169
170 // Delete the element
171 delete el_pt;
172 }
173 else if (level == min_ref)
174 {
175 // Get the sons (if there are any) and store them
176 unsigned n_sons = tree_pt->nsons();
178 for (unsigned i_son = 0; i_son < n_sons; i_son++)
179 {
180 backed_up_sons[i_son] = tree_pt->son_pt(i_son);
181 }
182
183 // Make the element into a new treeroot
185
186
187 // Pass sons
188 tree_root_pt->set_son_pt(backed_up_sons);
189
190 // Loop over sons and make the new treeroot their father
191 for (unsigned i_son = 0; i_son < n_sons; i_son++)
192 {
193 Tree* son_pt = backed_up_sons[i_son];
194
195 // Tell the son about its new father (which is also the root)
197 son_pt->root_pt() = tree_root_pt;
198
199 // ...and then tell all the descendants too
202 unsigned n = all_sons_pt.size();
203 for (unsigned i = 0; i < n; i++)
204 {
205 all_sons_pt[i]->root_pt() = tree_root_pt;
206 }
207 }
208
209 // Add tree root to the trees_pt vector
210 trees_pt.push_back(tree_root_pt);
211
212 // Now kill the original (non-root) tree: First
213 // flush sons for this tree
214 tree_pt->flush_sons();
215
216 // ...then delete the tree (no recursion)
217 delete tree_pt;
218 }
219 }
220 else // tree_pt->object_pt() is null, so delete tree
221 {
222 // Flush sons for this tree
223 tree_pt->flush_sons();
224
225 // Delete the tree (no recursion)
226 delete tree_pt;
227 }
228 }
229
230 // Flush the Forest's current trees
231 this->Forest_pt->flush_trees();
232
233 // Delete the old Forest
234 delete this->Forest_pt;
235
236 // Make a new Forest with the trees_pt roots created earlier
237 this->Forest_pt = new OcTreeForest(trees_pt);
238 }
239 else // Create a new Forest from scratch in the "usual" uniform way
240 {
241 // Turn elements into individual octrees and plant in forest
243 unsigned nel = nelement();
244 for (unsigned iel = 0; iel < nel; iel++)
245 {
246 // Get pointer to full element type
247 ELEMENT* el_pt = dynamic_cast<ELEMENT*>(element_pt(iel));
248
249 // Build associated octree(root) -- pass pointer to corresponding
250 // finite element and add the pointer to vector of octree (roots):
252 trees_pt.push_back(octree_root_pt);
253 }
254 // Plant OcTreeRoots in OcTreeForest
255 this->Forest_pt = new OcTreeForest(trees_pt);
256 }
257 }
258
259 protected:
260 };
261
262} // namespace oomph
263
264#endif
e
Definition cfortran.h:571
cstr elem_len * i
Definition cfortran.h:603
Base class for brick meshes (meshes made of 3D brick elements).
Definition brick_mesh.h:178
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
An OcTreeForest consists of a collection of OcTreeRoots. Each member tree can have neighbours to its ...
Definition octree.h:928
OcTreeRoot is a OcTree that forms the root of a (recursive) octree. The "root node" is special as it ...
Definition octree.h:611
static void setup_static_data()
Setup the static data, rotation and reflection schemes, etc.
Definition octree.cc:1040
Intermediate mesh class that implements the mesh adaptation functions specified in the TreeBasedRefin...
virtual ~RefineableBrickMesh()
Destructor:
RefineableBrickMesh(const RefineableBrickMesh &dummy)=delete
Broken copy constructor.
void setup_octree_forest()
Do what it says...
RefineableBrickMesh()
Constructor: Setup static octree data.
void operator=(const RefineableBrickMesh &)=delete
Broken assignment operator.
virtual void setup_tree_forest()
Set up the tree forest associated with the Mesh. Forwards call to setup_octree_forest()
RefineableElements are FiniteElements that may be subdivided into children to provide a better local ...
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).