MOAB: Mesh Oriented datABase  (version 5.5.0)
gqt_simple_test.cpp File Reference
#include <iostream>
#include "moab/Interface.hpp"
#include "TestUtil.hpp"
#include "Internals.hpp"
#include "moab/Core.hpp"
#include "moab/GeomTopoTool.hpp"
#include "moab/GeomQueryTool.hpp"
+ Include dependency graph for gqt_simple_test.cpp:

Go to the source code of this file.

Macros

#define IS_BUILDING_MB
 
#define CHKERR(A)
 

Functions

void gqt_load_file ()
 
void gqt_load_file_dagmc_build_obb ()
 
void gqt_load_file_dagmc_via_moab_build_obb ()
 
void gqt_load_file_dagmc_internal_build_obb ()
 
void gqt_test_obb_retreval ()
 
void gqt_create_impl_compl ()
 
void gqt_build_obb ()
 
void gqt_num_vols ()
 
void gqt_point_in ()
 
void gqt_test_obb_retreval_rayfire ()
 
void gqt_rayfire ()
 
void gqt_closest_to ()
 
void gqt_test_boundary ()
 
void gqt_point_in_box_1 ()
 
void gqt_point_in_box_2 ()
 
void gqt_point_in_box_3 ()
 
void gqt_point_in_box_4 ()
 
void gqt_point_in_box_5 ()
 
void cleanup ()
 
int main (int, char **)
 

Variables

GeomTopoToolGTT
 
GeomQueryToolGQT
 
InterfaceMBI
 
const std::string input_file = TestDir + "unittest/test_geom.h5m"
 

Macro Definition Documentation

◆ CHKERR

#define CHKERR (   A)
Value:
do \
{ \
if( MB_SUCCESS != ( A ) ) \
{ \
std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
return A; \
} \
} while( false )

Definition at line 19 of file gqt_simple_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file gqt_simple_test.cpp.

Function Documentation

◆ cleanup()

void cleanup ( )

Definition at line 338 of file gqt_simple_test.cpp.

339 {
340  // cleanup instances
341  delete GQT;
342  delete GTT;
343  delete MBI;
344 }

References GQT, GTT, and MBI.

Referenced by main().

◆ gqt_build_obb()

void gqt_build_obb ( )

Definition at line 126 of file gqt_simple_test.cpp.

127 {
128  ErrorCode rval = GQT->gttool()->construct_obb_trees();CHECK_ERR( rval );
129 }

References CHECK_ERR, moab::GeomTopoTool::construct_obb_trees(), ErrorCode, GQT, and moab::GeomQueryTool::gttool().

Referenced by main().

◆ gqt_closest_to()

void gqt_closest_to ( )

Definition at line 242 of file gqt_simple_test.cpp.

243 {
244  const double eps = 1e-6; // epsilon for test, faceting tol?
245 
246  int vol_idx = 1;
247  // note model is cube of side 10, centred at 0,0,0, so ray fire along
248  // any unit direction should be exactly 5.0
249  double xyz[3] = { -6.0, 0.0, 0.0 };
250  double distance; // distance from point to nearest surface
251  double expect_distance = 1.0;
252  EntityHandle vol_h;
253  ErrorCode rval;
254 
255  // get the volume handle
256  vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
257 
258  // test closest to location
259  rval = GQT->closest_to_location( vol_h, xyz, distance );CHECK_ERR( rval );
260 
261  // distance should be 1.0 cm
262  CHECK_REAL_EQUAL( expect_distance, distance, eps );
263 }

References CHECK_ERR, CHECK_REAL_EQUAL, moab::GeomQueryTool::closest_to_location(), moab::GeomTopoTool::entity_by_id(), eps, ErrorCode, GQT, and moab::GeomQueryTool::gttool().

Referenced by main().

◆ gqt_create_impl_compl()

void gqt_create_impl_compl ( )

Definition at line 121 of file gqt_simple_test.cpp.

122 {
124 }

References CHECK_ERR, ErrorCode, GQT, moab::GeomQueryTool::gttool(), and moab::GeomTopoTool::setup_implicit_complement().

