tree.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-2022 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 // Header file for generic tree structures
27 #ifndef OOMPH_TREE_HEADER
28 #define OOMPH_TREE_HEADER
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 #ifdef OOMPH_HAS_MPI
36 #include "mpi.h"
37 #endif
38 
39 // OOMPH-LIB headers
40 #include "Vector.h"
41 #include "map_matrix.h"
42 
43 namespace oomph
44 {
45  // Forward class definition for class representing the root of a Tree
46  class TreeRoot;
47 
48  class RefineableElement;
49 
50  class Mesh;
51 
52  //========================================================================
72  //=================================================================
73  class Tree
74  {
75  public:
78  virtual ~Tree();
79 
81  Tree(const Tree& dummy) = delete;
82 
84  void operator=(const Tree&) = delete;
85 
89  {
90  return Object_pt;
91  }
92 
94  void flush_object()
95  {
96  Object_pt = 0;
97  }
98 
103  Tree* son_pt(const int& son_index) const
104  {
105  // If there are no sons, return NULL (0)
106  if (Son_pt.size() == 0)
107  {
108  return 0;
109  }
110  // Otherwise, return the pointer to the appropriate son
111  else
112  {
113  return Son_pt[son_index];
114  }
115  }
116 
117 
124  {
125  Son_pt = son_pt;
126  }
127 
129  unsigned nsons() const
130  {
131  return Son_pt.size();
132  }
133 
135  void flush_sons()
136  {
137  Son_pt.clear();
138  }
139 
142  {
143  return Root_pt;
144  }
145 
147  TreeRoot* root_pt() const
148  {
149  return Root_pt;
150  }
151 
154  template<class ELEMENT>
155  void split_if_required();
156 
160  template<class ELEMENT>
161  void p_refine_if_required(Mesh*& mesh_pt);
162 
165  void merge_sons_if_required(Mesh*& mesh_pt);
166 
168  void deactivate_object();
169 
174  Tree* const& father_pt,
175  const int& son_type) = 0;
176 
178  typedef void (Tree::*VoidMemberFctPt)();
179 
182  typedef void (Tree::*VoidMeshPtArgumentMemberFctPt)(Mesh*& mesh_pt);
183 
184 
187  void traverse_all(Tree::VoidMemberFctPt member_function);
188 
192  Mesh*& mesh_pt);
193 
196  void traverse_all_but_leaves(Tree::VoidMemberFctPt member_function);
197 
200  void traverse_leaves(Tree::VoidMemberFctPt member_function);
201 
205  Mesh*& mesh_pt);
206 
209 
212 
214  int son_type() const
215  {
216  return Son_type;
217  }
218 
220  bool is_leaf()
221  {
222  // If there are no sons, it's a leaf, return true
223  if (Son_pt.size() == 0)
224  {
225  return true;
226  }
227  // Otherwise return false
228  else
229  {
230  return false;
231  }
232  }
233 
235  Tree* father_pt() const
236  {
237  return Father_pt;
238  }
239 
242  {
244  }
245 
247  unsigned level() const
248  {
249  return Level;
250  }
251 
256  {
258  }
259 
260  public:
262  static const int OMEGA;
263 
264  protected:
267  {
268  // Throw an error
269  throw OomphLibError("Don't call an empty constructor for a Tree object",
272  }
273 
280 
288  Tree* const& father_pt,
289  const int& son_type);
290 
293 
294  protected:
297 
300 
302  int Level;
303 
305  int Son_type;
306 
309 
314  };
315 
316 
317  //===================================================================
322  //==================================================================
323  class TreeRoot : public virtual Tree
324  {
325  protected:
330  std::map<int, TreeRoot*> Neighbour_pt;
331 
332 
338  std::map<int, bool> Neighbour_periodic;
339 
340  public:
343  {
344  // TreeRoot is the Root
345  Root_pt = this;
346  }
347 
348 
350  TreeRoot(const TreeRoot& dummy) = delete;
351 
353  void operator=(const TreeRoot&) = delete;
354 
357  TreeRoot*& neighbour_pt(const int& direction)
358  {
359  return Neighbour_pt[direction];
360  }
361 
364  bool is_neighbour_periodic(const int& direction)
365  {
366  return Neighbour_periodic[direction];
367  }
368 
370  void set_neighbour_periodic(const int& direction)
371  {
372  Neighbour_periodic[direction] = true;
373  }
374 
376  void set_neighbour_nonperiodic(const int& direction)
377  {
378  Neighbour_periodic[direction] = false;
379  }
380 
382  unsigned nneighbour()
383  {
384  // Loop over the neighbours and test whether they are non-null
385  unsigned count = 0;
386  for (std::map<int, TreeRoot*>::iterator it = Neighbour_pt.begin();
387  it != Neighbour_pt.end();
388  it++)
389  {
390  if (Neighbour_pt[it->first] != 0)
391  {
392  count++;
393  }
394  }
395  // Return number counted
396  return count;
397  }
398  };
399 
400 
401  //================================================================
407  //=================================================================
409  {
410  public:
413  TreeForest(Vector<TreeRoot*>& trees_pt);
414 
417  {
418  // Throw an error
419  throw OomphLibError(
420  "Don't call an empty constructor for a TreeForest object",
423  }
424 
426  TreeForest(const TreeForest& dummy) = delete;
427 
429  void operator=(const TreeForest&) = delete;
430 
433  virtual ~TreeForest();
434 
436  void stick_leaves_into_vector(Vector<Tree*>& forest_nodes);
437 
439  void stick_all_tree_nodes_into_vector(Vector<Tree*>& all_forest_nodes);
440 
443  virtual void check_all_neighbours(DocInfo& doc_info) = 0;
444 
451  DocInfo& doc_info, Vector<std::ofstream*>& output_stream) = 0;
452 
456  void close_hanging_node_files(DocInfo& doc_info,
457  Vector<std::ofstream*>& output_stream);
458 
460  unsigned ntree()
461  {
462  return Trees_pt.size();
463  }
464 
466  TreeRoot* tree_pt(const unsigned& i) const
467  {
468  return Trees_pt[i];
469  }
470 
472  void flush_trees()
473  {
474  // Clear Trees_pt vector
475  Trees_pt.clear();
476  }
477 
478  protected:
481  };
482 
483 } // namespace oomph
484 
485 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: oomph_utilities.h:499
Definition: mesh.h:67
Definition: oomph_definitions.h:222
Definition: refineable_elements.h:97
Definition: tree.h:409
void operator=(const TreeForest &)=delete
Broken assignment operator.
virtual void check_all_neighbours(DocInfo &doc_info)=0
TreeForest(const TreeForest &dummy)=delete
Broken copy constructor.
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
virtual void open_hanging_node_files(DocInfo &doc_info, Vector< std::ofstream * > &output_stream)=0
unsigned ntree()
Number of trees in forest.
Definition: tree.h:460
void stick_leaves_into_vector(Vector< Tree * > &forest_nodes)
Traverse forst and stick pointers to leaf "nodes" into Vector.
Definition: tree.cc:379
Vector< TreeRoot * > Trees_pt
Vector containing the pointers to the trees.
Definition: tree.h:480
TreeRoot * tree_pt(const unsigned &i) const
Return pointer to i-th tree in forest.
Definition: tree.h:466
virtual ~TreeForest()
Kill tree forest: Delete the constituent trees.
Definition: tree.cc:364
TreeForest()
Default constructor (empty and broken)
Definition: tree.h:416
void close_hanging_node_files(DocInfo &doc_info, Vector< std::ofstream * > &output_stream)
Definition: tree.cc:432
Definition: tree.h:324
std::map< int, bool > Neighbour_periodic
Definition: tree.h:338
void operator=(const TreeRoot &)=delete
Broken assignment operator.
bool is_neighbour_periodic(const int &direction)
Definition: tree.h:364
TreeRoot(const TreeRoot &dummy)=delete
Broken copy constructor.
unsigned nneighbour()
Return the number of neighbours.
Definition: tree.h:382
std::map< int, TreeRoot * > Neighbour_pt
Definition: tree.h:330
TreeRoot(RefineableElement *const &object_pt)
Constructor for the (empty) root tree.
Definition: tree.h:342
void set_neighbour_nonperiodic(const int &direction)
Set the neighbour in particular direction to be nonperiodic.
Definition: tree.h:376
void set_neighbour_periodic(const int &direction)
Set the neighbour in particular direction to be periodic.
Definition: tree.h:370
TreeRoot *& neighbour_pt(const int &direction)
Definition: tree.h:357
Definition: tree.h:74
Tree * Father_pt
Pointer to the Father of the Tree.
Definition: tree.h:296
void traverse_leaves(Tree::VoidMemberFctPt member_function)
Definition: tree.cc:207
void stick_all_tree_nodes_into_vector(Vector< Tree * > &)
Traverse and stick pointers to all "nodes" into Vector.
Definition: tree.cc:277
RefineableElement * object_pt() const
Definition: tree.h:88
unsigned nsons() const
Return number of sons (zero if it's a leaf node)
Definition: tree.h:129
void flush_sons()
Flush the sons.
Definition: tree.h:135
void traverse_all(Tree::VoidMemberFctPt member_function)
Definition: tree.cc:145
TreeRoot * root_pt() const
Return pointer to root of the tree (const version)
Definition: tree.h:147
void(Tree::* VoidMeshPtArgumentMemberFctPt)(Mesh *&mesh_pt)
Definition: tree.h:182
Tree(const Tree &dummy)=delete
Broken copy constructor.
virtual Tree * construct_son(RefineableElement *const &object_pt, Tree *const &father_pt, const int &son_type)=0
Tree * father_pt() const
Return pointer to father: NULL if it's a root node.
Definition: tree.h:235
TreeRoot * Root_pt
Pointer to the root of the tree.
Definition: tree.h:292
RefineableElement * Object_pt
Pointer to the object represented by the tree.
Definition: tree.h:308
void p_refine_if_required(Mesh *&mesh_pt)
Definition: tree.template.cc:149
void(Tree::* VoidMemberFctPt)()
Function pointer to argument-free void Tree member function.
Definition: tree.h:178
void operator=(const Tree &)=delete
Broken assignment operator.
bool is_leaf()
Return true if the tree is a leaf node.
Definition: tree.h:220
int son_type() const
Return son type.
Definition: tree.h:214
int Son_type
Son type (e.g. SW/SE/NW/NE in a quadtree)
Definition: tree.h:305
void flush_object()
Flush the object represented by the tree.
Definition: tree.h:94
void split_if_required()
Definition: tree.template.cc:61
int Level
Level of the Tree (level 0 = root)
Definition: tree.h:302
static const int OMEGA
Default value for an unassigned neighbour.
Definition: tree.h:262
Tree * son_pt(const int &son_index) const
Definition: tree.h:103
unsigned level() const
Return the level of the Tree (root=0)
Definition: tree.h:247
void set_son_pt(const Vector< Tree * > &son_pt)
Definition: tree.h:123
void set_father_pt(Tree *const &father_pt)
Set the father.
Definition: tree.h:241
Vector< Tree * > Son_pt
Vector of pointers to the sons of the Tree.
Definition: tree.h:299
void stick_leaves_into_vector(Vector< Tree * > &)
Traverse tree and stick pointers to leaf "nodes" (only) into Vector.
Definition: tree.cc:255
virtual ~Tree()
Definition: tree.cc:122
Tree()
Default constructor (empty and broken)
Definition: tree.h:266
TreeRoot *& root_pt()
Return pointer to root of the tree.
Definition: tree.h:141
void deactivate_object()
Call the RefineableElement's deactivate_element() function.
Definition: tree.cc:341
void traverse_all_but_leaves(Tree::VoidMemberFctPt member_function)
Definition: tree.cc:184
static double Max_neighbour_finding_tolerance
Definition: tree.h:313
void merge_sons_if_required(Mesh *&mesh_pt)
Definition: tree.cc:302
static double & max_neighbour_finding_tolerance()
Definition: tree.h:255
Definition: oomph-lib/src/generic/Vector.h:58
DRAIG: Change all instances of (SPATIAL_DIM) to (DIM-1).
Definition: AnisotropicHookean.h:10
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86