32 #include <vtkDataObjectWriter.h>
33 #include <vtkDataSetToDataObjectFilter.h>
48 m_writeGeomIndices(writeGeomIndices),
52 setOutputType(outputType);
55 "Vtk writer: nullptr pointer to discretization passed"
57 m_geom = discr->getProblem()->getGeometry();
63 m_outputLgMax =
static_cast<CepsUInt>(floor(log10(nOutputs))+1);
64 m_writtenTimes.reserve(nOutputs+1);
67 "Provided output directory is not a valid path name (do not forget \\ before spaces).\n"
68 <<
"Given path: \n " << m_outputDir
71 m_unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
74 m_vtkMpiComm = vtkSmartPointer<vtkMPICommunicator>::New();
76 m_vtkMpiComm->InitializeExternal(&m_opaqueCommVTK);
79 m_vtkMpiController = vtkSmartPointer<vtkMPIController>::New();
80 m_vtkMpiController->SetCommunicator(m_vtkMpiComm);
84 CepsString command =
"mkdir -p " + m_outputDir +
"/snapshots";
112 "Mismatch between number of field names and number of unknowns given to wtk writer"
115 for (
CepsUInt iu = 0u; iu<us.size(); iu++)
122 "Pointer to unknown passed to addScalar is null"
145 vtkDoubleArray* scalars = vtkDoubleArray::New();
146 scalars->SetName(fieldNames[iu].c_str());
147 scalars->SetNumberOfTuples(nToWrite);
155 scalars->SetTuple1(vtkId,data[i]);
180 "No data has been given to the writer with addScalarData"
221 return "Results can be viewed by opening "
244 return ".pvtu.series";
257 std::stringstream filename;
262 auto writer = vtkSmartPointer<vtkXMLPUnstructuredGridWriter>::New();
263 writer->SetDataModeToBinary();
267 writer->SetCompressor(
nullptr);
270 writer->SetFileName(filename.str().c_str());
278 std::stringstream filename;
283 auto writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
284 writer->SetFileTypeToBinary();
286 writer->SetFileName(filename.str().c_str());
293 std::stringstream filename;
298 auto fields = vtkSmartPointer<vtkDataSetToDataObjectFilter>::New();
300 fields->CellDataOn();
301 fields->PointDataOn();
302 fields->FieldDataOn();
303 fields->GeometryOff();
304 fields->TopologyOff();
307 auto writer = vtkSmartPointer<vtkDataObjectWriter>::New();
308 writer->SetFileTypeToBinary();
309 writer->SetFieldDataName(
"data");
310 writer->AddInputConnection(fields->GetOutputPort());
311 writer->SetFileName(filename.str().c_str());
319 std::ofstream file(series, std::ofstream::trunc);
320 std::stringstream filename;
322 file <<
"{" << std::endl;
323 file <<
" \"file-series-version\" : \"1.0\"," << std::endl;
324 file <<
" \"files\" : [" << std::endl;
328 filename <<
"./snapshots/" <<
m_baseName <<
"-" << std::setfill(
'0')
333 file <<
"\"name\" : \"" << filename.str() <<
"\", ";
334 file <<
"}," << std::endl;
339 file <<
" ]" << std::endl;
340 file <<
"}" << std::endl;
348 std::ofstream file(meta, std::ofstream::trunc);
349 std::stringstream filename;
351 file <<
"<?xml version=\"1.0\"?>" << endl;
352 file <<
"<VTKFile type=\"vtkDataManager\" version=\"0.1\" byte_order=\"LittleEndian\" "
353 "compressor=\"vtkZLibDataCompressor\">" << std::endl;
354 file <<
" <vtkDataManager>" << std::endl;
358 filename <<
"./snapshots/" <<
m_baseName <<
"-" << std::setfill(
'0')
361 file <<
" <vtkMetaDataSet type=\"1\" name=\"\" tag=\"\">" << std::endl;
362 file <<
" <metadata key=\"Time\" value=\"" <<
m_writtenTimes[i] <<
"\">" << std::endl;
363 file <<
" <DataSet group=\"0\" dataset=\"" << i <<
"\" file=\"" << filename.str() <<
"\"/>" << std::endl;
364 file <<
" </vtkMetaDataSet>" << std::endl;
369 file <<
" </vtkDataManager>" << std::endl;
370 file <<
"</VTKFile>" << std::endl;
394 vtkPoints* points = vtkPoints::New(VTK_DOUBLE);
395 points->GetData()->SetName(
"Vertex coordinates");
403 vtkIdTypeArray* globalIndices = vtkIdTypeArray::New();
406 globalIndices->SetName(
"globalIndices");
407 globalIndices->SetNumberOfComponents(1);
408 globalIndices->SetNumberOfTuples(nToWrite);
409 globalIndices->FillComponent(0,-1);
427 globalIndices->SetTuple1(i,gId);
448 points->InsertNextPoint(xyz[0],xyz[1],xyz[2]);
465 points->InsertNextPoint(n->x(),n->y(),n->z());
478 globalIndices->Delete();
514 vtkIdList *nodeIds = vtkCell->GetPointIds();
515 for (vtkIdType j=0; j<vtkCell->GetNumberOfPoints(); j++)
527 nodeIds->SetId(j,nodeId);
563 vtkIdList *nodeIds = vtkCell->GetPointIds();
565 for (vtkIdType j=0; j<vtkCell->GetNumberOfPoints(); j++)
569 nodeIds->SetId(j,nodeId);
583 return vtkTetra::New();
585 return vtkTriangle::New();
587 return vtkLine::New();
589 return vtkVertex::New();
595 auto timef = vtkSmartPointer<vtkDoubleArray>::New();
596 timef->SetNumberOfValues(1);
597 timef->SetValue(0,time);
598 timef->SetName(
"TIME_STEP");
CepsLocationFlag
DataLocation: an enum that will be used by various elements of the code (pde, readers,...
@ Point
Data is defined on each point.
@ ZeroD
Data is defined once.
CepsOutputFormat
Style of output files.
@ VTKCeps
vtk_ceps format, use contrib/CepsParaviewPlugin.py (5.11)
@ ParaviewSeries
Paraview files series, JSON + VTU/PVTU.
@ Music
MUSIC files, VTKLegacy and xml.
@ VTKLegacy
VTK Legacy, one by time steps.
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
std::basic_string< CepsChar > CepsString
C++ format string.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
float CepsReal
Need single precision floating point.
CepsInt CepsIndex
Index rowid etc.
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
Abstract Class for all numerical method (FE, FD, FV etc)
virtual void extractValuesForUnknown(const CepsUnknownIndex &uId, DVecPtr vec, CepsVector< CepsIndex > &indices, CepsVector< CepsReal > &values, CepsBool sendToMaster=false, CepsBool returnGeomIndices=false)=0
Slicing method that extracts the data corresponding to a specific unknown.
Profiler * getProfiler() const
Access to profiler.
CepsReal & getCoordinate(const CepsSize &dim)
Get coordinate of dimension 0 1 2, read & write.
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Base class for nodes used in meshes.
CepsBool has1dMesh() const
true if geometry has 1d data
GeomNode * getNode(CepsNodeGlobalIndex globalID, CepsBool ownedOnly=false)
Returns a pointer to the node with given global ID. Nullptr if node is not owned or halo.
const CepsVector< CepsNodeGlobalIndex > & getNodePartitionMap()
The node index map from before to after partitioning.
CepsBool has2dMesh() const
true if geometry has 2d data
CepsBool has3dMesh() const
true if geometry has 3d data
CepsUInt getNbNodesLocal() const
Number of nodes local to this process, with halo nodes.
Mesh * getMeshOfDim(CepsUInt dim) const
Return the mesh of requested dimension.
CepsUInt getNbNodes() const
Number of nodes of the geometry (global)
GeomCell * getCell(CepsCellGlobalIndex globalID)
Returns a pointer to the cell with given global ID. Nullptr if cell is not owned.
CepsBool hasMeshOfDim(CepsUInt dim) const
true if geometry has data of requested dimension
const CepsVector< CepsCellGlobalIndex > & getCellPartitionMap()
The node index map from before to after partitioning.
CepsUInt getNbCells() const
Number of non-boundary cells of the geometry (global).
Geometrical information of 1,2 or 3D distributed cells.
const CepsVector< GeomCell * > & getCells()
CepsVector of cells stored on this process.
const CepsVector< GeomNode * > & getHaloNodes()
CepsVector of halo nodes stored on this process.
const CepsVector< GeomCell * > & getBoundaryCells()
CepsVector of boundary cells stored on this process.
void stop(CepsString lbl)
Stops the measure of a labeled chronometer.
void start(CepsString lbl, CepsString dspl="")
Creates or continue a labeled chronometer.
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
const CepsLocationFlag & getLocation() const
Get the data location of the unknown.
CepsUnknownIndex getIdentifier() const
Get the identifier of the unknown.
void addScalarData(const DHVecPtr &v, const CepsVector< CepsString > &fieldNames, const CepsVector< Unknown * > &us)
Set multiple scalar fields to be output by this writer. addScalarData for several unknowns.
CepsUInt m_outputLgMax
estimated number of output files (log10)+1
CepsBool m_updateMesh
if the mesh data (geometry) must be updated
void updateMeshData()
Global geometrical data regrouping.
void writeVTU()
Write current state (Paraview xml pvtu & vtu file)
vtkSmartPointer< vtkMPIController > m_vtkMpiController
vtk mpi controller
void insertCell(GeomCell *cell)
Internal method which inserts one element as a cell in a unstructuredGrid vtk object.
vtkSmartPointer< vtkUnstructuredGrid > m_unstructuredGrid
the vtk data wrapper
CepsOutputFormat m_outputType
Output type.
void insertElementData()
Add cell definition to VTK structures.
void writeLegacyVTK()
Write current state (Paraview legacy vtk)
CepsOutputFormat getOutputType() const
Get the output type.
std::map< CepsUInt, CepsUInt > m_geomToVtkNodeIndex
mapping used for nodes
void insertPointData()
Add coordinates to VTK structures, add array of global indices if needed.
void write(CepsReal time=0., CepsBool writeXmlEntry=true)
Write all stored data.
Geometry * m_geom
Direct link to geometry.
CepsString getByeByeMessage()
Get string to be displayed at end of computation.
VtkWriter()=delete
Deleted constructor.
void insertElementsOfDim(CepsUInt dim)
Internal method which for looping on all elements on a mesh of given dimension.
CepsString getOuputExtension() const
Get the extension, deduced from CepsOutputFormat.
void setOutputType(CepsOutputFormat flag)
Set the output type.
void writeSeriesFile()
Write time series file for all time steps (Paraview pvtu.series)
void writeDataArray()
Write current state (vtk_ceps format)
CepsVector< CepsReal > m_writtenTimes
Previous times already written.
void writeMetaDataSet()
Write time pvd file for all time steps (Paraview .pvd)
CepsUInt m_internalIndex
Points counter.
vtkCell * allocateCellOfDim(CepsUInt dim)
Internal method allocating a cell for a finite element (tetra,tri,...)
std::map< CepsUInt, CepsUInt > m_geomToVtkCellIndex
mapping used for elements
~VtkWriter() override
Destructor.
CepsString m_baseName
base name of output files
CepsBool m_writeGeomIndices
option to add array of CEPS point IDs
CepsString m_outputDir
output directory
AbstractDiscretization * m_discr
Discretization (dofs)
CepsUInt m_outputNb
number of output file (not iteration)
void addTimeFieldToUGrid(CepsReal time)
Adds a single scalar field to unstructred grid to write, called before writing.
const CepsUInt & getDimension() const
Get the dimension of the object.
const CepsGlobalIndex & getGlobalIndex() const
Get the index
NodeType * getNodeAt(const CepsUInt &i)
Pointer to the i-th node.
CepsString getDir(const CepsString &str)
Get a substring of s, from beginning of s to the last '/' character. Example: "/home/someone/file....
CepsString execute(CepsString command, CepsBool withErr=false, CepsBool abortOnErr=false)
Not really a parallel thing. Calls system() and deals with return code.
CepsUInt getRank()
Returns current processor rank.
MPI_Comm getCommunicator()
Get the communicator.
CepsBool isValidPtr(_Type *ptr)
Tells if pointer is not null.
CepsBool isParallel()
Is there more than 1 process currently working ?
CepsUInt getGridSize()
Returns the number of process on the computing grid.
CepsBool isNullPtr(_Type *ptr)
Tells if passed pointer is null.
CepsBool isMaster()
Is calling process the master ?
MPI_Comm * getPtrCommunicator()
Get pointer to the communicator.
CepsString getBaseName(const CepsString &str)
Extracts the base of a file name, without path, nor extension. Ex: getBaseName("/path/to/myfile....
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
CepsBool isPathInOneWord(const CepsString &s)
Checks if given path is in one word (it may not exist yet)