diff --git a/src/meshIO/meson.build b/src/meshIO/meson.build new file mode 100644 index 0000000..1ea870a --- /dev/null +++ b/src/meshIO/meson.build @@ -0,0 +1,19 @@ +# Define the library +meshIO_sources = files( + 'private/meshIO.cpp', +) + +meshIO_headers = files( + 'public/meshIO.h' +) + +# Define the libmeshIO library so it can be linked against by other parts of the build system +libmeshIO = static_library('meshIO', + meshIO_sources, + include_directories: include_directories('public'), + cpp_args: ['-fvisibility=default'], + dependencies: [mfem_dep], + install : true) + +# Make headers accessible +install_headers(meshIO_headers, subdir : '4DSSE/meshIO') \ No newline at end of file diff --git a/src/meshIO/private/meshIO.cpp b/src/meshIO/private/meshIO.cpp new file mode 100644 index 0000000..8674af3 --- /dev/null +++ b/src/meshIO/private/meshIO.cpp @@ -0,0 +1,37 @@ +#include "mfem.hpp" +#include +#include +#include + +#include "meshIO.h" + + +MeshIO::MeshIO(const std::string &mesh_file) +{ + mesh_file_ = mesh_file; + std::ifstream mesh_stream(mesh_file); + if (!mesh_stream) + { + throw std::runtime_error("Mesh file not found: " + mesh_file); + loaded_ = false; + } + else + { + mesh_ = mfem::Mesh(mesh_stream, 1, 2); + loaded_ = true; + } +} + +MeshIO::~MeshIO() +{ +} + +bool MeshIO::IsLoaded() const +{ + return loaded_; +} + +mfem::Mesh& MeshIO::GetMesh() +{ + return mesh_; +} \ No newline at end of file diff --git a/src/meshIO/public/meshIO.h b/src/meshIO/public/meshIO.h new file mode 100644 index 0000000..5975801 --- /dev/null +++ b/src/meshIO/public/meshIO.h @@ -0,0 +1,42 @@ +#ifndef MESHIO_H +#define MESHIO_H + +#include "mfem.hpp" +#include + +/** + * @brief Class for handling mesh input/output operations. + */ +class MeshIO +{ +private: + bool loaded_; ///< Flag to indicate if the mesh is loaded + std::string mesh_file_; ///< Filename of the mesh file + mfem::Mesh mesh_; ///< The mesh object + +public: + /** + * @brief Constructor that initializes the MeshIO object with a mesh file. + * @param mesh_file The name of the mesh file. + */ + MeshIO(const std::string &mesh_file); + + /** + * @brief Destructor for the MeshIO class. + */ + ~MeshIO(); + + /** + * @brief Get the mesh object. + * @return Reference to the mesh object. + */ + mfem::Mesh& GetMesh(); + + /** + * @brief Check if the mesh is loaded. + * @return True if the mesh is loaded, false otherwise. + */ + bool IsLoaded() const; +}; + +#endif // MESHIO_H \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index db87771..9ae232d 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,4 +4,5 @@ subdir('resources') # Build the main source code subdir('dobj') subdir('const') -subdir('opatIO') \ No newline at end of file +subdir('opatIO') +subdir('meshIO') \ No newline at end of file diff --git a/src/resources/mesh/sphere.msh b/src/resources/mesh/sphere.msh new file mode 100644 index 0000000..416c655 Binary files /dev/null and b/src/resources/mesh/sphere.msh differ diff --git a/src/resources/mesh/sphere.vtk b/src/resources/mesh/sphere.vtk deleted file mode 100644 index 904ec6a..0000000 Binary files a/src/resources/mesh/sphere.vtk and /dev/null differ