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

fix reflective boundary conditions #225

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- fix potential segfault in slices
- ensure that Fargo also advect passive tracers
- fix reflective boundary conditions on the right of the domain (#225)

## [2.0.3] 2023-11-24
### Changed
Expand Down
21 changes: 11 additions & 10 deletions src/fluid/boundary/boundary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,12 @@ void Boundary<Phys>::EnforceReflective(int dir, BoundarySide side ) {

BoundaryForAll("BoundaryReflective", dir, side,
KOKKOS_LAMBDA (int n, int k, int j, int i) {
// ref= 2*ibound -i -1
// ref= 2*ibound -i -1 on the left and 2*ibound-1+1 on the right
// with ibound = nghost on the left and ibount = nghost + nx -1 on the right
const int iref = (dir==IDIR) ? 2*(ighost + side*(nxi-1)) - i - 1 : i;
const int jref = (dir==JDIR) ? 2*(jghost + side*(nxj-1)) - j - 1 : j;
const int kref = (dir==KDIR) ? 2*(kghost + side*(nxk-1)) - k - 1 : k;
// So overall iref=2*nghost-i-1 pn the left and ireft=2*nghost+2*nx-i-1 on the right
const int iref = (dir==IDIR) ? 2*(ighost + side*nxi) - i - 1 : i;
const int jref = (dir==JDIR) ? 2*(jghost + side*nxj) - j - 1 : j;
const int kref = (dir==KDIR) ? 2*(kghost + side*nxk) - k - 1 : k;

const int sign = (n == VX1+dir) ? -1.0 : 1.0;

Expand All @@ -673,8 +674,8 @@ void Boundary<Phys>::EnforceReflective(int dir, BoundarySide side ) {
// ref= 2*ibound -i -1
// with ibound = nghost on the left and ibount = nghost + nx -1 on the right
//const int iref = (dir==IDIR) ? 2*(ighost + side*(nxi-1)) - i - 1 : i;
const int jref = (dir==JDIR) ? 2*(jghost + side*(nxj-1)) - j - 1 : j;
const int kref = (dir==KDIR) ? 2*(kghost + side*(nxk-1)) - k - 1 : k;
const int jref = (dir==JDIR) ? 2*(jghost + side*nxj) - j - 1 : j;
const int kref = (dir==KDIR) ? 2*(kghost + side*nxk) - k - 1 : k;

Vs(BX1s,k,j,i) = -Vs(BX1s,kref,jref,i);
});
Expand All @@ -683,9 +684,9 @@ void Boundary<Phys>::EnforceReflective(int dir, BoundarySide side ) {
if(dir==IDIR || dir==KDIR) {
BoundaryForX2s("BoundaryReflectiveX2s",dir,side,
KOKKOS_LAMBDA (int k, int j, int i) {
const int iref = (dir==IDIR) ? 2*(ighost + side*(nxi-1)) - i - 1 : i;
const int iref = (dir==IDIR) ? 2*(ighost + side*nxi) - i - 1 : i;
//const int jref = (dir==JDIR) ? 2*(jghost + side*(nxj-1)) - j - 1 : j;
const int kref = (dir==KDIR) ? 2*(kghost + side*(nxk-1)) - k - 1 : k;
const int kref = (dir==KDIR) ? 2*(kghost + side*nxk) - k - 1 : k;

Vs(BX2s,k,j,i) = -Vs(BX2s,kref,j,iref);
});
Expand All @@ -695,8 +696,8 @@ void Boundary<Phys>::EnforceReflective(int dir, BoundarySide side ) {
if(dir==IDIR || dir==JDIR) {
BoundaryForX3s("BoundaryReflectiveX3s",dir,side,
KOKKOS_LAMBDA (int k, int j, int i) {
const int iref = (dir==IDIR) ? 2*(ighost + side*(nxi-1)) - i - 1 : i;
const int jref = (dir==JDIR) ? 2*(jghost + side*(nxj-1)) - j - 1 : j;
const int iref = (dir==IDIR) ? 2*(ighost + side*nxi) - i - 1 : i;
const int jref = (dir==JDIR) ? 2*(jghost + side*nxj) - j - 1 : j;
//const int kref = (dir==KDIR) ? 2*(kghost + side*(nxk-1)) - k - 1 : k;

Vs(BX3s,k,j,i) = -Vs(BX3s,k,jref,iref);
Expand Down