Let’s say that I build my model using functions that, if need be create variables and parameters, and return equations. In the end of the code i put all equations together. Let’s say I have an example block such as
using ModelingToolkit
@variables t # independent variable (time)
@variables f(t) = 0.0 # external forcing
function external_forcing_equation(; CO2_multiplier = 4, specs...)
@parameters CO2_multiplier = CO2_multiplier
@parameters CO2_forcing = 5.35 # 5.35 is A0
# Register a time-dependent step-like increase of forcing
CO2_instant_increase(t) = t < 1000 ? 0.0 : CO2_multiplier*CO_forcing
@register_symbolic CO2_instant_increase(t)
return f ~ CO2_instant_increase
end
This codeblock won’t work, it yields
ERROR: syntax: Global method definition around C:\Users\gd419\.julia\packages\Symbolics\CNA2l\src\register.jl:91 needs to be placed at the top level, or use "eval".
Stacktrace:
[1] top-level scope
@ REPL[31]:1
I am not sure how to proceed from here because putting @eval
before @register
doesn’t solve the problem either. How can I create a “registered function” within another function?