refactor(poly): updated header guards to pragma once

This commit is contained in:
2025-04-21 08:54:59 -04:00
parent 2192dca6d7
commit 431a47b9c7
6 changed files with 36 additions and 61 deletions

View File

@@ -18,23 +18,24 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// *********************************************************************** */
#include "mfem.hpp"
#include "polySolver.h"
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
#include "polySolver.h"
#include "mfem.hpp"
#include "4DSTARTypes.h"
#include "config.h"
#include "integrators.h"
#include "mfem.hpp"
#include "operator.h"
#include "polyCoeff.h"
#include "probe.h"
#include "resourceManager.h"
#include "resourceManagerTypes.h"
#include "quill/LogMacros.h"
@@ -159,8 +160,7 @@ void PolySolver::assembleBlockSystem() {
// --- Assemble the NonlinearForm (f) ---
auto fform = std::make_unique<mfem::NonlinearForm>(m_feTheta.get());
mfem::ConstantCoefficient oneCoeff(1.0);
fform->AddDomainIntegrator(new polyMFEMUtils::NonlinearPowerIntegrator(oneCoeff, m_polytropicIndex));
fform->AddDomainIntegrator(new polyMFEMUtils::NonlinearPowerIntegrator(m_polytropicIndex));
// TODO: Add essential boundary conditions to the nonlinear form
// -- Build the BlockOperator --
@@ -183,8 +183,8 @@ void PolySolver::solve() const {
// It's safer to get the offsets directly from the operator after finalization
const mfem::Array<int>& block_offsets = m_polytropOperator->GetBlockOffsets(); // Assuming a getter exists or accessing member if public/friend
mfem::BlockVector state_vector(block_offsets);
state_vector.GetBlock(0) = *m_theta;
state_vector.GetBlock(1) = *m_phi;
state_vector.GetBlock(0) = static_cast<mfem::Vector>(*m_theta);
state_vector.GetBlock(1) = static_cast<mfem::Vector>(*m_phi);
mfem::Vector zero_rhs(block_offsets.Last());
zero_rhs = 0.0;
@@ -289,7 +289,7 @@ void PolySolver::saveAndViewSolution(const mfem::BlockVector& state_vector) cons
}
// --- Extract the Solution ---
if (bool write11DSolution = m_config.get<bool>("Poly:Output:1D:Save", true)) {
if (m_config.get<bool>("Poly:Output:1D:Save", true)) {
auto solutionPath = m_config.get<std::string>("Poly:Output:1D:Path", "polytropeSolution_1D.csv");
auto derivSolPath = "d" + solutionPath;
@@ -340,7 +340,7 @@ solverBundle PolySolver::setupNewtonSolver() const {
LoadSolverUserParams(newtonRelTol, newtonAbsTol, newtonMaxIter, newtonPrintLevel, gmresRelTol, gmresAbsTol,
gmresMaxIter, gmresPrintLevel);
solverBundle solver;
solverBundle solver; // Use this solver bundle to ensure lifetime safety
solver.solver.SetRelTol(gmresRelTol);
solver.solver.SetAbsTol(gmresAbsTol);
solver.solver.SetMaxIter(gmresMaxIter);

View File

@@ -1,5 +1,4 @@
#ifndef POLYSOLVER_H
#define POLYSOLVER_H
#pragma once
#include "mfem.hpp"
#include <memory>
@@ -21,8 +20,8 @@ namespace laneEmden {
// Struct to persist lifetime of the linear and nonlinear solvers
struct solverBundle {
mfem::GMRESSolver solver;
mfem::NewtonSolver newton;
mfem::GMRESSolver solver; // Must be first so it lives longer than the newton solver
mfem::NewtonSolver newton; // Must be second so that when it is destroyed the solver is still alive preventing a double delete
};
class PolySolver {
@@ -32,10 +31,10 @@ public: // Public methods
void solve() const;
double getN() { return m_polytropicIndex; }
double getOrder() { return m_feOrder; }
mfem::Mesh* getMesh() { return m_mesh.get(); }
mfem::GridFunction& getSolution() { return *m_theta; }
double getN() const { return m_polytropicIndex; }
double getOrder() const { return m_feOrder; }
mfem::Mesh* getMesh() const { return m_mesh.get(); }
mfem::GridFunction& getSolution() const { return *m_theta; }
private: // Private Attributes
Config& m_config = Config::getInstance();
@@ -70,6 +69,4 @@ private: // Private methods
void LoadSolverUserParams(double &newtonRelTol, double &newtonAbsTol, int &newtonMaxIter, int &newtonPrintLevel,
double &gmresRelTol, double &gmresAbsTol, int &gmresMaxIter, int &gmresPrintLevel) const;
};
#endif // POLYSOLVER_H
};