30 #ifndef SAMPLE_POINT_CONTAINER_HEADER 31 #define SAMPLE_POINT_CONTAINER_HEADER 36 #include <CGAL/Cartesian_d.h> 37 #include <CGAL/Search_traits_d.h> 38 #include<CGAL/Search_traits_adapter.h> 39 #include<boost/iterator/zip_iterator.hpp> 40 #include<CGAL/Orthogonal_k_neighbor_search.h> 121 const unsigned& bin_index_in_bin_array)
122 : Sample_point_pt(0),
124 Bin_array_pt(bin_array_pt),
125 Bin_index_in_bin_array(bin_index_in_bin_array)
145 unsigned total_number_of_sample_points_computed_recursively()
const;
148 void add_sample_point(
SamplePoint* new_sample_point_pt,
149 const Vector<double>& zeta_coordinates);
154 void locate_zeta(
const Vector<double>& zeta,
155 GeomObject*& sub_geom_object_pt,
159 void output(std::ofstream& outfile,
const bool& don_t_recurse=
false);
162 void output_bins(std::ofstream& outfile);
165 void output_bin_vertices(std::ofstream& outfile);
170 if (Sample_point_pt==0)
176 return Sample_point_pt->size();
202 void make_sub_bin_array(
const Vector<std::pair<double, double> >&
203 min_and_max_coordinates);
207 void get_bin_boundaries(Vector<std::pair<double, double> >&
208 min_and_max_coordinates);
231 const Vector<std::pair<double, double> >& min_and_max_coordinates,
232 const bool& use_eulerian_coordinates_during_setup,
233 const bool& ignore_halo_elements_during_locate_zeta_search,
234 const unsigned& nsample_points_generated_per_element) :
236 Min_and_max_coordinates(min_and_max_coordinates),
237 Use_eulerian_coordinates_during_setup(use_eulerian_coordinates_during_setup),
239 Ignore_halo_elements_during_locate_zeta_search(
240 ignore_halo_elements_during_locate_zeta_search),
242 Nsample_points_generated_per_element(nsample_points_generated_per_element),
243 Total_number_of_sample_points_visited_during_locate_zeta_from_top_level(0)
246 Max_search_radius = DBL_MAX;
254 throw OomphLibError(
"Broken default constructor. Don't call this!",
255 OOMPH_CURRENT_FUNCTION,
256 OOMPH_EXCEPTION_LOCATION);
273 virtual void locate_zeta(
const Vector<double>& zeta,
274 GeomObject*& sub_geom_object_pt,
275 Vector<double>&
s)=0;
284 Total_number_of_sample_points_visited_during_locate_zeta_from_top_level;
289 virtual unsigned total_number_of_sample_points_computed_recursively()
const =0;
292 virtual unsigned ndim_zeta()
const = 0;
303 const unsigned&
i)
const 305 return Min_and_max_coordinates[
i];
312 return Min_and_max_coordinates;
321 return Ignore_halo_elements_during_locate_zeta_search;
330 return Use_eulerian_coordinates_during_setup;
336 return Nsample_points_generated_per_element;
349 return Max_search_radius;
375 void setup_min_and_max_coordinates();
430 const Vector<std::pair<double, double> >& min_and_max_coordinates,
431 const Vector<unsigned>& dimensions_of_bin_array,
432 const bool& use_eulerian_coordinates_during_setup,
433 const bool& ignore_halo_elements_during_locate_zeta_search,
434 const unsigned& nsample_points_generated_per_element) :
436 min_and_max_coordinates,
437 use_eulerian_coordinates_during_setup,
438 ignore_halo_elements_during_locate_zeta_search,
439 nsample_points_generated_per_element),
440 Dimensions_of_bin_array(dimensions_of_bin_array)
452 throw OomphLibError(
"Broken default constructor. Don't call this!",
453 OOMPH_CURRENT_FUNCTION,
454 OOMPH_EXCEPTION_LOCATION);
471 void get_neighbouring_bins_helper(
const unsigned& bin_index,
472 const unsigned& radius,
473 Vector<unsigned>& neighbouring_bin_index,
474 const bool& use_old_version=
true);
478 void profile_get_neighbouring_bins_helper();
483 unsigned coords_to_bin_index(
const Vector<double>& zeta);
487 void coords_to_vectorial_bin_index(
const Vector<double>& zeta,
488 Vector<unsigned>& bin_index);
491 virtual void output_bins(std::ofstream& outfile)=0;
494 virtual void output_bin_vertices(std::ofstream& outfile)=0;
498 virtual unsigned nbin()
const=0;
501 unsigned max_bin_dimension()
const;
506 return Dimensions_of_bin_array.size();
512 return Dimensions_of_bin_array[
i];
520 return Dimensions_of_bin_array;
527 return Dimensions_of_bin_array[
i];
569 unsigned n=Bin_pt.size();
570 for (
unsigned i=0;
i<n;
i++)
583 return Root_bin_array_pt;
595 return Bin_pt.size();
605 unsigned total_number_of_sample_points_computed_recursively()
const;
610 unsigned n_dim=ndim_zeta();
612 unsigned n=sample_point_pt.size();
613 for (
unsigned i = 0;
i < n;
i++)
616 Vector<double> zeta(n_dim);
619 unsigned e=sample_point_pt[
i]->element_index_in_mesh();
620 FiniteElement* el_pt=Mesh_pt->finite_element_pt(e);
623 unsigned j=sample_point_pt[
i]->sample_point_index_in_element();
624 Vector<double>
s(n_dim);
625 bool use_equally_spaced_interior_sample_points=
627 el_pt->get_s_plot(j,Nsample_points_generated_per_element,s,
628 use_equally_spaced_interior_sample_points);
629 if (Use_eulerian_coordinates_during_setup)
631 el_pt->interpolated_x(s,zeta);
635 el_pt->interpolated_zeta(s,zeta);
639 add_sample_point(sample_point_pt[
i],zeta);
645 const Vector<double>& zeta)
648 unsigned bin_index = coords_to_bin_index(zeta);
651 if (Bin_pt[bin_index] == 0)
656 Bin_pt[bin_index]->add_sample_point(new_sample_point_pt,zeta);
662 void locate_zeta(
const Vector<double>& zeta,
663 GeomObject*& sub_geom_object_pt,
668 void get_bin_boundaries(
const unsigned& bin_index,
669 Vector<std::pair<double, double> >&
670 min_and_max_coordinates);
693 return Bin_array_is_recursive;
700 return Max_number_of_sample_point_per_bin;
707 unsigned n_bin=Bin_pt.size();
708 for (
unsigned i=0;
i<n_bin;
i++)
712 Bin_pt[
i]->output(outfile);
718 void output_bin_vertices(std::ofstream& outfile);
721 void output_neighbouring_bins(
const unsigned& bin_index,
722 const unsigned& radius,
723 std::ofstream& outfile);
733 Total_number_of_sample_points_visited_during_locate_zeta_from_top_level;
737 return Root_bin_array_pt->
738 total_number_of_sample_points_visited_during_locate_zeta_from_top_level();
747 return First_sample_point_to_actually_lookup_during_locate_zeta;
755 return Last_sample_point_to_actually_lookup_during_locate_zeta;
767 return Multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta;
776 return Initial_last_sample_point_to_actually_lookup_during_locate_zeta;
783 void fill_bin_array();
788 void create_sample_points_from_element(FiniteElement*
const element_pt,
789 const unsigned& n_element);
863 bin_array_parameters_pt);
868 flush_bins_of_objects();
886 void locate_zeta(
const Vector<double>& zeta,
887 GeomObject*& sub_geom_object_pt,
893 const unsigned n_lagrangian = ndim_zeta();
894 unsigned ntotalbin = Dimensions_of_bin_array[0];
895 for(
unsigned i=1;
i<n_lagrangian;
i++)
897 ntotalbin *= Dimensions_of_bin_array[
i];
909 unsigned total_number_of_sample_points_computed_recursively()
const;
914 return Nspiral_chunk;
920 return Nspiral_chunk;
934 void get_fill_stats(
unsigned& n_bin,
935 unsigned& max_n_entry,
936 unsigned& min_n_entry,
937 unsigned& tot_n_entry,
938 unsigned& n_empty)
const;
942 double min_distance(
const unsigned& i_bin,
943 const Vector<double>& zeta);
946 void output_bin_vertices(std::ofstream& outfile);
951 void get_bin_vertices(
const unsigned& i_bin,
952 Vector<Vector<double> >& bin_vertex);
957 void get_bin(
const Vector<double>& zeta,
int& bin_number);
962 void get_bin(
const Vector<double>& zeta,
int& bin_number,
963 Vector<std::pair<FiniteElement*,
964 Vector<double> > >& sample_point_pairs);
967 Vector<Vector<std::pair<FiniteElement*,Vector<double> > > >
bin_content()
const 969 Vector<Vector<std::pair<FiniteElement*, Vector<double> > > > all_vals;
970 Bin_object_coord_pairs.get_all_values(all_vals);
975 const std::map<unsigned, Vector<std::pair<FiniteElement*, Vector<double> > > >*
979 return Bin_object_coord_pairs.map_pt();
985 void fill_bin_by_diffusion(
const unsigned& bin_diffusion_radius = 1);
990 void output_bins(std::ofstream& outfile);
995 std::ofstream outfile;
996 outfile.open(filename.c_str());
997 output_bins(outfile);
1034 void fill_bin_array();
1039 void create_bins_of_objects();
1045 Total_nbin_cells_counter -= Bin_object_coord_pairs.nnz();
1046 Bin_object_coord_pairs.clear();
1050 SparseVector<Vector<std::pair<FiniteElement*, Vector<double> > > >
1073 #ifdef OOMPH_HAS_CGAL 1086 sample_point_container_parameters_pt);
1103 unsigned n=Sample_point_pt.size();
1104 for (
unsigned i=0;
i<n;
i++)
1106 delete Sample_point_pt[
i];
1107 Sample_point_pt[
i]=0;
1109 delete CGAL_tree_d_pt;
1117 return First_sample_point_to_actually_lookup_during_locate_zeta;
1124 return Last_sample_point_to_actually_lookup_during_locate_zeta;
1137 return Multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta;
1145 return Initial_last_sample_point_to_actually_lookup_during_locate_zeta;
1152 void locate_zeta(
const Vector<double>& zeta,
1153 GeomObject*& sub_geom_object_pt,
1161 void limited_locate_zeta(
1162 const Vector<double>& zeta,
1163 const unsigned& max_sample_points_for_newton_based_search,
1164 GeomObject*& sub_geom_object_pt,
1175 unsigned total_number_of_sample_points_computed_recursively()
const;
1180 double get_sample_points();
1190 typedef CGAL::Search_traits_adapter<Point_d_and_pointer,
1191 CGAL::Nth_of_tuple_property_map<0, Point_d_and_pointer>,
1230 #endif // endif oomph has cgal void operator=(const NonRefineableBinArray &)
Broken assignment operator.
Class for containing sample points: Number of finite element in its mesh and index of sample point wi...
unsigned Total_number_of_sample_points_visited_during_locate_zeta_from_top_level
Counter to keep track of how many sample points we've visited during top level call to locate_zeta...
void fill_bin_array(const Vector< SamplePoint *> &sample_point_pt)
Fill the bin array with specified SamplePoints.
BinArray(Mesh *mesh_pt, const Vector< std::pair< double, double > > &min_and_max_coordinates, const Vector< unsigned > &dimensions_of_bin_array, const bool &use_eulerian_coordinates_during_setup, const bool &ignore_halo_elements_during_locate_zeta_search, const unsigned &nsample_points_generated_per_element)
Constructor.
K_neighbor_search_d::Tree * CGAL_tree_d_pt
Pointer to tree-based representation of sample points.
void broken_copy(const std::string &class_name)
Issue error message and terminate execution.
unsigned Max_spiral_level
Max. spiralling level (for efficiency; effect similar to max_search_radius)
unsigned & last_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points recursively from the top level RefineableBinArray (in determinis...
SamplePoint(const SamplePoint &data)
Broken copy constructor.
CGAL::Orthogonal_k_neighbor_search< Traits_d > K_neighbor_search_d
Vector< SamplePoint * > * Sample_point_pt
Container of SamplePoints. Pointer to vector because it's shorter than an empty vector! (Not all Refi...
Vector< Vector< std::pair< FiniteElement *, Vector< double > > > > bin_content() const
Get the contents of all bins in vector.
CGAL::Cartesian_d< double > Kernel_d
typedefs for cgal stuff
unsigned Element_index_in_mesh
Index of finite element in its mesh.
RefineableBin(const RefineableBin &data)
Broken copy constructor.
static bool Suppress_warning_about_large_total_number_of_bins
Boolean to supppress warnings about large number of bins.
void operator=(const SamplePoint &)
Broken assignment operator.
bool Use_eulerian_coordinates_during_setup
Use Eulerian coordinates (i.e. interpolated_x) rather than zeta itself (i.e. interpolated_zeta) to id...
unsigned & multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta()
Every time we've completed a "spiral", visiting a finite number of sample points in a deterministic o...
unsigned max_depth() const
Max depth of the hierarchical bin_array; const version.
Vector< SamplePoint * > Sample_point_pt
unsigned & multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta()
Every time we've completed a "spiral", visiting a finite number of sample points in a deterministic o...
unsigned & first_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points only actually do the locate_zeta calls when when the counter exc...
bool ignore_halo_elements_during_locate_zeta_search() const
Ignore halo elements?
void operator=(const CGALSamplePointContainer &)
Broken assignment operator.
unsigned Last_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points only actually do the locate_zeta calls when when the counter is ...
unsigned Nspiral_chunk
Number of spirals to be searched in one go.
unsigned & last_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points only actually do the locate_zeta calls when when the counter is ...
RefineableBinArray class.
unsigned & max_spiral_level()
Access function to max. spiral level during straight locate_zeta search (for efficiency; similar to m...
Vector< std::pair< double, double > > Min_and_max_coordinates
bool bin_array_is_recursive() const
Is the BinArray recursive?
virtual ~BinArray()
Virtual destructor.
CGAL-based SamplePointContainer.
unsigned Nsample_points_generated_per_element
"Measure of" number of sample points generated in each element
const Vector< std::pair< double, double > > & min_and_max_coordinates() const
Vector of pair of doubles for min and maximum coordinates. min (first) and max. (second) coordinates...
const std::pair< double, double > & min_and_max_coordinates(const unsigned &i) const
Pair of doubles for min and maximum coordinates in i-th direction: min (first) and max...
void output_bins(std::ofstream &outfile)
Output bins.
unsigned Max_depth
Max depth of the hierarchical bin_array.
virtual ~SamplePointContainer()
Virtual destructor.
Vector< Point_d > CGAL_sample_point_zeta_d
Vector containing sample point coordinates.
CGAL::Search_traits_d< Kernel_d > Traits_base_d
unsigned Current_min_spiral_level
Current min. spiralling level.
unsigned & first_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points recursively from the top level RefineableBinArray (in determinis...
virtual unsigned & total_number_of_sample_points_visited_during_locate_zeta_from_top_level()
Counter to keep track of how many sample points we've visited during top level call to locate_zeta...
unsigned First_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points recursively from the top level RefineableBinArray (in determinis...
BinArray()
Broken default constructor; needed for broken copy constructors. Don't call. It will die...
static unsigned long Threshold_for_total_bin_cell_number_warning
Total number of bins above which warning is issued. (Default assignment of 100^DIM bins per MeshAsGeo...
unsigned max_number_of_sample_point_per_bin() const
Maximum number of sample points in bin (before its subdivided recursively)
void add_sample_point(SamplePoint *new_sample_point_pt, const Vector< double > &zeta)
Add specified SamplePoint to RefineableBinArray.
CGAL::Search_traits_adapter< Point_d_and_pointer, CGAL::Nth_of_tuple_property_map< 0, Point_d_and_pointer >, Traits_base_d > Traits_d
unsigned & initial_last_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points only actually do the locate_zeta calls when when the counter exc...
virtual ~CGALSamplePointContainer()
Virtual destructor.
void flush_bins_of_objects()
Flush the storage for the binning method (and decrement counter for total number of bins in active us...
RefineableBinArray * root_bin_array_pt() const
Root bin array.
bool use_eulerian_coordinates_during_setup() const
Use Eulerian coordinates (i.e. interpolated_x) rather than zeta itself (i.e. interpolated_zeta) to id...
unsigned Ndim_zeta
Dimension of the zeta ( = dim of local coordinate of elements)
static std::ofstream Visited_sample_points_file
File to record sequence of visited sample points in.
unsigned depth() const
Depth of the hierarchical bin_array.
unsigned dimension_of_bin_array(const unsigned &i) const
Number of bins in coordinate direction i.
~RefineableBinArray()
Destructor.
bool Bin_array_is_recursive
Variable which stores if the RefineableBinArray is recursive or not.
unsigned nsample_points_in_bin()
Number of sample points stored in bin.
unsigned & current_max_spiral_level()
Access function to current max. spiral level.
unsigned ndim_zeta() const
Dimension of the zeta ( = dim of local coordinate of elements)
Base class for all bin arrays.
Kernel_d::Point_d Point_d
RefineableBinArray * Sub_bin_array_pt
Pointer to a possible sub-BinArray. Null by default.
RefineableBinArray(const RefineableBinArray &data)
Broken copy constructor.
void output_bins(std::string &filename)
Output bins.
static unsigned long Total_nbin_cells_counter
Counter for overall number of bins allocated – used to issue warning if this exceeds a threshhold...
RefineableBin * bin_pt(const unsigned &i) const
Pointer to i-th bin; can be null if bin is empty.
unsigned Sample_point_index_in_element
Index of the sample point within element.
NonRefineableBinArray(const NonRefineableBinArray &data)
Broken copy constructor.
static double Percentage_offset
Offset of sample point container boundaries beyond max/min coords.
unsigned Multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta
Every time we've completed a "spiral", visiting a finite number of sample points in a deterministic o...
SparseVector< Vector< std::pair< FiniteElement *, Vector< double > > > > Bin_object_coord_pairs
Storage for paired objects and coords in each bin.
unsigned n_spiral_chunk() const
Number of spirals to be searched in one go const version.
unsigned nbin() const
Number of bins (not taking recursion into account)
static bool Suppress_warning_about_small_number_of_bins
Boolean to supppress warnings about small number of bins.
void operator=(const BinArray &)
Broken assignment operator.
Vector< unsigned > Dimensions_of_bin_array
Number of bins in each coordinate direction.
void output(std::ostream &outfile)
Output with default number of plot points.
unsigned element_index_in_mesh() const
Access function to the index of finite element in its mesh.
static bool Use_equally_spaced_interior_sample_points
Use equally spaced sample points? (otherwise vertices are sampled repeatedly.
SamplePoint(const unsigned &element_index_in_mesh, const unsigned &sample_point_index_in_element)
Construct SamplePoint object from number of finite element in its mesh, and index of sample point wit...
const std::map< unsigned, Vector< std::pair< FiniteElement *, Vector< double > > > > * get_all_bins_content() const
Get the contents of all bins in vector.
static bool Always_fail_elemental_locate_zeta
Boolean flag to make to make locate zeta fail. Used for debugging/ illustration of search procedures...
unsigned Multiplier_for_max_sample_point_to_actually_lookup_during_locate_zeta
Every time we've completed a "spiral", visiting a finite number of sample points in a deterministic o...
static unsigned Default_n_bin_1d
Default number of bins (in each coordinate direction) (Note: don't move this into a common base class...
void broken_assign(const std::string &class_name)
Issue error message and terminate execution.
~NonRefineableBinArray()
Destructor:
NonRefineableBinArray class.
unsigned & initial_last_sample_point_to_actually_lookup_during_locate_zeta()
When searching through sample points recursively from the top level RefineableBinArray (in determinis...
RefineableBin(RefineableBinArray *bin_array_pt, const unsigned &bin_index_in_bin_array)
Constructor. Pass pointer to bin array that contains this bin and the index of the newly created bin ...
RefineableBinArray * Root_bin_array_pt
Pointer to root bin array.
std::string string(const unsigned &i)
Return the i-th string or "" if the relevant string hasn't been defined.
static bool Already_warned_about_large_number_of_bin_cells
Boolean flag to make sure that warning about large number of bin cells only gets triggered once...
unsigned First_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points only actually do the locate_zeta calls when when the counter exc...
Mesh * mesh_pt() const
Pointer to mesh from whose FiniteElements sample points are created.
unsigned Initial_last_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points only actually do the locate_zeta calls when when the counter exc...
unsigned Max_number_of_sample_point_per_bin
Maximum number of sample points in bin (before it's subdivided recursively)
bool Ignore_halo_elements_during_locate_zeta_search
Ignore halo elements?
unsigned Initial_last_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points recursively from the top level RefineableBinArray (in determinis...
CGALSamplePointContainer(const CGALSamplePointContainer &data)
Broken copy constructor.
static bool Already_warned_about_small_number_of_bin_cells
Boolean flag to make sure that warning about small number of bin cells only gets triggered once...
boost::tuple< Point_d, SamplePoint *> Point_d_and_pointer
unsigned dimensions_of_bin_array(const unsigned &i) const
Number of bins in specified coordinate direction.
unsigned nbin() const
Total number of bins (empty or not)
Mesh * Mesh_pt
Pointer to mesh from whose FiniteElements sample points are created.
unsigned sample_point_index_in_element() const
Index of sample point within element.
static unsigned Default_n_bin_1d
Default number of bins (in each coordinate direction). (Note: don't move this into a common base clas...
void operator=(const RefineableBin &)
Broken assignment operator.
void operator=(const SamplePointContainer &)
Broken assignment operator.
unsigned ndim_zeta() const
Dimension of the zeta ( = dim of local coordinate of elements)
Vector< unsigned > dimensions_of_bin_array() const
Number of bins in coordinate directions. Const vector-based version.
Vector< RefineableBin * > Bin_pt
Vector of pointers to constituent RefineableBins.
Base class for all sample point containers.
unsigned Current_max_spiral_level
Current max. spiralling level.
unsigned & n_spiral_chunk()
Number of spirals to be searched in one go.
double & max_search_radius()
Set maximum search radius for locate zeta. This is initialised do DBL_MAX so we brutally search throu...
unsigned & total_number_of_sample_points_visited_during_locate_zeta_from_top_level()
Counter to keep track of how many sample points we've visited during top level call to locate_zeta...
unsigned Bin_index_in_bin_array
Index of bin in its bin array.
unsigned & current_min_spiral_level()
Access function to current min. spiral level.
void operator=(const RefineableBinArray &)
Broken assignment operator.
SamplePointContainer(const SamplePointContainer &data)
Broken copy constructor.
SamplePointContainer()
Broken default constructor; needed for broken copy constructors. Don't call. It will die...
unsigned & nsample_points_generated_per_element()
"Measure of" number of sample points generated in each element
unsigned & max_depth()
Max depth of the hierarchical bin_array.
SamplePointContainer(Mesh *mesh_pt, const Vector< std::pair< double, double > > &min_and_max_coordinates, const bool &use_eulerian_coordinates_during_setup, const bool &ignore_halo_elements_during_locate_zeta_search, const unsigned &nsample_points_generated_per_element)
Constructor.
RefineableBinArray * Bin_array_pt
Pointer to the bin array which "owns" this RefineableBin.
static unsigned Threshold_for_elements_per_bin_warning
Fraction of elements/bin that triggers warning. Too many elements per bin can lead to very slow compu...
BinArray(const BinArray &data)
Broken copy constructor.
double Max_search_radius
Max radius beyond which we stop searching the bin. Initialised to DBL_MAX so keep going until the poi...
static bool Enable_timing_of_setup
Time setup?
unsigned Depth
Variable which stores the Depth value of the bin_array. Useful for debugging and for preventing "infi...
unsigned Last_sample_point_to_actually_lookup_during_locate_zeta
When searching through sample points recursively from the top level RefineableBinArray (in determinis...