diff --git a/src/meshIO/private/meshIO.cpp b/src/meshIO/private/meshIO.cpp index a894a14..66d028f 100644 --- a/src/meshIO/private/meshIO.cpp +++ b/src/meshIO/private/meshIO.cpp @@ -2,7 +2,7 @@ // // Copyright (C) 2025 -- The 4D-STAR Collaboration // File Author: Emily Boudreaux -// Last Modified: February 16, 2025 +// Last Modified: March 18, 2025 // // 4DSSE is free software; you can use it and/or modify // it under the terms and restrictions the GNU General Library Public @@ -22,11 +22,12 @@ #include #include #include +#include #include "meshIO.h" -MeshIO::MeshIO(const std::string mesh_file) +MeshIO::MeshIO(const std::string &mesh_file, double scale_factor) { mesh_file_ = mesh_file; std::ifstream mesh_stream(mesh_file); @@ -37,8 +38,9 @@ MeshIO::MeshIO(const std::string mesh_file) } else { - mesh_ = mfem::Mesh(mesh_stream, 1, 2); + mesh_ = mfem::Mesh(mesh_stream, 1, 10); loaded_ = true; + if (scale_factor != 1.0) { LinearRescale(scale_factor); } } } @@ -46,6 +48,32 @@ MeshIO::~MeshIO() { } +void MeshIO::LinearRescale(double scale_factor) { + if (!loaded_) { + throw std::runtime_error("Mesh not loaded before rescaling."); + } + + if (scale_factor <= 0.0) { + throw std::invalid_argument("Scale factor must be positive."); + } + + // Ensure there are nodes even for linear order meshes + mesh_.EnsureNodes(); + const mfem::GridFunction *nodes = mesh_.GetNodes(); + double *node_data = nodes->GetData(); // THIS IS KEY + + int data_size = nodes->Size(); + + for (int i = 0; i < data_size; ++i) { + node_data[i] *= scale_factor; + } + + // nodes->Update(); /updates the fespace + mesh_.NodesUpdated(); + + +} + bool MeshIO::IsLoaded() const { return loaded_; diff --git a/src/meshIO/public/meshIO.h b/src/meshIO/public/meshIO.h index 1a2c4db..f96cf63 100644 --- a/src/meshIO/public/meshIO.h +++ b/src/meshIO/public/meshIO.h @@ -2,7 +2,7 @@ // // Copyright (C) 2025 -- The 4D-STAR Collaboration // File Author: Emily Boudreaux -// Last Modified: February 16, 2025 +// Last Modified: March 18, 2025 // // 4DSSE is free software; you can use it and/or modify // it under the terms and restrictions the GNU General Library Public @@ -39,13 +39,19 @@ 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); + MeshIO(const std::string &mesh_file, double scale_factor = 1.0); /** * @brief Destructor for the MeshIO class. */ ~MeshIO(); + /** + * @brief Rescale the mesh by a linear factor. + * @param scale_factor The factor by which to scale the mesh. + */ + void LinearRescale(double scale_factor); + /** * @brief Get the mesh object. * @return Reference to the mesh object.