Introduction
Welcome to the documentation for 4DSSE (4D Stellar Structure and Evolution), a new code designed for simulating stellar phenomena in three spatial dimensions plus time. This project is currently under active development.
The primary goal of 4DSSE is to provide a flexible and extensible framework for advanced stellar modeling, incorporating modern numerical techniques and physics modules.
Building 4DSSE
The project uses Meson as its build system. MFEM is a core dependency and will be automatically downloaded and built if not found.
Prerequisites:
- A C++ compiler (supporting C++17 or later)
- Meson (Install via pip:
pip install meson)
- Python 3
Build Steps:
- Clone the repository (if you haven't already):
bash git clone <repository-url> cd 4dsse
- Using the
mk script (recommended for ease of use):
- To build the project:
bash ./mk
- To build without tests:
bash ./mk --noTest
- Using the
4DSSEConsole.sh script: This script provides a simple interface for building and debugging. bash ./4DSSEConsole.sh Follow the on-screen prompts.
- Manual Meson build:
- Setup the build directory (e.g.,
build): bash meson setup build
- Compile the project:
bash meson compile -C build
- To run tests (if built with tests enabled):
bash meson test -C build
The compiled executables and libraries will typically be found in the build directory.
High-Level Usage Examples
Below are some high-level examples of how to use key components of 4DSSE.
Solving for a Polytrope
The PolySolver class handles the setup and solution of the Lane-Emden equation for polytropic stellar models.
Config::getInstance().loadConfig("path/to/your/config.yaml");
try {
solver.solve();
mfem::GridFunction& theta_solution = solver.getSolution();
} catch (const std::exception& e) {
std::cerr << "An error occurred: " << e.what() << std::endl;
return 1;
}
return 0;
}
Solves the Lane-Emden equation for a polytropic star using a mixed finite element method.
quill::Logger * getLogger(const std::string &loggerName)
Get a logger by name.
static LogManager & getInstance()
Get the singleton instance of LogManager.
Managing Chemical Compositions
The Composition class allows for defining and managing chemical compositions.
#include <iostream>
#include <vector>
try {
std::vector<std::string> symbols = {"H-1", "He-4"};
std::vector<double> mass_fractions = {0.75, 0.25};
std::cout << "Mass fraction of H-1: " << comp.getMassFraction("H-1") << std::endl;
auto global_props = comp.getComposition().second;
std::cout << "Mean particle mass: " << global_props.meanParticleMass << std::endl;
} catch (const std::exception& e) {
std::cerr << "Composition error: " << e.what() << std::endl;
}
return 0;
}
Nuclear Reaction Networks
The Network and Approx8Network classes provide interfaces for nuclear reaction network calculations.
#include <iostream>
#include <vector>
input.
composition = {0.7, 0.0, 0.28, 0.01, 0.005, 0.004, 0.0005, 0.0005};
try {
std::cout <<
"Number of steps: " << output.
num_steps << std::endl;
} catch (const std::exception& e) {
std::cerr << "Network evaluation error: " << e.what() << std::endl;
}
return 0;
}
Header file for the Approx8 nuclear reaction network.
Class for the Approx8 nuclear reaction network.
void setStiff(bool stiff)
Sets whether the solver should use a stiff method.
virtual nuclearNetwork::NetOut evaluate(const nuclearNetwork::NetIn &netIn)
Evaluates the nuclear network.
Input structure for the network evaluation.
std::vector< double > composition
Composition of the network.
double density
Density in g/cm^3.
double temperature
Temperature in Kelvin.
double dt0
Initial time step.
Output structure for the network evaluation.
std::vector< double > composition
Composition of the network after evaluation.
int num_steps
Number of steps taken in the evaluation.
Accessing Physical Constants
The Constants singleton provides access to a database of physical constants.
#include <iostream>
std::cout << G.
name <<
": " << G.
value <<
" " << G.
unit << std::endl;
Constant c = consts[
"Speed of light in vacuum"];
std::cout << c.name << ": " << c.value << " " << c.unit << std::endl;
} else {
std::cerr << "Failed to load constants." << std::endl;
}
return 0;
}
Class to manage a collection of constants.
Constant get(const std::string &key) const
Get a constant by key.
static Constants & getInstance()
get instance of constants singelton
bool isLoaded()
Check if constants are loaded.
Structure to hold a constant's details.
const std::string unit
Unit of the constant.
const double value
Value of the constant.
const std::string name
Name of the constant.
Configuration Management
The Config singleton manages settings from a YAML configuration file.
#include <iostream>
Config& config = Config::getInstance();
if (config.loadConfig("path/to/your/config.yaml")) {
std::string outputPath = config.get<std::string>("Output:Path", "./output/");
std::cout << "Output path: " << outputPath << std::endl;
int maxIter = config.get<int>("Solver:MaxIterations", 100);
std::cout << "Max iterations: " << maxIter << std::endl;
} else {
std::cerr << "Failed to load configuration." << std::endl;
}
return 0;
}
Singleton class to manage configuration settings loaded from a YAML file.
Logging
The Probe::LogManager provides a way to manage and use loggers.
quill::Logger* mainLogger = logManager.
getLogger(
"main_app_log");
LOG_INFO(mainLogger, "Application started. Version: {}", "1.0.0");
LOG_ERROR(mainLogger, "An unexpected error occurred in module X.");
return 0;
}
Class to manage logging operations.
Equation of State (EOS)
The EosIO class loads EOS tables, and the helmholtz namespace provides functions to use them, for example, the Helmholtz EOS.
#include <iostream>
try {
EosIO helm_eos_io(
"path/to/helm_table.dat");
EOSTable& table_variant = helm_eos_io.getTable();
auto* helm_table_ptr = std::get_if<std::unique_ptr<helmholtz::HELMTable>>(&table_variant);
if (!helm_table_ptr || !(*helm_table_ptr) || !(*helm_table_ptr)->loaded) {
std::cerr << "Failed to load or access HELM table." << std::endl;
return 1;
}
std::cout <<
"Total Pressure (Ptot): " << results.
ptot <<
" dyne/cm^2" << std::endl;
std::cout <<
"Total Energy (Etot): " << results.
etot <<
" erg/g" << std::endl;
} catch (const std::exception& e) {
std::cerr << "EOS error: " << e.what() << std::endl;
return 1;
}
return 0;
}
Handles the input/output operations for EOS tables.
std::variant< std::unique_ptr< helmholtz::HELMTable > > EOSTable
EOS get_helm_EOS(EOSInput &q, const HELMTable &table)
Calculate the Helmholtz EOS components.
Structure to hold the output parameters and derivatives of the EOS calculation.
Structure to hold the Helmholtz EOS table data.
Mesh Handling
The MeshIO class facilitates loading and managing computational meshes.
#include "mfem.hpp"
#include <iostream>
try {
MeshIO mesh_handler(
"path/to/your/mesh.msh", 1.0);
if (mesh_handler.IsLoaded()) {
mfem::Mesh& mesh = mesh_handler.GetMesh();
std::cout << "Mesh loaded successfully with " << mesh.GetNE() << " elements." << std::endl;
} else {
std::cerr << "Failed to load mesh." << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "MeshIO error: " << e.what() << std::endl;
}
return 0;
}
Class for handling mesh input/output operations.
Key Modules and Components
4DSSE is organized into several key modules:
- Polytrope Solver (
polySolver.h, polytropeOperator.h): Provides tools to solve the Lane-Emden equation for polytropic stellar structures using a mixed finite element method. PolytropeOperator defines the nonlinear system and its Jacobian, while PolySolver orchestrates the solution process. The SchurCompliment and GMRESInverter classes are helper components for the linear algebra involved.
- Equation of State (EOS) (
helm.h, eosIO.h): Manages Equation of State data. helm.h provides an implementation of the Helmholtz EOS (Timmes & Swesty 2000), including structures for table data (HELMTable), input parameters (EOSInput), and output results (EOS). It also defines functions for reading tables and calculating EOS quantities. eosIO.h provides the EosIO class for loading EOS tables from files, currently supporting the HELM table format.
- Chemical Composition (
composition.h, atomicSpecies.h): Manages chemical compositions, allowing representation in mass or number fractions. It interfaces with atomicSpecies.h which provides a database of atomic species properties (based on AME2020).
- Nuclear Reaction Networks (
network.h, approx8.h): Defines a base Network class for nuclear reaction network calculations. approx8.h provides a specific implementation, Approx8Network, for an 8-isotope network (H1, He3, He4, C12, N14, O16, Ne20, Mg24) based on Frank Timmes' "aprox8". It includes functions for individual reaction rates and uses Boost.Numeric.Odeint for solving the ODE system.
- Physical Constants (
const.h): A singleton class Constants that loads and provides access to a wide range of physical constants with their values, uncertainties, units, and references.
- Configuration Management (
config.h): A singleton class Config for loading and accessing application settings from YAML configuration files.
- Probing and Logging (
probe.h): The Probe namespace offers utility functions for debugging, such as GLVis visualization (glVisView), and a LogManager for handling application-wide logging using the Quill library.
- Mesh I/O (
meshIO.h): The MeshIO class handles loading and basic manipulation (e.g., scaling) of computational meshes using MFEM's mfem::Mesh. It ensures that meshes are correctly loaded and accessible.
- Integrators (
integrators.h): (Details inferred) Likely contains custom MFEM integrators or coefficients used in the finite element formulations.
- Custom Types (
4DSTARTypes.h): Defines project-specific data type aliases within the SSE namespace, primarily for simplifying common std::pair combinations involving mfem::Array<int> and mfem::Array<double>. These include SSE::MFEMArrayPair and SSE::MFEMArrayPairSet, often used for managing collections of MFEM degree-of-freedom lists and their corresponding values, especially for boundary conditions.
Future Development
Future work will focus on expanding the physics modules (e.g., equation of state, opacity), improving numerical solvers, and enhancing the parallelization capabilities for large-scale simulations.
Contact and Contributions
For questions, bug reports, or contributions, please refer to the project's repository or contact the development team. (Details to be added)