Debian Codegraph @

packages/seacas/libraries/ioss/src/visualization/catalyst/exodus/CatalystExodusMesh.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 "CatalystExodusMesh.h"
8 #include "CatalystManager.h"
9 #include "vtkCell.h"
10 #include "vtkCellData.h"
11 #include "vtkCellType.h"
12 #include "vtkCompositeDataIterator.h"
13 #include "vtkDataAssembly.h"
14 #include "vtkDoubleArray.h"
15 #include "vtkFieldData.h"
16 #include "vtkInformation.h"
17 #include "vtkObjectFactory.h"
18 #include "vtkPartitionedDataSet.h"
19 #include "vtkPointData.h"
20 #include "vtkUnstructuredGrid.h"
21 #include "vtksys/SystemTools.hxx"
22 #include <unistd.h>
23
24 namespace Iovs_exodus {
25
26 CatalystExodusMesh::CatalystExodusMesh(Iovs::CatalystManager *cm,
27 CatalystPipelineInfo &catalystPipelineInfo)
28 {
29
30 this->catalystPipelineInfo = catalystPipelineInfo;
31 this->catManager = cm;
32 this->global_points = nullptr;
33 this->num_global_points = 0;
34 this->UnderscoreVectors = true;
35 this->ApplyDisplacements = true;
36 this->writeCatalystMesh = false;
37
38 vtkNew<vtkDataAssembly> assembly;
39 assembly->SetRootNodeName(ASSEMBLY_ROOT_NAME.c_str());
40 assembly->AddNode(ASSEMBLY_ELEMENT_BLOCKS.c_str());
41 this->vpdc->SetDataAssembly(assembly);
42 }
43
44 CatalystExodusMesh::~CatalystExodusMesh()
45 {
46 this->ReleaseGlobalPoints();
47 this->ebmap.clear();
48 this->ebmap_reverse.clear();
49 this->global_elem_id_map.clear();
50 this->global_point_id_to_global_elem_id.clear();
51 this->ebidmap.clear();
52 }
53
54 void CatalystExodusMesh::ReleaseGlobalPoints()
55 {
56 if (this->global_points) {
57 this->global_points->Delete();
58 this->global_points = nullptr;
59 }
60 }
61
62 vtkPartitionedDataSetCollection *CatalystExodusMesh::getPartitionedDataSetCollection()
63 {
64 return this->vpdc.GetPointer();
65 }
66
67 bool CatalystExodusMesh::UnderscoreVectorsON() { return this->UnderscoreVectors; }
68
69 void CatalystExodusMesh::SetUnderscoreVectors(bool status) { this->UnderscoreVectors = status; }
70
71 bool CatalystExodusMesh::ApplyDisplacementsON() { return this->ApplyDisplacements; }
72
73 void CatalystExodusMesh::SetApplyDisplacements(bool status) { this->ApplyDisplacements = status; }
74
75 void CatalystExodusMesh::PerformCoProcessing(std::vector<int> &error_and_warning_codes,
76 std::vector<std::string> &error_and_warning_messages)
77 {
78
79 this->catManager->PerformCoProcessing(error_and_warning_codes, error_and_warning_messages,
80 catalystPipelineInfo);
81 }
82
83 void CatalystExodusMesh::SetTimeData(double currentTime, int timeStep)
84 {
85 this->catManager->SetTimeData(currentTime, timeStep, catalystPipelineInfo);
86 }
87
88 void CatalystExodusMesh::CreateGlobalVariable(const std::string &variable_name, int num_comps,
89 const double *data)
90 {
91
92 vtkVariant v((double)0.0);
93 this->CreateGlobalVariableVariant(variable_name, num_comps, v, data);
94 }
95
96 void CatalystExodusMesh::CreateGlobalVariable(const std::string &variable_name, int num_comps,
97 const int *data)
98 {
99
100 vtkVariant v((int)0);
101 this->CreateGlobalVariableVariant(variable_name, num_comps, v, data);
102 }
103
104 void CatalystExodusMesh::CreateGlobalVariable(const std::string &variable_name, int num_comps,
105 const int64_t *data)
106 {
107
108 vtkVariant v((int64_t)0);
109 this->CreateGlobalVariableVariant(variable_name, num_comps, v, data);
110 }
111
112 void CatalystExodusMesh::CreateGlobalVariableVariant(const std::string &variable_name,
113 int num_comps, vtkVariant &v,
114 const void *data)
115 {
116 for (std::map<int, unsigned int>::iterator iter = this->ebidmap.begin();
117 iter != this->ebidmap.end(); ++iter) {
118 vtkUnstructuredGrid *ug = getUnstructuredGrid(iter->second);
119 this->CreateGlobalVariableInternal(variable_name, num_comps, ug, v, data);
120 }
121 }
122
123 void CatalystExodusMesh::CreateGlobalVariableInternal(const std::string &variable_name,
124 int num_comps, vtkUnstructuredGrid *ug,
125 vtkVariant &v, const void *data)
126 {
127 if (ug == nullptr) {
128 return;
129 }
130 vtkFieldData *fieldData = ug->GetFieldData();
131 vtkDataArray *da = fieldData->GetArray(variable_name.c_str());
132 if (da) {
133 fieldData->RemoveArray(variable_name.c_str());
134 }
135 vtkDataArray *arr = vtkDataArray::CreateDataArray(v.GetType());
136 arr->SetName(variable_name.c_str());
137 arr->SetNumberOfComponents(num_comps);
138 arr->SetNumberOfTuples(1);
139 fieldData->AddArray(arr);
140 arr->Delete();
141
142 for (int cc = 0; cc < num_comps; cc++) {
143 arr->SetComponent(0, cc, this->GetArrayValue(v, data, cc));
144 }
145 }
146
147 void CatalystExodusMesh::InitializeGlobalPoints(int num_points, int dimension, const double *data)
148 {
149
150 this->global_point_id_to_global_elem_id.resize(num_points);
151 this->num_global_points = num_points;
152 this->global_points = vtkPoints::New();
153 this->global_points->SetNumberOfPoints(num_points);
154 vtkDoubleArray *coords = vtkDoubleArray::New();
155 coords->SetNumberOfComponents(3);
156 coords->SetNumberOfTuples(num_points);
157 int index = 0;
158 for (int i = 0; i < num_points; i++) {
159 coords->SetComponent(i, 0, data[index++]);
160 coords->SetComponent(i, 1, data[index++]);
161 if (dimension != 2)
162 coords->SetComponent(i, 2, data[index++]);
163 else
164 coords->SetComponent(i, 2, 0.0);
165 }
166 this->global_points->SetData(coords);
167 coords->Delete();
168 }
169
170 void
171 CatalystExodusMesh::InitializeElementBlocks(const ElementBlockIdNameList &elemBlockNameIdList)
172 {
173 this->ReleaseGlobalPoints();
174 this->ebmap.clear();
175 this->ebmap_reverse.clear();
176 this->global_elem_id_map.clear();
177 this->global_point_id_to_global_elem_id.clear();
178 this->ebidmap.clear();
179
180 for (unsigned int i = 0; i < elemBlockNameIdList.size(); i++) {
181 this->ebidmap[elemBlockNameIdList[i].first] = i;
182 unsigned int pdsIdx = vpdc->GetNumberOfPartitionedDataSets();
183 vtkNew<vtkPartitionedDataSet> pds;
184 vpdc->SetPartitionedDataSet(pdsIdx, pds);
185 vpdc->GetMetaData(pdsIdx)->Set(vtkCompositeDataSet::NAME(), elemBlockNameIdList[i].second);
186 auto assembly = vpdc->GetDataAssembly();
187 auto node =
188 assembly->AddNode(elemBlockNameIdList[i].second.c_str(), getElementBlocksAssemblyNode());
189 assembly->SetAttribute(node, ASSEMBLY_LABEL.c_str(), elemBlockNameIdList[i].second.c_str());
190 assembly->AddDataSetIndex(node, pdsIdx);
191 }
192 }
193
194 void CatalystExodusMesh::CreateElementBlock(const char *elem_block_name, int elem_block_id,
195 const std::string &elem_type, int nodes_per_elem,
196 int num_elem, const int64_t *global_elem_ids,
197 int *connectivity)
198 {
199
200 vtkVariant v((int)0);
201 this->CreateElementBlockInternal(elem_block_name, elem_block_id, elem_type, nodes_per_elem,
202 num_elem, v, global_elem_ids, connectivity);
203 }
204
205 void CatalystExodusMesh::CreateElementBlock(const char *elem_block_name, int elem_block_id,
206 const std::string &elem_type, int nodes_per_elem,
207 int num_elem, const int64_t *global_elem_ids,
208 int64_t *connectivity)
209 {
210
211 vtkVariant v((int64_t)0);
212 this->CreateElementBlockInternal(elem_block_name, elem_block_id, elem_type, nodes_per_elem,
213 num_elem, v, global_elem_ids, connectivity);
214 }
215
216 void CatalystExodusMesh::CreateElementBlockInternal(const char *elem_block_name,
217 int elem_block_id,
218 const std::string &elem_type,
219 int nodes_per_elem, int num_elem,
220 vtkVariant &v, const int64_t *global_elem_ids,
221 void *connectivity)
222 {
223
224 std::string elemType(vtksys::SystemTools::UpperCase(elem_type));
225
226 int point_count;
227 int vtk_type;
228
229 // Check for quadratic elements
230 if ((elemType.substr(0, 3) == "TRI") && (nodes_per_elem == 6)) {
231 vtk_type = VTK_QUADRATIC_TRIANGLE;
232 point_count = 6;
233 }
234 else if ((elemType.substr(0, 3) == "SHE") && (nodes_per_elem == 8)) {
235 vtk_type = VTK_QUADRATIC_QUAD;
236 point_count = 8;
237 }
238 else if ((elemType.substr(0, 3) == "SHE") && (nodes_per_elem == 9)) {
239 vtk_type = VTK_QUADRATIC_QUAD;
240 point_count = 8;
241 }
242 else if ((elemType.substr(0, 3) == "TET") && (nodes_per_elem == 10)) {
243 vtk_type = VTK_QUADRATIC_TETRA;
244 point_count = 10;
245 }
246 else if ((elemType.substr(0, 3) == "TET") && (nodes_per_elem == 11)) {
247 vtk_type = VTK_QUADRATIC_TETRA;
248 point_count = 10;
249 }
250 else if ((elemType.substr(0, 3) == "WED") && (nodes_per_elem == 15)) {
251 vtk_type = VTK_QUADRATIC_WEDGE;
252 point_count = 15;
253 }
254 else if (((elemType.substr(0, 3) == "HEX") && (nodes_per_elem == 20)) ||
255 ((elemType.substr(0, 3) == "HEX") && (nodes_per_elem == 21))) {
256 vtk_type = VTK_QUADRATIC_HEXAHEDRON;
257 point_count = 20;
258 }
259 else if ((elemType.substr(0, 3) == "HEX") && (nodes_per_elem == 27)) {
260 vtk_type = VTK_TRIQUADRATIC_HEXAHEDRON;
261 point_count = 27;
262 }
263 else if ((elemType.substr(0, 3) == "QUA") && (nodes_per_elem == 8)) {
264 vtk_type = VTK_QUADRATIC_QUAD;
265 point_count = 8;
266 }
267 else if ((elemType.substr(0, 3) == "QUA") && (nodes_per_elem == 9)) {
268 vtk_type = VTK_BIQUADRATIC_QUAD;
269 point_count = 9;
270 }
271 else if ((elemType.substr(0, 3) == "TRU") && (nodes_per_elem == 3)) {
272 vtk_type = VTK_QUADRATIC_EDGE;
273 point_count = 3;
274 }
275 else if ((elemType.substr(0, 3) == "BEA") && (nodes_per_elem == 3)) {
276 vtk_type = VTK_QUADRATIC_EDGE;
277 point_count = 3;
278 }
279 else if ((elemType.substr(0, 3) == "BAR") && (nodes_per_elem == 3)) {
280 vtk_type = VTK_QUADRATIC_EDGE;
281 point_count = 3;
282 }
283 else if ((elemType.substr(0, 3) == "EDG") && (nodes_per_elem == 3)) {
284 vtk_type = VTK_QUADRATIC_EDGE;
285 point_count = 3;
286 }
287
288 // Check for linear elements
289 else if (elemType.substr(0, 3) == "CIR") {
290 vtk_type = VTK_VERTEX;
291 point_count = 1;
292 }
293 else if (elemType.substr(0, 3) == "SPH") {
294 vtk_type = VTK_VERTEX;
295 point_count = 1;
296 }
297 else if (elemType.substr(0, 3) == "BAR") {
298 vtk_type = VTK_LINE;
299 point_count = 2;
300 }
301 else if (elemType.substr(0, 3) == "TRU") {
302 vtk_type = VTK_LINE;
303 point_count = 2;
304 }
305 else if (elemType.substr(0, 3) == "BEA") {
306 vtk_type = VTK_LINE;
307 point_count = 2;
308 }
309 else if (elemType.substr(0, 3) == "EDG") {
310 vtk_type = VTK_LINE;
311 point_count = 2;
312 }
313 else if (elemType.substr(0, 3) == "TRI") {
314 vtk_type = VTK_TRIANGLE;
315 point_count = 3;
316 }
317 else if (elemType.substr(0, 3) == "QUA") {
318 vtk_type = VTK_QUAD;
319 point_count = 4;
320 }
321 else if (elemType.substr(0, 3) == "TET") {
322 vtk_type = VTK_TETRA;
323 point_count = 4;
324 }
325 else if (elemType.substr(0, 3) == "PYR") {
326 vtk_type = VTK_PYRAMID;
327 point_count = 5;
328 }
329 else if (elemType.substr(0, 3) == "WED") {
330 vtk_type = VTK_WEDGE;
331 point_count = 6;
332 }
333 else if (elemType.substr(0, 3) == "HEX") {
334 vtk_type = VTK_HEXAHEDRON;
335 point_count = 8;
336 }
337 else if (elemType.substr(0, 3) == "NSI") {
338 vtk_type = VTK_POLYGON;
339 point_count = 0;
340 }
341 else if (elemType.substr(0, 3) == "NFA") {
342 vtk_type = VTK_POLYHEDRON;
343 point_count = 0;
344 }
345 else if ((elemType.substr(0, 3) == "SHE") && (nodes_per_elem == 3)) {
346 vtk_type = VTK_TRIANGLE;
347 point_count = 3;
348 }
349 else if ((elemType.substr(0, 3) == "SHE") && (nodes_per_elem == 4)) {
350 vtk_type = VTK_QUAD;
351 point_count = 4;
352 }
353 else if ((elemType.substr(0, 8) == "STRAIGHT") && (nodes_per_elem == 2)) {
354 vtk_type = VTK_LINE;
355 point_count = 2;
356 }
357 else if (elemType.substr(0, 3) == "SUP") {
358 vtk_type = VTK_POLY_VERTEX;
359 point_count = nodes_per_elem;
360 }
361 else if ((elemType.substr(0, 4) == "NULL") && (num_elem == 0)) {
362 std::cout << "NULL element block found";
363 std::cout << "Unable to create element block " << elem_block_name;
364 return; // silently ignore empty element blocks
365 }
366 else {
367 std::cout << "Unsupported element type: " << elemType.c_str();
368 std::cout << "Unable to create element block " << elem_block_name;
369 return;
370 // cell types not currently handled
371 // quadratic wedge - 15,16 nodes
372 // quadratic pyramid - 13 nodes
373 }
374
375 vtkIdType cell_vertex_order[point_count];
376 for (int p = 0; p < point_count; p++) {
377 cell_vertex_order[p] = p;
378 }
379
380 if (vtk_type == VTK_QUADRATIC_WEDGE) {
381 cell_vertex_order[12] = 9;
382 cell_vertex_order[13] = 10;
383 cell_vertex_order[14] = 11;
384
385 cell_vertex_order[9] = 12;
386 cell_vertex_order[10] = 13;
387 cell_vertex_order[11] = 14;
388 }
389 else if (vtk_type == VTK_QUADRATIC_HEXAHEDRON) {
390 cell_vertex_order[16] = 12;
391 cell_vertex_order[17] = 13;
392 cell_vertex_order[18] = 14;
393 cell_vertex_order[19] = 15;
394
395 cell_vertex_order[12] = 16;
396 cell_vertex_order[13] = 17;
397 cell_vertex_order[14] = 18;
398 cell_vertex_order[15] = 19;
399 }
400 else if (vtk_type == VTK_TRIQUADRATIC_HEXAHEDRON) {
401 cell_vertex_order[16] = 12;
402 cell_vertex_order[17] = 13;
403 cell_vertex_order[18] = 14;
404 cell_vertex_order[19] = 15;
405
406 cell_vertex_order[12] = 16;
407 cell_vertex_order[13] = 17;
408 cell_vertex_order[14] = 18;
409 cell_vertex_order[15] = 19;
410
411 cell_vertex_order[23] = 20;
412 cell_vertex_order[24] = 21;
413 cell_vertex_order[25] = 22;
414 cell_vertex_order[26] = 23;
415
416 cell_vertex_order[21] = 24;
417 cell_vertex_order[22] = 25;
418 cell_vertex_order[20] = 26;
419 }
420
421 vtkIdType pts[point_count];
422 int index = 0;
423 while (index < num_elem * point_count) {
424 for (int p = 0; p < point_count; p++) {
425 int index_orig = index;
426
427 int64_t conn_ind = this->GetArrayValue(v, connectivity, index_orig) - 1;
428 this->ebmap[elem_block_id][conn_ind] = -1;
429 index++;
430 }
431 if (point_count < nodes_per_elem) {
432 for (int p = 0; p < (nodes_per_elem - point_count); p++) {
433 index++;
434 }
435 }
436 }
437
438 vtkUnstructuredGrid *ug = vtkUnstructuredGrid::New();
439 vtkPoints *points = vtkPoints::New();
440 double x[3];
441 vtkIdType i = 0;
442 for (std::map<int, int>::iterator ii = this->ebmap[elem_block_id].begin();
443 ii != this->ebmap[elem_block_id].end(); ++ii) {
444
445 this->global_points->GetPoint((*ii).first, x);
446 (*ii).second = i;
447 this->ebmap_reverse[elem_block_id][i] = (*ii).first;
448 points->InsertNextPoint(x);
449 i++;
450 }
451
452 index = 0;
453 std::vector<int> object_ids;
454 while (index < num_elem * point_count) {
455 for (int p = 0; p < point_count; p++) {
456 int64_t conn_ind = this->GetArrayValue(v, connectivity, index) - 1;
457 this->global_point_id_to_global_elem_id[conn_ind] = global_elem_ids[ug->GetNumberOfCells()];
458
459 conn_ind = this->GetArrayValue(v, connectivity, index++) - 1;
460 pts[cell_vertex_order[p]] = this->ebmap[elem_block_id][conn_ind];
461 }
462 if (point_count < nodes_per_elem) {
463 for (int p = 0; p < (nodes_per_elem - point_count); p++) {
464 int64_t conn_ind = this->GetArrayValue(v, connectivity, index) - 1;
465 this->global_point_id_to_global_elem_id[conn_ind] =
466 global_elem_ids[ug->GetNumberOfCells()];
467 index++;
468 }
469 }
470
471 this->global_elem_id_map[elem_block_id][global_elem_ids[ug->GetNumberOfCells()]] =
472 ug->GetNumberOfCells();
473
474 ug->InsertNextCell(vtk_type, point_count, pts);
475 object_ids.push_back(this->ebidmap[elem_block_id]);
476 }
477
478 ug->SetPoints(points);
479
480 vpdc->GetPartitionedDataSet(this->ebidmap[elem_block_id])
481 ->SetPartition(PDS_UNSTRUCTURED_GRID_INDEX, ug);
482
483 ug->Delete();
484 points->Delete();
485 }
486
487 void CatalystExodusMesh::CreateElementVariable(const std::string &variable_name, int num_comps,
488 int elem_block_id, const double *data)
489 {
490
491 vtkVariant v((double)0.0);
492 this->CreateElementVariableVariant(variable_name, num_comps, elem_block_id, v, data);
493 }
494
495 void CatalystExodusMesh::CreateElementVariable(const std::string &variable_name, int num_comps,
496 int elem_block_id, const int *data)
497 {
498
499 vtkVariant v((int)0);
500 this->CreateElementVariableVariant(variable_name, num_comps, elem_block_id, v, data);
501 }
502
503 void CatalystExodusMesh::CreateElementVariable(const std::string &variable_name, int num_comps,
504 int elem_block_id, const int64_t *data)
505 {
506
507 vtkVariant v((int64_t)0);
508 this->CreateElementVariableVariant(variable_name, num_comps, elem_block_id, v, data);
509 }
510
511 void CatalystExodusMesh::CreateElementVariableVariant(const std::string &variable_name,
512 int num_comps, int elem_block_id,
513 vtkVariant &v, const void *data)
514 {
515 vtkUnstructuredGrid *ug = getUnstructuredGrid(this->ebidmap[elem_block_id]);
516 this->CreateElementVariableInternal(variable_name, num_comps, ug, v, data);
517 }
518
519 void CatalystExodusMesh::CreateElementVariableInternal(const std::string &variable_name,
520 int num_comps, vtkUnstructuredGrid *ug,
521 vtkVariant &v, const void *data)
522 {
523 if (ug == nullptr) {
524 return;
525 }
526 vtkFieldData *cell_data = ug->GetCellData();
527 vtkDataArray *da = cell_data->GetArray(variable_name.c_str());
528 if (da) {
529 cell_data->RemoveArray(variable_name.c_str());
530 }
531 vtkDataArray *arr = vtkDataArray::CreateDataArray(v.GetType());
532 arr->SetName(variable_name.c_str());
533 arr->SetNumberOfComponents(num_comps);
534 arr->SetNumberOfTuples(ug->GetNumberOfCells());
535 cell_data->AddArray(arr);
536 arr->Delete();
537
538 for (int ii = 0; ii < ug->GetNumberOfCells(); ii++) {
539 for (int cc = 0; cc < num_comps; cc++) {
540 arr->SetComponent(ii, cc, this->GetArrayValue(v, data, num_comps * ii + cc));
541 }
542 }
543 }
544
545 void CatalystExodusMesh::CreateNodalVariable(const std::string &variable_name, int num_comps,
546 const double *data)
547 {
548
549 vtkVariant v((double)0.0);
550 this->CreateNodalVariableVariant(variable_name, num_comps, v, data);
551 }
552
553 void CatalystExodusMesh::CreateNodalVariable(const std::string &variable_name, int num_comps,
554 const int *data)
555 {
556
557 vtkVariant v((int)0);
558 this->CreateNodalVariableVariant(variable_name, num_comps, v, data);
559 }
560
561 void CatalystExodusMesh::CreateNodalVariable(const std::string &variable_name, int num_comps,
562 const int64_t *data)
563 {
564
565 vtkVariant v((int64_t)0);
566 this->CreateNodalVariableVariant(variable_name, num_comps, v, data);
567 }
568
569 void CatalystExodusMesh::CreateNodalVariableVariant(const std::string &variable_name,
570 int num_comps, vtkVariant &v,
571 const void *data)
572 {
573 for (std::map<int, unsigned int>::iterator iter = this->ebidmap.begin();
574 iter != this->ebidmap.end(); ++iter) {
575 vtkUnstructuredGrid *ug = getUnstructuredGrid(iter->second);
576 this->CreateNodalVariableInternal(variable_name, num_comps, ug, iter->first, this->ebmap, v,
577 data);
578 }
579 }
580
581 void CatalystExodusMesh::CreateNodalVariableInternal(const std::string &variable_name,
582 int num_comps, vtkUnstructuredGrid *ug,
583 int element_block_id,
584 std::map<int, std::map<int, int>> &point_map,
585 vtkVariant &v, const void *data)
586 {
587 if (ug == nullptr) {
588 return;
589 }
590
591 bool displace_nodes = false;
592 if ((variable_name.substr(0, 3) == "DIS") || (variable_name.substr(0, 3) == "dis")) {
593 displace_nodes = true;
594 }
595
596 if (ug->GetNumberOfCells() == 0) {
597 return;
598 }
599 vtkFieldData *point_data = ug->GetPointData();
600 vtkDataArray *da = point_data->GetArray(variable_name.c_str());
601 if (da) {
602 point_data->RemoveArray(variable_name.c_str());
603 }
604 vtkDataArray *arr = vtkDataArray::CreateDataArray(v.GetType());
605 arr->SetName(variable_name.c_str());
606 arr->SetNumberOfComponents(num_comps);
607 arr->SetNumberOfTuples(ug->GetPoints()->GetNumberOfPoints());
608 point_data->AddArray(arr);
609 arr->Delete();
610
611 int index = 0;
612 for (int i = 0; i < this->num_global_points; i++) {
613 std::map<int, int>::iterator mit = point_map[element_block_id].find(i);
614
615 for (int c = 0; c < num_comps; c++) {
616 if (mit != point_map[element_block_id].end()) {
617 arr->SetComponent(point_map[element_block_id][i], c,
618 this->GetArrayValue(v, data, index++));
619 }
620 else {
621 index++;
622 }
623 }
624
625 if (displace_nodes) {
626 if (mit != point_map[element_block_id].end()) {
627 vtkPoints *points = ug->GetPoints();
628 double x[3];
629 this->global_points->GetPoint(i, x);
630 for (int c = 0; c < num_comps; c++) {
631 x[c] += arr->GetComponent(point_map[element_block_id][i], c);
632 }
633 points->SetPoint(point_map[element_block_id][i], x);
634 }
635 }
636 }
637 }
638
639 void CatalystExodusMesh::ReleaseMemory()
640 {
641 for (std::map<int, unsigned int>::iterator iter = this->ebidmap.begin();
642 iter != this->ebidmap.end(); ++iter) {
643 vtkUnstructuredGrid *ug = getUnstructuredGrid(iter->second);
644 this->ReleaseMemoryInternal(ug);
645 }
646
647 this->ebmap_reverse.clear();
648 this->global_elem_id_map.clear();
649 this->global_point_id_to_global_elem_id.clear();
650
651 this->catManager->WriteToLogFile(catalystPipelineInfo);
652 }
653
654 void CatalystExodusMesh::ReleaseMemoryInternal(vtkUnstructuredGrid *ug)
655 {
656 if (ug == nullptr) {
657 return;
658 }
659 vtkFieldData *data = ug->GetCellData();
660 vtkDataArray *global_element_ids = nullptr;
661 vtkDataArray *object_id = nullptr;
662 while (data->GetNumberOfArrays() > 0) {
663 if (std::string(data->GetArray(0)->GetName()) == "ids") {
664 global_element_ids = data->GetArray(0);
665 global_element_ids->Register(0);
666 }
667 if (std::string(data->GetArray(0)->GetName()) == "object_id") {
668 object_id = data->GetArray(0);
669 object_id->Register(0);
670 }
671 data->RemoveArray(data->GetArray(0)->GetName());
672 }
673
674 if (global_element_ids) {
675 data->AddArray(global_element_ids);
676 ug->GetCellData()->SetActiveGlobalIds("ids");
677 global_element_ids->Delete();
678 }
679
680 if (object_id) {
681 data->AddArray(object_id);
682 object_id->Delete();
683 }
684
685 data = ug->GetPointData();
686 vtkDataArray *global_node_ids = 0;
687 while (data->GetNumberOfArrays() > 0) {
688 if (std::string(data->GetArray(0)->GetName()) == "ids") {
689 global_node_ids = data->GetArray(0);
690 global_node_ids->Register(0);
691 }
692 data->RemoveArray(data->GetArray(0)->GetName());
693 }
694
695 if (global_node_ids) {
696 data->AddArray(global_node_ids);
697 ug->GetPointData()->SetActiveGlobalIds("ids");
698 global_node_ids->Delete();
699 }
700 }
701
702 void CatalystExodusMesh::logMemoryUsageAndTakeTimerReading()
703 {
704 this->catManager->logMemoryUsageAndTakeTimerReading(catalystPipelineInfo);
705 }
706
707 void CatalystExodusMesh::Delete() { this->catManager->DeletePipeline(catalystPipelineInfo); }
708
709 double CatalystExodusMesh::GetArrayValue(vtkVariant &v, const void *data, int index)
710 {
711 if (v.IsDouble()) {
712 return ((double)static_cast<const double *>(data)[index]);
713 }
714 else if (v.IsFloat()) {
715 return ((double)static_cast<const float *>(data)[index]);
716 }
717 else if (v.IsInt()) {
718 return ((double)static_cast<const int *>(data)[index]);
719 }
720 else if (v.IsLongLong()) {
721 return ((double)static_cast<const long long *>(data)[index]);
722 }
723 else if (v.IsLong()) {
724 return ((double)static_cast<const long *>(data)[index]);
725 }
726 else {
727 std::cout << "Unhandled type found in GetArrayValue: " << v.GetTypeAsString();
728 return 0.0;
729 }
730 }
731
732 int CatalystExodusMesh::getElementBlocksAssemblyNode()
733 {
734 auto assembly = vpdc->GetDataAssembly();
735 return assembly->GetFirstNodeByPath(
736 ("/" + ASSEMBLY_ROOT_NAME + "/" + ASSEMBLY_ELEMENT_BLOCKS).c_str());
737 }
738
739 vtkUnstructuredGrid *CatalystExodusMesh::getUnstructuredGrid(int blockId)
740 {
741 vtkDataSet *ds =
742 vpdc->GetPartitionedDataSet(blockId)->GetPartition(PDS_UNSTRUCTURED_GRID_INDEX);
743 return vtkUnstructuredGrid::SafeDownCast(ds);
744 }
745
746 } // namespace Iovs_exodus