39 #ifndef TESTIMPORTEXPORT_HPP_ 40 #define TESTIMPORTEXPORT_HPP_ 1
43 #include <lifev/core/LifeV.hpp> 44 #include <lifev/core/util/Displayer.hpp> 45 #include <lifev/core/util/LifeChrono.hpp> 46 #include <lifev/core/fem/TimeData.hpp> 47 #include <lifev/core/filter/Exporter.hpp> 48 #include <lifev/core/mesh/MeshData.hpp> 49 #include <lifev/core/mesh/MeshPartitioner.hpp> 50 #include <lifev/navier_stokes/function/Womersley.hpp> 51 #include <lifev/navier_stokes/function/RossEthierSteinmanDec.hpp> 55 #include <Epetra_ConfigDefs.h> 57 #include "Epetra_MpiComm.h" 59 #include "Epetra_SerialComm.h" 82 template<
typename ImporterType,
typename ExporterType>
83 bool run (
GetPot& commandLine,
const std::string& testString =
"import" );
85 template<
typename ImporterType>
86 bool importLoop (
const std::shared_ptr< ImporterType >& importerPtr );
88 template<
typename ExporterType>
89 bool exportLoop (
const std::shared_ptr< ExporterType >& exporterPtr );
95 template<
typename ExporterType>
96 void buildExporter ( std::shared_ptr< ExporterType >& exporterPtr,
97 const std::string& prefix )
const;
128 using namespace LifeV;
135 M_displayer.leaderPrint (
"[Loading the data]\n" );
138 const std::string problemName = commandLine
.follow ("", 2
, "-p", "--problem");
139 const std::string defaultDataFileName (
"data" + problemName);
140 const std::string dataFileName = commandLine.follow (defaultDataFileName.c_str(), 2,
"-f",
"--file");
141 M_dataFile = GetPot (dataFileName);
143 UInt numVectors = M_dataFile (
"importer/numVectors", 0);
144 UInt numScalars = M_dataFile (
"importer/numScalars", 0);
146 M_vectorInterpolantPtr.resize (numVectors);
147 M_scalarInterpolantPtr.resize (numScalars);
149 M_vectorImportedPtr.resize (numVectors);
150 M_scalarImportedPtr.resize (numScalars);
152 M_vectorName.resize (numVectors);
153 M_scalarName.resize (numScalars);;
155 for (
UInt iVec = 0; iVec < numVectors; ++iVec )
157 std::stringstream ss;
159 ss <<
"importer/vector" << iVec <<
"Name";
160 M_vectorName[iVec] = M_dataFile (ss.str().c_str(),
"");
162 for (
UInt iScal = 0; iScal < numScalars; ++iScal )
164 std::stringstream ss;
166 ss <<
"importer/scalar" << iScal <<
"Name";
167 M_scalarName[iScal] = M_dataFile (ss.str().c_str(),
"");
170 problem_Type::setParamsFromGetPot (M_dataFile);
173 M_displayer.leaderPrint (
"[...done in ", chrono.diff(),
"s]\n" );
180 using namespace LifeV;
187 M_displayer.leaderPrint (
"[Building the mesh]\n" );
189 std::shared_ptr< mesh_Type > fullMeshPtr (
new mesh_Type ( M_commPtr ) );
191 if ( M_dataFile (
"space_discretization/mesh_from_file",
false) )
195 meshData.setup (M_dataFile,
"space_discretization");
197 readMesh (*fullMeshPtr, meshData);
201 UInt nEl (M_dataFile (
"space_discretization/dimension", 1) );
202 regularMesh3D (*fullMeshPtr, 0, nEl, nEl, nEl);
205 MeshPartitioner<
mesh_Type> meshPart ( fullMeshPtr, M_commPtr );
207 M_meshPtr = meshPart.meshPartition();
209 meshPart.releaseUnpartitionedMesh();
213 M_displayer.leaderPrint (
"[...done in ", chrono.diff(),
"s]\n" );
220 using namespace LifeV;
227 M_displayer.leaderPrint (
"[Creating the FE spaces...]\n" );
230 const std::string vectorFE = M_dataFile (
"space_discretization/vector_fespace",
"P2");
231 M_displayer.leaderPrint (
"\t-o FE for the vector: ", vectorFE,
"\n" );
233 M_displayer.leaderPrint (
"\t-o Building the vector FE space...\n" );
235 M_vectorFESpacePtr.reset (
new feSpace_Type ( M_meshPtr, vectorFE, nDimensions, M_commPtr ) );
237 M_displayer.leaderPrint (
"\t\t...ok.\n" );
239 const std::string scalarFE = M_dataFile (
"space_discretization/scalar_fespace",
"P1");
240 M_displayer.leaderPrint (
"\t-o FE for the scalar: ", scalarFE,
"\n" );
242 M_displayer.leaderPrint (
"\t-o Building the scalar FE space...\n" );
244 M_scalarFESpacePtr.reset (
new feSpace_Type ( M_meshPtr, scalarFE, 1, M_commPtr ) );
246 M_displayer.leaderPrint (
"\t\t...ok.\n" );
249 UInt vectorTotalDof = M_vectorFESpacePtr->map().map (Unique)->NumGlobalElements();
250 UInt scalarTotalDof = M_scalarFESpacePtr->map().map (Unique)->NumGlobalElements();
252 M_displayer.leaderPrint (
"\t-o Total Dof for the vector: ", vectorTotalDof,
"\n" );
253 M_displayer.leaderPrint (
"\t-o Total Dof for the scalar: ", scalarTotalDof,
"\n" );
256 M_displayer.leaderPrint (
"[...done in ", chrono.diff(),
"s]\n" );
261 template<
typename ExporterType>
263 TestImportExport::buildExporter ( std::shared_ptr< ExporterType >& exporterPtr,
264 const std::string& prefix )
const 266 using namespace LifeV;
273 M_displayer.leaderPrint (
"[Creating the exporter...]\n" );
276 exporterPtr.reset (
new ExporterType ( M_dataFile, prefix ) );
279 exporterPtr->setMeshProcId ( M_meshPtr, M_commPtr->MyPID() );
281 M_displayer.leaderPrint (
"[...done in ", chrono.diff(),
"s]\n" );
286 template<
typename ImporterType,
typename ExporterType>
290 using namespace LifeV;
292 bool passed (
true );
298 std::shared_ptr< ExporterType > exporterPtr;
299 std::shared_ptr< ImporterType > importerPtr;
301 buildExporter ( importerPtr, M_dataFile (
"importer/prefix",
"testImporter" ) );
302 buildExporter ( exporterPtr, M_dataFile (
"exporter/prefix",
"testExporter" ) );
304 importerPtr->setDataFromGetPot (M_dataFile,
"importer");
305 exporterPtr->setDataFromGetPot (M_dataFile,
"exporter");
313 M_displayer.leaderPrint (
"[Entering the time loop]\n" );
316 M_timeData.setup ( M_dataFile,
"time_discretization" );
318 M_timeData.updateTime();
319 M_displayer.leaderPrint (
"\t[t = ", M_timeData.time(),
" s.]\n" );
323 if ( testString.compare (
"export" ) == 0 )
325 passed = passed && exportLoop (exporterPtr);
328 MPI_Barrier (MPI_COMM_WORLD);
329 M_displayer.leaderPrint (
"Exporting finished. Now importing\n" );
332 passed = passed && importLoop (importerPtr);
335 M_displayer.leaderPrint (
"[Time loop, elapsed time: ", globalChrono.diff(),
" s.]\n" );
341 template<
typename ExporterType>
345 using namespace LifeV;
349 ASSERT ( M_vectorInterpolantPtr.size() + M_scalarInterpolantPtr.size(),
"There's no data on which to work!" )
351 const UInt vectorInterpolantPtrSize = M_vectorInterpolantPtr.size();
352 const UInt scalarInterpolantPtrSize = M_scalarInterpolantPtr.size();
355 for (
UInt iVec (0); iVec < vectorInterpolantPtrSize; ++iVec )
357 M_vectorInterpolantPtr[iVec].reset (
358 new Exporter<mesh_Type >::vector_Type ( M_vectorFESpacePtr->map(), ExporterType::MapType ) );
359 exporterPtr->addVariable ( ExporterData<mesh_Type>::VectorField, M_vectorName[iVec],
360 M_vectorFESpacePtr, M_vectorInterpolantPtr[iVec], UInt (0) );
362 for (
UInt iScal (0); iScal < scalarInterpolantPtrSize; ++iScal )
364 M_scalarInterpolantPtr[iScal].reset (
365 new Exporter<mesh_Type >::vector_Type ( M_scalarFESpacePtr->map(), ExporterType::MapType ) );
366 exporterPtr->addVariable ( ExporterData<mesh_Type>::ScalarField, M_scalarName[iScal],
367 M_scalarFESpacePtr, M_scalarInterpolantPtr[iScal], UInt (0) );
372 for ( ; M_timeData.canAdvance(); M_timeData.updateTime() )
375 M_displayer.leaderPrint (
"[t = ", M_timeData.time(),
" s.]\n" );
378 if ( vectorInterpolantPtrSize )
380 M_vectorFESpacePtr->interpolate (
static_cast<function_Type> ( problem_Type::uexact ), *M_vectorInterpolantPtr[0], M_timeData.time() );
382 if ( scalarInterpolantPtrSize )
384 M_scalarFESpacePtr->interpolate (
static_cast<function_Type> ( problem_Type::pexact ), *M_scalarInterpolantPtr[0], M_timeData.time() );
388 exporterPtr->postProcess ( M_timeData.time() );
392 exporterPtr->closeFile();
399 template<
typename ImporterType>
403 using namespace LifeV;
407 ASSERT ( M_vectorImportedPtr.size() + M_scalarImportedPtr.size(),
"There's no data on which to work!" )
410 ExporterData<mesh_Type>::WhereEnum whereVector =
411 ( M_vectorFESpacePtr->fe().refFE().type() == FE_P0_3D )
413 ExporterData<mesh_Type>::Cell : ExporterData<mesh_Type>::Node;
415 ExporterData<mesh_Type>::WhereEnum whereScalar =
416 ( M_scalarFESpacePtr->fe().refFE().type() == FE_P0_3D )
418 ExporterData<mesh_Type>::Cell : ExporterData<mesh_Type>::Node;
420 for ( UInt iVec (0); iVec < M_vectorImportedPtr.size(); ++iVec )
422 M_vectorImportedPtr[iVec].reset (
423 new Exporter<mesh_Type >::vector_Type ( M_vectorFESpacePtr->map(), ImporterType::MapType ) );
425 importerPtr->addVariable ( ExporterData<mesh_Type>::VectorField, M_vectorName[iVec],
426 M_vectorFESpacePtr, M_vectorImportedPtr[iVec], UInt (0),
427 ExporterData<mesh_Type>::UnsteadyRegime,
430 for ( UInt iScal (0); iScal < M_scalarImportedPtr.size(); ++iScal )
432 M_scalarImportedPtr[iScal].reset (
433 new Exporter<mesh_Type >::vector_Type ( M_scalarFESpacePtr->map(), ImporterType::MapType ) );
434 importerPtr->addVariable ( ExporterData<mesh_Type>::ScalarField, M_scalarName[iScal],
435 M_scalarFESpacePtr, M_scalarImportedPtr[iScal], UInt (0),
436 ExporterData<mesh_Type>::UnsteadyRegime,
440 const UInt vectorImportedPtrSize = M_vectorImportedPtr.size();
441 const UInt scalarImportedPtrSize = M_scalarImportedPtr.size();
443 Exporter<mesh_Type >::vector_Type vectorDiff ( M_vectorFESpacePtr->map(), ImporterType::MapType );
444 Exporter<mesh_Type >::vector_Type scalarDiff ( M_scalarFESpacePtr->map(), ImporterType::MapType );
447 for (
UInt iVec (0); iVec < vectorImportedPtrSize; ++iVec )
449 M_vectorInterpolantPtr[iVec].reset (
450 new Exporter<mesh_Type >::vector_Type ( M_vectorFESpacePtr->map(), ImporterType::MapType ) );
452 for (
UInt iScal (0); iScal < scalarImportedPtrSize; ++iScal )
454 M_scalarInterpolantPtr[iScal].reset (
455 new Exporter<mesh_Type >::vector_Type ( M_scalarFESpacePtr->map(), ImporterType::MapType ) );
458 M_timeData.setup ( M_dataFile,
"time_discretization" );
459 M_timeData.updateTime();
461 for ( ; M_timeData.canAdvance(); M_timeData.updateTime() )
464 if ( vectorImportedPtrSize )
466 M_vectorFESpacePtr->interpolate (
static_cast<function_Type> ( problem_Type::uexact ), *M_vectorInterpolantPtr[0], M_timeData.time() );
468 if ( scalarImportedPtrSize )
470 M_scalarFESpacePtr->interpolate (
static_cast<function_Type> ( problem_Type::pexact ), *M_scalarInterpolantPtr[0], M_timeData.time() );
474 importerPtr->import ( M_timeData.time() );
477 if ( vectorImportedPtrSize )
479 vectorDiff = *M_vectorInterpolantPtr[0];
480 vectorDiff += (-*M_vectorImportedPtr[0]);
481 maxDiff = vectorDiff.normInf();
486 M_displayer.leaderPrint (
"[vectorDiff.normInf() = ", vectorDiff.normInf(),
"]\n" );
488 if ( scalarImportedPtrSize )
490 scalarDiff = *M_scalarInterpolantPtr[0];
491 scalarDiff += (-*M_scalarImportedPtr[0]);
492 maxDiff = std::max (scalarDiff.normInf(), maxDiff);
497 M_displayer.leaderPrint (
"[scalarDiff.normInf() = ", scalarDiff.normInf(),
"]\n" );
499 passed = passed && (maxDiff < 1.e-4);
LifeV::FESpace< mesh_Type, LifeV::MapEpetra > feSpace_Type
void start()
Start the timer.
std::vector< vectorPtr_Type > M_scalarInterpolantPtr
LifeV::RegionMesh< LifeV::LinearTetra > mesh_Type
void loadData(GetPot &commandLine)
std::shared_ptr< Epetra_Comm > commPtr_Type
std::vector< vectorPtr_Type > M_vectorImportedPtr
std::vector< vectorPtr_Type > M_scalarImportedPtr
std::shared_ptr< mesh_Type > M_meshPtr
bool run(GetPot &commandLine, const std::string &testString="import")
LifeV::Exporter< mesh_Type >::vectorPtr_Type vectorPtr_Type
bool importLoop(const std::shared_ptr< ImporterType > &importerPtr)
feSpacePtr_Type M_vectorFESpacePtr
MeshData - class for handling spatial discretization.
LifeV::Displayer M_displayer
void buildExporter(std::shared_ptr< ExporterType > &exporterPtr, const std::string &prefix) const
std::vector< vectorPtr_Type > M_vectorInterpolantPtr
std::shared_ptr< feSpace_Type > feSpacePtr_Type
std::vector< std::string > M_scalarName
LifeV::RossEthierSteinmanUnsteadyDec problem_Type
void stop()
Stop the timer.
TestImportExport(const commPtr_Type &commPtr)
const std::string follow(const char *Default, unsigned No, const char *Option,...)
std::vector< std::string > M_vectorName
bool exportLoop(const std::shared_ptr< ExporterType > &exporterPtr)
std::function< LifeV::Real(LifeV::Real const &, LifeV::Real const &, LifeV::Real const &, LifeV::Real const &, LifeV::UInt const &) > function_Type
feSpacePtr_Type M_scalarFESpacePtr
uint32_type UInt
generic unsigned integer (used mainly for addressing)
LifeV::TimeData M_timeData