oomph::BinaryTreeForest Class Reference

#include <binary_tree.h>

+ Inheritance diagram for oomph::BinaryTreeForest:

Public Member Functions

 BinaryTreeForest ()
 Default constructor (empty and broken) More...
 
 BinaryTreeForest (Vector< TreeRoot * > &trees_pt)
 
 BinaryTreeForest (const BinaryTreeForest &dummy)=delete
 Broken copy constructor. More...
 
void operator= (const BinaryTreeForest &)=delete
 Broken assignment operator. More...
 
virtual ~BinaryTreeForest ()
 
void check_all_neighbours (DocInfo &doc_info)
 Document and check all the neighbours in all the nodes in the forest. More...
 
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. More...
 
unsigned self_test ()
 
- Public Member Functions inherited from oomph::TreeForest
 TreeForest (Vector< TreeRoot * > &trees_pt)
 
 TreeForest ()
 Default constructor (empty and broken) More...
 
 TreeForest (const TreeForest &dummy)=delete
 Broken copy constructor. More...
 
void operator= (const TreeForest &)=delete
 Broken assignment operator. More...
 
virtual ~TreeForest ()
 Kill tree forest: Delete the constituent trees. More...
 
void stick_leaves_into_vector (Vector< Tree * > &forest_nodes)
 Traverse forst and stick pointers to leaf "nodes" into Vector. More...
 
void stick_all_tree_nodes_into_vector (Vector< Tree * > &all_forest_nodes)
 Traverse forest and stick pointers to all "nodes" into Vector. More...
 
void close_hanging_node_files (DocInfo &doc_info, Vector< std::ofstream * > &output_stream)
 
unsigned ntree ()
 Number of trees in forest. More...
 
TreeRoottree_pt (const unsigned &i) const
 Return pointer to i-th tree in forest. More...
 
void flush_trees ()
 Flush trees from forest. More...
 

Private Member Functions

void find_neighbours ()
 Construct the neighbour lookup scheme. More...
 
BinaryTreeRootbinary_tree_pt (const unsigned &i)
 
BinaryTreeRootbinary_neigh_pt (const unsigned &i, const int &direction)
 

Additional Inherited Members

- Protected Attributes inherited from oomph::TreeForest
Vector< TreeRoot * > Trees_pt
 Vector containing the pointers to the trees. More...
 

Detailed Description

A BinaryTreeForest consists of a collection of BinaryTreeRoots. Each member tree can have neighbours to its left and right.

Constructor & Destructor Documentation

◆ BinaryTreeForest() [1/3]

oomph::BinaryTreeForest::BinaryTreeForest ( )
inline

Default constructor (empty and broken)

