MOAB: Mesh Oriented datABase  (version 5.5.0)
dagmc_rayfire_test.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include "moab/Interface.hpp"
3 #ifndef IS_BUILDING_MB
4 #define IS_BUILDING_MB
5 #endif
6 #include "TestUtil.hpp"
7 #include "Internals.hpp"
8 #include "moab/Core.hpp"
9 #include "moab/GeomQueryTool.hpp"
10 
11 #include "DagMC.hpp"
12 
13 using namespace moab;
14 
15 using moab::DagMC;
16 
17 DagMC* DAG;
18 
19 #define CHKERR( A ) \
20  do \
21  { \
22  if( MB_SUCCESS != ( A ) ) \
23  { \
24  std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \
25  return A; \
26  } \
27  } while( false )
28 
29 std::string input_file = TestDir + "unittest/test_geom.h5m";
30 
31 double eps = 1.0e-6;
32 
34 {
35  ErrorCode rval = DAG->load_file( input_file.c_str() ); // open the Dag file
36  CHECK_ERR( rval );
37  rval = DAG->init_OBBTree();CHECK_ERR( rval );
38 
39  /*
40  int num_vols = DAG->num_entities(3);
41  EntityHandle vol_h;
42  for (int i = 0; i < num_vols; i++)
43  vol_h = DAG->entity_by_index(3, i);
44  */
45  // EntityHandle volume = 12682136550675316765;
46  // CHECK_EQUAL(volume, vol);
47 }
48 
50 {
51  int vol_idx = 1;
52  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
53  double dir[3] = { -1.0, 0.0, 0.0 };
54  double origin[3] = { 0.0, 0.0, 0.0 };
55  double next_surf_dist;
56  EntityHandle next_surf;
57  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
58  double expected_next_surf_dist = 5.0;
59  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
60 }
61 
63 {
64  int vol_idx = 1;
65  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
66  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
67  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
68  double next_surf_dist;
69  EntityHandle next_surf;
70  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );
71  std::cout << next_surf_dist << std::endl;
72  double expected_next_surf_dist = 15.0;
73  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
74 }
75 
77 {
78  DagMC::RayHistory history;
79  int vol_idx = 1;
80  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
81  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
82  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
83  double next_surf_dist;
84  EntityHandle next_surf;
85  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
86  std::cout << next_surf_dist << std::endl;
87  double expected_next_surf_dist = 15.0;
88  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
89 }
90 
92 {
93  DagMC::RayHistory history;
94  int vol_idx = 1;
95  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
96  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
97  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
98  double next_surf_dist;
99  EntityHandle next_surf;
100  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0.0, -1 );
101  std::cout << next_surf_dist << std::endl;
102  double expected_next_surf_dist = 5.0;
103  CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps );
104 }
105 
107 {
108  DagMC::RayHistory history;
109  int vol_idx = 1;
110  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
111  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
112  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
113  double xyz[3];
114  double next_surf_dist;
115  EntityHandle next_surf;
116 
117  history.reset();
118 
119  // ray fired exactly along boundary shared by 2 facets on a single surface,
120  // needs two ray_fires to cross, this is expected and ok
121 
122  // first ray fire with history
123  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
124  // second ray fire with history
125  DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
126  // this fire should hit graveyard, i.e. next_surf = 0
127  DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
128 
129  // using history with this geom, there should be no next surface, i.e. 0
130  EntityHandle ZERO = 0;
131  CHECK_EQUAL( ZERO, next_surf );
132 }
133 
135 {
136  DagMC::RayHistory history;
137  int vol_idx = 1;
138  EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx );
139  double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction
140  double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0
141  double xyz[3];
142  double next_surf_dist;
143  EntityHandle next_surf;
144 
145  history.reset();
146  // first ray fire with history
147  DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 );
148  std::cout << next_surf << " " << history.size() << std::endl;
149  // second ray fire with history
150 
151  xyz[0] = origin[0] + ( next_surf_dist * dir[0] );
152  xyz[1] = origin[1] + ( next_surf_dist * dir[1] );
153  xyz[2] = origin[2] + ( next_surf_dist * dir[2] );
154 
155  // ray fired execacyl
156 
157  DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
158 
159  DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 );
160 
161  // using history with this geom, there should be no next surface, i.e. 0
162  EntityHandle ZERO = 0;
163  CHECK_EQUAL( ZERO, next_surf );
164 }
165 
166 int main( int /* argc */, char** /* argv */ )
167 {
168  int result = 0;
169 
170  DAG = new DagMC();
171 
172  result += RUN_TEST( dagmc_setup_test ); // setup problem
173  // rays fired along cardinal directions
174  result += RUN_TEST( dagmc_origin_face_rayfire ); // point in centre
176  result += RUN_TEST( dagmc_outside_face_rayfire_orient_exit ); // fire ray from point outside volume
177  // looking for exit intersections
178  result += RUN_TEST( dagmc_outside_face_rayfire_orient_entrance ); // fire ray from point outside volume looking
179  // for entrance intersection
180  result += RUN_TEST( dagmc_outside_face_rayfire_history_fail ); // fire ray from point outside
181  // geometry using ray history
182  result += RUN_TEST( dagmc_outside_face_rayfire_history ); // fire ray from point outside
183  // geometry using ray history
184 
185  delete DAG;
186 
187  return result;
188 }