Skip to content

linearize!(model, analytic=true, ... #122

@johhell

Description

@johhell

I tried to linearize a simple electrical system and received an error message when using option analytic=true

  • linearize!(model, analytic=false, ... ==> OK
  • simulate!(... ==> OK

The problem occurs when getDerivatives! is called from ForwardDiff.Jacobian, then
_leq_mode.residual_value is set to:

Any[Dual{ForwardDiff.Tag{ModiaLang.var"#modelToLinearize!#54"{SimulationModel{Float64,OrderedCollections.OrderedDict{Symbol,Any},OrderedCollections.OrderedDict{Symbol,Any},Float64}},Float64}}(-400001.0,-1000.0,-0.0,-400000.0,-0.0)]

which can not be handled by function LinearEquationsIteration.

generated function getDerivatives!

code = quote
    function getDerivatives(_der_x, _x, _m, _time)::Nothing
        _m.time = ModiaLang.getValue(_time)
        _m.nGetDerivatives += 1
        instantiatedModel = _m
        _p = _m.evaluatedParameters
        _leq_mode = nothing
        time = _time
        var"T1.X.ixRe" = _x[1]
        var"T1.X.ixIm" = _x[2]
        var"C1.voltsRe" = _x[3]
        var"C1.voltsIm" = _x[4]
        var"T1.Omegarated" = _p[:Omegarated]
        var"T1.wReference" = _p[:wReference]
        begin
            local var"T1.X.voltsRe", var"T1.R.voltsRe", var"C1.ampsRe", var"T1.X.iparallelRe"
            _leq_mode = _m.linearEquations[1]
            _leq_mode.mode = -2
             ModiaBase.TimerOutputs.@timeit _m.timer "LinearEquationsIteration" 
                while ModiaBase.LinearEquationsIteration(_leq_mode, _m.isInitial, _m.time, _m.timer)
                    var"T1.X.voltsRe" = _leq_mode.vTear_value[1]
                    var"T1.R.voltsRe" = -1var"C1.voltsRe" + -1var"T1.X.voltsRe"
                    var"C1.ampsRe" = var"T1.R.voltsRe" / ((_p[:T1])[:R])[:r]
                    var"T1.X.iparallelRe" = -((var"T1.X.ixRe" + -1var"C1.ampsRe"))
                    _leq_mode.residual_value[1] = ustrip(((_p[:T1])[:X])[:rparallel] * var"T1.X.iparallelRe" - var"T1.X.voltsRe")
                end
            _leq_mode = nothing
        end
        var"der(T1.X.ixRe)" = -((var"T1.X.voltsRe" - ((_p[:T1])[:X])[:x] * -(var"T1.wReference" * var"T1.X.ixIm"))) / -(((_p[:T1])[:X])[:x] * (1 / var"T1.Omegarated"))
        begin
            local var"T1.X.voltsIm", var"T1.R.voltsIm", var"C1.ampsIm", var"T1.X.iparallelIm"
            _leq_mode = _m.linearEquations[2]
            _leq_mode.mode = -2
             ModiaBase.TimerOutputs.@timeit _m.timer "LinearEquationsIteration" while ModiaBase.LinearEquationsIteration(_leq_mode, _m.isInitial, _m.time, _m.timer)
                    var"T1.X.voltsIm" = _leq_mode.vTear_value[1]
                    var"T1.R.voltsIm" = -1var"C1.voltsIm" + -1var"T1.X.voltsIm"
                    var"C1.ampsIm" = var"T1.R.voltsIm" / ((_p[:T1])[:R])[:r]
                    var"T1.X.iparallelIm" = -((var"T1.X.ixIm" + -1var"C1.ampsIm"))
                    _leq_mode.residual_value[1] = ustrip(((_p[:T1])[:X])[:rparallel] * var"T1.X.iparallelIm" - var"T1.X.voltsIm")
                end
            _leq_mode = nothing
        end
        var"der(T1.X.ixIm)" = -((var"T1.X.voltsIm" - ((_p[:T1])[:X])[:x] * (var"T1.wReference" * var"T1.X.ixRe"))) / -(((_p[:T1])[:X])[:x] * (1 / var"T1.Omegarated"))
        var"T1.R.p.vRe" = -((-1var"T1.R.voltsRe" + -1var"T1.X.voltsRe"))
        var"T1.R.p.vIm" = var"T1.R.voltsIm" + var"T1.X.voltsIm"
        var"C1.Omegarated" = _p[:Omegarated]
        var"C1.wReference" = _p[:wReference]
        var"der(C1.voltsRe)" = -((var"C1.ampsRe" * (_p[:C1])[:b] - -(var"C1.wReference" * var"C1.voltsIm"))) / -(1 / var"C1.Omegarated")
        var"der(C1.voltsIm)" = -((var"C1.ampsIm" * (_p[:C1])[:b] - var"C1.wReference" * var"C1.voltsRe")) / -(1 / var"C1.Omegarated")
        _der_x[1] = var"der(T1.X.ixRe)"
        _der_x[2] = var"der(T1.X.ixIm)"
        _der_x[3] = var"der(C1.voltsRe)"
        _der_x[4] = var"der(C1.voltsIm)"
        if _m.storeResult
            ModiaLang.addToResult!(_m, _der_x, time, var"T1.Omegarated", var"T1.wReference", var"T1.X.voltsRe", var"T1.X.voltsIm", var"T1.X.iparallelRe", var"T1.X.iparallelIm", var"T1.R.voltsRe", var"T1.R.p.vRe", var"T1.R.voltsIm", var"T1.R.p.vIm", var"C1.Omegarated", var"C1.wReference", var"C1.ampsRe", var"C1.ampsIm")
        end
        return nothing
    end
end

versions

"Modia" version = "0.5.0"
"ModiaBase" version = "0.7.5"
"ModiaLang" version = "0.8.1"
Julia: Version 1.5.3 (2020-11-09)
platform: LINUX x86_64

###PS:
After reading your paper from the ongoing MODELICA conference, I had a better understanding but couldn't resolve it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions