# MTK simulation allocation free?

**URL:** https://discourse.julialang.org/t/mtk-simulation-allocation-free/119581
**Category:** Modelling & Simulations
**Tags:** question, modelingtoolkit
**Created:** [September 19, 2024, 3:39am UTC](https://discourse.julialang.org/t/mtk-simulation-allocation-free/119581 "2024-09-19T03:39:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [September 19, 2024, 3:39am UTC](https://discourse.julialang.org/t/mtk-simulation-allocation-free/119581/1 "2024-09-19T03:39:17Z")

</div>

Is it possible to simulate an MTK model allocation-free?

The task is to run a simulation in a control loop with 1ms update interval in real-time.

---

<div class="post-metadata">

### Author: ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)
#### Post date: [September 19, 2024, 4:22am UTC](https://discourse.julialang.org/t/mtk-simulation-allocation-free/119581/2 "2024-09-19T04:22:20Z")

</div>

Under certain circumstances (ODE of not too large state dimension) it is possible.

You can use [`ModelingToolkit.generate_control_function`](https://docs.sciml.ai/ModelingToolkit/dev/basics/InputOutput/#Generating-a-dynamics-function-with-inputs,-f) to generate the dynamics function with inputs, and then [`SeeToDee.Rk4`](https://baggepinnen.github.io/SeeToDee.jl/dev/) which is an allocation-free RK4 integrator when used with StaticArrays to discretize this dynamics and step it forward with your desired sample interval.
