My attempt at fitting a simple energy balance model into an OpenGL compute shader.
Requires NetCDF, GLFW, and OpenGL. It may be necessary to fiddle with LFLAGS
and CFLAGS
inside the Makefile, depending on your system configuration.
TODO: Add and document process switches.
The outgoing long-wave radiation $\Phi_{OLR}$ is computed by:
\Phi_{OLR} = A + B * T
Where $A$ and $B$ are configurable parameters.
TODO.
The albedo $\alpha$ is computed by:
\alpha(T, ...) =
\left\{\begin{matrix}
\alpha_{0} + \alpha_{2}P_{2}(\sin(\phi)) & T > T_{f}\\
\alpha_{i} & T \le T_{f}
\end{matrix}\right.
Where $\alpha{0}$, $\alpha{2}$, and $\alpha_{i}$ are configurable parameters.
The surface temperature $T$ is computed from the energy balance of OLR and ASR. The ASR is computed by:
\Phi_{ASR} = (1 - \alpha) Q
And is then used to compute $T$ like so:
C \frac{\partial T}{\partial t} = \Phi_{ASR} - \Phi_{OLR}
Where $C$ is the specific heat, calculated from the depth $h$ like so:
C = 4184.3 \frac{\textup{J}}{\textup{m}^{2}\textup{K}} \times 1000 \frac{\textup{kg}}{\textup{m}^{3}} \times h
Where the depth is a configurable parameter.
TODO.
The moist amplification factor $f$ is computed (and used in the advection-diffusion schema) thusly:
TODO.
After you have installed the necessary dependencies, simply run:
make
to compile the executable, which will be named glEBM
by default.
The model expects to be fed a NetCDF file with two dimenstions: lat
, and lon
. It uses these to pick grid cell centers and to identify the dimensions of the model. In order for the model to function, the model dimensions must both be multiples of 32.
The following optional parameters (along with their default values) are listed below:
T
, Ts
, Temperature
, temperature
). Defaults to 273.15K.A
, As
). Defaults to 210.0 W/m2.B
, Bs
). Defaults to 2.0 W/m/K.depth
, depths
). Defaults to 30.0 m.a0
, a0s
). Defaults to 0.3.a2
, a2s
). Defaults to 0.078.ai
, ais
). Defaults to 0.62.The model may be executed by running:
glEBM <path_to_input_file.nc> <path_to_output_file.nc>
The results will be placed into a single NetCDF file.