-
Notifications
You must be signed in to change notification settings - Fork 12
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
Compute emf #642
Draft
AstroKriel
wants to merge
38
commits into
quokka-astro:development
Choose a base branch
from
AstroKriel:compute-emf
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
Compute emf #642
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
703537c
add call to solve induction eqn
AstroKriel d79c692
draft func to solve induction eqn
AstroKriel ae7a364
indicate box-array centering
AstroKriel a8fe9fd
initialise fc state variables
AstroKriel 44e1ded
focus on setup to reconstruct
AstroKriel db4f3d1
debug: add evolve step to check induction eqn
AstroKriel b3fdd3a
fc-rhs is only used for mhd
AstroKriel 4ba7bc7
don't index comp (=1)
AstroKriel 33a7b0e
fix index-range of reconstruction (can compile and run w.o. errors --…
AstroKriel 4309caa
fix arg parsing to induction soln
AstroKriel d2c3bd4
recuce domain size for terminal debugging
AstroKriel 65f747a
specify state centering
AstroKriel 03e6001
reinstate all reconstruct options
AstroKriel ec40a30
add alfven wave test problem (not implemented yet)
AstroKriel df25a22
compute emf computes things correctly, but output still needs work
AstroKriel 83af98a
propogate fast mhd wave speeds to compute emf func
AstroKriel 6afe3fa
remove debug evolve step
AstroKriel 7552e65
add alfven wave test problem (not implemented yet)
AstroKriel 90b5417
output fast mhd wave speed
AstroKriel 1cba5a5
code to save mhd wavespeeds
AstroKriel 40231d1
return emf components
AstroKriel 9593208
make a view of the bfield data / don't make an unnecessary copy
AstroKriel 17fbf88
remove unused code
AstroKriel c2dc7c4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] bffd5b3
store edge-centered emf components more compactly: data reconstructed…
AstroKriel b81e07c
more meaningful variable names
AstroKriel 6bfa86e
store edge-centered emf components more compactly: data reconstructed…
AstroKriel b49a1f1
synchronise emf values that are on identical edges shared between mul…
AstroKriel 23aaa22
add mask for the synching emf components
AstroKriel 5b05c4d
rename IC funcs for consistency and to indicate centering
AstroKriel 4dedeb1
compute momentum for ICs
AstroKriel bd79eb1
rename vars for consistency
AstroKriel 41622e7
(in-progress) setup of b-fields for Riemann solver
AstroKriel 0227b20
we have an extra cc-ghost for MHD problems
AstroKriel 9b2509b
being pedantic about syntax
AstroKriel dd70e56
update backend for mhd
AstroKriel 9e7a72c
check alfven wave test passes
AstroKriel cd9c937
implemented induction eqn solved by line integral of emf around face,…
AstroKriel 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,7 @@ | ||
add_executable(test_alfven_wave test_alfven_wave.cpp ../interpolate.cpp ${QuokkaObjSources}) | ||
|
||
if(AMReX_GPU_BACKEND MATCHES "CUDA") | ||
setup_target_for_cuda_compilation(test_alfven_wave) | ||
endif() | ||
|
||
add_test(NAME AlfvenWave COMMAND test_alfven_wave alfven_wave.in WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tests) |
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,174 @@ | ||
//============================================================================== | ||
// Copyright 2022 Neco Kriel. | ||
// Released under the MIT license. See LICENSE file included in the GitHub repo. | ||
//============================================================================== | ||
/// \file test_fc_quantities.cpp | ||
/// \brief Defines a test problem to make sure face-centred quantities are created correctly. | ||
/// | ||
|
||
#include <cassert> | ||
#include <ostream> | ||
#include <stdexcept> | ||
#include <valarray> | ||
|
||
#include "AMReX_Array.H" | ||
#include "AMReX_Array4.H" | ||
#include "AMReX_Print.H" | ||
#include "AMReX_REAL.H" | ||
|
||
#include "RadhydroSimulation.hpp" | ||
#include "fextract.hpp" | ||
#include "grid.hpp" | ||
#include "physics_info.hpp" | ||
#include "test_alfven_wave.hpp" | ||
|
||
struct AlfvenWave { | ||
}; | ||
|
||
template <> struct quokka::EOS_Traits<AlfvenWave> { | ||
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 Physics_Traits<AlfvenWave> { | ||
// cell-centred | ||
static constexpr bool is_hydro_enabled = true; | ||
static constexpr int numMassScalars = 0; // number of mass scalars | ||
static constexpr int numPassiveScalars = numMassScalars + 0; // number of passive scalars | ||
static constexpr bool is_radiation_enabled = false; | ||
// face-centred | ||
static constexpr bool is_mhd_enabled = true; | ||
static constexpr int nGroups = 1; // number of radiation groups | ||
}; | ||
|
||
constexpr double rho0 = 1.0; // background density | ||
constexpr double P0 = 1.0 / quokka::EOS_Traits<AlfvenWave>::gamma; // background pressure | ||
constexpr double v0 = 0.; // background velocity | ||
constexpr double amp = 1.0e-6; // perturbation amplitude | ||
|
||
AMREX_GPU_DEVICE void computeWaveSolution(int i, int j, int k, amrex::Array4<amrex::Real> const &state, amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> const &dx, | ||
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> const &prob_lo) | ||
{ | ||
const amrex::Real x_L = prob_lo[0] + (i + amrex::Real(0.0)) * dx[0]; | ||
const amrex::Real x_R = prob_lo[0] + (i + amrex::Real(1.0)) * dx[0]; | ||
const amrex::Real A = amp; | ||
|
||
const quokka::valarray<double, 3> R = {1.0, -1.0, 1.5}; // right eigenvector of sound wave | ||
const quokka::valarray<double, 3> U_0 = {rho0, rho0 * v0, P0 / (quokka::EOS_Traits<AlfvenWave>::gamma - 1.0) + 0.5 * rho0 * std::pow(v0, 2)}; | ||
const quokka::valarray<double, 3> dU = (A * R / (2.0 * M_PI * dx[0])) * (std::cos(2.0 * M_PI * x_L) - std::cos(2.0 * M_PI * x_R)); | ||
|
||
double rho = U_0[0] + dU[0]; | ||
double xmom = U_0[1] + dU[1]; | ||
double Etot = U_0[2] + dU[2]; | ||
double Eint = Etot - 0.5 * (xmom * xmom) / rho; | ||
|
||
state(i, j, k, HydroSystem<AlfvenWave>::density_index) = rho; | ||
state(i, j, k, HydroSystem<AlfvenWave>::x1Momentum_index) = xmom; | ||
state(i, j, k, HydroSystem<AlfvenWave>::x2Momentum_index) = 0; | ||
state(i, j, k, HydroSystem<AlfvenWave>::x3Momentum_index) = 0; | ||
state(i, j, k, HydroSystem<AlfvenWave>::energy_index) = Etot; | ||
state(i, j, k, HydroSystem<AlfvenWave>::internalEnergy_index) = Eint; | ||
} | ||
|
||
template <> void RadhydroSimulation<AlfvenWave>::setInitialConditionsOnGrid(quokka::grid grid_elem) | ||
{ | ||
// extract grid information | ||
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> dx = grid_elem.dx_; | ||
amrex::GpuArray<amrex::Real, AMREX_SPACEDIM> prob_lo = grid_elem.prob_lo_; | ||
const amrex::Array4<double> &state = grid_elem.array_; | ||
const amrex::Box &indexRange = grid_elem.indexRange_; | ||
|
||
const int ncomp_cc = Physics_Indices<AlfvenWave>::nvarTotal_cc; | ||
// loop over the grid and set the initial condition | ||
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) { | ||
for (int n = 0; n < ncomp_cc; ++n) { | ||
state(i, j, k, n) = 0; // fill unused quantities with zeros | ||
} | ||
computeWaveSolution(i, j, k, state, dx, prob_lo); | ||
}); | ||
} | ||
|
||
template <> void RadhydroSimulation<AlfvenWave>::setInitialConditionsOnGridFaceVars(quokka::grid grid_elem) | ||
{ | ||
// extract grid information | ||
const amrex::Array4<double> &state = grid_elem.array_; | ||
const amrex::Box &indexRange = grid_elem.indexRange_; | ||
const quokka::direction dir = grid_elem.dir_; | ||
|
||
if (dir == quokka::direction::x) { | ||
amrex::ParallelFor(indexRange, | ||
[=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<AlfvenWave>::bfield_index) = 1.0 + (i % 2); }); | ||
} else if (dir == quokka::direction::y) { | ||
amrex::ParallelFor(indexRange, | ||
[=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<AlfvenWave>::bfield_index) = 2.0 + (j % 2); }); | ||
} else if (dir == quokka::direction::z) { | ||
amrex::ParallelFor(indexRange, | ||
[=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { state(i, j, k, MHDSystem<AlfvenWave>::bfield_index) = 3.0 + (k % 2); }); | ||
} | ||
} | ||
|
||
void checkMFs(amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state1, | ||
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state2) | ||
{ | ||
double err = 0.0; | ||
for (int level = 0; level < state1.size(); ++level) { | ||
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { | ||
// initialise MF | ||
const amrex::BoxArray &ba = state1[level][idim].boxArray(); | ||
const amrex::DistributionMapping &dm = state1[level][idim].DistributionMap(); | ||
int ncomp = state1[level][idim].nComp(); | ||
int ngrow = state1[level][idim].nGrow(); | ||
amrex::MultiFab mf_diff(ba, dm, ncomp, ngrow); | ||
// compute difference between two MFs (at level) | ||
amrex::MultiFab::Copy(mf_diff, state1[level][idim], 0, 0, ncomp, ngrow); | ||
amrex::MultiFab::Subtract(mf_diff, state2[level][idim], 0, 0, ncomp, ngrow); | ||
// compute error (summed over each component) | ||
for (int icomp = 0; icomp < Physics_Indices<AlfvenWave>::nvarPerDim_fc; ++icomp) { | ||
err += mf_diff.norm1(icomp); | ||
} | ||
} | ||
} | ||
amrex::Print() << "Accumulated error in MFs read from chk-file: " << err << "\n"; | ||
amrex::Print() << "\n"; | ||
AMREX_ALWAYS_ASSERT(std::abs(err) == 0.0); | ||
} | ||
|
||
auto problem_main() -> int | ||
{ | ||
// Problem initialization | ||
const int ncomp_cc = Physics_Indices<AlfvenWave>::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) { | ||
BCs_cc[n].setLo(i, amrex::BCType::int_dir); // periodic | ||
BCs_cc[n].setHi(i, amrex::BCType::int_dir); | ||
} | ||
} | ||
|
||
const int nvars_fc = Physics_Indices<AlfvenWave>::nvarTotal_fc; | ||
amrex::Vector<amrex::BCRec> BCs_fc(nvars_fc); | ||
for (int n = 0; n < nvars_fc; ++n) { | ||
for (int i = 0; i < AMREX_SPACEDIM; ++i) { | ||
BCs_fc[n].setLo(i, amrex::BCType::int_dir); // periodic | ||
BCs_fc[n].setHi(i, amrex::BCType::int_dir); | ||
} | ||
} | ||
|
||
RadhydroSimulation<AlfvenWave> sim_write(BCs_cc, BCs_fc); | ||
sim_write.setInitialConditions(); | ||
sim_write.evolve(); | ||
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state_new_fc_write = sim_write.getNewMF_fc(); | ||
amrex::Print() << "\n"; | ||
|
||
RadhydroSimulation<AlfvenWave> sim_restart(BCs_cc, BCs_fc); | ||
sim_restart.setChkFile("chk00000"); | ||
sim_restart.setInitialConditions(); | ||
amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const &state_new_fc_restart = sim_restart.getNewMF_fc(); | ||
amrex::Print() << "\n"; | ||
|
||
amrex::Print() << "Checking new FC MFs...\n"; | ||
checkMFs(state_new_fc_write, state_new_fc_restart); | ||
|
||
return 0; | ||
} |
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,20 @@ | ||
#ifndef TEST_ALFVEN_WAVE_HPP_ // NOLINT | ||
#define TEST_ALFVEN_WAVE_HPP_ | ||
//============================================================================== | ||
// Copyright 2024 Neco Kriel. | ||
// Released under the MIT license. See LICENSE file included in the GitHub repo. | ||
//============================================================================== | ||
/// \file test_alfven_wave.hpp | ||
/// \brief Defines a test problem to check alfven waves propogate correctly. | ||
/// | ||
|
||
// external headers | ||
#include <fmt/format.h> | ||
|
||
// internal headers | ||
#include "hydro_system.hpp" | ||
#include "mhd_system.hpp" | ||
|
||
// function definitions | ||
|
||
#endif // TEST_ALFVEN_WAVE_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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly prefer to avoid Fortran-style four-character variable names. In my opinion, there is no reason in the year 2024 not to use descriptive variables names that use full words.