Skip to contents

Commodities, processes, policies, and the containers that make a model

PDF, A4, 2 pages · energyRt 0.91.5.9015 (dev) · 2026-11-29
Build a model
GAS <- newCommodity("GAS", unit = "GWh",
  timeframe = "ANNUAL",
  emis = data.frame(comm = "CO2", emis = 0.2))
ELC <- newCommodity("ELC", unit = "GWh")
CO2 <- newCommodity("CO2", unit = "kt",
  timeframe = "ANNUAL")
SUP_GAS <- newSupply("SUP_GAS", commodity = "GAS",
  supply = data.frame(ava.up = 5e4, cost = 0.03))
IMP_GAS <- newImport("IMP_GAS", commodity = "GAS",
  import = data.frame(price = 0.05))
EGAS <- newTechnology("EGAS", desc = "Gas power plant",
  input = list(comm = "GAS"),
  output = list(comm = "ELC"),
  ceff = list(comm = "ELC", cact2cout = 0.55),
  cap2act = 8760, olife = 30,
  invcost = list(invcost = 900))
STG_BTR <- newStorage("STG_BTR", commodity = "ELC",
  seff = data.frame(inp.eff = 0.95,
                    out.eff = 0.95),
  duration = 4)  # GWh/GW: hours, ELC in GWh
TBD_ELC_R1_R2 <- newTrade("TBD_ELC_R1_R2", commodity = "ELC",
  routes = data.frame(src = c("R1", "R2"),
                      dst = c("R2", "R1")),
  trade = data.frame(src = c("R1", "R2"),
    dst = c("R2", "R1"), teff = 0.97))
DEM_ELC <- newDemand("DEM_ELC", commodity = "ELC",
  demand = data.frame(year = c(2025, 2050),
    demand = c(10, 18)))  # per timeslice
repo <- newRepository("demo", GAS, ELC, CO2,
  SUP_GAS, IMP_GAS, EGAS, STG_BTR, TBD_ELC_R1_R2, DEM_ELC)
mod <- newModel("demo", repo = repo,
  region = c("R1", "R2"),
  calendar = calendars$s4_h24,
  horizon = newHorizon(seq(2025, 2050, 5)),
  discount = 0.05)
