35 #include <oomph-lib-config.h> 92 using namespace BinaryTreeNames;
97 std::ostringstream error_stream;
99 <<
"Inconsistent enumeration! \n Tree::OMEGA=" <<
Tree::OMEGA 103 OOMPH_CURRENT_FUNCTION,
104 OOMPH_EXCEPTION_LOCATION);
181 int& edge,
int& diff_level,
182 bool &in_neighbouring_tree)
const 184 using namespace BinaryTreeNames;
187 if ((direction!=
L)&&(direction!=
R))
189 std::ostringstream error_stream;
190 error_stream <<
"Direction " << direction
191 <<
" is not L or R" << std::endl;
194 OOMPH_CURRENT_FUNCTION,
195 OOMPH_EXCEPTION_LOCATION);
201 in_neighbouring_tree =
false;
205 int max_level =
Level;
218 in_neighbouring_tree,
219 max_level,orig_root_pt);
232 s_in_neighbour[0] =
S_base[edge];
262 const int& direction,
265 bool &in_neighbouring_tree,
269 using namespace BinaryTreeNames;
272 if ((direction!=
L)&&(direction!=
R))
274 std::ostringstream error_stream;
275 error_stream <<
"Direction " << direction
276 <<
" is not L or R" << std::endl;
279 OOMPH_CURRENT_FUNCTION,
280 OOMPH_EXCEPTION_LOCATION);
304 in_neighbouring_tree,
305 max_level,orig_root_pt);
320 s_diff += pow(0.5,-diff_level);
333 if((next_el_pt->Son_pt.size()==0)||(next_el_pt->Level>max_level-1))
335 return_el_pt = next_el_pt;
348 =
dynamic_cast<BinaryTree*
>(next_el_pt->Son_pt[son_segment]);
352 s_diff -= pow(0.5,-diff_level);
373 in_neighbouring_tree =
true;
401 unsigned long num_nodes=all_nodes_pt.size();
402 for (
unsigned long i=0;
i<num_nodes;
i++)
404 all_nodes_pt[
i]->object_pt()->set_number(++count);
409 double max_error=0.0;
410 std::ofstream neighbours_file;
411 std::ofstream neighbours_txt_file;
413 neighbours_txt_file, max_error);
417 oomph_info <<
"\n \n Failed self_test() for BinaryTree: Max. error " 418 << max_error << std::endl<< std::endl;
423 oomph_info <<
"\n \n Passed self_test() for BinaryTree: Max. error " 424 << max_error << std::endl<< std::endl;
443 LeakCheckNames::BinaryTreeForest_build+=1;
446 using namespace BinaryTreeNames;
457 using namespace BinaryTreeNames;
459 unsigned numtrees =
ntree();
463 n=
Trees_pt[0]->object_pt()->nnode_1d();
468 "Trying to setup the neighbour scheme for an empty forest\n",
469 OOMPH_CURRENT_FUNCTION,
470 OOMPH_EXCEPTION_LOCATION);
474 unsigned n_vertex_node = 2;
478 std::map<Node*,std::set<unsigned> > tree_assoc_with_vertex_node;
481 for(
unsigned i=0;
i<numtrees;
i++)
484 for (
unsigned j=0;j<n_vertex_node;j++)
487 (
Trees_pt[
i]->object_pt())->vertex_node_pt(j);
488 tree_assoc_with_vertex_node[nod_pt].insert(
i);
497 for (std::map<
Node*,std::set<unsigned> >::iterator it=
498 tree_assoc_with_vertex_node.begin();
499 it!=tree_assoc_with_vertex_node.end();it++)
502 for (std::set<unsigned>::iterator it_el1=it->second.begin();
503 it_el1!=it->second.end();it_el1++)
505 unsigned i=(*it_el1);
506 for (std::set<unsigned>::iterator it_el2=it->second.begin();
507 it_el2!=it->second.end();it_el2++)
509 unsigned j=(*it_el2);
513 neighb_tree[
i].insert(j);
520 for(
unsigned i=0;
i<numtrees;
i++)
523 for(std::set<unsigned>::iterator it=neighb_tree[
i].begin();
524 it!=neighb_tree[
i].end();it++)
530 Trees_pt[j]->object_pt()->get_node_number(
531 Trees_pt[
i]->object_pt()->node_pt(0))!=-1;
535 Trees_pt[j]->object_pt()->get_node_number(
536 Trees_pt[
i]->object_pt()->node_pt(n-1))!=-1;
554 std::ofstream neigh_file;
555 std::ofstream neigh_txt_file;
560 std::ostringstream fullname;
561 fullname << doc_info.
directory() <<
"/neighbours" 562 << doc_info.
number() <<
".dat";
563 oomph_info <<
"opened " << fullname.str() <<
" to doc neighbours" 565 neigh_file.open(fullname.str().c_str());
567 fullname << doc_info.
directory() <<
"/neighbours" 568 << doc_info.
number() <<
".txt";
569 oomph_info <<
"opened " << fullname.str() <<
" to doc neighbours" 571 neigh_txt_file.open(fullname.str().c_str());
575 double max_error=0.0;
577 neigh_txt_file,max_error);
582 std::ostringstream error_stream;
583 error_stream <<
"Max. error in binary tree neighbour finding: " 584 << max_error <<
" is too big" << std::endl;
586 <<
"i.e. bigger than Tree::max_neighbour_finding_tolerance()=" 593 neigh_txt_file.close();
597 OOMPH_CURRENT_FUNCTION,
598 OOMPH_EXCEPTION_LOCATION);
602 oomph_info <<
"Max. error in binary tree neighbour finding: " 603 << max_error <<
" 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 neighbours_txt_file, max_error);
646 oomph_info <<
"\n \n Failed self_test() for BinaryTree: Max. error " 647 << max_error << std::endl<< std::endl;
652 oomph_info <<
"\n \n Passed self_test() for BinaryTree: Max. error " 653 << max_error << std::endl<< std::endl;
667 std::ofstream& neighbours_file,
668 std::ofstream& neighbours_txt_file,
671 using namespace BinaryTreeNames;
675 bool in_neighbouring_tree;
692 unsigned long num_nodes=forest_nodes_pt.size();
693 for(
unsigned long i=0;
i<num_nodes;
i++)
696 forest_nodes_pt[
i]->object_pt()->set_number(
i);
701 for(
unsigned long i=0;
i<num_nodes;
i++)
711 if (neighbours_file.is_open())
714 ->
object_pt())->output_corners(neighbours_file,
"BLACK");
719 for (
int direction=
L;direction<=
R;direction++)
729 in_neighbouring_tree);
735 if(neighbours_txt_file.is_open())
737 neighbours_txt_file << Direct_string[direction]
738 <<
" neighbour of " <<
741 <<
" diff_level " << diff_level
742 <<
" s_diff " << s_diff
743 <<
" inside neighbour the edge is " 744 << Direct_string[edge] << std::endl
749 if(neighbours_file.is_open())
752 output_corners(neighbours_file,Colour[direction]);
759 if(neighbours_file.is_open())
761 neighbours_file <<
"ZONE I=1 \n";
768 s[0] = s_in_neighbour[0];
773 s[0] = S_base[direction];
778 bool is_periodic =
false;
779 if(in_neighbouring_tree)
787 if(is_periodic==
false)
789 error += pow(x_small[0]-x_large[0],2);
794 if(neighbours_txt_file.is_open())
796 neighbours_txt_file <<
"Error (1) " << error << std::endl;
799 if(std::fabs(error)>max_error)
801 max_error=std::fabs(error);
804 if(neighbours_file.is_open())
806 neighbours_file << x_large[0] <<
" 0 \n";
813 s[0] = s_in_neighbour[0];
817 s[0] = S_base[direction];
822 if(is_periodic==
false)
824 error += pow(x_small[0]-x_large[0],2);
831 if(neighbours_txt_file.is_open())
833 neighbours_txt_file <<
"Error (2) " << error << std::endl;
836 if(std::fabs(error)>max_error)
838 max_error=std::fabs(error);
841 if(neighbours_file.is_open())
843 neighbours_file << x_large[0] <<
" 0 \n";
863 if (neighbours_file.is_open())
865 neighbours_file <<
"ZONE \n 0.00 0 \n";
866 neighbours_file <<
"ZONE I=1 \n";
867 neighbours_file <<
"-0.05 0 \n";
868 neighbours_file <<
"-0.05 0 \n";
Vector< TreeRoot * > Trees_pt
Vector containing the pointers to the trees.
static double & max_neighbour_finding_tolerance()
Max. allowed discrepancy in neighbour finding routine (distance between points when identified from t...
unsigned ntree()
Number of trees in forest.
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.
TreeRoot *& neighbour_pt(const int &direction)
Return the pointer to the neighbouring TreeRoots in specified direction. Returns NULL if there's no n...
bool is_doc_enabled() const
Are we documenting?
static bool Static_data_has_been_setup
Boolean indicating that static member data has been setup.
Information for documentation of results: Directory and file number to enable output in the form RESL...
void find_neighbours()
Construct the neighbour lookup scheme.
std::string directory() const
Output directory.
bool is_neighbour_periodic(const int &direction)
Return whether the neighbour in the particular direction is periodic.
static Vector< std::string > Direct_string
Translate (enumerated) directions into strings.
void stick_all_tree_nodes_into_vector(Vector< Tree * > &all_forest_nodes)
Traverse forest and stick pointers to all "nodes" into Vector.
static double Max_neighbour_finding_tolerance
Max. allowed discrepancy in neighbour finding routine (distance between points when identified from t...
Nodes are derived from Data, but, in addition, have a definite (Eulerian) position in a space of a gi...
TreeRoot * Root_pt
Pointer to the root of the tree.
unsigned & number()
Number used (e.g.) for labeling output files.
static void setup_static_data()
Set up the static data, reflection schemes, etc.
static DenseMatrix< int > Reflect
Reflection scheme: Reflect(direction,segment): Get mirror of segment in specified direction...
long number() const
Element number (for debugging/plotting)
static Vector< std::string > Colour
Colours for neighbours in various directions.
int Level
Level of the Tree (level 0 = root)
static DenseMatrix< bool > Is_adjacent
Array of direction/segment adjacency scheme: Is_adjacent(i_vertex,j_segment): Is vertex adjacent to s...
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...
BinaryTreeForest()
Default constructor (empty and broken)
static Vector< int > Reflect_edge
Get opposite edge, e.g. Reflect_edge[L]=R.
static Vector< double > S_base
S_base(direction): Initial value for coordinate s on the edge indicated by direction (L/R) ...
Tree * Father_pt
Pointer to the Father of the Tree.
virtual bool nodes_built()
Return true if all the nodes have been built, false if not.
static const int OMEGA
Default value for an unassigned neighbour.
void stick_all_tree_nodes_into_vector(Vector< Tree * > &)
Traverse and stick pointers to all "nodes" into Vector.
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...
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. Output into neighbours_file which can be viewed from tecplot with BinaryTreeNeighbours.mcr. Neighbour info and errors are displayed on neighbours_txt_file. Finally, compute the maximum error between vertices when viewed from the neighbouring element. If the two filestreams are closed, output is suppressed.
RefineableElement * object_pt() const
Return the pointer to the object (RefineableElement) represented by the tree.
unsigned self_test()
Self-test: Check all neighbours. Return success (0) if the maximum distance between corresponding poi...
int Son_type
Son type (e.g. SW/SE/NW/NE in a quadtree)
TreeRoot *& root_pt()
Return pointer to root of the tree.
void resize(const unsigned long &n)