290  {
291  // Throw an error
292  throw OomphLibError(
293  "Don't call an empty constructor for a BinaryTreeForest object",
296  }
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References OOMPH_CURRENT_FUNCTION, and OOMPH_EXCEPTION_LOCATION.

◆ BinaryTreeForest() [2/3]

oomph::BinaryTreeForest::BinaryTreeForest ( Vector< TreeRoot * > &  trees_pt)

Constructor: Pass vector of pointers to the roots of the constituent BinaryTrees

Constructor for BinaryTreeForest:

Pass:

  • trees_pt[], the Vector of pointers to the constituent trees (BinaryTreeRoot objects)
439  : TreeForest(trees_pt)
440  {
441 #ifdef LEAK_CHECK
442  LeakCheckNames::BinaryTreeForest_build += 1;
443 #endif
444 
445  using namespace BinaryTreeNames;
446 
447  // Set up the neighbours
448  find_neighbours();
449  }
void find_neighbours()
Construct the neighbour lookup scheme.
Definition: binary_tree.cc:454
TreeForest()
Default constructor (empty and broken)
Definition: tree.h:416

References find_neighbours().

◆ BinaryTreeForest() [3/3]

oomph::BinaryTreeForest::BinaryTreeForest ( const BinaryTreeForest dummy)
delete

Broken copy constructor.

◆ ~BinaryTreeForest()

virtual oomph::BinaryTreeForest::~BinaryTreeForest ( )
inlinevirtual

Destructor: Delete the constituent binary trees (and thus the objects associated with its non-leaf nodes!)

310 {}

Member Function Documentation

◆ binary_neigh_pt()

BinaryTreeRoot* oomph::BinaryTreeForest::binary_neigh_pt ( const unsigned i,
const int direction 
)
inlineprivate

Given the number i of the root binary tree in this forest, return a pointer to its neighbour in the specified direction. NULL if neighbour doesn't exist. (This does the dynamic cast from a TreeRoot to a BinaryTreeRoot internally).

346  {
347  return dynamic_cast<BinaryTreeRoot*>(
348  Trees_pt[i]->neighbour_pt(direction));
349  }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Vector< TreeRoot * > Trees_pt
Vector containing the pointers to the trees.
Definition: tree.h:480

References i.

◆ binary_tree_pt()

BinaryTreeRoot* oomph::BinaryTreeForest::binary_tree_pt ( const unsigned i)
inlineprivate

Return pointer to i-th root binary tree in this forest (performs a dynamic cast from the TreeRoot to a BinaryTreeRoot).

337  {
338  return dynamic_cast<BinaryTreeRoot*>(Trees_pt[i]);
339  }

References i.

◆ check_all_neighbours()

void oomph::BinaryTreeForest::check_all_neighbours ( DocInfo doc_info)
virtual

Document and check all the neighbours in all the nodes in the forest.

Document and check all the neighbours of all the nodes in the forest. DocInfo object specifies the output directory and file numbers for the various files. If doc_info.disable_doc() has been called, no output is created.

Implements oomph::TreeForest.

549  {
550  // Create Vector of elements
551  Vector<Tree*> all_tree_nodes_pt;
552  this->stick_all_tree_nodes_into_vector(all_tree_nodes_pt);
553 
554  // Create storage for information files
555  std::ofstream neigh_file;
556  std::ofstream neigh_txt_file;
557 
558  // If we are documenting the results, then open the files
559  if (doc_info.is_doc_enabled())
560  {
561  std::ostringstream fullname;
562  fullname << doc_info.directory() << "/neighbours" << doc_info.number()
563  << ".dat";
564  oomph_info << "opened " << fullname.str() << " to doc neighbours"
565  << std::endl;
566  neigh_file.open(fullname.str().c_str());
567  fullname.str("");
568  fullname << doc_info.directory() << "/neighbours" << doc_info.number()
569  << ".txt";
570  oomph_info << "opened " << fullname.str() << " to doc neighbours"
571  << std::endl;
572  neigh_txt_file.open(fullname.str().c_str());
573  }
574 
575  // Call the standard documentation function
576  double max_error = 0.0;
578  all_tree_nodes_pt, neigh_file, neigh_txt_file, max_error);
579 
580  // If the error is too large, complain
582  {
583  std::ostringstream error_stream;
584  error_stream << "Max. error in binary tree neighbour finding: "
585  << max_error << " is too big" << std::endl;
586  error_stream
587  << "i.e. bigger than Tree::max_neighbour_finding_tolerance()="
588  << Tree::max_neighbour_finding_tolerance() << std::endl;
589 
590  // Close the files if they were opened
591  if (doc_info.is_doc_enabled())
592  {
593  neigh_file.close();
594  neigh_txt_file.close();
595  }
596 
597  throw OomphLibError(
598  error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
599  }
600  else
601  {
602  oomph_info << "Max. error in binary tree neighbour finding: " << max_error
603  << " is OK" << std::endl;
604  oomph_info
605  << "i.e. less than BinaryTree::max_neighbour_finding_tolerance()="
607  }
608 
609  // Close the files if they were opened
610  if (doc_info.is_doc_enabled())
611  {
612  neigh_file.close();
613  neigh_txt_file.close();
614  }
615  }
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
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
static double & max_neighbour_finding_tolerance()
Definition: tree.h:255
double max_error
Definition: MortaringCantileverCompareToNonMortaring.cpp:188
OomphInfo oomph_info
Definition: oomph_definitions.cc:319

References oomph::DocInfo::directory(), oomph::BinaryTree::doc_neighbours(), oomph::DocInfo::is_doc_enabled(), MeshRefinement::max_error, oomph::Tree::max_neighbour_finding_tolerance(), oomph::DocInfo::number(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::oomph_info, and oomph::TreeForest::stick_all_tree_nodes_into_vector().

◆ find_neighbours()

void oomph::BinaryTreeForest::find_neighbours ( )
private

Construct the neighbour lookup scheme.

Set up the neighbour lookup schemes for all constituent binary trees.

455  {
456  using namespace BinaryTreeNames;
457 
458  unsigned numtrees = ntree();
459  unsigned n = 0; // to store nnode1d
460  if (numtrees > 0)
461  {
462  n = Trees_pt[0]->object_pt()->nnode_1d();
463  }
464  else
465  {
466  throw OomphLibError(
467  "Trying to setup the neighbour scheme for an empty forest\n",
470  }
471 
472  // Number of vertex nodes: 2
473  unsigned n_vertex_node = 2;
474 
475  // Find connected trees by identifying those whose associated elements
476  // share a common vertex node
477  std::map<Node*, std::set<unsigned>> tree_assoc_with_vertex_node;
478 
479  // Loop over all trees
480  for (unsigned i = 0; i < numtrees; i++)
481  {
482  // Loop over the vertex nodes of the associated element
483  for (unsigned j = 0; j < n_vertex_node; j++)
484  {
485  Node* nod_pt = dynamic_cast<LineElementBase*>(Trees_pt[i]->object_pt())
486  ->vertex_node_pt(j);
487  tree_assoc_with_vertex_node[nod_pt].insert(i);
488  }
489  }
490 
491  // For each tree we store a set of neighbouring trees
492  // i.e. trees that share a node
493  Vector<std::set<unsigned>> neighb_tree(numtrees);
494 
495  // Loop over vertex nodes
496  for (std::map<Node*, std::set<unsigned>>::iterator it =
497  tree_assoc_with_vertex_node.begin();
498  it != tree_assoc_with_vertex_node.end();
499  it++)
500  {
501  // Loop over connected elements twice
502  for (std::set<unsigned>::iterator it_el1 = it->second.begin();
503  it_el1 != it->second.end();
504  it_el1++)
505  {
506  unsigned i = (*it_el1);
507  for (std::set<unsigned>::iterator it_el2 = it->second.begin();
508  it_el2 != it->second.end();
509  it_el2++)
510  {
511  unsigned j = (*it_el2);
512  // These two elements are connected
513  if (i != j)
514  {
515  neighb_tree[i].insert(j);
516  }
517  }
518  }
519  }
520 
521  // Loop over all trees
522  for (unsigned i = 0; i < numtrees; i++)
523  {
524  // Loop over their neighbours
525  for (std::set<unsigned>::iterator it = neighb_tree[i].begin();
526  it != neighb_tree[i].end();
527  it++)
528  {
529  unsigned j = (*it);
530 
531  // is it the left-hand neighbour?
532  bool is_L_neighbour = Trees_pt[j]->object_pt()->get_node_number(
533  Trees_pt[i]->object_pt()->node_pt(0)) != -1;
534 
535  // is it the right-hand neighbour?
536  bool is_R_neighbour = Trees_pt[j]->object_pt()->get_node_number(
537  Trees_pt[i]->object_pt()->node_pt(n - 1)) != -1;
538 
539  if (is_L_neighbour) Trees_pt[i]->neighbour_pt(L) = Trees_pt[j];
540  if (is_R_neighbour) Trees_pt[i]->neighbour_pt(R) = Trees_pt[j];
541  }
542  } // End of loop over all trees
543  }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
MatrixXd L
Definition: LLT_example.cpp:6
@ R
Definition: StatisticsVector.h:21
unsigned ntree()
Number of trees in forest.
Definition: tree.h:460
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References i, j, L, n, oomph::TreeForest::ntree(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, R, and oomph::TreeForest::Trees_pt.

Referenced by BinaryTreeForest().

◆ open_hanging_node_files()

void oomph::BinaryTreeForest::open_hanging_node_files ( DocInfo doc_info,
Vector< std::ofstream * > &  output_stream 
)
inlinevirtual

A line mesh cannot have hanging nodes so make this function empty.

Implements oomph::TreeForest.

321  {
322  }

◆ operator=()

void oomph::BinaryTreeForest::operator= ( const BinaryTreeForest )
delete

Broken assignment operator.

◆ self_test()

unsigned oomph::BinaryTreeForest::self_test ( )

Self-test: Check all neighbours. Return success (0) if the maximum distance between corresponding points in the neighbours is less than the tolerance specified in the static value BinaryTree::Max_neighbour_finding_tolerance.

Self test: Check neighbour finding routine. For each element in the tree and for each vertex, determine the distance between the vertex and its position in the neighbour. If the difference is less than Tree::Max_neighbour_finding_tolerance return success (0), otherwise failure (1).

625  {
626  // Stick pointers to all nodes into Vector and number elements
627  // in the process
628  Vector<Tree*> all_forest_nodes_pt;
629  stick_all_tree_nodes_into_vector(all_forest_nodes_pt);
630  long int count = 0;
631  unsigned long num_nodes = all_forest_nodes_pt.size();
632  for (unsigned long i = 0; i < num_nodes; i++)
633  {
634  all_forest_nodes_pt[i]->object_pt()->set_number(++count);
635  }
636 
637  // Check neighbours (distance between hanging nodes) -- don't print
638  // (keep output streams closed)
639  double max_error = 0.0;
640  std::ofstream neighbours_file;
641  std::ofstream neighbours_txt_file;
643  all_forest_nodes_pt, neighbours_file, neighbours_txt_file, max_error);
645  {
646  oomph_info << "\n \n Failed self_test() for BinaryTree: Max. error "
647  << max_error << std::endl
648  << std::endl;
649  return 1;
650  }
651  else
652  {
653  oomph_info << "\n \n Passed self_test() for BinaryTree: Max. error "
654  << max_error << std::endl
655  << std::endl;
656  return 0;
657  }
658  }

References oomph::BinaryTree::doc_neighbours(), i, MeshRefinement::max_error, oomph::Tree::max_neighbour_finding_tolerance(), oomph::oomph_info, and oomph::TreeForest::stick_all_tree_nodes_into_vector().


The documentation for this class was generated from the following files: