-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] prototype AGORA isolated galaxy #506
Draft
BenWibking
wants to merge
6
commits into
development
Choose a base branch
from
BenWibking/agora-galaxy
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7b83bc
prototype
BenWibking 1b0fd91
Merge branch 'development' into BenWibking/agora-galaxy
psharda 03e240d
Merge branch 'development' into BenWibking/agora-galaxy
BenWibking cc31803
Merge branch 'development' into BenWibking/agora-galaxy
psharda e3c86cd
Merge branch 'development' into BenWibking/agora-galaxy
psharda cc6f6ae
Merge branch 'development' into BenWibking/agora-galaxy
BenWibking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 @@ | ||
if (AMReX_SPACEDIM EQUAL 3) | ||
add_executable(agora_galaxy galaxy.cpp ${QuokkaObjSources}) | ||
if(AMReX_GPU_BACKEND MATCHES "CUDA") | ||
setup_target_for_cuda_compilation(agora_galaxy) | ||
endif() | ||
|
||
add_test(NAME AgoraGalaxy COMMAND agora_galaxy AgoraGalaxy.in WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests) | ||
endif() |
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,166 @@ | ||
//============================================================================== | ||
// TwoMomentRad - a radiation transport library for patch-based AMR codes | ||
// Copyright 2024 Benjamin Wibking. | ||
// Released under the MIT license. See LICENSE file included in the GitHub repo. | ||
//============================================================================== | ||
/// \file galaxy.cpp | ||
/// \brief Defines a simulation using the AGORA isolated galaxy initial conditions. | ||
/// | ||
|
||
#include <cmath> | ||
|
||
#include "AMReX_BC_TYPES.H" | ||
#include "AMReX_DistributionMapping.H" | ||
#include "AMReX_Geometry.H" | ||
#include "AMReX_MultiFab.H" | ||
#include "AMReX_ParmParse.H" | ||
#include "AMReX_REAL.H" | ||
|
||
#include "EOS.hpp" | ||
#include "RadhydroSimulation.hpp" | ||
#include "fundamental_constants.H" | ||
#include "galaxy.hpp" | ||
#include "hydro_system.hpp" | ||
|
||
struct AgoraGalaxy { | ||
}; | ||
|
||
template <> struct quokka::EOS_Traits<AgoraGalaxy> { | ||
static constexpr double gamma = 5. / 3.; | ||
static constexpr double mean_molecular_weight = C::m_u; | ||
static constexpr double boltzmann_constant = C::k_B; | ||
}; | ||
|
||
template <> struct HydroSystem_Traits<AgoraGalaxy> { | ||
static constexpr bool reconstruct_eint = true; | ||
}; | ||
|
||
template <> struct Physics_Traits<AgoraGalaxy> { | ||
static constexpr bool is_hydro_enabled = true; | ||
static constexpr bool is_radiation_enabled = false; | ||
static constexpr bool is_mhd_enabled = false; | ||
static constexpr int numMassScalars = 0; // number of mass scalars | ||
static constexpr int numPassiveScalars = numMassScalars + 0; // number of passive scalars | ||
static constexpr int nGroups = 1; // number of radiation groups | ||
}; | ||
|
||
template <> struct SimulationData<AgoraGalaxy> { | ||
std::vector<amrex::Real> radius{}; | ||
std::vector<amrex::Real> vcirc{}; | ||
}; | ||
|
||
template <> void RadhydroSimulation<AgoraGalaxy>::preCalculateInitialConditions() | ||
{ | ||
// 1. read in circular velocity table | ||
// 2. copy to GPU | ||
// 3. save interpolator object | ||
// | ||
// TODO(bwibking): implement. | ||
} | ||
|
||
template <> void RadhydroSimulation<AgoraGalaxy>::setInitialConditionsOnGrid(quokka::grid grid_elem) | ||
{ | ||
const amrex::Box &indexRange = grid_elem.indexRange_; | ||
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dx = grid_elem.dx_; | ||
const amrex::Array4<double> &state_cc = grid_elem.array_; | ||
const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> prob_lo = grid_elem.prob_lo_; | ||
const amrex::Real gamma = quokka::EOS_Traits<AgoraGalaxy>::gamma; | ||
|
||
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) { | ||
// Cartesian coordinates | ||
amrex::Real const x = prob_lo[0] + (i + static_cast<amrex::Real>(0.5)) * dx[0]; | ||
amrex::Real const y = prob_lo[1] + (j + static_cast<amrex::Real>(0.5)) * dx[1]; | ||
|
||
// cylindrical coordinates | ||
amrex::Real const R = std::sqrt(std::pow(x, 2) + std::pow(y, 2)); | ||
amrex::Real const theta = std::atan2(x, y); | ||
|
||
// compute double exponential density profile | ||
double const rho = 1.0e-22; // g cm^{-3} | ||
|
||
// interpolate circular velocity based on radius of cell center | ||
double const vcirc = 0; | ||
double const vx = vcirc * std::cos(theta); | ||
double const vy = vcirc * std::sin(theta); | ||
double const vz = 0; | ||
double const vsq = vx * vx + vy * vy + vz * vz; | ||
|
||
// compute temperature | ||
double T = NAN; | ||
if (R < 20.0e3 * C::parsec) { | ||
T = 1.0e4; // K | ||
} else { | ||
T = 1.0e6; // K | ||
} | ||
const double Eint = quokka::EOS<AgoraGalaxy>::ComputeEintFromTgas(rho, T); | ||
|
||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::density_index) = rho; | ||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::x1Momentum_index) = rho * vx; | ||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::x2Momentum_index) = rho * vy; | ||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::x3Momentum_index) = rho * vz; | ||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::energy_index) = Eint + 0.5 * rho * vsq; | ||
state_cc(i, j, k, HydroSystem<AgoraGalaxy>::internalEnergy_index) = Eint; | ||
}); | ||
} | ||
|
||
template <> void RadhydroSimulation<AgoraGalaxy>::createInitialParticles() | ||
{ | ||
// read particles from ASCII file | ||
const int nreal_extra = 4; // mass vx vy vz | ||
CICParticles->SetVerbose(1); | ||
CICParticles->InitFromAsciiFile("AgoraGalaxy_particles.txt", nreal_extra, nullptr); | ||
} | ||
|
||
template <> void RadhydroSimulation<AgoraGalaxy>::ComputeDerivedVar(int lev, std::string const &dname, amrex::MultiFab &mf, const int ncomp_cc_in) const | ||
{ | ||
// compute derived variables and save in 'mf' | ||
if (dname == "gpot") { | ||
const int ncomp = ncomp_cc_in; | ||
auto const &phi_arr = phi[lev].const_arrays(); | ||
auto output = mf.arrays(); | ||
amrex::ParallelFor(mf, [=] AMREX_GPU_DEVICE(int bx, int i, int j, int k) noexcept { output[bx](i, j, k, ncomp) = phi_arr[bx](i, j, k); }); | ||
} | ||
} | ||
|
||
auto problem_main() -> int | ||
{ | ||
auto isNormalComp = [=](int n, int dim) { | ||
if ((n == HydroSystem<AgoraGalaxy>::x1Momentum_index) && (dim == 0)) { | ||
return true; | ||
} | ||
if ((n == HydroSystem<AgoraGalaxy>::x2Momentum_index) && (dim == 1)) { | ||
return true; | ||
} | ||
if ((n == HydroSystem<AgoraGalaxy>::x3Momentum_index) && (dim == 2)) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
const int ncomp_cc = Physics_Indices<AgoraGalaxy>::nvarTotal_cc; | ||
amrex::Vector<amrex::BCRec> BCs_cc(ncomp_cc); | ||
for (int n = 0; n < ncomp_cc; ++n) { | ||
for (int i = 0; i < AMREX_SPACEDIM; ++i) { | ||
if (isNormalComp(n, i)) { | ||
BCs_cc[n].setLo(i, amrex::BCType::reflect_odd); | ||
BCs_cc[n].setHi(i, amrex::BCType::reflect_odd); | ||
} else { | ||
BCs_cc[n].setLo(i, amrex::BCType::reflect_even); | ||
BCs_cc[n].setHi(i, amrex::BCType::reflect_even); | ||
} | ||
} | ||
} | ||
|
||
// Problem initialization | ||
RadhydroSimulation<AgoraGalaxy> sim(BCs_cc); | ||
sim.doPoissonSolve_ = 1; // enable self-gravity | ||
|
||
// initialize | ||
sim.setInitialConditions(); | ||
|
||
// evolve | ||
sim.evolve(); | ||
|
||
const int status = 0; | ||
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,22 @@ | ||
#ifndef TEST_BINARY_ORBIT_HPP_ // NOLINT | ||
#define TEST_BINARY_ORBIT_HPP_ | ||
//============================================================================== | ||
// TwoMomentRad - a radiation transport library for patch-based AMR codes | ||
// Copyright 2020 Benjamin Wibking. | ||
// Released under the MIT license. See LICENSE file included in the GitHub repo. | ||
//============================================================================== | ||
/// \file binary_orbit.hpp | ||
/// \brief Defines a test problem for a binary orbit | ||
/// | ||
|
||
// external headers | ||
#include <fstream> | ||
|
||
// internal headers | ||
#include "hydro_system.hpp" | ||
#include "interpolate.hpp" | ||
|
||
// function definitions | ||
auto problem_main() -> int; | ||
|
||
#endif // TEST_BINARY_ORBIT_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
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,34 @@ | ||
# ***************************************************************** | ||
# Problem size and geometry | ||
# ***************************************************************** | ||
geometry.prob_lo = -2.5e13 -2.5e13 -2.5e13 | ||
geometry.prob_hi = 2.5e13 2.5e13 2.5e13 | ||
geometry.is_periodic = 0 0 0 | ||
|
||
# ***************************************************************** | ||
# VERBOSITY | ||
# ***************************************************************** | ||
amr.v = 1 # verbosity in Amr | ||
|
||
# ***************************************************************** | ||
# Resolution and refinement | ||
# ***************************************************************** | ||
amr.n_cell = 32 32 32 | ||
amr.max_level = 0 # number of levels = max_level + 1 | ||
amr.blocking_factor = 32 # grid size must be divisible by this | ||
amr.max_grid_size = 32 # at least 128 for GPUs | ||
amr.n_error_buf = 3 # minimum 3 cell buffer around tagged cells | ||
amr.grid_eff = 1.0 | ||
|
||
cfl = 0.3 | ||
max_timesteps = 8000 | ||
stop_time = 5.0e7 # s | ||
|
||
do_reflux = 1 | ||
do_subcycle = 0 | ||
do_cic_particles = 1 # turns on CIC particles | ||
|
||
ascent_interval = -1 | ||
checkpoint_interval = -1 | ||
plottime_interval = 2.0e5 # s | ||
derived_vars = gpot |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / CodeQL
Duplicate include guard Error