COSMOS
Functions
cosmos_d.cpp File Reference
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cfloat>
#include <cstring>
#include "cosmos.h"
#include "ahf2d.h"
Include dependency graph for cosmos_d.cpp:

Functions

void printpack (Fmv0 **fmv0, int ln, int pk, int pl, ofstream &filex, ofstream &filey, ofstream &filez, ofstream &filex0z, ofstream &filexy0)
 Helper function to call print routines for all active grid layers.
 
void check_continue_file ( ifstream &fcontinue, bool &fld, bool &scl, int &tab, int &nxmin, int &nxmax, int &nymin, int &nymax, int &nzmin, int &nzmax, int &laymax, int &ln, int *jbs, int *kbs, int *lbs)
 Checks if parameters in the restart file match the current simulation setup.
 
void output_params ( ofstream &fileall, bool &fld, bool &scl, int &tab, int &nxmin, int &nxmax, int &nymin, int &nymax, int &nzmin, int &nzmax, int &laymax, int &ln, int *jbs, int *kbs, int *lbs)
 Writes essential simulation parameters to the header of the restart file.
 
void initial_read (ifstream &fin, long int &mstep, double &tmax, int &tab, double &amp, int &nxmin, int &nxmax, int &nymin, int &nymax, int &nzmin, int &nzmax, double &xmin, double &xmax, double &ymin, double &ymax, double &zmin, double &zmax, double &cfl, double &cdt, double &etaa, double &etab, double &etabb, double &KOep, int &exg, int &contn, char *file_continue, double &mu, double &kk, double &xi2, double &xi3, double &w3, double &mus, double &kks, double &xi2s, double &xi3s, double &Hb, double &fluidw, double &Mkap, double &bminmod, double &ptintval1, double &ptintval2, double &changept)
 Reads simulation parameters from the main initialization file (par_ini.d).
 
void initial_fmr ( ifstream &fin, int &laymax, int *jbs, int *kbs, int *lbs, double *alp_fmr)
 Reads Fixed Mesh Refinement (FMR) parameters from par_fmr.d.
 
void ahf_read (ifstream &fin, double &AHFstart, int &ahcint, int &ahpint, int &ntheta, int &nphi, int &ahloop, double &etaah, double &facn, double &err_p, double &err_e, double &ahc)
 Reads Apparent Horizon Finder (AHF) parameters from par_ahf.d.
 
int main (int argc, char *argv[])
 Main function for the COSMOS simulation code.
 

Function Documentation

◆ ahf_read()

void ahf_read ( ifstream & fin,
double & AHFstart,
int & ahcint,
int & ahpint,
int & ntheta,
int & nphi,
int & ahloop,
double & etaah,
double & facn,
double & err_p,
double & err_e,
double & ahc )

Reads Apparent Horizon Finder (AHF) parameters from par_ahf.d.

Parameters
finInput file stream for par_ahf.d.
AHFstartSimulation time at which to start searching for apparent horizons.
ahcintTime step interval between AHF calls.
ahpintTime step interval for printing detailed AH information (e.g., shape).
nthetaNumber of grid points in the theta direction for the AHF surface.
nphiNumber of grid points in the phi direction for the AHF surface.
ahloopMaximum number of iterations allowed for the AHF solver.
etaahRelaxation parameter (eta) for the AHF elliptic solver. (Note: parameter name mismatch with variable var in main)
facnMixing factor for using the previous step's solution as an initial guess.
err_pTolerance for the Poisson solver part of the AHF.
err_eTolerance for the main apparent horizon equation solver.
ahcInitial guess for the coordinate radius of the apparent horizon.

Reads parameters controlling the behavior and execution of the apparent horizon finder from the par_ahf.d file. Aborts if the file cannot be opened.

Here is the caller graph for this function:

◆ check_continue_file()

void check_continue_file ( ifstream & fcontinue,
bool & fld,
bool & scl,
int & tab,
int & nxmin,
int & nxmax,
int & nymin,
int & nymax,
int & nzmin,
int & nzmax,
int & laymax,
int & ln,
int * jbs,
int * kbs,
int * lbs )

Checks if parameters in the restart file match the current simulation setup.

Parameters
fcontinueInput file stream for the restart file (out_all.dat).
fldBoolean indicating if fluid evolution is enabled (checked against file).
sclBoolean indicating if scalar field evolution is enabled (checked against file).
tabNumber of ghost zones (checked against file).
nxminMinimum x-index (checked against file).
nxmaxMaximum x-index (checked against file).
nyminMinimum y-index (checked against file).
nymaxMaximum y-index (checked against file).
nzminMinimum z-index (checked against file).
nzmaxMaximum z-index (checked against file).
laymaxMaximum allowed FMR layer number (checked against file's ln).
lnCurrent FMR layer number (read from file).
jbsArray of x-boundaries for FMR layers (checked against file).
kbsArray of y-boundaries for FMR layers (checked against file).
lbsArray of z-boundaries for FMR layers (checked against file).

Reads header lines from the restart file (out_all.dat) and compares the stored parameters (like grid dimensions, enabled physics modules, FMR setup) against the parameters provided from the current run's configuration. If any mismatch is found, it prints an error message and exits the program. It also reads the number of layers (ln) present in the restart file.

Here is the caller graph for this function:

◆ initial_fmr()

void initial_fmr ( ifstream & fin,
int & laymax,
int * jbs,
int * kbs,
int * lbs,
double * alp_fmr )

Reads Fixed Mesh Refinement (FMR) parameters from par_fmr.d.

Parameters
finInput file stream for par_fmr.d.
laymaxMaximum number of FMR layers allowed.
jbsArray to store the x-index boundary for each FMR layer.
kbsArray to store the y-index boundary for each FMR layer.
lbsArray to store the z-index boundary for each FMR layer.
alp_fmrArray to store the central lapse function value threshold for adding each FMR layer.

Reads the maximum number of layers and then iteratively reads the grid index boundaries (j, k, l) and the lapse threshold (alp_fmr) for triggering the creation of each refinement layer. Aborts if the file cannot be opened.

Here is the caller graph for this function:

◆ initial_read()

void initial_read ( ifstream & fin,
long int & mstep,
double & tmax,
int & tab,
double & amp,
int & nxmin,
int & nxmax,
int & nymin,
int & nymax,
int & nzmin,
int & nzmax,
double & xmin,
double & xmax,
double & ymin,
double & ymax,
double & zmin,
double & zmax,
double & cfl,
double & cdt,
double & etaa,
double & etab,
double & etabb,
double & KOep,
int & exg,
int & contn,
char * file_continue,
double & mu,
double & kk,
double & xi2,
double & xi3,
double & w3,
double & mus,
double & kks,
double & xi2s,
double & xi3s,
double & Hb,
double & fluidw,
double & Mkap,
double & bminmod,
double & ptintval1,
double & ptintval2,
double & changept )

Reads simulation parameters from the main initialization file (par_ini.d).

Parameters
finInput file stream for par_ini.d.
mstepMaximum number of time steps.
tmaxMaximum simulation time.
tabNumber of ghost zones.
ampAmplitude parameter for inhomogeneous grid stretching.
nxminMinimum x-index.
nxmaxMaximum x-index.
nyminMinimum y-index.
nymaxMaximum y-index.
nzminMinimum z-index.
nzmaxMaximum z-index.
xminMinimum x-coordinate.
xmaxMaximum x-coordinate.
yminMinimum y-coordinate.
ymaxMaximum y-coordinate.
zminMinimum z-coordinate.
zmaxMaximum z-coordinate.
cflCFL factor for time step calculation.
cdtCosmological time scale factor for time step.
etaaGauge parameter eta_alpha for 1+log slicing.
etabGauge parameter eta_beta for Gamma-driver shift.
etabbGauge parameter eta_B for Gamma-driver shift.
KOepCoefficient for Kreiss-Oliger dissipation.
exgGrid index for excision boundary (if used).
contnFlag indicating whether to continue from a restart file (1=yes, 0=no).
file_continueName of the restart file (e.g., "out_all.dat").
muAmplitude of the initial metric perturbation.
kkWavenumber/scale of the initial metric perturbation.
xi2Non-sphericity parameter 1 for metric perturbation.
xi3Non-sphericity parameter 2 for metric perturbation.
w3Non-sphericity parameter 3 for metric perturbation.
musAmplitude of the initial scalar field perturbation.
kksWavenumber/scale of the initial scalar field perturbation.
xi2sNon-sphericity parameter 1 for scalar field perturbation Laplacian.
xi3sNon-sphericity parameter 2 for scalar field perturbation Laplacian.
HbInitial Hubble parameter.
fluidwEquation of state parameter (w = P/rho) for the fluid.
MkapKappa parameter for MUSCL reconstruction in fluid dynamics.
bminmodBeta parameter for the minmod limiter in fluid dynamics.
ptintval1Initial time interval for printing output.
ptintval2Secondary time interval for printing output.
changeptTime at which the printing interval switches from ptintval1 to ptintval2.

Reads parameters line by line from par_ini.d, skipping comment lines starting with '#'. Uses sscanf to parse values. Aborts if the file cannot be opened.

Here is the caller graph for this function:

◆ main()

int main ( int argc,
char * argv[] )

Main function for the COSMOS simulation code.

Parameters
argcNumber of command-line arguments.
argvArray of command-line arguments.
Returns
0 on successful completion. Exits with non-zero status on error.

This is the main driver routine for the simulation. It performs the following steps:

  1. Reads simulation parameters from par_ini.d, par_fmr.d, and par_ahf.d.
  2. Initializes the base grid (Fmv) and potentially higher FMR layers (Fmv1).
  3. Initializes the Apparent Horizon Finder (Ahf2d).
  4. Sets up initial data, either from scratch using parameters or by loading from a restart file (out_all.dat).
  5. Enters the main time evolution loop (using 4th-order Runge-Kutta via BSSN calls).
  6. Manages the addition and evolution of FMR layers based on central lapse values.
  7. Periodically calls the AHF to search for and track apparent horizons.
  8. Handles output of data slices, constraints, AH properties, and full restart files.
  9. Performs final checks and cleanup.
Here is the call graph for this function:

◆ output_params()

void output_params ( ofstream & fileall,
bool & fld,
bool & scl,
int & tab,
int & nxmin,
int & nxmax,
int & nymin,
int & nymax,
int & nzmin,
int & nzmax,
int & laymax,
int & ln,
int * jbs,
int * kbs,
int * lbs )

Writes essential simulation parameters to the header of the restart file.

Parameters
fileallOutput file stream for the restart file (out_all.dat).
fldBoolean indicating if fluid evolution is enabled.
sclBoolean indicating if scalar field evolution is enabled.
tabNumber of ghost zones.
nxminMinimum x-index.
nxmaxMaximum x-index.
nyminMinimum y-index.
nymaxMaximum y-index.
nzminMinimum z-index.
nzmaxMaximum z-index.
laymaxMaximum allowed FMR layer number (informational, not strictly needed for restart).
lnCurrent FMR layer number being saved.
jbsArray of x-boundaries for FMR layers.
kbsArray of y-boundaries for FMR layers.
lbsArray of z-boundaries for FMR layers.

Writes specially formatted comment lines (##key=value) at the beginning of the out_all.dat file. These lines store crucial parameters needed to correctly interpret the data during a restart, ensuring consistency.

Here is the caller graph for this function:

◆ printpack()

void printpack ( Fmv0 ** fmv0,
int ln,
int pk,
int pl,
ofstream & filex,
ofstream & filey,
ofstream & filez,
ofstream & filex0z,
ofstream & filexy0 )

Helper function to call print routines for all active grid layers.

Parameters
fmv0Array of pointers to Fmv0 objects (grid hierarchy).
lnCurrent highest layer index.
pkY-index for slices.
plZ-index for slices.
filexOutput stream for x-slices.
fileyOutput stream for y-slices.
filezOutput stream for z-slices.
filex0zOutput stream for xz-plane slices.
filexy0Output stream for xy-plane slices.

Iterates through the grid hierarchy, calls dyntoprim if needed, and then calls the respective print methods (print_x, print_y, print_z, print_xz, print_xy) for each layer.

Here is the caller graph for this function: