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 00010 #include "DagMC.hpp" 00011 00012 using namespace moab; 00013 00014 using moab::DagMC; 00015 00016 DagMC* DAG; 00017 00018 #define CHKERR( A ) \ 00019 do \ 00020 { \ 00021 if( MB_SUCCESS != ( A ) ) \ 00022 { \ 00023 std::cerr << "Failure (error code " << ( A ) << ") at " __FILE__ ":" << __LINE__ << std::endl; \ 00024 return A; \ 00025 } \ 00026 } while( false ) 00027 00028 const std::string input_file = TestDir + "unittest/test_geom.h5m"; 00029 00030 void dagmc_load_file() 00031 { 00032 ErrorCode rval = DAG->load_file( input_file.c_str() ); // open the Dag file 00033 CHECK_ERR( rval ); 00034 } 00035 00036 void dagmc_load_file_dagmc() 00037 { 00038 /* 1 - Test with external moab, load file in DAGMC*/ 00039 // make new moab core 00040 Core* mbi = new moab::Core(); 00041 // make new dagmc into that moab 00042 DagMC* dagmc = new moab::DagMC( mbi ); 00043 00044 ErrorCode rval; 00045 // load a file 00046 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00047 00048 // delete dagmc 00049 delete dagmc; 00050 delete mbi; 00051 } 00052 00053 void dagmc_load_file_dagmc_via_moab() 00054 { 00055 /* 2 - Test with external moab, load file in MOAB*/ 00056 // load the file into moab rather than dagmc 00057 ErrorCode rval; 00058 00059 moab::Core* mbi = new moab::Core(); 00060 rval = mbi->load_file( input_file.c_str() );CHECK_ERR( rval ); 00061 moab::DagMC* dagmc = new moab::DagMC( mbi ); 00062 rval = dagmc->load_existing_contents();CHECK_ERR( rval ); 00063 00064 // delete dagmc; 00065 delete dagmc; 00066 delete mbi; 00067 } 00068 00069 void dagmc_load_file_dagmc_internal() 00070 { 00071 /* 3 - Test with internal moab, load file in DAG*/ 00072 // make new dagmc into that moab 00073 ErrorCode rval; 00074 00075 moab::DagMC* dagmc = new moab::DagMC(); 00076 // load a file 00077 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00078 delete dagmc; 00079 } 00080 00081 void dagmc_load_file_dagmc_build_obb() 00082 { 00083 /* 1 - Test with external moab, load file in DAGMC*/ 00084 // make new moab core 00085 ErrorCode rval; 00086 00087 moab::Core* mbi = new moab::Core(); 00088 // make new dagmc into that moab 00089 DagMC* dagmc = new moab::DagMC( mbi ); 00090 00091 // load a file 00092 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00093 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00094 // delete dagmc 00095 delete dagmc; 00096 delete mbi; 00097 } 00098 00099 void dagmc_load_file_dagmc_via_moab_build_obb() 00100 { 00101 /* 2 - Test with external moab, load file in MOAB*/ 00102 // load the file into moab rather than dagmc 00103 ErrorCode rval; 00104 00105 moab::Core* mbi = new moab::Core(); 00106 rval = mbi->load_file( input_file.c_str() );CHECK_ERR( rval ); 00107 moab::DagMC* dagmc = new moab::DagMC( mbi ); 00108 rval = dagmc->load_existing_contents();CHECK_ERR( rval ); 00109 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00110 00111 // delete dagmc; 00112 delete dagmc; 00113 delete mbi; 00114 } 00115 00116 void dagmc_load_file_dagmc_internal_build_obb() 00117 { 00118 /* 3 - Test with internal moab, load file in DAG*/ 00119 // make new dagmc into that moab 00120 ErrorCode rval; 00121 00122 moab::DagMC* dagmc = new moab::DagMC(); 00123 // load a file 00124 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00125 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00126 delete dagmc; 00127 } 00128 00129 void dagmc_test_obb_retreval() 00130 { 00131 // make new dagmc 00132 std::cout << "test_obb_retreval" << std::endl; 00133 00134 DagMC* dagmc = new moab::DagMC(); 00135 00136 ErrorCode rval; 00137 // load a file 00138 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00139 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00140 00141 // write the file 00142 rval = dagmc->write_mesh( "fcad", 4 ); 00143 00144 // now remove the dagmc instance a 00145 delete dagmc; 00146 00147 dagmc = new moab::DagMC(); 00148 rval = dagmc->load_file( "fcad" );CHECK_ERR( rval ); 00149 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00150 00151 // delete the fcad file 00152 remove( "fcad" ); 00153 delete dagmc; 00154 } 00155 00156 void dagmc_build_obb() 00157 { 00158 ErrorCode rval = DAG->init_OBBTree();CHECK_ERR( rval ); 00159 } 00160 00161 void dagmc_num_vols() 00162 { 00163 int expect_num_vols = 2; 00164 int num_vols = DAG->num_entities( 3 ); 00165 CHECK_EQUAL( expect_num_vols, num_vols ); 00166 } 00167 00168 void dagmc_entity_handle() 00169 { 00170 /* 00171 int num_vols = DAG->num_entities(3); 00172 EntityHandle vol_h; 00173 for (int i = 0; i < num_vols; i++) 00174 vol_h = DAG->entity_by_index(3, i); 00175 */ 00176 // EntityHandle expect_vol_h = 12682136550675316765; 00177 // CHECK_EQUAL(expect_vol_h, vol_h); 00178 } 00179 00180 void dagmc_point_in() 00181 { 00182 int result = 0; 00183 int expect_result = 1; 00184 int vol_idx = 1; 00185 double xyz[3] = { 0.0, 0.0, 0.0 }; 00186 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00187 ErrorCode rval = DAG->point_in_volume( vol_h, xyz, result );CHECK_ERR( rval ); 00188 CHECK_EQUAL( expect_result, result ); 00189 } 00190 00191 void dagmc_test_obb_retreval_rayfire() 00192 { 00193 // make new dagmc 00194 std::cout << "test_obb_retreval and ray_fire" << std::endl; 00195 00196 DagMC* dagmc = new moab::DagMC(); 00197 00198 ErrorCode rval; 00199 // load a file 00200 rval = dagmc->load_file( input_file.c_str() );CHECK_ERR( rval ); 00201 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00202 00203 // write the file 00204 rval = dagmc->write_mesh( "fcad", 4 ); 00205 00206 // now remove the dagmc instance a 00207 delete dagmc; 00208 00209 // now create new DAGMC 00210 dagmc = new moab::DagMC(); 00211 rval = dagmc->load_file( "fcad" );CHECK_ERR( rval ); 00212 rval = dagmc->init_OBBTree();CHECK_ERR( rval ); 00213 00214 // delete the fcad file 00215 remove( "fcad" ); 00216 00217 // now perform full ray fire 00218 double eps = 1.e-6; 00219 int vol_idx = 1; 00220 // note model is cube of side 10, centred at 0,0,0, so ray fire along 00221 // any unit direction should be exactly 5.0 00222 double xyz[3] = { 0.0, 0.0, 0.0 }; 00223 double dir[3] = { 0.0, 0.0, 1.0 }; 00224 EntityHandle next_surf; 00225 double next_surf_dist; 00226 double expect_next_surf_dist = 5.0; 00227 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00228 00229 rval = DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval ); 00230 CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps ); 00231 delete dagmc; 00232 } 00233 00234 void dagmc_rayfire() 00235 { 00236 const double eps = 1e-6; // epsilon for test, faceting tol? 00237 00238 int vol_idx = 1; 00239 // note model is cube of side 10, centred at 0,0,0, so ray fire along 00240 // any unit direction should be exactly 5.0 00241 double xyz[3] = { 0.0, 0.0, 0.0 }; 00242 double dir[3] = { 0.0, 0.0, 1.0 }; 00243 EntityHandle next_surf; 00244 double next_surf_dist; 00245 double expect_next_surf_dist = 5.0; 00246 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00247 00248 ErrorCode rval = DAG->ray_fire( vol_h, xyz, dir, next_surf, next_surf_dist );CHECK_ERR( rval ); 00249 CHECK_REAL_EQUAL( expect_next_surf_dist, next_surf_dist, eps ); 00250 } 00251 00252 void dagmc_closest_to() 00253 { 00254 const double eps = 1e-6; // epsilon for test, faceting tol? 00255 00256 int vol_idx = 1; 00257 // note model is cube of side 10, centred at 0,0,0, so ray fire along 00258 // any unit direction should be exactly 5.0 00259 double xyz[3] = { -6.0, 0.0, 0.0 }; 00260 double distance; // distance from point to nearest surface 00261 double expect_distance = 1.0; 00262 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00263 00264 ErrorCode rval = DAG->closest_to_location( vol_h, xyz, distance );CHECK_ERR( rval ); 00265 // distance should be 1.0 cm 00266 CHECK_REAL_EQUAL( expect_distance, distance, eps ); 00267 } 00268 00269 void dagmc_test_boundary() 00270 { 00271 int vol_idx = 1; 00272 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00273 int surf_idx = 1; 00274 EntityHandle surf_h = DAG->entity_by_index( 2, surf_idx ); 00275 00276 double xyz[3] = { 0.0, 0.0, 5.0 }; 00277 double dir[3] = { 0.0, 0.0, 1.0 }; 00278 int result; 00279 int expect_result = 0; 00280 00281 ErrorCode rval = DAG->test_volume_boundary( vol_h, surf_h, xyz, dir, result );CHECK_ERR( rval ); 00282 // check ray leaving volume 00283 CHECK_EQUAL( expect_result, result ); 00284 } 00285 00286 int main( int /* argc */, char** /* argv */ ) 00287 { 00288 int result = 0; 00289 00290 DAG = new moab::DagMC(); 00291 00292 result += RUN_TEST( dagmc_load_file ); // test ray fire 00293 result += RUN_TEST( dagmc_build_obb ); // build the obb 00294 result += RUN_TEST( dagmc_num_vols ); // make sure the num of vols correct 00295 result += RUN_TEST( dagmc_load_file_dagmc ); // 00296 result += RUN_TEST( dagmc_load_file_dagmc_via_moab ); // 00297 result += RUN_TEST( dagmc_load_file_dagmc_internal ); // 00298 result += RUN_TEST( dagmc_load_file_dagmc_build_obb ); // 00299 result += RUN_TEST( dagmc_load_file_dagmc_via_moab_build_obb ); // 00300 result += RUN_TEST( dagmc_load_file_dagmc_internal_build_obb ); // 00301 result += RUN_TEST( dagmc_test_obb_retreval ); // check that we are retreving loaded obbs 00302 result += RUN_TEST( dagmc_test_obb_retreval_rayfire ); // check that we can ray fire on loaded obbs 00303 result += RUN_TEST( dagmc_point_in ); // check entity by point 00304 result += RUN_TEST( dagmc_rayfire ); // ensure ray fire distance is correct 00305 result += RUN_TEST( dagmc_closest_to ); // check the distance to surface nearest point 00306 result += RUN_TEST( dagmc_test_boundary ); // check particle entering leaving 00307 00308 delete DAG; 00309 00310 return result; 00311 }