Optimization of the default MARGO configuration

Using ClimateMARGO.jl

using ClimateMARGO
using ClimateMARGO.Models
using ClimateMARGO.Optimization

Loading preset configurations

Load the pre-defined default MARGO parameters, which are described by the ClimateModelParameters struct

params = deepcopy(ClimateMARGO.IO.included_configurations["default"])
ClimateMARGO.Models.ClimateModelParameters("default", ClimateMARGO.Models.Domain(5.0, 2020.0, 2020.0, 2200.0), ClimateMARGO.Models.Economics(100.0, 0.02, 0.01, 0.02, 8.5, 0.055489419901509705, 36.97631285953187, 0.5658234787375677, 0.115, 0, 0, 0, 0, [7.5, 8.4375, 9.375, 10.3125, 11.25, 12.1875, 13.125, 14.0625, 15.0, 15.9375  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], 0.0, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]), ClimateMARGO.Models.Physics(460.0, 1.1, 4.977297891066924, 1.13, 106.0, 0.73, 0.5))

Create a MARGO instance based on these parameters

m = ClimateModel(params);

By default, the climate control timeseries are all set to zero.

m.controls
ClimateMARGO.Models.Controls([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0  …  0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])

Real-time climate optimization

Let's optimize the controls with the default settings, which finds the cheapest combination of the control timeseries that keeps adapted temperatures below 2°C.

@time optimize_controls!(m, temp_goal=1.5);
Solve_Succeeded
  0.178285 seconds (245.21 k allocations: 10.210 MiB, 33.87% compilation time)

The optimization can be slow the first time since it has to compile. Let's re-initialize the model and see how fast it runs now that the the optimization routine has been precompiled.

m = ClimateModel(params);
@time optimize_controls!(m, temp_goal=1.5);
Solve_Succeeded
  0.116712 seconds (173.09 k allocations: 6.220 MiB)

Visualizing the results

Finally, let's plot the resulting temperature timeseries

using PyPlot
fig, axes = ClimateMARGO.Plotting.plot_state(m, temp_goal=1.5);
gcf()

This page was generated using Literate.jl.