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

Correctly fill VariableFluxPack for edge fluxes in 2D #1083

Merged
merged 7 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [[PR 1004]](https://github.com/parthenon-hpc-lab/parthenon/pull/1004) Allow parameter modification from an input file for restarts

### Fixed (not changing behavior/API/variables/...)
- [[PR 1083]](https://github.com/parthenon-hpc-lab/parthenon/pull/1083) Correctly fill VariableFluxPack for edge fluxes in 2D
- [[PR 1071]](https://github.com/parthenon-hpc-lab/parthenon/pull/1070) Fix bug in static mesh refinement related to redefinition of Mesh::root_level
- [[PR 1073]](https://github.com/parthenon-hpc-lab/parthenon/pull/1073) Fix bug in AMR and sparse restarts
- [[PR 1070]](https://github.com/parthenon-hpc-lab/parthenon/pull/1070) Correctly exclude flux vars from searches by default
Expand Down
30 changes: 21 additions & 9 deletions src/interface/variable_pack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,14 @@ class VariableFluxPack : public VariablePack<T> {
// host only
inline auto flux_alloc_status() const { return flux_alloc_status_; }

KOKKOS_FORCEINLINE_FUNCTION
const ViewOfParArrays<T> &flux(const int dir) const {
assert(dir > 0 && dir <= this->ndim_);
template <TopologicalType TT = TopologicalType::Face>
KOKKOS_FORCEINLINE_FUNCTION const ViewOfParArrays<T> &flux(const int dir) const {
assert(dir > 0);
if constexpr (TT == TopologicalType::Edge) {
assert(dir <= this->ndim_ || (this->ndim_ == 2 && dir == 3));
} else {
assert(dir <= this->ndim_);
}
return f_[dir - 1];
}

Expand All @@ -471,10 +476,11 @@ class VariableFluxPack : public VariablePack<T> {
constexpr bool IsFluxAllocated(const int /*n*/) const { return true; }
#endif

KOKKOS_FORCEINLINE_FUNCTION
T &flux(const int dir, const int n, const int k, const int j, const int i) const {
template <TopologicalType TT = TopologicalType::Face>
KOKKOS_FORCEINLINE_FUNCTION T &flux(const int dir, const int n, const int k,
const int j, const int i) const {
assert(IsFluxAllocated(n));
return flux(dir)(n)(k, j, i);
return flux<TT>(dir)(n)(k, j, i);
}

private:
Expand Down Expand Up @@ -681,9 +687,15 @@ void FillFluxViews(const VariableVector<T> &vars, const int ndim,
for (int i = 0; i < v->GetDim(4); i++) {
host_al(vindex) = v->IsAllocated();
if (v->IsAllocated()) {
host_f1(vindex) = v->data.Get(0, k, j, i);
if (ndim >= 2) host_f2(vindex) = v->data.Get(1, k, j, i);
if (ndim >= 3) host_f3(vindex) = v->data.Get(2, k, j, i);
if (v->IsSet(Metadata::Edge)) {
if (ndim >= 2) host_f3(vindex) = v->data.Get(2, k, j, i);
if (ndim >= 3) host_f2(vindex) = v->data.Get(1, k, j, i);
if (ndim >= 3) host_f1(vindex) = v->data.Get(0, k, j, i);
} else {
host_f1(vindex) = v->data.Get(0, k, j, i);
if (ndim >= 2) host_f2(vindex) = v->data.Get(1, k, j, i);
if (ndim >= 3) host_f3(vindex) = v->data.Get(2, k, j, i);
}
}

vindex++;
Expand Down
Loading