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.
foamMesh.H
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 #ifndef NEMOSYS_FOAMMESH_H_
30 #define NEMOSYS_FOAMMESH_H_
31 
32 #ifdef HAVE_CFMSH
33 
34 #include "Mesh/meshBase.H"
35 
36 // OpenFOAM
37 #include <argList.H>
38 #include <fvOptions.H>
39 
40 namespace FOAM {
41 
42 /**
43  @brief foamMesh class contains methods for reading and writing mesh in
44  OpenFOAM polyMesh format. It also overrides certain methods of
45  meshBase for decomposing OpenFOAM polyMesh into VTK unstructured
46  database to facilitate convertion to and from OpenFOAM mesh to
47  different mesh formats through ConversionDriver.
48 **/
49 class foamMesh : public meshBase {
50  // --- constructor and deconstructor
51  public:
52  /**
53  @brief foamMesh default constructor. Initializes OpenFOAM environment.
54  @param readDB If true, reads mesh database from current location.
55  (default is false)
56  **/
57  explicit foamMesh(bool readDB = false);
58 
59  /** @brief foamMesh alternate constructor. Assigns incoming meshBase mesh
60  to internal pointer for manipulation. Creates necessary foam
61  dictionaries for runtime environment.
62  @param fullMesh meshBase shared pointer for mesh database.
63  **/
64  foamMesh(std::shared_ptr<meshBase> fullMesh);
65 
66  /** @brief foamMesh standard destructor
67  **/
68  ~foamMesh() override;
69 
70  // --- diagnostics
71  public:
72  // generate a report of the mesh
73  void report() const override;
74 
75  // --- access
76  public:
77  /**
78  @brief general purpose mesh information read method
79  @param fname File name to read the mesh from.
80  **/
81  void read(const std::string &fname) override;
82 
83  /** @brief Reads fvMesh for adaptive mesh refinement process
84  @param runTime OpenFOAM Time class object
85  **/
86  void readAMR(const Foam::Time &runTime);
87 
88  /**
89  @brief get point with id
90  @param id VTK Point ID
91  @return Vector of point coordinates <X, Y, Z>
92  **/
93  std::vector<double> getPoint(nemId_t id) const override;
94 
95  /**
96  @brief get 3 vecs with x,y and z coords
97  @returns Vector with all vertices coordinates in mesh
98  <vertices><X,Y,Z>
99  **/
100  std::vector<std::vector<double>> getVertCrds() const override;
101 
102  /**
103  @brief get cell with id : returns point indices and respective
104  coordinates
105  @param id VTK cell ID
106  @return a map of cell ID to its bounding point IDs.
107  **/
108  std::map<nemId_t, std::vector<double>> getCell(nemId_t id) const override;
109 
110  /**
111  @brief get cell points ids and their coordinates
112  @param id VTK cell ID
113  @return Vector of cell point ids with their coordinates.
114  **/
115  std::vector<std::vector<double>> getCellVec(nemId_t id) const override;
116 
117  /**
118  @brief get diameter of circumsphere of each cell
119  @return Vector of diameter of circumsphere of each cell
120  **/
121  std::vector<double> getCellLengths() const override;
122 
123  /**
124  @brief get center of a cell
125  @param cellID VTK cell ID
126  @return Vector of cell center coordinates.
127  **/
128  std::vector<double> getCellCenter(nemId_t cellID) const override;
129 
130  /**
131  @brief get cell type as an integer. assumes all elements are the
132  same type
133  **/
134  int getCellType() const override;
135 
136  /**
137  @brief get edge lengths of dataSet
138  @param ofname Output file name
139  **/
140  void inspectEdges(const std::string &ofname) const override;
141 
142  /**
143  @brief get vtk cell connectivities in terms of point ids
144  @return Vector of points
145  **/
146  std::vector<nemId_t> getConnectivities() const override;
147 
148  using meshBase::write;
149  /**
150  @brief write the mesh to file named fname
151  @param fname Output mesh file name (filename.extension)
152  **/
153  void write(const std::string &fname) const override;
154 
155  // --- processing
156  public:
157  /**
158  @brief Extracts foam mesh surface using VTK data set.
159  **/
160  vtkSmartPointer<vtkDataSet> extractSurface() override;
161 
162  /** @brief Return a polyMesh Object
163  **/
164  // Foam::polyMesh& getMsh();
165 
166  // --- internal methods
167  private:
168  /**
169  @brief Decomposes OpenFOAM mesh into VTK unstructured dataset.
170  **/
171  void genMshDB();
172 
173  /**
174  @brief Created necessary dictionaries for OpenFOAM runtime environment.
175  **/
176  void createFoamDicts();
177 
178  // --- openfoam data structure
179  private:
180  Foam::argList *_args;
181  Foam::Time *_runTime;
182  Foam::fvMesh *_fmesh;
183 
184  // --- internal data
185  private:
186  /** @brief Shared meshBase pointer for foamMesh constructor and some methods
187  **/
188  std::shared_ptr<meshBase> _volMB;
189 };
190 
191 } // namespace FOAM
192 
193 #endif
194 
195 #endif // NEMOSYS_FOAMMESH_H_
void inspectEdges(const std::string &ofname) const override
get edge lengths of dataSet
Definition: foamMesh.C:212
Foam::Time * _runTime
Definition: foamMesh.H:181
Foam::argList * _args
Definition: foamMesh.H:180
std::map< nemId_t, std::vector< double > > getCell(nemId_t id) const override
get cell with id : returns point indices and respective coordinates
Definition: foamMesh.C:175
std::shared_ptr< meshBase > _volMB
Shared meshBase pointer for foamMesh constructor and some methods.
Definition: foamMesh.H:188
~foamMesh() override
foamMesh standard destructor
Definition: foamMesh.C:83
void read(const std::string &fname) override
general purpose mesh information read method
Definition: foamMesh.C:99
A brief description of meshBase.
Definition: meshBase.H:64
std::size_t nemId_t
Definition: meshBase.H:51
void readAMR(const Foam::Time &runTime)
Reads fvMesh for adaptive mesh refinement process.
Definition: foamMesh.C:567
Foam::fvMesh * _fmesh
Definition: foamMesh.H:182
std::vector< double > getPoint(nemId_t id) const override
get point with id
Definition: foamMesh.C:153
void genMshDB()
Return a polyMesh Object.
Definition: foamMesh.C:136
foamMesh class contains methods for reading and writing mesh in OpenFOAM polyMesh format...
Definition: foamMesh.H:49
std::vector< std::vector< double > > getVertCrds() const override
get 3 vecs with x,y and z coords
Definition: foamMesh.C:161
std::vector< std::vector< double > > getCellVec(nemId_t id) const override
get cell points ids and their coordinates
Definition: foamMesh.C:194
virtual void write() const
write the mesh to file named after the private var &#39;filename&#39;.
Definition: meshBase.H:598
int getCellType() const override
get cell type as an integer.
Definition: foamMesh.C:338
foamMesh(bool readDB=false)
foamMesh default constructor.
Definition: foamMesh.C:63
std::vector< double > getCellLengths() const override
get diameter of circumsphere of each cell
Definition: foamMesh.C:317
void createFoamDicts()
Created necessary dictionaries for OpenFOAM runtime environment.
Definition: foamMesh.C:357
std::vector< double > getCellCenter(nemId_t cellID) const override
get center of a cell
Definition: foamMesh.C:327
vtkSmartPointer< vtkDataSet > extractSurface() override
Extracts foam mesh surface using VTK data set.
Definition: foamMesh.C:340
std::vector< nemId_t > getConnectivities() const override
get vtk cell connectivities in terms of point ids
Definition: foamMesh.C:238
Definition: foamMesh.C:57
void report() const override
generate a report of the mesh
Definition: foamMesh.C:251