# How does ModelingToolkit substitute the u0map?

**URL:** <https://discourse.julialang.org/t/how-does-modelingtoolkit-substitute-the-u0map/72688>\
**Category:** Chemistry\
**Tags:** question, symbolic, modelingtoolkit, symbolics, catalyst\
**Created:** [December 7, 2021, 12:37am UTC](https://discourse.julialang.org/t/how-does-modelingtoolkit-substitute-the-u0map/72688 "2021-12-07T00:37:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjwyett](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjwyett/32/13345_2.png) [@cjwyett](https://discourse.julialang.org/u/cjwyett)\
**Post date:** [December 7, 2021, 12:37am UTC](https://discourse.julialang.org/t/how-does-modelingtoolkit-substitute-the-u0map/72688/1 "2021-12-07T00:37:26Z")

</div>

Hi there, I’m trying to port some code over to use Catalyst.

```julia
using Catalyst, Symbolics

rs = @reaction_network begin
    1, 2A --> B
    2, B + C --> 0
end

v = Catalyst.oderatelaw.(reactions(rs))
u0 = [1,1,1]

```

Now if i want to substitute `u0` into `v`:

```julia
substitute(convert.(Num, v), Dict(species(rs) .=> u0))

```

This works, but the `convert` in there feels clunky. Is this what’s going on under the hood or is there a nicer way of doing it?

Many thanks!

---

<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:** [December 7, 2021, 3:46am UTC](https://discourse.julialang.org/t/how-does-modelingtoolkit-substitute-the-u0map/72688/2 "2021-12-07T03:46:29Z")

</div>

The code looks like this, where `u0map` is a dict from symbolic variables to values and comes from the user, and `dvs` are typically the states of the system (dependent variables).

```julia
defs = defaults(sys)
u0 = ModelingToolkit.varmap_to_vars(u0map, dvs; defaults=defs)

```

The `varmap_to_vars` helps you map symbolic names to indices

---

<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:** [December 7, 2021, 3:48am UTC](https://discourse.julialang.org/t/how-does-modelingtoolkit-substitute-the-u0map/72688/3 "2021-12-07T03:48:10Z")

</div>

You can find more info here  
[https://mtk.sciml.ai/dev/basics/FAQ/#Transforming-value-maps-to-arrays](https://mtk.sciml.ai/dev/basics/FAQ/#Transforming-value-maps-to-arrays)
