LifeV
lifev/core/testsuite/mesh/mesh_partition_tool/main.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 the MeshPartitionTool class
30 
31  @author Radu Popescu <radu.popescu@epfl.ch>
32  @date 14-11-2012
33  */
34 
35 #include <Epetra_ConfigDefs.h>
36 #ifdef EPETRA_MPI
37 #include <mpi.h>
38 #include <Epetra_MpiComm.h>
39 #else
40 #include <Epetra_SerialComm.h>
41 #endif
42 
43 #include <Teuchos_ParameterList.hpp>
44 
45 #include <lifev/core/LifeV.hpp>
46 
47 #include <lifev/core/array/MatrixEpetra.hpp>
48 
49 #include <lifev/core/fem/FESpace.hpp>
50 
51 #include <lifev/core/filter/GetPot.hpp>
52 
53 #include <lifev/core/mesh/MeshPartitionTool.hpp>
54 #include <lifev/core/mesh/RegionMesh3DStructured.hpp>
55 #include <lifev/core/mesh/RegionMesh.hpp>
56 
57 #include <lifev/core/solver/ADRAssembler.hpp>
58 
59 using namespace LifeV;
60 
64 typedef FESpace<mesh_Type, MapEpetra> feSpace_Type;
67 
68 int main ( int argc, char** argv )
69 {
70 
71 #ifdef HAVE_MPI
72  MPI_Init (&argc, &argv);
73  std::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
74 #else
75  std::shared_ptr<Epetra_Comm> Comm (new Epetra_SerialComm);
76 #endif
77 
78  const bool verbose (Comm->MyPID() == 0);
79 
80  // Read first the data needed
81 
82  GetPot cl (argc, argv);
83  const UInt numElements = cl.follow (9, "--num-elem");
84  // partitionerType should be MeshPartitioner, MeshPartitionTool_ParMETIS or
85  // MeshPartitionTool_Zoltan
86  const std::string graphLib = cl.follow ("parmetis", "--graph-lib");
87 
88  if (verbose) std::cout << " ---> Number of elements : "
89  << numElements << std::endl;
90 
91  // Build and partition the mesh
92 
93  if (verbose)
94  {
95  std::cout << " -- Building the mesh ... " << std::flush;
96  }
97  std::shared_ptr< mesh_Type > fullMeshPtr (new RegionMesh<LinearTetra>);
98  std::shared_ptr< mesh_Type > meshPart;
99  regularMesh3D ( *fullMeshPtr, 1, numElements, numElements, numElements, false,
100  2.0, 2.0, 2.0,
101  -1.0, -1.0, -1.0);
102  if (verbose)
103  {
104  std::cout << " done ! " << std::endl;
105  }
106 
107  if (verbose)
108  {
109  std::cout << " -- Partitioning the mesh ... " << std::flush;
110  }
111  {
112  Teuchos::ParameterList meshParameters;
113  meshParameters.set ("num-parts", Comm->NumProc(), "");
114  meshParameters.set ("graph-lib", graphLib, "");
115  meshCutter_Type meshCutter (fullMeshPtr, Comm, meshParameters);
116  if (! meshCutter.success() )
117  {
118  if (verbose)
119  {
120  std::cout << "Partitioning failed." << std::endl;
121  }
122  return EXIT_FAILURE;
123  }
124  meshPart = meshCutter.meshPart();
125  }
126  if (verbose)
127  {
128  std::cout << " done ! " << std::endl;
129  }
130 
131  if (verbose)
132  {
133  std::cout << " -- Freeing the global mesh ... " << std::flush;
134  }
135  fullMeshPtr.reset();
136  if (verbose)
137  {
138  std::cout << " done ! " << std::endl;
139  }
140 
141  // Build the FESpaces
142  if (verbose)
143  {
144  std::cout << " -- Building FESpaces ... " << std::flush;
145  }
146  std::string uOrder ("P1");
147  std::string bOrder ("P1");
148  std::shared_ptr < FESpace < mesh_Type,
149  MapEpetra > >
150  uFESpace (new FESpace < mesh_Type,
151  MapEpetra > (meshPart,
152  uOrder,
153  1,
154  Comm) );
155 
156  std::shared_ptr < FESpace < mesh_Type,
157  MapEpetra > >
158  betaFESpace (new FESpace < mesh_Type,
159  MapEpetra > (meshPart,
160  bOrder,
161  3,
162  Comm) );
163 
164  if (verbose)
165  {
166  std::cout << " done ! " << std::endl;
167  }
168  if (verbose) std::cout << " ---> Dofs: "
169  << uFESpace->dof().numTotalDof() << std::endl;
170 
171  // Build the assembler and the matrices
172 
173  if (verbose)
174  {
175  std::cout << " -- Building assembler ... " << std::flush;
176  }
177  ADRAssembler<mesh_Type, matrix_Type, vector_Type> adrAssembler;
178  if (verbose)
179  {
180  std::cout << " done! " << std::endl;
181  }
182 
183  if (verbose)
184  {
185  std::cout << " -- Setting up assembler ... " << std::flush;
186  }
187  adrAssembler.setup (uFESpace, betaFESpace);
188  if (verbose)
189  {
190  std::cout << " done! " << std::endl;
191  }
192 
193  if (verbose)
194  {
195  std::cout << " -- Defining the matrix ... " << std::flush;
196  }
197  std::shared_ptr<matrix_Type>
198  systemMatrix (new matrix_Type (uFESpace->map() ) );
199  *systemMatrix *= 0.0;
200  if (verbose)
201  {
202  std::cout << " done! " << std::endl;
203  }
204 
205  // Perform the assembly of the matrix
206 
207  if (verbose)
208  {
209  std::cout << " -- Adding the diffusion ... " << std::flush;
210  }
211  adrAssembler.addDiffusion (systemMatrix, 1.0);
212  if (verbose)
213  {
214  std::cout << " done! " << std::endl;
215  }
216  if (verbose)
217  {
218  std::cout << " Time needed : "
219  << adrAssembler.diffusionAssemblyChrono().diffCumul()
220  << std::endl;
221  }
222 
223  if (verbose)
224  {
225  std::cout << " -- Closing the matrix ... " << std::flush;
226  }
227  systemMatrix->globalAssemble();
228  if (verbose)
229  {
230  std::cout << " done ! " << std::endl;
231  }
232 
233  Real matrixNorm (systemMatrix->normFrobenius() );
234  if (verbose)
235  {
236  std::cout << " ---> Norm 1 : " << matrixNorm << std::endl;
237  }
238  if ( std::fabs (matrixNorm - 35.908 ) > 1e-3)
239  {
240  std::cout << " <!> Matrix has changed !!! <!> " << std::endl;
241  return EXIT_FAILURE;
242  }
243 
244  if (verbose)
245  {
246  std::cout << "End Result: TEST PASSED" << std::endl;
247  }
248 
249 #ifdef HAVE_MPI
250  MPI_Finalize();
251 #endif
252 
253  return ( EXIT_SUCCESS );
254 }
VectorEpetra - The Epetra Vector format Wrapper.
void assignFunction(bcBase_Type &base)
Assign the function to the base of the BCHandler.
int main(int argc, char **argv)
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
Class that does flexible mesh partitioning.
std::shared_ptr< feSpace_Type > feSpacePtr_Type
FESpace< mesh_Type, MapEpetra > feSpace_Type
MeshPartitionTool< mesh_Type > meshCutter_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
double Real
Generic real data.
Definition: LifeV.hpp:175
RegionMesh< LinearTetra > mesh_Type