MOAB: Mesh Oriented datABase  (version 5.4.1)
imoab_setwithGid.cpp
Go to the documentation of this file.
00001 /*
00002  * This imoab_setwithGid test will test the method
00003  * iMOAB_SetDoubleTagStorageWithGid, that is used in parallel
00004  * basically, 2 moab apps have different distribution of the same mesh, and use the method to
00005  * set the tag from one app to the other
00006  * 2 meshes are distributed differently, and each will be loaded in an app. GlobalId tag are the same
00007  * for both
00008  * example came from mct instance, and need to set the frac tag according to our moab variant of the
00009  * coupler distribution of the same mesh.
00010 
00011  */
00012 
00013 #include "moab/Core.hpp"
00014 
00015 // MPI includes
00016 #include "moab_mpi.h"
00017 #include "moab/ParallelComm.hpp"
00018 #include "MBParallelConventions.h"
00019 
00020 #include "moab/iMOAB.h"
00021 #include "TestUtil.hpp"
00022 #include "moab/CpuTimer.hpp"
00023 #include "moab/ProgOptions.hpp"
00024 #include <iostream>
00025 #include <sstream>
00026 // CHECKIERR
00027 #include "imoab_coupler_utils.hpp"
00028 
00029 using namespace moab;
00030 
00031 int main( int argc, char* argv[] )
00032 {
00033     int ierr;
00034     int rankInGlobalComm, numProcesses;
00035     MPI_Group jgroup;
00036     std::string readoptsLnd( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION" );
00037     std::string readopts( "PARALLEL=READ_PART;PARTITION=PARALLEL_PARTITION;PARALLEL_RESOLVE_SHARED_ENTS" );
00038 
00039     // Timer data
00040     moab::CpuTimer timer;
00041     double timer_ops;
00042     std::string opName;
00043 
00044     MPI_Init( &argc, &argv );
00045     MPI_Comm_rank( MPI_COMM_WORLD, &rankInGlobalComm );
00046     MPI_Comm_size( MPI_COMM_WORLD, &numProcesses );
00047 
00048     MPI_Comm dup_comm_world;
00049     MPI_Comm_dup( MPI_COMM_WORLD, &dup_comm_world );
00050 
00051     std::string lndMoab = TestDir + "unittest/recLand.h5m";
00052     std::string lndMct = TestDir + "unittest/WHOLE_cx_lnd.h5m";
00053     std::string tagname("frac");
00054     int entType = 0;
00055     int ntags = 1;
00056     int nghlay = 0; // no ghosts
00057 
00058     ierr = iMOAB_Initialize( argc, argv );  // not really needed anything from argc, argv, yet; maybe we should
00059     CHECKIERR( ierr, "Cannot initialize iMOAB" )
00060 
00061     ProgOptions opts;
00062     opts.addOpt< std::string >( "source,s", "mct mesh filename (source)", &lndMct );
00063 
00064     opts.addOpt< std::string >( "target,t", "moab mesh filename (target)", &lndMoab );
00065 
00066     opts.addOpt< std::string >( "tags,g", "list of tags, colon separated", &tagname );
00067 
00068     opts.addOpt< int >( "enttype,e", "entity type for moab mesh (0 point cloud, 1 cells)", &entType );
00069 
00070     opts.addOpt< int >( "ntags,n", "number of tags to set", &ntags );
00071 
00072     opts.parseCommandLine( argc, argv );
00073 
00074     int cplLndAppID = -1, cplLnd2AppID = -1;   // -1 means it is not initialized
00075     iMOAB_AppID cplLndPID    = &cplLndAppID;     // land on coupler PEs, moab dist
00076     iMOAB_AppID cplLnd2PID    = &cplLnd2AppID;     // land on coupler PEs, MCT dist
00077     int cpllnd = 9, cpllnd2 = 109;
00078     ierr = iMOAB_RegisterApplication( "LNDX", &dup_comm_world, &cpllnd,
00079                                               cplLndPID );  // mesh on coupler pes
00080     CHECKIERR( ierr, "Cannot register LNDX over coupler PEs" )
00081     ierr = iMOAB_RegisterApplication( "LNDX2", &dup_comm_world, &cpllnd2,
00082                                                   cplLnd2PID );  // mesh on coupler pes, MCT distr, point cloud
00083     CHECKIERR( ierr, "Cannot register LNDX2 over coupler PEs" )
00084 
00085     if (entType == 1)
00086     {
00087         ierr = iMOAB_LoadMesh( cplLndPID, lndMoab.c_str(), readopts.c_str(), &nghlay ); // moab mesh can be cells
00088     }
00089     else // entType == 0
00090     {
00091         ierr = iMOAB_LoadMesh( cplLndPID, lndMoab.c_str(), readoptsLnd.c_str(), &nghlay ); // moab mesh is point cloud
00092     }
00093 
00094     CHECKIERR( ierr, "Cannot load moab mesh on coupler pes" )
00095 
00096     ierr = iMOAB_LoadMesh( cplLnd2PID, lndMct.c_str(), readoptsLnd.c_str(), &nghlay );
00097     CHECKIERR( ierr, "Cannot load mct point cloud on coupler pes" )
00098 
00099     int nverts[3], nelem[3];
00100     int tagType[2] = {  DENSE_DOUBLE, DENSE_INTEGER};
00101     int sizeTag = 1;
00102     int tagIndex = -1;
00103     /*
00104      * Each process in the communicator will have access to a local mesh instance, which will
00105      * contain the original cells in the local partition and ghost entities. Number of vertices,
00106      * primary cells, visible blocks, number of sidesets and nodesets boundary conditions will be
00107      * returned in size 3 arrays, for local, ghost and total numbers.
00108      */
00109     ierr = iMOAB_GetMeshInfo( cplLnd2PID, nverts, nelem, 0, 0, 0 );
00110     CHECKIERR( ierr, "Cannot get info on mct mesh on coupler pes" )
00111     std::vector<int> gids(nverts[0]);
00112     int nvals = nverts[0]*ntags;
00113     std::vector<double> fracts(nvals);
00114     ierr = iMOAB_DefineTagStorage( cplLnd2PID, tagname.c_str(), &tagType[0], &sizeTag, &tagIndex );
00115     CHECKIERR( ierr, "Cannot define frac tag" )
00116 
00117     ierr = iMOAB_DefineTagStorage( cplLnd2PID, "GLOBAL_ID", &tagType[1], &sizeTag, &tagIndex );
00118     CHECKIERR( ierr, "Cannot define gid tag" )
00119 
00120     int mctEntType = 0; // vertex
00121     ierr  = iMOAB_GetDoubleTagStorage( cplLnd2PID, tagname.c_str(), &nvals, &mctEntType, &fracts[0] );
00122     CHECKIERR( ierr, "Cannot get frac tag on lnd2 on coupler pes" )
00123 
00124     ierr  = iMOAB_GetIntTagStorage( cplLnd2PID, "GLOBAL_ID", &nverts[0], &mctEntType, &gids[0] );
00125     CHECKIERR( ierr, "Cannot get global id tag on lnd2 on coupler pes" )
00126 
00127     // now on moab mesh
00128     ierr = iMOAB_DefineTagStorage( cplLndPID, tagname.c_str(), &tagType[0], &sizeTag, &tagIndex );
00129     CHECKIERR( ierr, "Cannot define list of tags" )
00130 
00131     ierr = iMOAB_SetDoubleTagStorageWithGid(cplLndPID, tagname.c_str(), &nvals, &entType, &fracts[0], &gids[0] );
00132     CHECKIERR( ierr, "Cannot set double tag with global ids " )
00133 
00134     char fileWriteOptions[] = "PARALLEL=WRITE_PART";
00135     char outputFileLnd[] = "recvLnd4.h5m";
00136     ierr                 = iMOAB_WriteMesh( cplLndPID, outputFileLnd, fileWriteOptions );
00137     CHECKIERR( ierr, "cannot write lnd mesh after setting tag" )
00138 
00139     ierr = iMOAB_DeregisterApplication( cplLnd2PID );
00140     CHECKIERR( ierr, "cannot deregister app LNDX2" )
00141     ierr = iMOAB_DeregisterApplication( cplLndPID );
00142     CHECKIERR( ierr, "cannot deregister app LNDX" )
00143 
00144     ierr = iMOAB_Finalize();
00145     CHECKIERR( ierr, "did not finalize iMOAB" )
00146 
00147     MPI_Comm_free(&dup_comm_world );
00148     MPI_Finalize();
00149     return 0;
00150 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines