MOAB: Mesh Oriented datABase  (version 5.5.0)
spatial_locator_test.cpp File Reference
#include "moab/Core.hpp"
#include "moab/SpatialLocator.hpp"
#include "moab/Tree.hpp"
#include "moab/HomXform.hpp"
#include "moab/ScdInterface.hpp"
#include "moab/CartVect.hpp"
#include "moab/AdaptiveKDTree.hpp"
#include "moab/BVHTree.hpp"
#include "moab/ElemEvaluator.hpp"
#include "moab/ProgOptions.hpp"
#include "moab/CpuTimer.hpp"
#include "TestUtil.hpp"
#include <cstdlib>
#include <sstream>
+ Include dependency graph for spatial_locator_test.cpp:

Go to the source code of this file.

Functions

void test_kd_tree ()
 
void test_bvh_tree ()
 
void test_locator (SpatialLocator *sl)
 
ErrorCode create_hex_mesh (Interface &mb, Range &elems, int n, int dim)
 
int main (int argc, char **argv)
 

Variables

int max_depth = 30
 
int npoints = 1000
 
int leaf = 6
 
bool print_tree = false
 
int ints = 10
 

Function Documentation

◆ create_hex_mesh()

ErrorCode create_hex_mesh ( Interface mb,
Range elems,
int  n,
int  dim 
)

Definition at line 153 of file spatial_locator_test.cpp.

154 {
155  ScdInterface* scdi;
156  ErrorCode rval = mb.query_interface( scdi );CHECK_ERR( rval );
157  HomCoord high( n - 1, -1, -1 );
158  if( dim > 1 ) high[1] = n - 1;
159  if( dim > 2 ) high[2] = n - 1;
160  ScdBox* new_box;
161  rval = scdi->construct_box( HomCoord( 0, 0, 0 ), high, NULL, 0, new_box );CHECK_ERR( rval );
162  rval = mb.release_interface( scdi );CHECK_ERR( rval );
163 
164  rval = mb.get_entities_by_dimension( 0, dim, elems );CHECK_ERR( rval );
165 
166  return rval;
167 }

References CHECK_ERR, moab::ScdInterface::construct_box(), dim, ErrorCode, moab::Core::get_entities_by_dimension(), mb, moab::Interface::query_interface(), and moab::Interface::release_interface().

Referenced by test_bvh_tree(), and test_kd_tree().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 36 of file spatial_locator_test.cpp.

37 {
38 #ifdef MOAB_HAVE_MPI
39  int fail = MPI_Init( &argc, &argv );
40  if( fail ) return fail;
41 #else
42  // silence the warning of parameters not used, in serial; there should be a smarter way :(
43  argv[0] = argv[argc - argc];
44 #endif
45 
46  ProgOptions po( "spatial_locator_test options" );
47  po.addOpt< int >( "ints,i", "Number of intervals on each side of scd mesh", &ints );
48  po.addOpt< int >( "leaf,l", "Maximum number of elements per leaf", &leaf );
49  po.addOpt< int >( "max_depth,m", "Maximum depth of tree", &max_depth );
50  po.addOpt< int >( "npoints,n", "Number of query points", &npoints );
51  po.addOpt< void >( "print,p", "Print tree details", &print_tree );
52  po.parseCommandLine( argc, argv );
53 
56 
57 #ifdef MOAB_HAVE_MPI
58  fail = MPI_Finalize();
59  if( fail ) return fail;
60 #endif
61 
62  return 0;
63 }

References ProgOptions::addOpt(), moab::fail(), ints, leaf, max_depth, npoints, ProgOptions::parseCommandLine(), print_tree, RUN_TEST, test_bvh_tree(), and test_kd_tree().

◆ test_bvh_tree()

void test_bvh_tree ( )

Definition at line 93 of file spatial_locator_test.cpp.

94 {
95  ErrorCode rval;
96  Core mb;
97 
98  // create a simple mesh to test
99  Range elems;
100  rval = create_hex_mesh( mb, elems, ints, 3 );CHECK_ERR( rval );
101 
102  // initialize spatial locator with the elements and a BVH tree
103  BVHTree bvh( &mb );
104  std::ostringstream opts;
105  opts << "MAX_DEPTH=" << max_depth << ";MAX_PER_LEAF=" << leaf;
106  FileOptions fo( opts.str().c_str() );
107  rval = bvh.parse_options( fo );
108  SpatialLocator* sl = new SpatialLocator( &mb, elems, &bvh );
109  test_locator( sl );
110 
111  // test with an evaluator
112  ElemEvaluator eval( &mb );
113  bvh.set_eval( &eval );
114  test_locator( sl );
115 
116  // destroy spatial locator, and tree along with it
117  delete sl;
118 }

