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.
foamGeoMesh.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_FOAMGEOMESH_H_
30 #define NEMOSYS_FOAMGEOMESH_H_
31 
32 #include "nemosys_export.h"
33 #include "Mesh/geoMeshBase.H"
34 
35 #include <vtkUnstructuredGrid.h>
36 
37 #include <argList.H>
38 #include <fvMesh.H>
39 #include <fvOptions.H>
40 
41 namespace NEM {
42 namespace MSH {
43 
44 // TODO: --> Read parameters from filename? (directory, field, runtime)
45 // --> Read/write volVectorField/volScalarFields
46 
47 /**
48  * @class foamGeoMesh
49  * A concrete implementation of @c geoMeshBase representing a mesh in a @c
50  * fvMesh
51  */
52 class NEMOSYS_EXPORT foamGeoMesh : public geoMeshBase {
53  public:
54  static foamGeoMesh *New();
55  vtkTypeMacro(foamGeoMesh, geoMeshBase)
56 
57  public:
58  /**
59  * Create a foamMesh from mesh in current directory
60  * @param fileName name of file
61  * @param phyGrpArrayName name of a volScalarField defining the
62  * physical group of each cell
63  * @return new foamGeoMesh from mesh
64  */
65  static foamGeoMesh *Read(const std::string &fileName,
66  const std::string &phyGrpArrayName = std::string());
67 
68  public:
69  /**
70  * Construct a foamGeoMesh with an empty mesh
71  */
72  foamGeoMesh();
73 
74  /**
75  * Construct a foamGeoMesh from an existing fvMesh
76  * @param foamMesh existing foamMesh
77  * @param phyGrpArrayName name of a volScalarField defining the physical
78  * group of each cell
79  */
80  explicit foamGeoMesh(Foam::fvMesh *foamMesh,
81  const std::string &phyGrpArrayName = std::string());
82 
83  /**
84  * foamGeoMesh destructor
85  */
86  ~foamGeoMesh() override;
87 
88  public:
89  /**
90  * Writes foam mesh into current directory
91  * @param fileName Directory path where foam mesh should be written
92  */
93  void write(const std::string &fileName) override;
94 
95  /**
96  * Reports data about mesh
97  */
98  void report(std::ostream &out) const override;
99 
100  public:
101  /**
102  * Copy the mesh
103  * @return fvMesh
104  */
105  const Foam::fvMesh &getFoamMesh() const { return *fmesh_; }
106 
107  /**
108  * Set the foamGeoMesh's mesh to @p foamMesh
109  * @param foamMesh existing fvMesh;
110  */
111  void setFoamMesh(std::unique_ptr<Foam::fvMesh> foamMesh);
112 
113  /**
114  * Resets the class members and initiates an empty foam mesh
115  */
116  void resetNative() override;
117 
118  private:
119  /**
120  * Initializes arguments and runtime objects
121  */
122  void InitializeFoam();
123 
124  private:
125  /**
126  * Create a @c GeoMesh from a @c fvMesh
127  * @details Assumes gmsh has already been initialized.
128  * @param foamMesh fv mesh
129  * @param phyGrpArrayName name of cell data array describing physical group of
130  * each cell
131  * @return @c GeoMesh
132  */
133  static GeoMesh foam2GM(Foam::fvMesh *foamMesh,
134  const std::string &phyGrpArrayName = std::string());
135 
136  /**
137  * Create a @c fvMesh from @c geoMeshBase
138  * @param geoMesh GeoMesh
139  * @param runTime TODO
140  * @param phyGrpArrayName name of cell data array describing physical group of
141  * each cell
142  * @return @c fvMesh
143  */
144  static std::unique_ptr<Foam::fvMesh> GM2foam(
145  const GeoMesh &geoMesh, Foam::Time *runTime,
146  const std::string &phyGrpArrayName = std::string());
147 
148  private:
149  // ControlDict
150  std::unique_ptr<Foam::dictionary> controlDict_;
151 
152  // fvSchemes
153  std::unique_ptr<Foam::dictionary> fvSchemes_;
154 
155  // fvSolution
156  std::unique_ptr<Foam::dictionary> fvSolution_;
157 
158  // OpenFOAM time object
159  std::unique_ptr<Foam::Time> runTime_;
160 
161  // OpenFOAM fvMesh Object
162  std::unique_ptr<Foam::fvMesh> fmesh_;
163 };
164 
165 } // namespace MSH
166 } // namespace NEM
167 
168 #endif // NEMOSYS_FOAMGEOMESH_H_
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
std::unique_ptr< Foam::dictionary > controlDict_
Definition: foamGeoMesh.H:150
std::unique_ptr< Foam::dictionary > fvSolution_
Definition: foamGeoMesh.H:156
const Foam::fvMesh & getFoamMesh() const
Copy the mesh.
Definition: foamGeoMesh.H:105
std::unique_ptr< Foam::fvMesh > fmesh_
Definition: foamGeoMesh.H:162
A concrete implementation of geoMeshBase representing a mesh in a fvMesh.
Definition: foamGeoMesh.H:52
std::unique_ptr< Foam::dictionary > fvSchemes_
Definition: foamGeoMesh.H:153
abstract class to specify geometry and mesh data
Definition: geoMeshBase.H:102
std::unique_ptr< Foam::Time > runTime_
Definition: foamGeoMesh.H:159