ModiaSim / Modia.jl

Modeling and simulation of multidomain engineering systems
MIT License
319 stars 37 forks source link

equations = :[ ] ... observation #124

Open johhell opened 2 years ago

johhell commented 2 years ago

I tried to run my MODELICA model for synchronous machine with a quadratic saturation in Modia

my 1st attempt ==> unstable

SynchronousMachine  = SynchrPart | Model(
    Omegarated=Var(_outer=true),
    rfd = 0.00037,
    xfd = 0.2181,
    xf1d = 0.0011,
    S10 = 0.18858668,
    S12 = 0.43618116,
    KIS =  0.15,
    a = parameter | Map(value=:(sqrt(S10/(S12*1.2)))),
    A = parameter | Map(value=:(1.2 + 0.2/(a - 1.0))),
    B = parameter | Map(value=:(S12*1.2* (a - 1.0)^2/(1.0 - 1.2)^2)),

    Plus = Pin,
    Minus = Pin,
    equations = :[
        ifd = Plus.i
        Plus.i + Minus.i = 0.0
        uF = Plus.v - Minus.v
        imRe = iRe + i1Re + ifd
        imIm = iIm + i1Im
        PsimRe = xadSat * imRe
        PsimIm = xaqSat * imIm
        Psifd = Psif1d + ifd * xfd + xadSat * imRe
#                                    ^^^^^^^^^^^^^ this is identical with PsimRe (def. above)
        Psif1d = xf1d * (i1Re + ifd) 
        uF*rfd/xad = rfd*ifd + (der(Psifd))/Omegarated
        PsimAbs = sqrt(PsimRe*PsimRe+PsimIm*PsimIm)
        psiM1 = max(0.1, PsimAbs + KIS*current)
        saturation = if (psiM1 > A); B*((psiM1-A)^2.0)/psiM1; else 0.0; end
        satD = 1.0 + saturation
        satQ = 1.0 + xq/xd * saturation
        xadSat = xad/satD
        xaqSat = xaq/satQ
    ]
)

after modification ==> OK

        imRe = iRe + i1Re + ifd
        imIm = iIm + i1Im
        PsimRe = xadSat * imRe
        PsimIm = xaqSat * imIm
        Psifd = Psif1d + ifd * xfd + PsimRe
#                                    ^^^^^^  replaced
        Psif1d = xf1d * (i1Re + ifd) 
        uF*rfd/xad = rfd*ifd + (der(Psifd))/Omegarated
        PsimAbs = sqrt(PsimRe*PsimRe+PsimIm*PsimIm)
        psiM1 = max(0.1, PsimAbs + KIS*current)
        saturation = if (psiM1 > A); B*((psiM1-A)^2.0)/psiM1; else 0.0; end

Basically the system of equations are the identical. But in implementation the expression PsimRe = xadSat * imRe is handled in a different way.

remark

in the MODELICA model I used Complex() values. In Modia it was necessary to spit explicit in Re and Im part.

versions

name = "ModiaLang" version = "0.9.0-dev" name = "ModiaBase" version = "0.8.0-dev"