2025-04-21 08:56:45 -04:00
|
|
|
/* ***********************************************************************
|
|
|
|
|
//
|
|
|
|
|
// Copyright (C) 2025 -- The 4D-STAR Collaboration
|
|
|
|
|
// File Author: Emily Boudreaux
|
|
|
|
|
// Last Modified: April 21, 2025
|
|
|
|
|
//
|
|
|
|
|
// 4DSSE is free software; you can use it and/or modify
|
|
|
|
|
// it under the terms and restrictions the GNU General Library Public
|
|
|
|
|
// License version 3 (GPLv3) as published by the Free Software Foundation.
|
|
|
|
|
//
|
|
|
|
|
// 4DSSE is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
// See the GNU Library General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Library General Public License
|
|
|
|
|
// along with this software; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
//
|
|
|
|
|
// *********************************************************************** */
|
2025-04-21 08:54:59 -04:00
|
|
|
#pragma once
|
2025-02-19 14:35:15 -05:00
|
|
|
|
|
|
|
|
#include "mfem.hpp"
|
|
|
|
|
#include <memory>
|
2025-04-02 14:57:37 -04:00
|
|
|
#include <utility>
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
#include "integrators.h"
|
2025-04-09 15:17:55 -04:00
|
|
|
#include "4DSTARTypes.h"
|
2025-04-02 14:57:37 -04:00
|
|
|
#include "operator.h"
|
2025-03-03 09:54:13 -05:00
|
|
|
#include "config.h"
|
|
|
|
|
#include "probe.h"
|
|
|
|
|
#include "quill/Logger.h"
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-09 15:17:55 -04:00
|
|
|
|
2025-03-03 09:54:13 -05:00
|
|
|
namespace laneEmden {
|
|
|
|
|
double a (int k, double n);
|
|
|
|
|
double c(int m, double n);
|
2025-04-09 15:17:55 -04:00
|
|
|
double thetaSeriesExpansion(double xi, double n, int order);
|
2025-03-03 09:54:13 -05:00
|
|
|
}
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-21 08:35:29 -04:00
|
|
|
// Struct to persist lifetime of the linear and nonlinear solvers
|
|
|
|
|
struct solverBundle {
|
2025-04-21 08:54:59 -04:00
|
|
|
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
|
2025-04-21 08:35:29 -04:00
|
|
|
};
|
|
|
|
|
|
2025-02-19 14:35:15 -05:00
|
|
|
class PolySolver {
|
2025-04-02 14:57:37 -04:00
|
|
|
public: // Public methods
|
|
|
|
|
PolySolver(double n, double order);
|
|
|
|
|
~PolySolver();
|
|
|
|
|
|
2025-04-09 15:17:55 -04:00
|
|
|
void solve() const;
|
2025-04-02 14:57:37 -04:00
|
|
|
|
2025-04-21 08:54:59 -04:00
|
|
|
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; }
|
2025-04-02 14:57:37 -04:00
|
|
|
|
|
|
|
|
private: // Private Attributes
|
|
|
|
|
Config& m_config = Config::getInstance();
|
|
|
|
|
Probe::LogManager& m_logManager = Probe::LogManager::getInstance();
|
|
|
|
|
quill::Logger* m_logger = m_logManager.getLogger("log");
|
|
|
|
|
double m_polytropicIndex, m_feOrder;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
std::unique_ptr<mfem::Mesh> m_mesh;
|
|
|
|
|
std::unique_ptr<mfem::H1_FECollection> m_fecH1;
|
|
|
|
|
std::unique_ptr<mfem::RT_FECollection> m_fecRT;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
std::unique_ptr<mfem::FiniteElementSpace> m_feTheta;
|
|
|
|
|
std::unique_ptr<mfem::FiniteElementSpace> m_fePhi;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
std::unique_ptr<mfem::GridFunction> m_theta;
|
|
|
|
|
std::unique_ptr<mfem::GridFunction> m_phi;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
std::unique_ptr<PolytropeOperator> m_polytropOperator;
|
2025-03-03 09:54:13 -05:00
|
|
|
|
2025-04-09 15:17:55 -04:00
|
|
|
std::unique_ptr<mfem::OperatorJacobiSmoother> m_prec;
|
|
|
|
|
|
2025-04-02 14:57:37 -04:00
|
|
|
|
|
|
|
|
private: // Private methods
|
|
|
|
|
void assembleBlockSystem();
|
2025-04-09 15:17:55 -04:00
|
|
|
SSE::MFEMArrayPairSet getEssentialTrueDof() const;
|
|
|
|
|
std::pair<mfem::Array<int>, mfem::Array<int>> findCenterElement() const;
|
|
|
|
|
void setInitialGuess() const;
|
|
|
|
|
void saveAndViewSolution(const mfem::BlockVector& state_vector) const;
|
2025-04-21 08:35:29 -04:00
|
|
|
solverBundle setupNewtonSolver() const;
|
2025-04-09 15:17:55 -04:00
|
|
|
void setupOperator() const;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-09 15:17:55 -04:00
|
|
|
void LoadSolverUserParams(double &newtonRelTol, double &newtonAbsTol, int &newtonMaxIter, int &newtonPrintLevel,
|
|
|
|
|
double &gmresRelTol, double &gmresAbsTol, int &gmresMaxIter, int &gmresPrintLevel) const;
|
2025-02-19 14:35:15 -05:00
|
|
|
|
2025-04-21 08:54:59 -04:00
|
|
|
};
|