LifeV
lifev/navier_stokes/examples/computeWSS/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 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  \file main.cpp
28  \author Paolo Tricerri <paolo.tricerri@epfl.ch>
29  \date 2012-05-01
30  */
31 #undef HAVE_HDF5
32 #ifdef TWODIM
33 #error example_computeWSS cannot be compiled in 2D
34 #endif
35 
36 #include <Epetra_ConfigDefs.h>
37 #ifdef EPETRA_MPI
38 #include <mpi.h>
39 #include <Epetra_MpiComm.h>
40 #else
41 #include <Epetra_SerialComm.h>
42 #endif
43 
44 #include <lifev/core/LifeV.hpp>
45 
46 //Vectors and related things
47 #include <lifev/core/array/MapEpetra.hpp>
48 #include <lifev/core/array/VectorEpetra.hpp>
49 #include <lifev/core/array/MatrixSmall.hpp>
50 #include <lifev/core/array/VectorSmall.hpp>
51 
52 // Mesh infos
53 #include <lifev/core/mesh/MeshData.hpp>
54 #include <lifev/core/mesh/RegionMesh.hpp>
55 #include <lifev/core/mesh/MeshPartitioner.hpp>
56 
57 // FESpaces and ETFESpaces
58 #include <lifev/core/fem/FESpace.hpp>
59 #include <lifev/eta/fem/ETFESpace.hpp>
60 
61 //Oseen data to make use of the fields that are available there.
62 //No real need for this.
63 #include <lifev/navier_stokes/solver/OseenData.hpp>
64 
65 // Evaluation operations
66 #include <lifev/eta/expression/Evaluate.hpp>
67 #include <lifev/eta/expression/Integrate.hpp>
68 
69 #include <lifev/core/filter/ExporterEnsight.hpp>
70 #ifdef HAVE_HDF5
71 #include <lifev/core/filter/ExporterHDF5.hpp>
72 #endif
73 #include <lifev/core/filter/ExporterEmpty.hpp>
74 
75 #include <iostream>
76 
77 using namespace LifeV;
78 
79 int returnValue = EXIT_SUCCESS;
80 
82 {
83  std::string stringList = list;
84  std::set<UInt> setList;
85  if ( list == "" )
86  {
87  return setList;
88  }
89  size_t commaPos = 0;
90  while ( commaPos != std::string::npos )
91  {
92  commaPos = stringList.find ( "," );
93  setList.insert ( atoi ( stringList.substr ( 0, commaPos ).c_str() ) );
94  stringList = stringList.substr ( commaPos + 1 );
95  }
96  setList.insert ( atoi ( stringList.c_str() ) );
97  return setList;
98 }
99 
100 class WSS
101 {
102 public:
103 
105 
106  // Filters
107  typedef LifeV::Exporter<mesh_Type > filter_Type;
109 
114 
115 #ifdef HAVE_HDF5
118 #endif
119 
120 
121 
122  /** @name Constructors, destructor
123  */
124  //@{
125  WSS ( int argc,
126  char** argv,
127  std::shared_ptr<Epetra_Comm> structComm );
128 
129  ~WSS()
130  {}
131  //@}
132 
133  //@{
134  void run()
135  {
136  run3d();
137  }
138  //@}
139 
140 protected:
141 
142 private:
143 
144  /**
145  * run the 2D driven cylinder simulation
146  */
147  void run2d();
148 
149  /**
150  * run the 3D driven cylinder simulation
151  */
152  void run3d();
153 
154 private:
155  struct Private;
158 };
159 
160 
161 
162 struct WSS::Private
163 {
165  {}
166  typedef std::function<Real ( Real const&, Real const&, Real const&, Real const&, ID const& ) > fct_type;
167 
169 
171 
172 };
173 
174 
175 
176 WSS::WSS ( int argc,
177  char** argv,
178  std::shared_ptr<Epetra_Comm> structComm) :
179  parameters ( new Private() )
180 {
181  GetPot command_line (argc, argv);
182  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
183  GetPot dataFile ( data_file_name );
184  parameters->data_file_name = data_file_name;
185 
186  parameters->comm = structComm;
187  int ntasks = parameters->comm->NumProc();
188 
189  if (!parameters->comm->MyPID() )
190  {
191  std::cout << "My PID = " << parameters->comm->MyPID() << " out of " << ntasks << " running." << std::endl;
192  }
193 }
194 
195 
196 
197 void
199 {
200  std::cout << "2D WSS example is not available yet\n";
201 }
202 
203 
204 
205 void
207 {
208  typedef VectorEpetra vector_Type;
209  typedef std::shared_ptr<VectorEpetra> vectorPtr_Type;
210 
211  typedef FESpace< mesh_Type, MapEpetra > wssFESpace_Type;
212  typedef std::shared_ptr<wssFESpace_Type> wssFESpacePtr_Type;
213 
214  typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 3 > vectorialETFESpace_Type;
215  typedef std::shared_ptr<vectorialETFESpace_Type> vectorialETFESpacePtr_Type;
216 
217  typedef ETFESpace< RegionMesh<LinearTetra>, MapEpetra, 3, 1 > scalarETFESpace_Type;
218  typedef std::shared_ptr<scalarETFESpace_Type> scalarETFESpacePtr_Type;
219 
220  bool verbose = (parameters->comm->MyPID() == 0);
221 
222  //! dataElasticStructure for parameters
223  GetPot dataFile ( parameters->data_file_name.c_str() );
224  std::shared_ptr<OseenData> dataClass (new OseenData( ) );
225  dataClass->setup (dataFile);
226 
227  dataClass->showMe();
228 
229  //! Read and partition mesh
230  MeshData meshData;
231  meshData.setup (dataFile, "fluid/space_discretization");
232 
233  std::shared_ptr<mesh_Type > fullMeshPtr (new RegionMesh<LinearTetra> ( ( parameters->comm ) ) );
234  readMesh (*fullMeshPtr, meshData);
235 
236  MeshPartitioner< mesh_Type > meshPart ( fullMeshPtr, parameters->comm );
237 
238  wssFESpacePtr_Type velFESpace ( new wssFESpace_Type (meshPart, dataClass->uOrder() , 3, parameters->comm) );
239 
240  // This FESpace is to have the nice quadrature rule
241  wssFESpacePtr_Type quadFESpace ( new wssFESpace_Type (meshPart, dataClass->uOrder() , 2, parameters->comm) );
242 
243  vectorialETFESpacePtr_Type uETFESpace ( new vectorialETFESpace_Type (meshPart, & (velFESpace->refFE() ),
244  & (velFESpace->fe().geoMap() ), parameters->comm) );
245 
246  //! 3. Creation of the importers to read the solution (u,p)
247  std::string const filename = dataFile ( "importer/filename", "noNameFile");
248  std::string const importerType = dataFile ( "importer/type", "hdf5");
249 
250  // How many solution do we have to read?
251  // If you want to read a specific solution, choose instant
252  // If you want to read a set of solutions, choose interval.
253  std::string readType = dataFile ( "importer/analysis", "instant");
254  UInt numberOfSol(0);
255  UInt start(0);
256  UInt end(0);
257 
258  if( !readType.compare("instant") )
259  {
260  numberOfSol = dataFile.vector_variable_size ( "importer/iteration" );
261  ASSERT( numberOfSol, "You did not set any solution to read!! ");
262  }
263  else
264  {
265  start = dataFile ( "importer/iterationStart" , 0 );
266  end = dataFile ( "importer/iterationEnd" , 0 );
267  numberOfSol = end - start;
268  }
269  ASSERT( numberOfSol, "You did not set any solution to read!! ");
270 
271  if (verbose)
272  {
273  std::cout << "The filename is : " << filename << std::endl;
274  std::cout << "The importerType is: " << importerType << std::endl;
275  }
276 
277 #ifdef HAVE_HDF5
278  if (importerType.compare ("hdf5") == 0)
279  {
280  M_importer.reset ( new hdf5Filter_Type (dataFile, filename) );
281  }
282  else
283 #endif
284  {
285  if (importerType.compare ("none") == 0)
286  {
287  M_importer.reset ( new emptyFilter_Type ( dataFile, velFESpace->mesh(), "WSS", velFESpace->map().comm().MyPID() ) );
288  }
289  else
290  {
291  M_importer.reset ( new ensightFilter_Type ( dataFile, filename ) );
292  }
293  }
294  M_importer->setMeshProcId (velFESpace->mesh(), velFESpace->map().comm().MyPID() );
295 
296  //! 6. Post-processing setting
297  std::shared_ptr< Exporter<RegionMesh<LinearTetra> > > exporter;
298 
299  std::string const exporterType = dataFile ( "exporter/type", "hdf5");
300  std::string const nameExporter = dataFile ( "exporter/name", "jacobian");
301 
302 #ifdef HAVE_HDF5
303  if (exporterType.compare ("hdf5") == 0)
304  {
305  exporter.reset ( new hdf5Filter_Type ( dataFile, nameExporter) );
306  }
307  else
308 #endif
309  {
310  if (exporterType.compare ("none") == 0)
311  {
312  exporter.reset ( new emptyFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
313  }
314 
315  else
316  {
317  exporter.reset ( new ensightFilter_Type ( dataFile, meshPart.meshPartition(), nameExporter, parameters->comm->MyPID() ) ) ;
318  }
319  }
320  exporter->setMeshProcId (velFESpace->mesh(), velFESpace->map().comm().MyPID() );
321 
322  // Scalar vector to have scalar quantities
323  vectorPtr_Type patchAreaVector;
324 
325  vectorPtr_Type velocity;
326  vectorPtr_Type velocityRead;
327 
328  vectorPtr_Type WSSvector;
329 
330  patchAreaVector.reset ( new vector_Type ( uETFESpace->map() ) );
331  velocity.reset( new vector_Type( velFESpace->map() ) );
332  velocityRead.reset( new vector_Type( velFESpace->map() ) );
333 
334  WSSvector.reset ( new vector_Type ( uETFESpace->map() ) );
335 
336  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "WSS",
337  velFESpace, WSSvector, UInt (0) );
338 
339  // Debug purposes
340  exporter->addVariable ( ExporterData<RegionMesh<LinearTetra> >::VectorField, "velocityRead",
341  velFESpace, velocityRead, UInt (0) );
342 
343  exporter->postProcess ( 0.0 );
344 
345  //! =================================================================================
346  //! Analysis - Istant or Interval
347  //! =================================================================================
348 
349  MPI_Barrier (MPI_COMM_WORLD);
350 
351  QuadratureRule fakeQuadratureRule( quadRuleTria3pt );
352 
353  GeoVector firstPoint(2); Real firstWeight(0.0);
354  firstPoint[0] = 0.0; firstPoint[1] = 0.0;; firstWeight = ( 0.5 ) / 3;
355  QuadraturePoint first( firstPoint, firstWeight );
356 
357  GeoVector secondPoint(2); Real secondWeight(0.0);
358  secondPoint[0] = 1.0; secondPoint[1] = 0.0; secondWeight = ( 0.5 ) / 3;
359  QuadraturePoint second( secondPoint, secondWeight );
360 
361  GeoVector thirdPoint(2); Real thirdWeight(0.0);
362  thirdPoint[0] = 0.0; thirdPoint[1] = 1.0; thirdWeight = ( 0.5 ) / 3;
363  QuadraturePoint third( thirdPoint, thirdWeight );
364 
365  std::vector<GeoVector> coordinates( 3 );
366  coordinates[0] = firstPoint;
367  coordinates[1] = secondPoint;
368  coordinates[2] = thirdPoint;
369  std::vector<Real> weights ( 3 , 1.0 / 6.0 );
370 
371  fakeQuadratureRule.setPoints(coordinates, weights);
372  QuadratureBoundary adaptedBDQuadRule( buildTetraBDQR( fakeQuadratureRule ) );
373 
374  using namespace ExpressionAssembly;
375 
376  // Trying to compute the Jacobian using ET
377  MatrixSmall<3,3> identity;
378  identity (0, 0) = 1.0;
379  identity (0, 1) = 0.0;
380  identity (0, 2) = 0.0;
381  identity (1, 0) = 0.0;
382  identity (1, 1) = 1.0;
383  identity (1, 2) = 0.0;
384  identity (2, 0) = 0.0;
385  identity (2, 1) = 0.0;
386  identity (2, 2) = 1.0;
387 
389  evaluateNode( boundary( uETFESpace->mesh(), 200 ),
390  adaptedBDQuadRule,
391  uETFESpace,
392  dot( vMeas , phi_i )
393  ) >> patchAreaVector;
394  patchAreaVector->globalAssemble();
395 
396  std::string const nameField = dataFile ( "importer/nameField", "f-velocity");
397  UInt i,k;
398 
399  for( i=0,k =0; i < numberOfSol; i++, k++ )
400  {
401 
402  // Reading the solution
403  // resetting the element of the vector
404  *velocity *= 0.0;
405  *WSSvector *= 0.0;
406  UInt current(0);
407  if( !readType.compare("interval") )
408  {
409  current = i + start;
410  }
411  else
412  {
413  current = dataFile ( "importer/iteration" , 100000, i );
414  }
415  // Transform current ingot a string
416  std::string iterationString;
417  std::ostringstream number;
418  number.fill ( '0' );
419  number << std::setw (5) << ( current );
420  iterationString = number.str();
421 
422  std::cout << "Current reading: " << iterationString << std::endl;
423 
424  /*!Definition of the ExporterData, used to load the solution inside the previously defined vectors*/
425  LifeV::ExporterData<mesh_Type> solutionVel (LifeV::ExporterData<mesh_Type>::VectorField,nameField + "." + iterationString,
426  velFESpace, velocity, UInt (0), LifeV::ExporterData<mesh_Type>::UnsteadyRegime );
427 
428 
429  //Read the variable
430  M_importer->readVariable (solutionVel);
431  *velocityRead = *velocity;
432 
433  Real dynamicViscosity = dataClass->viscosity( );
434 
435  std::cout << "Viscosity: " << dataClass->viscosity( ) << std::endl;
436  // Defining expressions
437  evaluateNode( boundary( uETFESpace->mesh(), 200 ),
438  adaptedBDQuadRule,
439  uETFESpace,
440  meas_BDk * dot ( value(dynamicViscosity) * ( grad(uETFESpace, *velocity) + transpose(grad(uETFESpace, *velocity)) ) * Nface -
441  dot( value(dynamicViscosity) * ( grad(uETFESpace, *velocity) + transpose(grad(uETFESpace, *velocity)) ) * Nface , Nface ) * Nface, phi_i )
442  ) >> WSSvector;
443  WSSvector->globalAssemble();
444  *WSSvector = *WSSvector / *patchAreaVector;
445 
446  // // Defining expressions
447  // integrate( boundary( uETFESpace->mesh(), 1 ),
448  // adaptedBDQuadRule,
449  // uETFESpace,
450  // dot ( Nface, phi_i )
451  // ) >> WSSvector;
452  // WSSvector->globalAssemble();
453 
454 
455  exporter->postProcess( dataClass->dataTime()->initialTime() + k * dataClass->dataTime()->timeStep() );
456  }
457 
458 
459  if (verbose )
460  {
461  std::cout << "Analysis Completed!" << std::endl;
462  }
463 
464  //Closing files
465  exporter->closeFile( );
466  M_importer->closeFile( );
467 
468  MPI_Barrier (MPI_COMM_WORLD);
469  //!---------------------------------------------.-----------------------------------------------------
470 }
471 
472 int
473 main ( int argc, char** argv )
474 {
475 
476 #ifdef HAVE_MPI
477  MPI_Init (&argc, &argv);
478  std::shared_ptr<Epetra_MpiComm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
479  if ( Comm->MyPID() == 0 )
480  {
481  std::cout << "% using MPI" << std::endl;
482  }
483 #else
484  std::shared_ptr<Epetra_SerialComm> Comm ( new Epetra_SerialComm() );
485  std::cout << "% using serial Version" << std::endl;
486 #endif
487 
488  WSS wss ( argc, argv, Comm );
489  wss.run();
490 
491 #ifdef HAVE_MPI
492  MPI_Finalize();
493 #endif
494  return returnValue ;
495 }
VectorEpetra - The Epetra Vector format Wrapper.
LifeV::Exporter< mesh_Type > filter_Type
class ExpressionEmult Class for representing the transpose operation of an expression ...
ExporterEnsight data exporter.
FESpace - Short description here please!
Definition: FESpace.hpp:78
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::shared_ptr< Epetra_Comm > comm
std::shared_ptr< ensightFilter_Type > ensightFilterPtr_Type
boost::numeric::ublas::vector< Real > GeoVector
QuadratureRule(const QuadratureRule &qr)
Copy constructor.
std::set< UInt > parseList(const std::string &list)
WSS(int argc, char **argv, std::shared_ptr< Epetra_Comm > structComm)
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
QuadraturePoint - Simple container for a point of a quadrature rule.
std::shared_ptr< LifeV::Exporter< mesh_Type > > filterPtr_Type
std::shared_ptr< std::vector< Int > > M_isOnProc
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
ExpressionMeasBDCurrentFE - Expression for the measure of the element.
LifeV::ExporterEnsight< mesh_Type > ensightFilter_Type
std::shared_ptr< Private > parameters
double Real
Generic real data.
Definition: LifeV.hpp:175
const QuadratureRule quadRuleTria3pt(pt_tria_3pt, 2, "Quadrature rule 3 points on a triangle", TRIANGLE, 3, 2)
LifeV::ExporterEmpty< mesh_Type > emptyFilter_Type
int operator()(const char *VarName, int Default, unsigned Idx) const
Definition: GetPot.hpp:2137
int operator()(const char *VarName, int Default) const
Definition: GetPot.hpp:2021
QuadraturePoint(const GeoVector &coor, const Real &weight)
Full multidimension constructor.
void run2d()
run the 2D driven cylinder simulation
QuadratureRule - The basis class for storing and accessing quadrature rules.
std::shared_ptr< emptyFilter_Type > emptyFilterPtr_Type
int main(int argc, char **argv)
void run3d()
run the 3D driven cylinder simulation
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
LifeV::RegionMesh< LinearTetra > mesh_Type
unsigned vector_variable_size(const char *VarName) const
Definition: GetPot.hpp:2291