Skip to content

Commit

Permalink
Change to Cosmo example
Browse files Browse the repository at this point in the history
  • Loading branch information
AreefW committed Oct 22, 2024
1 parent 1fae5ef commit edf2740
Show file tree
Hide file tree
Showing 22 changed files with 244 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ log*
*.dSYM
*.patch
*.log
*.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Please refer to LICENSE in GRChombo's root directory.
*/

#ifndef INFLATIONDIAGNOSTICS_HPP_
#define INFLATIONDIAGNOSTICS_HPP_
#ifndef COSMODIAGNOSTICS_HPP_
#define COSMODIAGNOSTICS_HPP_

#include "CCZ4Geometry.hpp"
#include "CCZ4Vars.hpp"
Expand All @@ -22,7 +22,7 @@
//! are stored as diagnostics

template <class matter_t>
class InflationDiagnostics // public MatterConstraints<matter_t>
class CosmoDiagnostics // public MatterConstraints<matter_t>
{
public:
// Inherit the variable definitions from CCZ4 + matter_t
Expand All @@ -45,8 +45,8 @@ class InflationDiagnostics // public MatterConstraints<matter_t>
}
};

//! Constructor of class InflationDiagnostics
InflationDiagnostics(const matter_t a_matter, double dx, double G_Newton)
//! Constructor of class CosmoDiagnostics
CosmoDiagnostics(const matter_t a_matter, double dx, double G_Newton)
: m_matter(a_matter), m_deriv(dx)
{
}
Expand All @@ -60,6 +60,6 @@ class InflationDiagnostics // public MatterConstraints<matter_t>
const FourthOrderDerivatives m_deriv;
};

#include "InflationDiagnostics.impl.hpp"
#include "CosmoDiagnostics.impl.hpp"

#endif /* INFLATIONDIAGNOSTICS_HPP_ */
#endif /* COSMODIAGNOSTICS_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
* Please refer to LICENSE in GRChombo's root directory.
*/

#if !defined(INFLATIONDIAGNOSTICS_HPP_)
#error "This file should only be included through InflationDiagnostics.hpp"
#if !defined(COSMODIAGNOSTICS_HPP_)
#error "This file should only be included through CosmoDiagnostics.hpp"
#endif

#ifndef INFLATIONDIAGNOSTICS_IMPL_HPP_
#define INFLATIONDIAGNOSTICS_IMPL_HPP_
#ifndef COSMODIAGNOSTICS_IMPL_HPP_
#define COSMODIAGNOSTICS_IMPL_HPP_
#include "DimensionDefinitions.hpp"

template <class matter_t>
template <class data_t>
void InflationDiagnostics<matter_t>::compute(Cell<data_t> current_cell) const
void CosmoDiagnostics<matter_t>::compute(Cell<data_t> current_cell) const
{
// Load local vars and calculate derivs
const auto vars = current_cell.template load_vars<Vars>();
Expand Down Expand Up @@ -53,4 +53,4 @@ void InflationDiagnostics<matter_t>::compute(Cell<data_t> current_cell) const
// store_vars(out, current_cell);
}

#endif /* INFLATIONDIAGNOSTICS_IMPL_HPP_ */
#endif /* COSMODIAGNOSTICS_IMPL_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

// General includes common to most GR problems
#include "InflationLevel.hpp"
#include "CosmoLevel.hpp"
#include "BoxLoops.hpp"
#include "NanCheck.hpp"
#include "PositiveChiAndAlpha.hpp"
Expand All @@ -23,9 +23,9 @@
// Problem specific includes
#include "AMRReductions.hpp"
#include "ComputePack.hpp"
#include "CosmoDiagnostics.hpp"
#include "CosmoMovingPunctureGauge.hpp"
#include "GammaCalculator.hpp"
#include "InflationDiagnostics.hpp"
#include "InitialK.hpp"
#include "InitialScalarData.hpp"
#include "Potential.hpp"
Expand All @@ -36,7 +36,7 @@
#include "CustomExtraction.hpp"

// Things to do at each advance step, after the RK4 is calculated
void InflationLevel::specificAdvance()
void CosmoLevel::specificAdvance()
{
// Enforce trace free A_ij and positive chi and alpha
BoxLoops::loop(
Expand All @@ -52,11 +52,11 @@ void InflationLevel::specificAdvance()
}

// Initial data for field and metric variables
void InflationLevel::initialData()
void CosmoLevel::initialData()
{
CH_TIME("InflationLevel::initialData");
CH_TIME("CosmoLevel::initialData");
if (m_verbosity)
pout() << "InflationLevel::initialData " << m_level << endl;
pout() << "CosmoLevel::initialData " << m_level << endl;

// First set everything to zero then initial conditions for scalar field -
// Set initial condition of inflaton, see details in Potential.hpp and
Expand All @@ -82,7 +82,7 @@ void InflationLevel::initialData()

#ifdef CH_USE_HDF5
// Things to do before outputting a checkpoint file
void InflationLevel::prePlotLevel()
void CosmoLevel::prePlotLevel()
{
fillAllGhosts();
Potential potential(m_p.potential_params, m_p.L, m_p.scalar_field_mode);
Expand All @@ -91,16 +91,16 @@ void InflationLevel::prePlotLevel()
MatterConstraints<ScalarFieldWithPotential>(
scalar_field, m_dx, m_p.G_Newton, c_Ham, Interval(c_Mom, c_Mom)),
m_state_new, m_state_diagnostics, EXCLUDE_GHOST_CELLS);
InflationDiagnostics<ScalarFieldWithPotential> inflation_diagnostics(
CosmoDiagnostics<ScalarFieldWithPotential> cosmo_diagnostics(
scalar_field, m_dx, m_p.G_Newton);
BoxLoops::loop(inflation_diagnostics, m_state_new, m_state_diagnostics,
BoxLoops::loop(cosmo_diagnostics, m_state_new, m_state_diagnostics,
EXCLUDE_GHOST_CELLS);
}
#endif

// Things to do in RHS update, at each RK4 step
void InflationLevel::specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs,
const double a_time)
void CosmoLevel::specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs,
const double a_time)
{
// Enforce trace free A_ij and positive chi and alpha
BoxLoops::loop(
Expand Down Expand Up @@ -132,28 +132,28 @@ void InflationLevel::specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs,
}

// Things to do at ODE update, after soln + rhs
void InflationLevel::specificUpdateODE(GRLevelData &a_soln,
const GRLevelData &a_rhs, Real a_dt)
void CosmoLevel::specificUpdateODE(GRLevelData &a_soln,
const GRLevelData &a_rhs, Real a_dt)
{
// Enforce trace free A_ij
BoxLoops::loop(TraceARemoval(), a_soln, a_soln, INCLUDE_GHOST_CELLS);
}

void InflationLevel::preTagCells()
void CosmoLevel::preTagCells()
{
// we don't need any ghosts filled for the fixed grids tagging criterion
// used here so don't fill any
}

void InflationLevel::computeTaggingCriterion(
void CosmoLevel::computeTaggingCriterion(
FArrayBox &tagging_criterion, const FArrayBox &current_state,
const FArrayBox &current_state_diagnostics)
{
BoxLoops::loop(
FixedGridsTaggingCriterion(m_dx, m_level, 2.0 * m_p.L, m_p.center),
current_state, tagging_criterion);
}
void InflationLevel::specificPostTimeStep()
void CosmoLevel::specificPostTimeStep()
{
int min_level = 0;
bool calculate_diagnostics = at_level_timestep_multiple(min_level);
Expand All @@ -173,9 +173,9 @@ void InflationLevel::specificPostTimeStep()
Interval(c_Mom, c_Mom), c_Ham_abs_sum,
Interval(c_Mom_abs_sum, c_Mom_abs_sum)),
m_state_new, m_state_diagnostics, EXCLUDE_GHOST_CELLS);
InflationDiagnostics<ScalarFieldWithPotential> inflation_diagnostics(
CosmoDiagnostics<ScalarFieldWithPotential> cosmo_diagnostics(
scalar_field, m_dx, m_p.G_Newton);
BoxLoops::loop(inflation_diagnostics, m_state_new, m_state_diagnostics,
BoxLoops::loop(cosmo_diagnostics, m_state_new, m_state_diagnostics,
EXCLUDE_GHOST_CELLS);

if (m_level == min_level)
Expand Down Expand Up @@ -227,7 +227,8 @@ void InflationLevel::specificPostTimeStep()

// set up the query and execute it
std::array<double, CH_SPACEDIM> extr_point = {
0., 0., 0.}; // specified point
0., m_p.L / 2, m_p.L / 2}; // specified point {x \in [0,L],y \in
// [0,L], z \in [0,L]}
CustomExtraction extraction(c_rho, m_p.lineout_num_points, m_p.L,
extr_point, m_dt, m_time);
extraction.execute_query(&interpolator, m_p.data_path + "lineout");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
time symmetry assuming conformal flatness). \sa MatterCCZ4(),
ConstraintsMatter(), ScalarField(), RelaxationChi()
*/
class InflationLevel : public GRAMRLevel
class CosmoLevel : public GRAMRLevel
{
friend class DefaultLevelFactory<InflationLevel>;
friend class DefaultLevelFactory<CosmoLevel>;
// Inherit the contructors from GRAMRLevel
using GRAMRLevel::GRAMRLevel;

Expand Down Expand Up @@ -66,4 +66,4 @@ class InflationLevel : public GRAMRLevel
virtual void specificPostTimeStep() override;
};

#endif /* INFLATIONLEVEL_HPP_ */
#endif /* COSMOLEVEL_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ class CustomExtraction
std::vector<double> interp_z(m_num_points);

// Work out the coordinates
// go out along x-axis from m_origin to L/2
// go out along x-axis from m_origin to L
for (int idx = 0; idx < m_num_points; ++idx)
{
interp_x[idx] =
m_origin[0] + (double(idx) / double(m_num_points) * 0.5 * m_L);
m_origin[0] + (double(idx) / double(m_num_points) * m_L);
interp_y[idx] = m_origin[1];
interp_z[idx] = m_origin[2];
}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

GRCHOMBO_SOURCE = ../../Source

ebase := Main_Inflation
ebase := Main_Cosmo

LibNames := AMRTimeDependent AMRTools BoxTools

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "SimulationParameters.hpp"

// Problem specific includes:
#include "InflationLevel.hpp"
#include "CosmoLevel.hpp"

// Chombo namespace
#include "UsingNamespace.H"
Expand All @@ -39,8 +39,8 @@ int runGRChombo(int argc, char *argv[])
// (To simulate a different problem, define a new child of AMRLevel
// and an associated LevelFactory)
CosmoAMR cosmo_amr;
DefaultLevelFactory<InflationLevel> scalar_field_level_fact(cosmo_amr,
sim_params);
DefaultLevelFactory<CosmoLevel> scalar_field_level_fact(cosmo_amr,
sim_params);
setupAMRObject(cosmo_amr, scalar_field_level_fact);

// call this after amr object setup so grids known
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Potential

// The potential gradient at phi
// m^2 phi
dVdphi = pow(m_params.scalar_mass, 2.0) * vars.phi;
dVdphi = pow(mass, 2.0) * vars.phi;
}
};

Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 9 additions & 9 deletions Examples/Inflation/params.txt → Examples/Cosmo/params.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ verbosity = 0