Next: interpolate_model() and solve_model() -- see the Workflow sheet.
The same bricks, drawn: draw()
Slot conventions
list() / data.frame a slot is a table; list columns of equal length, data.frame recycles
v c r y t key columns: vintage, cluster, region, year, timeslice
NA key applies to every value of that key
x.lo/up/fx lower, upper, fixed; fx overrides both
years interpolated between the years given
obj@slot read a slot; update(obj, slot = ...) replaces it whole
unit = declare units; costs follow the model currency
Commodity
newCommodity(name, desc, unit, limtype, timeframe, geoframe, emis, agg, cluster, …)
limtype factor or character balance type: LO (default, surplus allowed), UP, FX
timeframe chr time level it is balanced at
geoframe chr region level it is balanced at (coarser = free transport inside)
emis df c emitted per unit consumed (× the burner's combustion)
comm emitted commodity
emis emission factor 0
agg df c this commodity as a weighted sum of others
comm member commodity
agg weight of the member 0 factor
Supply, import, export
newSupply(name, commodity, unit, supply, reserve, weather, region, …)
supply df cryt availability and cost per slice
ava.lo/up/fx bounds on the supply flow 0/∞/– comm/year
cost cost per unit 0 cur/comm
reserve df cr cumulative resource over the horizon
res.lo/up/fx bounds on the total extracted 0/∞/– comm
newImport(name, commodity, import, reserve, …)
import df cryt from outside the model
imp.lo/up/fx bounds on the import flow 0/∞/– comm/year
price price per unit 0 cur/comm
newExport(name, commodity, export, reserve, …)
Same shape: export with exp.* and price (revenue).
Demand
newDemand(name, commodity, unit, demand, region, …)
demand df cryt exogenous demand per region, year, timeslice
demand amount per timeslice 0 comm
Storage
newStorage(name, commodity, seff, duration, af, invcost, capacity, cycle, …)

Three parts, three capacities: charger inp.*, reservoir stg.*, discharger out.* -- prefixes on af, invcost, capacity, fixom, aeff.

seff df vcryt efficiencies
stg.eff share kept per year (decay) 1 frac
inp.eff charging efficiency 1 frac
out.eff discharging efficiency 1 frac
duration df vcry reservoir per unit of discharger, in the stored commodity's units (GWh/GW = h; PJ/GW is not)
duration[.lo/up/fx] energy-to-power ratio; .lo/.up/.fx bounds –/0/∞/– comm/cap
cycle chr timeframe the charge cycle closes in; "ANNUAL" by default
Trade
newTrade(name, commodity, routes, trade, capacity, invcost, olife, …)
routes df directed routes
src source region
dst destination region
trade df vcyt flow per route
ava.lo/up/fx absolute flow bounds, units per slice 0/∞/– comm/year
af.lo/up/fx flow bounds as a share of capacity 0/1/– frac
teff share delivered (1 = lossless) 1 frac
newACLine(name, commodity, from, to, reactance, …)
An AC line: one route pair and its reactance.
newDCLink(name, commodity, from, to, bidirectional, …)
A DC link, one or both directions.
Weather
newWeather(name, unit, timeframe, weather, cluster, …)
weather df cryt a series by region, year, slice
wval factor value 0 wval

Read by technology@weather (waf.*, wafc.*, wafs.*), supply@weather (wava.*), storage and trade -- as a multiplier on their bounds.

Technology
newTechnology(name, input, output, ceff, af, cap2act, invcost, ...)
The converter: every slot, the identities and four drawn examples on the Technology sheet.
Policies
newConstraint(name, eq, for.each, rhs, ...)
A linear rule over model variables; each ... list is a left-hand term.
CO2CAP <- newConstraint("CO2CAP",
  eq = "<=",
  for.each = data.frame(comm = "CO2",
    year = c(2030, 2040, 2050)),
  emis = list(variable = "vEmsFuelTot"),
  rhs = data.frame(year = c(2030, 2050),
                   rhs = c(5000, 2000)),
  defVal = Inf)
NEWGAS <- newConstraint("NEWGAS",
  eq = "<=", rhs = 50,
  cap = list(variable = "vTechNewCap",
             for.sum = list(tech = "EGAS")))
for.each: one row per constraint; for.sum: summed over. Terms also select by process_ (regex), vintage, cluster, classes.
newTax(name, comm, process, classes, tax, …)
CO2TAX <- newTax("CO2TAX", comm = "CO2",
  tax = data.frame(year = c(2030, 2050),
                   bal = c(20, 100)))
Rate columns: inp, out, bal (per unit of flow), act, cap, ncap (per process).
newSubsidy(name, process, subsidy, …)
Same columns as newTax(), paid instead of charged.
newCosts(name, variable, mult, subset, …)
Any variable × a multiplier into the objective.
Containers
newRepository(name, ...)
An unordered bag of bricks; add(repo, obj) adds more.
add(obj, ...)
newCalendar(name, timetable, …)
Sub-annual structure; or take one from the calendars catalogue.
names(calendars)   # "annual" "s4" "s4_h24" "d365_h24" ...
cal <- newCalendar(name = "two_seasons",
  timetable = make_timetable(struct = list(
    ANNUAL = "ANNUAL",
    SEASON = c("WIN", "SUM"))))
newHorizon(period, intervals, base_year, …)
Milestone years and the period each one stands for.
newModel(name, repo, region, calendar, horizon, discount, ...)
Binds a repository to regions, a calendar and a horizon.
Time & space
setCalendar(obj, ...)
Change the calendar of a model.
recast_model_calendar(object, calendar, …)
Move a model's data to another calendar.
setGeoscale(obj, geoscale, ...)
Multi-level regions; commodities balance at their geoframe.
subset_model_regions(object, region, …)
Keep some regions.
aggregate_model_regions(object, level, clusters, …)
Merge regions into groups.
Look at a brick
draw(EGAS)                 # flow structure
autoplot(EGAS)             # its data over years
getData(GAS)             # slots as tables
names(repo); repo$EGAS     # repository members
report(object, ...)
A datasheet of any brick, model or scenario.
The commodity balance
out = sup + tech + stg + imp + ems + agg -- produced: supply, technology and storage output, imports, fuel emissions, aggregation
inp = dem + tech + stg + exp -- consumed: demand, technology and storage input, exports
bal = out − inp -- LO: bal ≥ 0 (surplus allowed) · UP: bal ≤ 0 · FX: bal = 0

One balance per commodity, region, year and timeslice -- at the commodity's timeframe and geoframe. Trade enters as imports and exports between regions.

vEmsFuelTot Emissions from fuel combustion cryt
vBalance Net commodity balance (all sources) cryt
vSupOut Output of supply cryt
vDemInp Input to demand cryt
vOutTot Total output, all processes cryt
vInpTot Total input, all processes cryt
vDummyImport Slack import, for debugging cryt
vDummyExport Slack export, for debugging cryt
vImportTot Total regional import (Ir + ROW) (weighted) cryt
vExportTot Total regional export (Ir + ROW) (weighted) cryt
Units & currencies

Declare units on commodities (unit =) and processes (units slot); getUnits(obj) lists them.

convert("PJ", "GWh")              # 277.78
convert("EUR/kW", "MEUR/GW", 2000)
convert(1, "MEUR2020", "MUSD2020") # FX
convert(1, "MUSD2015", "MUSD2020") # CPI
COA <- newCommodity("COA", unit = "PJ",
  property = data.frame(
    property = c("lhv", "density"),
    value = c(25.8, 0.85),
    unit = c("GJ/t", "t/m3")))
commodity_property(COA, "lhv")
Physical properties travel with the commodity, with their units.
commodity_properties()
Property names the converter knows.
currency_base_year(year)
Pin the year of the money unit.
add_currency_fx(code, year, lcu_per_usd, source)
Add an exchange rate the shipped tables lack.