Skip to content

Commit

Permalink
Add perfect fluid example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dina Traykova committed Jul 25, 2023
1 parent 9e34359 commit 9ca4f7b
Show file tree
Hide file tree
Showing 18 changed files with 1,653 additions and 0 deletions.
1 change: 1 addition & 0 deletions Examples/PerfectFluid/.#PerfectFluid.impl.hpp
31 changes: 31 additions & 0 deletions Examples/PerfectFluid/DefaultEoS.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/

#ifndef DEFAULTEOS_HPP_
#define DEFAULTEOS_HPP_

#include "Tensor.hpp"
#include "simd.hpp"

class DefaultEoS
{
public:
//! The constructor
DefaultEoS() {}

//! Set the potential function for the scalar field here to zero
template <class data_t, template <typename> class vars_t>
void compute_eos(data_t &P_of_rho0, data_t &dPdrho0,
const vars_t<data_t> &vars) const
{
// The pressure value at rho0
P_of_rho0 = 0.0;

// The pressure gradient at rho0
dPdrho0 = 0.0;
}
};

#endif /* DEFAULTEOS_HPP_ */
28 changes: 28 additions & 0 deletions Examples/PerfectFluid/DiagnosticVariables.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* 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
// todo: here add pressure, density, etc.
enum
{
c_Ham,

c_Mom,

NUM_DIAGNOSTIC_VARS
};

namespace DiagnosticVariables
{
static const std::array<std::string, NUM_DIAGNOSTIC_VARS> variable_names = {
"Ham",

"Mom"};
}

#endif /* DIAGNOSTICVARIABLES_HPP */
40 changes: 40 additions & 0 deletions Examples/PerfectFluid/EoS.hpp
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 EOS_HPP_
#define EOS_HPP_

#include "simd.hpp"

class EoS
{
public:
struct params_t
{
double eos_w;
};

private:
params_t m_params;

public:
//! The constructor
EoS(params_t a_params) : m_params(a_params) {}

//! Set the potential function for the scalar field here
template <class data_t, template <typename> class vars_t>
void compute_eos(data_t &P_of_rho0, data_t &dPdrho0,
const vars_t<data_t> &vars) const
{
// The pressure value at rho0
// w rho0
P_of_rho0 = m_params.eos_w * vars.rho0;

// The pressure gradient at rho0
dPdrho0 = m_params.eos_w;
}
};

#endif /* EOS_HPP_ */
25 changes: 25 additions & 0 deletions Examples/PerfectFluid/GNUmakefile
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 = ../../Source

ebase := Main_PerfectFluid

LibNames := AMRTimeDependent AMRTools BoxTools

src_dirs := $(GRCHOMBO_SOURCE)/utils \
$(GRCHOMBO_SOURCE)/simd \
$(GRCHOMBO_SOURCE)/CCZ4 \
$(GRCHOMBO_SOURCE)/Matter \
$(GRCHOMBO_SOURCE)/BoxUtils \
$(GRCHOMBO_SOURCE)/GRChomboCore \
$(GRCHOMBO_SOURCE)/TaggingCriteria \
$(GRCHOMBO_SOURCE)/AMRInterpolator \
$(GRCHOMBO_SOURCE)/InitialConditions/BlackHoles

include $(CHOMBO_HOME)/mk/Make.test
69 changes: 69 additions & 0 deletions Examples/PerfectFluid/InitialFluidData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/

#ifndef INITIALFLUIDDATA_HPP_
#define INITIALFLUIDDATA_HPP_

#include "Cell.hpp"
#include "Coordinates.hpp"
#include "MatterCCZ4RHS.hpp"
#include "PerfectFluid.hpp"
#include "Tensor.hpp"
#include "UserVariables.hpp" //This files needs NUM_VARS - total no. components
#include "VarsTools.hpp"
#include "simd.hpp"
//#include "PrimitiveRecovety.hpp"

