this tool will take an existing h5m pg2 mesh (fv) file and a land point cloud mesh
example of usage: ./ExtractLand -p wholeATM_PG2.h5m -l wholeLnd.h5m -o LandMesh.h5m
the *PG2" style atm mesh is available in E3SM only for pg2 runs, something like –res ne30pg2_r05_oECv3_ICG –compset A_WCYCL1850S_CMIP6 or –res ne4pg2_ne4pg2 –compset FC5AV1C-L
#include <cmath>
#include <sstream>
int main(
int argc,
char* argv[] )
{
std::string pg2file, lndfile, outfile;
opts.
addOpt< std::string >(
"land,l",
"phys grid filename", &lndfile );
opts.
addOpt< std::string >(
"pg2file,p",
"pg2 mesh file", &pg2file );
opts.
addOpt< std::string >(
"output,o",
"output mesh filename", &outfile );
std::cout << " land file " << lndfile << "\n";
std::cout << "pg2 mesh file: " << pg2file << "\n";
std::cout << "output file: " << outfile << "\n";
if( lndfile.empty() || pg2file.empty() || outfile.empty() )
{
return 0;
}
Core* mb2 = new Core();
rval = mb2->load_file( pg2file.c_str() );
MB_CHK_SET_ERR( rval,
"can't load pg2 mesh file" );
Tag globalIDTag2 = mb2->globalId_tag();
Range verts1;
Range cells;
rval = mb2->get_entities_by_dimension( 0, 2, cells );
MB_CHK_SET_ERR( rval,
"can't get 2d cells " );
std::vector< int > globalIdsCells;
globalIdsCells.resize( cells.size() );
rval = mb2->tag_get_data( globalIDTag2, cells, &globalIdsCells[0] );
MB_CHK_SET_ERR( rval,
"can't get global ids cells " );
std::vector< int > globalIdsVerts;
globalIdsVerts.resize( verts1.size() );
std::map< int, EntityHandle > gidToCell;
int i = 0;
{
gidToCell[globalIdsCells[i]] = *it;
}
Range landCells;
for( i = 0; i < (int)verts1.size(); i++ )
{
int gid = globalIdsVerts[i];
landCells.insert( gidToCell[gid] );
}
rval = mb2->add_entities( fileSet, landCells );
rval = mb2->write_file( outfile.c_str(), 0, 0, &fileSet, 1 );
MB_CHK_SET_ERR( rval,
"can't write file" );
double def_val = -1.;
{
double val = 0.;
rval = mb2->tag_set_data( mask, &cell, 1, &val );
MB_CHK_SET_ERR( rval,
"can't set mask tag" );
}
for(
Range::iterator it = landCells.begin(); it != landCells.end(); ++it, i++ )
{
double val = 1.;
rval = mb2->tag_set_data( mask, &cell, 1, &val );
MB_CHK_SET_ERR( rval,
"can't set mask tag" );
}
rval = mb2->delete_entities( &fileSet, 1 );
MB_CHK_SET_ERR( rval,
"can't delete set" );
rval = mb2->write_file(
"AtmWithLandMask.h5m" );
MB_CHK_SET_ERR( rval,
"can't write file" );
delete mb2;
return 0;
}