-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
callbacks_buckExample #998
Comments
what happens if you simulate this without adaptive false? turning off adaptivity could easily lead to loss of precision |
I tried both (with and without adaptive), and tried to change dt. still no correct output. |
From the graph it seems like Rd isn't working correctly. Could you add some printing to verify Rd has the value you expect and condition3 is producing the expected result and affect3 and affect33 are running when that happens? |
I am printing condition3 and rd from inside affect3 and affect33.
The output: So you are right. it looks like the issue is in condition3: the zero crossing function is positive inside affect33. when I flip the sign of condition3 or switch positions of affect3 and affect33, the code runs infinitely. |
What do you mean "runs infinitely"? |
Well, I waited 5 minutes for it and it did not finish. with a verbose mode, it was printing continuously. ie condition3 was being triggered a lot. |
That's probably because you change the condition equation in the affect function, so it ends up oscillating unable to find the zero point. Why isn't it just using id? |
I suspect
Results in a plot that looks more like the other solvers, but it appears that the inductor current is in mA rather than A. |
The following code seems to miss the positive callback entirely. Surely that's a bug right? What goes down must come up. using DifferentialEquations
using OrdinaryDiffEq
using Plots
function f(du, u, p, t)
C = 1e-4; L = 1e-4; R = 10;U = 24.0; T = 1e-4; DC = 0.5; ROn = 1e-5;ROff = 1e5;
rd=p[1];rs=p[2];
il=u[1] ;uc=u[2]
id=(il*rs-U)/(rd+rs) # diode's current
du[1] =(-id*rd-uc)/L # inductor's current
du[2]=(il-uc/R)/C # capacitor's voltage
end
function condition1( u, t, integrator)
(t-p[3])
end
function condition2( u, t, integrator)
(t-p[4]-0.5*1e-4)
end
function condition3( u, t, integrator)
C = 1e-4; L = 1e-4; R = 10;U = 24.0; T = 1e-4; DC = 0.5; ROn = 1e-5;ROff = 1e5;
rd=p[1];rs=p[2];
il=u[1] ;uc=u[2]
id=(il*rs-U)/(rd+rs) # diode's current
diodeon=p[5]
res=diodeon*(id)+(1.0-diodeon)*(id*rd)
end
function affect1!(integrator)
p[4]=p[3]
p[3]=p[3]+1e-4
p[2]=1e-5
end
function affect2!(integrator)
p[2]=1e5
end
function affect3!(integrator)
@show "pos", p[1], condition3(integrator.u, integrator.t, integrator)
p[1]=1e-5
p[5]=1.0
@show "pos", p[1], condition3(integrator.u, integrator.t, integrator)
end
function affect33!(integrator)
@show "neg", p[1], condition3(integrator.u, integrator.t, integrator)
p[1]=1e5
p[5]=0.0
@show "neg", p[1], condition3(integrator.u, integrator.t, integrator)
end
cb1 = ContinuousCallback(condition1, affect1!,nothing; )
cb2 = ContinuousCallback(condition2, affect2!,nothing; )
cb3 = ContinuousCallback(condition3, affect3!,affect33!; )
cbs = CallbackSet(cb1, cb2,cb3)
u0 = [0.0, 0.0]
tspan = (0.0, 0.001)
p = [1e5,1e-5,1e-4,0.0,0.0,0.0]
prob = ODEProblem(f, u0, tspan, p)
sol = solve(prob, Rodas5P(), callback = cbs, reltol=1e-9,abstol=1e-9#= dt = 1e-3, adaptive = false =#)
plot(sol) |
After playing with this example a little bit, it looks like the problem has something to do with one callback creating the condition for the other. As soon as the switch opens, the voltage rises above threshold (in one integrator timestep). It looks like the diode |
Doing this with a VectorContinuousCallback is fine? |
ERROR: LoadError: Double callback crossing floating pointer reducer errored. Report this issue. |
Do you have multiple events at the same time with this? |
Yes. There are 2 events at the same zero crossing function. 1 event for the rising transition and 1 event for the falling transition. |
Okay yes, that case is not handled right now. We should get to it soon, but currently it's not soon enough. SciML/DiffEqBase.jl#519 is tracking this. |
Greetings,
I tried to simulate the electronic buck converter using the following code:
These are the results:
However, after simulating the system via 3 other tools:
I received the following results:
c solver
ltspice
QS_Solver.jl
Am I misusing callbacks?
thank you.
The text was updated successfully, but these errors were encountered: