LifeV
test_TimeAndExtrapolationHandler.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 
9 #include <Epetra_ConfigDefs.h>
10 #ifdef EPETRA_MPI
11 #include <mpi.h>
12 #include <Epetra_MpiComm.h>
13 #else
14 #include <Epetra_SerialComm.h>
15 #endif
16 
17 
18 // LifeV includes
19 #include <lifev/core/LifeV.hpp>
20 #include <sys/stat.h>
21 
22 // Exporters
23 #include <lifev/core/filter/ExporterEnsight.hpp>
24 #include <lifev/core/filter/ExporterEmpty.hpp>
25 #ifdef HAVE_HDF5
26 #include <lifev/core/filter/ExporterHDF5.hpp>
27 #endif
28 
29 // Files
30 #include <lifev/core/mesh/MeshData.hpp>
31 #include <lifev/core/mesh/MeshPartitioner.hpp>
32 #include <lifev/core/fem/TimeAndExtrapolationHandler.hpp>
33 
34 using namespace LifeV;
35 
39 typedef FESpace<mesh_Type, MapEpetra > FESpace_Type;
41 
42 int main (int argc, char** argv)
43 {
44 
45 #ifdef HAVE_MPI
46  MPI_Init (&argc, &argv);
47  std::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm ( MPI_COMM_WORLD ) );
48  bool verbose = Comm->MyPID() == 0;
49 #else
50  std::shared_ptr<Epetra_Comm> Comm ( new Epetra_SerialComm() );
51  bool verbose = true;
52 #endif
53 
54  GetPot command_line (argc, argv);
55  const bool check = command_line.search (2, "-c", "--check");
56 
57  const std::string dataFile = command_line.follow ("data_TimeAndExtrapolationHandler", 2, "-d", "--data_TimeAndExtrapolationHandler");
58  GetPot data_file(dataFile);
59 
60  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
61  // LOADING THE MESH
62  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63 
64  MeshData meshDataFluid;
65  meshDataFluid.setup(data_file, "mesh_fluid");
66 
67  meshPtr_Type fluidMeshFull;
68 
69  if(Comm->MyPID()==0)
70  std::cout << "\n[Loading the mesh ] .." << std::flush;
71 
72  fluidMeshFull.reset(new mesh_Type());
73  readMesh(*fluidMeshFull, meshDataFluid);
74 
75  if(Comm->MyPID()==0)
76  std::cout << " done! \n\n" << std::flush;
77 
78  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
79 
80 
81  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
82  // PARTITIONING THE MESH
83  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84 
85 
86  if(Comm->MyPID()==0)
87  std::cout << "[Partitioning the fluid mesh ] \n\n";
88 
89  MeshPartitioner<mesh_Type > fluidPartio(fluidMeshFull, Comm);
90 
91  meshPtr_Type fluidMeshLocal;
92 
93  fluidMeshLocal.reset(new mesh_Type(*fluidPartio.meshPartition()));
94 
95  if(Comm->MyPID()==0)
96  std::cout << "\n";
97 
98  FESpacePtr_Type velocityFESpace;
99  velocityFESpace.reset (new FESpace_Type (fluidMeshLocal, "P1", 1, 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  TimeAndExtrapolationHandler timeVelocity;
114  timeVelocity.setBDForder(orderBDF);
115  timeVelocity.setMaximumExtrapolationOrder(orderExtrapolation);
116 
117  // Set the timestep
118  timeVelocity.setTimeStep(0.2);
119 
120  // Initialize 3 vectors
121  vector_Type firstVector(velocityFESpace->map());
122  vector_Type secondVector(velocityFESpace->map());
123  vector_Type thirdVector(velocityFESpace->map());
124  firstVector += 1;
125  secondVector += 2;
126  thirdVector += 3;
127 
128  // Initialize the state with two vectors (we suppose that in the datafile orderBDF=2)
129  std::vector<vector_Type> initialState;
130  initialState.push_back(firstVector);
131  initialState.push_back(secondVector);
132  timeVelocity.initialize(initialState);
133 
134  if(Comm->MyPID()==0)
135  std::cout << "\n";
136 
137  // empty vector to check the extrapolation
138  vector_Type extrapolation(velocityFESpace->map());
139 
140  // Do an extrapolation
141  timeVelocity.extrapolate(orderExtrapolation, extrapolation);
142  extrapolation.spy("FirstExtrapolation");
143 
144  // Put in the stencil a new vector, and do a new extrapolation
145  timeVelocity.shift(thirdVector);
146  timeVelocity.extrapolate(orderExtrapolation, extrapolation);
147  extrapolation.spy("SecondExtrapolation");
148 
149  // Compute the term that should go to the right hand side
150  vector_Type rhsTerm(velocityFESpace->map());
151  timeVelocity.rhsContribution(rhsTerm);
152  rhsTerm.spy("rhsTerm");
153 
154  timeVelocity.state()[0].spy("StatoZero");
155  timeVelocity.state()[1].spy("StatoUno");
156 
157  // Print the value of alpha
158  std::cout << "\nAlpha = " << timeVelocity.alpha() << "\n\n";
159 
160 #ifdef HAVE_MPI
161  MPI_Finalize();
162 #endif
163 
164 
165  return 0;
166 
167 }
VectorEpetra - The Epetra Vector format Wrapper.
VectorEpetra & operator+=(const data_type &scalar)
Addition operator.
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::shared_ptr< mesh_Type > meshPtr_Type
VectorEpetra vector_Type
FESpace< mesh_Type, MapEpetra > FESpace_Type
Epetra_Import const & importer()
Getter for the Epetra_Import.
Definition: MapEpetra.cpp:394
std::shared_ptr< FESpace_Type > FESpacePtr_Type
RegionMesh< LinearTetra > mesh_Type
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
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