This set of scripts is to help the user interrogate and analyse the energetics-related outputs from SPINS.
There are two toolboxes:
- Offline_Sorting : a MATLAB implementation of the sorting algorithm & checks for it's validity
- Analyse_Diagnos : Analysis of onboard SPINS diagnostics
Author: Sam Hartharn-Evans, 2022
calc_energetics is a re-formulation of SPINSmatlab plot_diagnos, which works for even very large number of outputs. Unlike, it reduces the temporal frequency consistently onto a regularly spaced grid across all outputs, and implements a different filter onto BPE which works for any size array. The diagnostics are then used to calculate BPE, PE, KE, APE, etc using the same equations as Deepwell.
filt_design is to explain the choice of timeseries filter used in calc_energetics BPE filter, compared to the one used in plot_diagnos. Three filters are explored, mlptdenoise, a spectral lowpass filter, and the MATLAB smooth filter (running mean).
mixing_characteristics calculates some characteristics which are
relevant to mixing:
- Pycnocline thickness, Nz in pycnocline, Dz in pycnocline,
$L_{pyc}/Dx$ -
$Sc = \nu/\kappa_{\rho}$ : Schmidt number, indicating momentum diffusivity over molecular diffusivity - Characterises the SPINS filter (exponential or hyperviscosity), assuming
$k_{nyquist} = \frac{\pi}{Lx}(Nx-1)$
sort_energetics.m employs the Winters (1995)-like sorting algorithm for a
mapped case to calculate BPE for a mapped grid (based off sorted stratification across the entire domain,
run_sort_energetics.m calculates and saves the output of sort_energetics for each timestep.
plot_offline_energetics.m plots timeseries of each energetic component, and can optionally compare these to all_diagnos.mat produced from plot_diagnos.m:
check_rhob_hovmoller plots diagnostics related to the sorting algorithm

- a) Reference density profile (
$\rho_b$ ) hovmoller - b) Change in reference density profile (
$\rho_b - \rho_b(0)$ ) hovmoller - c) Mass deviation timeseries
- d) Change in BPE over time
(b) is very useful to indicate if things look correct, we'll see a dipole band appear around the pycnocline, intensifying through the timeseries. (c) indicates if things look very wrong, for example if the mass suddenly ramps up.