Referenced by main().

◆ gqt_load_file()

void gqt_load_file ( )

Definition at line 31 of file gqt_simple_test.cpp.

32 {
33  MBI = new moab::Core();
34  ErrorCode rval = MBI->load_file( input_file.c_str() ); // open the
35  CHECK_ERR( rval );
36  GTT = new GeomTopoTool( MBI, true );
37  GQT = new GeomQueryTool( GTT );
38 }

References CHECK_ERR, ErrorCode, GQT, GTT, input_file, moab::Interface::load_file(), and MBI.

Referenced by main().

◆ gqt_load_file_dagmc_build_obb()

void gqt_load_file_dagmc_build_obb ( )

Definition at line 40 of file gqt_simple_test.cpp.

41 {
42  /* 1 - Test with external moab, load file in GTT/GQT*/
43  // make new moab core
44  ErrorCode rval;
45 
46  // load a file
47  MBI = new moab::Core();
48  rval = MBI->load_file( input_file.c_str() ); // open the
49  CHECK_ERR( rval );
50  GTT = new GeomTopoTool( MBI );
51  GQT = new GeomQueryTool( GTT );
52  rval = GQT->initialize();CHECK_ERR( rval );
53 }

References CHECK_ERR, ErrorCode, GQT, GTT, moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), and MBI.

Referenced by main().

◆ gqt_load_file_dagmc_internal_build_obb()

void gqt_load_file_dagmc_internal_build_obb ( )

Definition at line 72 of file gqt_simple_test.cpp.

73 {
74  /* 3 - Test with internal moab, load file in MOAB*/
75  // find geomsets, build implicit complement, and construct obb trees
76  ErrorCode rval;
77 
78  MBI = new moab::Core();
79  rval = MBI->load_file( input_file.c_str() ); // open the
80  CHECK_ERR( rval );
81  GTT = new GeomTopoTool( MBI, true, 0 );
82  GQT = new GeomQueryTool( GTT );
83  rval = GQT->gttool()->setup_implicit_complement();CHECK_ERR( rval );
84  rval = GQT->gttool()->construct_obb_trees();CHECK_ERR( rval );
85 }

References CHECK_ERR, moab::GeomTopoTool::construct_obb_trees(), ErrorCode, GQT, GTT, moab::GeomQueryTool::gttool(), input_file, moab::Interface::load_file(), MBI, and moab::GeomTopoTool::setup_implicit_complement().

Referenced by main().

◆ gqt_load_file_dagmc_via_moab_build_obb()

void gqt_load_file_dagmc_via_moab_build_obb ( )

Definition at line 55 of file gqt_simple_test.cpp.

56 {
57  /* 2 - Test with external moab, load file in MOAB*/
58  // build implicit complement and obb trees
59  ErrorCode rval;
60 
61  // load file
62  MBI = new moab::Core();
63  rval = MBI->load_file( input_file.c_str() ); // open the file
64  CHECK_ERR( rval );
65  GTT = new GeomTopoTool( MBI );
66  GQT = new GeomQueryTool( GTT );
67  // create obb trees
68  rval = GQT->gttool()->setup_implicit_complement();CHECK_ERR( rval );
69  rval = GQT->gttool()->construct_obb_trees();CHECK_ERR( rval );
70 }

References CHECK_ERR, moab::GeomTopoTool::construct_obb_trees(), ErrorCode, GQT, GTT, moab::GeomQueryTool::gttool(), input_file, moab::Interface::load_file(), MBI, and moab::GeomTopoTool::setup_implicit_complement().

Referenced by main().

◆ gqt_num_vols()

void gqt_num_vols ( )

Definition at line 131 of file gqt_simple_test.cpp.

132 {
133  int expect_num_vols = 2;
134  int num_vols = GQT->gttool()->num_ents_of_dim( 3 );
135  CHECK_EQUAL( expect_num_vols, num_vols );
136 }

References CHECK_EQUAL, GQT, moab::GeomQueryTool::gttool(), and moab::GeomTopoTool::num_ents_of_dim().

Referenced by main().

◆ gqt_point_in()

void gqt_point_in ( )

Definition at line 138 of file gqt_simple_test.cpp.

139 {
140  int result = 0;
141  int expect_result = 1;
142  int vol_idx = 1;
143  double xyz[3] = { 0.0, 0.0, 0.0 };
144  EntityHandle vol_h;
145 
146  // load file and create instances
147  MBI = new moab::Core();
148  ErrorCode rval = MBI->load_file( input_file.c_str() ); // open the
149  CHECK_ERR( rval );
150  GTT = new GeomTopoTool( MBI, true, 0 );
151  GQT = new GeomQueryTool( GTT );
152  // initialize for geom queries
153  GQT->initialize();
154 
155  // get volume
156  vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
157  // test point in volume
158  GQT->point_in_volume( vol_h, xyz, result );CHECK_ERR( rval );
159  CHECK_EQUAL( expect_result, result );
160 }

References CHECK_EQUAL, CHECK_ERR, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, GTT, moab::GeomQueryTool::gttool(), moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), MBI, and moab::GeomQueryTool::point_in_volume().

Referenced by main().

◆ gqt_point_in_box_1()

void gqt_point_in_box_1 ( )

Definition at line 283 of file gqt_simple_test.cpp.

284 {
285  int vol_id = 1;
286  double origin[3] = { 0.0, 0.0, 0.0 };
287  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_id );
288  int result;
289  ErrorCode rval = GQT->point_in_box( vol_h, origin, result );
290  CHECK_EQUAL( rval, moab::MB_SUCCESS );
291  CHECK_EQUAL( result, 1 ); // inside
292 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), MB_SUCCESS, origin, and moab::GeomQueryTool::point_in_box().

◆ gqt_point_in_box_2()

void gqt_point_in_box_2 ( )

Definition at line 294 of file gqt_simple_test.cpp.

295 {
296  int vol_id = 1;
297  double origin[3] = { 5.0, 0.0, 0.0 };
298  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_id );
299  int result;
300  ErrorCode rval = GQT->point_in_box( vol_h, origin, result );
301  CHECK_EQUAL( rval, moab::MB_SUCCESS );
302  CHECK_EQUAL( result, 1 ); // inside
303 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), MB_SUCCESS, origin, and moab::GeomQueryTool::point_in_box().

◆ gqt_point_in_box_3()

void gqt_point_in_box_3 ( )

Definition at line 305 of file gqt_simple_test.cpp.

306 {
307  int vol_id = 1;
308  double origin[3] = { 5.1, 0.0, 0.0 };
309  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_id );
310  int result;
311  ErrorCode rval = GQT->point_in_box( vol_h, origin, result );
312  CHECK_EQUAL( rval, moab::MB_SUCCESS );
313  CHECK_EQUAL( result, 0 ); // outside
314 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), MB_SUCCESS, origin, and moab::GeomQueryTool::point_in_box().

◆ gqt_point_in_box_4()

void gqt_point_in_box_4 ( )

Definition at line 316 of file gqt_simple_test.cpp.

317 {
318  int vol_id = 1;
319  double origin[3] = { 5.1, 5.1, 5.1 };
320  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_id );
321  int result;
322  ErrorCode rval = GQT->point_in_box( vol_h, origin, result );
323  CHECK_EQUAL( rval, moab::MB_SUCCESS );
324  CHECK_EQUAL( result, 0 ); // outside
325 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), MB_SUCCESS, origin, and moab::GeomQueryTool::point_in_box().

◆ gqt_point_in_box_5()

void gqt_point_in_box_5 ( )

Definition at line 327 of file gqt_simple_test.cpp.

328 {
329  int vol_id = 1;
330  double origin[3] = { 5.0 - 1.e-308, 5.0 - 1.e-308, 5.0 - 1.e-308 };
331  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_id );
332  int result;
333  ErrorCode rval = GQT->point_in_box( vol_h, origin, result );
334  CHECK_EQUAL( rval, moab::MB_SUCCESS );
335  CHECK_EQUAL( result, 1 ); // outside
336 }

