binary_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 binary tree and binary tree forest classes
27 #ifndef OOMPH_BINARY_TREE_HEADER
28 #define OOMPH_BINARY_TREE_HEADER
29 
30 // Config header generated by autoconfig
31 #ifdef HAVE_CONFIG_H
32 #include <oomph-lib-config.h>
33 #endif
34 
35 // oomph-lib headers
36 #include "tree.h"
37 #include "matrices.h"
38 
39 namespace oomph
40 {
41  //======================================================================
43  //======================================================================
44  namespace BinaryTreeNames
45  {
48  enum
49  {
50  L,
51  R,
52  OMEGA = 26
53  };
54  }; // namespace BinaryTreeNames
55 
56  // Forward class definition for class representing the root of a BinaryTree
57  class BinaryTreeRoot;
58 
59  //======================================================================
90  //======================================================================
91  class BinaryTree : public virtual Tree
92  {
93  public:
96  virtual ~BinaryTree() {}
97 
99  BinaryTree(const BinaryTree& dummy) = delete;
100 
102  void operator=(const BinaryTree&) = delete;
103 
107  Tree* const& father_pt,
108  const int& son_type)
109  {
110  BinaryTree* temp_binary_pt =
112  return temp_binary_pt;
113  }
114 
135  BinaryTree* gteq_edge_neighbour(const int& direction,
136  Vector<double>& s_in_neighbour,
137  int& edge,
138  int& diff_level,
139  bool& in_neighbouring_tree) const;
140 
145  unsigned self_test();
146 
148  static void setup_static_data();
149 
156  static void doc_neighbours(Vector<Tree*> forest_nodes_pt,
157  std::ofstream& neighbours_file,
158  std::ofstream& neighbours_txt_file,
159  double& max_error);
160 
163 
164  protected:
167  {
168  throw OomphLibError(
169  "Don't call an empty constructor for a BinaryTree object",
172  }
173 
179 
186  Tree* const& father_pt,
187  const int& son_type)
189  {
190  }
191 
194 
195  private:
198  BinaryTree* gteq_edge_neighbour(const int& direction,
199  double& s_diff,
200  int& diff_level,
201  bool& in_neighbouring_tree,
202  int max_level,
203  BinaryTreeRoot* const& orig_root_pt) const;
204 
207 
211 
214 
218 
222  };
223 
224 
225  //======================================================================
229  //======================================================================
230  class BinaryTreeRoot : public virtual BinaryTree, public virtual TreeRoot
231  {
232  public:
237  {
238 #ifdef PARANOID
239  // Check that static member data has been setup
241  {
242  std::string error_message =
243  "Static member data hasn't been setup yet.\n";
244  error_message +=
245  "Call BinaryTree::setup_static_data() before creating\n";
246  error_message += "any BinaryTreeRoots\n";
247 
248  throw OomphLibError(
250  }
251 #endif
252  }
253 
255  BinaryTreeRoot(const BinaryTreeRoot& dummy) = delete;
256 
258  void operator=(const BinaryTreeRoot&) = delete;
259 
262  int direction_of_neighbour(BinaryTreeRoot* binary_tree_root_pt)
263  {
264  using namespace BinaryTreeNames;
265 
266  if (Neighbour_pt[L] == binary_tree_root_pt)
267  {
268  return L;
269  }
270  if (Neighbour_pt[R] == binary_tree_root_pt)
271  {
272  return R;
273  }
274 
275  // If we get here, it's not a neighbour
276  return OMEGA;
277  }
278  };
279 
280 
281  //======================================================================
284  //======================================================================
286  {
287  public:
290  {
291  // Throw an error
292  throw OomphLibError(
293  "Don't call an empty constructor for a BinaryTreeForest object",
296  }
297 
301 
303  BinaryTreeForest(const BinaryTreeForest& dummy) = delete;
304 
306  void operator=(const BinaryTreeForest&) = delete;
307 
310  virtual ~BinaryTreeForest() {}
311 
316  void check_all_neighbours(DocInfo& doc_info);
317 
320  Vector<std::ofstream*>& output_stream)
321  {
322  }
323 
328  unsigned self_test();
329 
330  private:
332  void find_neighbours();
333 
336  BinaryTreeRoot* binary_tree_pt(const unsigned& i)
337  {
338  return dynamic_cast<BinaryTreeRoot*>(Trees_pt[i]);
339  }
340 
345  BinaryTreeRoot* binary_neigh_pt(const unsigned& i, const int& direction)
346  {
347  return dynamic_cast<BinaryTreeRoot*>(
348  Trees_pt[i]->neighbour_pt(direction));
349  }
350  };
351 
352 } // namespace oomph
353 
354 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
MatrixXd L
Definition: LLT_example.cpp:6
@ R
Definition: StatisticsVector.h:21
Definition: binary_tree.h:286
BinaryTreeForest()
Default constructor (empty and broken)
Definition: binary_tree.h:289
BinaryTreeRoot * binary_tree_pt(const unsigned &i)
Definition: binary_tree.h:336
virtual ~BinaryTreeForest()
Definition: binary_tree.h:310
void operator=(const BinaryTreeForest &)=delete
Broken assignment operator.
void open_hanging_node_files(DocInfo &doc_info, Vector< std::ofstream * > &output_stream)
A line mesh cannot have hanging nodes so make this function empty.
Definition: binary_tree.h:319
BinaryTreeRoot * binary_neigh_pt(const unsigned &i, const int &direction)
Definition: binary_tree.h:345
BinaryTreeForest(const BinaryTreeForest &dummy)=delete
Broken copy constructor.
Definition: binary_tree.h:231
BinaryTreeRoot(RefineableElement *const &object_pt)
Definition: binary_tree.h:235
int direction_of_neighbour(BinaryTreeRoot *binary_tree_root_pt)
Definition: binary_tree.h:262
void operator=(const BinaryTreeRoot &)=delete
Broken assignment operator.
BinaryTreeRoot(const BinaryTreeRoot &dummy)=delete
Broken copy constructor.
Definition: binary_tree.h:92
static Vector< double > S_base
Definition: binary_tree.h:210
static Vector< std::string > Colour
Colours for neighbours in various directions.
Definition: binary_tree.h:206
BinaryTree(RefineableElement *const &object_pt)
Definition: binary_tree.h:178
BinaryTree(RefineableElement *const &object_pt, Tree *const &father_pt, const int &son_type)
Definition: binary_tree.h:185
static Vector< std::string > Direct_string
Translate (enumerated) directions into strings.
Definition: binary_tree.h:162
BinaryTree()
Default constructor (empty and broken)
Definition: binary_tree.h:166
static void setup_static_data()
Set up the static data, reflection schemes, etc.
Definition: binary_tree.cc:86
static void doc_neighbours(Vector< Tree * > forest_nodes_pt, std::ofstream &neighbours_file, std::ofstream &neighbours_txt_file, double &max_error)
Definition: binary_tree.cc:668
static bool Static_data_has_been_setup
Boolean indicating that static member data has been setup.
Definition: binary_tree.h:193
virtual ~BinaryTree()
Definition: binary_tree.h:96
void operator=(const BinaryTree &)=delete
Broken assignment operator.
BinaryTree(const BinaryTree &dummy)=delete
Broken copy constructor.
static DenseMatrix< int > Reflect
Definition: binary_tree.h:221
BinaryTree * gteq_edge_neighbour(const int &direction, Vector< double > &s_in_neighbour, int &edge, int &diff_level, bool &in_neighbouring_tree) const
Definition: binary_tree.cc:172
unsigned self_test()
Definition: binary_tree.cc:393
Tree * construct_son(RefineableElement *const &object_pt, Tree *const &father_pt, const int &son_type)
Definition: binary_tree.h:106
static DenseMatrix< bool > Is_adjacent
Definition: binary_tree.h:217
static Vector< int > Reflect_edge
Get opposite edge, e.g. Reflect_edge[L]=R.
Definition: binary_tree.h:213
Definition: oomph_utilities.h:499
Definition: oomph_definitions.h:222
Definition: refineable_elements.h:97
Definition: tree.h:409
Definition: tree.h:324
std::map< int, TreeRoot * > Neighbour_pt
Definition: tree.h:330
Definition: tree.h:74
RefineableElement * object_pt() const
Definition: tree.h:88
Tree * father_pt() const
Return pointer to father: NULL if it's a root node.
Definition: tree.h:235
int son_type() const
Return son type.
Definition: tree.h:214
static const int OMEGA
Default value for an unassigned neighbour.
Definition: tree.h:262
double max_error
Definition: MortaringCantileverCompareToNonMortaring.cpp:188
@ R
Definition: binary_tree.h:51
@ L
Definition: binary_tree.h:50
@ OMEGA
Definition: binary_tree.h:52
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
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