Giter Club home page Giter Club logo

Comments (4)

ChrisRackauckas avatar ChrisRackauckas commented on June 11, 2024 1

I think we should hold off on this until the v9 release since that will have new initialization features which may fix this.

from modelingtoolkit.jl.

ChrisRackauckas avatar ChrisRackauckas commented on June 11, 2024

This needs code to be reproducible.

from modelingtoolkit.jl.

HKruenaegel avatar HKruenaegel commented on June 11, 2024

Sorry. I will debug into the model tomorrow, to locate the part of the model, which causes the error. Then I can give the code.

from modelingtoolkit.jl.

HKruenaegel avatar HKruenaegel commented on June 11, 2024

That is the shortest example I could make of the original code. In the discrete event a external DLL is called. This affect! is left empty now. But since the error occurs during initialization, this should not matter. But of course if this model were able to run, there may occur other unrelated errors.

The error disappears, if the EM model is commented out. Also if the inv model is commented out.

I hope that can help.

using DifferentialEquations,ModelingToolkit, OrdinaryDiffEq
using ProgressLogging


# Configuration of the simulation.
Ts=1/6000

function affect!(integ,u,p,ctx)
    
end



d_fun(phi,u,v,w) = (2/3*(u-v/2-w/2))*cos(phi)+sqrt(3)*2/3*(v/2-w/2)*sin(phi)
@register_symbolic d_fun(phi,u,v,w)
q_fun(phi,u,v,w) = -(2/3*(u-v/2-w/2))*sin(phi)+sqrt(3)*2/3*(v/2-w/2)*cos(phi)
@register_symbolic q_fun(phi,u,v,w)
u_fun(phi,Ug,ph)=Ug*sin(phi+pi*ph/3)
@register_symbolic u_fun(phi,Ug,ph)

hb(x) =  x>0.0 ? 1e4*x*(tanh(100*(x-0.05))/2 + (0.5)) : 0.0
@register_symbolic hb(x)

ib_fun(Ib)=Ib<0 ? Ib*1e4 : Ib*1e-3
@register_symbolic ib_fun(Ib)

function inverter(; name)
@parameters Lf Rf_HSchuetz u1_inv u2_inv u3_inv Ug1 Ug2 Ug3 C Fnom Lb  b_off C_ms d_b Rg Lg
@variables t u_in(t) ia(t) ib(t) ic(t) e1(t) e2(t) e3(t) idc(t) I1(t) I2(t) I3(t) Udc(t) Udc_ms(t) [irreducible=true] Id(t) Iq(t) Ud(t) Uq(t) ϕ(t) U1(t) U2(t) U3(t) Ib(t) D_b(t) [irreducible=true] I_byp(t) [irreducible=true] I_Vg1(t) I_Vg2(t) I_Vg3(t) I_Vu1(t) I_Vu2(t) I_Vu3(t) v1(t) [irreducible=true] v2(t) [irreducible=true] v3(t) [irreducible=true] v4(t) v5(t) v6(t) v7(t) v8(t) v9(t) v10(t)
dt=Differential(t)
eqs=[
I1 + I_Vg1 ~ 0,
I2 + I_Vg2 ~ 0,
I3 + I_Vg3 ~ 0,
-I_Vu1 - I_Vu2 - I_Vu3 ~ 0,
-I1 + v5/Rf_HSchuetz - v8/Rf_HSchuetz ~ 0,
-I2 + v6/Rf_HSchuetz - v9/Rf_HSchuetz ~ 0,
-I3 - v10/Rf_HSchuetz + v7/Rf_HSchuetz ~ 0,
I_Vu1 - v5/Rf_HSchuetz + v8/Rf_HSchuetz ~ 0,
I_Vu2 - v6/Rf_HSchuetz + v9/Rf_HSchuetz ~ 0,
I_Vu3 + v10/Rf_HSchuetz - v7/Rf_HSchuetz ~ 0,
-v4 + v8 ~ U1,
-v4 + v9 ~ U2,
v10 - v4 ~ U3,
v1 ~ u1_inv,
v2 ~ u2_inv,
v3 ~ u3_inv,
dt(I1)~(v1 - v5)/Lf,
dt(I2)~(v2 - v6)/Lf,
dt(I3)~(v3 - v7)/Lf,

U1~ifelse(t>3.0,u_fun(ϕ,1*Ug1,2),u_fun(ϕ,Ug1,2)),
U2~ifelse(t>3.0,u_fun(ϕ,1*Ug2,0),u_fun(ϕ,Ug2,0)),
U3~ifelse(t>3.0,u_fun(ϕ,1*Ug3,4),u_fun(ϕ,Ug3,4)),

I_byp~hb(Udc_ms-Udc),
dt(Ib)~b_off/Lb*(Udc_ms-(1-d_b)*Udc-ib_fun(Ib)),

dt(Udc)~((I_byp+Ib)*Udc_ms-1.5*Id*Ud-(0.0)*Udc/(0.02))/(Udc*C), 
#dt(Udc_ms)~(-(Ib+I_byp)+idc)/(C_ms), 
dt(ϕ)~2*pi*Fnom,

Id~q_fun(-ϕ,I2,I1,I3),
Iq~d_fun(-ϕ,I2,I1,I3),
Ud~q_fun(-ϕ,U2,U1,U3),
Uq~d_fun(-ϕ,U2,U1,U3),
D_b~d_b,

]

