Loading [MathJax]/extensions/tex2jax.js
Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PointInElementSearch.cpp File Reference
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "moab/Core.hpp"
#include "moab/Interface.hpp"
#include "moab/Range.hpp"
#include "moab/AdaptiveKDTree.hpp"
#include "moab/ElemEvaluator.hpp"
#include "moab/CN.hpp"
#include "moab/SpatialLocator.hpp"
+ Include dependency graph for PointInElementSearch.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Variables

string test_file_name = string( MESH_DIR ) + string( "/mbtest1.vtk" )
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file PointInElementSearch.cpp.

30 { 31  int num_queries = 1000000; 32  33  if( argc > 3 ) 34  { 35  cout << "Usage: " << argv[0] << " <filename> [num_queries]" << endl; 36  return 0; 37  } 38  else if( argc == 3 ) 39  { 40  test_file_name = argv[1]; 41  num_queries = atoi( argv[2] ); 42  } 43  else 44  { 45  num_queries = 100; 46  } 47  48  // Instantiate 49  Core mb; 50  51  // Load the file 52  ErrorCode rval = mb.load_file( test_file_name.c_str() );MB_CHK_SET_ERR( rval, "Error loading file" ); 53  54  // Get all 3d elements in the file 55  Range elems; 56  rval = mb.get_entities_by_dimension( 0, 3, elems );MB_CHK_SET_ERR( rval, "Error getting 3d elements" ); 57  58  // Create a tree to use for the location service 59  AdaptiveKDTree tree( &mb ); 60  61  // Specify an evaluator based on linear hexes 62  ElemEvaluator el_eval( &mb ); 63  64  // Build the SpatialLocator 65  SpatialLocator sl( &mb, elems, &tree ); 66  67  // Get the box extents 68  CartVect box_extents, pos; 69  BoundBox box = sl.local_box(); 70  box_extents = box.bMax - box.bMin; 71  72  // Query at random places in the tree 73  CartVect params; 74  int is_inside = 0; 75  int num_inside = 0; 76  EntityHandle elem; 77  for( int i = 0; i < num_queries; i++ ) 78  { 79  pos = box.bMin + CartVect( box_extents[0] * .01 * ( rand() % 100 ), box_extents[1] * .01 * ( rand() % 100 ), 80  box_extents[2] * .01 * ( rand() % 100 ) ); 81  rval = sl.locate_point( pos.array(), elem, params.array(), &is_inside, 0.0, 0.0 );MB_CHK_ERR( rval ); 82  if( is_inside ) num_inside++; 83  } 84  85  cout << "Mesh contains " << elems.size() << " elements of type " 86  << CN::EntityTypeName( mb.type_from_handle( *elems.begin() ) ) << endl; 87  cout << "Bounding box min-max = (" << box.bMin[0] << "," << box.bMin[1] << "," << box.bMin[2] << ")-(" 88  << box.bMax[0] << "," << box.bMax[1] << "," << box.bMax[2] << ")" << endl; 89  cout << "Queries inside box = " << num_inside << "/" << num_queries << " = " 90  << 100.0 * ( (double)num_inside ) / num_queries << "%" << endl; 91  92  return 0; 93 }

References moab::CartVect::array(), moab::Range::begin(), moab::BoundBox::bMax, moab::BoundBox::bMin, moab::CN::EntityTypeName(), ErrorCode, moab::Core::get_entities_by_dimension(), moab::Core::load_file(), moab::SpatialLocator::local_box(), moab::SpatialLocator::locate_point(), mb, MB_CHK_ERR, MB_CHK_SET_ERR, moab::Range::size(), test_file_name, and moab::Core::type_from_handle().

Variable Documentation

◆ test_file_name

string test_file_name = string( MESH_DIR ) + string( "/mbtest1.vtk" )

Definition at line 27 of file PointInElementSearch.cpp.

Referenced by main().