36 std::stringstream sstr;
40 int rank = 0,
size = 1;
42 MPI_Init( &argc, &argv );
43 MPI_Comm_rank( MPI_COMM_WORLD, &rank );
44 MPI_Comm_size( MPI_COMM_WORLD, &
size );
47 std::string sourceFile, targetFile, intxFile;
48 std::string source_verif(
"outS.h5m" ), target_verif(
"outt.h5m" );
50 int oldNamesParents = 0;
51 double areaErrSource = -1;
52 double areaErrTarget = -1;
55 opts.
addOpt< std::string >(
"source,s",
"source file ", &sourceFile );
56 opts.
addOpt< std::string >(
"target,t",
"target file ", &targetFile );
57 opts.
addOpt< std::string >(
"intersection,i",
"intersection file ", &intxFile );
58 opts.
addOpt< std::string >(
"verif_source,v",
"output source verification ", &source_verif );
59 opts.
addOpt< std::string >(
"verif_target,w",
"output target verification ", &target_verif );
60 opts.
addOpt<
double >(
"threshold_source,m",
"error source threshold ", &areaErrSource );
61 opts.
addOpt<
double >(
"threshold_target,q",
"error target threshold ", &areaErrTarget );
63 opts.
addOpt<
int >(
"sphere,p",
"mesh on a sphere", &sphere );
64 opts.
addOpt<
int >(
"old_convention,n",
"old names for parent tags", &oldNamesParents );
68 std::string opts_read = (
size == 1 ?
""
69 : std::string(
"PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION" ) +
70 std::string(
";PARALLEL_RESOLVE_SHARED_ENTS" ) );
82 if( 0 == rank ) std::cout <<
"Loading source file " << sourceFile <<
"\n";
83 rval =
mb->
load_file( sourceFile.c_str(), &sset, opts_read.c_str() );
MB_CHK_SET_ERR( rval,
"failed reading source file" );
84 if( 0 == rank ) std::cout <<
"Loading target file " << targetFile <<
"\n";
85 rval =
mb->
load_file( targetFile.c_str(), &tset, opts_read.c_str() );
MB_CHK_SET_ERR( rval,
"failed reading target file" );
87 if( 0 == rank ) std::cout <<
"Loading intersection file " << intxFile <<
"\n";
88 rval =
mb->
load_file( intxFile.c_str(), &ixset, opts_read.c_str() );
MB_CHK_SET_ERR( rval,
"failed reading intersection file" );
107 if( oldNamesParents )
124 std::map< int, double > sourceAreas;
125 std::map< int, double > targetAreas;
127 std::map< int, double > sourceAreasIntx;
128 std::map< int, double > targetAreasIntx;
130 std::map< int, int > sourceNbIntx;
131 std::map< int, int > targetNbIntx;
133 std::map< int, EntityHandle > sourceMap;
134 std::map< int, EntityHandle > targetMap;
142 Range non_convex_intx_cells;
150 std::vector< double > coords( 3 * num_nodes );
154 double area = areaAdaptor.area_spherical_polygon( &coords[0], num_nodes,
R );
157 sourceAreas[sourceID] = area;
159 sourceMap[sourceID] = cell;
168 std::vector< double > coords( 3 * num_nodes );
172 double area = areaAdaptor.area_spherical_polygon( &coords[0], num_nodes,
R );
175 targetAreas[targetID] = area;
177 targetMap[targetID] = cell;
187 std::vector< double > coords( 3 * num_nodes );
192 double intx_area = areaAdaptor.area_spherical_polygon( &coords[0], num_nodes,
R, &check_sign );
196 int sourceID, targetID;
200 std::map< int, double >::iterator sit = sourceAreasIntx.find( sourceID );
201 if( sit == sourceAreasIntx.end() )
203 sourceAreasIntx[sourceID] = intx_area;
204 sourceNbIntx[sourceID] = 1;
208 sourceAreasIntx[sourceID] += intx_area;
209 sourceNbIntx[sourceID]++;
212 std::map< int, double >::iterator tit = targetAreasIntx.find( targetID );
213 if( tit == targetAreasIntx.end() )
215 targetAreasIntx[targetID] = intx_area;
216 targetNbIntx[targetID] = 1;
220 targetAreasIntx[targetID] += intx_area;
221 targetNbIntx[targetID]++;
225 std::cout <<
"negative intx area: " << intx_area <<
" n:" << num_nodes <<
" parents: " << sourceID <<
" "
230 non_convex_intx_cells.
insert( cell );
231 std::cout <<
" non-convex polygon: " << intx_area <<
" n:" << num_nodes <<
" parents: " << sourceID <<
" "
238 Tag countIntxCellsTag;
247 double areaDiff = sourceAreas[sourceID];
248 std::map< int, double >::iterator sit = sourceAreasIntx.find( sourceID );
249 int countIntxCells = 0;
250 if( sit != sourceAreasIntx.end() )
252 areaDiff -= sourceAreasIntx[sourceID];
253 countIntxCells = sourceNbIntx[sourceID];
256 rval =
mb->
tag_set_data( countIntxCellsTag, &cell, 1, &countIntxCells );
258 if( ( areaErrSource > 0 ) && ( fabs( areaDiff ) > areaErrSource ) )
263 if( 0 == rank ) std::cout <<
"write source verification file " << source_verif <<
"\n";
265 if( areaErrSource > 0 )
267 Range sourceErrorCells;
271 if( !sourceErrorCells.
empty() )
274 std::vector< int > sourceIDs;
275 sourceIDs.resize( sourceErrorCells.
size() );
277 std::sort( sourceIDs.begin(), sourceIDs.end() );
283 std::vector< int >::iterator j = std::lower_bound( sourceIDs.begin(), sourceIDs.end(), sourceID );
284 if( ( j != sourceIDs.end() ) && ( *j == sourceID ) )
290 std::string filtersource = std::string(
"filt_" ) + source_verif;
291 rval =
mb->
write_file( filtersource.c_str(), 0, 0, &errorSourceSet, 1 );
292 std::string filterIntxsource = std::string(
"filtIntx_" ) + source_verif;
293 rval =
mb->
write_file( filterIntxsource.c_str(), 0, 0, &errorSourceIntxSet, 1 );
303 double areaDiff = targetAreas[targetID];
304 int countIntxCells = 0;
305 std::map< int, double >::iterator sit = targetAreasIntx.find( targetID );
306 if( sit != targetAreasIntx.end() )
308 areaDiff -= targetAreasIntx[targetID];
309 countIntxCells = targetNbIntx[targetID];
313 rval =
mb->
tag_set_data( countIntxCellsTag, &cell, 1, &countIntxCells );
315 if( ( areaErrTarget > 0 ) && ( fabs( areaDiff ) > areaErrTarget ) )
320 if( 0 == rank ) std::cout <<
"write target verification file " << target_verif <<
"\n";
322 if( areaErrTarget > 0 )
324 Range targetErrorCells;
326 if( !targetErrorCells.
empty() )
331 std::vector< int > targetIDs;
332 targetIDs.resize( targetErrorCells.
size() );
334 std::sort( targetIDs.begin(), targetIDs.end() );
340 std::vector< int >::iterator j = std::lower_bound( targetIDs.begin(), targetIDs.end(), targetID );
341 if( ( j != targetIDs.end() ) && ( *j == targetID ) )
347 std::string filterTarget = std::string(
"filt_" ) + target_verif;
348 rval =
mb->
write_file( filterTarget.c_str(), 0, 0, &errorTargetSet, 1 );
349 std::string filterIntxtarget = std::string(
"filtIntx_" ) + target_verif;
350 rval =
mb->
write_file( filterIntxtarget.c_str(), 0, 0, &errorTargetIntxSet, 1 );
354 if( !non_convex_intx_cells.
empty() )
362 int sourceID, targetID;
365 sourceCells.
insert( sourceMap[sourceID] );
366 targetCells.
insert( targetMap[targetID] );