Skip to content
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

Boundary bugfix(es) and exposing FluxDiv_ interface #558

Merged
merged 24 commits into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
25abe29
Expose FluxDiv_ call to that it can be used downstream
pgrete Jul 9, 2021
fd4aa0a
Fix index bug in boundaries
pgrete Jul 9, 2021
245cbbf
change kbounds for boundaries to be the same as the others. This pote…
jonahm-LANL Jul 9, 2021
c59c93a
Merge branch 'develop' into pgrete/expose-flux-div
Yurlungur Jul 9, 2021
d856b6d
Merge branch 'develop' into pgrete/expose-flux-div
pgrete Jul 26, 2021
7897792
Rename now public FluxDiv_ function to FluxDivHelper
pgrete Jul 26, 2021
6a87222
Adjust unit test to fixed k bounds
pgrete Jul 26, 2021
dab3022
make one generic boundary condition function
jlippuner Jul 28, 2021
5edf0cf
update copyright
jlippuner Jul 28, 2021
b0f29a1
Update src/bvals/boundary_conditions.cpp
jlippuner Aug 2, 2021
6fc0c8d
Merge branch 'develop' into pgrete/expose-flux-div
jlippuner Aug 2, 2021
a25fdfb
make inner/outer, outflow/reflect enums instead of bools
jlippuner Aug 2, 2021
65381a4
Merge branch 'develop' into pgrete/expose-flux-div
Yurlungur Aug 5, 2021
7cad3ae
Merge branch 'develop' into pgrete/expose-flux-div
pgrete Aug 12, 2021
a41c9fe
Merge remote-tracking branch 'origin/develop' into pgrete/expose-flux…
pgrete Sep 11, 2021
9bf07bc
Add block profile to advection example
pgrete Sep 12, 2021
38c2e8c
WIP Adding non-const v to advection example. Need dt, and v fluxes ar…
pgrete Sep 12, 2021
1b50125
Add 3D fluxes for cell advection
pgrete Sep 12, 2021
0d6d7fa
Use PackIndexMap to determien variable v
pgrete Sep 12, 2021
af1972f
Add bval convergence test
pgrete Sep 12, 2021
f287238
Add check for variables not initialized
pgrete Sep 12, 2021
b0678c4
Fix missing header
pgrete Sep 16, 2021
eae511b
Merge branch 'develop' into pgrete/expose-flux-div
pgrete Sep 21, 2021
e0100b3
Address review comments
pgrete Sep 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions example/advection/parthenon_app_inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ void ProblemGenerator(MeshBlock *pmb, ParameterInput *pin) {
const auto &profile = pkg->Param<std::string>("profile");

auto cellbounds = pmb->cellbounds;
IndexRange ib = cellbounds.GetBoundsI(IndexDomain::entire);
IndexRange jb = cellbounds.GetBoundsJ(IndexDomain::entire);
IndexRange kb = cellbounds.GetBoundsK(IndexDomain::entire);
IndexRange ib = cellbounds.GetBoundsI(IndexDomain::interior);
IndexRange jb = cellbounds.GetBoundsJ(IndexDomain::interior);
IndexRange kb = cellbounds.GetBoundsK(IndexDomain::interior);

auto coords = pmb->coords;
auto q = data->PackVariables(std::vector<MetadataFlag>{Metadata::Independent});
Expand Down
4 changes: 2 additions & 2 deletions src/bvals/boundary_conditions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void OutflowOuterX2(std::shared_ptr<MeshBlockData<Real>> &rc, bool coarse) {
void OutflowInnerX3(std::shared_ptr<MeshBlockData<Real>> &rc, bool coarse) {
std::shared_ptr<MeshBlock> pmb = rc->GetBlockPointer();
auto bounds = coarse ? pmb->c_cellbounds : pmb->cellbounds;
int ref = bounds.GetBoundsJ(IndexDomain::interior).s;
int ref = bounds.GetBoundsK(IndexDomain::interior).s;
pgrete marked this conversation as resolved.
Show resolved Hide resolved
auto q = rc->PackVariables(std::vector<MetadataFlag>{Metadata::FillGhost}, coarse);
auto nb = IndexRange{0, q.GetDim(4) - 1};
pmb->par_for_bndry(
Expand All @@ -148,7 +148,7 @@ void OutflowInnerX3(std::shared_ptr<MeshBlockData<Real>> &rc, bool coarse) {
void OutflowOuterX3(std::shared_ptr<MeshBlockData<Real>> &rc, bool coarse) {
std::shared_ptr<MeshBlock> pmb = rc->GetBlockPointer();
auto bounds = coarse ? pmb->c_cellbounds : pmb->cellbounds;
int ref = bounds.GetBoundsJ(IndexDomain::interior).e;
int ref = bounds.GetBoundsK(IndexDomain::interior).e;
auto q = rc->PackVariables(std::vector<MetadataFlag>{Metadata::FillGhost}, coarse);
auto nb = IndexRange{0, q.GetDim(4) - 1};
pmb->par_for_bndry(
Expand Down
4 changes: 3 additions & 1 deletion src/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ void EvolutionDriver::InitializeBlockTimeSteps() {
void EvolutionDriver::SetGlobalTimeStep() {
// don't allow dt to grow by more than 2x
// consider making this configurable in the input
tm.dt *= 2.0;
if (tm.dt < 0.1 * std::numeric_limits<Real>::max()) {
tm.dt *= 2.0;
}
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
Real big = std::numeric_limits<Real>::max();
for (auto const &pmb : pmesh->block_list) {
tm.dt = std::min(tm.dt, pmb->NewDt());
Expand Down
24 changes: 4 additions & 20 deletions src/interface/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@ namespace parthenon {

namespace Update {

KOKKOS_FORCEINLINE_FUNCTION
Real FluxDiv_(const int l, const int k, const int j, const int i, const int ndim,
const Coordinates_t &coords, const VariableFluxPack<Real> &v) {
Real du = (coords.Area(X1DIR, k, j, i + 1) * v.flux(X1DIR, l, k, j, i + 1) -
coords.Area(X1DIR, k, j, i) * v.flux(X1DIR, l, k, j, i));
if (ndim >= 2) {
du += (coords.Area(X2DIR, k, j + 1, i) * v.flux(X2DIR, l, k, j + 1, i) -
coords.Area(X2DIR, k, j, i) * v.flux(X2DIR, l, k, j, i));
}
if (ndim == 3) {
du += (coords.Area(X3DIR, k + 1, j, i) * v.flux(X3DIR, l, k + 1, j, i) -
coords.Area(X3DIR, k, j, i) * v.flux(X3DIR, l, k, j, i));
}
return -du / coords.Volume(k, j, i);
}

template <>
TaskStatus FluxDivergence(MeshBlockData<Real> *in, MeshBlockData<Real> *dudt_cont) {
std::shared_ptr<MeshBlock> pmb = in->GetBlockPointer();
Expand All @@ -62,7 +46,7 @@ TaskStatus FluxDivergence(MeshBlockData<Real> *in, MeshBlockData<Real> *dudt_con
pmb->par_for(
"FluxDivergenceBlock", 0, vin.GetDim(4) - 1, kb.s, kb.e, jb.s, jb.e, ib.s, ib.e,
KOKKOS_LAMBDA(const int l, const int k, const int j, const int i) {
dudt(l, k, j, i) = FluxDiv_(l, k, j, i, ndim, coords, vin);
dudt(l, k, j, i) = FluxDivHelper(l, k, j, i, ndim, coords, vin);
});

return TaskStatus::complete;
Expand All @@ -86,7 +70,7 @@ TaskStatus FluxDivergence(MeshData<Real> *in_obj, MeshData<Real> *dudt_obj) {
KOKKOS_LAMBDA(const int m, const int l, const int k, const int j, const int i) {
const auto &coords = vin.coords(m);
const auto &v = vin(m);
dudt(m, l, k, j, i) = FluxDiv_(l, k, j, i, ndim, coords, v);
dudt(m, l, k, j, i) = FluxDivHelper(l, k, j, i, ndim, coords, v);
});
return TaskStatus::complete;
}
Expand All @@ -111,7 +95,7 @@ TaskStatus UpdateWithFluxDivergence(MeshBlockData<Real> *u0_data,
"UpdateWithFluxDivergenceBlock", 0, u0.GetDim(4) - 1, kb.s, kb.e, jb.s, jb.e, ib.s,
ib.e, KOKKOS_LAMBDA(const int l, const int k, const int j, const int i) {
u0(l, k, j, i) = gam0 * u0(l, k, j, i) + gam1 * u1(l, k, j, i) +
beta_dt * FluxDiv_(l, k, j, i, ndim, coords, u0);
beta_dt * FluxDivHelper(l, k, j, i, ndim, coords, u0);
});

return TaskStatus::complete;
Expand All @@ -138,7 +122,7 @@ TaskStatus UpdateWithFluxDivergence(MeshData<Real> *u0_data, MeshData<Real> *u1_
const auto &coords = u0_pack.coords(m);
const auto &u0 = u0_pack(m);
u0_pack(m, l, k, j, i) = gam0 * u0(l, k, j, i) + gam1 * u1_pack(m, l, k, j, i) +
beta_dt * FluxDiv_(l, k, j, i, ndim, coords, u0);
beta_dt * FluxDivHelper(l, k, j, i, ndim, coords, u0);
});
return TaskStatus::complete;
}
Expand Down
17 changes: 17 additions & 0 deletions src/interface/update.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ namespace parthenon {

namespace Update {

// Calculate the flux divergence for a specific component l of a variable v
KOKKOS_FORCEINLINE_FUNCTION
Real FluxDivHelper(const int l, const int k, const int j, const int i, const int ndim,
const Coordinates_t &coords, const VariableFluxPack<Real> &v) {
Real du = (coords.Area(X1DIR, k, j, i + 1) * v.flux(X1DIR, l, k, j, i + 1) -
coords.Area(X1DIR, k, j, i) * v.flux(X1DIR, l, k, j, i));
if (ndim >= 2) {
du += (coords.Area(X2DIR, k, j + 1, i) * v.flux(X2DIR, l, k, j + 1, i) -
coords.Area(X2DIR, k, j, i) * v.flux(X2DIR, l, k, j, i));
}
if (ndim == 3) {
du += (coords.Area(X3DIR, k + 1, j, i) * v.flux(X3DIR, l, k + 1, j, i) -
coords.Area(X3DIR, k, j, i) * v.flux(X3DIR, l, k, j, i));
}
return -du / coords.Volume(k, j, i);
}

template <typename T>
TaskStatus FluxDivergence(T *in, T *dudt_obj);

Expand Down
21 changes: 7 additions & 14 deletions src/mesh/domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,14 @@ class IndexShape {
}
}

// note ks and ke are different than the others for boundaries.
// This is because extending i and j over extra ghost zones
// is sufficient to fill whole ghost layer
KOKKOS_INLINE_FUNCTION int ks(const IndexDomain &domain) const noexcept {
switch (domain) {
case IndexDomain::entire:
return 0;
case IndexDomain::inner_x3:
return 0;
case IndexDomain::interior:
return x_[2].s;
case IndexDomain::outer_x3:
return entire_ncells_[2] == 1 ? 0 : x_[2].e + 1;
default: // interior+
return x_[2].s;
default:
return 0;
}
}

Expand Down Expand Up @@ -217,14 +212,12 @@ class IndexShape {

KOKKOS_INLINE_FUNCTION int ke(const IndexDomain &domain) const noexcept {
switch (domain) {
case IndexDomain::entire:
return entire_ncells_[2] - 1;
case IndexDomain::interior:
return x_[2].e;
case IndexDomain::inner_x3:
return x_[2].s == 0 ? 0 : x_[2].s - 1;
case IndexDomain::outer_x3:
default:
return entire_ncells_[2] - 1;
default: // interior+
return x_[2].e;
}
}

Expand Down
32 changes: 16 additions & 16 deletions tst/unit/test_unit_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,33 +199,33 @@ TEST_CASE("Checking IndexShape indices", "[IndexShape]") {
REQUIRE(shape.ie(inner_x1) == 0);
REQUIRE(shape.js(inner_x1) == 0);
REQUIRE(shape.je(inner_x1) == 2);
REQUIRE(shape.ks(inner_x1) == 1);
REQUIRE(shape.ke(inner_x1) == 4);
REQUIRE(shape.GetTotal(inner_x1) == 12);
REQUIRE(shape.ks(inner_x1) == 0);
REQUIRE(shape.ke(inner_x1) == 5);
REQUIRE(shape.GetTotal(inner_x1) == 18);

REQUIRE(shape.is(outer_x1) == 7);
REQUIRE(shape.ie(outer_x1) == 7);
REQUIRE(shape.js(outer_x1) == 0);
REQUIRE(shape.je(outer_x1) == 2);
REQUIRE(shape.ks(outer_x1) == 1);
REQUIRE(shape.ke(outer_x1) == 4);
REQUIRE(shape.GetTotal(outer_x1) == 12);
REQUIRE(shape.ks(outer_x1) == 0);
REQUIRE(shape.ke(outer_x1) == 5);
REQUIRE(shape.GetTotal(outer_x1) == 18);

REQUIRE(shape.is(inner_x2) == 0);
REQUIRE(shape.ie(inner_x2) == 7);
REQUIRE(shape.js(inner_x2) == 0);
REQUIRE(shape.je(inner_x2) == 0);
REQUIRE(shape.ks(inner_x2) == 1);
REQUIRE(shape.ke(inner_x2) == 4);
REQUIRE(shape.GetTotal(inner_x2) == 32);
REQUIRE(shape.ks(inner_x2) == 0);
REQUIRE(shape.ke(inner_x2) == 5);
REQUIRE(shape.GetTotal(inner_x2) == 48);

REQUIRE(shape.is(outer_x2) == 0);
REQUIRE(shape.ie(outer_x2) == 7);
REQUIRE(shape.js(outer_x2) == 2);
REQUIRE(shape.je(outer_x2) == 2);
REQUIRE(shape.ks(outer_x2) == 1);
REQUIRE(shape.ke(outer_x2) == 4);
REQUIRE(shape.GetTotal(outer_x2) == 32);
REQUIRE(shape.ks(outer_x2) == 0);
REQUIRE(shape.ke(outer_x2) == 5);
REQUIRE(shape.GetTotal(outer_x2) == 48);

REQUIRE(shape.is(inner_x3) == 0);
REQUIRE(shape.ie(inner_x3) == 7);
Expand Down Expand Up @@ -398,19 +398,19 @@ TEST_CASE("Checking IndexShape cell counts", "[IndexShape]") {

REQUIRE(shape.ncellsi(inner_x1) == 1);
REQUIRE(shape.ncellsj(inner_x1) == 3);
REQUIRE(shape.ncellsk(inner_x1) == 4);
REQUIRE(shape.ncellsk(inner_x1) == 6);

REQUIRE(shape.ncellsi(outer_x1) == 1);
REQUIRE(shape.ncellsj(outer_x1) == 3);
REQUIRE(shape.ncellsk(outer_x1) == 4);
REQUIRE(shape.ncellsk(outer_x1) == 6);

REQUIRE(shape.ncellsi(inner_x2) == 8);
REQUIRE(shape.ncellsj(inner_x2) == 1);
REQUIRE(shape.ncellsk(inner_x2) == 4);
REQUIRE(shape.ncellsk(inner_x2) == 6);

REQUIRE(shape.ncellsi(outer_x2) == 8);
REQUIRE(shape.ncellsj(outer_x2) == 1);
REQUIRE(shape.ncellsk(outer_x2) == 4);
REQUIRE(shape.ncellsk(outer_x2) == 6);

REQUIRE(shape.ncellsi(inner_x3) == 8);
REQUIRE(shape.ncellsj(inner_x3) == 3);
Expand Down