36 m_showGeometryPartitioning (false)
40 "Geometry passed to MeditGeometryWriter is nullptr"
74 m_file <<
"MeshVersionFormatted 2" << std::endl;
75 m_file <<
"Dimension" << std::endl <<
"3" << std::endl;
98 myCoords[3*nID ] = n->x();
99 myCoords[3*nID+1] = n->y();
100 myCoords[3*nID+2] = n->z();
105 myAttrs[nID] = *(n->getAttributes().begin());
110 MPI_Allreduce(myCoords.data(),coords.data(),nbNodes*3,
CEPS_MPI_REAL,MPI_SUM,comm);
111 MPI_Allreduce(myAttrs .data(),attrs .data(),nbNodes ,
CEPS_MPI_INT ,MPI_SUM,comm);
117 m_file << std::endl <<
"Vertices" << std::endl << nbNodes << std::endl;
118 std::stringstream toWrite (std::stringstream::out);
119 toWrite.unsetf (std::ios::floatfield);
120 toWrite.precision (15);
122 for (
CepsUInt i = 0; i < nbNodes; i++, counter++)
124 toWrite << coords[i*3 ] <<
" "
125 << coords[i*3+1] <<
" "
126 << coords[i*3+2] <<
" "
127 << attrs [i] << std::endl;
131 m_file.write(toWrite.str().c_str(),toWrite.str().length());
136 m_file.write(toWrite.str().c_str(),toWrite.str().length());
143 CepsBool surfacicCellsWritten =
false;
154 m_file << std::endl <<
"Tetrahedra" << std::endl << nCells << std::endl;
167 m_file <<
"Triangles" << std::endl << nCells << std::endl;
168 surfacicCellsWritten =
true;
179 m_file << std::endl <<
"Triangles" << std::endl << nCells << std::endl;
191 m_file <<
"Edges" << std::endl << nCells << std::endl;
192 cableCellsWritten =
true;
203 m_file << std::endl <<
"Edges" << std::endl << nCells << std::endl;
227 nbCellsArray[rank] = nbLocalCells;
235 sizeHint = cells[0]->getNumberOfNodes();
244 sizeHintArray[rank] = sizeHint;
249 for (
CepsUInt i = 1U; i < gridSize; i++)
250 if (sizeHintArray[i] >
max)
251 max = sizeHintArray[i];
255 cellNodeIndicesToSend.reserve (nbLocalCells*sizeHint);
256 cellAttrToSend .reserve (nbLocalCells);
257 cellIndicesToSend .reserve (nbLocalCells);
262 for (
CepsUInt i = 0U; i < size; i++)
264 nodeIndices.clear ();
268 cellNodeIndicesToSend.insert(cellNodeIndicesToSend.end(),
269 nodeIndices.begin(),nodeIndices.end());
279 int *cellIndicesToSendSizes =
new int[gridSize];
280 int localIndicesSize = (int) cellIndicesToSend.size ();
281 cellIndicesToSendSizes[rank] = localIndicesSize;
282 MPI_Gather(&localIndicesSize,1,MPI_INT,cellIndicesToSendSizes,1,MPI_INT,0,comm);
285 int *cellNodeIndicesToSendSizes =
new int[gridSize];
286 int localNodeIndicesSize = (int) cellNodeIndicesToSend.size ();
287 cellNodeIndicesToSendSizes[rank] = localNodeIndicesSize;
288 MPI_Gather(&localNodeIndicesSize,1,MPI_INT,cellNodeIndicesToSendSizes,1,MPI_INT,0,comm);
293 CepsUInt *cellNodeIndices =
nullptr;
295 CepsUInt cellIndicesTotalSize = 0, cellNodeIndicesTotalSize = 0;
298 for (
CepsUInt i = 0; i < gridSize; i++)
300 cellIndicesTotalSize += cellIndicesToSendSizes[i];
301 cellNodeIndicesTotalSize += cellNodeIndicesToSendSizes[i];
303 cellIndices =
new CepsUInt[cellIndicesTotalSize];
304 cellNodeIndices =
new CepsUInt[cellNodeIndicesTotalSize];
305 cellAttr =
new CepsInt[cellIndicesTotalSize];
312 int* displ =
new int[gridSize];
315 for (
CepsUInt i = 1; i < gridSize; i++)
316 displ[i] = displ[i-1] + cellIndicesToSendSizes[i-1];
318 MPI_Gatherv(cellIndicesToSend.data(),cellIndicesToSendSizes[rank],
CEPS_MPI_UINT,
319 cellIndices,cellIndicesToSendSizes,displ,
CEPS_MPI_UINT,0,comm);
322 MPI_Gatherv(cellAttrToSend.data(),cellIndicesToSendSizes[rank],
CEPS_MPI_INT,
323 cellAttr,cellIndicesToSendSizes,displ,
CEPS_MPI_INT,0,comm);
328 for (
CepsUInt i = 1; i < gridSize; i++)
329 displ[i] = displ[i-1] + cellNodeIndicesToSendSizes[i-1];
331 MPI_Gatherv(cellNodeIndicesToSend.data(),cellNodeIndicesToSendSizes[rank],
CEPS_MPI_UINT,
332 cellNodeIndices,cellNodeIndicesToSendSizes,displ,
CEPS_MPI_UINT,0,comm);
339 for (
CepsUInt i = 1; i <= gridSize; i++)
341 cellOffset[i] = cellOffset[i-1] + cellIndicesToSendSizes[i-1];
344 std::stringstream toWrite(std::stringstream::out);
345 std::set<CepsUInt> duplicates;
348 for (
CepsUInt j = 0; j < cellIndicesTotalSize; j++)
350 index = cellIndices[j];
351 if (duplicates.find (index) == duplicates.end ())
357 toWrite << nID+1 <<
" ";
364 toWrite << cellAttr[j] << std::endl;
366 duplicates.insert(index);
373 m_file.write(toWrite.str().c_str(),toWrite.str().length());
378 m_file.write(toWrite.str().c_str(),toWrite.str().length());
399 while(proc<gridSize and index>= cellOffset[proc+1])
#define CEPS_SAYS(message)
Writes a message in the debug log and in the terminal (stdio).
#define CEPS_ABORT_IF(condition, message)
Stops the execution with a message if condition is true. If testing is enabled, only throws a runtime...
#define CEPS_SEPARATOR
Writes a separator in the debug log and in the terminal.
std::basic_string< CepsChar > CepsString
C++ format string.
CepsGlobalIndex CepsCellGlobalIndex
Indices of cells.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
std::make_unsigned_t< CepsInt > CepsUInt
Unsigned version on CepsInt.
CepsGlobalIndex CepsNodeGlobalIndex
Indices of nodes.
int32_t CepsInt
Need 32 bit integer.
Enables the writing of files.
void open()
Creates file or cleans previous content.
CepsString m_fileName
file to write
std::ofstream m_file
corresponding stream
void close()
Close current file.
Abstract class for geometrical cell. On top of index and attributes managament, the cell has informat...
Base class for nodes used in meshes.
Encapsulates all the geometrical data.
CepsBool has1dMesh() const
true if geometry has 1d data
Mesh * get3dMesh() const
Pointer on the 3D mesh.
Mesh * get2dMesh() const
Pointer on the 2D mesh.
CepsBool has2dMesh() const
true if geometry has 2d data
CepsBool has3dMesh() const
true if geometry has 3d data
Mesh * get1dMesh() const
Pointer on the 1D mesh.
Mesh * getMeshOfDim(CepsUInt dim) const
Return the mesh of requested dimension.
CepsUInt getNbNodes() const
Number of nodes of the geometry (global)
CepsBool hasMeshOfDim(CepsUInt dim) const
true if geometry has data of requested dimension
CepsBool m_showGeometryPartitioning
Replaces attributes with owners rank.
void writeHeader()
Medit headers are written using this method.
void showGeometryPartitioning(CepsBool flag)
If true, cell attribute is replaced by owning process rank. (default is false)
CepsUInt determineCellOwner(CepsUInt *cellOffset, CepsUInt index)
Get index of owner of cell (owner of first node)
void writeCells()
Writes cells and boundary cells with attributes.
void writeCellsOf(Mesh *mesh, CepsBool boundary=false)
Gather and write the cells.
MeditGeometryWriter(const CepsString &fileName, Geometry *geom)
Constructor with ouput file name and linked geometry.
~MeditGeometryWriter()
Destructor.
void writeNodes()
Writes node coordinates and attribute.
Geometry * m_geom
Geometry to write.
Geometrical information of 1,2 or 3D distributed cells.
const CepsVector< GeomNode * > & getOwnedNodes()
CepsVector of local nodes stored on this process.
CepsUInt getNbBoundaryCells() const
Total number of boundary cells of the mesh.
CepsUInt getLocalNbCells() const
Number of non-boundary cells stored on this process.
const CepsVector< GeomCell * > & getCells()
CepsVector of cells stored on this process.
CepsUInt getNbCells() const
Total number of non-boundary cells of the mesh.
CepsUInt getLocalNbBoundaryCells() const
Number of boundary cells stored on this process.
const CepsVector< GeomCell * > & getBoundaryCells()
CepsVector of boundary cells stored on this process.
CepsSet< CepsAttribute > & getAttributes()
Returns the attributes of the entity.
const CepsGlobalIndex & getGlobalIndex() const
Get the index
CepsVector< CepsGlobalIndex > getNodeIndices() const
Get indices of all nodes.
CepsUInt getRank()
Returns current processor rank.
void destroyTabular(_Type &)
Destroy[delete] any type.
MPI_Comm getCommunicator()
Get the communicator.
const _Type & max(const CepsVector< _Type, _Alloc > &vec)
Returns the maximum of the vector, const version.
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 ?