# location / naming of output files
# output_path = "" # Main path for all files. Must exist!
chk_prefix = Inflation_
plot_prefix = Inflationp_
# restart_file = Inflation_000000.3d.hdf5
chk_prefix = Cosmo_
plot_prefix = Cosmop_
# restart_file = Cosmo_000000.3d.hdf5

# HDF5files are written every dt = L/N*dt_multiplier*checkpoint_interval
checkpoint_interval = 500
checkpoint_interval = 1000
# set to 0 to turn off plot files (except at t=0 and t=stop_time)
# set to -1 to never ever print plotfiles
plot_interval = 100
num_plot_vars = 5
plot_vars = chi phi rho_scaled S_scaled K_scaled
plot_interval = 500
num_plot_vars = 7
plot_vars = chi phi rho_scaled S_scaled K_scaled Ham Mom

# subpaths - specific directories for hdf5, pout, extraction data
# (these are created at runtime)
Expand Down Expand Up @@ -50,7 +50,7 @@ scalar_mass = 1.0
scalar_field_mode = 1.0

# lineout params
lineout_num_points = 20
lineout_num_points = 10

#################################################
# Grid parameters
Expand Down Expand Up @@ -130,7 +130,7 @@ extrapolating_vars = phi Pi

# dt will be dx*dt_multiplier on each grid level
dt_multiplier = 0.5
stop_time = 100.0
stop_time = 100.
# max_steps = 4

# Spatial derivative order (only affects CCZ4 RHS)
Expand Down
Loading

0 comments on commit edf2740

Please sign in to comment.