quadtree.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 quadtree and quadtree forest classes
27 #ifndef OOMPH_QUADTREE_HEADER
28 #define OOMPH_QUADTREE_HEADER
29 
30 
31 // Config header generated by autoconfig
32 #ifdef HAVE_CONFIG_H
33 #include <oomph-lib-config.h>
34 #endif
35 
36 #ifdef OOMPH_HAS_MPI
37 #include "mpi.h"
38 #endif
39 
40 // OOMPH-LIB headers
41 #include "tree.h"
42 #include "matrices.h"
43 
44 
45 namespace oomph
46 {
47  //====================================================================
49  //====================================================================
50  namespace QuadTreeNames
51  {
54  enum
55  {
56  SW,
57  SE,
58  NW,
59  NE,
60  N,
61  E,
62  S,
63  W,
64  OMEGA = 26
65  };
66  }; // namespace QuadTreeNames
67 
68  // Forward class definition for class representing the root of a QuadTree
69  class QuadTreeRoot;
70 
71  //================================================================
102  //=================================================================
103  class QuadTree : public virtual Tree
104  {
105  public:
108  virtual ~QuadTree() {}
109 
111  QuadTree(const QuadTree& dummy) = delete;
112 
114  void operator=(const QuadTree&) = delete;
115 
119  Tree* const& father_pt,
120  const int& son_type)
121  {
122  QuadTree* temp_quad_pt = new QuadTree(object_pt, father_pt, son_type);
123  return temp_quad_pt;
124  }
125 
158  QuadTree* gteq_edge_neighbour(const int& direction,
159  Vector<unsigned>& translate_s,
160  Vector<double>& s_lo,
161  Vector<double>& s_hi,
162  int& edge,
163  int& diff_level,
164  bool& in_neighbouring_tree) const;
165 
169  Vector<const QuadTree*>& tree_neighbouring_nodes,
170  Vector<Vector<double>>& tree_neighbouring_s_lo,
171  Vector<Vector<double>>& tree_neighbouring_s_hi,
172  Vector<int>& tree_neighbouring_diff_level,
173  const QuadTree* my_neigh_pt,
174  const int& direction) const;
175 
180  unsigned self_test();
181 
183  static void setup_static_data();
184 
192  static void doc_neighbours(Vector<Tree*> forest_nodes_pt,
193  std::ofstream& neighbours_file,
194  std::ofstream& neighbours_txt_file,
195  double& max_error);
196 
197 
200 
201  protected:
204  {
205  throw OomphLibError(
206  "Don't call an empty constructor for a QuadTree object",
209  }
210 
217 
225  Tree* const& father_pt,
226  const int& son_type)
228  {
229  }
230 
233 
234 
235  private:
238  QuadTree* gteq_edge_neighbour(const int& direction,
239  double& s_diff,
240  int& diff_level,
241  bool& in_neighbouring_tree,
242  int max_level,
243  QuadTreeRoot* const& orig_root_pt) const;
244 
247 
251 
256 
259 
264 
268 
272 
278 
283  };
284 
285 
286  //===================================================================
291  //==================================================================
292  class QuadTreeRoot : public virtual QuadTree, public virtual TreeRoot
293  {
294  private:
305 
306  public:
311  {
312 #ifdef PARANOID
313  // Check that static member data has been setup
315  {
316  std::string error_message =
317  "Static member data hasn't been setup yet.\n";
318  error_message += "Call QuadTree::setup_static_data() before creating\n";
319  error_message += "any QuadTreeRoots\n";
320 
321  throw OomphLibError(
323  }
324 #endif
325 
326  using namespace QuadTreeNames;
327 
328  // Initialise the North equivalents of the neighbouring QuadTreeRoots
329  North_equivalent.resize(27);
330 
331  North_equivalent[N] = N;
332  North_equivalent[E] = N;
333  North_equivalent[W] = N;
334  North_equivalent[S] = N;
335  }
336 
337 
339  QuadTreeRoot(const QuadTreeRoot& dummy) = delete;
340 
342  void operator=(const QuadTreeRoot&) = delete;
343 
344 
354  int& north_equivalent(const int& neighbour)
355  {
356 #ifdef PARANOID
357  using namespace QuadTreeNames;
358  // Neighbour can only be located in N/S/E/W direction
359  if ((neighbour != S) && (neighbour != N) && (neighbour != W) &&
360  (neighbour != E))
361  {
362  std::ostringstream error_message;
363  error_message << "The neighbour can only be N,S,E,W, not"
364  << Direct_string[neighbour] << std::endl;
365 
366  throw OomphLibError(error_message.str(),
369  }
370 #endif
371  return North_equivalent[neighbour];
372  }
373 
374 
377  int direction_of_neighbour(QuadTreeRoot* quadtree_root_pt)
378  {
379  using namespace QuadTreeNames;
380  if (Neighbour_pt[N] == quadtree_root_pt)
381  {
382  return N;
383  }
384  if (Neighbour_pt[E] == quadtree_root_pt)
385  {
386  return E;
387  }
388  if (Neighbour_pt[S] == quadtree_root_pt)
389  {
390  return S;
391  }
392  if (Neighbour_pt[W] == quadtree_root_pt)
393  {
394  return W;
395  }
396  // If we get here, it's not a neighbour
397  return OMEGA;
398  }
399  };
400 
401 
402  //================================================================
407  //=================================================================
408  class QuadTreeForest : public TreeForest
409  {
410  public:
413  {
414  // Throw an error
415  throw OomphLibError(
416  "Don't call an empty constructor for a QuadTreeForest object",
419  }
420 
424 
426  QuadTreeForest(const QuadTreeForest& dummy) = delete;
427 
429  void operator=(const QuadTreeForest&) = delete;
430 
433  virtual ~QuadTreeForest() {}
434 
439  void check_all_neighbours(DocInfo& doc_info);
440 
443  void open_hanging_node_files(DocInfo& doc_info,
444  Vector<std::ofstream*>& output_stream);
445 
450  unsigned self_test();
451 
452  private:
454  void construct_north_equivalents();
455 
457  void find_neighbours();
458 
462  QuadTreeRoot* quadtree_pt(const unsigned& i)
463  {
464  return dynamic_cast<QuadTreeRoot*>(Trees_pt[i]);
465  }
466 
471  QuadTreeRoot* quad_neigh_pt(const unsigned& i, const int& direction)
472  {
473  return dynamic_cast<QuadTreeRoot*>(Trees_pt[i]->neighbour_pt(direction));
474  }
475  };
476 
477 } // namespace oomph
478 
479 #endif
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Definition: oomph_utilities.h:499
Definition: oomph_definitions.h:222
Definition: quadtree.h:409
QuadTreeForest(const QuadTreeForest &dummy)=delete
Broken copy constructor.
void operator=(const QuadTreeForest &)=delete
Broken assignment operator.
QuadTreeRoot * quadtree_pt(const unsigned &i)
Definition: quadtree.h:462
QuadTreeForest()
Default constructor (empty and broken)
Definition: quadtree.h:412
QuadTreeRoot * quad_neigh_pt(const unsigned &i, const int &direction)
Definition: quadtree.h:471
virtual ~QuadTreeForest()
Definition: quadtree.h:433
Definition: quadtree.h:293
void operator=(const QuadTreeRoot &)=delete
Broken assignment operator.
Vector< int > North_equivalent
Definition: quadtree.h:304
QuadTreeRoot(RefineableElement *const &object_pt)
Definition: quadtree.h:309
QuadTreeRoot(const QuadTreeRoot &dummy)=delete
Broken copy constructor.
int & north_equivalent(const int &neighbour)
Definition: quadtree.h:354
int direction_of_neighbour(QuadTreeRoot *quadtree_root_pt)
Definition: quadtree.h:377
Definition: quadtree.h:104
void operator=(const QuadTree &)=delete
Broken assignment operator.
static Vector< std::string > Direct_string
Translate (enumerated) directions into strings.
Definition: quadtree.h:199
static void doc_neighbours(Vector< Tree * > forest_nodes_pt, std::ofstream &neighbours_file, std::ofstream &neighbours_txt_file, double &max_error)
Definition: quadtree.cc:1402
static DenseMatrix< double > S_step
Definition: quadtree.h:255
void stick_neighbouring_leaves_into_vector(Vector< const QuadTree * > &tree_neighbouring_nodes, Vector< Vector< double >> &tree_neighbouring_s_lo, Vector< Vector< double >> &tree_neighbouring_s_hi, Vector< int > &tree_neighbouring_diff_level, const QuadTree *my_neigh_pt, const int &direction) const
Definition: quadtree.cc:751
static Vector< int > Reflect_edge
Get opposite edge, e.g. Reflect_edge[N]=S.
Definition: quadtree.h:258
QuadTree(RefineableElement *const &object_pt)
Definition: quadtree.h:216
static DenseMatrix< int > Reflect
Definition: quadtree.h:267
static DenseMatrix< int > Rotate
Definition: quadtree.h:271
static void setup_static_data()
Setup the static data, rotation and reflection schemes, etc.
Definition: quadtree.cc:120
QuadTree(const QuadTree &dummy)=delete
Broken copy constructor.
static DenseMatrix< double > S_base
Definition: quadtree.h:250
Tree * construct_son(RefineableElement *const &object_pt, Tree *const &father_pt, const int &son_type)
Definition: quadtree.h:118
QuadTree()
Default constructor (empty and broken)
Definition: quadtree.h:203
static DenseMatrix< int > S_direct
Definition: quadtree.h:282
unsigned self_test()
Definition: quadtree.cc:814
virtual ~QuadTree()
Definition: quadtree.h:108
static Vector< std::string > Colour
Colours for neighbours in various directions.
Definition: quadtree.h:246
QuadTree * gteq_edge_neighbour(const int &direction, Vector< unsigned > &translate_s, Vector< double > &s_lo, Vector< double > &s_hi, int &edge, int &diff_level, bool &in_neighbouring_tree) const
Definition: quadtree.cc:413
static DenseMatrix< bool > Is_adjacent
Definition: quadtree.h:263
QuadTree(RefineableElement *const &object_pt, Tree *const &father_pt, const int &son_type)
Definition: quadtree.h:224
static bool Static_data_has_been_setup
Bool indicating that static member data has been setup.
Definition: quadtree.h:232
static DenseMatrix< int > Rotate_angle
Definition: quadtree.h:277
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
@ N
Definition: constructor.cpp:22
double max_error
Definition: MortaringCantileverCompareToNonMortaring.cpp:188
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
@ SE
Definition: quadtree.h:57
@ E
Definition: quadtree.h:61
@ S
Definition: quadtree.h:62
@ OMEGA
Definition: quadtree.h:64
@ NW
Definition: quadtree.h:58
@ NE
Definition: quadtree.h:59
@ W
Definition: quadtree.h:63
@ SW
Definition: quadtree.h:56
@ N
Definition: quadtree.h:60
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