ViennaLS
Loading...
Searching...
No Matches
lsVTKReader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fstream>
4#include <string>
5#include <unordered_map>
6
7#include <lsFileFormats.hpp>
8#include <lsMesh.hpp>
9
10#include <utility>
11#include <vcLogger.hpp>
12#include <vcSmartPointer.hpp>
13
14#ifdef VIENNALS_USE_VTK
15#include <vtkCellData.h>
16#include <vtkIdList.h>
17#include <vtkPointData.h>
18#include <vtkPolyData.h>
19#include <vtkSmartPointer.h>
20#include <vtkUnstructuredGrid.h>
21#include <vtkXMLPolyDataReader.h>
22#include <vtkXMLUnstructuredGridReader.h>
23#endif // VIENNALS_USE_VTK
24
25namespace viennals {
26
27using namespace viennacore;
28
30template <class T = double> class VTKReader {
31 SmartPointer<Mesh<T>> mesh = nullptr;
33 std::string fileName;
34 std::unordered_map<std::string, std::vector<double>> metaData;
35
36#ifdef VIENNALS_USE_VTK
37 // For memory-based reading
38 vtkPolyData *inputPolyData = nullptr;
39 vtkUnstructuredGrid *inputUnstructuredGrid = nullptr;
40#endif
41
42 unsigned vtk_nodes_for_cell_type[15] = {0, 1, 0, 2, 0, 3, 0, 0,
43 4, 4, 4, 8, 8, 6, 5};
44
45 // accepts either vtkPolyData or vtkUnstructuredGrid
46 void extractFieldData(vtkDataSet *data) {
47 vtkFieldData *fieldData = data->GetFieldData();
48 if (!fieldData)
49 return;
50
51 for (int i = 0; i < fieldData->GetNumberOfArrays(); ++i) {
52 vtkDataArray *array = fieldData->GetArray(i);
53 if (!array)
54 continue;
55
56 const char *name = array->GetName();
57 if (!name)
58 continue;
59
60 int numTuples = array->GetNumberOfTuples();
61 int numComponents = array->GetNumberOfComponents();
62
63 std::vector<T> values;
64 values.reserve(numTuples * numComponents);
65
66 for (int t = 0; t < numTuples; ++t) {
67 T tuple[9]; // safe default (up to 9 components)
68 array->GetTuple(t, tuple);
69 for (int c = 0; c < numComponents; ++c)
70 values.push_back(tuple[c]);
71 }
72
73 metaData[name] = std::move(values);
74 }
75 }
76
77public:
78 VTKReader() = default;
79
80 VTKReader(SmartPointer<Mesh<T>> passedMesh) : mesh(passedMesh) {}
81
82 VTKReader(SmartPointer<Mesh<T>> passedMesh, std::string passedFileName)
83 : mesh(passedMesh), fileName(std::move(passedFileName)) {}
84
85 VTKReader(SmartPointer<Mesh<>> passedMesh, FileFormatEnum passedFormat,
86 std::string passedFileName)
87 : mesh(passedMesh), fileFormat(passedFormat),
88 fileName(std::move(passedFileName)) {}
89
90#ifdef VIENNALS_USE_VTK
92 VTKReader(SmartPointer<Mesh<T>> passedMesh, vtkPolyData *polyData)
93 : mesh(passedMesh), inputPolyData(polyData) {
94 fileFormat = FileFormatEnum::VTP;
95 }
96
98 VTKReader(SmartPointer<Mesh<T>> passedMesh,
99 vtkUnstructuredGrid *unstructuredGrid)
100 : mesh(passedMesh), inputUnstructuredGrid(unstructuredGrid) {
101 fileFormat = FileFormatEnum::VTU;
102 }
103#endif
104
106 void setMesh(SmartPointer<Mesh<>> passedMesh) { mesh = passedMesh; }
107
109 void setFileFormat(FileFormatEnum passedFormat) { fileFormat = passedFormat; }
110
112 void setFileName(std::string passedFileName) {
113 fileName = std::move(passedFileName);
114 }
115
116#ifdef VIENNALS_USE_VTK
118 void setPolyData(vtkPolyData *polyData) {
119 inputPolyData = polyData;
120 inputUnstructuredGrid = nullptr;
121 fileFormat = FileFormatEnum::VTP;
122 fileName.clear();
123 }
124
126 void setUnstructuredGrid(vtkUnstructuredGrid *unstructuredGrid) {
127 inputUnstructuredGrid = unstructuredGrid;
128 inputPolyData = nullptr;
129 fileFormat = FileFormatEnum::VTU;
130 fileName.clear();
131 }
132#endif
133
134 auto &getMetaData() { return metaData; }
135
136 void apply() {
137 // check mesh
138 if (mesh == nullptr) {
139 Logger::getInstance()
140 .addError("No mesh was passed to VTKReader.")
141 .print();
142 return;
143 }
144
145#ifdef VIENNALS_USE_VTK
146 // Check if we're reading from memory
147 if (inputPolyData != nullptr) {
148 buildFromPolyData(inputPolyData);
149 return;
150 }
151
152 if (inputUnstructuredGrid != nullptr) {
153 buildFromUnstructuredGrid(inputUnstructuredGrid);
154 return;
155 }
156#endif
157
158 // check filename
159 if (fileName.empty()) {
160 Logger::getInstance()
161 .addError("No file name specified for VTKReader.")
162 .print();
163 return;
164 }
165
166 if (fileFormat == FileFormatEnum::VTK_AUTO) {
167 auto dotPos = fileName.rfind('.');
168 if (dotPos == std::string::npos) {
169 Logger::getInstance()
170 .addError("No valid file format found based on the file ending "
171 "passed to VTKReader.")
172 .print();
173 return;
174 }
175 auto ending = fileName.substr(dotPos);
176 if (ending == ".vtk") {
177 fileFormat = FileFormatEnum::VTK_LEGACY;
178 } else if (ending == ".vtp") {
179 fileFormat = FileFormatEnum::VTP;
180 } else if (ending == ".vtu") {
181 fileFormat = FileFormatEnum::VTU;
182 } else {
183 Logger::getInstance()
184 .addError("No valid file format found based on the file ending "
185 "passed to VTKReader.")
186 .print();
187 return;
188 }
189 }
190
191 // check file format
192 switch (fileFormat) {
194 readVTKLegacy(fileName);
195 break;
196#ifdef VIENNALS_USE_VTK
198 readVTP(fileName);
199 break;
201 readVTU(fileName);
202 break;
203#else
206 Logger::getInstance()
207 .addError("VTKReader was built without VTK support. Only VTK_LEGACY "
208 "can be used.")
209 .print();
210#endif
211 default:
212 Logger::getInstance()
213 .addError("No valid file format set for VTKReader.")
214 .print();
215 }
216 }
217
218private:
219#ifdef VIENNALS_USE_VTK
221 void buildFromPolyData(vtkPolyData *polyData) {
222 if (!polyData) {
223 Logger::getInstance()
224 .addError("Null vtkPolyData passed to VTKReader.")
225 .print();
226 return;
227 }
228
229 mesh->clear();
230
231 mesh->nodes.resize(polyData->GetNumberOfPoints());
232 for (unsigned i = 0; i < mesh->nodes.size(); ++i) {
233 std::array<double, 3> coords{};
234 polyData->GetPoint(i, coords.data());
235 mesh->nodes[i] = coords;
236 }
237
238 vtkSmartPointer<vtkCellArray> cellArray =
239 vtkSmartPointer<vtkCellArray>::New();
240 // get vertices
241 {
242 mesh->vertices.reserve(polyData->GetNumberOfVerts());
243 cellArray = polyData->GetVerts();
244 cellArray->InitTraversal();
245 vtkIdList *pointList = vtkIdList::New();
246 while (cellArray->GetNextCell(pointList)) {
247 std::array<unsigned, 1> cell{};
248 cell[0] = pointList->GetId(0);
249 mesh->vertices.push_back(cell);
250 }
251 }
252
253 // get lines
254 {
255 mesh->lines.reserve(polyData->GetNumberOfLines());
256 cellArray = polyData->GetLines();
257 cellArray->InitTraversal();
258 vtkIdList *pointList = vtkIdList::New();
259 while (cellArray->GetNextCell(pointList)) {
260 std::array<unsigned, 2> cell{};
261 for (unsigned i = 0; i < 2; ++i) {
262 cell[i] = pointList->GetId(i);
263 }
264 mesh->lines.push_back(cell);
265 }
266 }
267
268 // get triangles
269 {
270 mesh->triangles.reserve(polyData->GetNumberOfPolys());
271 cellArray = polyData->GetPolys();
272 cellArray->InitTraversal();
273 vtkIdList *pointList = vtkIdList::New();
274 while (cellArray->GetNextCell(pointList)) {
275 std::array<unsigned, 3> cell{};
276 for (unsigned i = 0; i < 3; ++i) {
277 cell[i] = pointList->GetId(i);
278 }
279 mesh->triangles.push_back(cell);
280 }
281 }
282
283 // get point data
284 vtkSmartPointer<vtkPointData> pointData =
285 vtkSmartPointer<vtkPointData>::New();
286 pointData = polyData->GetPointData();
287
288 for (int i = 0; i < static_cast<int>(pointData->GetNumberOfArrays()); ++i) {
289 if (vtkDataArray *dataArray = pointData->GetArray(i);
290 dataArray->GetNumberOfComponents() == 1) {
291 mesh->pointData.insertNextScalarData(
292 typename PointData<T>::ScalarDataType(),
293 std::string(pointData->GetArrayName(i)));
294 auto &scalars = *(mesh->pointData.getScalarData(i));
295 scalars.resize(pointData->GetNumberOfTuples());
296 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
297 scalars[j] = dataArray->GetTuple1(j);
298 }
299 } else if (dataArray->GetNumberOfComponents() == 3) {
300 mesh->pointData.insertNextVectorData(
301 typename PointData<T>::VectorDataType(),
302 std::string(pointData->GetArrayName(i)));
303 auto &vectors = *(mesh->pointData.getVectorData(i));
304 vectors.resize(pointData->GetNumberOfTuples());
305 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
306 std::array<double, 3> vector{};
307 dataArray->GetTuple(j, &(vector[0]));
308 vectors[j] = vector;
309 }
310 }
311 }
312
313 // get cell data
314 vtkSmartPointer<vtkCellData> cellData = vtkSmartPointer<vtkCellData>::New();
315 cellData = polyData->GetCellData();
316
317 for (int i = 0; i < cellData->GetNumberOfArrays(); ++i) {
318 vtkDataArray *dataArray = cellData->GetArray(i);
319 if (cellData->GetNumberOfComponents() == 1) {
320 mesh->cellData.insertNextScalarData(
321 typename PointData<T>::ScalarDataType(),
322 std::string(cellData->GetArrayName(i)));
323 auto &scalars = *(mesh->cellData.getScalarData(i));
324 scalars.resize(cellData->GetNumberOfTuples());
325 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
326 scalars[j] = dataArray->GetTuple1(j);
327 }
328 } else if (cellData->GetNumberOfComponents() == 3) {
329 mesh->cellData.insertNextVectorData(
330 typename PointData<T>::VectorDataType(),
331 std::string(cellData->GetArrayName(i)));
332 auto &vectors = *(mesh->cellData.getVectorData(i));
333 vectors.resize(cellData->GetNumberOfTuples());
334 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
335 std::array<double, 3> vector{};
336 dataArray->GetTuple(j, &(vector[0]));
337 vectors[j] = vector;
338 }
339 }
340 }
341
342 // read meta data
343 extractFieldData(polyData);
344 }
345
346 void readVTP(const std::string &filename) {
347
348 mesh->clear();
349 vtkSmartPointer<vtkXMLPolyDataReader> pReader =
350 vtkSmartPointer<vtkXMLPolyDataReader>::New();
351 pReader->SetFileName(filename.c_str());
352 pReader->Update();
353
354 vtkSmartPointer<vtkPolyData> polyData = pReader->GetOutput();
355 buildFromPolyData(polyData);
356 }
357
359 void buildFromUnstructuredGrid(vtkUnstructuredGrid *ugrid) {
360 if (!ugrid) {
361 Logger::getInstance()
362 .addError("Null vtkUnstructuredGrid passed to VTKReader.")
363 .print();
364 return;
365 }
366
367 mesh->clear();
368
369 // get all points
370 mesh->nodes.resize(ugrid->GetNumberOfPoints());
371 for (unsigned i = 0; i < mesh->nodes.size(); ++i) {
372 std::array<double, 3> coords{};
373 ugrid->GetPoint(i, &(coords[0]));
374 mesh->nodes[i] = coords;
375 }
376
377 // get cells
378 for (unsigned i = 0; i < ugrid->GetNumberOfCells(); ++i) {
379 vtkIdList *pointList = vtkIdList::New();
380 ugrid->GetCellPoints(i, pointList);
381
382 switch (ugrid->GetCellType(i)) {
383 case 1: // vert
384 {
385 std::array<unsigned, 1> vert{};
386 vert[0] = pointList->GetId(0);
387 mesh->vertices.push_back(vert);
388 } break;
389 case 3: // line
390 {
391 std::array<unsigned, 2> elements{};
392 for (unsigned j = 0; j < 2; ++j) {
393 elements[j] = pointList->GetId(j);
394 }
395 mesh->lines.push_back(elements);
396 } break;
397 case 5: // triangle
398 {
399 std::array<unsigned, 3> elements{};
400 for (unsigned j = 0; j < 3; ++j) {
401 elements[j] = pointList->GetId(j);
402 }
403 mesh->triangles.push_back(elements);
404 } break;
405 case 10: // tetra
406 {
407 std::array<unsigned, 4> elements{};
408 for (unsigned j = 0; j < 4; ++j) {
409 elements[j] = pointList->GetId(j);
410 }
411 mesh->tetras.push_back(elements);
412 } break;
413 case 12: // hexa
414 {
415 std::array<unsigned, 8> elements{};
416 for (unsigned j = 0; j < 8; ++j) {
417 elements[j] = pointList->GetId(j);
418 }
419 mesh->hexas.push_back(elements);
420 } break;
421 }
422 }
423
424 // get point data
425 vtkSmartPointer<vtkPointData> pointData =
426 vtkSmartPointer<vtkPointData>::New();
427 pointData = ugrid->GetPointData();
428
429 for (int i = 0; i < pointData->GetNumberOfArrays(); ++i) {
430 if (vtkDataArray *dataArray = pointData->GetArray(i);
431 dataArray->GetNumberOfComponents() == 1) {
432 mesh->pointData.insertNextScalarData(
433 typename PointData<T>::ScalarDataType(),
434 std::string(pointData->GetArrayName(i)));
435 auto &scalars = *(mesh->pointData.getScalarData(i));
436 scalars.resize(pointData->GetNumberOfTuples());
437 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
438 scalars[j] = dataArray->GetTuple1(j);
439 }
440 } else if (dataArray->GetNumberOfComponents() == 3) {
441 mesh->pointData.insertNextVectorData(
442 typename PointData<T>::VectorDataType(),
443 std::string(pointData->GetArrayName(i)));
444 auto &vectors = *(mesh->pointData.getVectorData(i));
445 vectors.resize(pointData->GetNumberOfTuples());
446 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
447 std::array<double, 3> vector{};
448 dataArray->GetTuple(j, &(vector[0]));
449 vectors[j] = vector;
450 }
451 }
452 }
453
454 // get cell data
455 vtkSmartPointer<vtkCellData> cellData = vtkSmartPointer<vtkCellData>::New();
456 cellData = ugrid->GetCellData();
457
458 for (int i = 0; i < static_cast<int>(cellData->GetNumberOfArrays()); ++i) {
459 vtkDataArray *dataArray = cellData->GetArray(i);
460 if (cellData->GetNumberOfComponents() == 1) {
461 mesh->cellData.insertNextScalarData(
462 typename PointData<T>::ScalarDataType(),
463 std::string(cellData->GetArrayName(i)));
464 auto &scalars = *(mesh->cellData.getScalarData(i));
465 scalars.resize(cellData->GetNumberOfTuples());
466 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
467 scalars[j] = dataArray->GetTuple1(j);
468 }
469 } else if (cellData->GetNumberOfComponents() == 3) {
470 mesh->cellData.insertNextVectorData(
471 typename PointData<T>::VectorDataType(),
472 std::string(cellData->GetArrayName(i)));
473 auto &vectors = *(mesh->cellData.getVectorData(i));
474 vectors.resize(cellData->GetNumberOfTuples());
475 for (unsigned j = 0; j < dataArray->GetNumberOfTuples(); ++j) {
476 std::array<double, 3> vector{};
477 dataArray->GetTuple(j, &(vector[0]));
478 vectors[j] = vector;
479 }
480 }
481 }
482
483 // read meta data
484 extractFieldData(ugrid);
485 }
486
487 void readVTU(const std::string &filename) {
488
489 mesh->clear();
490
491 vtkSmartPointer<vtkXMLUnstructuredGridReader> greader =
492 vtkSmartPointer<vtkXMLUnstructuredGridReader>::New();
493 greader->SetFileName(filename.c_str());
494 greader->Update();
495
496 vtkSmartPointer<vtkUnstructuredGrid> ugrid = greader->GetOutput();
497 buildFromUnstructuredGrid(ugrid);
498 }
499
500#endif // VIENNALS_USE_VTK
501
502 void readVTKLegacy(const std::string &filename) {
503
504 mesh->clear();
505 // open geometry file
506 std::ifstream f(filename.c_str());
507 if (!f)
508 Logger::getInstance().addError("Could not open geometry file!");
509 std::string temp;
510
511 // Check if geometry is an unstructured grid as required
512 while (std::getline(f, temp)) {
513 if (temp.find("DATASET") != std::string::npos)
514 break;
515 }
516 if (temp.find("UNSTRUCTURED_GRID") == std::string::npos) {
517 Logger::getInstance().addError("DATASET is not an UNSTRUCTURED_GRID!");
518 }
519
520 // Find POINTS in file to know number of nodes to read in
521 while (std::getline(f, temp)) {
522 if (temp.find("POINTS") != std::string::npos)
523 break;
524 }
525 int num_nodes = atoi(&temp[temp.find(' ') + 1]);
526
527 mesh->nodes.resize(num_nodes);
528
529 for (int i = 0; i < num_nodes; i++) {
530 double coords[3];
531
532 for (double &coord : coords)
533 f >> coord;
534 for (int j = 0; j < 3; j++) {
535 mesh->nodes[i][j] = coords[j];
536 // int shift_size = shift.size();
537 // if (shift_size > j)
538 // mesh->nodes[i][j] += shift[j]; // Assign desired shift
539 // if (InputTransformationSigns[j])
540 // mesh->nodes[i][j] = -mesh->nodes[i][j]; // Assign sign
541 // transformation, if needed
542 // mesh->nodes[i][j] *= scale; // Scale the geometry according to
543 // parameters file
544 }
545 }
546
547 while (std::getline(f, temp)) {
548 if (temp.find("CELLS") == 0)
549 break;
550 }
551
552 int num_elems = atoi(&temp[temp.find(' ') + 1]);
553
554 std::ifstream f_ct(filename.c_str()); // stream to read cell CELL_TYPES
555 std::ifstream f_m(
556 filename.c_str()); // stream for material numbers if they exist
557
558 // advance to cell types and check if there are the right number
559 while (std::getline(f_ct, temp)) {
560 if (temp.find("CELL_TYPES") == 0)
561 break;
562 }
563 int num_cell_types = atoi(&temp[temp.find(' ') + 1]);
564 // need a cell_type for each cell
565 if (num_elems != num_cell_types) {
566 Logger::getInstance().addError(
567 "Corrupt input geometry! Number of CELLS and CELL_TYPES "
568 "is different!");
569 }
570
571 bool is_material = true;
572 // advance to material if it is specified
573 while (std::getline(f_m, temp)) {
574 if (temp.find("CELL_DATA") != std::string::npos) {
575 std::getline(f_m, temp);
576 if ((temp.find("SCALARS material") != std::string::npos) ||
577 (temp.find("SCALARS Material") != std::string::npos)) {
578 std::getline(f_m, temp);
579 break;
580 }
581 }
582 }
583 if (f_m.eof()) {
584 is_material = false;
585 }
586
587 // maximum cell to read in is a tetra with 4 points
588 std::vector<VectorType<unsigned int, 4>> elements;
589 elements.reserve(num_elems);
590
591 std::vector<double> materials;
592
593 unsigned elems_fake;
594 unsigned cell_type;
595 unsigned cell_material;
596 for (int i = 0; i < num_elems; i++) {
597 f >> elems_fake;
598 f_ct >> cell_type;
599 if (is_material)
600 f_m >> cell_material;
601 else
602 cell_material =
603 1; // if there are no materials specified make all the same
604
605 // check if the correct number of nodes for cell_type is given
606 unsigned number_nodes = vtk_nodes_for_cell_type[cell_type];
607 if (number_nodes == elems_fake || number_nodes == 0) {
608 // check for different types to subdivide them into supported types
609 switch (cell_type) {
610 case 1: {
611 std::array<unsigned, 1> elem{};
612 f >> elem[0];
613 mesh->template getElements<1>().push_back(elem);
614 materials.push_back(cell_material);
615 break;
616 }
617 case 3: {
618 std::array<unsigned, 2> elem{};
619 for (unsigned j = 0; j < number_nodes; ++j) {
620 f >> elem[j];
621 }
622 mesh->template getElements<2>().push_back(elem);
623 materials.push_back(cell_material);
624 break;
625 }
626 case 5: // triangle for 2D
627 {
628 std::array<unsigned, 3> elem{};
629 for (unsigned j = 0; j < number_nodes; ++j) {
630 f >> elem[j];
631 }
632 mesh->template getElements<3>().push_back(elem);
633 materials.push_back(cell_material);
634 break;
635 }
636
637 case 10: // tetra for 3D
638 {
639 std::array<unsigned, 4> elem{};
640 for (unsigned j = 0; j < number_nodes; ++j) {
641 f >> elem[j];
642 }
643 mesh->template getElements<4>().push_back(elem);
644 materials.push_back(cell_material);
645 break;
646 }
647
648 case 9: // this is a quad, so just plit it into two triangles
649 {
650 std::array<unsigned, 3> elem{};
651 for (unsigned j = 0; j < 3; ++j) {
652 f >> elem[j];
653 }
654 mesh->template getElements<3>().push_back(
655 elem); // push the first three nodes as a triangle
656 materials.push_back(cell_material);
657
658 f >> elem[1]; // replace middle element to create other triangle
659 mesh->template getElements<3>().push_back(elem);
660 materials.push_back(cell_material);
661 break;
662 }
663
664 default:
665 std::ostringstream oss;
666 oss << "VTK Cell type " << cell_type
667 << " is not supported. Cell ignored..." << std::endl;
668 VIENNACORE_LOG_WARNING(oss.str());
669 }
670 } else {
671 std::ostringstream oss;
672 oss << "INVALID CELL TYPE! Expected number of nodes: " << number_nodes
673 << ", Found number of nodes: " << elems_fake
674 << "; Ignoring element...";
675 VIENNACORE_LOG_ERROR(oss.str());
676 // ignore rest of lines
677 f.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
678 }
679 }
680
681 mesh->cellData.insertNextScalarData(materials, "Material");
682
683 // Now read Cell Data
684 int num_cell_data = 0;
685 while (std::getline(f, temp)) {
686 if (temp.find("CELL_DATA") != std::string::npos) {
687 num_cell_data = atoi(&temp[temp.find(' ') + 1]);
688 break;
689 }
690 }
691 std::cout << "Read cell data: " << num_cell_data << std::endl;
692
693 while (!f.eof()) {
694 std::cout << "reading scalar data" << std::endl;
695 while (std::getline(f, temp)) {
696 if (temp.find("SCALARS") != std::string::npos)
697 break;
698 }
699 if (f.eof()) {
700 break;
701 }
702
703 std::string scalarDataName;
704 {
705 auto firstS = temp.find(' ') + 1;
706 auto secondS = temp.find(' ', firstS + 1);
707 scalarDataName = temp.substr(firstS, secondS - firstS);
708 }
709 std::vector<double> scalarData;
710
711 // consume one line, which defines the lookup table
712 std::getline(f, temp);
713 if (temp != "LOOKUP_TABLE default") {
714 VIENNACORE_LOG_WARNING("Wrong lookup table for VTKLegacy: " + temp);
715 }
716
717 // now read scalar values
718 for (int i = 0; i < num_cell_data; ++i) {
719 double data;
720 f >> data;
721 scalarData.push_back(data);
722 }
723
724 mesh->cellData.insertNextScalarData(scalarData, scalarDataName);
725 }
726
727 f_ct.close();
728 f_m.close();
729 f.close();
730 }
731};
732
733} // namespace viennals
double T
Definition Epitaxy.cpp:13
This class holds an explicit mesh, which is always given in 3 dimensions. If it describes a 2D mesh,...
Definition lsMesh.hpp:21
void setFileName(std::string passedFileName)
set file name for file to read
Definition lsVTKReader.hpp:112
void setMesh(SmartPointer< Mesh<> > passedMesh)
set the mesh the file should be read into
Definition lsVTKReader.hpp:106
VTKReader(SmartPointer< Mesh< T > > passedMesh, std::string passedFileName)
Definition lsVTKReader.hpp:82
VTKReader(SmartPointer< Mesh< T > > passedMesh)
Definition lsVTKReader.hpp:80
VTKReader(SmartPointer< Mesh<> > passedMesh, FileFormatEnum passedFormat, std::string passedFileName)
Definition lsVTKReader.hpp:85
void setFileFormat(FileFormatEnum passedFormat)
set file format for file to read. Defaults to VTK_LEGACY.
Definition lsVTKReader.hpp:109
void apply()
Definition lsVTKReader.hpp:136
auto & getMetaData()
Definition lsVTKReader.hpp:134
list coord
Definition LOCOSOxidation.py:184
Definition lsAdvect.hpp:41
FileFormatEnum
Definition lsFileFormats.hpp:4
@ VTK_AUTO
Definition lsFileFormats.hpp:8
@ VTK_LEGACY
Definition lsFileFormats.hpp:5
@ VTP
Definition lsFileFormats.hpp:6
@ VTU
Definition lsFileFormats.hpp:7