LifeV
core/testsuite/offline_partition_io/main_read.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 - read and solve
30 
31  @author Radu Popescu <radu.popescu@epfl.ch>
32  @maintainer Radu Popescu <radu.popescu@epfl.ch>
33  @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34 
35  @date 10-05-2012
36 
37  Loads mesh parts from HDF5 and solves a Laplacian problem.
38  Based on the ADRAssembler class unit test.
39  */
40 
41 #include <lifev/core/LifeV.hpp>
42 
43 #ifdef LIFEV_HAS_HDF5
44 
45 #include "Epetra_config.h"
46 
47 #ifdef HAVE_MPI
48 
49 #include <mpi.h>
50 
51 #include <Epetra_MpiComm.h>
52 
53 #include <lifev/core/filter/GetPot.hpp>
54 #include <lifev/core/array/MatrixEpetra.hpp>
55 #include <lifev/core/array/VectorEpetra.hpp>
56 #include <lifev/core/fem/FESpace.hpp>
57 #include <lifev/core/filter/PartitionIO.hpp>
58 #include <lifev/core/mesh/RegionMesh.hpp>
59 #include <lifev/core/solver/ADRAssembler.hpp>
60 
61 using namespace LifeV;
62 
63 typedef RegionMesh<LinearTetra> mesh_Type;
64 typedef MatrixEpetra<Real> matrix_Type;
65 typedef VectorEpetra vector_Type;
66 
67 #endif /* HAVE_MPI */
68 #endif /* LIFEV_HAS_HDF5 */
69 
70 int
71 main ( int argc, char** argv )
72 {
73 #ifdef LIFEV_HAS_HDF5
74 #ifdef HAVE_MPI
75 
76  MPI_Init (&argc, &argv);
77  std::shared_ptr<Epetra_MpiComm> comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
78 
79  const bool verbose (comm->MyPID() == 0);
80 
81  // Read first the data needed
82 
83  if (verbose)
84  {
85  std::cout << " -- Reading the data ... " << std::flush;
86  }
87  // GetPot dataFile ( "data" );
88  if (verbose)
89  {
90  std::cout << " done ! " << std::endl;
91  }
92 
93  GetPot cl (argc, argv);
94  // partitionerType should be MeshPartitioner, MeshPartitionTool_ParMETIS or
95  // MeshPartitionTool_Zoltan
96  const std::string partitionerType = cl.follow ("MeshPartitioner",
97  "--partitioner-type");
98  std::string partsFile;
99  partsFile.reserve (50);
100  partsFile += "cube_";
101  partsFile += partitionerType;
102  partsFile += ".h5";
103 
104  std::shared_ptr<mesh_Type> mesh;
105  {
106  PartitionIO<RegionMesh<LinearTetra> > partitionIO (partsFile, comm);
107  partitionIO.read (mesh);
108  }
109 
110  // Build the FESpaces
111 
112  if (verbose)
113  {
114  std::cout << " -- Building FESpaces ... " << std::flush;
115  }
116  std::string uOrder ("P1");
117  std::string bOrder ("P1");
118  std::shared_ptr<FESpace<mesh_Type, MapEpetra> >
119  uFESpace (new FESpace<mesh_Type, MapEpetra> (mesh, uOrder, 1, comm) );
120  std::shared_ptr<FESpace<mesh_Type, MapEpetra> >
121  betaFESpace (new FESpace<mesh_Type, MapEpetra> (mesh, bOrder, 3, comm) );
122  if (verbose)
123  {
124  std::cout << " done ! " << std::endl;
125  }
126  if (verbose) std::cout << " ---> Dofs: "
127  << uFESpace->dof().numTotalDof() << std::endl;
128 
129  // Build the assembler and the matrices
130 
131  if (verbose)
132  {
133  std::cout << " -- Building assembler ... " << std::flush;
134  }
135  ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
136  if (verbose)
137  {
138  std::cout << " done! " << std::endl;
139  }
140 
141  if (verbose)
142  {
143  std::cout << " -- Setting up assembler ... " << std::flush;
144  }
145  adrAssembler.setup (uFESpace, betaFESpace);
146  if (verbose)
147  {
148  std::cout << " done! " << std::endl;
149  }
150 
151  if (verbose)
152  {
153  std::cout << " -- Defining the matrix ... " << std::flush;
154  }
155  std::shared_ptr<matrix_Type>
156  systemMatrix (new matrix_Type (uFESpace->map() ) );
157  *systemMatrix *= 0.0;
158  if (verbose)
159  {
160  std::cout << " done! " << std::endl;
161  }
162 
163  // Perform the assembly of the matrix
164 
165  if (verbose)
166  {
167  std::cout << " -- Adding the diffusion ... " << std::flush;
168  }
169  adrAssembler.addDiffusion (systemMatrix, 1);
170  if (verbose)
171  {
172  std::cout << " done! " << std::endl;
173  }
174  if (verbose) std::cout << " Time needed : "
175  << adrAssembler.diffusionAssemblyChrono().diffCumul()
176  << std::endl;
177 
178  if (verbose)
179  {
180  std::cout << " -- Closing the matrix ... " << std::flush;
181  }
182  systemMatrix->globalAssemble();
183  if (verbose)
184  {
185  std::cout << " done ! " << std::endl;
186  }
187 
188  Real matrixNorm (systemMatrix->normFrobenius() );
189  if (verbose)
190  {
191  std::cout << " ---> Norm 2 : " << matrixNorm << std::endl;
192  }
193  if (std::fabs (matrixNorm - 35.908) > 1e-3)
194  {
195  std::cout << " <!> Matrix has changed !!! <!> " << std::endl;
196  return EXIT_FAILURE;
197  }
198 
199  if (verbose)
200  {
201  std::cout << "End Result: TEST PASSED" << std::endl;
202  }
203 
204  MPI_Finalize();
205 
206 #else
207  std::cout << "This test needs MPI to run. Aborting." << std::endl;
208  return (EXIT_FAILURE);
209 #endif /* HAVE_MPI */
210 #else
211  std::cout << "This test needs HDF5 to run. Aborting." << std::endl;
212  return (EXIT_FAILURE);
213 #endif /* LIFEV_HAS_HDF5 */
214 
215  return ( EXIT_SUCCESS );
216 }
int main(int argc, char **argv)
Definition: dummy.cpp:5