31 #include <oomph-lib-config.h>
88 using namespace BinaryTreeNames;
93 std::ostringstream error_stream;
94 error_stream <<
"Inconsistent enumeration! \n Tree::OMEGA="
98 error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
176 bool& in_neighbouring_tree)
const
178 using namespace BinaryTreeNames;
181 if ((direction !=
L) && (direction !=
R))
183 std::ostringstream error_stream;
184 error_stream <<
"Direction " << direction <<
" is not L or R"
188 error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
194 in_neighbouring_tree =
false;
198 int max_level =
Level;
213 in_neighbouring_tree,
228 s_in_neighbour[0] =
S_base[edge];
258 const int& direction,
261 bool& in_neighbouring_tree,
265 using namespace BinaryTreeNames;
268 if ((direction !=
L) && (direction !=
R))
270 std::ostringstream error_stream;
271 error_stream <<
"Direction " << direction <<
" is not L or R"
275 error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
301 in_neighbouring_tree,
318 s_diff += pow(0.5, -diff_level);
331 if ((next_el_pt->
Son_pt.size() == 0) ||
332 (next_el_pt->
Level > max_level - 1))
334 return_el_pt = next_el_pt;
351 s_diff -= pow(0.5, -diff_level);
372 in_neighbouring_tree =
true;
400 unsigned long num_nodes = all_nodes_pt.size();
401 for (
unsigned long i = 0;
i < num_nodes;
i++)
403 all_nodes_pt[
i]->object_pt()->set_number(++count);
408 double max_error = 0.0;
409 std::ofstream neighbours_file;
410 std::ofstream neighbours_txt_file;
412 all_nodes_pt, neighbours_file, neighbours_txt_file, max_error);
416 oomph_info <<
"\n \n Failed self_test() for BinaryTree: Max. error "
417 << max_error << std::endl
423 oomph_info <<
"\n \n Passed self_test() for BinaryTree: Max. error "
424 << max_error << std::endl
442 LeakCheckNames::BinaryTreeForest_build += 1;
445 using namespace BinaryTreeNames;
456 using namespace BinaryTreeNames;
458 unsigned numtrees =
ntree();
462 n =
Trees_pt[0]->object_pt()->nnode_1d();
467 "Trying to setup the neighbour scheme for an empty forest\n",
468 OOMPH_CURRENT_FUNCTION,
469 OOMPH_EXCEPTION_LOCATION);
473 unsigned n_vertex_node = 2;
477 std::map<Node*, std::set<unsigned>> tree_assoc_with_vertex_node;
480 for (
unsigned i = 0;
i < numtrees;
i++)
483 for (
unsigned j = 0; j < n_vertex_node; j++)
487 tree_assoc_with_vertex_node[nod_pt].insert(
i);
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();
502 for (std::set<unsigned>::iterator it_el1 = it->second.begin();
503 it_el1 != it->second.end();
506 unsigned i = (*it_el1);
507 for (std::set<unsigned>::iterator it_el2 = it->second.begin();
508 it_el2 != it->second.end();
511 unsigned j = (*it_el2);
515 neighb_tree[
i].insert(j);
522 for (
unsigned i = 0;
i < numtrees;
i++)
525 for (std::set<unsigned>::iterator it = neighb_tree[
i].begin();
526 it != neighb_tree[
i].end();
532 bool is_L_neighbour =
Trees_pt[j]->object_pt()->get_node_number(
533 Trees_pt[
i]->object_pt()->node_pt(0)) != -1;
536 bool is_R_neighbour =
Trees_pt[j]->object_pt()->get_node_number(
537 Trees_pt[
i]->object_pt()->node_pt(n - 1)) != -1;
555 std::ofstream neigh_file;
556 std::ofstream neigh_txt_file;
561 std::ostringstream fullname;
564 oomph_info <<
"opened " << fullname.str() <<
" to doc neighbours"
566 neigh_file.open(fullname.str().c_str());
570 oomph_info <<
"opened " << fullname.str() <<
" to doc neighbours"
572 neigh_txt_file.open(fullname.str().c_str());
576 double max_error = 0.0;
578 all_tree_nodes_pt, neigh_file, neigh_txt_file, max_error);
583 std::ostringstream error_stream;
584 error_stream <<
"Max. error in binary tree neighbour finding: "
585 << max_error <<
" is too big" << std::endl;
587 <<
"i.e. bigger than Tree::max_neighbour_finding_tolerance()="
594 neigh_txt_file.close();
598 error_stream.str(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION);
602 oomph_info <<
"Max. error in binary tree neighbour finding: " << max_error
603 <<
" is OK" << std::endl;
605 <<
"i.e. less than BinaryTree::max_neighbour_finding_tolerance()="
613 neigh_txt_file.close();
631 unsigned long num_nodes = all_forest_nodes_pt.size();
632 for (
unsigned long i = 0;
i < num_nodes;
i++)
634 all_forest_nodes_pt[
i]->object_pt()->set_number(++count);
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);
646 oomph_info <<
"\n \n Failed self_test() for BinaryTree: Max. error "
647 << max_error << std::endl
653 oomph_info <<
"\n \n Passed self_test() for BinaryTree: Max. error "
654 << max_error << std::endl
669 std::ofstream& neighbours_file,
670 std::ofstream& neighbours_txt_file,
673 using namespace BinaryTreeNames;
677 bool in_neighbouring_tree;
694 unsigned long num_nodes = forest_nodes_pt.size();
695 for (
unsigned long i = 0;
i < num_nodes;
i++)
698 forest_nodes_pt[
i]->object_pt()->set_number(
i);
703 for (
unsigned long i = 0;
i < num_nodes;
i++)
712 if (neighbours_file.is_open())
715 ->output_corners(neighbours_file,
"BLACK");
720 for (
int direction =
L; direction <=
R; direction++)
728 direction, s_in_neighbour, edge, diff_level, in_neighbouring_tree);
734 if (neighbours_txt_file.is_open())
737 << Direct_string[direction] <<
" neighbour of "
740 << diff_level <<
" s_diff " << s_diff
741 <<
" inside neighbour the edge is " << Direct_string[edge]
747 if (neighbours_file.is_open())
750 ->output_corners(neighbours_file, Colour[direction]);
757 if (neighbours_file.is_open())
759 neighbours_file <<
"ZONE I=1 \n";
766 s[0] = s_in_neighbour[0];
771 s[0] = S_base[direction];
776 bool is_periodic =
false;
777 if (in_neighbouring_tree)
786 if (is_periodic ==
false)
788 error += pow(x_small[0] - x_large[0], 2);
793 if (neighbours_txt_file.is_open())
795 neighbours_txt_file <<
"Error (1) " << error << std::endl;
798 if (std::fabs(error) > max_error)
800 max_error = std::fabs(error);
803 if (neighbours_file.is_open())
805 neighbours_file << x_large[0] <<
" 0 \n";
812 s[0] = s_in_neighbour[0];
816 s[0] = S_base[direction];
821 if (is_periodic ==
false)
823 error += pow(x_small[0] - x_large[0], 2);
830 if (neighbours_txt_file.is_open())
832 neighbours_txt_file <<
"Error (2) " << error << std::endl;
835 if (std::fabs(error) > max_error)
837 max_error = std::fabs(error);
840 if (neighbours_file.is_open())
842 neighbours_file << x_large[0] <<
" 0 \n";
862 if (neighbours_file.is_open())
864 neighbours_file <<
"ZONE \n 0.00 0 \n";
865 neighbours_file <<
"ZONE I=1 \n";
866 neighbours_file <<
"-0.05 0 \n";
867 neighbours_file <<
"-0.05 0 \n";
void find_neighbours()
Construct the neighbour lookup scheme.
BinaryTreeForest()
Default constructor (empty and broken)
void check_all_neighbours(DocInfo &doc_info)
Document and check all the neighbours of all the nodes in the forest. DocInfo object specifies the ou...
unsigned self_test()
Self-test: Check all neighbours. Return success (0) if the maximum distance between corresponding poi...
BinaryTreeRoot is a BinaryTree that forms the root of a (recursive) binary tree. The "root node" is s...
BinaryTree class: Recursively defined, generalised binary tree.
static Vector< double > S_base
S_base(direction): Initial value for coordinate s on the edge indicated by direction (L/R)
static Vector< std::string > Colour
Colours for neighbours in various directions.
static Vector< std::string > Direct_string
Translate (enumerated) directions into strings.
static void setup_static_data()
Set up the static data, reflection schemes, etc.
static void doc_neighbours(Vector< Tree * > forest_nodes_pt, std::ofstream &neighbours_file, std::ofstream &neighbours_txt_file, double &max_error)
Doc/check all neighbours of binary tree (nodes) contained in the Vector forest_node_pt....
static bool Static_data_has_been_setup
Boolean indicating that static member data has been setup.
static DenseMatrix< int > Reflect
Reflection scheme: Reflect(direction,segment): Get mirror of segment in specified direction....
BinaryTree * gteq_edge_neighbour(const int &direction, Vector< double > &s_in_neighbour, int &edge, int &diff_level, bool &in_neighbouring_tree) const
Return pointer to greater or equal-sized edge neighbour in specified direction; also provide info reg...
unsigned self_test()
Self-test: Check all neighbours. Return success (0) if the maximum distance between corresponding poi...
static DenseMatrix< bool > Is_adjacent
Array of direction/segment adjacency scheme: Is_adjacent(i_vertex,j_segment): Is vertex adjacent to s...
static Vector< int > Reflect_edge
Get opposite edge, e.g. Reflect_edge[L]=R.
void resize(const unsigned long &n)
Resize to a square nxn matrix; any values already present will be transfered.
Information for documentation of results: Directory and file number to enable output in the form RESL...
bool is_doc_enabled() const
Are we documenting?
std::string directory() const
Output directory.
unsigned & number()
Number used (e.g.) for labeling output files.
void get_x(const Vector< double > &s, Vector< double > &x) const
Global coordinates as function of local coordinates. Either via FE representation or via macro-elemen...
Base class for all line elements.
Nodes are derived from Data, but, in addition, have a definite (Eulerian) position in a space of a gi...
An OomphLibError object which should be thrown when an run-time error is encountered....
long number() const
Element number (for debugging/plotting)
virtual bool nodes_built()
Return true if all the nodes have been built, false if not.
Refineable version of QElement<1,NNODE_1D>.
A TreeForest consists of a collection of TreeRoots. Each member tree can have neighbours in various e...
void stick_all_tree_nodes_into_vector(Vector< Tree * > &all_forest_nodes)
Traverse forest and stick pointers to all "nodes" into Vector.
unsigned ntree()
Number of trees in forest.
Vector< TreeRoot * > Trees_pt
Vector containing the pointers to the trees.
bool is_neighbour_periodic(const int &direction)
Return whether the neighbour in the particular direction is periodic.
TreeRoot *& neighbour_pt(const int &direction)
Return the pointer to the neighbouring TreeRoots in specified direction. Returns NULL if there's no n...
Tree * Father_pt
Pointer to the Father of the Tree.
void stick_all_tree_nodes_into_vector(Vector< Tree * > &)
Traverse and stick pointers to all "nodes" into Vector.
RefineableElement * object_pt() const
Return the pointer to the object (RefineableElement) represented by the tree.
TreeRoot * Root_pt
Pointer to the root of the tree.
int Son_type
Son type (e.g. SW/SE/NW/NE in a quadtree)
int Level
Level of the Tree (level 0 = root)
static const int OMEGA
Default value for an unassigned neighbour.
Vector< Tree * > Son_pt
Vector of pointers to the sons of the Tree.
TreeRoot *& root_pt()
Return pointer to root of the tree.
static double Max_neighbour_finding_tolerance
Max. allowed discrepancy in neighbour finding routine (distance between points when identified from t...
static double & max_neighbour_finding_tolerance()
Max. allowed discrepancy in neighbour finding routine (distance between points when identified from t...
//////////////////////////////////////////////////////////////////// ////////////////////////////////...
OomphInfo oomph_info
Single (global) instantiation of the OomphInfo object – this is used throughout the library as a "rep...