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.
oshGeoMesh.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_OSHGEOMESH_H_
30 #define NEMOSYS_OSHGEOMESH_H_
31 
32 #include "Mesh/geoMeshBase.H"
33 
34 // Use forward declaration to avoid importing Omega_h headers
35 namespace Omega_h {
36 class Library;
37 class Mesh;
38 } // namespace Omega_h
39 
40 namespace NEM {
41 namespace MSH {
42 
43 /**
44  * @class OmegaHInterface
45  * @brief management class for @c Omega_h::Library
46  * @details To avoid initializing Kokkos multiple times, use this @c
47  * OmegaHInterface::GetLibrary() to get an @c Omega_h::Library object
48  */
49 class NEMOSYS_EXPORT OmegaHInterface {
50  public:
51  ~OmegaHInterface() = default;
52 
53  /**@{*/
54  OmegaHInterface(const OmegaHInterface &) = delete;
55  OmegaHInterface &operator=(const OmegaHInterface &) = delete;
56  OmegaHInterface(OmegaHInterface &&) = delete;
57  OmegaHInterface &operator=(OmegaHInterface &&) = delete;
58  /**@}*/
59 
60  public:
61  /**
62  * Initialize Omega_h. Will only create an Omega_h::Library on first call to
63  * method.
64  */
65  static std::shared_ptr<Omega_h::Library> GetLibrary();
66 
67  private:
69 
70  private:
71  static std::shared_ptr<OmegaHInterface> instance;
72  std::shared_ptr<Omega_h::Library> library;
73 };
74 
75 /**
76  * @class oshGeoMesh
77  * A concrete implementation of @c geoMeshBase representing a @c Omega_h::Mesh
78  */
79 class NEMOSYS_EXPORT oshGeoMesh : public geoMeshBase {
80  public:
81  static oshGeoMesh *New();
82  vtkTypeMacro(oshGeoMesh, geoMeshBase)
83 
84  public:
85  /**
86  * Create a oshGeoMesh from a file.
87  * @param fileName name of file that Omega_h can read
88  * @param lib library pointer; if @c nullptr, @c OmegaHInterface::GetLibrary()
89  * is used
90  * @return new oshGeoMesh
91  */
92  static oshGeoMesh *Read(const std::string &fileName,
93  Omega_h::Library *lib = nullptr);
94 
95  public:
96  /**
97  * Construct a oshGeoMesh with an empty mesh
98  */
99  oshGeoMesh();
100 
101  /**
102  * Construct a oshGeoMesh from an existing Omega_h::Mesh
103  * @param oshMesh existing Omega_h::Mesh; note the mesh is copied
104  * @param lib library pointer; if @c nullptr, @c OmegaHInterface::GetLibrary()
105  * is used
106  */
107  explicit oshGeoMesh(Omega_h::Mesh *oshMesh, Omega_h::Library *lib = nullptr);
108 
109  ~oshGeoMesh() override;
110 
111  public:
112  void write(const std::string &fileName) override;
113  void report(std::ostream &out) const override;
114  void takeGeoMesh(geoMeshBase *otherGeoMesh) override;
115  void reconstructGeo() override;
116 
117  private:
118  static GeoMesh osh2GM(Omega_h::Mesh *oshMesh, const std::string &geo = "",
119  const std::string &link = "");
120  static Omega_h::Mesh *GM2osh(const GeoMesh &geoMesh,
121  Omega_h::Library *lib = nullptr);
122 
123  public:
124  /**
125  * Get the @c Omega_h::Mesh
126  * @return reference to the @c Omega_h::Mesh
127  */
128  const Omega_h::Mesh &getOshMesh() const { return *_oshMesh; }
129  /**
130  * Set the mesh to an existing @c Omega_h::Mesh
131  * @param oshMesh an existing @c Omega_h::Mesh; note the mesh is actually
132  * copied
133  */
134  void setOshMesh(Omega_h::Mesh *oshMesh);
135 
136  private:
137  void resetNative() override;
138 
139  private:
140  std::unique_ptr<Omega_h::Mesh> _oshMesh;
141 };
142 
143 } // namespace MSH
144 } // namespace NEM
145 
146 #endif // NEMOSYS_OSHGEOMESH_H_
A concrete implementation of geoMeshBase representing a Omega_h::Mesh.
Definition: oshGeoMesh.H:79
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
std::unique_ptr< Omega_h::Mesh > _oshMesh
Definition: oshGeoMesh.H:140
geoMeshBase * New(MeshType meshType)
Create a new mesh object.
static std::shared_ptr< OmegaHInterface > instance
Definition: oshGeoMesh.H:71
const Omega_h::Mesh & getOshMesh() const
Get the Omega_h::Mesh.
Definition: oshGeoMesh.H:128
std::shared_ptr< Omega_h::Library > library
Definition: oshGeoMesh.H:72
management class for Omega_h::Library
Definition: oshGeoMesh.H:49
abstract class to specify geometry and mesh data
Definition: geoMeshBase.H:102