References CHECK_ERR, create_hex_mesh(), ErrorCode, ints, leaf, max_depth, mb, moab::BVHTree::parse_options(), moab::Tree::set_eval(), and test_locator().

Referenced by main().

◆ test_kd_tree()

void test_kd_tree ( )

Definition at line 65 of file spatial_locator_test.cpp.

66 {
67  ErrorCode rval;
68  Core mb;
69 
70  // create a simple mesh to test
71  Range elems;
72  rval = create_hex_mesh( mb, elems, ints, 3 );CHECK_ERR( rval );
73 
74  // initialize spatial locator with the elements and KDtree
75  AdaptiveKDTree kd( &mb );
76  std::ostringstream opts;
77  opts << "MAX_DEPTH=" << max_depth << ";MAX_PER_LEAF=" << leaf;
78  FileOptions fo( opts.str().c_str() );
79  rval = kd.parse_options( fo );
80  SpatialLocator* sl = new SpatialLocator( &mb, elems, &kd );
81 
82  test_locator( sl );
83 
84  // test with an evaluator
85  ElemEvaluator eval( &mb );
86  kd.set_eval( &eval );
87  test_locator( sl );
88 
89  // destroy spatial locator, and tree along with it
90  delete sl;
91 }

References CHECK_ERR, create_hex_mesh(), ErrorCode, ints, leaf, max_depth, mb, moab::AdaptiveKDTree::parse_options(), moab::Tree::set_eval(), and test_locator().

Referenced by main().

◆ test_locator()

void test_locator ( SpatialLocator sl)

Definition at line 120 of file spatial_locator_test.cpp.

121 {
122  CartVect box_del, test_pt, test_res;
123  BoundBox box = sl->local_box();
124  box_del = box.bMax - box.bMin;
125 
126  double denom = 1.0 / (double)RAND_MAX;
127  int is_in;
128  EntityHandle ent = 0;
129  ErrorCode rval;
130  for( int i = 0; i < npoints; i++ )
131  {
132  // generate a small number of random point to test
133  double rx = (double)rand() * denom, ry = (double)rand() * denom, rz = (double)rand() * denom;
134  test_pt = box.bMin + CartVect( rx * box_del[0], ry * box_del[1], rz * box_del[2] );
135 
136  // call spatial locator to locate points
137  rval = sl->locate_points( test_pt.array(), 1, &ent, test_res.array(), &is_in );CHECK_ERR( rval );
138 
139  // verify that the point was found
140  CHECK_EQUAL( is_in, true );
141  }
142 
143  std::cout << "Traversal stats:" << std::endl;
145 
146  if( print_tree )
147  {
148  std::cout << "Tree information: " << std::endl;
149  rval = sl->get_tree()->print();CHECK_ERR( rval );
150  }
151 }

References moab::CartVect::array(), box(), CHECK_EQUAL, CHECK_ERR, ErrorCode, moab::SpatialLocator::get_tree(), moab::SpatialLocator::local_box(), moab::SpatialLocator::locate_points(), npoints, moab::TreeStats::output_trav_stats(), moab::Tree::print(), print_tree, and moab::Tree::tree_stats().

Referenced by test_bvh_tree(), and test_kd_tree().

Variable Documentation

◆ ints

int ints = 10

Definition at line 34 of file spatial_locator_test.cpp.

Referenced by main(), test_bvh_tree(), and test_kd_tree().

◆ leaf

int leaf = 6

Definition at line 32 of file spatial_locator_test.cpp.

Referenced by main(), test_bvh_tree(), and test_kd_tree().

◆ max_depth

int max_depth = 30

Definition at line 30 of file spatial_locator_test.cpp.

Referenced by main(), test_bvh_tree(), and test_kd_tree().

◆ npoints

int npoints = 1000

Definition at line 31 of file spatial_locator_test.cpp.

Referenced by main(), and test_locator().

◆ print_tree

bool print_tree = false

Definition at line 33 of file spatial_locator_test.cpp.

Referenced by main(), and test_locator().