15 #define CHECKIERR( ierr, message ) \
18 printf( "%s", message ); \
22 #define ENABLE_ATMLND_COUPLING
24 int main(
int argc,
char* argv[] )
27 std::string
atmFilename, ocnFilename, lndFilename, mapFilename;
30 ocnFilename = TestDir +
"unittest/recMeshOcn.h5m";
31 #ifdef ENABLE_ATMLND_COUPLING
32 lndFilename = TestDir +
"unittest/wholeLnd.h5m";
37 opts.
addOpt< std::string >(
"atmosphere,t",
"atm mesh filename (source)", &
atmFilename );
38 opts.
addOpt< std::string >(
"ocean,m",
"ocean mesh filename (target)", &ocnFilename );
39 #ifdef ENABLE_ATMLND_COUPLING
40 opts.
addOpt< std::string >(
"land,l",
"land mesh filename (target)", &lndFilename );
42 bool gen_baseline =
false;
43 opts.
addOpt<
void >(
"genbase,g",
"generate baseline 1", &gen_baseline );
45 bool no_test_against_baseline =
false;
46 opts.
addOpt<
void >(
"no_testbase,t",
"do not test against baseline 1", &no_test_against_baseline );
47 std::string baseline = TestDir +
"unittest/baseline1.txt";
52 std::cout <<
" atm file: " <<
atmFilename <<
"\n ocn file: " << ocnFilename
53 #ifdef ENABLE_ATMLND_COUPLING
54 <<
"\n lnd file: " << lndFilename
60 MPI_Init( &argc, &argv );
70 int atmAppID, ocnAppID, lndAppID, atmocnAppID, atmlndAppID, lndatmAppID;
83 int atmCompID = 10, ocnCompID = 20, lndCompID = 30, atmocnCompID = 100, atmlndCompID = 102, lndatmCompID = 103;
97 #ifdef ENABLE_ATMLND_COUPLING
102 &lndCompID, lndPID );
109 &atmocnCompID, atmocnPID );
111 #ifdef ENABLE_ATMLND_COUPLING
116 &atmlndCompID, atmlndPID );
123 &lndatmCompID, lndatmPID );
126 const char* read_opts =
"";
127 int num_ghost_layers = 0;
139 #ifdef ENABLE_ATMLND_COUPLING
144 int nverts[3], nelem[3];
153 printf(
"Atmosphere Component Mesh: %d vertices and %d elements\n", nverts[0], nelem[0] );
157 printf(
"Ocean Component Mesh: %d vertices and %d elements\n", nverts[0], nelem[0] );
158 #ifdef ENABLE_ATMLND_COUPLING
161 printf(
"Land Component Mesh: %d vertices and %d elements\n", nverts[0], nelem[0] );
173 int disc_orders[3] = { 4, 1, 1 };
174 int fMonotoneTypeID = 0, fVolumetric = 0, fValidate = 0, fNoConserve = 0, fNoBubble = 1, fInverseDistanceMap = 0;
176 const std::string disc_methods[3] = {
"cgll",
"fv",
"pcloud" };
177 const std::string dof_tag_names[3] = {
"GLOBAL_DOFS",
"GLOBAL_ID",
"GLOBAL_ID" };
178 const std::string weights_identifiers[3] = {
"scalar",
"scalar_pointcloud",
"scalar_conservative" };
180 const std::string bottomTempField =
"a2oTbot";
181 const std::string bottomTempFieldATM =
"a2oTbotATM";
182 const std::string bottomTempProjectedField =
"a2oTbot_proj";
183 const std::string bottomTempProjectedNCField =
"a2oTbot_projnocons";
189 int atmCompNDoFs = disc_orders[0] * disc_orders[0], ocnCompNDoFs = 1 ;
198 iMOAB_DefineTagStorage( ocnPID, bottomTempProjectedField.c_str(), &tagTypes[1], &ocnCompNDoFs, &tagIndex[1] );
202 iMOAB_DefineTagStorage( ocnPID, bottomTempProjectedNCField.c_str(), &tagTypes[1], &ocnCompNDoFs, &tagIndex[2] );
205 #ifdef ENABLE_ATMLND_COUPLING
207 iMOAB_DefineTagStorage( lndPID, bottomTempProjectedField.c_str(), &tagTypes[1], &ocnCompNDoFs, &tagIndex[3] );
213 ierr = iMOAB_ComputeMeshIntersectionOnSphere( atmPID, ocnPID, atmocnPID );
214 CHECKIERR(
ierr,
"failed to compute mesh intersection between ATM and OCN" );
216 #ifdef ENABLE_ATMLND_COUPLING
219 ierr = iMOAB_ComputePointDoFIntersection( atmPID, lndPID, atmlndPID );
220 CHECKIERR(
ierr,
"failed to compute point-cloud mapping ATM-LND" );
224 ierr = iMOAB_ComputePointDoFIntersection( lndPID, atmPID, lndatmPID );
225 CHECKIERR(
ierr,
"failed to compute point-cloud mapping LND-ATM" );
232 ierr = iMOAB_ComputeScalarProjectionWeights( atmocnPID, weights_identifiers[0].c_str(), disc_methods[0].c_str(),
233 &disc_orders[0], disc_methods[1].c_str(), &disc_orders[1],
nullptr,
234 &fNoBubble, &fMonotoneTypeID, &fVolumetric, &fInverseDistanceMap,
235 &fNoConserve, &fValidate, dof_tag_names[0].c_str(),
236 dof_tag_names[1].c_str() );
237 CHECKIERR(
ierr,
"failed to compute remapping projection weights for ATM-OCN scalar "
238 "non-conservative field" );
241 #ifdef MOAB_HAVE_NETCDF
243 const std::string atmocn_map_file_name =
"atm_ocn_map.nc";
245 iMOAB_WriteMappingWeightsToFile( atmocnPID, weights_identifiers[0].c_str(), atmocn_map_file_name.c_str() );
248 const std::string intx_from_file_identifier =
"map-from-file";
251 int dummy_rowcol = -1;
253 ierr = iMOAB_LoadMappingWeightsFromFile( atmocnPID, &dummyCpl, &dummy_rowcol, &dummyType,
254 intx_from_file_identifier.c_str(), atmocn_map_file_name.c_str() );
258 #ifdef ENABLE_ATMLND_COUPLING
261 ierr = iMOAB_ComputeScalarProjectionWeights( atmlndPID, weights_identifiers[1].c_str(), disc_methods[0].c_str(),
262 &disc_orders[0], disc_methods[2].c_str(), &disc_orders[2],
nullptr,
263 &fNoBubble, &fMonotoneTypeID, &fVolumetric, &fInverseDistanceMap,
264 &fNoConserve, &fValidate, dof_tag_names[0].c_str(),
265 dof_tag_names[2].c_str() );
266 CHECKIERR(
ierr,
"failed to compute remapping projection weights for ATM-LND scalar "
267 "non-conservative field" );
270 ierr = iMOAB_ComputeScalarProjectionWeights( lndatmPID, weights_identifiers[1].c_str(), disc_methods[2].c_str(),
271 &disc_orders[2], disc_methods[0].c_str(), &disc_orders[0],
nullptr,
272 &fNoBubble, &fMonotoneTypeID, &fVolumetric, &fInverseDistanceMap,
273 &fNoConserve, &fValidate, dof_tag_names[2].c_str(),
274 dof_tag_names[0].c_str() );
275 CHECKIERR(
ierr,
"failed to compute remapping projection weights for LND-ATM scalar "
276 "non-conservative field" );
280 ierr = iMOAB_ComputeScalarProjectionWeights( atmocnPID, weights_identifiers[2].c_str(), disc_methods[0].c_str(),
281 &disc_orders[0], disc_methods[1].c_str(), &disc_orders[1],
nullptr,
282 &fNoBubble, &fMonotoneTypeID, &fVolumetric, &fInverseDistanceMap,
283 &fNoConserve, &fValidate, dof_tag_names[0].c_str(),
284 dof_tag_names[1].c_str() );
285 CHECKIERR(
ierr,
"failed to compute remapping projection weights for scalar conservative field" );
289 ierr = iMOAB_ApplyScalarProjectionWeights( atmocnPID, weights_identifiers[0].c_str(), bottomTempField.c_str(),
290 bottomTempProjectedNCField.c_str() );
291 CHECKIERR(
ierr,
"failed to apply projection weights for scalar non-conservative field" );
295 ierr = iMOAB_ApplyScalarProjectionWeights( atmocnPID, weights_identifiers[2].c_str(), bottomTempField.c_str(),
296 bottomTempProjectedField.c_str() );
297 CHECKIERR(
ierr,
"failed to apply projection weights for scalar conservative field" );
305 std::vector< int > gidElems;
306 gidElems.resize( nelem[2] );
307 std::vector< double > tempElems;
308 tempElems.resize( nelem[2] );
310 const std::string GidStr =
"GLOBAL_ID";
323 fs.open( baseline.c_str(), std::fstream::out );
324 fs << std::setprecision( 15 );
325 for(
int i = 0; i < nelem[2]; i++ )
326 fs << gidElems[i] <<
" " << tempElems[i] <<
"\n";
329 if( !no_test_against_baseline )
335 std::vector< int > gidElems;
336 gidElems.resize( nelem[2] );
337 std::vector< double > tempElems;
338 tempElems.resize( nelem[2] );
340 const std::string GidStr =
"GLOBAL_ID";
353 check_baseline_file( baseline, gidElems, tempElems, 1.e-9, err_code );
354 if( 0 == err_code ) std::cout <<
" passed baseline test 1\n";
356 #ifdef ENABLE_ATMLND_COUPLING
359 ierr = iMOAB_ApplyScalarProjectionWeights( atmlndPID, weights_identifiers[1].c_str(), bottomTempField.c_str(),
360 bottomTempProjectedField.c_str() );
361 CHECKIERR(
ierr,
"failed to apply projection weights for ATM-LND scalar field" );
365 ierr = iMOAB_ApplyScalarProjectionWeights( lndatmPID, weights_identifiers[1].c_str(),
366 bottomTempProjectedField.c_str(), bottomTempFieldATM.c_str() );
367 CHECKIERR(
ierr,
"failed to apply projection weights for LND-ATM scalar field" );
375 #ifdef ENABLE_ATMLND_COUPLING
376 char outputFileAtmTgt[] =
"fIntxAtmTarget.h5m";
378 char outputFileOcnTgt[] =
"fIntxOcnTarget.h5m";
379 #ifdef ENABLE_ATMLND_COUPLING
380 char outputFileLndTgt[] =
"fIntxLndTarget.h5m";
382 char writeOptions[] =
"";
387 #ifdef ENABLE_ATMLND_COUPLING
399 #ifdef ENABLE_ATMLND_COUPLING