22 #include <LbmLib/include/reportHandler/vtkCellReporter.hpp>
23 #include <UtilLib/include/Exception.hpp>
25 #include <vtkSmartPointer.h>
26 #include <vtkPolygon.h>
27 #include <vtkCellArray.h>
28 #include <vtkPolyData.h>
29 #include <vtkDoubleArray.h>
30 #include <vtkStringArray.h>
31 #include <vtkPointData.h>
32 #include <vtkMultiBlockDataSet.h>
33 #include <vtkXMLMultiBlockDataWriter.h>
34 #include <vtkXMLMultiBlockDataReader.h>
42 namespace reportHandler {
44 std::stringstream filename;
45 filename <<
filename_ <<
"_" << time <<
".vtm";
47 vtkSmartPointer<vtkPoints> polygonpoints =
48 vtkSmartPointer<vtkPoints>::New();
49 vtkSmartPointer<vtkCellArray> polygons =
50 vtkSmartPointer<vtkCellArray>::New();
51 vtkSmartPointer<vtkPolyData> polygonPolyData =
52 vtkSmartPointer<vtkPolyData>::New();
53 vtkSmartPointer<vtkMultiBlockDataSet> multiBDS =
54 vtkSmartPointer<vtkMultiBlockDataSet>::New ();
55 vtkSmartPointer<vtkXMLMultiBlockDataReader> reader =
56 vtkSmartPointer<vtkXMLMultiBlockDataReader>::New();
57 vtkSmartPointer<vtkXMLMultiBlockDataWriter> writer =
58 vtkSmartPointer<vtkXMLMultiBlockDataWriter>::New();
59 std::vector<vtkSmartPointer<vtkPolygon> > polygonvector;
60 std::map<unsigned int,std::vector<std::shared_ptr<LbmLib::geometry::Connection> > > celldefinition;
61 std::shared_ptr<LbmLib::geometry::Connection> startC =
nullptr;
62 std::shared_ptr<LbmLib::geometry::Connection> tempC =
nullptr;
63 vtkSmartPointer<vtkDoubleArray> domainidentifier =
64 vtkSmartPointer<vtkDoubleArray>::New();
65 domainidentifier->SetName(
"domain_identifier");
66 vtkSmartPointer<vtkDoubleArray> celltype =
67 vtkSmartPointer<vtkDoubleArray>::New();
68 celltype->SetName(
"cell_type");
70 vtkSmartPointer<vtkStringArray> stringCDESolverArray =
71 vtkSmartPointer<vtkStringArray>::New();
73 stringCDESolverArray->SetNumberOfComponents(1);
74 stringCDESolverArray->SetName(
"boundarydescriptors");
76 std::stringstream boundarydescriptor;
78 int globalpointcounter = 0;
79 int polygonpointcounter;
80 int polygoncounter = 0;
81 unsigned int temp_celltype;
83 for (
auto it : this->connections_) {
84 celldefinition[(*it).getDomainIdentifier()].push_back(it);
87 for (
auto it : celldefinition) {
88 startC = it.second[0];
90 polygonpointcounter = 0;
91 polygonvector.push_back(vtkSmartPointer<vtkPolygon>::New());
94 polygonpoints->InsertNextPoint(tempC->getGeometryNodes().second->getXPos(),
95 tempC->getGeometryNodes().second->getYPos(),
97 domainidentifier->InsertNextValue(tempC->getDomainIdentifier());
99 if ( this->cellTypeTrackerMap_.find(tempC->getDomainIdentifier()) == this->cellTypeTrackerMap_.end() ) {
100 lbm_fail(
"domainIdentifier not found in the cellTrackerMap.");
102 temp_celltype = this->cellTypeTrackerMap_.at(tempC->getDomainIdentifier());
105 celltype->InsertNextValue(temp_celltype);
107 boundarydescriptor.str(
"");
108 boundarydescriptor <<
"\t";
109 for (
const auto& bSolver : tempC->getBoundaryConditionDescriptor()) {
110 for (
const auto& cdeSolver : bSolver.second) {
111 boundarydescriptor << bSolver.first <<
'\t' << cdeSolver <<
'\t';
115 stringCDESolverArray->InsertNextValue(boundarydescriptor.str().c_str());
116 polygonvector.back()->GetPointIds()->InsertId(polygonpointcounter, globalpointcounter);
118 tempC = tempC->getGeometryNodes().second->getConnection<1>();
119 globalpointcounter++;
120 polygonpointcounter++;
121 }
while(tempC != startC);
125 for (
auto k : polygonvector) {
126 polygons->InsertNextCell(k);
129 polygonPolyData->SetPoints(polygonpoints);
130 polygonPolyData->SetPolys(polygons);
131 polygonPolyData->GetPointData()->AddArray(domainidentifier);
132 polygonPolyData->GetPointData()->AddArray(celltype);
133 polygonPolyData->GetPointData()->AddArray(stringCDESolverArray);
135 reader->SetFileName(filename.str().c_str());
137 if (stat(filename.str().c_str(), &buffer) == 0) {
140 multiBDS->DeepCopy(reader->GetOutput());
143 multiBDS->SetBlock(multiBDS->GetNumberOfBlocks(),polygonPolyData);
145 writer->SetFileName(filename.str().c_str());
146 #if VTK_MAJOR_VERSION <= 5
147 writer->SetInput(multiBDS);
149 writer->SetInputData(multiBDS);
152 writer->SetDataModeToAscii();
virtual void operator()(unsigned int time) const
operator() Writes the report
const std::string filename_
filename_ Stores the filename of this functor