44 #define EXPORTERVTK_H 1
46 #include <lifev/core/filter/Exporter.hpp> 47 #include <lifev/core/util/EncoderBase64.hpp> 56 template<
typename MeshType>
175 ERROR_MSG (
"ExporterVTK::importFromTime has not yet been implemented.");
188 ERROR_MSG (
"ExporterVTK::importFromTime has not yet been implemented.");
200 if ( !comm->MyPID() )
202 std::cerr <<
" X- exportPID is not working with VTK" << std::endl;
254 std::map<UInt, UInt>& globalToLocalPointsMap,
255 std::map<UInt, UInt>& localToGlobalPointsMap,
256 std::vector<Vector>& coordinatesOfPoints );
265 std::stringstream& vtkCollectionStringStream);
274 std::stringstream& vtuHeaderStringStream );
297 const std::map<UInt, UInt>& globalToLocalPointsMap,
298 const std::vector<Vector>& coordinatesOfPoints,
299 std::stringstream& vtuGeoStringStream );
313 std::stringstream& typeDataHeaderStringStream);
322 std::stringstream& typeDataFooterStringStream);
332 const std::map<UInt, UInt>& localToGlobalMap,
333 std::stringstream& dataArraysStringStream);
337 std::stringstream& dataArraysStringStream);
345 ERROR_MSG (
"ExporterVTK::readScalar has not yet been implemented.");
353 ERROR_MSG (
"ExporterVTK::readVector has not yet been implemented.");
366 void readBinaryData (
const std::string& line, std::vector<Real>& values,
const UInt& numBits );
372 void readASCIIData (
const std::string& line, std::vector<Real>& values );
391 template<
typename MeshType>
398 template<
typename MeshType>
409 const std::string prefix)
411 super (data_file, prefix)
413 this->setDataFromGetPot (data_file);
417 template<
typename MeshType>
420 const std::string& section )
422 super::setDataFromGetPot ( data_file, section );
424 switch ( data_file ( (section +
"/exportMode").c_str(), 1) )
427 M_exportMode = ASCII_EXPORT;
430 M_exportMode = BINARY_EXPORT;
433 ERROR_MSG (
"Unsupported export mode!" );
437 switch ( data_file ( (section +
"/floatPrecision").c_str(), 2) )
440 M_floatPrecision = SINGLE_PRECISION;
443 M_floatPrecision = DOUBLE_PRECISION;
446 ERROR_MSG (
"Unsupported float precision requirement!" );
454 template<
typename MeshType>
461 if (
this->M_timeSteps.size() )
463 std::stringstream buffer (
"");
466 if (
this->M_procId == 0)
468 for (
typename super::dataVectorIterator_Type iData =
this->M_dataVector.begin();
469 iData !=
this->M_dataVector.end(); ++iData)
471 composeVTKCollection ( iData->variableName(), buffer );
473 std::string filename (
this->M_postDir +
this->M_prefix +
"_" + iData->variableName() +
".pvd" );
474 std::ofstream vtkCollectionFile;
475 vtkCollectionFile.open ( filename.c_str() );
476 ASSERT (vtkCollectionFile.is_open(),
"There is an error while opening " + filename );
477 ASSERT (vtkCollectionFile.good(),
"There is an error while writing to " + filename );
478 vtkCollectionFile << buffer.str();
479 vtkCollectionFile.close();
492 template<
typename MeshType>
497 this->computePostfix();
499 std::size_t found (
this->M_postfix.find (
"*" ) );
500 if ( found == std::string::npos )
502 if (
this->M_procId == 0)
504 std::cout <<
" X- ExporterVTK post-processing" << std::flush;
510 this->M_timeSteps.push_back (time);
512 for (
typename super::dataVectorIterator_Type iData =
this->M_dataVector.begin();
513 iData !=
this->M_dataVector.end(); ++iData)
515 std::ofstream vtkFile;
516 std::stringstream buffer (
"");
519 if (
this->M_procId == 0)
521 composePVTUStream (*iData, buffer);
523 std::string vtkPFileName (
this->M_prefix +
"_" + iData->variableName() +
524 this->M_postfix +
".pvtu" );
525 std::string vtkPFileNameWithDir (
this->M_postDir + vtkPFileName);
527 std::ofstream vtkPFile;
528 vtkPFile.open ( vtkPFileNameWithDir.c_str() );
529 ASSERT (vtkPFile.is_open(),
"There is an error while opening " + vtkPFileName );
530 ASSERT (vtkPFile.good(),
"There is an error while writing to " + vtkPFileName );
531 vtkPFile << buffer.str();
536 this->M_pvtuFiles[iData->variableName()].push_back (vtkPFileName);
542 std::map<UInt, UInt> ltgPointsMap, gtlPointsMap;
543 std::vector<Vector> pointsCoords;
544 createPointsMaps ( iData->feSpacePtr(), gtlPointsMap, ltgPointsMap, pointsCoords );
546 composeVTUHeaderStream ( gtlPointsMap.size(), buffer );
547 composeVTUGeoStream ( iData->feSpacePtr(), gtlPointsMap, pointsCoords, buffer );
549 composeTypeDataHeaderStream (iData->where(), buffer);
550 composeDataArrayStream (*iData, ltgPointsMap, buffer);
551 composeTypeDataFooterStream (iData->where(), buffer);
553 composeVTUFooterStream ( buffer );
556 std::string filename (
this->M_postDir +
this->M_prefix +
"_" + iData->variableName() +
557 this->M_postfix +
"." +
this->M_procId +
".vtu" );
558 vtkFile.open ( filename.c_str() );
559 ASSERT (vtkFile.is_open(),
"There is an error while opening " + filename );
560 ASSERT (vtkFile.good(),
"There is an error while writing to " + filename );
561 vtkFile << buffer.str();
570 std::cout <<
"...done in " << chrono.diff() <<
" s." << std::endl;
576 template<
typename MeshType>
579 this->computePostfix();
581 assert (
this->M_postfix !=
"*****" );
583 if (
this->M_procId == 0)
585 std::cout <<
" X- ExporterVTK importing ..." << std::endl;
590 for (
typename super::dataVectorIterator_Type iData =
this->M_dataVector.begin();
591 iData !=
this->M_dataVector.end(); ++iData)
593 this->readVTUFiles (*iData);
596 if (
this->M_procId == 0)
598 std::cout <<
" done in " << chrono.diff() <<
" s." << std::endl;
607 template<
typename MeshType>
618 template <
typename MeshType>
621 ASSERT ( _feSpacePtr.get(),
"\nA pointer to a valid FE object is required!");
623 UInt vtkCellType (0);
625 switch ( _feSpacePtr->fe().refFE().type() )
656 ERROR_MSG (
"WARNING: the element is not yet implemented in ExporterVTK\n" )
664 template <
typename MeshType>
667 const std::map<UInt, UInt>& localToGlobalMap,
668 std::stringstream& dataArraysStringStream)
670 const UInt start ( dvar.start() );
671 const UInt numGlobalDOF ( dvar.numDOF() );
672 const UInt numMyDOF ( localToGlobalMap.size() );
674 std::stringstream dataToBeEncoded;
675 dataToBeEncoded.str (
"");
676 std::string encodedDataString;
678 std::string formatString;
679 std::stringstream nComponents;
680 nComponents << dvar.fieldDim();
683 std::string floatTypeString;
687 ASSERT (
sizeof (
float) == 4,
"\nThis piece of code assumes sizeof(float) == 4" )
688 sizeOfFloat =
sizeof (
float);
689 floatTypeString =
"Float32";
692 ASSERT (
sizeof (Real) == 8,
"\nThis piece of code assumes sizeof(float) == 4" )
693 sizeOfFloat =
sizeof (
Real);
694 floatTypeString =
"Float64";
697 ERROR_MSG (
"WARNING: this float precision cannot be handled in ExporterVTK\n" )
701 int32_type lengthOfRawData ( dvar.fieldDim() *numMyDOF * sizeOfFloat );
706 formatString =
"ascii";
709 formatString =
"binary";
710 dataToBeEncoded.write (
reinterpret_cast<
char*> ( &lengthOfRawData ),
711 sizeof (int32_type) );
715 ERROR_MSG (
"WARNING: this export mode cannot be handled in ExporterVTK\n" )
719 dataArraysStringStream <<
"\t\t\t\t<DataArray type=\"" << floatTypeString <<
"\" Name=\"" 720 << dvar.variableName() <<
"\" NumberOfComponents=\"" 721 << nComponents.str() <<
"\" format=\"" << formatString <<
"\">\n";
726 dataArraysStringStream.setf (std::ios_base::fixed);
727 dataArraysStringStream.precision (5);
728 dataArraysStringStream.width (12);
730 for (
UInt iDOF = 0; iDOF < numMyDOF; ++iDOF)
732 const Int id = localToGlobalMap.find (iDOF)->second;
733 for (
UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
735 dataArraysStringStream << dvar ( start + id +
736 iCoor * numGlobalDOF ) <<
" ";
741 for (
UInt iDOF = 0; iDOF < numMyDOF; ++iDOF)
743 const Int id = localToGlobalMap.find (iDOF)->second;
744 for (
UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
748 const float value ( dvar ( start + id + iCoor * numGlobalDOF ) );
749 dataToBeEncoded.write (
reinterpret_cast<
const char*> (&value),
sizeof (
float) );
753 const Real value ( dvar ( start + id + iCoor * numGlobalDOF ) );
754 dataToBeEncoded.write (
reinterpret_cast<
const char*> (&value),
sizeof (Real) );
759 encodedDataString = base64_encode (
reinterpret_cast<
const unsigned char*> ( dataToBeEncoded.str().c_str() ),
761 dataArraysStringStream << encodedDataString;
765 ERROR_MSG (
"WARNING: this export mode cannot be handled in ExporterVTK\n" )
769 dataArraysStringStream <<
"\n\t\t\t\t</DataArray>\n";
771 dataArraysStringStream <<
"\t\t\t\t<DataArray type=\"Int32\" NumberOfComponents=\"1\" " 772 <<
"Name=\"GlobalId\" format=\"ascii\">\n";
773 for (
UInt iDOF = 0; iDOF < numMyDOF; ++iDOF )
775 dataArraysStringStream << localToGlobalMap.find ( iDOF )->second <<
" ";
777 dataArraysStringStream <<
"\n\t\t\t\t</DataArray>\n";
781 template <
typename MeshType>
785 ASSERT (
this->M_numImportProc,
"The number of pieces to be loaded was not specified." );
787 UInt numPoints, numCells;
788 std::vector<Real> inputValues;
789 std::vector<Real> globalIDs;
791 const UInt start ( dvar.start() );
792 const UInt numGlobalDOF ( dvar.numDOF() );
795 for (
UInt iProc = 0; iProc <
this->M_numImportProc; ++iProc )
797 std::string filename (
this->M_postDir +
this->M_prefix +
"_" + dvar.variableName() +
798 this->M_postfix +
"." + iProc +
".vtu" );
799 std::ifstream inputFile ( filename.c_str() );
801 if (
this->M_procId == 0)
803 std::cout <<
"\tfile " << filename << std::endl;
806 ASSERT (inputFile.is_open(),
"There is an error while opening " + filename );
811 std::stringstream parseLine;
813 while ( inputFile.good() && getline ( inputFile, line ) )
818 found = line.find (
"NumberOfPoints" );
819 if ( found != std::string::npos )
822 found = line.find (
"\"", found, 1 );
824 parseLine.str ( line.substr (found + 1) );
825 parseLine >> numPoints;
828 found = line.find (
"NumberOfCells" );
829 found = line.find (
"\"", found, 1 );
830 parseLine.str ( line.substr (found + 1) );
831 parseLine >> numCells;
835 if ( line.find (
"<PointData" ) != std::string::npos )
837 while ( inputFile.good() && getline ( inputFile, line ) )
839 if ( line.find ( dvar.variableName() ) != std::string::npos )
841 inputValues.resize ( dvar.fieldDim() *numPoints );
843 if ( line.find (
"binary" ) != std::string::npos )
846 found = line.find (
"Float" );
847 parseLine.str ( line.substr (found + 5) );
848 parseLine >> numBitsFloat;
849 ASSERT (inputFile.good(),
"There is an error while opening " + filename );
850 getline ( inputFile, line );
851 readBinaryData ( line, inputValues, numBitsFloat );
855 ASSERT (inputFile.good(),
"There is an error while opening " + filename );
856 getline ( inputFile, line );
857 readASCIIData ( line, inputValues );
860 if ( line.find (
"GlobalId" ) != std::string::npos )
862 globalIDs.resize ( numPoints );
863 ASSERT (inputFile.good(),
"There is an error while opening " + filename );
864 getline ( inputFile, line );
865 readASCIIData ( line, globalIDs );
869 for (UInt iPoint = 0; iPoint < numPoints; ++iPoint)
871 const Int id = globalIDs[iPoint];
872 if ( dvar.feSpacePtr()->map().map (Repeated)->MyGID ( id ) )
874 for (UInt iCoor = 0; iCoor < dvar.fieldDim(); ++iCoor)
876 dvar ( start + id + iCoor * numGlobalDOF ) =
877 inputValues[ iPoint * dvar.fieldDim() + iCoor ];
888 template <
typename MeshType>
892 std::stringstream decodedData, dataToBeDecoded;
893 dataToBeDecoded.str (
"");
894 std::string decodedDataString;
895 UInt sizeOfFloat ( 0 ), sizeOfVector ( values.size() );
900 ASSERT (
sizeof (
float) == 4,
"\nThis piece of code assumes sizeof(float) == 4" );
901 sizeOfFloat =
sizeof (
float);
904 ASSERT (
sizeof (Real) == 8,
"\nThis piece of code assumes sizeof(Real) == 8" );
905 sizeOfFloat =
sizeof (
Real);
913 dataToBeDecoded.write ( line.c_str(), line.size() );
917 decodedDataString = base64_decode ( dataToBeDecoded.str() );
918 decodedData.str ( decodedDataString );
920 #ifdef HAVE_LIFEV_DEBUG 921 UInt lengthOfRawData = sizeOfVector * sizeOfFloat +
sizeof (int32_type);
922 ASSERT ( lengthOfRawData == decodedDataString.size(),
"unexpected line length" );
927 decodedData.read (
reinterpret_cast<
char*> ( inputInt ),
928 sizeof (int32_type) );
930 ASSERT ( *inputInt - sizeOfVector,
"Inconsistent size of data!" );
936 float* inputFloat =
new float[sizeOfVector];
937 decodedData.read (
reinterpret_cast<
char*> ( inputFloat ),
938 sizeOfVector * sizeOfFloat );
939 std::vector<
float> inputValuesTemp (sizeOfVector);
940 inputValuesTemp.assign ( inputFloat, inputFloat + sizeOfVector );
941 values.assign ( inputValuesTemp.begin(), inputValuesTemp.end() );
948 Real* inputReal =
new Real[sizeOfVector];
949 decodedData.read (
reinterpret_cast<
char*> ( inputReal ),
950 sizeOfVector * sizeOfFloat );
951 values.assign ( inputReal, inputReal + sizeOfVector );
958 template <
typename MeshType>
962 std::stringstream readData ( line );
965 for (UInt i = 0; i < values.size(); i++)
967 readData >> values[i];
979 template <
typename MeshType>
982 std::stringstream& dataArraysStringStream)
986 typename super::iterator_Type it;
987 std::pair<
typename super::iterator_Type,
typename super::iterator_Type> rangeFound;
989 rangeFound =
this->M_whereToDataMap.equal_range (where);
991 if ( rangeFound.first != rangeFound.second )
993 debugStream (8000
) <<
"\n[ExporterVTK::composeDataArrayStream] found data\n";
995 dataArraysStringStream.setf (std::ios_base::fixed);
996 dataArraysStringStream.precision (5);
997 dataArraysStringStream.width (12);
999 for (it = rangeFound.first; it != rangeFound.second; ++it)
1001 switch ( it->second.fieldType() )
1003 case exporterData_Type::ScalarField:
1005 dataArraysStringStream <<
"\t\t\t\t<DataArray type=\"Float32\" Name=\"" 1006 << it->second.variableName() <<
"\" NumberOfComponents=\"1\" format=\"ascii\">\n";
1008 for (
UInt iValue = 1; iValue <= it->second.size(); ++iValue)
1010 dataArraysStringStream << it->second ( iValue ) <<
" ";
1013 case exporterData_Type::VectorField:
1015 dataArraysStringStream <<
"\t\t\t\t<DataArray type=\"Float32\" Name=\"" 1016 << it->second.variableName() <<
"\" NumberOfComponents=\"" 1017 << nDimensions <<
"\" format=\"ascii\">\n";
1019 for (
UInt iValue = 1; iValue <= it->second.size(); ++iValue)
1023 dataArraysStringStream << it->second ( iValue + iCoor * it->second.size() ) <<
" ";
1046 dataArraysStringStream <<
"\n\t\t\t\t</DataArray>\n";
1053 template <
typename MeshType>
1055 std::stringstream& pVTUStringStream)
1058 std::string floatTypeString;
1061 case SINGLE_PRECISION:
1062 floatTypeString =
"Float32";
1064 case DOUBLE_PRECISION:
1065 floatTypeString =
"Float64";
1073 pVTUStringStream <<
"<?xml version=\"1.0\"?>\n";
1074 pVTUStringStream <<
"<VTKFile type=\"PUnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1075 pVTUStringStream <<
"\t<PUnstructuredGrid GhostLevel=\"0\">\n";
1077 pVTUStringStream <<
"\t\t<PPoints>\n";
1078 pVTUStringStream <<
"\t\t\t<PDataArray type=\"Float32\" NumberOfComponents=\"" << nDimensions
1079 <<
"\" format=\"ascii\"/>\n";
1080 pVTUStringStream <<
"\t\t</PPoints>\n";
1084 pVTUStringStream <<
"\t\t<PCells>\n";
1085 pVTUStringStream <<
"\t\t\t<PDataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\"/>\n";
1087 pVTUStringStream <<
"\t\t\t<PDataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\"/>\n";
1089 pVTUStringStream <<
"\t\t\t<PDataArray type=\"Int32\" Name=\"types\" format=\"ascii\"/>\n";
1091 pVTUStringStream <<
"\t\t</PCells>\n";
1093 std::string whereString;
1094 switch ( dvar.where() )
1096 case exporterData_Type::Node:
1097 whereString =
"PPointData";
1099 case exporterData_Type::Cell:
1100 whereString =
"PCellData";
1103 ERROR_MSG (
"Cannot manage this data location" );
1106 pVTUStringStream <<
"\t\t<" << whereString <<
" ";
1108 pVTUStringStream <<
">\n";
1110 std::string formatString;
1111 std::stringstream nComponents;
1112 nComponents << dvar.fieldDim();
1116 formatString =
"ascii";
1119 formatString =
"binary";
1122 ERROR_MSG (
"Cannot manage this export mode" );
1125 pVTUStringStream <<
"\t\t\t<PDataArray type=\"" << floatTypeString <<
"\" Name=\"" 1126 << dvar.variableName() <<
"\" NumberOfComponents=\"" 1127 << nComponents.str() <<
"\" format=\"" << formatString <<
"\">\n";
1129 pVTUStringStream <<
"\t\t\t</PDataArray>\n";
1131 pVTUStringStream <<
"\t\t\t<PDataArray type=\"Int32\" Name=\"GlobalId\" NumberOfComponents=\"1\" " 1132 <<
"format=\"ascii\">\n";
1133 pVTUStringStream <<
"\t\t\t</PDataArray>\n";
1135 pVTUStringStream <<
"\t\t</" << whereString <<
">\n";
1137 for (
Int iProc = 0; iProc < dvar.feSpacePtr()->map().comm().NumProc(); ++iProc )
1139 std::stringstream fileName ( (
this->M_prefix +
"_" + dvar.variableName() +
1140 this->M_postfix +
"." + iProc +
".vtu").c_str() );
1143 pVTUStringStream <<
"\t\t<Piece Source=\"" << fileName.str() <<
"\"/>\n";
1146 pVTUStringStream <<
"\t</PUnstructuredGrid>\n";
1147 pVTUStringStream <<
"</VTKFile>\n";
1152 template <
typename MeshType>
1154 std::map<UInt, UInt>& globalToLocalPointsMap,
1155 std::map<UInt, UInt>& localToGlobalPointsMap,
1156 std::vector<Vector>& coordinatesOfPoints )
1158 ASSERT (
this->M_mesh.get(),
"\nA pointer to a valid mesh object is required!");
1159 ASSERT ( _feSpacePtr.get(),
"\nA pointer to a valid FESpace object is required!");
1161 const ID numVertices =
this->M_mesh->numVertices();
1162 const ID numElements =
this->M_mesh->numElements();
1166 const UInt numPoints = _feSpacePtr->map().map (
Repeated)->NumMyElements() / _feSpacePtr->fieldDim();
1168 coordinatesOfPoints.resize ( nDimensions, ZeroVector (numPoints) );
1173 UInt globalPointId (0);
1175 UInt positionInPartitionedMesh (0);
1177 std::pair< std::map<UInt, UInt>::iterator,
bool > returnType;
1180 for (
ID iVertex = 0; iVertex < numVertices; ++iVertex)
1182 globalPointId =
this->M_mesh->point (iVertex).id();
1183 localToGlobalPointsMap.insert ( std::pair<UInt, UInt> ( positionInPartitionedMesh, globalPointId ) );
1184 globalToLocalPointsMap.insert ( std::pair<UInt, UInt> ( globalPointId, positionInPartitionedMesh ) );
1188 coordinatesOfPoints[jCoor][positionInPartitionedMesh] =
1189 this->M_mesh->point (iVertex).coordinate (jCoor);
1191 ++positionInPartitionedMesh;
1193 ASSERT ( positionInPartitionedMesh == numVertices,
"didn't store all vertices in the maps");
1194 ASSERT ( localToGlobalPointsMap.size() == globalToLocalPointsMap.size(),
1195 "problem in storing the local to global and global to local maps" );
1198 for (
UInt iElement = 0; iElement < numElements; ++iElement )
1201 for (
UInt iPoint = _feSpacePtr->dof().numLocalVertices();
1202 iPoint < _feSpacePtr->dof().numLocalDof(); ++iPoint )
1204 _feSpacePtr->fe().coorMap ( x, y, z,
1205 _feSpacePtr->fe().refFE().xi ( iPoint ),
1206 _feSpacePtr->fe().refFE().eta ( iPoint ),
1207 _feSpacePtr->fe().refFE().zeta ( iPoint ) );
1209 globalPointId = _feSpacePtr->dof().localToGlobalMap ( iElement, iPoint );
1211 returnType = globalToLocalPointsMap.insert ( std::pair<UInt, UInt> ( globalPointId,
1212 positionInPartitionedMesh ) );
1216 if ( returnType.second )
1218 localToGlobalPointsMap.insert ( std::pair<UInt, UInt> ( positionInPartitionedMesh, globalPointId ) );
1219 coordinatesOfPoints[0][positionInPartitionedMesh] = x;
1220 coordinatesOfPoints[1][positionInPartitionedMesh] = y;
1221 coordinatesOfPoints[2][positionInPartitionedMesh] = z;
1222 ++positionInPartitionedMesh;
1227 ASSERT ( positionInPartitionedMesh == numPoints,
"didn't store all points in the maps" );
1228 ASSERT ( localToGlobalPointsMap.size() == globalToLocalPointsMap.size(),
1229 "problem in storing the local to global and global to local maps" );
1230 ASSERT ( localToGlobalPointsMap.size() == numPoints,
1231 "problem in storing the local to global and global to local maps" );
1236 template <
typename MeshType>
1238 std::stringstream& vtkCollectionStringStream )
1246 vtkCollectionStringStream <<
"<?xml version=\"1.0\"?>\n";
1247 vtkCollectionStringStream <<
"<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1248 vtkCollectionStringStream <<
"\t<Collection>\n";
1250 typedef std::list<Real>::const_iterator realIterator;
1251 realIterator iTime =
this->M_timeSteps.begin();
1252 typedef std::list<std::string>::const_iterator stringIterator;
1253 stringIterator iFileName =
this->M_pvtuFiles[variableName].begin();
1256 if (iFileName !=
this->M_pvtuFiles[variableName].end() )
1257 for ( ; iTime !=
this->M_timeSteps.end(); ++iTime, ++iFileName)
1258 vtkCollectionStringStream <<
"\t\t<DataSet timestep=\"" << *iTime <<
"\" group=\"\" part=\"0\" " 1259 <<
"file=\"" << *iFileName <<
"\" />\n";
1261 vtkCollectionStringStream <<
"\t</Collection>\n";
1262 vtkCollectionStringStream <<
"</VTKFile>\n";
1267 template <
typename MeshType>
1269 const std::map<UInt, UInt>& globalToLocalPointsMap,
1271 const std::vector<Vector>& coordinatesOfPoints,
1272 std::stringstream& vtuGeoStringStream )
1274 ASSERT (
this->M_mesh.get(),
"\nA pointer to a valid mesh object is required!");
1275 ASSERT ( _feSpacePtr.get(),
"\nA pointer to a valid FESpace object is required!");
1277 debugStream (8000
) <<
"\n[ExporterVTK::composeVTUHeaderStream]\n";
1279 const UInt numPoints = globalToLocalPointsMap.size();
1280 const UInt numElements =
this->M_mesh->numElements();
1281 const UInt numLocalDof = _feSpacePtr->dof().numLocalDof();
1283 vtuGeoStringStream <<
"\t\t\t<Points>\n";
1284 vtuGeoStringStream <<
"\t\t\t\t<DataArray type=\"Float32\" NumberOfComponents=\"" << nDimensions
1285 <<
"\" format=\"ascii\">\n";
1287 for (
UInt iPoint = 0; iPoint < numPoints; ++iPoint )
1291 vtuGeoStringStream << coordinatesOfPoints[iCoor][ iPoint ] <<
" ";
1294 vtuGeoStringStream <<
"\n\t\t\t\t</DataArray>\n";
1296 vtuGeoStringStream <<
"\t\t\t</Points>\n";
1300 vtuGeoStringStream <<
"\t\t\t<Cells>\n";
1301 vtuGeoStringStream <<
"\t\t\t\t<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
1303 for (
UInt iElement = 0; iElement < numElements; ++iElement)
1305 for (
UInt jPoint = 0; jPoint < numLocalDof; ++jPoint)
1308 const UInt globalPointId ( _feSpacePtr->dof().localToGlobalMap ( iElement, jPoint ) );
1309 ASSERT ( globalToLocalPointsMap.find ( globalPointId ) != globalToLocalPointsMap.end(),
1310 "didn't find a local ID for global point" );
1311 const UInt localId ( globalToLocalPointsMap.find ( globalPointId )->second );
1312 vtuGeoStringStream << localId <<
" ";
1315 vtuGeoStringStream <<
"\n\t\t\t\t</DataArray>\n";
1317 vtuGeoStringStream <<
"\t\t\t\t<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
1319 for (
UInt iElement = 1; iElement <= numElements; ++iElement)
1321 vtuGeoStringStream << iElement* numLocalDof <<
" ";
1324 vtuGeoStringStream <<
"\n\t\t\t\t</DataArray>\n";
1326 vtuGeoStringStream <<
"\t\t\t\t<DataArray type=\"Int32\" Name=\"types\" format=\"ascii\">\n";
1330 for (
UInt iElement = 1; iElement <= numElements; ++iElement)
1332 vtuGeoStringStream << vtkCellType <<
" ";
1335 vtuGeoStringStream <<
"\n\t\t\t\t</DataArray>\n";
1336 vtuGeoStringStream <<
"\t\t\t</Cells>\n";
1341 template <
typename MeshType>
1343 std::stringstream& vtuHeaderStringStream )
1347 vtuHeaderStringStream <<
"<?xml version=\"1.0\"?>\n";
1348 vtuHeaderStringStream <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
1349 vtuHeaderStringStream <<
"\t<UnstructuredGrid>\n";
1350 vtuHeaderStringStream <<
"\t\t<Piece NumberOfPoints=\"" << numPoints <<
"\"" 1351 <<
" NumberOfCells=\"" <<
this->M_mesh->numElements() <<
"\">\n";
1357 template <
typename MeshType>
1363 vtuFooterStringStream <<
"\t\t</Piece>\n";
1364 vtuFooterStringStream <<
"\t</UnstructuredGrid>\n";
1365 vtuFooterStringStream <<
"</VTKFile>\n";
1371 template <
typename MeshType>
1374 std::stringstream& dataHeaderStringStream)
1376 debugStream (8000
) <<
"\n[ExporterVTK::composeTypeDataHeaderStream] where = " << where <<
"\n";
1378 std::string whereString;
1381 case exporterData_Type::Node:
1382 whereString =
"PointData";
1384 case exporterData_Type::Cell:
1385 whereString =
"CellData";
1388 ERROR_MSG (
"Cannot manage this data location")
1391 dataHeaderStringStream <<
"\t\t\t<" << whereString <<
" ";
1393 dataHeaderStringStream <<
">\n";
1397 template <
typename MeshType>
1400 std::stringstream& dataFooterStringStream)
1402 std::string whereString;
1405 case exporterData_Type::Node:
1406 whereString =
"PointData";
1408 case exporterData_Type::Cell:
1409 whereString =
"CellData";
1412 ERROR_MSG (
"Cannot manage this data location")
1415 dataFooterStringStream <<
"\t\t\t</" << whereString <<
">\n";
virtual void setDataFromGetPot(const GetPot &dataFile, const std::string §ion="exporter")
Set data from file.
super::feTypeToDataIdMap_Type::iterator feTypeToDataIdMap_Type_Type
virtual void postProcess(const Real &time)
Post-process the variables added to the list.
void start()
Start the timer.
void createPointsMaps(const feSpacePtr_Type &_feSpacePtr, std::map< UInt, UInt > &globalToLocalPointsMap, std::map< UInt, UInt > &localToGlobalPointsMap, std::vector< Vector > &coordinatesOfPoints)
virtual UInt importFromTime(const Real &)
Import data from previous simulations at a certain time.
void exportPID(meshPtr_Type, commPtr_Type comm, const bool=false)
temporary: the method should work form the Exporter class
virtual MapEpetraType mapType() const
returns the type of the map to use for the VectorEpetra
virtual void import(const Real &, const Real &)
Import data from previous simulations and rebuild the internal time counters.
ExporterVTK(const GetPot &data_file, const std::string prefix)
int32_type Int
Generic integer data.
ExporterVTK(const ExporterVTK &example)
Copy constructor.
void composeDataArrayStream(const exporterData_Type &dvar, const std::map< UInt, UInt > &localToGlobalMap, std::stringstream &dataArraysStringStream)
ExporterVTK()
Default constructor.
void readBinaryData(const std::string &line, std::vector< Real > &values, const UInt &numBits)
A routine for loading values stored in binary format in a VTU file.
dataVector_Type::iterator dataVectorIterator_Type
ExporterData - Holds the data structure of the array to import/export.
virtual void readVector(ExporterData< mesh_Type > &)
The vector reader (specialization of the parent class method)
void readVTUFiles(exporterData_Type &dvar)
The reader for VTU files.
void composeVTUGeoStream(const feSpacePtr_Type &_feSpacePtr, const std::map< UInt, UInt > &globalToLocalPointsMap, const std::vector< Vector > &coordinatesOfPoints, std::stringstream &vtuGeoStringStream)
UInt whichCellType(const feSpacePtr_Type &_feSpacePtr)
void composeDataArrayStream(where_Type where, std::stringstream &dataArraysStringStream)
void readASCIIData(const std::string &line, std::vector< Real > &values)
A routine for loading values stored in ASCII format in a VTU file.
void composeVTKCollection(const std::string &variableName, std::stringstream &vtkCollectionStringStream)
const exporterData_Type::WhereEnum & where_Type
void composeTypeDataFooterStream(where_Type where, std::stringstream &typeDataFooterStringStream)
Exporter< mesh_Type > super
double Real
Generic real data.
super::meshPtr_Type meshPtr_Type
NdebugStream noDebugStream(int=0, NdebugStream::stprintf=&printf)
virtual void import(const Real &Tstart)
Import data from previous simulations.
const UInt nDimensions(NDIM)
void composeVTUHeaderStream(UInt numPoints, std::stringstream &vtuHeaderStringStream)
super::feSpacePtr_Type feSpacePtr_Type
virtual void readScalar(ExporterData< mesh_Type > &)
The scalar reader (specialization of the parent class method)
void stop()
Stop the timer.
void composeVTUFooterStream(std::stringstream &vtuFooterStringStream)
static MapEpetraType const MapType
returns the type of the map to use for the VectorEpetra
std::map< std::string, std::list< std::string > > M_pvtuFiles
void composeTypeDataHeaderStream(where_Type where, std::stringstream &typeDataHeaderStringStream)
FLOAT_PRECISION M_floatPrecision
uint32_type UInt
generic unsigned integer (used mainly for addressing)
ExporterVTK data exporter.
super::exporterData_Type exporterData_Type
void composePVTUStream(const exporterData_Type &dvar, std::stringstream &pVTUStringStream)
super::commPtr_Type commPtr_Type
virtual ~ExporterVTK()
Destructor.
const flag_Type UPDATE_ONLY_CELL_NODES(1)