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 std::string input_file = TestDir + "unittest/test_geom.h5m"; 00029 00030 void dagmc_setup_test() 00031 { 00032 ErrorCode rval = DAG->load_file( input_file.c_str() ); // open the Dag file 00033 CHECK_ERR( rval ); 00034 rval = DAG->init_OBBTree();CHECK_ERR( rval ); 00035 00036 /* 00037 int num_vols = DAG->num_entities(3); 00038 EntityHandle vol; 00039 for (int i = 0; i < num_vols; i++) 00040 vol = DAG->entity_by_index(3, i); 00041 */ 00042 // EntityHandle volume = 12682136550675316765; 00043 // CHECK_EQUAL(volume, vol); 00044 } 00045 00046 void dagmc_point_in() 00047 { 00048 int result = 0; 00049 int expected_result = 1; 00050 double xyz[3] = { 0.0, 0.0, 0.0 }; 00051 int vol_idx = 1; 00052 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00053 ErrorCode rval = DAG->point_in_volume( vol_h, xyz, result );CHECK_ERR( rval ); 00054 CHECK_EQUAL( expected_result, result ); 00055 } 00056 00057 int dagmc_point_in_vol_dir( double origin[3], double dir[3], int vol_idx ) 00058 { 00059 int result = 0; 00060 EntityHandle vol_h = DAG->entity_by_index( 3, vol_idx ); 00061 double xyz[3]; 00062 double next_surf_dist; 00063 EntityHandle next_surf; 00064 00065 // normalise the vector 00066 double dir_norm = ( dir[0] * dir[0] ) + ( dir[1] * dir[1] ) + ( dir[2] * dir[2] ); 00067 00068 dir[0] = dir[0] / sqrt( dir_norm ); 00069 dir[1] = dir[1] / sqrt( dir_norm ); 00070 dir[2] = dir[2] / sqrt( dir_norm ); 00071 00072 ErrorCode rval = DAG->ray_fire( vol_h, origin, dir, next_surf, next_surf_dist );CHECK_ERR( rval ); 00073 00074 xyz[0] = origin[0] + ( next_surf_dist * dir[0] ); 00075 xyz[1] = origin[1] + ( next_surf_dist * dir[1] ); 00076 xyz[2] = origin[2] + ( next_surf_dist * dir[2] ); 00077 00078 std::cout << xyz[0] << " " << xyz[1] << " " << xyz[2] << std::endl; 00079 00080 rval = DAG->point_in_volume( vol_h, xyz, result, dir );CHECK_ERR( rval ); 00081 return result; 00082 } 00083 00084 void dagmc_point_in_vol_1() 00085 { 00086 double dir[3] = { -1.0, 0.0, 0.0 }; 00087 double origin[3] = { 0.0, 0.0, 0.0 }; 00088 int vol_idx = 1; 00089 int expected_result = 1; 00090 00091 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00092 CHECK_EQUAL( expected_result, result ); 00093 } 00094 00095 void dagmc_point_in_vol_2() 00096 { 00097 int expected_result = 1; 00098 int vol_idx = 1; 00099 double dir[3] = { 1.0, 0.0, 0.0 }; 00100 double origin[3] = { 0.0, 0.0, 0.0 }; 00101 00102 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00103 00104 CHECK_EQUAL( expected_result, result ); 00105 } 00106 00107 void dagmc_point_in_vol_3() 00108 { 00109 int expected_result = 1; 00110 int vol_idx = 1; 00111 double dir[3] = { 0.0, -1.0, 0.0 }; 00112 double origin[3] = { 0.0, 0.0, 0.0 }; 00113 00114 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00115 00116 CHECK_EQUAL( expected_result, result ); 00117 } 00118 00119 void dagmc_point_in_vol_4() 00120 { 00121 int expected_result = 1; 00122 int vol_idx = 1; 00123 double dir[3] = { 0.0, 1.0, 0.0 }; 00124 double origin[3] = { 0.0, 0.0, 0.0 }; 00125 00126 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00127 00128 CHECK_EQUAL( expected_result, result ); 00129 } 00130 00131 void dagmc_point_in_vol_5() 00132 { 00133 int expected_result = 1; 00134 int vol_idx = 1; 00135 double dir[3] = { 0.0, 0.0, -1.0 }; 00136 double origin[3] = { 0.0, 0.0, 0.0 }; 00137 00138 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00139 00140 CHECK_EQUAL( expected_result, result ); 00141 } 00142 00143 void dagmc_point_in_vol_6() 00144 { 00145 int expected_result = 1; 00146 int vol_idx = 1; 00147 double dir[3] = { 0.0, 0.0, 1.0 }; 00148 double origin[3] = { 0.0, 0.0, 0.0 }; 00149 00150 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00151 00152 CHECK_EQUAL( expected_result, result ); 00153 } 00154 00155 void dagmc_point_on_corner_1() 00156 { 00157 int expected_result = 1; 00158 int vol_idx = 1; 00159 double dir[3] = { 1.0, 1.0, 1.0 }; 00160 double origin[3] = { 0.0, 0.0, 0.0 }; 00161 00162 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00163 00164 CHECK_EQUAL( expected_result, result ); 00165 } 00166 00167 void dagmc_point_on_corner_2() 00168 { 00169 int expected_result = 1; 00170 int vol_idx = 1; 00171 double dir[3] = { -1.0, 1.0, 1.0 }; 00172 double origin[3] = { 0.0, 0.0, 0.0 }; 00173 00174 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00175 00176 CHECK_EQUAL( expected_result, result ); 00177 } 00178 00179 void dagmc_point_on_corner_3() 00180 { 00181 int expected_result = 1; 00182 int vol_idx = 1; 00183 double dir[3] = { 1.0, 1.0, -1.0 }; 00184 double origin[3] = { 0.0, 0.0, 0.0 }; 00185 00186 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00187 00188 CHECK_EQUAL( expected_result, result ); 00189 } 00190 00191 void dagmc_point_on_corner_4() 00192 { 00193 int expected_result = 1; 00194 int vol_idx = 1; 00195 double dir[3] = { -1.0, 1.0, -1.0 }; 00196 double origin[3] = { 0.0, 0.0, 0.0 }; 00197 00198 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00199 00200 CHECK_EQUAL( expected_result, result ); 00201 } 00202 00203 void dagmc_point_on_corner_5() 00204 { 00205 int expected_result = 1; 00206 int vol_idx = 1; 00207 double dir[3] = { 1.0, -1.0, 1.0 }; 00208 double origin[3] = { 0.0, 0.0, 0.0 }; 00209 00210 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00211 00212 CHECK_EQUAL( expected_result, result ); 00213 } 00214 00215 void dagmc_point_on_corner_6() 00216 { 00217 int expected_result = 1; 00218 int vol_idx = 1; 00219 double dir[3] = { -1.0, -1.0, 1.0 }; 00220 double origin[3] = { 0.0, 0.0, 0.0 }; 00221 00222 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00223 00224 CHECK_EQUAL( expected_result, result ); 00225 } 00226 00227 void dagmc_point_on_corner_7() 00228 { 00229 int expected_result = 1; 00230 int vol_idx = 1; 00231 double dir[3] = { 1.0, -1.0, -1.0 }; 00232 double origin[3] = { 0.0, 0.0, 0.0 }; 00233 00234 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00235 00236 CHECK_EQUAL( expected_result, result ); 00237 } 00238 00239 void dagmc_point_on_corner_8() 00240 { 00241 int expected_result = 1; 00242 int vol_idx = 1; 00243 double dir[3] = { -1.0, -1.0, -1.0 }; 00244 double origin[3] = { 0.0, 0.0, 0.0 }; 00245 00246 int result = dagmc_point_in_vol_dir( origin, dir, vol_idx ); 00247 00248 CHECK_EQUAL( expected_result, result ); 00249 } 00250 00251 int main( int /* argc */, char** /* argv */ ) 00252 { 00253 int result = 0; 00254 00255 DAG = new DagMC(); 00256 00257 result += RUN_TEST( dagmc_setup_test ); // setup problem 00258 result += RUN_TEST( dagmc_point_in ); // point in centre 00259 // rays fired along cardinal directions 00260 result += RUN_TEST( dagmc_point_in_vol_1 ); // point in centre 00261 result += RUN_TEST( dagmc_point_in_vol_2 ); // point in centre 00262 result += RUN_TEST( dagmc_point_in_vol_3 ); // point in centre 00263 result += RUN_TEST( dagmc_point_in_vol_4 ); // point in centre 00264 result += RUN_TEST( dagmc_point_in_vol_5 ); // point in centre 00265 result += RUN_TEST( dagmc_point_in_vol_6 ); // point in centre 00266 // rays fired at nodes 00267 result += RUN_TEST( dagmc_point_on_corner_1 ); 00268 result += RUN_TEST( dagmc_point_on_corner_2 ); 00269 result += RUN_TEST( dagmc_point_on_corner_3 ); 00270 result += RUN_TEST( dagmc_point_on_corner_4 ); 00271 00272 // result += RUN_TEST(dagmc_point_in({0.0, 0.0, 5.0}); // point in centre 00273 // result += RUN_TEST(dagmc_point_in({0.0, 0.0, -5.0}); // point in centre 00274 // result += RUN_TEST(dagmc_point_in({0.0, 5.0, 0.0}); // point in centre 00275 // result += RUN_TEST(dagmc_point_in({0.0, -5.0, 0.0}); // point in centre 00276 // result += RUN_TEST(dagmc_point_in({5.0, 0.0, 0.0}); // point in centre 00277 // result += RUN_TEST(dagmc_point_in({-5.0, 0.0, 0.0}); // point in centre 00278 00279 delete DAG; 00280 00281 return result; 00282 }