Background
PR #1432 consolidated several module-level directional triplets into derived types. Two triplets remain that are among the highest-leverage targets left: the primitive-variable gradient arrays that appear as three separate arguments in every viscous and diffusion-related subroutine call.
Current state
m_rhs.fpp declares six module-level allocatable triplets:
type(vector_field), allocatable, dimension(:) :: dqL_prim_dx_n, dqL_prim_dy_n, dqL_prim_dz_n
type(vector_field), allocatable, dimension(:) :: dqR_prim_dx_n, dqR_prim_dy_n, dqR_prim_dz_n
Each is a type(vector_field) array indexed by the Riemann direction index n. All three appear together in every allocation, deallocation, GPU declaration, and subroutine call — they are never used independently.
They propagate as three separate arguments through approximately 7 subroutines spanning m_rhs.fpp and m_riemann_solvers.fpp, including the cross-module interface at the Riemann solver call site.
Proposed change
Introduce a module-private wrapper type (or add to m_derived_types.fpp if reusable):
type, private :: vf_dir_t
type(vector_field), allocatable, dimension(:) :: x, y, z
end type vf_dir_t
type(vf_dir_t) :: dqL_prim_dn, dqR_prim_dn
Update GPU_DECLARE, allocation, deallocation, and all call sites to use dqL_prim_dn%x/y/z.
The cross-module call in m_rhs.fpp into m_riemann_solvers.fpp means both modules must be updated together — this is a single atomic change.
What this enables
Signature reduction. Every subroutine currently taking dqL_dx, dqL_dy, dqL_dz, dqR_dx, dqR_dy, dqR_dz (6 arguments) takes dqL, dqR (2 arguments) after consolidation. With 7 subroutines affected, this removes ~42 argument slots from interfaces.
Single allocation/deallocation site. The current allocation block is:
@:ALLOCATE(dqL_prim_dx_n(1:num_dims))
@:ALLOCATE(dqL_prim_dy_n(1:num_dims))
@:ALLOCATE(dqL_prim_dz_n(1:num_dims))
@:ALLOCATE(dqR_prim_dx_n(1:num_dims))
@:ALLOCATE(dqR_prim_dy_n(1:num_dims))
@:ALLOCATE(dqR_prim_dz_n(1:num_dims))
This becomes 2 lines. Same for deallocation and GPU_DECLARE.
Foundation for directional sweep unification. Once the gradient triplets are in a struct, the directional dispatch loops in m_rhs.fpp that select dqL_prim_dx_n vs dqL_prim_dy_n vs dqL_prim_dz_n based on norm_dir can be collapsed to a single block using dqL_prim_dn%x/y/z as Fypp loop variables (see #1440).
Scope
Files affected: m_rhs.fpp, m_riemann_solvers.fpp (interface boundary).
The change is mechanical but touches a cross-module interface, so a GPU build and the full viscous/diffusion test suite should be run before merging.
Related
Background
PR #1432 consolidated several module-level directional triplets into derived types. Two triplets remain that are among the highest-leverage targets left: the primitive-variable gradient arrays that appear as three separate arguments in every viscous and diffusion-related subroutine call.
Current state
m_rhs.fppdeclares six module-level allocatable triplets:Each is a
type(vector_field)array indexed by the Riemann direction indexn. All three appear together in every allocation, deallocation, GPU declaration, and subroutine call — they are never used independently.They propagate as three separate arguments through approximately 7 subroutines spanning
m_rhs.fppandm_riemann_solvers.fpp, including the cross-module interface at the Riemann solver call site.Proposed change
Introduce a module-private wrapper type (or add to
m_derived_types.fppif reusable):Update
GPU_DECLARE, allocation, deallocation, and all call sites to usedqL_prim_dn%x/y/z.The cross-module call in
m_rhs.fppintom_riemann_solvers.fppmeans both modules must be updated together — this is a single atomic change.What this enables
Signature reduction. Every subroutine currently taking
dqL_dx, dqL_dy, dqL_dz, dqR_dx, dqR_dy, dqR_dz(6 arguments) takesdqL, dqR(2 arguments) after consolidation. With 7 subroutines affected, this removes ~42 argument slots from interfaces.Single allocation/deallocation site. The current allocation block is:
This becomes 2 lines. Same for deallocation and
GPU_DECLARE.Foundation for directional sweep unification. Once the gradient triplets are in a struct, the directional dispatch loops in
m_rhs.fppthat selectdqL_prim_dx_nvsdqL_prim_dy_nvsdqL_prim_dz_nbased onnorm_dircan be collapsed to a single block usingdqL_prim_dn%x/y/zas Fypp loop variables (see #1440).Scope
Files affected:
m_rhs.fpp,m_riemann_solvers.fpp(interface boundary).The change is mechanical but touches a cross-module interface, so a GPU build and the full viscous/diffusion test suite should be run before merging.
Related
m_riemann_solvers: reduce duplication, improve structure, add schemes #1426 (Riemann solver refactor — shares them_riemann_solversinterface)