29 std::string sourceFile, targetFile, intersectionFile, mapEdgeTargetFile;
34 intersectionFile =
"intx_edges.h5m";
35 mapEdgeTargetFile =
"target_edge.nc";
38 opts.
addOpt< std::string >(
"source,s",
"first mesh filename (source)", &sourceFile );
39 opts.
addOpt< std::string >(
"target,t",
"second mesh filename (target)", &targetFile );
40 opts.
addOpt< std::string >(
"intersectionFile,i",
"output intersection file", &intersectionFile );
41 opts.
addOpt< std::string >(
"edgeTarget,p",
"output map edge target file", &mapEdgeTargetFile );
44 double epsrel = 1.e-12;
45 double boxeps = 1.e-4;
46 double areaTolerance = 5.e-12;
47 intersectionFile =
"intx.h5m";
48 opts.
addOpt<
double >(
"radius,R",
"radius for model intx", &
R );
49 opts.
addOpt<
double >(
"epsilon,e",
"relative error in intx", &epsrel );
50 opts.
addOpt<
double >(
"boxerror,b",
"relative error for box boundaries", &boxeps );
51 opts.
addOpt<
double >(
"areaTol,a",
"area recovery tolerance", &areaTolerance );
53 opts.
addOpt<
void >(
"writeFiles,w",
"write files of interest" );
54 opts.
addOpt<
void >(
"kdtreeOption,k",
"use kd tree for intersection" );
58 bool write_files_rank = opts.
numOptSet(
"writeFiles" ) > 0;
59 bool brute_force = opts.
numOptSet(
"kdtreeOption" ) > 0;
61 int rank = 0, size = 1;
63 MPI_Init( &argc, &argv );
64 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
65 MPI_Comm_size( MPI_COMM_WORLD, &size );
67 std::string optsRead = ( size == 1 ?
""
68 : std::string(
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION" ) +
69 std::string(
";PARALLEL_RESOLVE_SHARED_ENTS" ) );
82 if( 0 == rank ) std::cout <<
"Loading mesh file " << sourceFile <<
"\n";
84 if( 0 == rank ) std::cout <<
"Loading mesh file " << targetFile <<
"\n";
89 std::cout <<
"Radius: " <<
R <<
"\n";
90 std::cout <<
"relative eps: " << epsrel <<
"\n";
91 std::cout <<
"box eps: " << boxeps <<
"\n";
93 std::cout <<
" use kd tree for intersection \n";
95 std::cout <<
" use advancing front for intersection \n";
97 std::cout <<
" area tolerance:" << areaTolerance <<
"\n";
98 std::cout <<
" target edge file: " << mapEdgeTargetFile <<
"\n";
112 worker.set_error_tolerance(
R * epsrel );
113 worker.set_box_error( boxeps );
115 worker.set_parallel_comm( pcomm );
118 worker.set_radius_source_mesh(
R );
119 worker.set_radius_destination_mesh(
R );
122 rval = worker.FindMaxEdges( sf1, sf2 );
MB_CHK_ERR( rval );
129 rval = worker.build_processor_euler_boxes( sf2, local_verts );
MB_CHK_ERR( rval );
130 if( write_files_rank )
132 std::stringstream outf;
133 outf <<
"second_mesh" << rank <<
".h5m";
139 double elapsed = MPI_Wtime();
141 bool gnomonic =
true;
143 bool include_edges =
true;
144 rval = worker.construct_covering_set( sf1, covering_set, gnomonic, order, include_edges );
MB_CHK_ERR( rval );
145 elapsed = MPI_Wtime() - elapsed;
146 if( 0 == rank ) std::cout <<
"\nTime to communicate the mesh = " << elapsed << std::endl;
147 if( write_files_rank )
149 std::stringstream cof;
150 cof <<
"covering_mesh" << rank <<
".h5m";
158 if( 0 == rank ) std::cout <<
"Computing intersections ..\n";
160 double elapsed = MPI_Wtime();
164 rval = worker.intersect_meshes_kdtree( covering_set, sf2, outputSet );
MB_CHK_SET_ERR( rval,
"failed to intersect meshes with slow method" );
168 rval = worker.intersect_meshes( covering_set, sf2, outputSet );
MB_CHK_SET_ERR( rval,
"failed to intersect meshes" );
171 elapsed = MPI_Wtime() - elapsed;
172 if( 0 == rank ) std::cout <<
"\nTime to compute the intersection between meshes = " << elapsed << std::endl;
174 if( write_files_rank )
176 std::stringstream outf;
177 outf <<
"intersect" << rank <<
".h5m";
182 std::cout <<
"On rank : " << rank <<
" arrival area: " << arrival_area <<
" intersection area:" << intx_area
183 <<
" rel error: " << fabs( ( intx_area - arrival_area ) / arrival_area ) <<
"\n";
186 #ifdef MOAB_HAVE_HDF5_PARALLEL
187 std::ostringstream intx_str;
188 intx_str <<
"p" << pcomm->
size() <<
"_" << intersectionFile;
189 rval =
mb->
write_file( intx_str.str().c_str(), 0,
"PARALLEL=WRITE_PART", &outputSet, 1 );
MB_CHK_SET_ERR( rval,
"failed to write intx file" );
190 if( 0 == rank ) std::cout <<
" Wrote intx file: " << intx_str.str() <<
"\n";
208 &defVal );
MB_CHK_SET_ERR( rval,
"can't create edge recovery fraction tag" );
217 rval = worker.EdgeSplits( areaTolerance );
MB_CHK_SET_ERR( rval,
"failed to compute edge splits for target" );
219 #ifdef MOAB_HAVE_HDF5_PARALLEL
220 std::ostringstream h5mFile;
221 h5mFile <<
"p" << pcomm->
size() <<
"_targetWithEdges.h5m";
222 rval =
mb->
write_file( h5mFile.str().c_str(), 0,
"PARALLEL=WRITE_PART", &sf2, 1 );
MB_CHK_SET_ERR( rval,
"failed to write intx file" );
223 if( 0 == rank ) std::cout <<
" Wrote file with edge mapping info: " << h5mFile.str() <<
"\n";
227 #ifdef MOAB_HAVE_PNETCDF
229 std::ostringstream file_str;
230 file_str <<
"p" << pcomm->
size() <<
"_" << mapEdgeTargetFile;
231 rval = worker.write_edge_map_parallel( file_str.str().c_str() );
MB_CHK_SET_ERR( rval,
"failed to write edge map for target" );
232 if( 0 == rank ) std::cout <<
" Wrote netcdf file with edge mapping info: " << file_str.str() <<
"\n";
234 #ifdef MOAB_HAVE_NETCDF
235 rval = worker.write_edge_map( mapEdgeTargetFile.c_str() );
MB_CHK_SET_ERR( rval,
"failed to write edge map for target" );