PALEOocean functions
Helper functions for use by Reactions.
Configuring Domains and Variables
PALEOocean.Ocean.set_model_domains
— Functionset_model_domains(model::PB.Model, oceangrid, surfacegrid, floorgrid)
Set model Domain
sizes and Subdomains for ocean, oceansurface, oceanfloor Domain
s. (Helper function for a Reaction implementing ocean transport.)
PALEOocean.Ocean.find_transport_vars
— Functionfind_transport_vars(domain::PB.AbstractDomain; transport_input_components=false)
-> (conc_vars, sms_vars, input_components, num_components)
Find all variables in domain
with attribute :advect == true, and then use naming convention <rootname>_conc
to identify <rootname>_sms
Variables to add transport flux to.
If transport_input_components = true
, also define input_components
as <varname>_transport_input
to calculate advective transport input into each cell (slow)
Constructing and using transport matrices
PALEOocean.Ocean.add_loop!
— Functionadd_loop!(A::AbstractMatrix, vm::AbstractVector, L::Real, loopindices)
Add circulation with flux L
to transport matrix A
, around a closed loop loopindices
.
Transport matrix A
(s^{-1}) represents tracer transport,
dc/dt = A * c
where c
is Vector of tracer concentrations
loopindices
is a list of cell indices representing a closed loop, eg [2, 3, 4, 2]
Units for tracers and fluxes are:
- Ocean / volume based:
c
: mol m-3 tracer concentrationvm
: m^3. volume per cellL
: m^3 s-1 (volume flux, cf 1 Sverdrup = 1e6 m^3 s-1)
- Atmosphere / mass based
c
: kg / total kg, tracer mass mixing ratiovm
: kg, total mass per callL
: kg s-1 (mass flux)
PALEOocean.Ocean.prepare_transport
— Functionprepare_transport(m::ReactionMethod, (grid_vars, conc_components, sms_components, input_components)) ->
(grid_vars, conc_components, sms_components, input_components, buffer)
Add an additional buffer
for do_transport
. conc_components
, sms_components
, optional input_components
are Vectors of data Arrays (as created by VarList_components
from lists generated by find_transport_vars
).
PALEOocean.Ocean.do_transport
— Functiondo_transport(grid_vars, conc_components, sms_components, input_components, buffer, dtm::AbstractMatrix, cr::AbstractCellRange)
Calculate transport rates.
Arguments
grid_vars, conc_components, sms_components, input_components
: Vectors of data Arrays (created by VarList_components)buffer
: buffer arrays created byprepare_transport
dtm::AbstractMatrix
: transport matrix (units yr-1)
PALEOocean.Ocean.do_transport_tr
— Functiondo_transport_tr(grid_vars, conc_components, sms_components, input_components, buffer,
dtm_tr::SparseArrays.SparseMatrixCSC, cr::PB.AbstractCellRange)
do_transport_tr(grid_vars, conc_components, sms_components, input_components, buffer,
colptr, rowval, (nzval1, nzval2), (wt1, wt2), cr::PB.AbstractCellRange)
Memory-bandwidth optimised version of do_transport
using transposed matrix dtm_tr
. This is an optimisation specifically tied to the Compressed Sparse Column storage layout (Julia SparseMatrixCSC).
If two matrices are supplied with a common sparsity pattern specified by colptr
, rowptr
, applies a linear combination with (wt1, wt2)
Optimized SIMD transport matrix x contiguous packed conc data array
Optimized transport using transport matrices with a common sparsity pattern
PALEOocean.Ocean.TrsptCSC
— TypeTrsptCSC
Store multiple SparseArrays.SparseMatrixCSC with a common sparsity pattern.
This allows fast interpolation for eg a time-series of transport matrices over a seasonal cycle.
SparseMatrixCSC format, except with a Vector of nzval, ie:
colptr
: Column j is in colptr[j]:(colptr[j+1]-1)rowval
: Row indices of stored valuesnzval
: Vector of Vector of non-zero values
PALEOocean.Ocean.create_common_sparsity_tr!
— Functioncreate_common_sparsity_tr!(a_matrices; do_transpose, TMeltype=Float64) -> TrsptCSC
Reduce a collection of matrices to common sparsity pattern, optionally transposing.
NB: a_matrices
is used as workspace and contents deleted.
Optimized transport using SIMD packed vectors
PALEOocean.Ocean.PackedBuffer
— TypePackedBuffer
Buffer Arrays for optimized SIMD transport using elements of type SIMD.Vec{pack_chunk_width, pack_eltype}
. Creates packed_conc_array
for packed and padded Variable concentrations, and an additional workspace buffer
. Uses additional type parameters to allow do_transport_tr
specialization on number of Variable components etc as well as SIMD chunk width.