control = Ts  => (affect!,      [I1, I2, I3,Udc,Ib,I_byp,Udc_ms], [Lf,  Rf_HSchuetz, u1_inv, u2_inv, u3_inv, Ug1, Ug2, Ug3,C,Fnom,b_off,d_b], nothing) 

ODESystem(eqs, t; discrete_events = [control],continuous_events=[-Udc+Udc_ms-0.02 ~ 0],name=name)
end
@named inv=inverter()

u0inv = [  inv.I1=>0,
        inv.I2=>0,
        inv.I3=>0,
        inv.Udc=>1000,
        inv.ϕ=>0.0,
        inv.Id=>0,
        inv.Iq=>0,
        inv.Ud=>0,
        inv.Uq=>0,
        inv.U1=>0,
        inv.U2=>0,
        inv.U3=>0,
        inv.Ib=>0,
        inv.Udc_ms=>1,
        inv.I_byp=>0,
        inv.v6=>0,
        inv.v4=>0,
        inv.v10=>0,
        inv.v1=>0,
        inv.v2=>0,
        inv.v3=>0,
        inv.D_b=>1,
        
        ]
pinv=[  inv.Lf=>250e-6, 
        inv.Rf_HSchuetz=>100, 
        inv.u1_inv=>0, 
        inv.u2_inv=>0, 
        inv.u3_inv=>0,
        inv.Ug1=>690*sqrt(2)/sqrt(3),
        inv.Ug2=>690*sqrt(2)/sqrt(3),
        inv.Ug3=>690*sqrt(2)/sqrt(3),
        inv.C=>15.75e-3,
        inv.Fnom=>50.0,
        inv.Lb=>1e-3,
        inv.d_b=>1,
        inv.b_off=>1,
        ]



h(x) = tanh(1*(x))/2 + (0.5)
@register_symbolic h(x)

f(a,b,c) = 1.224744871391589*(2*h(a)-h(b)-h(c))/3
@register_symbolic f(a,b,c)

(ihd,MdE,mode)=mode>0 ? MdE : ((ihd)./(883.2749425452234.+0.28527750033027716*(ihd)))./ihd
@register_symbolic (Ihd,MdE,mode)

@register_symbolic dq2a(id,iq,ϕ)
function dq2a(id,iq,ϕ)
    iα=id*cos(ϕ)-iq*sin(ϕ)
    ia=return ia
end

@register_symbolic dq2b(iα,id,iq,ϕ)
function dq2b(iα,id,iq,ϕ)
    iβ=id*sin(ϕ)+iq*cos(ϕ)
    ib=-0.5*+sqrt(3)/2*return ib
end

@register_symbolic abc2d(ia,ib,ic,ϕ)
function abc2d(ia,ib,ic,ϕ)
    iα=ia
    iβ=(ib-ic)/sqrt(3)

    id=*cos(ϕ)+*sin(ϕ)

    return id
end

@register_symbolic abc2q(ia,ib,ic,ϕ)
function abc2q(ia,ib,ic,ϕ)
    iα=ia
    iβ=(ib-ic)/sqrt(3)

    iq=-*sin(ϕ)+*cos(ϕ)

    return iq
end

@register_symbolic phi(id,iq)
function phi(id,iq)
    id_=abs(id)
    iq_=abs(iq)

    if id >0
        if iq >= 0
            phi=atan(iq_/id_)
        else
            phi=2*pi-atan(iq_/id_)
        end
    else
        if iq >= 0
            phi=atan(id_/iq_)+pi/2
        else
            phi=atan(iq_/id_)+pi
        end
    end
    phi=isnan(phi) ? 0.0 : phi

    return phi*360/(2*pi)
end

@register_symbolic mag(id,iq)
function mag(id,iq)
    I=sqrt(abs(id)^2+abs(iq)^2)
    return I
end

function geno(; name)
    @parameters ld lq lσe r1 re ω MdE MqE ü Zp C lσa a2 a1 R sat ω0 par_gen
    @variables t iout(t) id(t) iq(t) Udc(t) e1(t) e2(t) e3(t) idc(t) ie(t) Ψd(t) Ψq(t) Ψe(t)  ud(t) id_(t) iq_(t) id__(t) iq__(t) uq(t) ua(t) ub(t) uc(t) ue(t) ifd(t) ufd(t) M(t) P(t) ϕi(t) ϕu(t) θ(t) ϕ(t) ia(t) ib(t) ic(t) Imag(t) ϕs(t) udc(t) ϕ_filt(t)  ϕ_filtˍt(t) L_mu(t)
    dt = Differential(t)
    eqs = [
        L_mu~(ie+id+id_,MdE,sat),
        Ψd~lσa*(id+id_)+(ie+(id+id_),MdE,sat)*(ie+(id+id_)),
        Ψq~lσa*(iq+iq_)+MqE*(iq+iq_),
        Ψe~lσe*ie+(ie+(id+id_),MdE,sat)*(ie+(id+id_)),
        dt(Ψd)~ud+ω*Ψq-r1*(id+id_),
        dt(Ψq)~uq-ω*Ψd-r1*(iq+iq_),
        dt(Ψe)~ue-re*ie,

        ud~-id*1000,
        uq~-iq*1000,
        dt(id_)~ω0*(par_gen*abc2d(-ia,-ib,-ic,ϕ)-id_),
        dt(iq_)~ω0*(par_gen*abc2q(-ia,-ib,-ic,ϕ)-iq_),  
        id__~par_gen*abc2d(-ia,-ib,-ic,ϕ),
        iq__~par_gen*abc2q(-ia,-ib,-ic,ϕ),   
        ifd~ie*ü*1.5,
        ufd~ue/ü,
        M~1.5*Zp*((ie+(id+id_),MdE,sat)*ie*(iq+iq_)+(ld-lq)*(id+id_)*(iq+iq_)),
        P~M*ω/Zp,
        ϕi~phi(id,iq),
        ϕu~phi(ud,uq),
        θ~90-ϕu,
        dt(ϕ)~ω,
        ua~dq2a(ud,uq,ϕ),
        ub~dq2b(ua,ud,uq,ϕ),
        uc~-ua-ub,
        Imag~mag(id,iq),
        ϕs~deg2rad(2.5),
        dt(Udc)~(idc-iout)/(C), 

        dt(ia)~1/(lσa*par_gen)*(-e1-r1*par_gen * ia +ua),
        dt(ib)~1/(lσa*par_gen)*(-e2-r1*par_gen * ib +ub),
        dt(ic)~1/(lσa*par_gen)*(-e3-r1*par_gen * ic +uc),
        e1~f(ia,ib,ic)*Udc,
        e2~f(ib,ic,ia)*Udc,
        e3~f(ic,ia,ib)*Udc,
        idc~h(ia)*ia+h(ib)*ib+h(ic)*ic,        ]

    ODESystem(eqs;name=name,continuous_events=[ib~0,ic~0,ia~0])
end


@named HM = geno()
@named EM = geno()

u0 = [  HM.id=>0,
        HM.iq=>0,
        HM.ie=>10,
        HM.ia=>0,
        HM.ib=>0,
        HM.ic=>0,
        HM.id_=>0,
        HM.iq_=>0,
        HM.id__=>0,
        HM.iq__=>0,
        HM.ua=>0,
        HM.ub=>0,
        HM.uc=>0,
        HM.e1=>0,
        HM.e2=>0,
        HM.e3=>0,
        HM.idc=>0,
        HM.Udc=>10,
        HM.Imag=>0,
        HM.Ψd=>0,
        HM.Ψq=>0,
        HM.Ψe=>0,
        HM.ud=>0,
        HM.uq=>0,
        HM.ue=>0,
        HM.ufd=>0,
        HM.ifd=>0,
        HM.M=>0,
        HM.P=>0,
        HM.ϕi=>0,
        HM.ϕu=>0,
        HM.ϕs=>0,
        HM.θ=>0,
        HM.ϕ=>0,
        HM.iout=>0,
        EM.iout=>0,
        EM.id=>0,
        EM.iq=>0,
        EM.ie=>10,
        EM.ia=>0,
        EM.ib=>0,
        EM.ic=>0,
        HM.e1=>0,
        HM.e2=>0,
        HM.e3=>0,
        EM.id_=>0,
        EM.iq_=>0,
        EM.id__=>0,
        EM.iq__=>0,
        EM.ua=>0,
        EM.ub=>0,
        EM.uc=>0,
        EM.idc=>0,
        EM.Udc=>10,
        EM.Imag=>0,
        EM.Ψd=>0,
        EM.Ψq=>0,
        EM.Ψe=>0,
        EM.ud=>0,
        EM.uq=>0,
        EM.ue=>0,
        EM.ufd=>0,
        EM.ifd=>0,
        EM.M=>0,
        EM.P=>0,
        EM.ϕi=>0,
        EM.ϕu=>0,
        EM.ϕs=>0,
        EM.θ=>0,
        EM.ϕ=>0,
        ]

function x_pu_in_real(Z0,f,x)
    ω0=2*pi*f
    return (x*Z0)/ω0
end

Z0=0.163
xhd=1.913
xhq=1.041
xd=2.035
xq=1.163
xσa=0.1218
ra=5.82e-3
xσf=0.2802
rσf=1.47e-3
ü_=sqrt(2/3*(rσf*Z0)/0.81220)

Z0_EM=0.502
xhd_EM=1.07
xhq_EM=0.358
xd_EM=1.247
xq_EM=0.531
xσa_EM=0.1729
ra_EM=26.15e-3
xσf_EM=0.2106
rσf_EM=4.6e-3
ü_EM=sqrt(2/3*(rσf_EM*Z0_EM)/3.20863309352518)

ω_0=2*pi*1e4
D=100
p = [   HM.r1=>ra*Z0,
        #-----------------------
        HM.re=>rσf*Z0,
        HM.lσe=>x_pu_in_real(Z0,68.1,xσf),
        HM.MdE=>x_pu_in_real(Z0,68.1,xhd),
        HM.MqE=>x_pu_in_real(Z0,68.1,xhq),
        HM.lσa=>x_pu_in_real(Z0,68.1,xσa),
        #-----------------------
        HM.ld=>x_pu_in_real(Z0,68.1,xd),
        HM.lq=>x_pu_in_real(Z0,68.1,xq),
        #-----------------------
        HM.ω=>pi*68.1,
        HM.ü=>ü_,
        HM.Zp=>6,
        HM.C=>4.5e-3,
        HM.sat=>0,
        HM.ω0=>2*pi*5,
        HM.par_gen=>6,
        EM.par_gen=>1,
        EM.r1=>ra_EM*Z0_EM,
        #-----------------------
        EM.re=>rσf_EM*Z0_EM,
        EM.lσe=>x_pu_in_real(Z0_EM,136.2,xσf_EM),
        EM.MdE=>x_pu_in_real(Z0_EM,136.2,xhd_EM),
        EM.MqE=>x_pu_in_real(Z0_EM,136.2,xhq_EM),
        EM.lσa=>x_pu_in_real(Z0_EM,136.2,xσa_EM),
        #-----------------------
        EM.ld=>x_pu_in_real(Z0_EM,136.2,xd_EM),
        EM.lq=>x_pu_in_real(Z0_EM,136.2,xq_EM),
        #-----------------------
        EM.ω=>2*pi*68.1,
        EM.ü=>ü_EM,
        EM.Zp=>12,
        EM.C=>4.5e-5,
        EM.sat=>1,
        EM.ω0=>2*pi*10,

]


append!(u0,u0inv)
append!(p,pinv)

tspan = (0.0, 30)
        

@variables t
connected = compose(ODESystem([
    HM.ufd~10,
    HM.iout~inv.Ib+inv.I_byp,
    inv.Udc_ms~HM.Udc,
    EM.iout~HM.ifd,
    EM.ufd~5.0,
     ], t; name = :connected), EM,HM,inv)

oprob = ODEProblem(structural_simplify(connected), u0, tspan, p)


sol = solve(oprob,  Rodas4P2(),reltol=1e-3,maxiters = 1e7, progress = true,saveat=tspan[2]*1e3)#,callback=downcrossing_cb)

from modelingtoolkit.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.