# MTK - simple case with \`@mtkmodel\` and standard library doesn't work

**URL:** <https://discourse.julialang.org/t/mtk-simple-case-with-mtkmodel-and-standard-library-doesnt-work/104807>\
**Category:** Modelling & Simulations\
**Created:** [October 10, 2023, 3:01pm UTC](https://discourse.julialang.org/t/mtk-simple-case-with-mtkmodel-and-standard-library-doesnt-work/104807 "2023-10-10T15:01:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 10, 2023, 3:01pm UTC](https://discourse.julialang.org/t/mtk-simple-case-with-mtkmodel-and-standard-library-doesnt-work/104807/1 "2023-10-10T15:01:20Z")

</div>

I’m experimenting with the new `@mtkmodel` in combination with the `ModelingToolkitStandardLibrary`. I get an error message…

My case is simple: a liquid tank “class” `Tank_m` with flow out given by gravity, encoded via `@mtkmodel`. [The `_m` part indicates “modified” – a modification of a model that _works_ when I do not use `ModelingToolkitStandardLibrary`.]

```julia
using ModelingToolkit, ModelingToolkitStandardLibrary.Blocks

@variables t
Dt = Differential(t)

@mtkmodel Tank_m begin
    # Model parameters
    @parameters begin 
        ρ=1, [description = "Liquid density"]
        A=5, [description = "Cross sectional tank area"]
        K=5, [description = "Effluent valve constant"]
        h_ς=3, [description = "Scaling level in valve model"]
    end
    # Model variables, with initial values needed
    @variables begin
        m(t)=1.5*ρ*A, [description = "Liquid mass"]
        # ṁ_i(t), [description = "Influent mass flow rate"]
        ṁ_e(t), [description = "Effluent mass flow rate"]
        V(t), [description = "Liquid volume"]
        h(t), [description = "level"]
    end
    # Components from ModelingToolkitStandardLibrary
    @components begin
        # We move ṁ_i from "variables" to "components"
        ṁ_i = RealInput() # Influent mass flow rate
        y_ṁ_e = RealOutput()
    end
    # Providing model equations
    @equations begin
        Dt(m) ~ ṁ_i.u - ṁ_e
        m ~ ρ*V
        V ~ A*h
        ṁ_e ~ K*sqrt(h/h_ς)
        y_ṁ_e.u ~ ṁ_e
    end
end

```

Next, I make two copies of this liquid tank model and use MTK SL (standard library) to generate the input flow rate to the first tank, and then passes the output from the first tank as input to the second tank…

```julia
@mtkmodel Sys2Tank_m begin
    # Components used
    @components begin 
        ṁ = Constant(k=2)
        tank_1 = Tank_m()
        tank_2 = Tank_m()
    end
    # Equations for connecting components
    @equations begin
        connect(ṁ.output, tank_1.ṁ_i)
        connect(tank_1.y_ṁ_e, tank_2.ṁ_i)
    end
end

```

Executing these macros work, but then I get an error message:

```julia
@mtkbuild sys2tank_m_balanced = Sys2Tank_m()

```

leads to:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/1/f173973b4cf3d412da806e37e2b182ea2197df88.png)

I’m sure it is a trivial thing I do incorrectly… Any ideas?  
[Note: with fixes, the above code should now work.]

---

<div class="post-metadata">

**Author:** ![YingboMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yingboma/32/2181_2.png) [@YingboMa](https://discourse.julialang.org/u/YingboMa)\
**Post date:** [October 10, 2023, 9:06pm UTC](https://discourse.julialang.org/t/mtk-simple-case-with-mtkmodel-and-standard-library-doesnt-work/104807/2 "2023-10-10T21:06:54Z")

</div>

Could you make sure the MWE can be reproduced in a fresh Julia session? There are multiple undefined symbols in the MWE.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [October 11, 2023, 7:10am UTC](https://discourse.julialang.org/t/mtk-simple-case-with-mtkmodel-and-standard-library-doesnt-work/104807/3 "2023-10-11T07:10:06Z")

</div>

Ahrg. Found the error. I’ll update the code above anyways. The key error was that I had forgotten to update the name of the class `Tank` to `Tank_m` in the `Sys2Tank_m` class.
