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

Go to the source code of this file.

Macros

#define IS_BUILDING_MB
 
#define CHKERR(A)
 

Functions

void dagmc_load_file ()
 
void dagmc_load_file_dagmc ()
 
void dagmc_load_file_dagmc_via_moab ()
 
void dagmc_load_file_dagmc_internal ()
 
void dagmc_load_file_dagmc_build_obb ()
 
void dagmc_load_file_dagmc_via_moab_build_obb ()
 
void dagmc_load_file_dagmc_internal_build_obb ()
 
void dagmc_test_obb_retreval ()
 
void dagmc_build_obb ()
 
void dagmc_num_vols ()
 
void dagmc_entity_handle ()
 
void dagmc_point_in ()
 
void dagmc_test_obb_retreval_rayfire ()
 
void dagmc_rayfire ()
 
void dagmc_closest_to ()
 
void dagmc_test_boundary ()
 
int main (int, char **)
 

Variables

DagMC * DAG
 
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 18 of file dagmc_simple_test.cpp.

◆ IS_BUILDING_MB

#define IS_BUILDING_MB

Definition at line 4 of file dagmc_simple_test.cpp.

Function Documentation

◆ dagmc_build_obb()

void dagmc_build_obb ( )

Definition at line 156 of file dagmc_simple_test.cpp.

157 {
158  ErrorCode rval = DAG->init_OBBTree();CHECK_ERR( rval );
159 }

References CHECK_ERR, DAG, and ErrorCode.

Referenced by main().

◆ dagmc_closest_to()

void dagmc_closest_to ( )

Definition at line 252 of file dagmc_simple_test.cpp.

253 {
254  const double eps = 1e-6; // epsilon for test, faceting tol?
255 
256  int vol_idx = 1;
257  // note model is cube of side 10, centred at 0,0,0, so ray fire along
258  // any unit direction should be exactly 5.0
259  double xyz[3] = { -6.0, 0.0, 0.0 };
260  double distance; // distance from point to nearest surface
261  double expect_distance = 1.0;
262  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
263 
264  ErrorCode rval = DAG->closest_to_location( vol_h, xyz, distance );CHECK_ERR( rval );
265  // distance should be 1.0 cm
266  CHECK_REAL_EQUAL( expect_distance, distance, eps );
267 }

References CHECK_ERR, CHECK_REAL_EQUAL, DAG, eps, and ErrorCode.

Referenced by main().

◆ dagmc_entity_handle()

void dagmc_entity_handle ( )

Definition at line 168 of file dagmc_simple_test.cpp.

169 {
170  /*
171  int num_vols = DAG->num_entities(3);
172  EntityHandle vol_h;
173  for (int i = 0; i < num_vols; i++)
174  vol_h = DAG->entity_by_index(3, i);
175  */
176  // EntityHandle expect_vol_h = 12682136550675316765;
177  // CHECK_EQUAL(expect_vol_h, vol_h);
178 }

◆ dagmc_load_file()

void dagmc_load_file ( )

Definition at line 30 of file dagmc_simple_test.cpp.

31 {
32  ErrorCode rval = DAG->load_file( input_file.c_str() ); // open the Dag file
33  CHECK_ERR( rval );
34 }

References CHECK_ERR, DAG, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_load_file_dagmc()

void dagmc_load_file_dagmc ( )

Definition at line 36 of file dagmc_simple_test.cpp.

37 {
38  /* 1 - Test with external moab, load file in DAGMC*/
39  // make new moab core
40  Core* mbi = new moab::Core();
41  // make new dagmc into that moab
42  DagMC* dagmc = new moab::DagMC( mbi );
43 
44  ErrorCode rval;
45  // load a file
46  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
47 
48  // delete dagmc
49  delete dagmc;
50  delete mbi;
51 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_load_file_dagmc_build_obb()

void dagmc_load_file_dagmc_build_obb ( )

Definition at line 81 of file dagmc_simple_test.cpp.

82 {
83  /* 1 - Test with external moab, load file in DAGMC*/
84  // make new moab core
85  ErrorCode rval;
86 
87  moab::Core* mbi = new moab::Core();
88  // make new dagmc into that moab
89  DagMC* dagmc = new moab::DagMC( mbi );
90 
91  // load a file
92  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
93  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
94  // delete dagmc
95  delete dagmc;
96  delete mbi;
97 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_load_file_dagmc_internal()

void dagmc_load_file_dagmc_internal ( )

Definition at line 69 of file dagmc_simple_test.cpp.

70 {
71  /* 3 - Test with internal moab, load file in DAG*/
72  // make new dagmc into that moab
73  ErrorCode rval;
74 
75  moab::DagMC* dagmc = new moab::DagMC();
76  // load a file
77  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
78  delete dagmc;
79 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_load_file_dagmc_internal_build_obb()

void dagmc_load_file_dagmc_internal_build_obb ( )

Definition at line 116 of file dagmc_simple_test.cpp.

117 {
118  /* 3 - Test with internal moab, load file in DAG*/
119  // make new dagmc into that moab
120  ErrorCode rval;
121 
122  moab::DagMC* dagmc = new moab::DagMC();
123  // load a file
124  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
125  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
126  delete dagmc;
127 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_load_file_dagmc_via_moab()

void dagmc_load_file_dagmc_via_moab ( )

Definition at line 53 of file dagmc_simple_test.cpp.

54 {
55  /* 2 - Test with external moab, load file in MOAB*/
56  // load the file into moab rather than dagmc
57  ErrorCode rval;
58 
59  moab::Core* mbi = new moab::Core();
60  rval = mbi->load_file( input_file.c_str() );CHECK_ERR( rval );
61  moab::DagMC* dagmc = new moab::DagMC( mbi );
62  rval = dagmc->load_existing_contents();CHECK_ERR( rval );
63 
64  // delete dagmc;
65  delete dagmc;
66  delete mbi;
67 }

References CHECK_ERR, ErrorCode, input_file, and moab::Core::load_file().

Referenced by main().

◆ dagmc_load_file_dagmc_via_moab_build_obb()

void dagmc_load_file_dagmc_via_moab_build_obb ( )

Definition at line 99 of file dagmc_simple_test.cpp.

100 {
101  /* 2 - Test with external moab, load file in MOAB*/
102  // load the file into moab rather than dagmc
103  ErrorCode rval;
104 
105  moab::Core* mbi = new moab::Core();
106  rval = mbi->load_file( input_file.c_str() );CHECK_ERR( rval );
107  moab::DagMC* dagmc = new moab::DagMC( mbi );
108  rval = dagmc->load_existing_contents();CHECK_ERR( rval );
109  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
110 
111  // delete dagmc;
112  delete dagmc;
113  delete mbi;
114 }

References CHECK_ERR, ErrorCode, input_file, and moab::Core::load_file().

Referenced by main().

◆ dagmc_num_vols()

void dagmc_num_vols ( )

Definition at line 161 of file dagmc_simple_test.cpp.

162 {
163  int expect_num_vols = 2;
164  int num_vols = DAG->num_entities( 3 );
165  CHECK_EQUAL( expect_num_vols, num_vols );
166 }

References CHECK_EQUAL, and DAG.

Referenced by main().

◆ dagmc_point_in()

void dagmc_point_in ( )

Definition at line 180 of file dagmc_simple_test.cpp.

181 {
182  int result = 0;
183  int expect_result = 1;
184  int vol_idx = 1;
185  double xyz[3] = { 0.0, 0.0, 0.0 };
186  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
187  ErrorCode rval = DAG->point_in_volume( vol_h, xyz, result );CHECK_ERR( rval );
188  CHECK_EQUAL( expect_result, result );
189 }

References CHECK_EQUAL, CHECK_ERR, DAG, and ErrorCode.

Referenced by main().

◆ dagmc_rayfire()

void dagmc_rayfire ( )

Definition at line 234 of file dagmc_simple_test.cpp.

235 {
236  const double eps = 1e-6; // epsilon for test, faceting tol?
237 
238  int vol_idx = 1;
239  // note model is cube of side 10, centred at 0,0,0, so ray fire along
240  // any unit direction should be exactly 5.0
241  double xyz[3] = { 0.0, 0.0, 0.0 };
242  double dir[3] = { 0.0, 0.0, 1.0 };
243  EntityHandle next_surf;
244  double next_surf_dist;
245  double expect_next_surf_dist = 5.0;
246  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
247 
248  ErrorCode rval = DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval );
249  CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps );
250 }

References CHECK_ERR, CHECK_REAL_EQUAL, DAG, eps, and ErrorCode.

Referenced by main().

◆ dagmc_test_boundary()

void dagmc_test_boundary ( )

Definition at line 269 of file dagmc_simple_test.cpp.

270 {
271  int vol_idx = 1;
272  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
273  int surf_idx = 1;
274  EntityHandle surf_h = DAG->entity_by_index( 2, surf_idx );
275 
276  double xyz[3] = { 0.0, 0.0, 5.0 };
277  double dir[3] = { 0.0, 0.0, 1.0 };
278  int result;
279  int expect_result = 0;
280 
281  ErrorCode rval = DAG->test_volume_boundary( vol_h, surf_h, xyz, dir, result );CHECK_ERR( rval );
282  // check ray leaving volume
283  CHECK_EQUAL( expect_result, result );
284 }

References CHECK_EQUAL, CHECK_ERR, DAG, and ErrorCode.

Referenced by main().

◆ dagmc_test_obb_retreval()

void dagmc_test_obb_retreval ( )

Definition at line 129 of file dagmc_simple_test.cpp.

130 {
131  // make new dagmc
132  std::cout << "test_obb_retreval" << std::endl;
133 
134  DagMC* dagmc = new moab::DagMC();
135 
136  ErrorCode rval;
137  // load a file
138  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
139  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
140 
141  // write the file
142  rval = dagmc->write_mesh( "fcad", 4 );
143 
144  // now remove the dagmc instance a
145  delete dagmc;
146 
147  dagmc = new moab::DagMC();
148  rval = dagmc->load_file( "fcad" );CHECK_ERR( rval );
149  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
150 
151  // delete the fcad file
152  remove( "fcad" );
153  delete dagmc;
154 }

References CHECK_ERR, ErrorCode, and input_file.

Referenced by main().

◆ dagmc_test_obb_retreval_rayfire()

void dagmc_test_obb_retreval_rayfire ( )

Definition at line 191 of file dagmc_simple_test.cpp.

192 {
193  // make new dagmc
194  std::cout << "test_obb_retreval and ray_fire" << std::endl;
195 
196  DagMC* dagmc = new moab::DagMC();
197 
198  ErrorCode rval;
199  // load a file
200  rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval );
201  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
202 
203  // write the file
204  rval = dagmc->write_mesh( "fcad", 4 );
205 
206  // now remove the dagmc instance a
207  delete dagmc;
208 
209  // now create new DAGMC
210  dagmc = new moab::DagMC();
211  rval = dagmc->load_file( "fcad" );CHECK_ERR( rval );
212  rval = dagmc->init_OBBTree();CHECK_ERR( rval );
213 
214  // delete the fcad file
215  remove( "fcad" );
216 
217  // now perform full ray fire
218  double eps = 1.e-6;
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 = DAG->entity_by_index( 3, vol_idx );
228 
229  rval = DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval );
230  CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps );
231  delete dagmc;
232 }

