Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@mtkmodel gives "LoadError: Could not parse 0 of component..." #2415

Open
bradcarman opened this issue Jan 3, 2024 · 2 comments
Open

@mtkmodel gives "LoadError: Could not parse 0 of component..." #2415

bradcarman opened this issue Jan 3, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@bradcarman
Copy link
Contributor

The following code gives the error LoadError: Could not parse 0 of component vol. Note: `MassVolume() is given to show the working version, when trying to recreate this with @mtkmodel the error is given.

using ModelingToolkitStandardLibrary.Mechanical.Translational
using ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible
using ModelingToolkitStandardLibrary.Blocks

mass_flow_fun(t) = cos(2π*10*t)

function MassVolume(; name)

    pars = @parameters begin
        A = 0.01 #
        x₀ = 1.0 #m
        M = 10_000 #kg
        g = 9.807 #m/s²
        amp = 5e-2 #m
        f = 15 #Hz   
        p_int=M*g/A
    end
    vars = []
    systems = @named begin
        mass = Mass(;m=M)
        vol = DynamicVolume(0; p_int, area=A, x_int=x₀, x_max=10*x₀)
        mass_flow = MassFlow(;p_int)
        mass_flow_input = TimeVaryingFunction(;f = mass_flow_fun)
    end

    eqs = [
        connect(mass.flange, vol.flange)
        connect(vol.port, mass_flow.port)
        connect(mass_flow.dm, mass_flow_input.output)
    ]

    return ODESystem(eqs, t, vars, pars; systems, name)
end

@named odesys = MassVolume()

@mtkmodel MassVolumeMTK begin
    @parameters begin
        A = 0.01 #
        x₀ = 1.0 #m
        M = 10_000 #kg
        g = 9.807 #m/s²
        amp = 5e-2 #m
        f = 15 #Hz   
        p_int=M*g/A
    end
    @components begin
        mass = Mass(;m=M)
        vol = DynamicVolume(0; p_int, area=A, x_int=x₀, x_max=10*x₀)
        mass_flow = MassFlow(;p_int)
        mass_flow_input = TimeVaryingFunction(;f = mass_flow_fun)
    end
    @equations begin
        connect(mass.flange, vol.flange)
        connect(vol.port, mass_flow.port)
        connect(mass_flow.dm, mass_flow_input.output)
    end
end

Currently using ModelingToolkit v8.75.0 with Julia v1.10.0

@bradcarman bradcarman added the bug Something isn't working label Jan 3, 2024
@ChrisRackauckas
Copy link
Member

vol = DynamicVolume(0; p_int, area=A, x_int=x₀, x_max=10*x₀) that 0 should be a keyword argument?

@bradcarman
Copy link
Contributor Author

No it's a function argument (N). The function signature is:

@component function DynamicVolume(N, add_inertia = true, reversible = false;
    p_int,
    area,
    x_int = 0,
    x_max,
    x_min = 0,
    x_damp = x_min,
    direction = +1,

    # Tube
    perimeter = 2 * sqrt(area * pi),
    shape_factor = 64,
    head_factor = 1,

    # Valve
    Cd = 1e2,
    Cd_reverse = Cd,
    minimum_area = 0,
    name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants