Skip to content

Commit 87f299f

Browse files
fix: correct MTHINC normals on non-uniform grids (#1401)
Co-authored-by: Ben Wilfong <bwilfong3@gatech.edu> Co-authored-by: Ben Wilfong <48168887+wilfonba@users.noreply.github.com>
1 parent 8fc2202 commit 87f299f

15 files changed

Lines changed: 749 additions & 132 deletions

File tree

examples/2D_advection_muscl/case.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"t_step_save": 100,
2222
# Simulation Algorithm Parameters
2323
"num_patches": 2,
24-
"model_eqns": 3,
24+
"model_eqns": 2,
2525
"alt_soundspeed": "F",
2626
"num_fluids": 2,
2727
"mpp_lim": "T",

src/simulation/m_muscl.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module m_muscl
1717
use m_mpi_proxy
1818
use m_helper
1919
use m_thinc
20+
use m_nvtx
2021

2122
private; public :: s_initialize_muscl_module, s_muscl, s_finalize_muscl_module
2223

src/simulation/m_rhs.fpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,16 @@ contains
670670
& qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, id)
671671
end if
672672
else
673-
if (all(Re_size == 0)) then
673+
if (int_comp > 0) then
674+
! THINC reads cont and adv from v_rs_ws; must reconstruct full sys_size range to populate both
675+
iv%beg = 1; iv%end = sys_size
676+
call s_reconstruct_cell_boundary_values(q_prim_qp%vf(1:sys_size), qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
677+
& qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, id)
678+
! Surface tension requires first-order energy; overwrite the higher-order result from the full pass above
679+
iv%beg = eqn_idx%E; iv%end = eqn_idx%E
680+
call s_reconstruct_cell_boundary_values_first_order(q_prim_qp%vf(eqn_idx%E), qL_rsx_vf, qL_rsy_vf, &
681+
& qL_rsz_vf, qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, id)
682+
else if (all(Re_size == 0)) then
674683
iv%beg = 1; iv%end = eqn_idx%E - 1
675684
call s_reconstruct_cell_boundary_values(q_prim_qp%vf(iv%beg:iv%end), qL_rsx_vf, qL_rsy_vf, qL_rsz_vf, &
676685
& qR_rsx_vf, qR_rsy_vf, qR_rsz_vf, id)

src/simulation/m_thinc.fpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,14 @@ module m_thinc
3030
real(wp) :: gq3_pts(3) = [-5e-1_wp*0.7745966692414834_wp, 0._wp, 5e-1_wp*0.7745966692414834_wp]
3131
!> Weights: 5/18, 8/18, 5/18
3232
real(wp) :: gq3_wts(3) = [5._wp/18._wp, 8._wp/18._wp, 5._wp/18._wp]
33-
!> ln(2)
34-
real(wp) :: ln2 = 0.6931471805599453_wp
35-
$:GPU_DECLARE(create='[gq3_pts, gq3_wts, ln2]')
33+
$:GPU_DECLARE(copyin='[gq3_pts, gq3_wts]')
3634

3735
real(wp), allocatable, dimension(:,:,:,:) :: mthinc_nhat !> Unit normal vector
3836
real(wp), allocatable, dimension(:,:,:) :: mthinc_d !> Interface position parameter
3937
$:GPU_DECLARE(create='[mthinc_nhat, mthinc_d]')
4038

4139
contains
4240

43-
!> @brief Stable computation of ln(cosh(x))
44-
function f_log_cosh(x) result(res)
45-
46-
$:GPU_ROUTINE(parallelism='[seq]')
47-
real(wp), intent(in) :: x
48-
real(wp) :: res, ax
49-
50-
ax = abs(x)
51-
if (ax > 20._wp) then
52-
res = ax - ln2
53-
else
54-
res = ax + log(1._wp + exp(-2._wp*ax)) - ln2
55-
end if
56-
57-
end function f_log_cosh
58-
5941
!> @brief Stable difference: log_cosh(a+h) - log_cosh(a-h) = 2*atanh(tanh(a)*tanh(h)). Avoids catastrophic cancellation when h
6042
!! is small relative to a.
6143
function f_log_cosh_diff(a, h) result(res)
@@ -259,16 +241,19 @@ contains
259241
ac = v_vf(eqn_idx%adv%beg)%sf(j, k, l)
260242

261243
if (ac >= ic_eps .and. ac <= 1._wp - ic_eps) then
262-
nr_x = (v_vf(eqn_idx%adv%beg)%sf(j + 1, k, l) - v_vf(eqn_idx%adv%beg)%sf(j - 1, k, l))*5e-1_wp
244+
nr_x = (v_vf(eqn_idx%adv%beg)%sf(j + 1, k, l) - v_vf(eqn_idx%adv%beg)%sf(j - 1, k, &
245+
& l))*(x_cb(j) - x_cb(j - 1))/(x_cc(j + 1) - x_cc(j - 1))
263246

264247
nr_y = 0._wp
265248
if (n > 0) then
266-
nr_y = (v_vf(eqn_idx%adv%beg)%sf(j, k + 1, l) - v_vf(eqn_idx%adv%beg)%sf(j, k - 1, l))*5e-1_wp
249+
nr_y = (v_vf(eqn_idx%adv%beg)%sf(j, k + 1, l) - v_vf(eqn_idx%adv%beg)%sf(j, k - 1, &
250+
& l))*(y_cb(k) - y_cb(k - 1))/(y_cc(k + 1) - y_cc(k - 1))
267251
end if
268252

269253
nr_z = 0._wp
270254
if (p > 0) then
271-
nr_z = (v_vf(eqn_idx%adv%beg)%sf(j, k, l + 1) - v_vf(eqn_idx%adv%beg)%sf(j, k, l - 1))*5e-1_wp
255+
nr_z = (v_vf(eqn_idx%adv%beg)%sf(j, k, l + 1) - v_vf(eqn_idx%adv%beg)%sf(j, k, &
256+
& l - 1))*(z_cb(l) - z_cb(l - 1))/(z_cc(l + 1) - z_cc(l - 1))
272257
end if
273258

274259
nmag = sqrt(nr_x*nr_x + nr_y*nr_y + nr_z*nr_z)

tests/10DE58AA/golden-metadata.txt

Lines changed: 71 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)