LifeV
test_TimeAndExtrapolationHandlerQuadPts.cpp
Go to the documentation of this file.
1 /* davide forti*/
2 
3 #undef HAVE_HDF5
4 
5 #include <cassert>
6 #include <cstdlib>
7 
8 #include <Epetra_ConfigDefs.h>
9 #ifdef EPETRA_MPI
10 #include <mpi.h>
11 #include <Epetra_MpiComm.h>
12 #else
13 #include <Epetra_SerialComm.h>
14 #endif
15 
16 
17 // LifeV includes
18 #include <lifev/core/LifeV.hpp>
19 #include <sys/stat.h>
20 
21 // Exporters
22 #include <lifev/core/filter/ExporterEnsight.hpp>
23 #include <lifev/core/filter/ExporterEmpty.hpp>
24 #ifdef HAVE_HDF5
25 #include <lifev/core/filter/ExporterHDF5.hpp>
26 #endif
27 
28 // Files
29 #include <lifev/core/mesh/MeshData.hpp>
30 #include <lifev/core/mesh/MeshPartitioner.hpp>
31 #include <lifev/core/fem/TimeAndExtrapolationHandlerQuadPts.hpp>
32 
33 using namespace LifeV;
34 
38 typedef FESpace<mesh_Type, MapEpetra > FESpace_Type;
40 
41 int main (int argc, char** argv)
42 {
43 
44 #ifdef HAVE_MPI
45  MPI_Init (&argc, &argv);
46  std::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
47  bool verbose = Comm->MyPID() == 0;
48 #else
49  std::shared_ptr<Epetra_Comm> Comm ( new Epetra_SerialComm() );
50  bool verbose = true;
51 #endif
52 
53  GetPot command_line (argc, argv);
54  const bool check = command_line.search (2, "-c", "--check");
55 
56  const std::string dataFile = command_line.follow ("data_TimeAndExtrapolationHandler", 2, "-d", "--data_TimeAndExtrapolationHandler");
57  GetPot data_file(dataFile);
58 
59  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
60  // LOADING THE MESH
61  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62 
63  MeshData meshDataFluid;
64  meshDataFluid.setup(data_file, "mesh_fluid");
65 
66  meshPtr_Type fluidMeshFull;
67 
68  if(Comm->MyPID()==0)
69  std::cout << "\n[Loading the mesh ] .." << std::flush;
70 
71  fluidMeshFull.reset(new mesh_Type());
72  readMesh(*fluidMeshFull, meshDataFluid);
73 
74  if(Comm->MyPID()==0)
75  std::cout << " done! \n\n" << std::flush;
76 
77  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
78 
79 
80  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81  // PARTITIONING THE MESH
82  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
83 
84 
85  if(Comm->MyPID()==0)
86  std::cout << "[Partitioning the fluid mesh ] \n\n";
87 
88  MeshPartitioner<mesh_Type > fluidPartio(fluidMeshFull, Comm);
89 
90  meshPtr_Type fluidMeshLocal;
91 
92  fluidMeshLocal.reset(new mesh_Type(*fluidPartio.meshPartition()));
93 
94  if(Comm->MyPID()==0)
95  std::cout << "\n";
96 
97  const UInt sizeField = 3;
98  FESpacePtr_Type velocityFESpace;
99  velocityFESpace.reset (new FESpace_Type (fluidMeshLocal, data_file("mesh_fluid/fe_order","P1"), sizeField, Comm) );
100 
101 
102  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103  // TESTING THE TIME HANDLER OBJECT
104  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
105 
106  if(Comm->MyPID()==0)
107  std::cout << "[Test with empty constructor ]";
108 
109  UInt orderBDF = data_file("dataTimeHandler/orderBDF",2);
110  UInt orderExtrapolation = data_file("dataTimeHandler/orderExtrapolation",2);
111 
112  // Initialize the time handler object, set the order of the BDF and for the extrapolation
113  TimeAndExtrapolationHandlerQuadPts<sizeField> timeVelocity;
114  timeVelocity.setBDForder(orderBDF);
115 
116  // Set the timestep
117  timeVelocity.setTimeStep(0.2);
118 
119  std::vector<std::vector<VectorSmall<sizeField>>> firstVector;
120  std::vector<std::vector<VectorSmall<sizeField>>> secondVector;
121  std::vector<std::vector<VectorSmall<sizeField>>> thirdVector;
122 
123  firstVector.resize(fluidMeshLocal->numElements());
124  secondVector.resize(fluidMeshLocal->numElements());
125  thirdVector.resize(fluidMeshLocal->numElements());
126 
127  // Initialize 3 vectors
128  for (int i = 0 ; i < fluidMeshLocal->numElements() ; ++i ) // loop elements
129  {
130  firstVector[i].resize(velocityFESpace->qr().nbQuadPt());
131  secondVector[i].resize(velocityFESpace->qr().nbQuadPt());
132  thirdVector[i].resize(velocityFESpace->qr().nbQuadPt());
133 
134  for (int j = 0 ; j < velocityFESpace->qr().nbQuadPt(); ++j ) // loop quadrature points
135  {
136  for (int k = 0 ; k < sizeField; ++k ) // loop dimensions
137  {
138  firstVector[i][j](k) = 1.0;
139  secondVector[i][j](k) = 2.0;
140  thirdVector[i][j](k) = 3.0;
141  }
142  }
143  }
144 
145  // Initialize the state with two vectors (we suppose that in the datafile orderBDF=2)
146  std::vector<std::vector<std::vector<VectorSmall<sizeField>>>> initialState;
147  initialState.push_back(firstVector);
148  initialState.push_back(secondVector);
149  timeVelocity.initialize(initialState);
150 
151  if(Comm->MyPID()==0)
152  std::cout << "\n";
153 
154  // Put in the stencil a new vector, and do a new extrapolation
155  timeVelocity.shift(thirdVector);
156 
157  // Compute the term that should go to the right hand side
158  std::vector<std::vector<VectorSmall<sizeField>>> rhsTerm;
159  rhsTerm.resize(fluidMeshLocal->numElements());
160  for (int i = 0 ; i < fluidMeshLocal->numElements() ; ++i ) // loop elements
161  {
162  rhsTerm[i].resize(velocityFESpace->qr().nbQuadPt());
163  }
164 
165  timeVelocity.rhsContribution(rhsTerm);
166 
167  for ( int i = 0; i < fluidMeshLocal->numElements(); ++i )
168  {
169  for ( int j = 0; j < velocityFESpace->qr().nbQuadPt(); ++j )
170  {
171  std::cout << " (";
172  for ( int k = 0; k < sizeField; ++k )
173  {
174  std::cout << " " << rhsTerm[i][j](k);
175  }
176  std::cout << "),";
177  }
178 
179  std::cout << "\n";
180  }
181 
182 
183  // Print the value of alpha
184  std::cout << "\nAlpha = " << timeVelocity.alpha() << "\n\n";
185 
186 #ifdef HAVE_MPI
187  MPI_Finalize();
188 #endif
189 
190 
191  return 0;
192 
193 }
VectorEpetra - The Epetra Vector format Wrapper.
RegionMesh< LinearTetra > mesh_Type
std::shared_ptr< mesh_Type > meshPtr_Type
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::vector< std::vector< VectorSmall< DIM > > > vector_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
int operator()(const char *VarName, int Default) const
Definition: GetPot.hpp:2021
bool search(unsigned No, const char *P,...)
Definition: GetPot.hpp:1217
GetPot(const STRING_VECTOR &FileNameList)
Definition: GetPot.hpp:645
std::shared_ptr< FESpace_Type > FESpacePtr_Type
const std::string follow(const char *Default, unsigned No, const char *Option,...)
Definition: GetPot.hpp:1510
int main(int argc, char **argv)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
FESpace< mesh_Type, MapEpetra > FESpace_Type