LifeV
core/testsuite/partition_io/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 Radu Popescu <radu.popescu@epfl.ch>
32  @maintainer Radu Popescu <radu.popescu@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.
37  */
38 
39 #include <lifev/core/LifeV.hpp>
40 
41 #ifdef LIFEV_HAS_HDF5
42 
43 
44 #include "Epetra_config.h"
45 
46 #ifdef HAVE_MPI
47 
48 #include <Epetra_MpiComm.h>
49 
50 
51 #include <lifev/core/mesh/MeshPartitioner.hpp>
52 #include <lifev/core/filter/PartitionIO.hpp>
53 #include <lifev/core/filter/ExporterHDF5Mesh3D.hpp>
54 #include <lifev/core/mesh/RegionMesh3DStructured.hpp>
55 #include <lifev/core/mesh/MeshData.hpp>
56 
57 using namespace LifeV;
58 
59 #endif /* HAVE_MPI */
60 #endif /* LIFEV_HAS_HDF5 */
61 
62 int main (int argc, char** argv)
63 {
64 #ifdef LIFEV_HAS_HDF5
65 #ifdef HAVE_MPI
66 
67  typedef RegionMesh<LinearTetra> mesh_Type;
68  typedef boost::shared_ptr<mesh_Type> meshPtr_Type;
69 
70  MPI_Init (&argc, &argv);
71  boost::shared_ptr<Epetra_Comm> comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
72 
73  if (comm->NumProc() != 1)
74  {
75  std::cout << "This test needs to be run "
76  << "with a single process. Aborting."
77  << std::endl;
78  return (EXIT_FAILURE);
79  }
80 
81  GetPot commandLine (argc, argv);
82  std::string dataFileName = commandLine.follow ("data", 2, "-f", "--file");
83  GetPot dataFile (dataFileName);
84 
85  const UInt numParts (dataFile ("test/num_parts", 4) );
86  const std::string partsFileName (dataFile ("test/hdf5_file_name", "cube.h5") );
87  const std::string ioClass (dataFile ("test/io_class", "new") );
88 
89  std::cout << "Number of parts: " << numParts << std::endl;
90  std::cout << "Name of HDF5 container: " << partsFileName << std::endl;
91 
92  boost::shared_ptr<mesh_Type> fullMeshPtr (new mesh_Type );
93  //regularMesh3D (*fullMeshPtr, 1, numElements, numElements, numElements,
94  // false, 2.0, 2.0, 2.0, -1.0, -1.0, -1.0);
95 
96  // New part to partition the new mesh
97  MeshData meshData;
98  meshData.setup(dataFile, "mesh");
99  readMesh(*fullMeshPtr, meshData);
100 
101  MeshPartitioner<mesh_Type> meshPart;
102  meshPart.setup (numParts, comm);
103 
104  meshPart.attachUnpartitionedMesh (fullMeshPtr);
105  meshPart.doPartitionGraph();
106  meshPart.doPartitionMesh();
107 
108  // Release the original mesh from the MeshPartitioner object and
109  // delete the RegionMesh object
110  meshPart.releaseUnpartitionedMesh();
111  fullMeshPtr.reset();
112 
113  // Write mesh parts to HDF5 container
114  if (! ioClass.compare ("old") )
115  {
116  ExporterHDF5Mesh3D<mesh_Type> HDF5Output (dataFile,
117  meshPart.meshPartition(),
118  partsFileName,
119  comm->MyPID() );
120  HDF5Output.addPartitionGraph (meshPart.elementDomains(), comm);
121  HDF5Output.addMeshPartitionAll (meshPart.meshPartitions(), comm);
122  HDF5Output.postProcess (0);
123  HDF5Output.closeFile();
124  }
125  else
126  {
127  boost::shared_ptr<Epetra_MpiComm> mpiComm =
128  boost::dynamic_pointer_cast<Epetra_MpiComm> (comm);
129  PartitionIO<mesh_Type> partitionIO (partsFileName, mpiComm);
130  partitionIO.write (meshPart.meshPartitions() );
131  }
132 
133  MPI_Finalize();
134 
135 #else
136  std::cout << "This test needs MPI to run. Aborting." << std::endl;
137  return (EXIT_FAILURE);
138 #endif /* HAVE_MPI */
139 #else
140  std::cout << "This test needs HDF5 to run. Aborting." << std::endl;
141  return (EXIT_FAILURE);
142 #endif /* LIFEV_HAS_HDF5 */
143 
144  return (EXIT_SUCCESS);
145 }
int main(int argc, char **argv)
Definition: dummy.cpp:5