References CHECK_EQUAL, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), MB_SUCCESS, origin, and moab::GeomQueryTool::point_in_box().

◆ gqt_rayfire()

void gqt_rayfire ( )

Definition at line 215 of file gqt_simple_test.cpp.

216 {
217  const double eps = 1e-6; // epsilon for test, faceting tol?
218 
219  int vol_idx = 1;
220  // note model is cube of side 10, centred at 0,0,0, so ray fire along
221  // any unit direction should be exactly 5.0
222  double xyz[3] = { 0.0, 0.0, 0.0 };
223  double dir[3] = { 0.0, 0.0, 1.0 };
224  EntityHandle next_surf;
225  double next_surf_dist;
226  double expect_next_surf_dist = 5.0;
227  EntityHandle vol_h;
228  ErrorCode rval;
229 
230  MBI = new moab::Core();
231  rval = MBI->load_file( input_file.c_str() ); // open the
232  CHECK_ERR( rval );
233  GTT = new GeomTopoTool( MBI, true, 0 );
234  GQT = new GeomQueryTool( GTT );
235  GQT->initialize();CHECK_ERR( rval );
236 
237  vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
238  rval = GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval );
239  CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps );
240 }

References CHECK_ERR, CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, ErrorCode, GQT, GTT, moab::GeomQueryTool::gttool(), moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), MBI, and moab::GeomQueryTool::ray_fire().

Referenced by main().

◆ gqt_test_boundary()

void gqt_test_boundary ( )

Definition at line 265 of file gqt_simple_test.cpp.

266 {
267  int vol_idx = 1;
268  EntityHandle vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
269  int surf_idx = 1;
270  EntityHandle surf_h = GQT->gttool()->entity_by_id( 2, surf_idx );
271 
272  double xyz[3] = { 0.0, 0.0, 5.0 };
273  double dir[3] = { 0.0, 0.0, 1.0 };
274  int result;
275  int expect_result = 0;
276 
277  // test vol boundary
278  ErrorCode rval = GQT->test_volume_boundary( vol_h, surf_h, xyz, dir, result );CHECK_ERR( rval );
279  // check ray leaving volume
280  CHECK_EQUAL( expect_result, result );
281 }

References CHECK_EQUAL, CHECK_ERR, moab::GeomTopoTool::entity_by_id(), ErrorCode, GQT, moab::GeomQueryTool::gttool(), and moab::GeomQueryTool::test_volume_boundary().

Referenced by main().

◆ gqt_test_obb_retreval()

void gqt_test_obb_retreval ( )

Definition at line 87 of file gqt_simple_test.cpp.

88 {
89  // make new dagmc
90  std::cout << "test_obb_retreval" << std::endl;
91 
92  ErrorCode rval;
93  // load a file
94  MBI = new moab::Core();
95  rval = MBI->load_file( input_file.c_str() ); // open the
96  CHECK_ERR( rval );
97  GTT = new GeomTopoTool( MBI, true, 0 );
98  GQT = new GeomQueryTool( GTT );
99  GQT->initialize();CHECK_ERR( rval );
100 
101  // write to file
102  rval = MBI->write_file( "fcad" );CHECK_ERR( rval );
103 
104  // cleanup instances
105  delete GQT;
106  delete GTT;
107  delete MBI;
108 
109  // re-load written file
110  MBI = new moab::Core();
111  rval = MBI->load_file( "fcad" ); // open the
112  CHECK_ERR( rval );
113  GTT = new GeomTopoTool( MBI, true, 0 );
114  GQT = new GeomQueryTool( GTT );
115  rval = GQT->initialize();CHECK_ERR( rval );
116 
117  // remove file
118  remove( "fcad" );
119 }

References CHECK_ERR, ErrorCode, GQT, GTT, moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), MBI, and moab::Interface::write_file().

Referenced by main().

◆ gqt_test_obb_retreval_rayfire()

void gqt_test_obb_retreval_rayfire ( )

Definition at line 162 of file gqt_simple_test.cpp.

163 {
164  // make new dagmc
165  std::cout << "test_obb_retreval and ray_fire" << std::endl;
166 
167  ErrorCode rval;
168 
169  // load file and initialize
170  MBI = new moab::Core();
171  rval = MBI->load_file( input_file.c_str() ); // open the
172  CHECK_ERR( rval );
173  GTT = new GeomTopoTool( MBI, true, 0 );
174  GQT = new GeomQueryTool( GTT );
175  GQT->initialize();CHECK_ERR( rval );
176 
177  // write to file
178  rval = MBI->write_file( "fcad" );CHECK_ERR( rval );
179 
180  // delete instances
181  delete GTT;
182  delete GQT;
183  delete MBI;
184 
185  // load the file that was written and initialize
186  MBI = new moab::Core();
187  rval = MBI->load_file( "fcad" ); // open the
188  CHECK_ERR( rval );
189  GTT = new GeomTopoTool( MBI, true, 0 );
190  GQT = new GeomQueryTool( GTT );
191  rval = GQT->initialize();CHECK_ERR( rval );
192 
193  // remove generated test file
194  remove( "fcad" );
195 
196  // now perform full ray fire
197  double eps = 1.e-6;
198  int vol_idx = 1;
199  // note model is cube of side 10, centred at 0,0,0, so ray fire along
200  // any unit direction should be exactly 5.0
201  double xyz[3] = { 0.0, 0.0, 0.0 };
202  double dir[3] = { 0.0, 0.0, 1.0 };
203  EntityHandle next_surf;
204  double next_surf_dist;
205  double expect_next_surf_dist = 5.0;
206  EntityHandle vol_h;
207 
208  // get volume handle to fire on
209  vol_h = GQT->gttool()->entity_by_id( 3, vol_idx );
210  // test ray fire
211  rval = GQT->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval );
212  CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps );
213 }

References CHECK_ERR, CHECK_REAL_EQUAL, moab::GeomTopoTool::entity_by_id(), eps, ErrorCode, GQT, GTT, moab::GeomQueryTool::gttool(), moab::GeomQueryTool::initialize(), input_file, moab::Interface::load_file(), MBI, moab::GeomQueryTool::ray_fire(), and moab::Interface::write_file().

Referenced by main().

◆ main()

int main ( int  ,
char **   
)

Definition at line 346 of file gqt_simple_test.cpp.

347 {
348  int result = 0;
349 
350  result += RUN_TEST( gqt_load_file ); // test ray fire
351  result += RUN_TEST( gqt_build_obb ); // build the obb
352  result += RUN_TEST( gqt_create_impl_compl ); // build the obb
353  result += RUN_TEST( gqt_num_vols ); // make sure the num of vols correct
354  cleanup();
355 
356  result += RUN_TEST( gqt_load_file_dagmc_build_obb ); //
357  cleanup();
358 
360  cleanup();
361 
363  cleanup();
364 
365  result += RUN_TEST( gqt_test_obb_retreval ); // check that we are retreving loaded obbs
366  cleanup();
367 
368  result += RUN_TEST( gqt_test_obb_retreval_rayfire ); // check that we can ray fire on loaded obbs
369  cleanup();
370 
371  result += RUN_TEST( gqt_point_in ); // check entity by point
372  cleanup();
373 
374  result += RUN_TEST( gqt_rayfire ); // ensure ray fire distance is correct
375  result += RUN_TEST( gqt_closest_to ); // check the distance to surface nearest point
376  result += RUN_TEST( gqt_test_boundary ); // check particle entering leaving
377  cleanup();
378 
379  return result;
380 }

References cleanup(), gqt_build_obb(), gqt_closest_to(), gqt_create_impl_compl(), gqt_load_file(), gqt_load_file_dagmc_build_obb(), gqt_load_file_dagmc_internal_build_obb(), gqt_load_file_dagmc_via_moab_build_obb(), gqt_num_vols(), gqt_point_in(), gqt_rayfire(), gqt_test_boundary(), gqt_test_obb_retreval(), gqt_test_obb_retreval_rayfire(), and RUN_TEST.

Variable Documentation

◆ GQT

◆ GTT

◆ input_file

◆ MBI