mod_linear_solver Module

Preconditioned Conjugate Gradient (PCG) linear solver and operators.

This module houses the pure numerical and linear algebra routines used by the LowMachReact-Hex framework. It manages the static Poisson matrix cache, temporary workspace allocations, Preconditioned Conjugate Gradient (PCG) solver loop, sparse matrix-vector products, and zero-mean gauge projections for pure Neumann systems.



Variables

Type Visibility Attributes Name Initial
type(pressure_operator_cache_t), public, save :: pressure_cache
type(projection_workspace_t), public, save :: projection_work
integer, private, parameter :: pcg_nullspace_projection_interval = 50

Variable-density pure-Neumann pressure systems use an explicit zero-mean projection to control the constant nullspace.


Derived Types

type, public ::  pressure_operator_cache_t

Cached sparse matrix coefficients for the Pressure Poisson operator.

Components

Type Visibility Attributes Name Initial
real(kind=rk), public, allocatable :: coeff(:,:)
real(kind=rk), public, allocatable :: diag(:)
logical, public :: has_dirichlet_pressure = .false.
logical, public :: has_neumann_outlet = .false.
logical, public :: initialized = .false.
integer, public :: max_faces = 0
integer, public, allocatable :: nb(:,:)
integer, public :: ncells = 0
real(kind=rk), public, allocatable :: var_coeff(:,:)
real(kind=rk), public, allocatable :: var_diag(:)

type, public ::  projection_workspace_t

Temporary workspace for projection step calculations.

Components

Type Visibility Attributes Name Initial
real(kind=rk), public, allocatable :: ap(:)
logical, public :: initialized = .false.
real(kind=rk), public, allocatable :: local_ap(:)
real(kind=rk), public, allocatable :: local_face_flux(:)
real(kind=rk), public, allocatable :: local_scalar(:)
real(kind=rk), public, allocatable :: local_vec(:,:)
real(kind=rk), public, allocatable :: local_vec_star(:,:)
integer, public :: ncells = 0
integer, public :: nfaces = 0
real(kind=rk), public, allocatable :: predicted_face_flux(:)
real(kind=rk), public, allocatable :: pvec(:)
real(kind=rk), public, allocatable :: r(:)
real(kind=rk), public, allocatable :: rhs_poisson(:)
real(kind=rk), public, allocatable :: z(:)

type, public ::  solver_stats_t

Dummy/diagnostic solver statistics structure mirroring the one in flow. Keeping structural declarations isolated or shared if needed.

Components

Type Visibility Attributes Name Initial
real(kind=rk), public :: cfl = zero
real(kind=rk), public :: kinetic_energy = zero
real(kind=rk), public :: max_divergence = zero
real(kind=rk), public :: max_velocity = zero
real(kind=rk), public :: min_species_y = zero
real(kind=rk), public :: net_boundary_flux = zero
integer, public :: pressure_iterations = 0
real(kind=rk), public :: pressure_iterations_avg = zero
integer, public :: pressure_iterations_max = 0
integer, public :: pressure_iterations_total = 0
real(kind=rk), public :: pressure_residual = zero
real(kind=rk), public :: pressure_residual_abs = zero
integer, public :: pressure_solve_count = 0
real(kind=rk), public :: rms_divergence = zero
real(kind=rk), public :: total_mass = zero
real(kind=rk), public :: wall_time = zero

Functions

public function face_normal_distance(mesh, bc, face_id, cell_id, nb) result(dist)

Calculates the distance between cell and neighbor center along face normal.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(bc_set_t), intent(in) :: bc
integer, intent(in) :: face_id
integer, intent(in) :: cell_id
integer, intent(in) :: nb

Return Value real(kind=rk)

public pure function outward_normal(mesh, face_id, cell_id) result(nvec)

Determines the outward unit normal relative to a specific cell.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
integer, intent(in) :: face_id
integer, intent(in) :: cell_id

Return Value real(kind=rk), (3)

public function pressure_cache_has_dirichlet_pressure() result(flag)

Expose Dirichlet flag from cache.

Arguments

None

Return Value logical

public function pressure_cache_has_neumann_outlet() result(flag)

Expose Neumann outlet flag from cache.

Arguments

None

Return Value logical

public function pressure_face_inverse_density(transport, owner, nb) result(beta)

Face-centered inverse density coefficient for variable-density projection.

Arguments

Type IntentOptional Attributes Name
type(transport_properties_t), intent(in) :: transport
integer, intent(in) :: owner
integer, intent(in) :: nb

Return Value real(kind=rk)

private function pressure_preconditioner_diag(params, c) result(diag_value)

Select the active diagonal used by the pressure PCG preconditioner.

Arguments

Type IntentOptional Attributes Name
type(case_params_t), intent(in) :: params
integer, intent(in) :: c

Return Value real(kind=rk)


Subroutines

public subroutine ensure_pressure_operator_cache(mesh, flow, bc)

Pre-computes Laplacian coefficients for the Poisson operator.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(in) :: flow
type(bc_set_t), intent(in) :: bc

public subroutine ensure_projection_workspace(mesh)

Allocate persistent solver workspace.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh

Deallocate temporary work arrays.

Arguments

None

public subroutine solve_pressure_correction(mesh, flow, bc, params, transport, rhs, phi, stats)

Iteratively solves the Pressure Poisson system using PCG.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(inout) :: flow
type(bc_set_t), intent(in) :: bc
type(case_params_t), intent(in) :: params
type(transport_properties_t), intent(in) :: transport
real(kind=rk), intent(in) :: rhs(:)
real(kind=rk), intent(inout) :: phi(:)
type(solver_stats_t), intent(inout) :: stats

public subroutine subtract_owned_mean_scalar(flow, scalar)

Remove the constant nullspace component from an owned-cell scalar.

Arguments

Type IntentOptional Attributes Name
type(flow_mpi_t), intent(in) :: flow
real(kind=rk), intent(inout) :: scalar(:)

public subroutine update_variable_pressure_operator_cache(mesh, flow, bc, transport)

Rebuild per-step variable-density pressure coefficients.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(in) :: flow
type(bc_set_t), intent(in) :: bc
type(transport_properties_t), intent(in) :: transport

private subroutine pressure_matvec(mesh, flow, bc, params, x, local_ax)

Sparse Matrix-Vector multiplication for the Laplacian operator.

Arguments

Type IntentOptional Attributes Name
type(mesh_t), intent(in) :: mesh
type(flow_mpi_t), intent(in) :: flow
type(bc_set_t), intent(in) :: bc
type(case_params_t), intent(in) :: params
real(kind=rk), intent(in) :: x(:)
real(kind=rk), intent(out) :: local_ax(:)