LifeV
structure/examples/example_partitionMesh/main_write.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010, 2011, 2012 EPFL, Politecnico di Milano, Emory University
7 
8 This file is part of LifeV.
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  @file
29  @brief Test for PartitionIO class - cut and write
30 
31  @author Paolo Tricerri <paolo.tricerri@epfl.ch>
32  @maintainer Paolo Tricerri <paolo.tricerri@epfl.ch>
33  @date 10-05-2012
34 
35  Partition a mesh using a single (MPI) process and save mesh parts
36  to an HDF5 file. The example is very similar to the testsuite/offline_partitionin_io
37  but it reads the infos it needs from data file instead of having some hardcoded variables.
38  */
39 
40 #include <lifev/core/LifeV.hpp>
41 
42 #include <iostream>
43 #include <string>
44 
45 #include "Epetra_config.h"
46 
47 #ifndef LIFEV_HAS_HDF5
48 
49 #warning warning you should reconfigure LifeV with -D TPL_ENABLE_HDF5:BOOL=ON
50 
51 #endif // od ifndef LIFEV_HAS_HDF5
52 
53 #ifndef HAVE_MPI
54 
55 #warning warning you should reconfigure LifeV with -D TPL_ENABLE_MPI:BOOL=ON
56 
57 #else
58 
59 // Tell the compiler to ignore specific kind of warnings:
60 #pragma GCC diagnostic ignored "-Wunused-variable"
61 #pragma GCC diagnostic ignored "-Wunused-parameter"
62 
63 #include <mpi.h>
64 
65 #include <Epetra_MpiComm.h>
66 
67 //Tell the compiler to restore the warning previously silented
68 #pragma GCC diagnostic warning "-Wunused-variable"
69 #pragma GCC diagnostic warning "-Wunused-parameter"
70 
71 #include <lifev/core/mesh/MeshPartitioner.hpp>
72 #include <lifev/core/filter/PartitionIO.hpp>
73 #include <lifev/core/mesh/MeshData.hpp>
74 #include <lifev/core/mesh/RegionMesh.hpp>
75 
76 using namespace LifeV;
77 
78 #endif // of ifndef LIFEV_HAS_MPI
79 
80 
81 int main (int argc, char** argv)
82 {
83 #ifdef LIFEV_HAS_HDF5
84 #ifdef HAVE_MPI
85 
86  typedef RegionMesh<LinearTetra> mesh_Type;
87 
88  MPI_Init (&argc, &argv);
89  std::shared_ptr<Epetra_Comm> comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
90 
91  if (comm->NumProc() != 1)
92  {
93  std::cout << "This test needs to be run "
94  << "with a single process. Aborting."
95  << std::endl;
96  return (EXIT_FAILURE);
97  }
98 
99  GetPot commandLine (argc, argv);
100  std::string dataFileName = commandLine.follow ("data", 2, "-f", "--file");
101  GetPot dataFile (dataFileName);
102 
103  const UInt numParts (dataFile ("offlinePartition/num_parts", 4) );
104  std::string stringFileName (dataFile ("offlinePartition/nameFile", "NO_DEFAULT_VALE") );
105 
106  stringFileName += "Partitioned.h5";
107 
108  std::cout << "Number of parts: " << numParts << std::endl;
109  std::cout << "Name of HDF5 container: " << stringFileName << std::endl;
110 
111  //Creation mesh data object to read the whole mesh
112  MeshData meshData;
113  meshData.setup (dataFile, "solid/space_discretization");
114 
115  //Creation of the object whole mesh
116  std::shared_ptr<mesh_Type> fullMeshPtr (new mesh_Type ( comm ) );
117  readMesh (*fullMeshPtr, meshData);
118 
119  fullMeshPtr->showMe();
120 
121  //Creation object mesh partitioner
122  MeshPartitioner<mesh_Type> meshPart;
123  meshPart.setup (numParts, comm);
124 
125  meshPart.attachUnpartitionedMesh (fullMeshPtr);
126  meshPart.doPartitionGraph();
127  meshPart.doPartitionMesh();
128 
129  // Release the original mesh from the MeshPartitioner object and
130  // delete the RegionMesh object
131  meshPart.releaseUnpartitionedMesh();
132  fullMeshPtr.reset();
133 
134  // Write mesh parts to HDF5 container
135 
136  std::shared_ptr<Epetra_MpiComm> mpiComm =
137  std::dynamic_pointer_cast<Epetra_MpiComm> (comm);
138  PartitionIO<mesh_Type> partitionIO (stringFileName, mpiComm);
139 
140  partitionIO.write (meshPart.meshPartitions() );
141 
142  MPI_Finalize();
143 
144 #else
145  std::cout << "This test needs MPI to run. Aborting." << std::endl;
146  return (EXIT_FAILURE);
147 #endif /* HAVE_MPI */
148 #else
149  std::cout << "This test needs HDF5 enabled in LifeV to run. Aborting." << std::endl;
150  return (EXIT_FAILURE);
151 #endif /* LIFEV_HAS_HDF5 */
152 
153  return (EXIT_SUCCESS);
154 }
int main(int argc, char **argv)
Definition: dummy.cpp:5