-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed analytic FRW background implemented
- Loading branch information
melley95
committed
Sep 25, 2024
1 parent
495c0b0
commit ca16fed
Showing
11 changed files
with
725 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
#ifndef DIAGNOSTICVARIABLES_HPP | ||
#define DIAGNOSTICVARIABLES_HPP | ||
|
||
// assign an enum to each variable | ||
enum | ||
{ | ||
c_scalefac, | ||
c_hubbleparam, | ||
NUM_DIAGNOSTIC_VARS | ||
}; | ||
|
||
namespace DiagnosticVariables | ||
{ | ||
static const std::array<std::string, NUM_DIAGNOSTIC_VARS> variable_names = { | ||
"scalefac", "hubbleparam"}; | ||
} | ||
|
||
#endif /* DIAGNOSTICVARIABLES_HPP */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
// General includes common to most GR problems | ||
#include "FRWScalarLevel.hpp" | ||
#include "AMRReductions.hpp" | ||
#include "BoxLoops.hpp" | ||
#include "ComputePack.hpp" | ||
#include "NanCheck.hpp" | ||
#include "SetValue.hpp" | ||
#include "SmallDataIO.hpp" | ||
|
||
// For tag cells | ||
#include "FixedGridsTaggingCriterion.hpp" | ||
|
||
// Problem specific includes | ||
#include "InitialScalarData.hpp" | ||
#include "FRW.hpp" | ||
#include "MatterEvolution.hpp" | ||
#include "ScalarField.hpp" | ||
#include "ScalarPotential.hpp" | ||
|
||
// Initial data for field and metric variables | ||
void FRWScalarLevel::initialData() | ||
{ | ||
CH_TIME("FRWScalarLevel::initialData"); | ||
if (m_verbosity) | ||
pout() << "FRWScalarLevel::initialData " << m_level << endl; | ||
|
||
// First set everything to zero ... we don't want undefined values in | ||
// constraints etc, then initial conditions for fields | ||
SetValue set_zero(0.0); | ||
FRW frw_bg(m_p.bg_params, m_dx, m_time); | ||
InitialScalarData initial_sf(m_p.initial_params, m_dx); | ||
auto compute_pack = make_compute_pack(set_zero, frw_bg); | ||
BoxLoops::loop(compute_pack, m_state_diagnostics, m_state_diagnostics, | ||
SKIP_GHOST_CELLS); | ||
BoxLoops::loop(initial_sf, m_state_new, m_state_new, FILL_GHOST_CELLS); | ||
|
||
} | ||
|
||
// Things to do in RHS update, at each RK4 step | ||
void FRWScalarLevel::specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs, | ||
const double a_time) | ||
{ | ||
// Calculate MatterCCZ4 right hand side with matter_t = ScalarField | ||
// We don't want undefined values floating around in the constraints so | ||
// zero these | ||
ScalarPotential potential(m_p.initial_params); | ||
ScalarFieldWithPotential scalar_field(potential); | ||
FRW frw_bg(m_p.bg_params, m_dx, m_time); | ||
MatterEvolution<ScalarFieldWithPotential, FRW> my_matter( | ||
scalar_field, frw_bg, m_p.sigma, m_dx, m_p.center); | ||
BoxLoops::loop(my_matter, a_soln, a_rhs, SKIP_GHOST_CELLS); | ||
|
||
} | ||
|
||
void FRWScalarLevel::specificPostTimeStep() | ||
{ | ||
// Check for nans on every level | ||
if (m_p.nan_check) | ||
BoxLoops::loop(NanCheck(), m_state_new, m_state_new, SKIP_GHOST_CELLS, | ||
disable_simd()); | ||
|
||
// At any level, but after the min_level timestep | ||
int min_level = 0; // TODO: extraction | ||
bool calculate_diagnostics = at_level_timestep_multiple(min_level); | ||
if (calculate_diagnostics) | ||
{ | ||
fillAllGhosts(); | ||
ScalarPotential potential(m_p.initial_params); | ||
ScalarFieldWithPotential scalar_field(potential); | ||
FRW frw_bg(m_p.bg_params, m_dx, m_time); | ||
BoxLoops::loop(frw_bg, m_state_new, | ||
m_state_diagnostics, SKIP_GHOST_CELLS); | ||
|
||
} | ||
|
||
// write out the integral after each timestep on minimum level | ||
|
||
} | ||
|
||
void FRWScalarLevel::computeTaggingCriterion(FArrayBox &tagging_criterion, | ||
const FArrayBox ¤t_state) | ||
{ | ||
BoxLoops::loop(FixedGridsTaggingCriterion(m_dx, m_level, m_p.L, m_p.center), | ||
current_state, tagging_criterion); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
#ifndef FRWSCALARLEVEL_HPP_ | ||
#define FRWSCALARLEVEL_HPP_ | ||
|
||
#include "DefaultLevelFactory.hpp" | ||
#include "GRAMRLevel.hpp" | ||
// Problem specific includes | ||
#include "ScalarField.hpp" | ||
#include "ScalarPotential.hpp" | ||
|
||
//! A class for the evolution of a scalar field, minimally coupled to gravity | ||
/*! | ||
The class takes some initial data for a scalar field (variables phi and Pi) | ||
and evolves it using the CCZ4 equations. It is possible to specify an | ||
initial period of relaxation for the conformal factor chi, for non analytic | ||
initial conditions (for example, a general field configuration at a moment of | ||
time symmetry assuming conformal flatness). \sa MatterCCZ4(), | ||
ConstraintsMatter(), ScalarField(), RelaxationChi() | ||
*/ | ||
class FRWScalarLevel : public GRAMRLevel | ||
{ | ||
friend class DefaultLevelFactory<FRWScalarLevel>; | ||
// Inherit the contructors from GRAMRLevel | ||
using GRAMRLevel::GRAMRLevel; | ||
|
||
// Typedef for scalar field | ||
typedef ScalarField<ScalarPotential> ScalarFieldWithPotential; | ||
|
||
//! Initialize data for the field and metric variables | ||
virtual void initialData(); | ||
|
||
//! RHS routines used at each RK4 step | ||
virtual void specificEvalRHS(GRLevelData &a_soln, GRLevelData &a_rhs, | ||
const double a_time); | ||
|
||
//! To do after each timestep | ||
virtual void specificPostTimeStep(); | ||
|
||
//! Tell Chombo how to tag cells for regridding | ||
virtual void computeTaggingCriterion(FArrayBox &tagging_criterion, | ||
const FArrayBox ¤t_state); | ||
}; | ||
|
||
#endif /* FRWSCALARLEVEL_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- Mode: Makefile -*- | ||
|
||
### This makefile produces an executable for each name in the `ebase' | ||
### variable using the libraries named in the `LibNames' variable. | ||
|
||
# Included makefiles need an absolute path to the Chombo installation | ||
# CHOMBO_HOME := Please set the CHOMBO_HOME locally (e.g. export CHOMBO_HOME=... in bash) | ||
# GRCHOMBO_SOURCE := Set locally (e.g. export GRCHOMBO_SOURCE=path/to/GRChombo/Source in bash) | ||
|
||
GRDZHADZHA_SOURCE = ../../Source | ||
|
||
ebase := Main_FRWScalar | ||
|
||
LibNames := AMRTimeDependent AMRTools BoxTools | ||
|
||
src_dirs := $(GRCHOMBO_SOURCE)/utils \ | ||
$(GRCHOMBO_SOURCE)/simd \ | ||
$(GRCHOMBO_SOURCE)/BoxUtils \ | ||
$(GRCHOMBO_SOURCE)/GRChomboCore \ | ||
$(GRCHOMBO_SOURCE)/TaggingCriteria \ | ||
$(GRCHOMBO_SOURCE)/AMRInterpolator \ | ||
$(GRDZHADZHA_SOURCE)/Background \ | ||
$(GRDZHADZHA_SOURCE)/Matter | ||
|
||
include $(CHOMBO_HOME)/mk/Make.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
#ifndef INITIALSCALARDATA_HPP_ | ||
#define INITIALSCALARDATA_HPP_ | ||
|
||
#include "ScalarField.hpp" | ||
#include "UserVariables.hpp" //This files needs NUM_VARS - total no. components | ||
#include "VarsTools.hpp" | ||
#include "simd.hpp" | ||
|
||
//! Class which creates a constant scalar field given params for initial | ||
//! matter config | ||
class InitialScalarData | ||
{ | ||
public: | ||
struct params_t | ||
{ | ||
double mass; | ||
double amplitude; | ||
std::array<double, CH_SPACEDIM> center; | ||
}; | ||
|
||
//! The constructor for the class | ||
InitialScalarData(const params_t a_params, const double a_dx) | ||
: m_params(a_params), m_dx(a_dx) | ||
{ | ||
} | ||
|
||
//! Function to compute the value of all the initial vars on the grid | ||
template <class data_t> void compute(Cell<data_t> current_cell) const | ||
{ | ||
|
||
ScalarField<>::Vars<data_t> vars; | ||
VarsTools::assign(vars, 0.); | ||
|
||
Coordinates<data_t> coords(current_cell, m_dx, m_params.center); | ||
data_t radius = coords.get_radius(); | ||
data_t x = coords.x; | ||
double y = coords.y; | ||
double z = coords.z; | ||
|
||
// set the field vars | ||
data_t f_of_r = | ||
m_params.amplitude * exp(-(radius - 20.0) * (radius - 20.0) / 10.0); | ||
vars.phi = f_of_r * x / radius; | ||
vars.Pi = -f_of_r * y / radius; | ||
|
||
current_cell.store_vars(vars); | ||
} | ||
|
||
protected: | ||
const double m_dx; | ||
const params_t m_params; | ||
}; | ||
|
||
#endif /* INITIALSCALARDATA_HPP_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
#include "parstream.H" //Gives us pout() | ||
#include <iostream> | ||
|
||
#include "DefaultLevelFactory.hpp" | ||
#include "GRAMR.hpp" | ||
#include "GRParmParse.hpp" | ||
#include "SetupFunctions.hpp" | ||
#include "SimulationParameters.hpp" | ||
|
||
// Problem specific includes: | ||
#include "FRWScalarLevel.hpp" | ||
|
||
int runGRChombo(int argc, char *argv[]) | ||
{ | ||
// Load the parameter file and construct the SimulationParameter class | ||
// To add more parameters edit the SimulationParameters file. | ||
char *in_file = argv[1]; | ||
GRParmParse pp(argc - 2, argv + 2, NULL, in_file); | ||
SimulationParameters sim_params(pp); | ||
|
||
// The line below selects the problem that is simulated | ||
// (To simulate a different problem, define a new child of AMRLevel | ||
// and an associated LevelFactory) | ||
GRAMR gr_amr; | ||
DefaultLevelFactory<FRWScalarLevel> scalar_field_level_fact(gr_amr, | ||
sim_params); | ||
setupAMRObject(gr_amr, scalar_field_level_fact); | ||
|
||
// call this after amr object setup so grids known | ||
// and need it to stay in scope throughout run | ||
AMRInterpolator<Lagrange<4>> interpolator( | ||
gr_amr, sim_params.origin, sim_params.dx, sim_params.boundary_params, | ||
sim_params.verbosity); | ||
gr_amr.set_interpolator(&interpolator); | ||
|
||
// Engage! Run the evolution | ||
gr_amr.run(sim_params.stop_time, sim_params.max_steps); | ||
gr_amr.conclude(); | ||
|
||
return 0; | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
mainSetup(argc, argv); | ||
|
||
int status = runGRChombo(argc, argv); | ||
|
||
if (status == 0) | ||
pout() << "GRChombo finished." << std::endl; | ||
else | ||
pout() << "GRChombo failed with return code " << status << std::endl; | ||
|
||
mainFinalize(); | ||
return status; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* GRChombo | ||
* Copyright 2012 The GRChombo collaboration. | ||
* Please refer to LICENSE in GRChombo's root directory. | ||
*/ | ||
|
||
#ifndef SCALARPOTENTIAL_HPP_ | ||
#define SCALARPOTENTIAL_HPP_ | ||
|
||
#include "simd.hpp" | ||
|
||
class ScalarPotential | ||
{ | ||
protected: | ||
// const double m_mu; | ||
const InitialScalarData::params_t m_initial_params; | ||
|
||
public: | ||
//! The constructor | ||
ScalarPotential(const InitialScalarData::params_t a_initial_params) | ||
: m_initial_params(a_initial_params) | ||
{ | ||
} | ||
|
||
//! Set the potential function for the scalar field here | ||
template <class data_t, template <typename> class vars_t> | ||
void compute_potential(data_t &V_of_phi, data_t &dVdphi, | ||
const vars_t<data_t> &vars) const | ||
{ | ||
// The potential value at phi | ||
// 1/2 m^2 phi^2 | ||
const double mu = m_initial_params.mass; | ||
V_of_phi = 0.5 * mu * mu * vars.phi * vars.phi; | ||
|
||
// The potential gradient at phi wrt the field | ||
// m^2 phi | ||
dVdphi = mu * mu * vars.phi; | ||
} | ||
}; | ||
|
||
#endif /* SCALARPOTENTIAL_HPP_ */ |
Oops, something went wrong.