CEPS  24.01
Cardiac ElectroPhysiology Simulator
VtkWriter.hpp
Go to the documentation of this file.
1 /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2  This file is part of CEPS.
3 
4  CEPS is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  CEPS is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with CEPS (see file LICENSE at root of project).
16  If not, see <https://www.gnu.org/licenses/>.
17 
18 
19  Copyright 2019-2024 Inria, Universite de Bordeaux
20 
21  Authors, in alphabetical order:
22 
23  Pierre-Elliott BECUE, Florian CARO, Yves COUDIERE(*), Andjela DAVIDOVIC,
24  Charlie DOUANLA-LONTSI, Marc FUENTES, Mehdi JUHOOR, Michael LEGUEBE(*),
25  Pauline MIGERDITICHAN, Valentin PANNETIER(*), Nejib ZEMZEMI.
26  * : currently active authors
27 
28 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
30 #pragma once
31 
32 #include <vtkCellData.h>
33 #include <vtkDoubleArray.h>
34 #include <vtkPointData.h>
35 #include <vtkSmartPointer.h>
36 
37 #include <vtkIdTypeArray.h>
38 #include <vtkLine.h>
39 #include <vtkQuadraticEdge.h>
40 #include <vtkQuadraticTetra.h>
41 #include <vtkQuadraticTriangle.h>
42 #include <vtkTetra.h>
43 #include <vtkTriangle.h>
44 #include <vtkUnstructuredGrid.h>
45 #include <vtkUnstructuredGridWriter.h>
46 #include <vtkVertex.h>
47 #include <vtkXMLPUnstructuredGridWriter.h>
48 
49 #include <vtkMPIController.h>
50 #include <vtkMPICommunicator.h>
51 #include <vtkMPI.h>
52 
53 #include "common/CepsCommon.hpp"
54 #include "geometry/Geometry.hpp"
57 
68 class VtkWriter : public CepsObject
69 {
70 
71  public:
72 
77  VtkWriter() = delete;
78 
88  const CepsString& name,
89  CepsUInt nOutputs,
90  CepsOutputFormat outputFormat,
91  CepsBool writeGlobalIndices = false);
92 
94  ~VtkWriter() override;
95 
99  void
100  addScalarData(const DHVecPtr& v, const CepsVector<CepsString>& fieldNames,
101  const CepsVector<Unknown*>& us);
102 
115  void
116  addScalarData(const DHVecPtr& v, const CepsString& fieldName, Unknown* u);
117 
123  void
124  write(CepsReal time = 0., CepsBool writeXmlEntry = true);
125 
127  CepsString
129 
131  void
133 
136  getOutputType() const;
137 
139  CepsString
140  getOuputExtension() const;
141 
142  protected:
143  // ======================================================================================================
144  // Write functions
145 
147  void
148  writeVTU();
149 
151  void
152  writeLegacyVTK();
153 
155  void
156  writeDataArray();
157 
159  void
160  writeSeriesFile();
161 
163  //void
164  //writeParaviewFile();
165 
167  void
169 
170  // ======================================================================================================
171  // Data
172 
174  void
175  updateMeshData();
176 
178  void
179  insertPointData();
180 
182  void
184 
186  void
188 
190  void
191  insertCell(GeomCell* cell);
192 
194  vtkCell *
196 
198  void
200 
201 
202  protected:
203 
207 
212 
217 
218  vtkSmartPointer<vtkUnstructuredGrid> m_unstructuredGrid;
219 
220  std::map<CepsUInt, CepsUInt> m_geomToVtkNodeIndex;
221  std::map<CepsUInt, CepsUInt> m_geomToVtkCellIndex;
222 
223  // Tools to handle the writing of pvtu file on multiple processors
224  vtkSmartPointer<vtkMPICommunicator> m_vtkMpiComm;
225  vtkMPICommunicatorOpaqueComm m_opaqueCommVTK;
226  vtkSmartPointer<vtkMPIController> m_vtkMpiController;
227 };
CepsOutputFormat
Style of output files.
Definition: CepsEnums.hpp:179
std::basic_string< CepsChar > CepsString
C++ format string.
Definition: CepsTypes.hpp:128
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
Definition: CepsTypes.hpp:109
float CepsReal
Need single precision floating point.
Definition: CepsTypes.hpp:100
std::shared_ptr< DistributedHaloVector > DHVecPtr
Typedef for pointer on Distributed Halo CepsVector.
Abstract Class for all numerical method (FE, FD, FV etc)
Base class for other (big) CEPS classes. All classes can get a pointer to this base class and also co...
Definition: CepsObject.hpp:40
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Definition: GeomCell.hpp:48
Encapsulates all the geometrical data.
Definition: Geometry.hpp:50
A class used to defined an unknown of a PDE problem The unknown can be defined on a specific region,...
Definition: Unknown.hpp:45
A class that enables the output of binary parallel VTK format files.
Definition: VtkWriter.hpp:69
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.
Definition: VtkWriter.cpp:101
CepsUInt m_outputLgMax
estimated number of output files (log10)+1
Definition: VtkWriter.hpp:210
CepsBool m_updateMesh
if the mesh data (geometry) must be updated
Definition: VtkWriter.hpp:215
void updateMeshData()
Global geometrical data regrouping.
Definition: VtkWriter.cpp:375
void writeVTU()
Write current state (Paraview xml pvtu & vtu file)
Definition: VtkWriter.cpp:255
vtkSmartPointer< vtkMPIController > m_vtkMpiController
vtk mpi controller
Definition: VtkWriter.hpp:226
void insertCell(GeomCell *cell)
Internal method which inserts one element as a cell in a unstructuredGrid vtk object.
Definition: VtkWriter.cpp:560
vtkSmartPointer< vtkUnstructuredGrid > m_unstructuredGrid
the vtk data wrapper
Definition: VtkWriter.hpp:218
CepsOutputFormat m_outputType
Output type.
Definition: VtkWriter.hpp:214
void insertElementData()
Add cell definition to VTK structures.
Definition: VtkWriter.cpp:483
void writeLegacyVTK()
Write current state (Paraview legacy vtk)
Definition: VtkWriter.cpp:276
CepsOutputFormat getOutputType() const
Get the output type.
Definition: VtkWriter.cpp:233
std::map< CepsUInt, CepsUInt > m_geomToVtkNodeIndex
mapping used for nodes
Definition: VtkWriter.hpp:220
vtkMPICommunicatorOpaqueComm m_opaqueCommVTK
a vtk object to create user defined MPI communicators
Definition: VtkWriter.hpp:225
void insertPointData()
Add coordinates to VTK structures, add array of global indices if needed.
Definition: VtkWriter.cpp:390
void write(CepsReal time=0., CepsBool writeXmlEntry=true)
Write all stored data.
Definition: VtkWriter.cpp:176
Geometry * m_geom
Direct link to geometry.
Definition: VtkWriter.hpp:205
CepsString getByeByeMessage()
Get string to be displayed at end of computation.
Definition: VtkWriter.cpp:217
VtkWriter()=delete
Deleted constructor.
void insertElementsOfDim(CepsUInt dim)
Internal method which for looping on all elements on a mesh of given dimension.
Definition: VtkWriter.cpp:550
CepsString getOuputExtension() const
Get the extension, deduced from CepsOutputFormat.
Definition: VtkWriter.cpp:239
void setOutputType(CepsOutputFormat flag)
Set the output type.
Definition: VtkWriter.cpp:227
vtkSmartPointer< vtkMPICommunicator > m_vtkMpiComm
a vtk wrapping object for the communicator
Definition: VtkWriter.hpp:224
void writeSeriesFile()
Write time series file for all time steps (Paraview pvtu.series)
Definition: VtkWriter.cpp:316
void writeDataArray()
Write current state (vtk_ceps format)
Definition: VtkWriter.cpp:291
CepsVector< CepsReal > m_writtenTimes
Previous times already written.
Definition: VtkWriter.hpp:206
void writeMetaDataSet()
Write time pvd file for all time steps (Paraview .pvd)
Definition: VtkWriter.cpp:345
CepsUInt m_internalIndex
Points counter.
Definition: VtkWriter.hpp:213
vtkCell * allocateCellOfDim(CepsUInt dim)
Internal method allocating a cell for a finite element (tetra,tri,...)
Definition: VtkWriter.cpp:580
std::map< CepsUInt, CepsUInt > m_geomToVtkCellIndex
mapping used for elements
Definition: VtkWriter.hpp:221
~VtkWriter() override
Destructor.
Definition: VtkWriter.cpp:89
CepsString m_baseName
base name of output files
Definition: VtkWriter.hpp:208
CepsBool m_writeGeomIndices
option to add array of CEPS point IDs
Definition: VtkWriter.hpp:216
CepsString m_outputDir
output directory
Definition: VtkWriter.hpp:211
AbstractDiscretization * m_discr
Discretization (dofs)
Definition: VtkWriter.hpp:204
CepsUInt m_outputNb
number of output file (not iteration)
Definition: VtkWriter.hpp:209
void addTimeFieldToUGrid(CepsReal time)
Adds a single scalar field to unstructred grid to write, called before writing.
Definition: VtkWriter.cpp:593