LifeV
lifev/navier_stokes_blocks/testsuite/nonlinear_steady_navier_stokes/main.cpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2 
3  This file is part of the LifeV library.
4  Copyright (C) 2010 EPFL
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2.1 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful, but
12  WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  USA
20 */
21 /**
22  \file main.cpp
23  \author Davide Forti <davide.forti@epfl.ch>
24  \date 2014-02-06
25  */
26 
27 
28 #include <Epetra_ConfigDefs.h>
29 #ifdef EPETRA_MPI
30 #include <mpi.h>
31 #include <Epetra_MpiComm.h>
32 #else
33 #include <Epetra_SerialComm.h>
34 #endif
35 
36 
37 #include <lifev/core/LifeV.hpp>
38 #include <lifev/core/mesh/MeshData.hpp>
39 #include <lifev/core/mesh/MeshPartitioner.hpp>
40 #include <lifev/navier_stokes_blocks/solver/NavierStokesSolverBlocks.hpp>
41 #include <lifev/core/fem/TimeAndExtrapolationHandler.hpp>
42 #include <lifev/core/filter/ExporterEnsight.hpp>
43 #include <lifev/core/filter/ExporterHDF5.hpp>
44 #include <lifev/core/filter/ExporterVTK.hpp>
45 #include <Teuchos_XMLParameterListHelpers.hpp>
46 #include <lifev/core/filter/PartitionIO.hpp>
47 
49 
50 using namespace LifeV;
51 
52 int
53 main ( int argc, char** argv )
54 {
55  bool verbose (false);
56 #ifdef HAVE_MPI
57  MPI_Init (&argc, &argv);
58  std::shared_ptr<Epetra_Comm> Comm ( new Epetra_MpiComm (MPI_COMM_WORLD) );
59  if ( Comm->MyPID() == 0 )
60  {
61  verbose = true;
62  }
63 #else
64  std::shared_ptr<Epetra_Comm> Comm( new Epetra_SerialComm () );
65  verbose = true;
66 #endif
67 
68  Real normTwo_Velo;
69  Real normTwo_Pres;
70 
71  {
72 
73  typedef RegionMesh<LinearTetra> mesh_Type;
74  typedef VectorEpetra vector_Type;
75  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
76 
77  // Reading the dataFile
78  const std::string defaultDataName = "data";
79  GetPot command_line (argc, argv);
80  std::string data_file_name = command_line.follow (defaultDataName.c_str(), 2, "-f", "--file");
81  GetPot dataFile( data_file_name );
82 
83  // Mesh
84  std::shared_ptr<mesh_Type > localMeshPtr ( new mesh_Type ( Comm ) );
85 
86  if ( dataFile ( "offline_partitioner/useOfflinePartitionedMesh", false) )
87  {
88  std::shared_ptr<Epetra_MpiComm> comm = std::dynamic_pointer_cast<Epetra_MpiComm>(Comm);
89  const std::string partsFileName (dataFile ("offline_partitioner/hdf5_file_name", "name.h5") );
90  PartitionIO<mesh_Type > partitionIO (partsFileName, comm);
91  partitionIO.read (localMeshPtr);
92  }
93  else
94  {
95  // reading the mesh
96  std::shared_ptr<mesh_Type > fullMeshPtr ( new mesh_Type ( Comm ) );
97  MeshData meshData;
98  meshData.setup (dataFile, "fluid/space_discretization");
99  readMesh (*fullMeshPtr, meshData);
100 
101  // mesh partitioner
102  MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
103  localMeshPtr = meshPart.meshPartition();
104  fullMeshPtr.reset();
105  }
106 
107  // create the solver
108  NavierStokesSolverBlocks ns( dataFile, Comm);
109  ns.setup(localMeshPtr);
111  ns.buildSystem();
112 
113  // Exporter
114  std::string outputName = dataFile ( "exporter/filename", "result");
115  std::shared_ptr< Exporter<mesh_Type > > exporter;
116  std::string const exporterType = dataFile ( "exporter/type", "ensight");
117 
118 #ifdef HAVE_HDF5
119  if (exporterType.compare ("hdf5") == 0)
120  {
121  exporter.reset ( new ExporterHDF5<mesh_Type > ( dataFile, outputName ) );
122  exporter->setPostDir ( "./" ); // This is a test to see if M_post_dir is working
123  exporter->setMeshProcId ( localMeshPtr, Comm->MyPID() );
124  }
125 #endif
126  else if(exporterType.compare ("vtk") == 0)
127  {
128  exporter.reset ( new ExporterVTK<mesh_Type > ( dataFile, outputName ) );
129  exporter->setPostDir ( "./" ); // This is a test to see if M_post_dir is working
130  exporter->setMeshProcId ( localMeshPtr, Comm->MyPID() );
131  }
132 
133  // Vectors post-processing
134  vectorPtr_Type velocity( new vector_Type(ns.uFESpace()->map(), exporter->mapType() ) );
135  vectorPtr_Type pressure( new vector_Type(ns.pFESpace()->map(), exporter->mapType() ) );
136  exporter->addVariable ( ExporterData<mesh_Type>::VectorField, "velocity", ns.uFESpace(), velocity, UInt (0) );
137  exporter->addVariable ( ExporterData<mesh_Type>::ScalarField, "pressure", ns.pFESpace(), pressure, UInt (0) );
138  exporter->postProcess ( 0.0 );
139 
140  // Boundary conditions
141  std::shared_ptr<BCHandler> bc ( new BCHandler (*BCh_fluid ()) );
142 
143  // Set boundary conditions
144  ns.setBoundaryConditions( bc );
145 
146  // Solve problem
148 
149  // Get the velocity
150  ns.updateVelocity(velocity);
151 
152  // Get the pressure
153  ns.updatePressure(pressure);
154 
155  // Do post-processing
156  exporter->postProcess ( 1.0 );
157 
158  // Close file post-processing
159  exporter->closeFile();
160 
161  normTwo_Velo = velocity->norm2();
162  normTwo_Pres = pressure->norm2();
163 
164  }
165 
166 #ifdef HAVE_MPI
167  if (verbose)
168  {
169  std::cout << "\nMPI Finalization" << std::endl;
170  }
171  MPI_Finalize();
172 #endif
173 
174  if ( std::abs(normTwo_Velo - 108.783606 ) < 1.0e-4 && std::abs(normTwo_Pres - 129.597065 ) < 1.0e-4 )
175  {
176  return ( EXIT_SUCCESS );
177  }
178  else
179  {
180  return ( EXIT_FAILURE );
181  }
182 }
void iterate_steady()
Solve the steady Navier-Stokes equations.
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::shared_ptr< std::vector< Int > > M_isOnProc
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
void setParameters()
Set parameters of the solver.
double Real
Generic real data.
Definition: LifeV.hpp:175
void updatePressure(vectorPtr_Type &pressure)
Get the pressure vector.
void buildSystem()
Assemble constant terms.
bool operator()(const char *VarName, bool Default) const
Definition: GetPot.hpp:2008
int main(int argc, char **argv)