Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lroberts36 committed Oct 15, 2024
1 parent 1dd0e5c commit 3911b42
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 51 deletions.
21 changes: 12 additions & 9 deletions example/fine_advection/advection_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ TaskCollection AdvectionDriver::MakeTaskCollection(BlockList_t &blocks, const in
using namespace parthenon::Update;
TaskCollection tc;
TaskID none(0);

std::shared_ptr<parthenon::StateDescriptor> pkg = pmesh->packages.Get("advection_package");

std::shared_ptr<parthenon::StateDescriptor> pkg =
pmesh->packages.Get("advection_package");
const auto do_regular_advection = pkg->Param<bool>("do_regular_advection");
const auto do_fine_advection = pkg->Param<bool>("do_fine_advection");
const auto do_CT_advection = pkg->Param<bool>("do_CT_advection");
Expand Down Expand Up @@ -125,8 +126,8 @@ TaskCollection AdvectionDriver::MakeTaskCollection(BlockList_t &blocks, const in
auto flx_fine = none;
for (auto face : faces) {
if (do_regular_advection) {
flx = flx | tl.AddTask(none, advection_package::CalculateFluxes<pack_desc_t>, desc,
face, parthenon::CellLevel::same, mc0.get());
flx = flx | tl.AddTask(none, advection_package::CalculateFluxes<pack_desc_t>,
desc, face, parthenon::CellLevel::same, mc0.get());
}
if (do_fine_advection) {
flx_fine = flx_fine |
Expand All @@ -150,20 +151,22 @@ TaskCollection AdvectionDriver::MakeTaskCollection(BlockList_t &blocks, const in

auto update = set_flx;
if (do_regular_advection) {
update = AddUpdateTasks(set_flx, tl, parthenon::CellLevel::same, TT::Cell, beta, dt, desc,
mbase.get(), mc0.get(), mdudt.get(), mc1.get());
update = AddUpdateTasks(set_flx, tl, parthenon::CellLevel::same, TT::Cell, beta, dt,
desc, mbase.get(), mc0.get(), mdudt.get(), mc1.get());
}

auto update_fine = set_flx;
if (do_fine_advection) {
update_fine = AddUpdateTasks(set_flx, tl, parthenon::CellLevel::fine, TT::Cell, beta, dt,
update_fine =
AddUpdateTasks(set_flx, tl, parthenon::CellLevel::fine, TT::Cell, beta, dt,
desc_fine, mbase.get(), mc0.get(), mdudt.get(), mc1.get());
}

auto update_vec = set_flx;
if (do_CT_advection) {
update_vec = AddUpdateTasks(set_flx, tl, parthenon::CellLevel::same, TT::Face, beta, dt,
desc_vec, mbase.get(), mc0.get(), mdudt.get(), mc1.get());
update_vec =
AddUpdateTasks(set_flx, tl, parthenon::CellLevel::same, TT::Face, beta, dt,
desc_vec, mbase.get(), mc0.get(), mdudt.get(), mc1.get());
}

auto boundaries = parthenon::AddBoundaryExchangeTasks(
Expand Down
57 changes: 29 additions & 28 deletions example/fine_advection/advection_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,39 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
}
pkg->AddParam<>("profile", profile_str);


bool do_regular_advection = pin->GetOrAddBoolean("Advection", "do_regular_advection", true);
bool do_regular_advection =
pin->GetOrAddBoolean("Advection", "do_regular_advection", true);
pkg->AddParam<>("do_regular_advection", do_regular_advection);
if (do_regular_advection) {
if (do_regular_advection) {
int shape_size = pin->GetOrAddInteger("Advection", "shape_size", 1);
int sparse_size = pin->GetOrAddInteger("Advection", "sparse_size", 1);
Real alloc_threshold = pin->GetOrAddReal("Advection", "alloc_threshold", 1.e-6);
Real dealloc_threshold = pin->GetOrAddReal("Advection", "dealloc_threshold", 5.e-7);
Metadata m({Metadata::Cell, Metadata::Independent, Metadata::WithFluxes,
Metadata::FillGhost, Metadata::Sparse}, std::vector<int>{shape_size});
Metadata::FillGhost, Metadata::Sparse},
std::vector<int>{shape_size});
m.SetSparseThresholds(alloc_threshold, dealloc_threshold, 0.0);
std::vector<int> sparse_idxs(sparse_size);
std::vector<int> sparse_idxs(sparse_size);
std::iota(sparse_idxs.begin(), sparse_idxs.end(), 0);
pkg->AddSparsePool<Conserved::phi>(m, sparse_idxs);
}


bool do_fine_advection = pin->GetOrAddBoolean("Advection", "do_fine_advection", true);
pkg->AddParam<>("do_fine_advection", do_fine_advection);
if (do_fine_advection) {
if (do_fine_advection) {
pkg->AddField<Conserved::phi_fine>(
Metadata({Metadata::Cell, Metadata::Fine, Metadata::Independent,
Metadata::WithFluxes, Metadata::FillGhost}));

pkg->AddField<Conserved::phi_fine_restricted>(
Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}));
}
}

bool do_CT_advection = pin->GetOrAddBoolean("Advection", "do_CT_advection", true);
pkg->AddParam<>("do_CT_advection", do_CT_advection);
if (do_CT_advection) {
auto m = Metadata(
{Metadata::Face, Metadata::Independent, Metadata::WithFluxes, Metadata::FillGhost});
if (do_CT_advection) {
auto m = Metadata({Metadata::Face, Metadata::Independent, Metadata::WithFluxes,
Metadata::FillGhost});
m.RegisterRefinementOps<parthenon::refinement_ops::ProlongateSharedMinMod,
parthenon::refinement_ops::RestrictAverage,
parthenon::refinement_ops::ProlongateInternalTothAndRoe>();
Expand All @@ -115,7 +115,7 @@ std::shared_ptr<StateDescriptor> Initialize(ParameterInput *pin) {
Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}));
pkg->AddField<Conserved::divD>(
Metadata({Metadata::Cell, Metadata::Derived, Metadata::OneCopy}));
}
}

pkg->CheckRefinementBlock = CheckRefinement;
pkg->EstimateTimestepMesh = EstimateTimestep;
Expand All @@ -139,24 +139,25 @@ AmrTag CheckRefinement(MeshBlockData<Real> *rc) {

typename Kokkos::MinMax<Real>::value_type minmax;
parthenon::par_reduce(
parthenon::loop_pattern_mdrange_tag, PARTHENON_AUTO_LABEL, DevExecSpace(),
0, pack.GetNBlocks() - 1, // Runs from [0, 0] since pack built from MeshBlockData
pack.GetLowerBoundHost(0), pack.GetUpperBoundHost(0), kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e,
parthenon::loop_pattern_mdrange_tag, PARTHENON_AUTO_LABEL, DevExecSpace(), 0,
pack.GetNBlocks() - 1, // Runs from [0, 0] since pack built from MeshBlockData
pack.GetLowerBoundHost(0), pack.GetUpperBoundHost(0), kb.s, kb.e, jb.s, jb.e,
ib.s, ib.e,
KOKKOS_LAMBDA(const int b, const int n, const int k, const int j, const int i,
typename Kokkos::MinMax<Real>::value_type &lminmax) {
lminmax.min_val =
(pack(b, n, k, j, i) < lminmax.min_val ? pack(b, n, k, j, i) : lminmax.min_val);
lminmax.max_val =
(pack(b, n, k, j, i) > lminmax.max_val ? pack(b, n, k, j, i) : lminmax.max_val);
lminmax.min_val = (pack(b, n, k, j, i) < lminmax.min_val ? pack(b, n, k, j, i)
: lminmax.min_val);
lminmax.max_val = (pack(b, n, k, j, i) > lminmax.max_val ? pack(b, n, k, j, i)
: lminmax.max_val);
},
Kokkos::MinMax<Real>(minmax));

auto pkg = pmb->packages.Get("advection_package");
const auto &refine_tol = pkg->Param<Real>("refine_tol");
const auto &derefine_tol = pkg->Param<Real>("derefine_tol");

if (minmax.max_val > refine_tol && minmax.min_val < derefine_tol) return AmrTag::refine;
if (minmax.max_val > refine_tol && minmax.min_val < derefine_tol)
return AmrTag::refine;
if (minmax.max_val < derefine_tol) return AmrTag::derefine;
}
return AmrTag::same;
Expand Down Expand Up @@ -203,21 +204,21 @@ TaskStatus FillDerived(MeshData<Real> *md) {
Conserved::D_cc, Conserved::divC, Conserved::divD>(
md);
auto pack = desc.GetPack(md);

std::shared_ptr<StateDescriptor> pkg =
md->GetMeshPointer()->packages.Get("advection_package");

IndexRange ib = md->GetBoundsI(IndexDomain::interior);
IndexRange jb = md->GetBoundsJ(IndexDomain::interior);
IndexRange kb = md->GetBoundsK(IndexDomain::interior);
const int ndim = md->GetMeshPointer()->ndim;
const int nghost = parthenon::Globals::nghost;

auto do_fine_advection = pkg->Param<bool>("do_fine_advection");
if (do_fine_advection) {
parthenon::par_for(
PARTHENON_AUTO_LABEL, 0, pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
PARTHENON_AUTO_LABEL, 0, pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
const int kf = (ndim > 2) ? (k - nghost) * 2 + nghost : k;
const int jf = (ndim > 1) ? (j - nghost) * 2 + nghost : j;
const int fi = (ndim > 0) ? (i - nghost) * 2 + nghost : i;
Expand All @@ -238,8 +239,8 @@ TaskStatus FillDerived(MeshData<Real> *md) {
if (do_CT_advection) {
using TE = parthenon::TopologicalElement;
parthenon::par_for(
PARTHENON_AUTO_LABEL, 0, pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
PARTHENON_AUTO_LABEL, 0, pack.GetNBlocks() - 1, kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e, KOKKOS_LAMBDA(const int b, const int k, const int j, const int i) {
pack(b, Conserved::C_cc(0), k, j, i) =
0.5 * (pack(b, TE::F1, Conserved::C(), k, j, i) +
pack(b, TE::F1, Conserved::C(), k, j, i + (ndim > 0)));
Expand Down
24 changes: 12 additions & 12 deletions example/fine_advection/advection_package.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ TaskStatus CalculateVectorFluxes(parthenon::TopologicalElement edge,
constexpr int scratch_size = 0;
constexpr int scratch_level = 1;
parthenon::par_for_outer(
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s - (ndim > 2), kb.e + (ndim > 2),
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s - (ndim > 2), kb.e + (ndim > 2),
KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
parthenon::Indexer2D idxer({jb.s - (ndim > 1), jb.e + (ndim > 1)},
{ib.s - (ndim > 0), ib.e + (ndim > 0)});
if (pack.GetLowerBound(b, flux_var()) <= pack.GetUpperBound(b, flux_var())) {
parthenon::par_for_inner(member, 0, idxer.size() - 1, [&](const int idx) {
const auto [j, i] = idxer(idx);
// Piecewise linear in the orthogonal directions, could do something better here
// Piecewise linear in the orthogonal directions, could do something better
// here
pack(b, TE::CC, recon(0), k, j, i) =
0.5 * (pack(b, fe, flux_var(), k, j, i) +
pack(b, fe, flux_var(), k + koff, j + joff, i + ioff));
Expand All @@ -160,9 +161,8 @@ TaskStatus CalculateVectorFluxes(parthenon::TopologicalElement edge,
jb = md->GetBoundsJ(cl, IndexDomain::interior, edge);
kb = md->GetBoundsK(cl, IndexDomain::interior, edge);
parthenon::par_for_outer(
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s, kb.e,
KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1, kb.s,
kb.e, KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
parthenon::Indexer2D idxer({jb.s, jb.e}, {ib.s, ib.e});
if (pack.GetLowerBound(b, var()) <= pack.GetUpperBound(b, var())) {
parthenon::par_for_inner(member, 0, idxer.size() - 1, [&](const int idx) {
Expand Down Expand Up @@ -191,15 +191,16 @@ TaskStatus CalculateVectorFluxes(parthenon::TopologicalElement edge,
jb = md->GetBoundsJ(cl, IndexDomain::interior, f);
kb = md->GetBoundsK(cl, IndexDomain::interior, f);
parthenon::par_for_outer(
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s - (ndim > 2), kb.e + (ndim > 2),
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s - (ndim > 2), kb.e + (ndim > 2),
KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
parthenon::Indexer2D idxer({jb.s - (ndim > 1), jb.e + (ndim > 1)},
{ib.s - (ndim > 0), ib.e + (ndim > 0)});
if (pack.GetLowerBound(b, var()) <= pack.GetUpperBound(b, var())) {
parthenon::par_for_inner(member, 0, idxer.size() - 1, [&](const int idx) {
const auto [j, i] = idxer(idx);
// Piecewise linear in the orthogonal directions, could do something better here
// Piecewise linear in the orthogonal directions, could do something better
// here
pack(b, f, recon_f(0), k, j, i) = pack(b, f, var(), k, j, i);
pack(b, f, recon_f(1), k, j, i) = pack(b, f, var(), k, j, i);
});
Expand All @@ -220,9 +221,8 @@ TaskStatus CalculateVectorFluxes(parthenon::TopologicalElement edge,
d2[static_cast<int>(edge) % 3] = 0;
d2[static_cast<int>(f2) % 3] = 0;
parthenon::par_for_outer(
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1,
kb.s, kb.e,
KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
PARTHENON_AUTO_LABEL, scratch_size, scratch_level, 0, pack.GetNBlocks() - 1, kb.s,
kb.e, KOKKOS_LAMBDA(parthenon::team_mbr_t member, const int b, const int k) {
parthenon::Indexer2D idxer({jb.s, jb.e}, {ib.s, ib.e});
if (pack.GetLowerBound(b, var()) <= pack.GetUpperBound(b, var())) {
parthenon::par_for_inner(member, 0, idxer.size() - 1, [&](const int idx) {
Expand Down
3 changes: 1 addition & 2 deletions example/fine_advection/parthenon_app_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
}
}
} else {
if (do_regular_advection)
pack(b, phi(), k, j, i) = 0.0;
if (do_regular_advection) pack(b, phi(), k, j, i) = 0.0;
if (do_fine_advection) {
for (int ioff = 0; ioff <= (ndim > 0); ++ioff)
for (int joff = 0; joff <= (ndim > 1); ++joff)
Expand Down

0 comments on commit 3911b42

Please sign in to comment.