Skip to content

Consolidate dqL/R_prim_dx/dy/dz_n triplets into a single derived type argument across m_rhs and m_riemann_solvers #1441

@sbryngelson

Description

@sbryngelson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions