moab
|
00001 00006 #include <vector> 00007 #include <iostream> 00008 #include <time.h> 00009 00010 #include <sstream> 00011 #include <fstream> 00012 00013 #ifndef POINT_LOCATER_HPP 00014 #define POINT_LOCATER_HPP 00015 00016 namespace moab { 00017 00018 template< typename _Tree, 00019 typename _Boxes> 00020 class Point_search { 00021 00022 //public types 00023 public: 00024 typedef _Tree Tree; 00025 typedef _Boxes Boxes; 00026 // typedef typename Tree::Elements::value_type Element; 00027 typedef int Error; 00028 00029 //private types 00030 private: 00031 typedef Point_search< _Tree, 00032 _Boxes> Self; 00033 //public methods 00034 public: 00035 00036 //Constructor 00037 Point_search( Tree & _tree, 00038 Boxes & _boxes): 00039 tree_( _tree), 00040 boxes( _boxes){} 00041 00042 //Copy constructor 00043 Point_search( Self & s): tree_( s.tree_), 00044 boxes( s.boxes){} 00045 00046 //private functionality 00047 private: 00048 00049 //TODO: deprecate this 00050 template< typename Point_map, typename List> 00051 void resolve_boxes( const Point_map & query_points, List & list){ 00052 /* 00053 typedef typename std::vector< bool> Bitmask; 00054 typedef typename Points::const_iterator Point; 00055 typedef typename Tree::const_element_iterator Element; 00056 typedef typename std::vector< std::size_t> Processor_list; 00057 typedef typename List::value_type Tuple; 00058 const Element & end = tree_.element_end(); 00059 Bitmask located_points( query_points.size(), 0); 00060 std::size_t index=0; 00061 for( Point i = query_points.begin(); 00062 i != query_points.end(); ++i,++index){ 00063 const Element & element = tree_.find( *i); 00064 if(element != end){ 00065 located_points[ index] = 1; 00066 } 00067 } 00068 for(int i = 0; i < located_points.size(); ++i){ 00069 if(!located_points[ i]){ 00070 Processor_list processors; 00071 const Point & point = query_point.begin()+i; 00072 resolve_box_for_point( point, processors); 00073 for( std::size_t p = processors.begin(); 00074 p != processors.end(); ++p){ 00075 list.push_back( Tuple( *point, *p) ); 00076 } 00077 } 00078 } 00079 */ 00080 } 00081 00082 00083 //public functionality 00084 public: 00085 template< typename Point_map, typename Entities, typename Communicator> 00086 Error locate_points( Point_map & query_points, Entities & entities, 00087 Communicator & comm, double tol){ 00088 /*TODO: implement a parallel location algorithm here 00089 original algorithm: 00090 all-scatter/gather bounding boxes 00091 for each point perform box checks 00092 scatter/gather points 00093 perform location and solution interpolation 00094 //send results back 00095 ------------ 00096 new algorithm 00097 Assume power num_proc = n^2; 00098 all-reduce bounding boxes 00099 divide box up into n x n grid 00100 each source processor can communicate its elements to grid proc 00101 each target processor then communicates its points to grid proc 00102 grid proc sends points to correct source proc. 00103 */ 00104 return 0; 00105 } 00106 00107 template< typename Points, typename Entities> 00108 Error locate_points( const Points & query_points, 00109 Entities & entities, double tol) const{ 00110 typedef typename Points::const_iterator Point_iterator; 00111 typedef typename Entities::value_type Result; 00112 Entities result; 00113 result.reserve( query_points.size()); 00114 for(Point_iterator i = query_points.begin(); 00115 i != query_points.end(); ++i){ 00116 Result h; 00117 tree_.find( *i, tol, h); 00118 result.push_back( h); 00119 } 00120 entities = result; 00121 return 0; 00122 } 00123 00124 template< typename Points, typename Entities> 00125 Error bruteforce_locate_points( const Points & query_points, 00126 Entities & entities, double tol) const{ 00127 //TODO: this could be faster with caching, but of course this is 00128 //really just for testing 00129 typedef typename Points::const_iterator Point_iterator; 00130 typedef typename Entities::value_type::first_type Entity_handle; 00131 Entities result; 00132 result.reserve( query_points.size()); 00133 std::size_t count = 0; 00134 std::stringstream ss; 00135 typename Entities::iterator j = entities.begin(); 00136 for( Point_iterator i = query_points.begin(); 00137 i != query_points.end(); ++i, ++j){ 00138 if( j->first == 0){ 00139 const Entity_handle h = tree_.bruteforce_find( *i, tol); 00140 if( h == 0){ 00141 ++count; 00142 for(int k = 0; k < 3; ++k){ 00143 ss << (*i)[ k]; 00144 if ( k < 2){ 00145 ss << ", "; 00146 }else{ 00147 ss << std::endl; 00148 } 00149 } 00150 00151 } 00152 } 00153 } 00154 std::ofstream out("unlocated_pts"); 00155 out << ss.str(); 00156 out.close(); 00157 std::cout << count << " vertices are not contained in _any_ elements!" 00158 << std::endl; 00159 return 0; 00160 } 00161 00162 //public accessor methods 00163 public: 00164 Tree & tree() const { return tree_; } 00165 00166 //private data members 00167 private: 00168 const Tree & tree_; 00169 const Boxes & boxes; 00170 }; //class Point_search 00171 00172 } // namespace moab 00173 00174 #endif //POINT_LOCATER_HPP