40 #ifndef EXPORTER_ENSIGHT_H 41 #define EXPORTER_ENSIGHT_H 43 #include <lifev/core/filter/Exporter.hpp> 54 template<
typename MeshType>
117 ERROR_MSG (
"ExporterEnsight::importFromTime has not yet been implemented.");
140 super::readVariable (dvar);
153 if ( !comm->MyPID() )
155 std::cerr <<
" X- exportPID is not working with Ensight" << std::endl;
241 std::vector<Real>& globalDOF );
268 M_ltGNodesMap = ltGNodesMap;
306 template<
typename MeshType>
313 template<
typename MeshType>
323 template<
typename MeshType>
327 super (dfile, prefix),
333 this->setDataFromGetPot (dfile,
"exporter");
334 this->setMeshProcId (mesh, procId);
337 template<
typename MeshType>
339 super (dfile, prefix),
345 this->setDataFromGetPot (dfile,
"exporter");
352 template<
typename MeshType>
358 if (!
this->M_multimesh)
364 this->M_me +
".scl" );
369 this->computePostfix();
372 std::size_t found (
this->M_postfix.find (
"*" ) );
373 if ( found == std::string::npos )
377 std::cout <<
" X- ExporterEnsight post-processing ... " << std::flush;
381 for (
typename super::dataVectorIterator_Type i =
this->M_dataVector.begin();
382 i !=
this->M_dataVector.end(); ++i)
399 if (
this->M_multimesh)
401 writeAsciiGeometry ( this->M_postDir +
this->M_prefix +
this->M_postfix +
this->M_me +
".geo" );
406 std::cout <<
" done in " << chrono.diff() <<
" s." << std::endl;
412 template<
typename MeshType>
416 Real time (startTime -
this->M_timeIndex * dt);
418 for (
UInt count (0); count <
this->M_timeIndex; ++count)
420 this->M_timeSteps.push_back (time);
431 template<
typename MeshType>
434 this->M_timeSteps.push_back (time);
439 this->computePostfix();
441 assert (
this->M_postfix.find (
"*" ) == std::string::npos );
445 std::cout <<
" X- ExporterEnsight importing ..." << std::endl;
450 for (
typename super::dataVectorIterator_Type i =
this->M_dataVector.begin(); i !=
this->M_dataVector.end(); ++i)
452 this->readVariable (*i);
457 std::cout <<
" done in " << chrono.diff() <<
" s." << std::endl;
462 template<
typename MeshType>
465 super::setMeshProcId ( mesh, procId );
470 typedef typename MeshType::elementShape_Type elementShape_Type;
472 switch ( elementShape_Type::S_shape )
499 ERROR_MSG (
"FE not allowed in ExporterEnsight writer" );
513 template <
typename MeshType>
516 std::string filename (
this->M_postDir +
this->M_prefix +
this->M_me +
".case" );
517 std::ofstream casef ( filename.c_str() );
518 ASSERT (casef.is_open(),
"There is an error while opening " + filename );
519 ASSERT (casef.good(),
"There is an error while writing to " + filename );
520 casef <<
"FORMAT\ntype: ensight\n";
527 template <
typename MeshType>
532 std::ofstream geoFile (gFile.c_str() );
533 ASSERT (geoFile.is_open(),
"There is an error while opening " + gFile );
534 ID vertexNumber =
this->M_mesh->numVertices();
535 ID elementNumber =
this->M_mesh->numElements();
537 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
538 geoFile <<
"Geometry file\nGenerated by LifeV\nnode id given\nelement id given\ncoordinates\n";
539 geoFile.setf (std::ios::right | std::ios_base::scientific);
540 geoFile.precision (5);
541 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
542 geoFile << setw (8) << vertexNumber <<
"\n";
543 for (
ID i = 0; i < vertexNumber; ++i)
545 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
549 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
550 geoFile << setw (12) <<
static_cast<
float> (
this->M_mesh->pointList (i).coordinatesArray() [icoor]);
552 ASSERT (geoFile.good(),
"There is an error while opening " + gFile );
556 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
558 geoFile <<
"part" << setw (8) << part <<
"\nfull geometry\n" 560 << M_FEstr <<
"\n" << setw (8) << elementNumber <<
"\n";
561 for (
ID i = 0; i < elementNumber; ++i)
563 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
567 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
568 geoFile << setw (8) <<
this->M_mesh->element (i).point (j).localId() +
ensightOffset;
570 ASSERT (geoFile.good(),
"There is an error while writing to " + gFile );
577 template <
typename MeshType>
581 switch ( dvar.fieldType() )
596 template <
typename MeshType>
601 std::ofstream exportFile;
602 std::string filename;
605 filename =
this->M_postDir +
super::M_prefix +
"_" + dvar.variableName() +
608 filename =
this->M_postDir +
super::M_prefix +
"_" + dvar.variableName() +
609 this->M_postfix +
this->M_me + suffix;
611 exportFile.open ( filename.c_str() );
613 ASSERT (exportFile.is_open(),
"There is an error while opening " + filename );
617 const UInt size = dvar.numDOF();
618 const UInt start = dvar.start();
619 const UInt vertexNumber =
static_cast<
UInt> (
this->M_ltGNodesMap.size() );
621 ASSERT (exportFile.good(),
"There is an error while writing to " + filename );
622 if ( suffix.compare (
".vct") == 0 )
624 exportFile <<
"Vector per node\n";
626 else if ( suffix.compare (
".scl") == 0 )
628 exportFile <<
"Scalar per node\n";
631 exportFile.setf (std::ios::right | std::ios_base::scientific);
632 exportFile.precision (5);
634 for (
UInt i = 0; i < vertexNumber; ++i)
635 for (
UInt j = 0; j < dvar.fieldDim(); ++j)
637 const Int id =
this->M_ltGNodesMap[i];
638 ASSERT (exportFile.good(),
"There is an error while writing to " + filename );
639 exportFile << setw (12) <<
static_cast<
float> (dvar (start + j * size + id) ) ;
643 ASSERT (exportFile.good(),
"There is an error while writing to " + filename );
648 ASSERT (exportFile.good(),
"There is an error while writing to " + filename );
649 exportFile << std::endl;
654 template <
typename MeshType>
659 std::ofstream globalIDsFile;
661 globalIDsFile.open ( filename.c_str() );
662 ASSERT (globalIDsFile.is_open(),
"There is an error while opening " + filename );
666 const UInt vertexNumber =
static_cast<
UInt> (
this->M_ltGNodesMap.size() );
667 ASSERT (globalIDsFile.good(),
"There is an error while writing to " + filename );
668 globalIDsFile <<
"Node global ID " << vertexNumber <<
"\n";
670 for (
UInt i = 0; i < vertexNumber; ++i)
672 const Int id =
this->M_ltGNodesMap[i];
673 ASSERT (globalIDsFile.good(),
"There is an error while writing to " + filename );
674 globalIDsFile << setw (12) << id ;
678 ASSERT (globalIDsFile.good(),
"There is an error while writing to " + filename );
679 globalIDsFile <<
"\n";
683 ASSERT (globalIDsFile.good(),
"There is an error while writing to " + filename );
684 globalIDsFile << std::endl;
685 globalIDsFile.close();
688 template <
typename MeshType>
691 ASSERT (casef.good(),
"There is an error while writing to file" );
692 casef <<
"GEOMETRY\n";
693 if (
this->M_multimesh )
695 std::string stars (
".");
696 for (
UInt cc (0); cc <
this->M_timeIndexWidth; ++cc)
701 ASSERT (casef.good(),
"There is an error while writing to file" );
702 casef <<
"model: 1 " +
this->M_prefix + stars <<
this->M_me <<
".geo change_coords_only\n";
706 ASSERT (casef.good(),
"There is an error while writing to file" );
707 casef <<
"model: 1 " +
this->M_prefix +
this->M_me +
".geo\n";
711 template <
typename MeshType>
714 ASSERT (casef.good(),
"There is an error while writing to file" );
715 casef <<
"VARIABLE\n";
716 std::string aux, str;
717 for (
typename super::dataVectorIterator_Type i =
this->M_dataVector.begin(); i !=
this->M_dataVector.end(); ++i)
725 std::string stars (
".");
726 for (
UInt cc (0); cc <
this->M_timeIndexWidth; ++cc)
733 aux = i->variableName() +
" " +
super::M_prefix +
"_" + i->variableName();
734 switch ( i->fieldType() )
737 ASSERT (casef.good(),
"There is an error while writing to file" );
738 casef <<
"scalar per node: 1 " + aux + str <<
this->M_me <<
".scl\n";
741 ASSERT (casef.good(),
"There is an error while writing to file" );
742 casef <<
"vector per node: 1 " + aux + str <<
this->M_me <<
".vct\n";
748 template <
typename MeshType>
751 ASSERT (casef.good(),
"There is an error while writing to file" );
752 this->M_timeSteps.push_back (time);
754 casef <<
"TIME\ntime set: 1\nnumber of steps: " <<
this->M_steps <<
"\n" 755 <<
"filename start number: " <<
this->M_timeIndexStart <<
"\n" 756 <<
"filename increment: 1\ntime values:\n";
760 typedef std::list<Real>::const_iterator Iterator;
761 for (Iterator i =
this->M_timeSteps.begin(); i !=
this->M_timeSteps.end(); ++i)
763 ASSERT (casef.good(),
"There is an error while writing to file" );
768 ASSERT (casef.good(),
"There is an error while writing to file" );
775 template <
typename MeshType>
779 switch ( dvar.fieldType() )
795 const std::string& suffix)
797 ASSERT (
this->M_numImportProc,
"The number of pieces to be loaded was not specified." );
800 std::vector<Real> globalDOF;
803 for (
UInt iProc = 0; iProc <
this->M_numImportProc; ++iProc )
806 std::ostringstream index;
808 index << std::setw (1) <<
"." ;
809 index << std::setw (3) << iProc;
812 readGlobalIDs (
this->M_postDir + super::M_prefix +
"_globalIDs" + index.str() +
".scl", globalDOF );
815 const std::string filename (
this->M_postDir + super::M_prefix +
"_" + dvar.variableName() +
816 this->M_postfix + index.str() + suffix );
817 std::ifstream importFile ( filename.c_str() );
822 std::cout <<
"\tfile " << filename << std::endl;
825 ASSERT (importFile.is_open(),
"There is an error while reading " + filename );
828 ASSERT (importFile.good(),
"There is an error while reading from " + filename );
829 getline ( importFile, line );
832 const UInt size = dvar.numDOF();
833 const UInt start = dvar.start();
836 for (UInt i = 0; i < globalDOF.size(); ++i)
839 const Int id = globalDOF[i];
841 for (UInt j = 0; j < dvar.fieldDim(); ++j)
846 ASSERT (importFile.good(),
"There is an error while reading from " + filename );
850 if ( dvar.feSpacePtr()->map().map (Repeated)->MyGID ( id ) )
852 dvar (start + j * size + id) = value;
857 ASSERT (!importFile.fail(),
"There is an error while reading " + filename );
862 template<
typename MeshType>
865 std::ostringstream index;
867 if (
this->M_procId >= 0)
869 index << std::setw (1) <<
"." ;
870 index << std::setw (3) <<
this->M_procId;
875 template<
typename MeshType>
878 UInt vertexNumber =
this->M_mesh->numVertices();
879 M_ltGNodesMap.resize (vertexNumber);
880 for (
UInt i = 0; i < vertexNumber; ++i)
882 M_ltGNodesMap[i] =
this->M_mesh->pointList ( i ).id();
886 template<
typename MeshType>
888 std::vector<Real>& globalDOF )
890 std::ifstream globalIDsFile ( filename.c_str() );
894 std::cout <<
"\tfile " << filename << std::endl;
897 ASSERT (globalIDsFile.is_open(),
"There is an error while opening " + filename );
900 globalDOF.resize (0);
904 std::stringstream parseLine;
906 ASSERT (globalIDsFile.good(),
"There is an error while reading " + filename );
907 getline ( globalIDsFile, line );
908 parseLine.str (line);
909 std::string trashcan;
910 parseLine >> trashcan >> trashcan >> trashcan >> vertexNumber;
912 for (
UInt iNode = 0; iNode < vertexNumber; ++iNode )
915 ASSERT (globalIDsFile.good(),
"There is an error while reading " + filename );
916 globalIDsFile >> gID;
917 globalDOF.push_back ( gID );
920 ASSERT (!globalIDsFile.fail(),
"There is an error while reading " + filename );
921 globalIDsFile.close();
UInt importFromTime(const Real &)
Import data from previous simulations at a certain time.
super::exporterData_Type exporterData_Type
void postProcess(const Real &time)
Post-process the variables added to the list.
bool M_firstTimeStep
are we performing the first post-processing operation?
void import(const Real &importTime, const Real &dt)
Import data from previous simulations and rebuild the internal time counters.
std::vector< Int > M_ltGNodesMap
the local-to-global map: ltGNodesMap[i] is the global ID of the i-th DOF owned by the current process...
void start()
Start the timer.
ExporterEnsight data exporter.
ExporterEnsight()
Default constructor.
ExporterEnsight(const GetPot &dfile, const std::string &prefix)
Constructor for ExporterEnsight.
void readVector(exporterData_Type &dvar)
The generic reader (specialization of the parent class method)
void writeAsciiGeometry(const std::string geoFile)
Compose the .geo file.
void setNodesMap(std::vector< Int > ltGNodesMap)
Set the local-to-global map of DOFs.
int32_type Int
Generic integer data.
void writeAsciiValues(const exporterData_Type &dvar, const std::string &suffix)
The ASCII writer.
void exportPID(meshPtr_Type, commPtr_Type comm, const bool=false)
temporary: the method should work form the Exporter class
super::vectorPtr_Type vectorPtr_Type
UInt M_steps
the counter of the number of steps processed
void setMeshProcId(const meshPtr_Type mesh, const Int &procId)
Set the mesh and the processor id.
MapEpetraType mapType() const
returns the type of the map to use for the VectorEpetra
void readGlobalIDs(const std::string &filename, std::vector< Real > &globalDOF)
Read from file and store in a vector a list of global IDs.
std::string M_FEstr
a string label for the FE space
void readAscii(exporterData_Type &dvar)
The ASCII reader.
ExporterEnsight(const GetPot &dfile, meshPtr_Type mesh, const std::string &prefix, const Int &procId)
Constructor for ExporterEnsight.
UInt M_nbLocalDof
the number of local DOFs (per element)
super::meshPtr_Type meshPtr_Type
static MapEpetraType const MapType
returns the type of the map to use for the VectorEpetra
void writeGlobalIDs(const std::string &filename)
Dump on file the IDs of the global DOFs associated to this process.
void initProcId()
initialize the internal data structures storing the ID of the current process
void caseVariableSection(std::ofstream &casef)
Compose the "variable" section of the .case file.
UInt M_nbLocalBdDof
the number of local boundary DOFs (per element)
double Real
Generic real data.
void caseTimeSection(std::ofstream &casef, const Real &time)
Compose the "time" section of the .case file.
void readScalar(exporterData_Type &dvar)
The generic reader (specialization of the parent class method)
const UInt nDimensions(NDIM)
void readAsciiValues(exporterData_Type &dvar, const std::string &suffix)
The ASCII reader.
std::string M_bdFEstr
a string label for the boundary FE space
void stop()
Stop the timer.
super::commPtr_Type commPtr_Type
void writeCase(const Real &time)
Compose the .case file.
std::string M_me
the ID of the current process
void readVariable(exporterData_Type &dvar)
Read variable.
Exporter< mesh_Type > super
void caseMeshSection(std::ofstream &casef)
Compose the "mesh" section of the .case file.
void initNodesMap()
Build the local-to-global map of DOFs.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
void import(const Real &importTime)
Import data from previous simulations.
void writeAscii(const exporterData_Type &dvar)
The ASCII writer.