Skip to content

Commit 66a70ff

Browse files
authored
make w2a initialization more accurate, especially for low resolutions (#1669)
* make w2a initialization more accurate, especially for low resolutions * formatting * avoid dividing by 0, just in case
1 parent 4f76d51 commit 66a70ff

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

amr-wind/ocean_waves/relaxation_zones/waves2amr_ops.H

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,16 @@ struct InitDataOp<W2AWaves>
652652
const bool has_beach = wdata.has_beach && multiphase_mode;
653653
const bool init_wave_field = wdata.init_wave_field || !multiphase_mode;
654654

655+
amrex::MultiFab phi_tmp_fab(
656+
velocity(level).boxArray(), velocity(level).DistributionMap(), 1,
657+
3);
658+
amrex::MultiFab vel_tmp_fab(
659+
velocity(level).boxArray(), velocity(level).DistributionMap(),
660+
AMREX_SPACEDIM, 3);
661+
662+
const auto& phi_tmp = phi_tmp_fab.arrays();
663+
const auto& vel_tmp = vel_tmp_fab.arrays();
664+
655665
amrex::ParallelFor(
656666
velocity(level), amrex::IntVect(3),
657667
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
@@ -673,17 +683,13 @@ struct InitDataOp<W2AWaves>
673683
x, problo[0], gen_length, probhi[0], beach_length, wave_sol,
674684
bulk, outlet);
675685

676-
const amrex::Real phi = local_profile[3] - z;
677-
const amrex::Real cell_length_2D =
678-
std::sqrt(dx[0] * dx[0] + dx[2] * dx[2]);
679-
if (phi + cell_length_2D >= 0) {
680-
vel[nbx](i, j, k, 0) = local_profile[0];
681-
vel[nbx](i, j, k, 1) = local_profile[1];
682-
vel[nbx](i, j, k, 2) = local_profile[2];
683-
}
686+
phi_tmp[nbx](i, j, k) = local_profile[3] - z;
687+
vel_tmp[nbx](i, j, k, 0) = local_profile[0];
688+
vel_tmp[nbx](i, j, k, 1) = local_profile[1];
689+
vel_tmp[nbx](i, j, k, 2) = local_profile[2];
684690

685691
if (multiphase_mode) {
686-
phi_arrs[nbx](i, j, k) = phi;
692+
phi_arrs[nbx](i, j, k) = phi_tmp[nbx](i, j, k);
687693
}
688694

689695
// Default w2a values matter for where no updates happen
@@ -693,6 +699,39 @@ struct InitDataOp<W2AWaves>
693699
w2a_vel[nbx](i, j, k, 2) = quiescent[0];
694700
});
695701
amrex::Gpu::streamSynchronize();
702+
703+
amrex::ParallelFor(
704+
velocity(level), amrex::IntVect(2),
705+
[=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept {
706+
const amrex::Real eps = 2. * std::cbrt(dx[0] * dx[1] * dx[2]);
707+
const amrex::Real vof_local =
708+
multiphase::levelset_to_vof(i, j, k, eps, phi_tmp[nbx]);
709+
710+
if (vof_local > 1. - constants::TIGHT_TOL) {
711+
// Entire cell is liquid
712+
vel[nbx](i, j, k, 0) = vel_tmp[nbx](i, j, k, 0);
713+
vel[nbx](i, j, k, 1) = vel_tmp[nbx](i, j, k, 1);
714+
vel[nbx](i, j, k, 2) = vel_tmp[nbx](i, j, k, 2);
715+
} else if (vof_local > 1e-3) {
716+
// Velocity of liquid becomes velocity of entire cell
717+
// Interpolate using cell-centered values to liquid centroid
718+
// Consider only z-direction to find centroid
719+
const amrex::Real z_cell = problo[2] + (k + 0.5) * dx[2];
720+
const amrex::Real z_cell_below = z_cell - dx[2];
721+
const amrex::Real z_cell_bottom = z_cell - 0.5 * dx[2];
722+
const amrex::Real z_liq_center =
723+
z_cell_bottom + 0.5 * vof_local * dx[2];
724+
for (int n = 0; n < AMREX_SPACEDIM; ++n) {
725+
vel[nbx](i, j, k, n) =
726+
vel_tmp[nbx](i, j, k - 1, n) +
727+
(vel_tmp[nbx](i, j, k, n) -
728+
vel_tmp[nbx](i, j, k - 1, n)) *
729+
((z_liq_center - z_cell_below) /
730+
(z_cell - z_cell_below + constants::EPS));
731+
}
732+
}
733+
});
734+
amrex::Gpu::streamSynchronize();
696735
#else
697736
amrex::ignore_unused(data, level, geom, multiphase_mode);
698737
#endif

0 commit comments

Comments
 (0)