SciML / ModelingToolkitStandardLibrary.jl

A standard library of components to model the world and beyond
https://docs.sciml.ai/ModelingToolkitStandardLibrary/stable/
MIT License
115 stars 36 forks source link

how to pass exogenous input signals to components? #123

Open YangyangFu opened 1 year ago

YangyangFu commented 1 year ago

For most systems, there will be exogenous input signals as control inputs/disturbances, such as the outdoor air temperature.

Say I have a zone temperature file saved as a csv, and the temperature is sampled every hour. But I have a system, which runs at a time step of 5 min. How can I connect this exogenous temperature to Thermal.PrescribedTemperature, and solve the resulting ODE on a 5-minute basis?

In Modelica, there is a block called TimeTable, which performs auto interpolation between time indexes. Is there any similar block in ModelingToolkitStandardLibrary for this purpose?

ValentinKaisermayer commented 1 year ago

Unfortunately there is no component to do this at the moment but there should be. Or at least a tutorial to demonstrate a solution to this not uncommon task.

You have two options:

YangyangFu commented 1 year ago

Thanks a lot for these very helpful suggestions. I will take a look soon.

baggepinnen commented 1 year ago

The easiest way to incorporate data like this is probably to create an interpolation function using any of the interpolators from https://github.com/PumasAI/DataInterpolations.jl

Have a look at how some of the sources in the standard librsry are implemented, like the sine source https://github.com/SciML/ModelingToolkitStandardLibrary.jl/blob/9cfa7875e8eac8a46d8997a165f851aff888c94f/src/Blocks/sources.jl#L94 Then change the equation to use the interpolator $int(t)$ instead of $\sin(t)$

ValentinKaisermayer commented 1 year ago

If this is implemented without a discrete update operator or callback, your data has to be somewhat smooth in oder to get correct results. Although, in the library are step sources that seem to work just fine without, so the solvers are already quite good at handling this.