NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
geoMeshFactory.C
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #include "Mesh/geoMeshFactory.H"
30 
31 #include "AuxiliaryFunctions.H"
32 
33 #include "Mesh/exoGeoMesh.H"
34 #include "Mesh/inpGeoMesh.H"
35 #include "Mesh/oshGeoMesh.H"
36 #include "Mesh/vtkGeoMesh.H"
37 
38 #ifdef HAVE_CFMSH
39 # include "Mesh/foamGeoMesh.H"
40 #endif
41 
42 #ifdef HAVE_GMSH
43 # include "Mesh/gmshGeoMesh.H"
44 #endif
45 
46 #ifdef HAVE_OCC
47 # include "Mesh/smeshGeoMesh.H"
48 #endif
49 
50 namespace NEM {
51 namespace MSH {
52 
53 MeshType MeshTypeFromFilename(const std::string &fileName) {
54  std::string fileExt = nemAux::find_ext(fileName);
55 
56  if (fileExt == ".vtu" || fileExt == ".vtk") {
58  } else if (fileExt == ".msh" || fileExt == ".geo") {
60  } else if (fileExt == ".osh") {
62  } else if (fileExt == ".exo" || fileExt == ".e" || fileExt == ".gen" ||
63  fileExt == ".g") {
65  } else if (fileExt == ".inp") {
67  } else if (fileExt == ".foam") {
69  } else {
70  std::cerr << "File extension " << fileExt << " is not supported."
71  << std::endl;
72  exit(1);
73  }
74 }
75 
76 geoMeshBase *Read(const std::string &fileName) {
77  return Read(fileName, MeshTypeFromFilename(fileName));
78 }
79 
80 geoMeshBase *Read(const std::string &fileName, MeshType meshType) {
81  switch (meshType) {
82  case MeshType::VTK_GEO_MESH: return vtkGeoMesh::Read(fileName);
84 #ifdef HAVE_GMSH
85  return gmshGeoMesh::Read(fileName);
86 #else
87  std::cerr << "Please build NEMoSys with ENABLE_GMSH=ON to use this"
88  << " feature!" << std::endl;
89  throw;
90 #endif
91  }
92  case MeshType::OSH_GEO_MESH: return oshGeoMesh::Read(fileName);
93  case MeshType::EXO_GEO_MESH: return exoGeoMesh::Read(fileName);
94  case MeshType::INP_GEO_MESH: return inpGeoMesh::Read(fileName);
96 #ifdef HAVE_CFMSH
97  std::string fname = fileName;
98  fname.erase(fname.find_last_of('.'));
99  return foamGeoMesh::Read(fname);
100 #else
101  std::cerr << "Please build NEMoSys with ENABLE_CFMSH=ON to use this"
102  << " feature!" << std::endl;
103  throw;
104 #endif
105  }
107  std::cerr << "Unsupported.\n";
108  throw;
109  }
110  }
111  // Don't put inside switch statement so static analyzers can detect unhandled
112  // cases
113  return nullptr;
114 }
115 
116 geoMeshBase *New(MeshType meshType) {
117  switch (meshType) {
120 #ifdef HAVE_GMSH
121  return gmshGeoMesh::New();
122 #else
123  std::cerr << "Please build NEMoSys with ENABLE_GMSH=ON to use this"
124  << " feature!" << std::endl;
125  throw;
126 #endif
127  }
132 #ifdef HAVE_CFMSH
133  return foamGeoMesh::New();
134 #else
135  std::cerr << "Please build NEMoSys with ENABLE_CFMSH=ON to use this"
136  << " feature!" << std::endl;
137  throw;
138 #endif
139  }
141 #ifdef HAVE_OCC
142  return smeshGeoMesh::New();
143 #else
144  std::cerr << "Requires ENABLE_OPENCASCADE=ON\n";
145  throw;
146 #endif
147  }
148  }
149  return nullptr;
150 }
151 
152 geoMeshBase *New(const std::string &fileName) {
153  return New(MeshTypeFromFilename(fileName));
154 }
155 
156 } // namespace MSH
157 } // namespace NEM
OSH_GEO_MESH
Based on Omega_h::Mesh from Omega_h library.
SMESH_GEO_MESH
Based on SMESH_Mesh from Salome SMESH (see contrib/)
static smeshGeoMesh * New()
static inpGeoMesh * New()
static exoGeoMesh * New()
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
INP_GEO_MESH
Abaqus/CalculiX mesh input format.
std::string find_ext(const std::string &fname)
VTK_GEO_MESH
Based on vtkUnstructuredGrid from VTK library.
MeshType MeshTypeFromFilename(const std::string &fileName)
static inpGeoMesh * Read(const std::string &fileName)
FOAM_GEO_MESH
Based on fvMesh from OpenFOAM library.
GMSH_GEO_MESH
Mesh and geometry based on Gmsh&#39;s public API.
static foamGeoMesh * New()
static vtkGeoMesh * New()
geoMeshBase * Read(const std::string &fileName, MeshType meshType)
Read a mesh from file.
EXO_GEO_MESH
Interface to EXODUS II library.
abstract class to specify geometry and mesh data
Definition: geoMeshBase.H:102
static oshGeoMesh * New()
static gmshGeoMesh * New()