16 #include "../tools/mbcoupler/ElemUtil.hpp"
18 #define MBI mb_instance()
37 int main(
int argc,
char** argv )
47 result =
MCNP->initialize_tags();
56 std::cout <<
"Failure reading MCNP file!" << std::endl;
78 std::cout << std::endl <<
"Read in mesh from h5m file." << std::endl << std::endl;
79 std::cout <<
"Querying mesh file..." << std::endl;
83 std::cout <<
"Failure reading h5m file!" << std::endl;
84 std::cerr <<
"Error code: " <<
MBI->get_error_string( MBresult ) <<
" (" << MBresult <<
")" << std::endl;
87 std::cerr <<
"Error message: " << message << std::endl;
97 std::cout <<
"Building KD-Tree..." << std::endl;
106 std::cout <<
"KD-Tree has been built successfully!" << std::endl << std::endl;
107 MBresult =
MBI->write_mesh( (
MCNP->MCNP_filename +
".h5m" ).c_str() );
109 std::cout <<
"Querying mesh file..." << std::endl;
113 std::cout <<
"Error building KD-Tree!" << std::endl << std::endl;
114 std::cerr <<
"Error code: " <<
MBI->get_error_string( MBresult ) <<
" (" << MBresult <<
")" << std::endl;
117 std::cerr <<
"Error message: " << message << std::endl;
131 std::ifstream cadfile;
132 std::ofstream outfile;
145 double* cfd_coords = NULL;
152 cadfile.getline( line, 10000 );
153 cadfile.getline( line, 10000 );
154 result =
next_int( line, num_pts, p );
161 assert( 0 != meshset );
165 num_pts = cfd_verts.
size();
167 cfd_coords =
new double[3 * num_pts];
168 MBresult =
MBI->get_coords( cfd_verts, cfd_coords );
MB_CHK_ERR( MBresult );
170 cfd_iter = cfd_verts.
begin();
176 std::cout << std::endl <<
"Read in mesh with query points." << std::endl << std::endl;
180 double transformed_pt[3];
189 std::vector< moab::EntityHandle > verts;
195 std::vector< double > coords;
197 double tal_sum = 0.0, err_sum = 0.0, tal_sum_sqr = 0.0, err_sum_sqr = 0.0;
202 for(
unsigned int i = 0; i < (
unsigned int)num_pts; i++ )
211 cadfile.getline( line, 10000 );
213 nl = std::strtol( line, &ctmp, 10 );
214 n = (
unsigned int)
nl;
215 testpt[0] = std::strtod( ctmp + 1, &ctmp );
216 testpt[1] = std::strtod( ctmp + 1, &ctmp );
217 testpt[2] = std::strtod( ctmp + 1, NULL );
221 testpt[0] = cfd_coords[3 * i];
222 testpt[1] = cfd_coords[3 * i + 1];
223 testpt[2] = cfd_coords[3 * i + 2];
227 result =
MCNP->transform_point( testpt, transformed_pt, coord_sys, rmatrix );
229 testvc[0] = transformed_pt[0];
230 testvc[1] = transformed_pt[1];
231 testvc[2] = transformed_pt[2];
235 MBresult = kdtree.
point_search( transformed_pt, tree_node );
238 double x = 0.0, y = 0.0, z = 0.0;
247 x = testvc[0] * cos( 2 * M_PI * testvc[2] );
248 y = testvc[0] * sin( 2 * M_PI * testvc[2] );
253 std::cout <<
"MOAB WARNING: Unhandled error code during point search in KdTree, "
255 << MBresult <<
" and Coord xyz=" << x <<
" " << y <<
" " << z << std::endl;
257 std::cout <<
"No leaf found, MCNP coord xyz=" << x <<
" " << y <<
" " << z << std::endl;
274 MBresult =
MBI->get_connectivity( *rit, connect, num_connect,
true );
MB_CHK_ERR( MBresult );
276 coords.resize( 3 * num_connect );
277 MBresult =
MBI->get_coords( connect, num_connect, &coords[0] );
MB_CHK_ERR( MBresult );
279 for(
unsigned int j = 0; j < (
unsigned int)num_connect; j++ )
281 hexverts[j][0] = coords[3 * j];
282 hexverts[j][1] = coords[3 * j + 1];
283 hexverts[j][2] = coords[3 * j + 2];
288 MBresult =
MBI->tag_get_data(
MCNP->tally_tag, &( *rit ), 1, &taldata );
MB_CHK_ERR( MBresult );
289 MBresult =
MBI->tag_get_data(
MCNP->relerr_tag, &( *rit ), 1, &errdata );
MB_CHK_ERR( MBresult );
291 outfile << n <<
"," << testpt[0] <<
"," << testpt[1] <<
"," << testpt[2] <<
"," << taldata <<
","
292 << errdata << std::endl;
303 tal_sum = tal_sum + taldata;
304 err_sum = err_sum + errdata;
305 tal_sum_sqr = tal_sum_sqr + taldata * taldata;
306 err_sum_sqr = err_sum_sqr + errdata * errdata;
316 std::cout << n <<
" " << testvc << std::endl;
326 std::cout <<
"Success! " << elems_read <<
" elements interpolated." << std::endl << std::endl;
330 std::cout <<
"Failure during query! " << elems_read <<
" elements interpolated." << std::endl << std::endl;
333 double tal_std_dev = sqrt( ( 1.0 / elems_read ) * ( tal_sum_sqr - ( 1.0 / elems_read ) * tal_sum * tal_sum ) );
334 double err_std_dev = sqrt( ( 1.0 / elems_read ) * ( err_sum_sqr - ( 1.0 / elems_read ) * err_sum * err_sum ) );
336 std::cout <<
"Tally Mean: " << tal_sum / elems_read << std::endl;
337 std::cout <<
"Tally Standard Deviation: " << tal_std_dev << std::endl;
338 std::cout <<
"Error Mean: " << err_sum / elems_read << std::endl;
339 std::cout <<
"Error Standard Deviation: " << err_std_dev << std::endl;
346 MBresult =
MBI->write_mesh( ( out_mesh_fname +
".h5m" ).c_str(), &meshset, 1 );
351 std::cout <<
"Time to read in file: " << (double)
load_time / CLOCKS_PER_SEC << std::endl;
352 std::cout <<
"Time to build kd-tree: " << (double)
build_time / CLOCKS_PER_SEC << std::endl;
353 std::cout <<
"Time to interpolate data: " << (double)
interp_time / CLOCKS_PER_SEC << std::endl;
365 std::cout <<
"Source and Target mesh filenames NOT specified!";
366 std::cout << std::endl;
374 unsigned int itmp = str.find(
".h5m" );
375 if( ( itmp > 0 ) && ( itmp < str.length() ) )
382 result =
MCNP->set_filename( str );
389 itmp = str.find(
".qnv" );
390 if( ( itmp > 0 ) && ( itmp < str.length() ) )
read_qnv =
true;
402 unsigned int slen = s.length();
405 for(
unsigned int i = p; i < slen; i++ )
407 if( ( ( s[i] >= 48 ) && ( s[i] <= 57 ) ) || ( s[i] == 45 ) )
410 j = s.find(
",", i );
411 if( j > slen ) j = slen;
413 d = std::atof( s.substr( i, j - i ).c_str() );
426 unsigned int slen = s.length();
429 for(
unsigned int i = p; i < slen; i++ )
431 if( ( ( s[i] >= 48 ) && ( s[i] <= 57 ) ) || ( s[i] == 45 ) )
434 j = s.find(
",", i );
435 if( j > slen ) j = slen;
437 k = std::atoi( s.substr( i, j - i ).c_str() );