Skip to content

Help with initializing a model #3141

Open
@bradcarman

Description

@bradcarman

Take the following model (Note: Hydraulic branch of the ModelingToolkitStandardLibrary is required currently)...

using ModelingToolkitStandardLibrary.Hydraulic.IsothermalCompressible: FixedPressure,
                                                                       Orifice, Volume,
                                                                       HydraulicFluid, HydraulicPort, liquid_density
using ModelingToolkitStandardLibrary.Blocks: Ramp, Constant
using ModelingToolkitStandardLibrary.Mechanical.Translational: Force, MechanicalPort, Mass

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using OrdinaryDiffEq

@mtkmodel System begin
    @components begin
        src = FixedPressure(p = 101325)
        res = Orifice()
        act = Volume(direction = -1, area = 0.1)
        # mass = Mass(m=1e-5)
        fluid = HydraulicFluid(density = 1000, bulk_modulus = 2.0e9)
    end
    @equations begin
        connect(src.port, res.port_a)
        connect(res.port_b, act.port)
        # connect(act.flange, mass.flange)

        connect(fluid, src.port)
    end
end

@mtkbuild sys = System()

Note: this model was providing an error (#3138) when including the Mass component, so it's being removed. However this should still work. This model will not have any forces in the actuator, and will therefore have zero pressure, therefore no compressibility, and the flow dm will be dictated by the orifice. This means the system is solving for the equations...

dm = function of the orifice pressure differential (orifice equation)
dm = rho*dx*area (swept volume equation)

I can solve this system and get the correct result.

prob = ODEProblem(sys, [], (0, 1), []) 
sol = solve(prob, Rodas5P())

using Plots
plot(sol; idxs = [sys.act.dx*sys.fluid.ρ*sys.act.area, sys.act.dm], ylims=(6,10))

As can be seen, both the actuator velocity dx and the mass flow dm are constants...

image

However, the trouble is, how can one specify the initial actuator position x? As shown with the explanation above, the problem is not compressible anymore, and therefore x is eliminated essentially from the problem, I believe this is what causes an issue here. So for example, take...

initsys = ModelingToolkit.generate_initializesystem(sys)
initsys = structural_simplify(initsys) #ERROR: InvalidSystemException: The system is structurally singular!
initprob = NonlinearProblem(complete(initsys), [t=>0, sys.act.x => 1], [])
initsol = solve(initprob; abstol=1e-6)
initsol[sys.act.x] #1.0

I can assemble an initialization problem and set sys.act.x to 1.0 and get a successful solution. However, note this problem cannot be structurally simplified! See #2952. How can one do this with the ODEProblem interface? The system will complain about an unbalanced initialization, which is not my intent, I only want to set an observable variable start value, not necessarily add an initial equation...

prob = ODEProblem(sys, [sys.act.x => 1], (0, 1), []) # Warning: Initialization system is overdetermined. 2 equations for 1 unknowns. 

So, is there another interface for ODEProblem that allows me to set a start value for an observed variable without breaking the initialization system?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions