There were major improvements to reinitialization of DAEs, and this seems fine now at lower tolerances.
using OrdinaryDiffEq
function fx!(du,u,p,t)
δ,ω,i_d,i_q,v_1,θ_1,v_3,θ_3=u
k,e_q_prime0=p
e_q_prime=e_q_prime0
x_d_prime=0.24
p_m=0.944
H=3.5
y_12=0.0
y_13=6.66666667
y_11=y_12+y_13
y_21=0.0
y_23=5.05050505
y_22=y_21+y_23
y_31=6.66666667
y_32=5.05050505
y_33=y_31+y_32
ϕ_11=-1.57079633
ϕ_12=0.0
ϕ_13= 1.57079633
ϕ_21=0.0
ϕ_22=-1.57079633
ϕ_23=1.57079633
ϕ_31= 1.57079633
ϕ_32=1.57079633
ϕ_33=-1.57079633
v_2=1.0
θ_2=0.0
Ω=2π*60
d=1
r_f=0
x_f=1e-4im
y_f = 1/(r_f+x_f)
p_fault = (v_3^2)*abs(y_f)*cos(-1*angle(y_f))
q_fault = (v_3^2)*abs(y_f)*sin(-1*angle(y_f))
p_l3=0 - k*p_fault
q_l3=0 - k*q_fault
du[1] = Ω*(ω-1)
du[2] = (p_m - (i_d*v_1*sin(δ-θ_1) + i_q*v_1*cos(δ-θ_1)) - d*(ω-1))/(2H)
du[3] = v_1*sin(δ-θ_1) - x_d_prime*i_q
du[4] = -e_q_prime + v_1*cos(δ-θ_1) + x_d_prime*i_d
du[5] = i_d*v_1*sin(δ-θ_1) + i_q*v_1*cos(δ-θ_1) - (v_1*v_1*y_11*cos(θ_1 - θ_1 -ϕ_11) + v_1*v_2*y_12*cos(θ_1 - θ_2 -ϕ_12) + v_1*v_3*y_13*cos(θ_1 - θ_3 -ϕ_13))
du[6] = i_d*v_1*cos(δ-θ_1) - i_q*v_1*sin(δ-θ_1) - (v_1*v_1*y_11*sin(θ_1 - θ_1 -ϕ_11) + v_1*v_2*y_12*sin(θ_1 - θ_2 -ϕ_12)+ v_1*v_3*y_13*sin(θ_1 - θ_3 -ϕ_13))
du[7] = p_l3 - (v_3*v_1*y_31*cos(θ_3 - θ_1 -ϕ_31) + v_3*v_2*y_32*cos(θ_3 - θ_2 -ϕ_32) + v_3*v_3*y_33*cos(θ_3 - θ_3 -ϕ_33))
du[8] = q_l3 - (v_3*v_1*y_31*sin(θ_3 - θ_1 -ϕ_31) + v_3*v_2*y_32*sin(θ_3 - θ_2 -ϕ_32) + v_3*v_3*y_33*sin(θ_3 - θ_3 -ϕ_33))
end
M = zeros(8,8)
M[1,1],M[2,2]=1,1
t_span=(0.0,5)
v_10=1.03
v_20=1.0
θ_20=0.0
δ0 = 0.5243271427959093
ω0 = 1.0
i_d0 = 0.41340918211007344
i_q0 = 0.8514126244761779
θ_10 = 0.32461479155703327
v_30 = 1.004014153353707
θ_30 = 0.18725718301004352
e_q_prime0 = 1.1087455985400045
u0=[δ0,ω0,i_d0,i_q0,v_10,θ_10,v_30,θ_30];
f = ODEFunction(fx!,mass_matrix=M)
k=0
p=[k,e_q_prime0]
prob = ODEProblem(f,u0,t_span,p);
function condition1(u,t,integrator,save_positions=(true,true))
t == 0.1
end
function affect1!(integrator)
@show "entering affect1"
integrator.p[1] = 1
u_modified!(integrator,true)
end
cb1=DiscreteCallback(condition1,affect1!)
p=[k,e_q_prime0]
prob = ODEProblem(f,u0,t_span,p);
sol1=solve(prob,Rodas5P(),callback=cb1,tstops=[0.1], saveat = 0.1, abstol=1e-10, reltol=1e-10)
p=[k,e_q_prime0]
prob = ODEProblem(f,u0,t_span,p);
sol2=solve(prob,FBDF(),callback=cb1,tstops=[0.1], saveat = 0.1, abstol=1e-10, reltol=1e-10)
Both solve, checking the difference:
julia> sol1 - sol2
VectorOfArray{Float64,2}:
52-element Vector{Vector{Float64}}:
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
[-9.848788451449764e-13, 1.2589929099249275e-13, -8.392730954653871e-13, -1.4493961586481419e-12, 1.283417816466681e-13, -6.151745779447992e-13, 1.2168044349891716e-13, -3.456956942926581e-13]
[-9.848788451449764e-13, 1.2589929099249275e-13, -1.787725523172412e-11, 3.288296284570391e-12, 4.9669712787192566e-12, 1.4911405443740477e-12, 8.300534305033525e-12, -4.545008702727671e-9]
[-2.3977719809664677e-10, 1.1612932837579137e-13, -7.131387880221496e-8, -2.4595117536249482e-8, 1.7109302419271444e-8, -5.209714711240654e-5, 1.1407411998299796e-8, -1.6107900885575788e-5]
[-2.400699639082404e-10, 8.548717289613705e-14, -1.3591581637939498e-8, 2.545654042445701e-8, 3.2664175253493966e-9, -9.81995196513985e-6, 4.586860387497359e-9, 1.7506057102822936e-6]
[-2.3677015903444953e-10, 4.773959005888173e-14, 5.39947775379801e-9, 3.534371990226732e-9, -1.296616924939542e-9, -1.068550248284339e-6, -1.5788576581115404e-9, 1.0352748133934941e-5]
[-2.198099480210658e-10, 2.3092638912203256e-14, 5.8237463740340445e-9, -1.7031891305294145e-8, -1.3949167376736682e-9, -1.6947831351643572e-6, 6.419038963562107e-10, -4.72278221397282e-6]
⋮
[6.565073817910161e-9, -4.0678571622265736e-13, 1.8942347246309055e-8, -2.7873452780689117e-8, -4.543984410965152e-9, -4.644618911697762e-9, 7.285772300139742e-12, -1.7673110691007743e-5]
[6.442348876589676e-9, 2.156053113822054e-13, 6.684017339608772e-9, 4.116655970623495e-8, -1.5972529410213099e-9, -4.8331173729820875e-8, 2.77156804451284e-9, 9.480809935347168e-6]
[6.3961351770558394e-9, -1.3427037259816643e-12, -4.3778739300393e-8, -1.6818814049313676e-8, 1.0500807001712076e-8, -1.8222806374978973e-8, 6.449213563902191e-9, -8.993695660708401e-7]
[6.219920578587335e-9, -1.261879489788953e-12, 7.422707337667589e-9, -9.85985547526623e-9, -1.7808509111816306e-9, 3.201819254172733e-9, -1.3493299235107017e-10, -7.1553641446397975e-6]
[6.038987976353383e-9, -1.4672707493446069e-12, 4.871099079650776e-9, 3.7149643253124587e-9, -1.169345953400125e-9, -1.0965095498249866e-10, -6.293475783916702e-10, 6.202034353530728e-6]
[3.4690970096562523e-9, -6.326250634458574e-11, -9.49850464948554e-9, 2.320217818438733e-8, 2.2827632562005817e-9, -2.543339405747247e-8, 2.7335558761215975e-9, 2.267419438817253e-6]
[1.0565486263658386e-9, -6.265277185946161e-11, 1.5987211554602254e-13, 1.3588889941681254e-12, -3.824718319833664e-14, 1.055809661920648e-9, -2.2072404667894396e-14, 3.808920956416273e-10]
Both give the same solution.
I would recommend FBDF for this kind of case.