References CHECK_ERR, CHECK_REAL_EQUAL, DAG, eps, ErrorCode, and input_file.

Referenced by main().

◆ main()

int main ( int  ,
char **   
)

Definition at line 286 of file dagmc_simple_test.cpp.

287 {
288  int result = 0;
289 
290  DAG = new moab::DagMC();
291 
292  result += RUN_TEST( dagmc_load_file ); // test ray fire
293  result += RUN_TEST( dagmc_build_obb ); // build the obb
294  result += RUN_TEST( dagmc_num_vols ); // make sure the num of vols correct
295  result += RUN_TEST( dagmc_load_file_dagmc ); //
301  result += RUN_TEST( dagmc_test_obb_retreval ); // check that we are retreving loaded obbs
302  result += RUN_TEST( dagmc_test_obb_retreval_rayfire ); // check that we can ray fire on loaded obbs
303  result += RUN_TEST( dagmc_point_in ); // check entity by point
304  result += RUN_TEST( dagmc_rayfire ); // ensure ray fire distance is correct
305  result += RUN_TEST( dagmc_closest_to ); // check the distance to surface nearest point
306  result += RUN_TEST( dagmc_test_boundary ); // check particle entering leaving
307 
308  delete DAG;
309 
310  return result;
311 }

References DAG, dagmc_build_obb(), dagmc_closest_to(), dagmc_load_file(), dagmc_load_file_dagmc(), dagmc_load_file_dagmc_build_obb(), dagmc_load_file_dagmc_internal(), dagmc_load_file_dagmc_internal_build_obb(), dagmc_load_file_dagmc_via_moab(), dagmc_load_file_dagmc_via_moab_build_obb(), dagmc_num_vols(), dagmc_point_in(), dagmc_rayfire(), dagmc_test_boundary(), dagmc_test_obb_retreval(), dagmc_test_obb_retreval_rayfire(), and RUN_TEST.

Variable Documentation

◆ DAG

◆ input_file