feat(meshIO): added basic mesh reading implimentation
also added basic unit sphere mesh file which can be rescaled
This commit is contained in:
19
src/meshIO/meson.build
Normal file
19
src/meshIO/meson.build
Normal 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')
|
||||
37
src/meshIO/private/meshIO.cpp
Normal file
37
src/meshIO/private/meshIO.cpp
Normal 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_;
|
||||
}
|
||||
42
src/meshIO/public/meshIO.h
Normal file
42
src/meshIO/public/meshIO.h
Normal 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
|
||||
@@ -4,4 +4,5 @@ subdir('resources')
|
||||
# Build the main source code
|
||||
subdir('dobj')
|
||||
subdir('const')
|
||||
subdir('opatIO')
|
||||
subdir('opatIO')
|
||||
subdir('meshIO')
|
||||
BIN
src/resources/mesh/sphere.msh
Normal file
BIN
src/resources/mesh/sphere.msh
Normal file
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user