Debian Codegraph @

packages/seacas/libraries/ioss/src/visualization/catalyst/cgns/CatalystCGNSMesh.cxx

raw
1 // Copyright(C) 1999-2021 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "CatalystCGNSMesh.h"
8 #include "CatalystManager.h"
9 #include "vtkCellData.h"
10 #include "vtkDataAssembly.h"
11 #include "vtkAOSDataArrayTemplate.h"
12 #include "vtkInformation.h"
13 #include "vtkObjectFactory.h"
14 #include "vtkPartitionedDataSet.h"
15 #include "vtkPointData.h"
16 #include "vtkPoints.h"
17 #include "vtkStructuredGrid.h"
18 #include <sstream>
19
20 namespace Iovs_cgns {
21
22 namespace detail {
23
24 template <typename T>
25 void addStructuredZoneArray(T *data, const CatalystCGNSMeshBase::ZoneData &zoneData, int index,
26 vtkStructuredGrid *sg)
27 {
28 if (index >= 0) {
29 vtkPoints *pts = sg->GetPoints();
30 for (int i = 0; i < zoneData.size; i++) {
31 double p[3];
32 pts->GetPoint(i, p);
33 p[index] = data[i];
34 pts->InsertPoint(i, p);
35 }
36 }
37 else {
38 vtkAOSDataArrayTemplate<T> *da = vtkAOSDataArrayTemplate<T>::New();
39 da->SetName(zoneData.data_name.c_str());
40 da->SetNumberOfComponents(zoneData.comp_count);
41 da->SetNumberOfTuples(zoneData.size);
42 for (int j = 0; j < zoneData.size; j++) {
43 double d[zoneData.comp_count];
44 for (int i = 0; i < zoneData.comp_count; i++) {
45 d[i] = data[(zoneData.comp_count * j) + i];
46 }
47 da->InsertTuple(j, d);
48 }
49
50 if (zoneData.is_cell_field) {
51 sg->GetCellData()->AddArray(da);
52 }
53 else {
54 sg->GetPointData()->AddArray(da);
55 }
56 da->Delete();
57 }
58 }
59
60 } // namespace detail
61
62 CatalystCGNSMesh::CatalystCGNSMesh(Iovs::CatalystManager *cm,
63 CatalystPipelineInfo &catalystPipelineInfo)
64 {
65
66 vtkNew<vtkDataAssembly> assembly;
67 assembly->SetRootNodeName(ASSEMBLY_ROOT_NAME.c_str());
68 auto id = assembly->AddNode(ASSEMBLY_STRUCTURED_BLOCKS.c_str());
69 this->vpdc->SetDataAssembly(assembly);
70
71 this->catManager = cm;
72 this->catalystPipelineInfo = catalystPipelineInfo;
73 }
74
75 CatalystCGNSMesh::~CatalystCGNSMesh() {}
76
77 vtkPartitionedDataSetCollection *CatalystCGNSMesh::getPartitionedDataSetCollection()
78 {
79 return this->vpdc.GetPointer();
80 }
81
82 void CatalystCGNSMesh::PerformCoProcessing(std::vector<int> &error_and_warning_codes,
83 std::vector<std::string> &error_and_warning_messages)
84 {
85
86 this->catManager->PerformCoProcessing(error_and_warning_codes, error_and_warning_messages,
87 catalystPipelineInfo);
88 }
89
90 void CatalystCGNSMesh::SetTimeData(double currentTime, int timeStep)
91 {
92 this->catManager->SetTimeData(currentTime, timeStep, catalystPipelineInfo);
93 }
94
95 void CatalystCGNSMesh::ReleaseMemory() {}
96
97 void CatalystCGNSMesh::logMemoryUsageAndTakeTimerReading()
98 {
99 this->catManager->logMemoryUsageAndTakeTimerReading(catalystPipelineInfo);
100 }
101
102 void CatalystCGNSMesh::Delete() { this->catManager->DeletePipeline(catalystPipelineInfo); }
103
104 void CatalystCGNSMesh::AddStructuredZoneData(const ZoneData &zoneData)
105 {
106 int dims[3] = {zoneData.ni + 1, zoneData.nj + 1, zoneData.nk + 1};
107
108 // if this is an empty block, we just need to make a NULL grid with the
109 // proper name, and we don't need to add any data variables
110 // alternative is to make block with dims of (I think) -1,-1,-1
111 // or extents of [0,-1,0,-1,0,-1] (I think)
112 if ((zoneData.ni == 0) or (zoneData.nj == 0) or (zoneData.nk == 0)) {
113 if (zone_id_to_zone_location_map.find(zoneData.zone_id) ==
114 zone_id_to_zone_location_map.end()) {
115 createPartitionedDataSet(zoneData, nullptr);
116 }
117 return;
118 }
119
120 if (zone_id_to_zone_location_map.find(zoneData.zone_id) == zone_id_to_zone_location_map.end()) {
121 vtkStructuredGrid *sg = vtkStructuredGrid::New();
122 vtkPoints *pts = vtkPoints::New();
123 sg->SetDimensions(dims);
124 pts->Allocate(dims[0] * dims[1] * dims[2]);
125 sg->SetPoints(pts);
126 pts->Delete();
127 createPartitionedDataSet(zoneData, sg);
128 sg->Delete();
129 }
130
131 vtkStructuredGrid *sg = getStucturedGrid(zoneData);
132
133 int index = -1;
134 if (zoneData.data_name == "mesh_model_coordinates_x") {
135 index = 0;
136 }
137 else if (zoneData.data_name == "mesh_model_coordinates_y") {
138 index = 1;
139 }
140 else if (zoneData.data_name == "mesh_model_coordinates_z") {
141 index = 2;
142 }
143
144 if (zoneData.data_type == zoneData.T_INT) {
145 detail::addStructuredZoneArray(zoneData.data.p_int, zoneData, index, sg);
146 }
147 else if (zoneData.data_type == zoneData.T_INT64) {
148 detail::addStructuredZoneArray(zoneData.data.p_int64, zoneData, index, sg);
149 }
150 else {
151 detail::addStructuredZoneArray(zoneData.data.p_double, zoneData, index, sg);
152 }
153 }
154
155 int CatalystCGNSMesh::getStructuredBlocksAssemblyNode()
156 {
157 auto assembly = vpdc->GetDataAssembly();
158 return assembly->GetFirstNodeByPath(
159 ("/" + ASSEMBLY_ROOT_NAME + "/" + ASSEMBLY_STRUCTURED_BLOCKS).c_str());
160 }
161
162 void CatalystCGNSMesh::createPartitionedDataSet(const ZoneData &zoneData, vtkStructuredGrid *sg)
163 {
164 const auto pdsIdx = vpdc->GetNumberOfPartitionedDataSets();
165 zone_id_to_zone_location_map[zoneData.zone_id] = pdsIdx;
166 vtkNew<vtkPartitionedDataSet> pds;
167 if (sg != nullptr) {
168 pds->SetPartition(PDS_STRUCTURED_GRID_INDEX, sg);
169 }
170 vpdc->SetPartitionedDataSet(pdsIdx, pds);
171 vpdc->GetMetaData(pdsIdx)->Set(vtkCompositeDataSet::NAME(), zoneData.zone_name);
172 auto assembly = vpdc->GetDataAssembly();
173 auto node = assembly->AddNode(zoneData.zone_name.c_str(), getStructuredBlocksAssemblyNode());
174 assembly->SetAttribute(node, ASSEMBLY_LABEL.c_str(), zoneData.zone_name.c_str());
175 assembly->AddDataSetIndex(node, pdsIdx);
176 }
177
178 vtkStructuredGrid *CatalystCGNSMesh::getStucturedGrid(const ZoneData &zoneData)
179 {
180 int zone_location = zone_id_to_zone_location_map[zoneData.zone_id];
181 vtkStructuredGrid *sg = vtkStructuredGrid::SafeDownCast(
182 vpdc->GetPartitionedDataSet(zone_location)->GetPartition(PDS_STRUCTURED_GRID_INDEX));
183 return sg;
184 }
185
186 } // namespace Iovs_cgns