40 #include <Epetra_ConfigDefs.h> 43 #include <Epetra_MpiComm.h> 45 #include <Epetra_SerialComm.h> 49 #include <lifev/core/array/MapEpetra.hpp> 50 #include <lifev/core/mesh/MeshData.hpp> 51 #include <lifev/core/mesh/MeshPartitioner.hpp> 52 #include <lifev/core/algorithm/SolverAztecOO.hpp> 53 #include <lifev/core/algorithm/LinearSolver.hpp> 54 #include <lifev/core/fem/Assembly.hpp> 55 #include <lifev/core/fem/AssemblyElemental.hpp> 56 #include <lifev/core/fem/BCHandler.hpp> 57 #include <lifev/core/fem/BCManage.hpp> 58 #include <lifev/core/fem/FESpace.hpp> 59 #include <lifev/core/fem/TimeAdvanceBDFVariableStep.hpp> 61 #include <lifev/core/algorithm/PreconditionerIfpack.hpp> 62 #include <lifev/core/algorithm/PreconditionerML.hpp> 64 #include <lifev/core/filter/Exporter.hpp> 65 #include <lifev/core/filter/ExporterEmpty.hpp> 66 #include <lifev/core/filter/ExporterEnsight.hpp> 67 #include <lifev/core/filter/ExporterHDF5.hpp> 69 #include <Teuchos_ParameterList.hpp> 70 #include <Teuchos_XMLParameterListHelpers.hpp> 71 #include <Teuchos_RCP.hpp> 79 using namespace LifeV;
113 test_bdf::test_bdf (
int argc,
char** argv) :
114 Members (
new Private)
117 const std::string data_file_name =
118 command_line.follow (
"data", 2,
"-f",
"--file");
119 GetPot dataFile (data_file_name);
121 Members->data_file_name = data_file_name;
124 std::cout <<
"Epetra Initialization" << std::endl;
125 Members->comm.reset (
new Epetra_MpiComm (MPI_COMM_WORLD) );
127 Members->comm.reset (
new Epetra_SerialComm() );
137 typedef VectorEpetra vector_Type;
138 typedef std::shared_ptr<vector_Type> vectorPtr_Type;
140 typedef LifeV::Preconditioner basePrec_Type;
141 typedef std::shared_ptr<basePrec_Type> basePrecPtr_Type;
142 typedef LifeV::PreconditionerIfpack prec_Type;
143 typedef std::shared_ptr<prec_Type> precPtr_Type;
146 GetPot dataFile (Members->data_file_name.c_str() );
148 bool verbose = (Members->comm->MyPID() == 0);
152 std::cout <<
"The BDF Solver" << std::flush;
158 BCFunctionBase g_Ess (AnalyticalSol::u);
162 bc.addBC (
"Top", TOP, Essential, Full, g_Ess, 1);
163 bc.addBC (
"Bottom", BOTTOM, Essential, Full, g_Ess, 1);
164 bc.addBC (
"Left", LEFT, Essential, Full, g_Ess, 1);
165 bc.addBC (
"Right", RIGHT, Essential, Full, g_Ess, 1);
166 bc.addBC (
"Front", FRONT, Essential, Full, g_Ess, 1);
167 bc.addBC (
"Back", BACK, Essential, Full, g_Ess, 1);
171 Members->comm->Barrier();
172 MeshData meshData (dataFile, (
"bdf/" + discretization_section).c_str() );
173 std::shared_ptr<regionMesh> fullMeshPtr (
new regionMesh ( Members->comm ) );
174 readMesh (*fullMeshPtr, meshData);
175 std::shared_ptr<regionMesh> meshPtr;
178 meshPtr = meshPart.meshPartition();
183 std::shared_ptr<FESpace<regionMesh, MapEpetra> > feSpacePtr (
184 new FESpace<regionMesh, MapEpetra> (
185 meshPtr, dataFile ( (
"bdf/" + discretization_section +
"/order").c_str(),
"P2"), 1, Members->comm) );
188 std::cout <<
" Number of unknowns : " 189 << feSpacePtr->map().map (Unique)->NumGlobalElements()
192 bc.bcUpdate (* (feSpacePtr->mesh() ), feSpacePtr->feBd(), feSpacePtr->dof() );
196 MatrixElemental elmat (feSpacePtr->fe().nbFEDof(), 1, 1);
197 MatrixEpetra<
double> matM (feSpacePtr->map() );
198 std::shared_ptr<MatrixEpetra<
double> > matA_ptr (
199 new MatrixEpetra<
double> (feSpacePtr->map() ) );
200 vectorPtr_Type u (
new vector_Type (feSpacePtr->map(), Unique) );
201 vectorPtr_Type f (
new vector_Type (feSpacePtr->map(), Unique) );
205 Members->comm->Barrier();
207 for (UInt iVol = 0; iVol < feSpacePtr->mesh()->numElements(); iVol++)
209 feSpacePtr->fe().updateJac (feSpacePtr->mesh()->element (iVol) );
211 AssemblyElemental::mass (1., elmat, feSpacePtr->fe(), 0, 0);
212 assembleMatrix (matM, elmat, feSpacePtr->fe(), feSpacePtr->fe(), feSpacePtr->dof(),
213 feSpacePtr->dof(), 0, 0, 0, 0);
215 matM.globalAssemble();
216 Members->comm->Barrier();
219 std::cout <<
"\n \n -- Mass matrix assembling time = " << chrono.diff() << std::endl
225 Real Tfin = dataFile
("bdf/endtime", 10.0
);
226 Real delta_t = dataFile
("bdf/timestep", 0.5
);
228 UInt ord_bdf = dataFile
("bdf/order", 3
);
233 bdf.setInitialCondition<Real (*) (Real, Real, Real, Real, UInt), FESpace<regionMesh, MapEpetra> > (AnalyticalSol::u, *u, *feSpacePtr, t0, delta_t);
239 Members->comm->Barrier();
243 std::shared_ptr<Exporter<regionMesh> > exporter;
244 std::string
const exporterType = dataFile (
"exporter/type",
"hdf5");
247 if (exporterType.compare (
"hdf5") == 0)
249 exporter.reset (
new ExporterHDF5<regionMesh > ( dataFile,
"bdf_test" ) );
254 if (exporterType.compare (
"none") == 0)
256 exporter.reset (
new ExporterEmpty<regionMesh > ( dataFile, meshPtr,
"bdf_test", Members->comm->MyPID() ) );
260 exporter.reset (
new ExporterEnsight<regionMesh > ( dataFile, meshPtr,
"bdf_test", Members->comm->MyPID() ) );
264 exporter->setPostDir (
"./" );
265 exporter->setMeshProcId ( meshPtr, Members->comm->MyPID() );
267 std::shared_ptr<VectorEpetra> u_display_ptr (
new VectorEpetra (
268 feSpacePtr->map(), exporter->mapType() ) );
269 exporter->addVariable (ExporterData<regionMesh >::ScalarField,
"u", feSpacePtr,
270 u_display_ptr, UInt (0) );
272 exporter->postProcess (0);
277 LinearSolver linearSolver;
279 Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp (
new Teuchos::ParameterList );
280 belosList = Teuchos::getParametersFromXmlFile (
"SolverParamList.xml" );
282 linearSolver.setCommunicator ( Members->comm );
283 linearSolver.setParameters ( *belosList );
285 prec_Type* precRawPtr;
286 basePrecPtr_Type precPtr;
287 precRawPtr =
new prec_Type;
288 precRawPtr->setDataFromGetPot ( dataFile,
"bdf/prec" );
289 precPtr.reset ( precRawPtr );
290 linearSolver.setPreconditioner ( precPtr );
296 matA_ptr.reset (
new MatrixEpetra<
double> (feSpacePtr->map() ) );
298 for (Real t = t0 + delta_t; t <= Tfin; t += delta_t)
300 Members->comm->Barrier();
303 std::cout <<
"Now we are at time " << t << std::endl;
308 Real coeff = bdf.coefficientDerivative (0) / delta_t;
311 for (UInt i = 0; i < feSpacePtr->mesh()->numElements(); i++)
313 feSpacePtr->fe().updateFirstDerivQuadPt (feSpacePtr->mesh()->element (i) );
315 AssemblyElemental::mass (coeff + s, elmat, feSpacePtr->fe() );
316 AssemblyElemental::stiff (visc, elmat, feSpacePtr->fe() );
317 assembleMatrix (*matA_ptr, elmat, feSpacePtr->fe(), feSpacePtr->fe(),
318 feSpacePtr->dof(), feSpacePtr->dof(), 0, 0, 0, 0);
323 std::cout <<
"A has been constructed in " << chrono.diff() <<
"s." << std::endl;
328 *f = (matM * bdf.rhsContribution() );
329 feSpacePtr->l2ScalarProduct (sf, *f, t);
330 Members->comm->Barrier();
335 std::cout <<
"*** BC Management: " << std::endl;
339 bcManage (*matA_ptr, *f, *feSpacePtr->mesh(), feSpacePtr->dof(), bc, feSpacePtr->feBd(), tgv, t);
340 matA_ptr->globalAssemble();
344 std::cout << chrono.diff() <<
"s." << std::endl;
348 Members->comm->Barrier();
350 linearSolver.setOperator ( matA_ptr );
351 linearSolver.setReusePreconditioner (
false);
352 linearSolver.setRightHandSide ( f );
354 Members->comm->Barrier();
356 linearSolver.solve ( u );
363 std::cout <<
"*** Solution computed in " << chrono.diff() <<
"s." 366 Members->comm->Barrier();
369 vector_Type uComputed (*u, Repeated);
371 Real L2_Error, L2_RelError;
373 L2_Error = feSpacePtr->l2Error (AnalyticalSol::u, uComputed, t, &L2_RelError);
376 std::cout <<
"Error Norm L2: " << L2_Error
377 <<
"\nRelative Error Norm L2: " << L2_RelError << std::endl;
379 Members->errorNorm = L2_Error;
386 exporter->postProcess (t);
393 bool test_bdf::check()
396 GetPot dataFile (Members->data_file_name.c_str() );
397 return Members->errorNorm < dataFile (
"errorNorms/l2Error", -10e10);
double operator()(const char *VarName, const double &Default) const
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
std::shared_ptr< Epetra_Comm > comm
const std::string discretization_section
TimeAdvanceBDFVariableStep - Backward differencing formula time discretization with non-uniform time ...
std::shared_ptr< std::vector< Int > > M_isOnProc
MeshData - class for handling spatial discretization.
RegionMesh< LinearTetra > regionMesh
double Real
Generic real data.
std::string data_file_name
int operator()(const char *VarName, int Default) const
std::function< Real(Real const &, Real const &, Real const &, Real const &, ID const &) > fct_type
uint32_type UInt
generic unsigned integer (used mainly for addressing)