CEPS  24.01
Cardiac ElectroPhysiology Simulator
VtkWriter.cpp
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 #include "VtkWriter.hpp"
31 
32 #include <vtkDataObjectWriter.h>
33 #include <vtkDataSetToDataObjectFilter.h>
34 
37 
39  const CepsString& baseName,
40  CepsUInt nOutputs,
41  CepsOutputFormat outputType,
42  CepsBool writeGeomIndices) :
43  m_discr (discr),
44  m_writtenTimes ({}),
45  m_internalIndex (0),
46  m_outputType (CepsOutputFormat::ParaviewSeries),
47  m_updateMesh (true),
48  m_writeGeomIndices(writeGeomIndices),
49  m_unstructuredGrid()
50 {
51 
52  setOutputType(outputType);
53 
55  "Vtk writer: nullptr pointer to discretization passed"
56  );
57  m_geom = discr->getProblem()->getGeometry();
58 
59  // Creating a subdirectory where to put vtu and pvtu files
60  m_outputDir = ceps::getDir(baseName);
61  m_baseName = ceps::getBaseName(baseName);
62  m_outputNb = 0;
63  m_outputLgMax = static_cast<CepsUInt>(floor(log10(nOutputs))+1);
64  m_writtenTimes.reserve(nOutputs+1);
65 
66  CEPS_ABORT_IF(not ceps::isPathInOneWord(m_outputDir),
67  "Provided output directory is not a valid path name (do not forget \\ before spaces).\n"
68  << "Given path: \n " << m_outputDir
69  );
70 
71  m_unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
72 
73  // Tools to handle the writing of pvtu file on multiple processors
74  m_vtkMpiComm = vtkSmartPointer<vtkMPICommunicator>::New();
75  m_opaqueCommVTK = ceps::getPtrCommunicator();
76  m_vtkMpiComm->InitializeExternal(&m_opaqueCommVTK);
77 
79  m_vtkMpiController = vtkSmartPointer<vtkMPIController>::New();
80  m_vtkMpiController->SetCommunicator(m_vtkMpiComm);
81 
82  if (ceps::isMaster())
83  {
84  CepsString command = "mkdir -p " + m_outputDir + "/snapshots";
85  ceps::execute(command);
86  }
87 }
88 
90 {
91 }
92 
93 void
94 VtkWriter::addScalarData(const DHVecPtr& v, const CepsString &fieldName, Unknown* u)
95 {
98 }
99 
100 void
101 VtkWriter::addScalarData(const DHVecPtr& solution, const CepsVector<CepsString>& fieldNames,
102  const CepsVector<Unknown*>& us)
103 {
104  if (ceps::isProfiling())
105  getProfiler()->start("write","writing solution");
106 
107  // check if the mesh must be updated
108  if (m_updateMesh)
109  updateMeshData();
110 
111  CEPS_ABORT_IF(fieldNames.size()!=us.size(),
112  "Mismatch between number of field names and number of unknowns given to wtk writer"
113  );
114 
115  for (CepsUInt iu = 0u; iu<us.size(); iu++)
116  {
117 
118  Unknown* u = us[iu];
119 
120  // Few sanity checks
122  "Pointer to unknown passed to addScalar is null"
123  );
124 
125  // Get data for this unknown
126  CepsVector<CepsReal > data ;
127  CepsVector<CepsIndex> dataIndices;
128  CepsBool reduceOnMaster = isEnabledOption(m_outputType,CepsOutputFormat::VTKLegacy)
129  or isEnabledOption(m_outputType,CepsOutputFormat::VTKCeps);
131  u->getIdentifier(),solution,dataIndices,data,
132  reduceOnMaster,u->getLocation()!=CepsLocationFlag::ZeroD
133  );
134 
135  if (ceps::isMaster() or not reduceOnMaster) // For those who write
136  {
137  CepsLocationFlag loc = u->getLocation();
138  CepsUInt nToParse = data.size();
139 
140  // There may be additional nodes (P2) !
141  CepsUInt nToWrite = loc == CepsLocationFlag::ZeroD ? 1
143  : m_geom->getNbCells());
144 
145  vtkDoubleArray* scalars = vtkDoubleArray::New();
146  scalars->SetName(fieldNames[iu].c_str());
147  scalars->SetNumberOfTuples(nToWrite);
148  scalars->Fill(NAN);
149  for (CepsUInt i=0; i<nToParse; i++)
150  {
151  CepsIndex vtkId = loc == CepsLocationFlag::ZeroD ? 0
152  :( loc == CepsLocationFlag::Point ? m_geomToVtkNodeIndex.at(dataIndices[i])
153  : m_geomToVtkCellIndex.at(dataIndices[i]));
154  if (vtkId<CepsIndex(nToWrite))
155  scalars->SetTuple1(vtkId,data[i]);
156  }
157 
158  // this replaces any existing scalar field with the same name
159  if (loc==CepsLocationFlag::ZeroD)
160  m_unstructuredGrid->GetFieldData()->AddArray(scalars);
161  else if (loc == CepsLocationFlag::Point)
162  m_unstructuredGrid->GetPointData()->AddArray(scalars);
163  else
164  m_unstructuredGrid->GetCellData()->AddArray(scalars);
165  scalars->Delete();
166 
167  }
168 
169  }
170 
171  if (ceps::isProfiling ())
172  getProfiler ()->stop ("write");
173 }
174 
175 void
176 VtkWriter::write(CepsReal time, CepsBool writeXmlEntry)
177 {
178  // check if the mesh must be updated
180  "No data has been given to the writer with addScalarData"
181  );
182 
183  if (ceps::isProfiling())
184  getProfiler()->start("write");
185 
186  m_writtenTimes.push_back(time);
187  addTimeFieldToUGrid(time);
188 
189  // We suppose data has been regrouped and given to the master node.
190  if (isEnabledOption(m_outputType, CepsOutputFormat::Music))
191  {
192  if (ceps::isMaster())
193  {
194  writeLegacyVTK();
196  }
197  }
198  else if (isEnabledOption(m_outputType, CepsOutputFormat::ParaviewSeries))
199  {
200  writeVTU();
201  if (ceps::isMaster())
202  writeSeriesFile();
203  }
204  else if (isEnabledOption(m_outputType, CepsOutputFormat::VTKCeps))
205  {
206  if (ceps::isMaster())
207  writeDataArray();
208  }
209 
210  if (ceps::isProfiling())
211  getProfiler()->stop("write");
212 
213  m_outputNb++;
214 }
215 
218 {
219  CepsString ext = "";
220 
221  return "Results can be viewed by opening "
222  + m_outputDir + "/" + m_baseName
223  + getOuputExtension();
224 }
225 
226 void
228 {
229  m_outputType = flag;
230 }
231 
234 {
235  return m_outputType;
236 }
237 
238 CepsString
240 {
241  if (isEnabledOption(m_outputType, CepsOutputFormat::Music))
242  return ".xml";
243  else if (isEnabledOption(m_outputType, CepsOutputFormat::ParaviewSeries))
244  return ".pvtu.series";
245  else if (isEnabledOption(m_outputType, CepsOutputFormat::VTKCeps))
246  return".vtk_ceps";
247  return "";
248 }
249 
250 // -----------------------------------------------------------------------------------------------====
251 // Protected
252 // -----------------------------------------------------------------------------------------------====
253 
254 void
256 {
257  std::stringstream filename;
258  filename << m_outputDir << "/snapshots/" << m_baseName << "-" << std::setfill('0')
259  << std::setw (m_outputLgMax) << m_outputNb << ".pvtu";
260 
262  auto writer = vtkSmartPointer<vtkXMLPUnstructuredGridWriter>::New();
263  writer->SetDataModeToBinary();
264  writer->SetNumberOfPieces(ceps::getGridSize());
265  writer->SetStartPiece(ceps::getRank());
266  writer->SetEndPiece(ceps::getRank());
267  writer->SetCompressor(nullptr);
268  writer->SetInputData(m_unstructuredGrid);
269  writer->SetController(m_vtkMpiController);
270  writer->SetFileName(filename.str().c_str());
271  writer->Update();
272  writer->Write();
273 }
274 
275 void
277 {
278  std::stringstream filename;
279 
280  filename << m_outputDir << "/snapshots/" << m_baseName << "-" << std::setfill('0')
281  << std::setw(m_outputLgMax) << m_outputNb << ".vtk";
282 
283  auto writer = vtkSmartPointer<vtkUnstructuredGridWriter>::New();
284  writer->SetFileTypeToBinary();
285  writer->SetInputData(m_unstructuredGrid);
286  writer->SetFileName(filename.str().c_str());
287  writer->Write();
288 }
289 
290 void
292 {
293  std::stringstream filename;
294 
295  filename << m_outputDir << "/snapshots/" << m_baseName << "-" << std::setfill('0')
296  << std::setw(m_outputLgMax) << m_outputNb << ".vtk_ceps";
297 
298  auto fields = vtkSmartPointer<vtkDataSetToDataObjectFilter>::New();
299  fields->AddInputData(m_unstructuredGrid);
300  fields->CellDataOn();
301  fields->PointDataOn();
302  fields->FieldDataOn();
303  fields->GeometryOff();
304  fields->TopologyOff();
305 
306  // fields->AddInputDataObject(m_unstructuredGrid);
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());
312  writer->Write();
313 }
314 
315 void
317 {
318  CepsString series = m_outputDir + "/" + m_baseName + ".pvtu.series";
319  std::ofstream file(series, std::ofstream::trunc);
320  std::stringstream filename;
321 
322  file << "{" << std::endl;
323  file << " \"file-series-version\" : \"1.0\"," << std::endl;
324  file << " \"files\" : [" << std::endl;
325 
326  for (CepsUInt i = 0UL; i < m_writtenTimes.size(); ++i)
327  {
328  filename << "./snapshots/" << m_baseName << "-" << std::setfill('0')
329  << std::setw (m_outputLgMax) << i << ".pvtu";
330 
331  file << " { ";
332  file << "\"time\" : " << m_writtenTimes[i] << ", ";
333  file << "\"name\" : \"" << filename.str() << "\", ";
334  file << "}," << std::endl;
335 
336  filename.str("");
337  }
338 
339  file << " ]" << std::endl;
340  file << "}" << std::endl;
341  file.close();
342 }
343 
344 void
346 {
347  CepsString meta = m_outputDir + "/" + m_baseName + ".xml";
348  std::ofstream file(meta, std::ofstream::trunc);
349  std::stringstream filename;
350 
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;
355 
356  for (CepsUInt i = 0UL; i < m_writtenTimes.size(); ++i)
357  {
358  filename << "./snapshots/" << m_baseName << "-" << std::setfill('0')
359  << std::setw (m_outputLgMax) << i << ".vtk";
360 
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;
365 
366  filename.str("");
367  }
368 
369  file << " </vtkDataManager>" << std::endl;
370  file << "</VTKFile>" << std::endl;
371  file.close();
372 }
373 
374 void
376 {
377 
378  // Reset if needed
379  m_internalIndex = 0;
380  m_geomToVtkNodeIndex.clear();
381 
382  insertPointData();
384 
385  // Geometry data is up to date
386  m_updateMesh = false;
387 }
388 
389 void
391 {
392 
393  // Vtk array for points coordinates
394  vtkPoints* points = vtkPoints::New(VTK_DOUBLE);
395  points->GetData()->SetName("Vertex coordinates");
396 
397  // Number of nodes (all of them if writing legacy vtk)
398  CepsBool reduceOnMaster = isEnabledOption(m_outputType, CepsOutputFormat::Music)
399  or isEnabledOption(m_outputType, CepsOutputFormat::VTKCeps);
400  CepsUInt nToWrite = reduceOnMaster ? m_geom->getNbNodes() : m_geom->getNbNodesLocal();
401 
402  // Vtk array for global indices (after partitioning)
403  vtkIdTypeArray* globalIndices = vtkIdTypeArray::New();
404  if (m_writeGeomIndices)
405  {
406  globalIndices->SetName("globalIndices");
407  globalIndices->SetNumberOfComponents(1);
408  globalIndices->SetNumberOfTuples(nToWrite);
409  globalIndices->FillComponent(0,-1);
410  }
411 
412  // Now fill the arrays
413  if (reduceOnMaster)
414  {
415  // Write whole mesh in one fle : we follow the original ordering of the geometry,
416  // before partitioning
418 
419  for (CepsUInt i=0; i<nToWrite; i++)
420  {
421  CepsIndex gId = partMap[i];
422  // We build the reverse node partition mapping (for cells later on)
423  if (ceps::isMaster())
424  {
425  m_geomToVtkNodeIndex[gId] = i;
426  if (m_writeGeomIndices)
427  globalIndices->SetTuple1(i,gId);
428  }
429 
430  GeomNode* n = m_geom->getNode(gId,true); // Fetch only owned nodes
431  CepsVector<CepsReal> xyz(3,0.e0);
432 
433  if (ceps::isParallel())
434  {
435  // Send coordinates to everyone (incl master)
436  CepsVector<CepsReal> myxyz(3,0.e0);
437  if (ceps::isValidPtr(n))
438  for (CepsUInt j=0;j<3;j++)
439  myxyz[j] = n->getCoordinate(j);
440  MPI_Allreduce(myxyz.data(),xyz.data(),3,CEPS_MPI_REAL,MPI_SUM,ceps::getCommunicator());
441  }
442  else
443  // Just get coordinates
444  for (CepsUInt j=0;j<3;j++)
445  xyz[j] = n->getCoordinate(j);
446 
447  if (ceps::isMaster())
448  points->InsertNextPoint(xyz[0],xyz[1],xyz[2]);
449  }
450  }
451  else
452  {
453  // Write blocks.
454  // In each block, we follow the same order for nodes:
455  // 3D owned, 3D halo, 2D owned, 2D halo, 1D owned, 1D halo
456  // We build a map between geomID and vtkIndex in this block along the way
457  for (CepsUInt dim=3;dim>0;dim--)
458  if (m_geom->hasMeshOfDim(dim))
459  {
460  for (const CepsVector<GeomNode*>& nodeVector: {m_geom->getMeshOfDim(dim)->getOwnedNodes(),
461  m_geom->getMeshOfDim(dim)->getHaloNodes ()})
462  for (GeomNode* n : nodeVector)
463  {
464  m_geomToVtkNodeIndex[n->getGlobalIndex()] = m_internalIndex;
465  points->InsertNextPoint(n->x(),n->y(),n->z());
466  if (m_writeGeomIndices)
467  globalIndices->SetTuple1(m_internalIndex,n->getGlobalIndex());
468  m_internalIndex++;
469  }
470  }
471  }
472 
473  m_unstructuredGrid->SetPoints(points);
474  if (m_writeGeomIndices)
475  m_unstructuredGrid->GetPointData()->AddArray(globalIndices);
476 
477  points ->Delete();
478  globalIndices->Delete();
479 
480 }
481 
482 void
484 {
485  CepsBool reduceOnMaster = isEnabledOption(m_outputType, CepsOutputFormat::Music)
486  or isEnabledOption(m_outputType, CepsOutputFormat::VTKCeps);
487 
488  if (reduceOnMaster)
489  {
490  // We write the whole mesh, so we follow the original ordering of cells
491  CepsUInt nToWrite = m_geom->getNbCells();
493 
494  for (CepsUInt i=0; i<nToWrite; i++)
495  {
496  CepsIndex gId = partMap[i];
497  if (ceps::isMaster())
498  m_geomToVtkCellIndex[gId] = i;
499 
500  GeomCell* c = m_geom->getCell(gId);
501  // Get cell dimension
502  CepsUInt dim;
503  if (ceps::isParallel())
504  {
505  CepsUInt mydim = ceps::isValidPtr(c) ? c->getDimension() : 0u;
506  MPI_Allreduce(&mydim,&dim,1,CEPS_MPI_UINT,MPI_SUM,ceps::getCommunicator());
507  }
508  else
509  dim = c->getDimension();
510 
511  auto vtkCell = allocateCellOfDim(dim);
512 
513  // Get node IDs
514  vtkIdList *nodeIds = vtkCell->GetPointIds();
515  for (vtkIdType j=0; j<vtkCell->GetNumberOfPoints(); j++)
516  {
517  CepsIndex nodeId;
518  if (ceps::isParallel())
519  {
520  CepsIndex mynodeId = ceps::isValidPtr(c) ? c->getNodeAt(j)->getGlobalIndex() : 0u;
521  MPI_Allreduce(&mynodeId,&nodeId,1,CEPS_MPI_UINT,MPI_SUM,ceps::getCommunicator());
522  }
523  else
524  nodeId = c->getNodeAt(j)->getGlobalIndex();
525 
526  nodeId = m_geomToVtkNodeIndex[nodeId];
527  nodeIds->SetId(j,nodeId);
528  }
529 
530  m_unstructuredGrid->InsertNextCell(vtkCell->GetCellType(),nodeIds);
531  vtkCell->Delete();
532 
533  }
534 
535  }
536  else
537  {
538  // We write blocks, so we follow the order 3D, 2D, 1D of cells in the block
539  m_internalIndex = 0;
540  if (m_geom->has3dMesh())
542  if (m_geom->has2dMesh())
544  if (m_geom->has1dMesh())
546  }
547 }
548 
549 void
551 {
552  Mesh* m = m_geom->getMeshOfDim(dim);
553  for (GeomCell* cell : m->getCells())
554  insertCell(cell);
555  for (GeomCell* cell : m->getBoundaryCells())
556  insertCell(cell);
557 }
558 
559 void
561 {
562  auto vtkCell = allocateCellOfDim(cell->getDimension());
563  vtkIdList *nodeIds = vtkCell->GetPointIds();
564 
565  for (vtkIdType j=0; j<vtkCell->GetNumberOfPoints(); j++)
566  {
567  CepsIndex nodeId = cell->getNodeAt(j)->getGlobalIndex();
568  nodeId = m_geomToVtkNodeIndex[nodeId];
569  nodeIds->SetId(j,nodeId);
570  }
571 
573  m_internalIndex++;
574 
575  m_unstructuredGrid->InsertNextCell(vtkCell->GetCellType(),nodeIds);
576  vtkCell->Delete();
577 }
578 
579 vtkCell*
581 {
582  if (dim== 3U)
583  return vtkTetra::New();
584  else if (dim== 2U)
585  return vtkTriangle::New();
586  else if (dim== 1U)
587  return vtkLine::New();
588 
589  return vtkVertex::New();
590 }
591 
592 void
594 {
595  auto timef = vtkSmartPointer<vtkDoubleArray>::New();
596  timef->SetNumberOfValues(1);
597  timef->SetValue(0,time);
598  timef->SetName("TIME_STEP");
599  m_unstructuredGrid->GetFieldData()->AddArray(timef);
600 }
CepsLocationFlag
DataLocation: an enum that will be used by various elements of the code (pde, readers,...
Definition: CepsEnums.hpp:108
@ Point
Data is defined on each point.
@ ZeroD
Data is defined once.
CepsOutputFormat
Style of output files.
Definition: CepsEnums.hpp:179
@ 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.
Definition: CepsTypes.hpp:128
std::vector< _Type, _Alloc > CepsVector
C++ vector.
Definition: CepsTypes.hpp:155
bool CepsBool
Booleans.
Definition: CepsTypes.hpp:124
#define CEPS_MPI_REAL
Definition: CepsTypes.hpp:315
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
#define CEPS_MPI_UINT
Definition: CepsTypes.hpp:325
CepsInt CepsIndex
Index rowid etc.
Definition: CepsTypes.hpp:111
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.
Definition: CepsObject.cpp:46
CepsReal & getCoordinate(const CepsSize &dim)
Get coordinate of dimension 0 1 2, read & write.
Definition: CepsVertex.cpp:144
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Definition: GeomCell.hpp:48
Base class for nodes used in meshes.
Definition: GeomNode.hpp:53
CepsBool has1dMesh() const
true if geometry has 1d data
Definition: Geometry.cpp:188
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.
Definition: Geometry.cpp:459
const CepsVector< CepsNodeGlobalIndex > & getNodePartitionMap()
The node index map from before to after partitioning.
Definition: Geometry.cpp:643
CepsBool has2dMesh() const
true if geometry has 2d data
Definition: Geometry.cpp:182
CepsBool has3dMesh() const
true if geometry has 3d data
Definition: Geometry.cpp:176
CepsUInt getNbNodesLocal() const
Number of nodes local to this process, with halo nodes.
Definition: Geometry.cpp:416
Mesh * getMeshOfDim(CepsUInt dim) const
Return the mesh of requested dimension.
Definition: Geometry.cpp:139
CepsUInt getNbNodes() const
Number of nodes of the geometry (global)
Definition: Geometry.cpp:383
GeomCell * getCell(CepsCellGlobalIndex globalID)
Returns a pointer to the cell with given global ID. Nullptr if cell is not owned.
Definition: Geometry.cpp:478
CepsBool hasMeshOfDim(CepsUInt dim) const
true if geometry has data of requested dimension
Definition: Geometry.cpp:167
const CepsVector< CepsCellGlobalIndex > & getCellPartitionMap()
The node index map from before to after partitioning.
Definition: Geometry.cpp:649
CepsUInt getNbCells() const
Number of non-boundary cells of the geometry (global).
Definition: Geometry.cpp:371
Geometrical information of 1,2 or 3D distributed cells.
Definition: Mesh.hpp:57
const CepsVector< GeomCell * > & getCells()
CepsVector of cells stored on this process.
Definition: Mesh.cpp:204
const CepsVector< GeomNode * > & getHaloNodes()
CepsVector of halo nodes stored on this process.
Definition: Mesh.cpp:222
const CepsVector< GeomCell * > & getBoundaryCells()
CepsVector of boundary cells stored on this process.
Definition: Mesh.cpp:210
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,...
Definition: Unknown.hpp:45
const CepsLocationFlag & getLocation() const
Get the data location of the unknown.
Definition: Unknown.cpp:101
CepsUnknownIndex getIdentifier() const
Get the identifier of the unknown.
Definition: Unknown.cpp:82
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
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
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
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....
Definition: CepsString.cpp:521
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.
Definition: CepsMemory.hpp:61
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.
Definition: CepsMemory.hpp:45
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....
Definition: CepsString.cpp:563
CepsBool isProfiling()
Check if we are currently profiling on the master proc (always false on slave procs).
Definition: CepsFlags.cpp:257
CepsBool isPathInOneWord(const CepsString &s)
Checks if given path is in one word (it may not exist yet)
Definition: CepsString.cpp:144