Skip to content

Commit

Permalink
Merge pull request #261 from hklion/adjust_corners
Browse files Browse the repository at this point in the history
swap east and west and add masking on velocity boundaries
  • Loading branch information
hklion authored Sep 4, 2024
2 parents e3d9e45 + dee9a12 commit 6785d57
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 77 deletions.
16 changes: 8 additions & 8 deletions Source/BoundaryConditions/BoundaryConditions_netcdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ REMORA::fill_from_bdyfiles (MultiFab& mf_to_fill, const MultiFab& mf_mask, const
const auto& bdatyhi_n = bdy_data_yhi[n_time ][ivar+icomp].const_array();
const auto& bdatyhi_np1 = bdy_data_yhi[n_time+1][ivar+icomp].const_array();

const bool apply_east = domain_bcs_type[bccomp+icomp].lo(0) == REMORABCType::clamped;
const bool apply_west = domain_bcs_type[bccomp+icomp].hi(0) == REMORABCType::clamped;
const bool apply_west = domain_bcs_type[bccomp+icomp].lo(0) == REMORABCType::clamped;
const bool apply_east = domain_bcs_type[bccomp+icomp].hi(0) == REMORABCType::clamped;
const bool apply_south = domain_bcs_type[bccomp+icomp].lo(1) == REMORABCType::clamped;
const bool apply_north = domain_bcs_type[bccomp+icomp].hi(1) == REMORABCType::clamped;

Expand Down Expand Up @@ -106,15 +106,15 @@ REMORA::fill_from_bdyfiles (MultiFab& mf_to_fill, const MultiFab& mf_mask, const
const Array4<Real>& dest_arr = mf_to_fill.array(mfi);
const Array4<const Real>& mask_arr = mf_mask.array(mfi);

if (!xlo.isEmpty() && apply_east) {
if (!xlo.isEmpty() && apply_west) {
ParallelFor(xlo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = (oma * bdatxlo_n (ubound(xlo).x,j,k,0)
+ alpha * bdatxlo_np1(ubound(xlo).x,j,k,0)) * mask_arr(i,j,0);
});
}

if (!xhi.isEmpty() && apply_west) {
if (!xhi.isEmpty() && apply_east) {
ParallelFor(xhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = (oma * bdatxhi_n (lbound(xhi).x,j,k,0)
Expand All @@ -139,25 +139,25 @@ REMORA::fill_from_bdyfiles (MultiFab& mf_to_fill, const MultiFab& mf_mask, const
}

// If we've applied boundary conditions to either side, update the corner
if (!xlo_ylo.isEmpty() && (apply_east || apply_south)) {
if (!xlo_ylo.isEmpty() && (apply_west || apply_south)) {
ParallelFor(xlo_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = 0.5 * (dest_arr(i,dom_lo.y+mf_index_type[1],k,icomp+icomp_to_fill) + dest_arr(dom_lo.x+mf_index_type[0],j,k,icomp+icomp_to_fill));
});
}
if (!xlo_yhi.isEmpty() && (apply_east || apply_north)) {
if (!xlo_yhi.isEmpty() && (apply_west || apply_north)) {
ParallelFor(xlo_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = 0.5 * (dest_arr(i,dom_hi.y-mf_index_type[1],k,icomp+icomp_to_fill) + dest_arr(dom_lo.x+mf_index_type[0],j,k,icomp+icomp_to_fill));
});
}
if (!xhi_ylo.isEmpty() && (apply_west || apply_south)) {
if (!xhi_ylo.isEmpty() && (apply_east || apply_south)) {
ParallelFor(xhi_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = 0.5 * (dest_arr(i,dom_lo.y+mf_index_type[1],k,icomp+icomp_to_fill) + dest_arr(dom_hi.x-mf_index_type[0],j,k,icomp+icomp_to_fill));
});
}
if (!xhi_yhi.isEmpty() && (apply_west || apply_north)) {
if (!xhi_yhi.isEmpty() && (apply_east || apply_north)) {
ParallelFor(xhi_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k,icomp+icomp_to_fill) = 0.5 * (dest_arr(i,dom_hi.y-mf_index_type[1],k,icomp+icomp_to_fill) + dest_arr(dom_hi.x-mf_index_type[0],j,k,icomp+icomp_to_fill));
Expand Down
48 changes: 24 additions & 24 deletions Source/BoundaryConditions/BoundaryConditions_xvel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][0]*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::foextrap || bc_ptr[n].lo(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k);
dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k);
dest_arr(i,j,k) = dest_arr(iflip,j,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k);
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*msku(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR
Expand All @@ -81,11 +81,11 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].hi(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][3]*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::foextrap || bc_ptr[n].hi(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_hi.x+1,j,k);
dest_arr(i,j,k) = dest_arr(dom_hi.x+1,j,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k);
dest_arr(i,j,k) = dest_arr(iflip,j,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k);
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*msku(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR
Expand All @@ -107,23 +107,23 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][1]*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::foextrap || bc_ptr[n].lo(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k);
dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k);
dest_arr(i,j,k) = dest_arr(i,jflip,k)*msku(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,jflip,k);
dest_arr(i,j,k) = -dest_arr(i,jflip,k)*msku(i,j,0);
}
},
bx_yhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int jflip = 2*dom_hi.y + 1 - j;
if (bc_ptr[n].hi(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][4]*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::foextrap || bc_ptr[n].hi(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_hi.y,k);
dest_arr(i,j,k) = dest_arr(i,dom_hi.y,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k);
dest_arr(i,j,k) = dest_arr(i,jflip,k)*msku(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,jflip,k);
dest_arr(i,j,k) = -dest_arr(i,jflip,k)*msku(i,j,0);
}
}
);
Expand All @@ -139,23 +139,23 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(2) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][2]*msku(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(i,j,dom_lo.z);
dest_arr(i,j,k) = dest_arr(i,j,dom_lo.z)*msku(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,j,kflip);
dest_arr(i,j,k) = dest_arr(i,j,kflip)*msku(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,j,kflip);
dest_arr(i,j,k) = -dest_arr(i,j,kflip)*msku(i,j,0);
}
},
bx_zhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int kflip = 2*dom_hi.z + 1 - k;
if (bc_ptr[n].hi(2) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][5]*msku(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(i,j,dom_hi.z);
dest_arr(i,j,k) = dest_arr(i,j,dom_hi.z)*msku(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,j,kflip);
dest_arr(i,j,k) = dest_arr(i,j,kflip)*msku(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,j,kflip);
dest_arr(i,j,k) = -dest_arr(i,j,kflip)*msku(i,j,0);
}
}
);
Expand All @@ -172,30 +172,30 @@ void REMORAPhysBCFunct::impose_xvel_bcs (const Array4<Real>& dest_arr, const Box
Box xhi_ylo = xhi & ylo;
Box xhi_yhi = xhi & yhi;

const bool clamp_east = m_domain_bcs_type[bccomp].lo(0) == REMORABCType::clamped;
const bool clamp_west = m_domain_bcs_type[bccomp].hi(0) == REMORABCType::clamped;
const bool clamp_west = m_domain_bcs_type[bccomp].lo(0) == REMORABCType::clamped;
const bool clamp_east = m_domain_bcs_type[bccomp].hi(0) == REMORABCType::clamped;
const bool clamp_south = m_domain_bcs_type[bccomp].lo(1) == REMORABCType::clamped;
const bool clamp_north = m_domain_bcs_type[bccomp].hi(1) == REMORABCType::clamped;

if (!clamp_east && !clamp_south) {
if (!clamp_west && !clamp_south) {
ParallelFor(xlo_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_lo.y,k) + dest_arr(dom_lo.x+1,j,k));
});
}
if (!clamp_east && !clamp_north) {
if (!clamp_west && !clamp_north) {
ParallelFor(xlo_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_hi.y,k) + dest_arr(dom_lo.x+1,j,k));
});
}
if (!clamp_west && !clamp_south) {
if (!clamp_east && !clamp_south) {
ParallelFor(xhi_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_lo.y,k) + dest_arr(dom_hi.x,j,k));
});
}
if (!clamp_west && !clamp_north) {
if (!clamp_east && !clamp_north) {
ParallelFor(xhi_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_hi.y,k) + dest_arr(dom_hi.x,j,k));
Expand Down
48 changes: 24 additions & 24 deletions Source/BoundaryConditions/BoundaryConditions_yvel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ void REMORAPhysBCFunct::impose_yvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][0]*mskv(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::foextrap || bc_ptr[n].lo(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k);
dest_arr(i,j,k) = dest_arr(dom_lo.x,j,k)*mskv(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k);
dest_arr(i,j,k) = dest_arr(iflip,j,k)*mskv(i,j,0);
} else if (bc_ptr[n].lo(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k);
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*mskv(i,j,0);
}
},
bx_xhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int iflip = 2*dom_hi.x + 1 - i;
if (bc_ptr[n].hi(0) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][3]*mskv(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::foextrap || bc_ptr[n].hi(0) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(dom_hi.x,j,k);
dest_arr(i,j,k) = dest_arr(dom_hi.x,j,k)*mskv(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(iflip,j,k);
dest_arr(i,j,k) = dest_arr(iflip,j,k)*mskv(i,j,0);
} else if (bc_ptr[n].hi(0) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(iflip,j,k);
dest_arr(i,j,k) = -dest_arr(iflip,j,k)*mskv(i,j,0);
}
}
);
Expand All @@ -97,11 +97,11 @@ void REMORAPhysBCFunct::impose_yvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][1]*mskv(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::foextrap || bc_ptr[n].lo(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k);
dest_arr(i,j,k) = dest_arr(i,dom_lo.y,k)*mskv(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k);
dest_arr(i,j,k) = dest_arr(i,jflip,k)*mskv(i,j,0);
} else if (bc_ptr[n].lo(1) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,jflip,k);
dest_arr(i,j,k) = -dest_arr(i,jflip,k)*mskv(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR
Expand All @@ -116,11 +116,11 @@ void REMORAPhysBCFunct::impose_yvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].hi(1) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][4]*mskv(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::foextrap || bc_ptr[n].hi(1) == REMORABCType::clamped) {
dest_arr(i,j,k) = dest_arr(i,dom_hi.y+1,k);
dest_arr(i,j,k) = dest_arr(i,dom_hi.y+1,k)*mskv(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,jflip,k);
dest_arr(i,j,k) = dest_arr(i,jflip,k)*mskv(i,j,0);
} else if (bc_ptr[n].hi(1) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,jflip,k);
dest_arr(i,j,k) = -dest_arr(i,jflip,k)*mskv(i,j,0);
}
},
// We only set the values on the domain faces themselves if EXT_DIR
Expand All @@ -141,23 +141,23 @@ void REMORAPhysBCFunct::impose_yvel_bcs (const Array4<Real>& dest_arr, const Box
if (bc_ptr[n].lo(2) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][2]*mskv(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(i,j,dom_lo.z);
dest_arr(i,j,k) = dest_arr(i,j,dom_lo.z)*mskv(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,j,kflip);
dest_arr(i,j,k) = dest_arr(i,j,kflip)*mskv(i,j,0);
} else if (bc_ptr[n].lo(2) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,j,kflip);
dest_arr(i,j,k) = -dest_arr(i,j,kflip)*mskv(i,j,0);
}
},
bx_zhi, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) {
int kflip = 2*dom_hi.z + 1 - k;
if (bc_ptr[n].hi(2) == REMORABCType::ext_dir) {
dest_arr(i,j,k) = l_bc_extdir_vals_d[n][5]*mskv(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::foextrap) {
dest_arr(i,j,k) = dest_arr(i,j,dom_hi.z);
dest_arr(i,j,k) = dest_arr(i,j,dom_hi.z)*mskv(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::reflect_even) {
dest_arr(i,j,k) = dest_arr(i,j,kflip);
dest_arr(i,j,k) = dest_arr(i,j,kflip)*mskv(i,j,0);
} else if (bc_ptr[n].hi(2) == REMORABCType::reflect_odd) {
dest_arr(i,j,k) = -dest_arr(i,j,kflip);
dest_arr(i,j,k) = -dest_arr(i,j,kflip)*mskv(i,j,0);
}
}
);
Expand All @@ -173,30 +173,30 @@ void REMORAPhysBCFunct::impose_yvel_bcs (const Array4<Real>& dest_arr, const Box
Box xlo_yhi = xlo & yhi;
Box xhi_ylo = xhi & ylo;
Box xhi_yhi = xhi & yhi;
const bool clamp_east = m_domain_bcs_type[bccomp].lo(0) == REMORABCType::clamped;
const bool clamp_west = m_domain_bcs_type[bccomp].hi(0) == REMORABCType::clamped;
const bool clamp_west = m_domain_bcs_type[bccomp].lo(0) == REMORABCType::clamped;
const bool clamp_east = m_domain_bcs_type[bccomp].hi(0) == REMORABCType::clamped;
const bool clamp_south = m_domain_bcs_type[bccomp].lo(1) == REMORABCType::clamped;
const bool clamp_north = m_domain_bcs_type[bccomp].hi(1) == REMORABCType::clamped;

if (!clamp_east && !clamp_south) {
if (!clamp_west && !clamp_south) {
ParallelFor(xlo_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_lo.y+1,k) + dest_arr(dom_lo.x,j,k));
});
}
if (!clamp_east && !clamp_north) {
if (!clamp_west && !clamp_north) {
ParallelFor(xlo_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_hi.y,k) + dest_arr(dom_lo.x,j,k));
});
}
if (!clamp_west && !clamp_south) {
if (!clamp_east && !clamp_south) {
ParallelFor(xhi_ylo, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_lo.y+1,k) + dest_arr(dom_hi.x,j,k));
});
}
if (!clamp_west && !clamp_north) {
if (!clamp_east && !clamp_north) {
ParallelFor(xhi_yhi, [=] AMREX_GPU_DEVICE (int i, int j, int k)
{
dest_arr(i,j,k) = 0.5 * (dest_arr(i,dom_hi.y,k) + dest_arr(dom_hi.x,j,k));
Expand Down
Loading

0 comments on commit 6785d57

Please sign in to comment.