ocean_budgets_t Derived Type

type, public :: ocean_budgets_t


Inherits

type~~ocean_budgets_t~~InheritsGraph type~ocean_budgets_t ocean_budgets_t type~budget_contributor_t budget_contributor_t type~ocean_budgets_t->type~budget_contributor_t contributors type~diag_mask_t diag_mask_t type~ocean_budgets_t->type~diag_mask_t mask type~hgrid_t hgrid_t type~ocean_budgets_t->type~hgrid_t grid

Components

Type Visibility Attributes Name Initial
real(kind=wp), public, allocatable :: areaT(:,:)

Per-cell T-area (m²) copied from the metrics slot via set_area. Physical integrals weight by mask%weight·areaT; falls back to grid%dx·grid%dy until set.

type(budget_contributor_t), public, allocatable :: contributors(:)
type(hgrid_t), public :: grid
logical, public :: has_snapshot = .false.

True once init_snapshot has populated values_init.

logical, public :: is_init = .false.
type(diag_mask_t), public, allocatable :: mask

Optional region mask. Default = whole interior (built lazily); reset via set_mask.

integer, public :: n_contributors = 0
integer, public :: n_contributors_max = 0
integer, public :: nbudgets = BUDGET_N_DEFAULT
real(kind=wp), public :: values(BUDGET_N_DEFAULT) = 0.0_wp
real(kind=wp), public :: values_init(BUDGET_N_DEFAULT) = 0.0_wp

Type-Bound Procedures

procedure, public, non_overridable :: bytes => ocean_budgets_bytes

  • private pure function ocean_budgets_bytes(this) result(nbytes)

    Counted allocatable footprint of the conservation budgets (own accumulator; registry contributors are counted by their owning slot) slot (0 when unallocated).

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(in) :: this

    Return Value integer(kind=int64)

procedure, public, non_overridable :: destroy => ocean_budgets_destroy

procedure, public, non_overridable :: drain_contributors => ocean_budgets_drain_contributors

  • private subroutine ocean_budgets_drain_contributors(this)

    For each contributor: integrate per_cell·mask·areaT (over k) into total_integrated, then zero per_cell for the next window.

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this

procedure, public, non_overridable :: evaluate => ocean_budgets_evaluate

  • private subroutine ocean_budgets_evaluate(this, ms)

    Recompute this%values(:) from the current multilayer state. Honours this%mask — sums are weighted by mask%weight · areaT.

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this
    type(multilayer_state_t), intent(in) :: ms

procedure, public, non_overridable :: init => ocean_budgets_init

procedure, public, non_overridable :: init_snapshot => ocean_budgets_init_snapshot

  • private subroutine ocean_budgets_init_snapshot(this, ms)

    Snapshot values_init from the current state. Call once after the IC is set + the EOS has run, before stepping.

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this
    type(multilayer_state_t), intent(in) :: ms

procedure, public, non_overridable :: register_contributor => ocean_budgets_register_contributor

  • private subroutine ocean_budgets_register_contributor(this, name, quantity, per_cell, device_resident)

    Register a per-kernel contributor: store a non-owning pointer to the kernel-owned per_cell + metadata. Set device_resident when per_cell is GPU-mapped (drain syncs it). Idempotent on name (re-registering updates the pointer, resets the integral).

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this
    character(len=*), intent(in) :: name
    integer, intent(in) :: quantity
    real(kind=wp), intent(in), target :: per_cell(:,:,:)
    logical, intent(in), optional :: device_resident

procedure, public, non_overridable :: set_area => ocean_budgets_set_area

  • private subroutine ocean_budgets_set_area(this, areaT)

    Cache the per-cell T-area (m²) from the metrics slot. After this, physical integrals weight by mask%weight·areaT; before it they fall back to grid%dx·grid%dy (= areaT on uniform Cartesian).

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this
    real(kind=wp), intent(in) :: areaT(:,:)

procedure, public, non_overridable :: set_mask => ocean_budgets_set_mask

  • private subroutine ocean_budgets_set_mask(this, mask)

    Override the default global mask. Useful for regional conservation diagnostics — “mass north of 30°S stays at FP.”

    Arguments

    Type IntentOptional Attributes Name
    class(ocean_budgets_t), intent(inout) :: this
    type(diag_mask_t), intent(in) :: mask

Source Code

   type :: ocean_budgets_t
      logical :: is_init = .false.

      ! ---- Active integrals ----
      integer :: nbudgets = BUDGET_N_DEFAULT
      real(wp) :: values(BUDGET_N_DEFAULT) = 0.0_wp
      real(wp) :: values_init(BUDGET_N_DEFAULT) = 0.0_wp
      logical :: has_snapshot = .false.
         !! True once `init_snapshot` has populated `values_init`.

      ! ---- Geometry cache ----
      type(hgrid_t) :: grid
      real(wp), allocatable :: areaT(:, :)
         !! Per-cell T-area (m²) copied from the metrics slot via `set_area`.
         !! Physical integrals weight by `mask%weight·areaT`; falls back to
         !! `grid%dx·grid%dy` until set.

      ! ---- Region restriction ----
      type(diag_mask_t), allocatable :: mask
         !! Optional region mask.  Default = whole interior (built lazily);
         !! reset via `set_mask`.

      ! ---- Per-kernel contributors ----
      ! Populated via `register_contributor`, drained each eval cadence.
      ! Budget identity: LHS = values(q) − values_init(q),
      ! RHS = Σ contributors of quantity q %total_integrated, residual = LHS − RHS.
      type(budget_contributor_t), allocatable :: contributors(:)
      integer :: n_contributors = 0
      integer :: n_contributors_max = 0
   contains
      procedure, non_overridable :: init => ocean_budgets_init
      procedure, non_overridable :: destroy => ocean_budgets_destroy
      procedure, non_overridable :: set_area => ocean_budgets_set_area
      procedure, non_overridable :: set_mask => ocean_budgets_set_mask
      procedure, non_overridable :: init_snapshot => ocean_budgets_init_snapshot
      procedure, non_overridable :: evaluate => ocean_budgets_evaluate
      procedure, non_overridable :: register_contributor => ocean_budgets_register_contributor
      procedure, non_overridable :: drain_contributors => ocean_budgets_drain_contributors
      procedure, non_overridable :: bytes => ocean_budgets_bytes
   end type ocean_budgets_t