From e5432d263a6ab3053ef1210b58daa8627c79ff12 Mon Sep 17 00:00:00 2001 From: AppleChen17 Date: Sun, 18 Oct 2026 01:19:17 +0800 Subject: [PATCH] Read WENO stencil directly from v_vf The WENO3/5/7 reconstruction kernels read their stencil from v_rs_weno, which s_pack_weno_input_arr fills with an element-wise copy of v_vf using the same (j, k, l) layout. Read v_vf directly instead, which removes one read and one write of every reconstructed field per direction and per RK stage. v_rs_weno and the pack are still needed by MP-WENO (s_preserve_monotonicity) and THINC (s_thinc_compression), so they are allocated, filled and deallocated only when mp_weno or int_comp > 0. WENO1 and MUSCL do not use s_pack_weno_input_arr and are unchanged. --- src/simulation/m_weno.fpp | 42 ++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/simulation/m_weno.fpp b/src/simulation/m_weno.fpp index 89cc45f77..06d5965e0 100644 --- a/src/simulation/m_weno.fpp +++ b/src/simulation/m_weno.fpp @@ -117,7 +117,10 @@ contains call s_compute_weno_coefficients(1, is1_weno) - @:ALLOCATE(v_rs_weno(is1_weno%beg:is1_weno%end, is2_weno%beg:is2_weno%end, is3_weno%beg:is3_weno%end, 1:sys_size)) + ! Only MP-WENO and THINC read the packed copy; the reconstruction kernels read v_vf directly + if (mp_weno .or. int_comp > 0) then + @:ALLOCATE(v_rs_weno(is1_weno%beg:is1_weno%end, is2_weno%beg:is2_weno%end, is3_weno%beg:is3_weno%end, 1:sys_size)) + end if ! Allocating/Computing WENO Coefficients in y-direction if (n == 0) return @@ -963,7 +966,8 @@ contains end if end if - if (weno_order /= 1) then + ! The reconstruction kernels read the stencil straight from v_vf; only MP-WENO and THINC still read the packed copy + if (weno_order /= 1 .and. (mp_weno .or. int_comp > 0)) then call s_pack_weno_input_arr(v_vf) end if @@ -984,9 +988,9 @@ contains alpha(:) = 0._wp - vp0 = v_rs_weno(${SF('')}$, i) - vm1 = v_rs_weno(${SF(' - 1')}$, i) - vp1 = v_rs_weno(${SF(' + 1')}$, i) + vp0 = v_vf(i)%sf(${SF('')}$) + vm1 = v_vf(i)%sf(${SF(' - 1')}$) + vp1 = v_vf(i)%sf(${SF(' + 1')}$) dvd(0) = vp1 - vp0 dvd(-1) = vp0 - vm1 @@ -1077,11 +1081,11 @@ contains alpha(:) = 0._wp - vp0 = v_rs_weno(${SF('')}$, i) - vm1 = v_rs_weno(${SF(' - 1')}$, i) - vm2 = v_rs_weno(${SF(' - 2')}$, i) - vp1 = v_rs_weno(${SF(' + 1')}$, i) - vp2 = v_rs_weno(${SF(' + 2')}$, i) + vp0 = v_vf(i)%sf(${SF('')}$) + vm1 = v_vf(i)%sf(${SF(' - 1')}$) + vm2 = v_vf(i)%sf(${SF(' - 2')}$) + vp1 = v_vf(i)%sf(${SF(' + 1')}$) + vp2 = v_vf(i)%sf(${SF(' + 2')}$) dvd(1) = vp2 - vp1 dvd(0) = vp1 - vp0 @@ -1234,13 +1238,13 @@ contains do i = 1, v_size alpha(:) = 0._wp - vp0 = v_rs_weno(${SF('')}$, i) - vm1 = v_rs_weno(${SF(' - 1')}$, i) - vm2 = v_rs_weno(${SF(' - 2')}$, i) - vm3 = v_rs_weno(${SF(' - 3')}$, i) - vp1 = v_rs_weno(${SF(' + 1')}$, i) - vp2 = v_rs_weno(${SF(' + 2')}$, i) - vp3 = v_rs_weno(${SF(' + 3')}$, i) + vp0 = v_vf(i)%sf(${SF('')}$) + vm1 = v_vf(i)%sf(${SF(' - 1')}$) + vm2 = v_vf(i)%sf(${SF(' - 2')}$) + vm3 = v_vf(i)%sf(${SF(' - 3')}$) + vp1 = v_vf(i)%sf(${SF(' + 1')}$) + vp2 = v_vf(i)%sf(${SF(' + 2')}$) + vp3 = v_vf(i)%sf(${SF(' + 3')}$) if (teno) then v(-3) = vm3 @@ -1578,7 +1582,9 @@ contains ! Deallocating the WENO-stencil of the WENO-reconstructed variables - @:DEALLOCATE(v_rs_weno) + if (mp_weno .or. int_comp > 0) then + @:DEALLOCATE(v_rs_weno) + end if ! Deallocating WENO coefficients in x-direction @:DEALLOCATE(poly_coef_cbL_x, poly_coef_cbR_x)