Skip to content

Commit 3694405

Browse files
author
guo.2154
committedNov 27, 2022
Merge branch 'dev'
2 parents 55c9cd0 + 44f4454 commit 3694405

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed
 

‎include/ftk/filters/json_interface.hh

+3-18
Original file line numberDiff line numberDiff line change
@@ -417,32 +417,17 @@ void json_interface::consume_unstructured(ndarray_stream<> &stream, diy::mpi::co
417417
vtkSmartPointer<vtkXMLUnstructuredGridReader> reader = vtkXMLUnstructuredGridReader::New();
418418
reader->SetFileName(filename.c_str());
419419
reader->Update();
420-
// vtkSmartPointer<vtkUnstructuredGrid> grid = reader->GetOutput();
421420
grid = reader->GetOutput();
422-
// return new_from_vtu(grid);
423-
424-
vtkSmartPointer<vtkUnsignedCharArray> types = grid->GetDistinctCellTypesArray();
425-
const int ntypes = types->GetNumberOfValues();
426-
427-
if (ntypes == 1) {
428-
unsigned char type = types->GetValue(0);
429-
if (type == VTK_TRIANGLE) {
430-
nd = 2;
431-
// m.reset(new simplicial_unstructured_2d_mesh<>());
432-
} else if (type == VTK_TETRA) {
433-
nd = 3;
434-
// m.reset(new simplicial_unstructured_3d_mesh<>());
435-
} else
436-
fatal(FTK_ERR_MESH_NONSIMPLICIAL);
437-
} else
438-
fatal(FTK_ERR_MESH_NONSIMPLICIAL);
421+
nd = simplicial_unstructured_mesh<>::check_simplicial_mesh_dims(grid);
439422
}
440423

441424
diy::mpi::broadcast(comm, nd, get_root_proc());
442425
if (nd == 2)
443426
m.reset(new simplicial_unstructured_2d_mesh<>());
444427
else if (nd == 3)
445428
m.reset(new simplicial_unstructured_3d_mesh<>());
429+
else
430+
fatal(FTK_ERR_MESH_NONSIMPLICIAL);
446431

447432
m->from_vtu(grid);
448433
#else

‎include/ftk/mesh/simplicial_unstructured_mesh.hh

+33
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public: // io
5858

5959
virtual vtkSmartPointer<vtkUnstructuredGrid> to_vtu() const = 0;
6060
virtual void from_vtu(vtkSmartPointer<vtkUnstructuredGrid> grid) = 0;
61+
62+
static int check_simplicial_mesh_dims(vtkSmartPointer<vtkUnstructuredGrid> grid); // 0: nonsimplicial, 2 or 3: 2D or 3D
6163
#endif
6264
};
6365

@@ -177,6 +179,37 @@ vtkSmartPointer<vtkUnstructuredGrid> simplicial_unstructured_mesh<I, F>::vector_
177179

178180
return grid;
179181
}
182+
183+
template <typename I, typename F>
184+
int simplicial_unstructured_mesh<I, F>::check_simplicial_mesh_dims(vtkSmartPointer<vtkUnstructuredGrid> grid)
185+
{
186+
int nd = 0;
187+
#if (VTK_VERSION_NUMBER >= VTK_VERSION_CHECK(9, 2, 0))
188+
vtkSmartPointer<vtkUnsignedCharArray> types = grid->GetDistinctCellTypesArray();
189+
const int ntypes = types->GetNumberOfValues();
190+
191+
if (ntypes == 1) {
192+
unsigned char type = types->GetValue(0);
193+
if (type == VTK_TRIANGLE) nd = 2;
194+
else if (type == VTK_TETRA) nd = 3;
195+
else nd = 0; // nonsimplicial
196+
} else
197+
nd = 0; // nonsimplicial
198+
#else
199+
vtkSmartPointer<vtkCellTypes> types = vtkSmartPointer<vtkCellTypes>::New();
200+
grid->GetCellTypes(types);
201+
const int ntypes = types->GetNumberOfTypes();
202+
203+
if (ntypes == 1) {
204+
unsigned char type = types->GetCellType(0);
205+
if (type == VTK_TRIANGLE) nd = 2;
206+
else if (type == VTK_TETRA) nd = 3;
207+
else nd = 0; // nonsimplicial
208+
} else
209+
nd = 0; // nonsimplicial
210+
#endif
211+
return nd;
212+
}
180213
#endif
181214

182215
} // namespace ftk

0 commit comments

Comments
 (0)
Please sign in to comment.