feat(meshIO): added basic mesh reading implimentation

also added basic unit sphere mesh file which can be rescaled
This commit is contained in:
2025-02-16 15:08:33 -05:00
parent 1713f6cb08
commit ea037cf996
6 changed files with 100 additions and 1 deletions

19
src/meshIO/meson.build Normal file
View File

@@ -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')

View File

@@ -0,0 +1,37 @@
#include "mfem.hpp"
#include <string>
#include <iostream>
#include <fstream>
#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_;
}

View File

@@ -0,0 +1,42 @@
#ifndef MESHIO_H
#define MESHIO_H
#include "mfem.hpp"
#include <string>
/**
* @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

View File

@@ -5,3 +5,4 @@ subdir('resources')
subdir('dobj')
subdir('const')
subdir('opatIO')
subdir('meshIO')

Binary file not shown.

Binary file not shown.