MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #include <iostream> 00002 #include "moab/Interface.hpp" 00003 #ifndef IS_BUILDING_MB 00004 #define IS_BUILDING_MB 00005 #endif 00006 #include "TestUtil.hpp" 00007 #include "Internals.hpp" 00008 #include "moab/Core.hpp" 00009 #include "moab/GeomQueryTool.hpp" 00010 00011 #include "DagMC.hpp" 00012 00013 using namespace moab; 00014 00015 using moab::DagMC; 00016 00017 DagMC* DAG; 00018 00019 #define CHKERR( A ) \ 00020 do \ 00021 { \ 00022 if( MB_SUCCESS != ( A ) ) \ 00023 { \ 00024 std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \ 00025 return A; \ 00026 } \ 00027 } while( false ) 00028 00029 std::string input_file = TestDir + "unittest/test_geom.h5m"; 00030 00031 double eps = 1.0e-6; 00032 00033 void dagmc_setup_test() 00034 { 00035 ErrorCode rval = DAG->load_file( input_file.c_str() ); // open the Dag file 00036 CHECK_ERR( rval ); 00037 rval = DAG->init_OBBTree();CHECK_ERR( rval ); 00038 00039 /* 00040 int num_vols = DAG->num_entities(3); 00041 EntityHandle vol_h; 00042 for (int i = 0; i < num_vols; i++) 00043 vol_h = DAG->entity_by_index(3, i); 00044 */ 00045 // EntityHandle volume = 12682136550675316765; 00046 // CHECK_EQUAL(volume, vol); 00047 } 00048 00049 void dagmc_origin_face_rayfire() 00050 { 00051 int vol_idx = 1; 00052 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00053 double dir[3] = { -1.0, 0.0, 0.0 }; 00054 double origin[3] = { 0.0, 0.0, 0.0 }; 00055 double next_surf_dist; 00056 EntityHandle next_surf; 00057 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist ); 00058 double expected_next_surf_dist = 5.0; 00059 CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps ); 00060 } 00061 00062 void dagmc_outside_face_rayfire() 00063 { 00064 int vol_idx = 1; 00065 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00066 double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction 00067 double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0 00068 double next_surf_dist; 00069 EntityHandle next_surf; 00070 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist ); 00071 std::cout << next_surf_dist << std::endl; 00072 double expected_next_surf_dist = 15.0; 00073 CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps ); 00074 } 00075 00076 void dagmc_outside_face_rayfire_orient_exit() 00077 { 00078 DagMC::RayHistory history; 00079 int vol_idx = 1; 00080 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00081 double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction 00082 double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0 00083 double next_surf_dist; 00084 EntityHandle next_surf; 00085 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00086 std::cout << next_surf_dist << std::endl; 00087 double expected_next_surf_dist = 15.0; 00088 CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps ); 00089 } 00090 00091 void dagmc_outside_face_rayfire_orient_entrance() 00092 { 00093 DagMC::RayHistory history; 00094 int vol_idx = 1; 00095 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00096 double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction 00097 double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0 00098 double next_surf_dist; 00099 EntityHandle next_surf; 00100 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0.0, -1 ); 00101 std::cout << next_surf_dist << std::endl; 00102 double expected_next_surf_dist = 5.0; 00103 CHECK_REAL_EQUAL( expected_next_surf_dist, next_surf_dist, eps ); 00104 } 00105 00106 void dagmc_outside_face_rayfire_history_fail() 00107 { 00108 DagMC::RayHistory history; 00109 int vol_idx = 1; 00110 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00111 double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction 00112 double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0 00113 double xyz[3]; 00114 double next_surf_dist; 00115 EntityHandle next_surf; 00116 00117 history.reset(); 00118 00119 // ray fired exactly along boundary shared by 2 facets on a single surface, 00120 // needs two ray_fires to cross, this is expected and ok 00121 00122 // first ray fire with history 00123 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00124 // second ray fire with history 00125 DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00126 // this fire should hit graveyard, i.e. next_surf = 0 00127 DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00128 00129 // using history with this geom, there should be no next surface, i.e. 0 00130 EntityHandle ZERO = 0; 00131 CHECK_EQUAL( ZERO, next_surf ); 00132 } 00133 00134 void dagmc_outside_face_rayfire_history() 00135 { 00136 DagMC::RayHistory history; 00137 int vol_idx = 1; 00138 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00139 double dir[3] = { 1.0, 0.0, 0.0 }; // ray along x direction 00140 double origin[3] = { -10.0, 0.0, 0.0 }; // origin at -10 0 0 00141 double xyz[3]; 00142 double next_surf_dist; 00143 EntityHandle next_surf; 00144 00145 history.reset(); 00146 // first ray fire with history 00147 DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00148 std::cout << next_surf << " " << history.size() << std::endl; 00149 // second ray fire with history 00150 00151 xyz[0] = origin[0] + ( next_surf_dist * dir[0] ); 00152 xyz[1] = origin[1] + ( next_surf_dist * dir[1] ); 00153 xyz[2] = origin[2] + ( next_surf_dist * dir[2] ); 00154 00155 // ray fired execacyl 00156 00157 DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00158 00159 DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist, &history, 0, 1 ); 00160 00161 // using history with this geom, there should be no next surface, i.e. 0 00162 EntityHandle ZERO = 0; 00163 CHECK_EQUAL( ZERO, next_surf ); 00164 } 00165 00166 int main( int /* argc */, char** /* argv */ ) 00167 { 00168 int result = 0; 00169 00170 DAG = new DagMC(); 00171 00172 result += RUN_TEST( dagmc_setup_test ); // setup problem 00173 // rays fired along cardinal directions 00174 result += RUN_TEST( dagmc_origin_face_rayfire ); // point in centre 00175 result += RUN_TEST( dagmc_outside_face_rayfire ); 00176 result += RUN_TEST( dagmc_outside_face_rayfire_orient_exit ); // fire ray from point outside volume 00177 // looking for exit intersections 00178 result += RUN_TEST( dagmc_outside_face_rayfire_orient_entrance ); // fire ray from point outside volume looking 00179 // for entrance intersection 00180 result += RUN_TEST( dagmc_outside_face_rayfire_history_fail ); // fire ray from point outside 00181 // geometry using ray history 00182 result += RUN_TEST( dagmc_outside_face_rayfire_history ); // fire ray from point outside 00183 // geometry using ray history 00184 00185 delete DAG; 00186 00187 return result; 00188 }