MOAB: Mesh Oriented datABase  (version 5.5.0)
imoab_setwithGid.cpp
Go to the documentation of this file.
1 /*
2  * This imoab_setwithGid test will test the method
3  * iMOAB_SetDoubleTagStorageWithGid, that is used in parallel
4  * basically, 2 moab apps have different distribution of the same mesh, and use the method to
5  * set the tag from one app to the other
6  * 2 meshes are distributed differently, and each will be loaded in an app. GlobalId tag are the same
7  * for both
8  * example came from mct instance, and need to set the frac tag according to our moab variant of the
9  * coupler distribution of the same mesh.
10 
11  */
12 
13 #include "moab/Core.hpp"
14 
15 // MPI includes
16 #include "moab_mpi.h"
17 #include "moab/ParallelComm.hpp"
18 #include "MBParallelConventions.h"
19 
20 #include "moab/iMOAB.h"
21 #include "TestUtil.hpp"
22 #include "moab/CpuTimer.hpp"
23 #include "moab/ProgOptions.hpp"
24 #include <iostream>
25 #include <sstream>
26 // CHECKIERR
27 #include "imoab_coupler_utils.hpp"
28 
29 using namespace moab;
30 
31 int main( int argc, char* argv[] )
32 {
33  int ierr;
35  MPI_Group jgroup;
36  std::string readoptsLnd( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION" );
37  std::string readopts( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS" );
38 
39  // Timer data
40  moab::CpuTimer timer;
41  double timer_ops;
42  std::string opName;
43 
44  MPI_Init( &argc, &argv );
45  MPI_Comm_rank( MPI_COMM_WORLD, &rankInGlobalComm );
46  MPI_Comm_size( MPI_COMM_WORLD, &numProcesses );
47 
48  MPI_Comm dup_comm_world;
49  MPI_Comm_dup( MPI_COMM_WORLD, &dup_comm_world );
50 
51  std::string lndMoab = TestDir + "unittest/recLand.h5m";
52  std::string lndMct = TestDir + "unittest/WHOLE_cx_lnd.h5m";
53  std::string tagname( "frac" );
54  int entType = 0;
55  int ntags = 1;
56  int nghlay = 0; // no ghosts
57 
58  ierr = iMOAB_Initialize( argc, argv ); // not really needed anything from argc, argv, yet; maybe we should
59  CHECKIERR( ierr, "Cannot initialize iMOAB" )
60 
61  ProgOptions opts;
62  opts.addOpt< std::string >( "source,s", "mct mesh filename (source)", &lndMct );
63 
64  opts.addOpt< std::string >( "target,t", "moab mesh filename (target)", &lndMoab );
65 
66  opts.addOpt< std::string >( "tags,g", "list of tags, colon separated", &tagname );
67 
68  opts.addOpt< int >( "enttype,e", "entity type for moab mesh (0 point cloud, 1 cells)", &entType );
69 
70  opts.addOpt< int >( "ntags,n", "number of tags to set", &ntags );
71 
72  opts.parseCommandLine( argc, argv );
73 
74  int cplLndAppID = -1, cplLnd2AppID = -1; // -1 means it is not initialized
75  iMOAB_AppID cplLndPID = &cplLndAppID; // land on coupler PEs, moab dist
76  iMOAB_AppID cplLnd2PID = &cplLnd2AppID; // land on coupler PEs, MCT dist
77  int cpllnd = 9, cpllnd2 = 109;
78  ierr = iMOAB_RegisterApplication( "LNDX", &dup_comm_world, &cpllnd,
79  cplLndPID ); // mesh on coupler pes
80  CHECKIERR( ierr, "Cannot register LNDX over coupler PEs" )
81  ierr = iMOAB_RegisterApplication( "LNDX2", &dup_comm_world, &cpllnd2,
82  cplLnd2PID ); // mesh on coupler pes, MCT distr, point cloud
83  CHECKIERR( ierr, "Cannot register LNDX2 over coupler PEs" )
84 
85  if( entType == 1 )
86  {
87  ierr = iMOAB_LoadMesh( cplLndPID, lndMoab.c_str(), readopts.c_str(), &nghlay ); // moab mesh can be cells
88  }
89  else // entType == 0
90  {
91  ierr = iMOAB_LoadMesh( cplLndPID, lndMoab.c_str(), readoptsLnd.c_str(), &nghlay ); // moab mesh is point cloud
92  }
93 
94  CHECKIERR( ierr, "Cannot load moab mesh on coupler pes" )
95 
96  ierr = iMOAB_LoadMesh( cplLnd2PID, lndMct.c_str(), readoptsLnd.c_str(), &nghlay );
97  CHECKIERR( ierr, "Cannot load mct point cloud on coupler pes" )
98 
99  int nverts[3], nelem[3];
100  int tagType[2] = { DENSE_DOUBLE, DENSE_INTEGER };
101  int sizeTag = 1;
102  int tagIndex = -1;
103  /*
104  * Each process in the communicator will have access to a local mesh instance, which will
105  * contain the original cells in the local partition and ghost entities. Number of vertices,
106  * primary cells, visible blocks, number of sidesets and nodesets boundary conditions will be
107  * returned in size 3 arrays, for local, ghost and total numbers.
108  */
109  ierr = iMOAB_GetMeshInfo( cplLnd2PID, nverts, nelem, 0, 0, 0 );
110  CHECKIERR( ierr, "Cannot get info on mct mesh on coupler pes" )
111  std::vector< int > gids( nverts[0] );
112  int nvals = nverts[0] * ntags;
113  std::vector< double > fracts( nvals );
114  ierr = iMOAB_DefineTagStorage( cplLnd2PID, tagname.c_str(), &tagType[0], &sizeTag, &tagIndex );
115  CHECKIERR( ierr, "Cannot define frac tag" )
116 
117  ierr = iMOAB_DefineTagStorage( cplLnd2PID, "GLOBAL_ID", &tagType[1], &sizeTag, &tagIndex );
118  CHECKIERR( ierr, "Cannot define gid tag" )
119 
120  int mctEntType = 0; // vertex
121  ierr = iMOAB_GetDoubleTagStorage( cplLnd2PID, tagname.c_str(), &nvals, &mctEntType, &fracts[0] );
122  CHECKIERR( ierr, "Cannot get frac tag on lnd2 on coupler pes" )
123 
124  ierr = iMOAB_GetIntTagStorage( cplLnd2PID, "GLOBAL_ID", &nverts[0], &mctEntType, &gids[0] );
125  CHECKIERR( ierr, "Cannot get global id tag on lnd2 on coupler pes" )
126 
127  // now on moab mesh
128  ierr = iMOAB_DefineTagStorage( cplLndPID, tagname.c_str(), &tagType[0], &sizeTag, &tagIndex );
129  CHECKIERR( ierr, "Cannot define list of tags" )
130 
131  ierr = iMOAB_SetDoubleTagStorageWithGid( cplLndPID, tagname.c_str(), &nvals, &entType, &fracts[0], &gids[0] );
132  CHECKIERR( ierr, "Cannot set double tag with global ids " )
133 
134  char fileWriteOptions[] = "PARALLEL=WRITE_PART";
135  char outputFileLnd[] = "recvLnd4.h5m";
136  ierr = iMOAB_WriteMesh( cplLndPID, outputFileLnd, fileWriteOptions );
137  CHECKIERR( ierr, "cannot write lnd mesh after setting tag" )
138 
139  ierr = iMOAB_DeregisterApplication( cplLnd2PID );
140  CHECKIERR( ierr, "cannot deregister app LNDX2" )
141  ierr = iMOAB_DeregisterApplication( cplLndPID );
142  CHECKIERR( ierr, "cannot deregister app LNDX" )
143 
144  ierr = iMOAB_Finalize();
145  CHECKIERR( ierr, "did not finalize iMOAB" )
146 
147  MPI_Comm_free( &dup_comm_world );
148  MPI_Finalize();
149  return 0;
150 }