SERiF 0.0.1a
3+1D Stellar Structure and Evolution
Loading...
Searching...
No Matches
polySolver.h
Go to the documentation of this file.
1/* ***********************************************************************
2//
3// Copyright (C) 2025 -- The 4D-STAR Collaboration
4// File Author: Emily Boudreaux
5// Last Modified: April 21, 2025
6//
7// 4DSSE is free software; you can use it and/or modify
8// it under the terms and restrictions the GNU General Library Public
9// License version 3 (GPLv3) as published by the Free Software Foundation.
10//
11// 4DSSE is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14// See the GNU Library General Public License for more details.
15//
16// You should have received a copy of the GNU Library General Public License
17// along with this software; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// *********************************************************************** */
21#pragma once
22
23#include "mfem.hpp"
24#include <memory>
25#include <utility>
26
27#include "integrators.h"
28#include "4DSTARTypes.h"
29#include "polytropeOperator.h"
30#include "config.h"
31#include "meshIO.h"
32#include "probe.h"
33#include "quill/Logger.h"
34
35namespace serif {
36namespace polytrope {
37
51namespace laneEmden {
65 double a (const int k, const double n);
66
81 double c(const int m, const double n);
82
103 double thetaSeriesExpansion(const double xi, const double n, const int order);
104} // namespace laneEmden
105
118 mfem::GMRESSolver solver;
119 mfem::NewtonSolver newton;
120};
121
143 std::unique_ptr<mfem::MixedBilinearForm> M;
144
151 std::unique_ptr<mfem::MixedBilinearForm> Q;
152
158 std::unique_ptr<mfem::BilinearForm> D;
159
165 std::unique_ptr<mfem::BilinearForm> S;
166
172 std::unique_ptr<mfem::NonlinearForm> f;
173};
174
203class PolySolver final{
204public: // Public methods
226 PolySolver(const double n, const double order);
227
234
249 void solve() const;
250
255 double getN() const { return m_polytropicIndex; }
256
261 double getOrder() const { return m_feOrder; }
262
267 mfem::Mesh& getMesh() const { return m_mesh; }
268
274 mfem::GridFunction& getTheta() const { return *m_theta; }
275
281 mfem::GridFunction& getPhi() const { return *m_phi; }
282
283private: // Private Attributes
284 // --- Configuration and Logging ---
285 serif::config::Config& m_config;
287 quill::Logger* m_logger;
288
289 // --- Physical and Discretization Parameters ---
291 double m_feOrder;
292
293 // --- MFEM Core Objects ---
294 mfem::Mesh& m_mesh;
295 std::unique_ptr<mfem::H1_FECollection> m_fecH1;
296 std::unique_ptr<mfem::RT_FECollection> m_fecRT;
297
298 std::unique_ptr<mfem::FiniteElementSpace> m_feTheta;
299 std::unique_ptr<mfem::FiniteElementSpace> m_fePhi;
300
301 // --- Solution Vectors ---
302 std::unique_ptr<mfem::GridFunction> m_theta;
303 std::unique_ptr<mfem::GridFunction> m_phi;
304
305 // --- Operator and Solver Components ---
306 std::unique_ptr<PolytropeOperator> m_polytropOperator;
307 std::unique_ptr<mfem::OperatorJacobiSmoother> m_prec;
308
309private: // Private methods
320 PolySolver(mfem::Mesh& mesh, double n, double order);
321
338 static mfem::Mesh& prepareMesh(double n);
339
348 void assembleBlockSystem();
349
374 mfem::Array<int> computeBlockOffsets() const;
375
418 std::unique_ptr<formBundle> buildIndividualForms(const mfem::Array<int>& blockOffsets);
419
437 static void assembleAndFinalizeForm(auto &f);
438
464
488 std::pair<mfem::Array<int>, mfem::Array<int>> findCenterElement() const;
489
514 void setInitialGuess() const;
515
531 void saveAndViewSolution(const mfem::BlockVector& state_vector) const;
532
552
566 void setOperatorEssentialTrueDofs() const;
567
592 void LoadSolverUserParams(double &newtonRelTol, double &newtonAbsTol, int &newtonMaxIter, int &newtonPrintLevel,
593 double &gmresRelTol, double &gmresAbsTol, int &gmresMaxIter, int &gmresPrintLevel) const;
594
617 static void GetDofCoordinates(const mfem::FiniteElementSpace &fes, const std::string& filename);
618
619};
620
621} // namespace polytrope
622} // namespace serif
void saveAndViewSolution(const mfem::BlockVector &state_vector) const
Saves the 1D radial solution and optionally displays the 2D/3D solution using GLVis.
~PolySolver()
Destructor for PolySolver.
double m_polytropicIndex
The polytropic index .
Definition polySolver.h:290
std::unique_ptr< mfem::H1_FECollection > m_fecH1
Finite Element Collection for (H1 elements).
Definition polySolver.h:295
serif::types::MFEMArrayPairSet getEssentialTrueDof() const
Computes the essential true degrees of freedom (DOFs) and their values for boundary conditions.
void solve() const
Solves the polytropic system.
PolySolver(const double n, const double order)
double m_feOrder
The polynomial order for H1 elements ( ). RT elements for are of order m_feOrder - 1.
Definition polySolver.h:291
std::unique_ptr< mfem::GridFunction > m_phi
Grid function for the vector flux .
Definition polySolver.h:303
mfem::GridFunction & getPhi() const
Gets a reference to the solution grid function for .
Definition polySolver.h:281
static void GetDofCoordinates(const mfem::FiniteElementSpace &fes, const std::string &filename)
Utility function to get and save the coordinates of degrees of freedom for a finite element space.
static void assembleAndFinalizeForm(auto &f)
Assemble and finalize a given MFEM form.
mfem::Array< int > computeBlockOffsets() const
Compute the block offsets for the operator. These are the offsets that define which dofs belong to wh...
solverBundle setupNewtonSolver() const
Sets up the Newton solver and its associated linear solver (GMRES).
quill::Logger * m_logger
Pointer to the specific logger instance for this class.
Definition polySolver.h:287
std::unique_ptr< PolytropeOperator > m_polytropOperator
The main nonlinear operator for the mixed system.
Definition polySolver.h:306
void assembleBlockSystem()
Assembles the block system operator m_polytropOperator.
void LoadSolverUserParams(double &newtonRelTol, double &newtonAbsTol, int &newtonMaxIter, int &newtonPrintLevel, double &gmresRelTol, double &gmresAbsTol, int &gmresMaxIter, int &gmresPrintLevel) const
Loads Newton and GMRES solver parameters from the configuration.
mfem::Mesh & m_mesh
Reference to the computational mesh (owned by ResourceManager).
Definition polySolver.h:294
void setOperatorEssentialTrueDofs() const
Sets the essential true DOFs on the PolytropeOperator.
std::unique_ptr< mfem::FiniteElementSpace > m_fePhi
Finite Element Space for .
Definition polySolver.h:299
std::unique_ptr< formBundle > buildIndividualForms(const mfem::Array< int > &blockOffsets)
Build the individual forms for the block operator (M, Q, D, S, and f).
static mfem::Mesh & prepareMesh(double n)
Prepares the mesh for the simulation.
std::pair< mfem::Array< int >, mfem::Array< int > > findCenterElement() const
Finds the degrees of freedom (DOFs) associated with the geometric center (origin) of the mesh.
mfem::GridFunction & getTheta() const
Gets a reference to the solution grid function for .
Definition polySolver.h:274
double getN() const
Gets the polytropic index .
Definition polySolver.h:255
std::unique_ptr< mfem::GridFunction > m_theta
Grid function for the scalar potential .
Definition polySolver.h:302
void setInitialGuess() const
Sets the initial guess for the solution variables and .
std::unique_ptr< mfem::FiniteElementSpace > m_feTheta
Finite Element Space for .
Definition polySolver.h:298
std::unique_ptr< mfem::OperatorJacobiSmoother > m_prec
Preconditioner (currently seems unused in polySolver.cpp).
Definition polySolver.h:307
mfem::Mesh & getMesh() const
Gets a reference to the computational mesh.
Definition polySolver.h:267
double getOrder() const
Gets the finite element order used for the variable.
Definition polySolver.h:261
serif::probe::LogManager & m_logManager
Reference to the global log manager instance.
Definition polySolver.h:286
std::unique_ptr< mfem::RT_FECollection > m_fecRT
Finite Element Collection for (Raviart-Thomas elements).
Definition polySolver.h:296
serif::config::Config & m_config
Reference to the global configuration manager instance.
Definition polySolver.h:285
Class to manage logging operations.
Definition probe.h:79
A collection of utilities for working with MFEM and solving the lane-emden equation.
Namespace for Lane-Emden equation related utility functions.
double thetaSeriesExpansion(const double xi, const double n, const int order)
double a(const int k, const double n)
Computes the coefficient for the Lane-Emden series expansion.
double c(const int m, const double n)
Computes the auxiliary coefficient used in determining .
std::pair< MFEMArrayPair, MFEMArrayPair > MFEMArrayPairSet
Definition 4DSTARTypes.h:28
Structure to hold the various bilinear and nonlinear forms for the polytrope problem.
Definition polySolver.h:137
std::unique_ptr< mfem::MixedBilinearForm > Q
Mixed bilinear form . This form arises from the term in the first equation, tested with a scalar tes...
Definition polySolver.h:151
std::unique_ptr< mfem::MixedBilinearForm > M
Mixed bilinear form . This form arises from the term in the first equation, tested with a vector tes...
Definition polySolver.h:143
std::unique_ptr< mfem::BilinearForm > D
Bilinear form . This is a mass matrix for the vector field . It arises from the term in the first eq...
Definition polySolver.h:158
std::unique_ptr< mfem::NonlinearForm > f
Nonlinear form . This form arises from the nonlinear source term in the second equation,...
Definition polySolver.h:172
std::unique_ptr< mfem::BilinearForm > S
Bilinear form . This is a stiffness matrix (Laplacian) for the scalar field . It is used for stabiliz...
Definition polySolver.h:165
Structure to manage the lifetime of MFEM solver objects.
Definition polySolver.h:117
mfem::GMRESSolver solver
The linear solver (e.g., GMRES). Must be declared first.
Definition polySolver.h:118
mfem::NewtonSolver newton
The nonlinear solver (e.g., Newton). Must be declared second.
Definition polySolver.h:119