25 #include "VTUGridWriterASCII.hpp"
34 m_vtkVertexMap =
nullptr;
49 m_vtkVertexMap = &vtkVertexMap;
62 assert(format == bitpit::VTKFormat::ASCII && m_patch !=
nullptr);
63 BITPIT_UNUSED(format);
65 if (name ==
"Points") {
66 auto &verts = m_patch->getVertices();
67 for (bitpit::PatchKernel::VertexConstIterator itr = m_patch->vertexConstBegin(); itr != m_patch->vertexConstEnd(); ++itr) {
68 std::size_t vertexRawId = itr.getRawIndex();
69 long vertexVTKId = m_vtkVertexMap->rawAt(vertexRawId);
70 if (vertexVTKId != bitpit::Vertex::NULL_ID) {
71 const bitpit::Vertex &vertex = verts.rawAt(vertexRawId);
72 bitpit::genericIO::flushASCII(stream, 3, vertex.getCoords());
75 }
else if (name ==
"offsets") {
77 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
78 offset += cell.getVertexCount();
79 bitpit::genericIO::flushASCII(stream, offset);
81 }
else if (name ==
"types") {
82 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
83 bitpit::VTKElementType VTKType;
84 switch (cell.getType()) {
86 case bitpit::ElementType::VERTEX:
87 VTKType = bitpit::VTKElementType::VERTEX;
90 case bitpit::ElementType::LINE:
91 VTKType = bitpit::VTKElementType::LINE;
94 case bitpit::ElementType::TRIANGLE:
95 VTKType = bitpit::VTKElementType::TRIANGLE;
98 case bitpit::ElementType::PIXEL:
99 VTKType = bitpit::VTKElementType::PIXEL;
102 case bitpit::ElementType::QUAD:
103 VTKType = bitpit::VTKElementType::QUAD;
106 case bitpit::ElementType::POLYGON:
107 VTKType = bitpit::VTKElementType::POLYGON;
110 case bitpit::ElementType::TETRA:
111 VTKType = bitpit::VTKElementType::TETRA;
114 case bitpit::ElementType::VOXEL:
115 VTKType = bitpit::VTKElementType::VOXEL;
118 case bitpit::ElementType::HEXAHEDRON:
119 VTKType = bitpit::VTKElementType::HEXAHEDRON;
122 case bitpit::ElementType::WEDGE:
123 VTKType = bitpit::VTKElementType::WEDGE;
126 case bitpit::ElementType::PYRAMID:
127 VTKType = bitpit::VTKElementType::PYRAMID;
130 case bitpit::ElementType::POLYHEDRON:
131 VTKType = bitpit::VTKElementType::POLYHEDRON;
135 VTKType = bitpit::VTKElementType::UNDEFINED;
140 bitpit::genericIO::flushASCII(stream, (
int) VTKType);
142 }
else if (name ==
"connectivity") {
143 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
144 bitpit::ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
145 const int nCellVertices = cell.getVertexCount();
146 for (
int k = 0; k < nCellVertices; ++k) {
147 long vertexId = cellVertexIds[k];
148 long vtkVertexId = m_vtkVertexMap->at(vertexId);
149 bitpit::genericIO::flushASCII(stream, vtkVertexId);
152 }
else if (name ==
"faces") {
153 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
154 if (cell.getDimension() <= 2 || cell.hasInfo()) {
155 bitpit::genericIO::flushASCII(stream, (
long) 0);
157 std::vector<long> faceStream = cell.getFaceStream();
158 bitpit::Cell::renumberFaceStream(*(m_vtkVertexMap), &faceStream);
159 int faceStreamSize = faceStream.size();
160 for (
int k = 0; k < faceStreamSize; ++k) {
161 bitpit::genericIO::flushASCII(stream, faceStream[k]);
165 }
else if (name ==
"faceoffsets") {
167 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
168 if (cell.getDimension() <= 2 || cell.hasInfo()) {
171 offset += cell.getFaceStreamSize();
174 bitpit::genericIO::flushASCII(stream, offset);
176 }
else if (name ==
"cellIndex") {
177 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
178 bitpit::genericIO::flushASCII(stream, cell.getId());
180 }
else if (name ==
"PID") {
181 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
182 bitpit::genericIO::flushASCII(stream, cell.getPID());
184 }
else if (name ==
"vertexIndex") {
185 for (bitpit::PatchKernel::VertexConstIterator itr = m_patch->vertexConstBegin(); itr != m_patch->vertexConstEnd(); ++itr) {
186 std::size_t vertexRawId = itr.getRawIndex();
187 long vertexVTKId = m_vtkVertexMap->rawAt(vertexRawId);
188 if (vertexVTKId != bitpit::Vertex::NULL_ID) {
189 std::size_t vertexId = itr.getId();
190 bitpit::genericIO::flushASCII(stream, vertexId);
195 #if MIMMO_ENABLE_MPI==1
196 }
else if (name ==
"cellGlobalIndex") {
197 bitpit::PatchNumberingInfo numberingInfo(m_patch);
198 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
199 bitpit::genericIO::flushASCII(stream, numberingInfo.getCellGlobalId(cell.getId()));
201 }
else if (name ==
"cellRank") {
202 for (
const bitpit::Cell &cell : m_patch->getVTKCellWriteRange()) {
203 bitpit::genericIO::flushASCII(stream, m_patch->getCellRank(cell.getId()));
205 }
else if (name ==
"vertexRank") {
206 for (bitpit::PatchKernel::VertexConstIterator itr = m_patch->vertexConstBegin(); itr != m_patch->vertexConstEnd(); ++itr) {
207 std::size_t vertexRawId = itr.getRawIndex();
208 long vertexVTKId = m_vtkVertexMap->rawAt(vertexRawId);
209 if (vertexVTKId != bitpit::Vertex::NULL_ID) {
210 bitpit::genericIO::flushASCII(stream, m_patch->getVertexRank(itr.getId()));
227 VTKUnstructuredGrid(eltype), m_patch(patch), m_streamer(streamer)
229 for(
auto & field : m_geometry){
231 field.setStreamer(streamer);
234 addData<long>(
"vertexIndex", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::POINT, &streamer);
235 addData<long>(
"cellIndex", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::CELL, &streamer);
236 addData<int>(
"PID", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::CELL, &streamer);
237 #if MIMMO_ENABLE_MPI==1
238 addData<long>(
"cellGlobalIndex", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::CELL, &streamer);
239 addData<int>(
"cellRank", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::CELL, &streamer);
240 addData<int>(
"vertexRank", bitpit::VTKFieldType::SCALAR, bitpit::VTKLocation::POINT, &streamer);
244 long vtkCellCount = 0;
245 if (m_patch.getVTKWriteTarget() == bitpit::PatchKernel::WriteTarget::WRITE_TARGET_CELLS_ALL) {
246 vtkCellCount = m_patch.getCellCount();
247 #if MIMMO_ENABLE_MPI==1
248 }
else if (m_patch.getVTKWriteTarget() == bitpit::PatchKernel::WriteTarget::WRITE_TARGET_CELLS_INTERNAL) {
249 vtkCellCount = m_patch.getInternalCellCount();
254 bitpit::PiercedStorage<long, long> vertexWriteFlag(1, &(m_patch.getVertices()));
255 vertexWriteFlag.fill(
false);
257 bool vtkFaceStreamNeeded =
false;
258 for (
const bitpit::Cell &cell : m_patch.getCells()) {
259 if (cell.getDimension() > 2 && !cell.hasInfo()) {
260 vtkFaceStreamNeeded =
true;
265 long vtkConnectSize = 0;
266 long vtkFaceStreamSize = 0;
267 for (
const bitpit::Cell &cell : m_patch.getVTKCellWriteRange()) {
268 bitpit::ConstProxyVector<long> cellVertexIds = cell.getVertexIds();
269 const int nCellVertices = cellVertexIds.size();
270 for (
int k = 0; k < nCellVertices; ++k) {
271 long vertexId = cellVertexIds[k];
272 vertexWriteFlag.at(vertexId) =
true;
275 vtkConnectSize += nCellVertices;
276 if (vtkFaceStreamNeeded) {
277 if (cell.getDimension() <= 2 || cell.hasInfo()) {
278 vtkFaceStreamSize += 1;
280 vtkFaceStreamSize += cell.getFaceStreamSize();
285 int vtkVertexCount = 0;
286 m_vtkVertexMap.unsetKernel(
true);
287 m_vtkVertexMap.setStaticKernel(&(m_patch.getVertices()));
288 for (bitpit::PatchKernel::VertexConstIterator itr = m_patch.vertexConstBegin(); itr != m_patch.vertexConstEnd(); ++itr) {
289 std::size_t vertexRawId = itr.getRawIndex();
290 if (vertexWriteFlag.rawAt(vertexRawId)) {
291 m_vtkVertexMap.rawAt(vertexRawId) = vtkVertexCount++;
293 m_vtkVertexMap.rawAt(vertexRawId) = bitpit::Vertex::NULL_ID;
297 setDimensions(vtkCellCount, vtkVertexCount, vtkConnectSize, vtkFaceStreamSize);
298 setCodex(bitpit::VTKFormat::ASCII);
302 if (m_patch.getProcessorCount() > 1) {
303 setParallel(m_patch.getProcessorCount(), m_patch.getRank());
323 VTKUnstructuredGrid::write(mode);