29 #if defined(_MSC_VER) && !defined(_USE_MATH_DEFINES) 30 # define _USE_MATH_DEFINES 39 #include <vtkGenericDataObjectReader.h> 40 #include <vtkGenericDataObjectWriter.h> 41 #include <vtkSTLReader.h> 42 #include <vtkXMLDataSetWriter.h> 43 #include <vtkXMLGenericDataObjectReader.h> 57 const std::string &geoArrayName) {
58 vtkSmartPointer<vtkUnstructuredGrid> inUnstructuredGrid;
61 if (fileExt ==
".vtk") {
62 vtkSmartPointer<vtkGenericDataObjectReader> reader =
64 reader->SetFileName(fileName.c_str());
67 inUnstructuredGrid = vtkUnstructuredGrid::SafeDownCast(reader->GetOutput());
68 }
else if (fileExt.substr(0, 3) ==
".vt") {
69 vtkSmartPointer<vtkXMLGenericDataObjectReader> reader =
71 reader->SetFileName(fileName.c_str());
74 inUnstructuredGrid = vtkUnstructuredGrid::SafeDownCast(reader->GetOutput());
85 std::cerr <<
"ERROR: File extension " << fileExt
86 <<
" is not supported by vtkGeoMesh." << std::endl;
90 if (!inUnstructuredGrid) {
91 std::cerr <<
"ERROR: Only VTK Unstructured Grid (vtu) is supported." 96 return new vtkGeoMesh(inUnstructuredGrid, geoArrayName);
103 const std::string &geoArrayName)
105 std::cout <<
"vtkGeoMesh constructed" << std::endl;
118 if (fileExt ==
".vtk") {
119 vtkSmartPointer<vtkGenericDataObjectWriter> writer =
121 writer->SetFileName(fileName.c_str());
122 writer->SetInputData(
mesh);
125 vtkSmartPointer<vtkXMLDataSetWriter> writer =
127 writer->SetFileName(fileName.c_str());
128 writer->SetInputData(
mesh);
144 const std::string &phyGrpArrayName) {
148 gmsh::model::add(gmshMesh);
149 gmsh::model::setCurrent(gmshMesh);
153 vtkMesh->GetNumberOfPoints() == 0 ||
154 !vtkMesh->GetCellData()->HasArray(phyGrpArrayName.c_str())
156 return {vtkMesh,
"",
"", {}};
159 std::set<std::pair<int, int>> dim_phyGrp;
160 auto phyGrpArray = vtkArrayDownCast<vtkDataArray>(
161 vtkMesh->GetCellData()->GetArray(phyGrpArrayName.c_str()));
162 vtkSmartPointer<vtkGenericCell> vtkGC =
166 for (vtkIdType i = 0; i < vtkMesh->GetNumberOfCells(); ++i) {
167 vtkGC->SetCellType(vtkMesh->GetCellType(i));
168 int dim = vtkGC->GetCellDimension();
169 int phyGrp =
static_cast<int>(phyGrpArray->GetComponent(i, 0));
171 dim_phyGrp.insert({dim, phyGrp});
176 for (
const auto &dp : dim_phyGrp) {
177 gmsh::model::addDiscreteEntity(dp.first, dp.second);
178 gmsh::model::addPhysicalGroup(dp.first, {dp.second}, dp.second);
200 return {vtkMesh, gmshMesh, phyGrpArrayName, {}};
virtual void report(std::ostream &out) const =0
Print a report about the mesh.
vtkSmartPointer< vtkUnstructuredGrid > mesh
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
void setGeoMesh(const geoMeshBase::GeoMesh &geoMesh)
Set the underlying geometry object.
static void Initialize()
Initialize Gmsh.
std::string find_ext(const std::string &fname)
A concrete implementation of geoMeshBase representing a mesh in a vtkUnstructuredGrid.
void getVtkMesh(vtkUnstructuredGrid *dest)
Copy the mesh.
vtkGeoMesh()
Create a vtkGeoMesh from a vtkUnstructuredGrid file.
std::string getRandomString(int length)
std::shared_ptr< meshBase > mesh
vtkStandardNewMacro(exoGeoMesh)
void resetNative() override
static vtkGeoMesh * New()
static GeoMesh vtk2GM(vtkUnstructuredGrid *vtkMesh, const std::string &phyGrpArrayName=std::string())
Create a GeoMesh from a vtkUnstructuredGrid.
void report(std::ostream &out) const override
Print a report about the mesh.
void write(const std::string &fileName) override
Write mesh to file.
abstract class to specify geometry and mesh data
const GeoMesh & getGeoMesh() const
Get the underlying geometry object.
void setVtkMesh(vtkUnstructuredGrid *vtkMesh)
Set the vtkGeoMesh's mesh to vtkMesh.