33 std::ifstream mesh_stream(mesh_file);
36 throw std::runtime_error(
"Mesh file not found: " + mesh_file);
38 m_mesh = std::make_unique<mfem::Mesh>(mesh_stream, 1, 10);
41 int space_dim =
m_mesh->SpaceDimension();
42 int ordering = mfem::Ordering::byVDIM;
44 m_mesh->Finalize(
false,
true);
53 throw std::runtime_error(
"Mesh not loaded before rescaling.");
56 if (scale_factor <= 0.0) {
57 throw std::invalid_argument(
"Scale factor must be positive.");
62 const mfem::GridFunction *nodes =
m_mesh->GetNodes();
63 double *node_data = nodes->GetData();
64 const int data_size = nodes->Size();
66 for (
int i = 0; i < data_size; ++i) {
67 node_data[i] *= scale_factor;
void LinearRescale(double scale_factor) const
Rescale the mesh by a linear factor.
~MeshIO()
Destructor for the MeshIO class.
std::string mesh_file_
Filename of the mesh file.
MeshIO(const std::string &mesh_file, double scale_factor=1.0)
Constructor that initializes the MeshIO object with a mesh file.
bool IsLoaded() const
Check if the mesh is loaded.
mfem::Mesh & GetMesh() const noexcept
Get the mesh object.
std::unique_ptr< mfem::Mesh > m_mesh
The mesh object.
bool loaded_
Flag to indicate if the mesh is loaded.