//! Class which sets the initial scalar field matter config
class InitialFluidData
{
public:
//! A structure for the input params for fluid properties and initial
//! conditions
struct params_t
{
double amplitude; //
std::array<double, CH_SPACEDIM>
center; //!< Centre of perturbation in initial SF bubble
double delta;
double width; //!< Width of bump in initial SF bubble
};

//! The constructor
InitialFluidData(params_t a_params, double a_dx)
: m_dx(a_dx), m_params(a_params)
{
}

//! 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
{
// where am i?
Coordinates<data_t> coords(current_cell, m_dx, m_params.center);
data_t rr = coords.get_radius();
data_t rr2 = rr * rr;

// calculate the field value
data_t rho0 = m_params.amplitude *
(exp(-pow(rr / m_params.width, 2.0))) + m_params.delta;
data_t v2 = 0.;
data_t eps = 0.;
data_t P = rho0*(1.+eps)/3.;
data_t WW = 1./(1. - v2);
data_t hh = 1. + eps + P/rho0;

data_t D0 = rho0*sqrt(WW);
data_t Ec0 = rho0 * hh * WW - P - D0;
// store the vars
current_cell.store_vars(D0, c_D);
current_cell.store_vars(Ec0, c_Ec);
}

protected:
double m_dx;
const params_t m_params; //!< The matter initial condition params
};

#endif /* INITIALFLUIDDATA_HPP_ */
64 changes: 64 additions & 0 deletions Examples/PerfectFluid/Main_PerfectFluid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/

// Chombo includes
#include "parstream.H" //Gives us pout()

// System includes
#include <iostream>

// Our general includes
#include "DefaultLevelFactory.hpp"
#include "GRAMR.hpp"
#include "GRParmParse.hpp"
#include "SetupFunctions.hpp"
#include "SimulationParameters.hpp"

// Problem specific includes:
#include "PerfectFluidLevel.hpp"

// Chombo namespace
#include "UsingNamespace.H"

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);

if (sim_params.just_check_params)
return 0;

// 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<PerfectFluidLevel> perfect_fluid_level_fact(gr_amr,
sim_params);
setupAMRObject(gr_amr, perfect_fluid_level_fact);

// 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;
}
69 changes: 69 additions & 0 deletions Examples/PerfectFluid/Minkowski.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* GRChombo
* Copyright 2012 The GRChombo collaboration.
* Please refer to LICENSE in GRChombo's root directory.
*/

#ifndef MINKOWSKI_HPP_
#define MINKOWSKI_HPP_

#include "ADMConformalVars.hpp"
#include "Cell.hpp"
#include "CoordinateTransformations.hpp"
#include "Coordinates.hpp"
#include "Tensor.hpp"
#include "TensorAlgebra.hpp"
#include "UserVariables.hpp" //This files needs NUM_VARS - total number of components
#include "VarsTools.hpp"
#include "simd.hpp"

//! Class which computes the Kerr initial conditions per arXiv 1401.1548
class Minkowski
{
// Use the variable definition in CCZ4
template <class data_t>
using Vars = ADMConformalVars::VarsWithGauge<data_t>;

public:
//! Stuct for the params of the Kerr BH
struct params_t
{
double mass; //!<< The mass of the Kerr BH
std::array<double, CH_SPACEDIM> center; //!< The center of the Kerr BH
double spin; //!< The spin param a = J/M, so 0 <= |a| <= M
};

protected:
double m_dx;
params_t m_params;

public:
Minkowski(params_t a_params, double a_dx) : m_dx(a_dx), m_params(a_params)

{
// check this spin param is sensible
if (std::abs(m_params.spin) > m_params.mass)
{
MayDay::Error("The spin parameter must satisfy |a| <= M");
}
}

template <class data_t> void compute(Cell<data_t> current_cell) const;

protected:
//! Function which computes the components of the metric in spherical coords
template <class data_t>
void compute_kerr(
Tensor<2, data_t>
&spherical_g, //!<< The spatial metric in spherical coords
Tensor<2, data_t>
&spherical_K, //!<< The extrinsic curvature in spherical coords
Tensor<1, data_t>
&spherical_shift, //!<< The spherical components of the shift
data_t &kerr_lapse, //!<< The lapse for the kerr solution
const Coordinates<data_t> coords //!<< Coords of current cell
) const;
};

#include "Minkowski.impl.hpp"

#endif /* MINKOWSKI_HPP_ */
Loading

0 comments on commit 9ca4f7b

Please sign in to comment.