From d38ff35e67a65267d3256de447c122bf2bf91557 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 18 Sep 2024 09:12:22 -0600 Subject: [PATCH 1/7] incorporate iblank_to_mask_vof --- amr-wind/overset/OversetOps.cpp | 5 +++ amr-wind/overset/overset_ops_routines.H | 4 +++ amr-wind/overset/overset_ops_routines.cpp | 40 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/amr-wind/overset/OversetOps.cpp b/amr-wind/overset/OversetOps.cpp index 0ef0671e24..c318fd48af 100644 --- a/amr-wind/overset/OversetOps.cpp +++ b/amr-wind/overset/OversetOps.cpp @@ -82,6 +82,11 @@ void OversetOps::pre_advance_work() // Update pressure gradient using sharpened pressure field update_gradp(); } + // Calculate vof-dependent node mask + const auto& iblank = m_sim_ptr->repo().get_int_field("iblank_node"); + const auto& vof = m_sim_ptr->repo().get_field("vof"); + auto& mask = m_sim_ptr->repo().get_int_field("mask_node"); + overset_ops::iblank_to_mask_vof(iblank, vof, mask); } // If pressure gradient will be replaced, store current pressure gradient diff --git a/amr-wind/overset/overset_ops_routines.H b/amr-wind/overset/overset_ops_routines.H index b14043b26a..b8cb235b6f 100644 --- a/amr-wind/overset/overset_ops_routines.H +++ b/amr-wind/overset/overset_ops_routines.H @@ -5,9 +5,13 @@ #include "AMReX_MultiFab.H" #include "amr-wind/equation_systems/vof/volume_fractions.H" #include "amr-wind/overset/overset_ops_K.H" +#include "amr-wind/core/FieldRepo.H" namespace amr_wind::overset_ops { +void iblank_to_mask_vof( + const IntField& iblank, const Field& vof, IntField& maskf); + // Populate approximate signed distance function using vof field void populate_psi( amrex::MultiFab& mf_psi, diff --git a/amr-wind/overset/overset_ops_routines.cpp b/amr-wind/overset/overset_ops_routines.cpp index f9ae2ea1ed..f8b5faa857 100644 --- a/amr-wind/overset/overset_ops_routines.cpp +++ b/amr-wind/overset/overset_ops_routines.cpp @@ -1,6 +1,46 @@ #include "amr-wind/overset/overset_ops_routines.H" namespace amr_wind::overset_ops { + +void iblank_to_mask_vof( + const IntField& iblank, const Field& voff, IntField& maskf) +{ + const auto& nlevels = iblank.repo().mesh().finestLevel() + 1; + + for (int lev = 0; lev < nlevels; ++lev) { + const auto& ibl = iblank(lev); + const auto& vof = voff(lev); + auto& mask = maskf(lev); + + const auto& ibarrs = ibl.const_arrays(); + const auto& vofarrs = vof.const_arrays(); + const auto& marrs = mask.arrays(); + amrex::ParallelFor( + ibl, ibl.n_grow, + [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept { + // Default is masking all 0 and -1 iblanks + marrs[nbx](i, j, k) = amrex::max(ibarrs[nbx](i, j, k), 0); + // Check cells neighboring node for being near interface + bool near_interface = false; + for (int ii = i - 1; ii < i + 1; ii++) { + for (int jj = j - 1; jj < j + 1; jj++) { + for (int kk = k - 1; kk < k + 1; kk++) { + near_interface = + near_interface || + amr_wind::multiphase::interface_band( + ii, jj, kk, vofarrs[nbx], 1e-4); + } + } + } + // Do mask -1 cells near interface + if (ibarrs[nbx](i, j, k) == -1 && near_interface) { + marrs[nbx](i, j, k) = 1; + } + }); + } + amrex::Gpu::synchronize(); +} + // Populate approximate signed distance function using vof field void populate_psi( amrex::MultiFab& mf_psi, From 7cd32e5636fb8123c5f9dd5c5b614f7da57dc4d4 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 18 Sep 2024 10:11:43 -0600 Subject: [PATCH 2/7] make vof-dependent node mask when nodal_proj coupling not disabled --- amr-wind/overset/OversetOps.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/amr-wind/overset/OversetOps.cpp b/amr-wind/overset/OversetOps.cpp index c318fd48af..1677db84ba 100644 --- a/amr-wind/overset/OversetOps.cpp +++ b/amr-wind/overset/OversetOps.cpp @@ -82,11 +82,13 @@ void OversetOps::pre_advance_work() // Update pressure gradient using sharpened pressure field update_gradp(); } - // Calculate vof-dependent node mask - const auto& iblank = m_sim_ptr->repo().get_int_field("iblank_node"); - const auto& vof = m_sim_ptr->repo().get_field("vof"); - auto& mask = m_sim_ptr->repo().get_int_field("mask_node"); - overset_ops::iblank_to_mask_vof(iblank, vof, mask); + if (!m_disable_nodal_proj) { + // Calculate vof-dependent node mask + const auto& iblank = m_sim_ptr->repo().get_int_field("iblank_node"); + const auto& vof = m_sim_ptr->repo().get_field("vof"); + auto& mask = m_sim_ptr->repo().get_int_field("mask_node"); + overset_ops::iblank_to_mask_vof(iblank, vof, mask); + } } // If pressure gradient will be replaced, store current pressure gradient From 5f712f379db5f19d942e552bf2bd90486e19dc09 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 18 Sep 2024 15:04:54 -0600 Subject: [PATCH 3/7] correcting arguments --- amr-wind/overset/overset_ops_routines.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amr-wind/overset/overset_ops_routines.cpp b/amr-wind/overset/overset_ops_routines.cpp index f8b5faa857..2e7df40840 100644 --- a/amr-wind/overset/overset_ops_routines.cpp +++ b/amr-wind/overset/overset_ops_routines.cpp @@ -28,7 +28,7 @@ void iblank_to_mask_vof( near_interface = near_interface || amr_wind::multiphase::interface_band( - ii, jj, kk, vofarrs[nbx], 1e-4); + ii, jj, kk, vofarrs[nbx], 1, 1e-4); } } } From 997fb4e10ba54c2185e31cdf9c72bbebf6c28a63 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 18 Sep 2024 16:07:49 -0600 Subject: [PATCH 4/7] make tolerance an argument --- amr-wind/equation_systems/vof/volume_fractions.H | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/amr-wind/equation_systems/vof/volume_fractions.H b/amr-wind/equation_systems/vof/volume_fractions.H index 055a59d3f5..9e265e6b72 100644 --- a/amr-wind/equation_systems/vof/volume_fractions.H +++ b/amr-wind/equation_systems/vof/volume_fractions.H @@ -493,10 +493,11 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool interface_band( const int j, const int k, amrex::Array4 const& volfrac, - const int n_band = 1) noexcept + const int n_band = 1, + const amrex::Real tiny = 1e-12) noexcept { // n_band must be <= number of vof ghost cells (3) - constexpr amrex::Real tiny = 1e-12; + // Check if near interface amrex::Real VOF_max = 0.0; amrex::Real VOF_min = 1.0; From bd122d3773c4dcd1d29c3371ad9eab4c99b2f43a Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Wed, 18 Sep 2024 16:08:05 -0600 Subject: [PATCH 5/7] use constexpr instead of hard-coding it --- amr-wind/overset/overset_ops_routines.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/amr-wind/overset/overset_ops_routines.cpp b/amr-wind/overset/overset_ops_routines.cpp index 2e7df40840..9b8347899b 100644 --- a/amr-wind/overset/overset_ops_routines.cpp +++ b/amr-wind/overset/overset_ops_routines.cpp @@ -6,6 +6,7 @@ void iblank_to_mask_vof( const IntField& iblank, const Field& voff, IntField& maskf) { const auto& nlevels = iblank.repo().mesh().finestLevel() + 1; + constexpr amrex::Real band_tol = 1e-4; for (int lev = 0; lev < nlevels; ++lev) { const auto& ibl = iblank(lev); @@ -28,7 +29,7 @@ void iblank_to_mask_vof( near_interface = near_interface || amr_wind::multiphase::interface_band( - ii, jj, kk, vofarrs[nbx], 1, 1e-4); + ii, jj, kk, vofarrs[nbx], 1, band_tol); } } } From 1a67f1fffca5bbafad2b1dbb8611b29b9e1db2e2 Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Thu, 19 Sep 2024 17:11:15 -0600 Subject: [PATCH 6/7] be able to replace gradp inside objects too --- amr-wind/overset/overset_ops_routines.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/amr-wind/overset/overset_ops_routines.cpp b/amr-wind/overset/overset_ops_routines.cpp index 9b8347899b..6447342d99 100644 --- a/amr-wind/overset/overset_ops_routines.cpp +++ b/amr-wind/overset/overset_ops_routines.cpp @@ -543,7 +543,7 @@ void replace_gradp( amrex::ParallelFor( mf_gp, mf_gp.n_grow, [=] AMREX_GPU_DEVICE(int nbx, int i, int j, int k) noexcept { - if (iblank[nbx](i, j, k) == -1) { + if (iblank[nbx](i, j, k) <= 0) { gp[nbx](i, j, k, 0) = gp0[nbx](i, j, k, 0); gp[nbx](i, j, k, 1) = gp0[nbx](i, j, k, 1); gp[nbx](i, j, k, 2) = gp0[nbx](i, j, k, 2); From 20390eaaf6c32230ff493d22d124ba954cc11d8d Mon Sep 17 00:00:00 2001 From: Michael Kuhn Date: Fri, 20 Sep 2024 11:48:14 -0600 Subject: [PATCH 7/7] body-node tweak to iblank_to_mask_vof --- amr-wind/overset/overset_ops_routines.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/amr-wind/overset/overset_ops_routines.cpp b/amr-wind/overset/overset_ops_routines.cpp index 6447342d99..f8a4466262 100644 --- a/amr-wind/overset/overset_ops_routines.cpp +++ b/amr-wind/overset/overset_ops_routines.cpp @@ -33,8 +33,20 @@ void iblank_to_mask_vof( } } } + // Check nodes neighboring node for being near solid + bool near_solid = false; + for (int ii = i - 1; ii < i + 2; ii++) { + for (int jj = j - 1; jj < j + 2; jj++) { + for (int kk = k - 1; kk < k + 2; kk++) { + near_solid = ibarrs[nbx](ii, jj, kk) == 0 + ? true + : near_solid; + } + } + } // Do mask -1 cells near interface - if (ibarrs[nbx](i, j, k) == -1 && near_interface) { + if (ibarrs[nbx](i, j, k) == -1 && + (near_interface && !near_solid)) { marrs[nbx](i, j, k) = 1; } });