# 2D arrays with ModelingToolkit

**URL:** https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448
**Category:** Modelling & Simulations
**Tags:** question, package, modelingtoolkit
**Created:** [December 11, 2023, 2:33pm UTC](https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448 "2023-12-11T14:33:53Z")
**Posts on this page:** 3
**Page:** 2

<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: [December 15, 2023, 8:20pm UTC](https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448/22 "2023-12-15T20:20:43Z")

</div>

I also implemented that in the following Julia package: [https://github.com/ufechner7/KiteModels.jl/blob/main/src/KPS4.jl](https://github.com/ufechner7/KiteModels.jl/blob/main/src/KPS4.jl) , but in this package I was doing these calculations numerically and not symbolically. It uses a lookup table:

```julia
const SPRINGS_INPUT = [0. 1. 150.
                       1. 2. -1. # s1, p7, p8
                       4. 2. -1. # s2, p10, p8                        
                       4. 5. -1. # s3, p10, p11
                       3. 4. -1. # s4, p9, p10
                       5. 1. -1. # s5, p11, p7
                       4. 1. -1. # s6, p10, p7
                       3. 5. -1. # s7, p9, p11
                       5. 2. -1. # s8, p11, p8
                       2. 3. -1.] # s9, p8, p9

```

to define which springs are connecting which point masses…

I don’t see any issue to do something similar symbolically… But it would take a lot of time, it is very easy to make mistakes and they are hard to debug…

In other words, perhaps the better approach with ModelingToolkit is to create components and connect them, but I don’t have any experience with this approach…

---

<div class="post-metadata">

### Author: ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)
#### Post date: [December 18, 2023, 9:01am UTC](https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448/23 "2023-12-18T09:01:09Z")

</div>

> [@ufechner7](#):
>
> In other words, perhaps the better approach with ModelingToolkit is to create components and connect them, but I don’t have any experience with this approach…

Yes I think it is the way to go too. I wonder, if this necessitates connectors, or if a more straightforward approach like in my previous post is enough.

Another thing. I get some errors related to symbolic vectors when calling `structural_simplify` without specifying only scalar parameters in `ODESystem`. Such as the following.

```julia
julia> sys = structural_simplify(model)
ERROR: MethodError: no method matching hasmetadata(::Vector{SymbolicUtils.BasicSymbolic{Real}}, ::Type{Symbolics.VariableDefaultValue})

```

Did you get such errors ?

@ChrisRackauckas, is this still a missing functionality, should I file an issue ?

* * *

EDIT : So I found a way to circumvent this problem by (without much surprise) iterating through the symbolic vectors. So for instance, if you have an `ODESystem` such as

```julia
@named _model = ODESystem(eqs, t)

```

where some symbolic parameters are arrays, one way to make it work is to do

```julia
@named _model = ODESystem(eqs, t, [<list of all symbolic variables of interest, even arrays>], [mysymbolicparameterarray...])

```

With the same logic, getting the default value of a given parameter array dos not work so something like `[ModelingToolkit.getdefault(d) for d in sys.mysymbolicparameterarray]` seems to be the only solution.

---

<div class="post-metadata">

### Author: ![BambOoxX](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bambooxx/32/22179_2.png) [@BambOoxX](https://discourse.julialang.org/u/BambOoxX)
#### Post date: [December 19, 2023, 8:25am UTC](https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448/24 "2023-12-19T08:25:28Z")

</div>

For the record it seems such an implementation is presented in [Exposing More Parallelism By Tearing Algebraic Equations in ODESystems · ModelingToolkit.jl](https://docs.sciml.ai/ModelingToolkit/stable/examples/tearing_parallelism/#The-Model)

```julia
<...>
eqs = [
    D(E) ~ sum(((i, sys),) -> getproperty(sys, Symbol(:resistor, i)).h.Q_flow,
        enumerate(rc_systems)),
]
<...>

```

[Previous page](https://discourse.julialang.org/t/2d-arrays-with-modelingtoolkit/107448.md?page=1)
