-
-
Notifications
You must be signed in to change notification settings - Fork 234
Add support for the initializealg argument in SciMLBase callbacks #3144
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
Conversation
| @mtkmodel TestSystem begin | ||
| @components begin | ||
| pressure_source_1 = PressureSource(p_set = 2.0) | ||
| binary_valve_1 = BinaryValve(S = 1.0, k_leakage = 0.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting the leakage streams to zero will potentially lead to inifite solutions for the value between the valves, because you have "dirichlet" boundary values at the input of the first valve and the output of the second valve. The pressure difference between is distributed based the implicit relationship Vdot = Sf(\Delta p) + k_leakage\Delta p . Thus, there is no clear solution if all "S" and "k_leakage" are 0. I am not sure how the Julia solver will deal with this kind of equation system breakdown.
| # Test Simulation | ||
| prob = ODEProblem(sys, [], (0.0, 150.0)) | ||
| sol = solve(prob) | ||
| @test sol[end] == [0.0, 0.0, 0.0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me suggest a proper set of test conditions until tomorrow ;-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if I would test the behavior of the system, I would use the following checks. These numbers were calculated with NonlinearSolve assuming a k_leakage = 1e-08, furthermore I exchanged the valve equation to smooth its behavior. I'll make an extra post on that.
# Case 1: Both valves are open
@test ( (sol(45;idxs=sys.binary_valve_1.Δp) ≈ 0.5) &&
(sol(45;idxs=sys.binary_valve_2.Δp) ≈ 0.5) &&
(sol(45;idxs=sys.binary_valve_1.Vdot) ≈ 0.707107493292268) &&
sol(45;idxs=sys.binary_valve_1.Vdot) == sol(45;idxs=sys.binary_valve_2.Vdot))
# Case 2: First valve is open, second valve is closed
@test ( isapprox(sol(45;idxs=sys.binary_valve_1.Δp),2.6913001348648953e-10;atol=1e-06) &&
isapprox(sol(45;idxs=sys.binary_valve_2.Δp),0.99999999973087;atol=1e-06) &&
isapprox(sol(45;idxs=sys.binary_valve_1.Vdot),9.9999999973087e-9;atol=1e-06) &&
sol(45;idxs=sys.binary_valve_1.Vdot) == sol(45;idxs=sys.binary_valve_2.Vdot))
# Case 3: First valve is closed, second valve is open
@test ( isapprox(sol(45;idxs=sys.binary_valve_1.Δp),0.99999999973087;atol=1e-06) &&
isapprox(sol(45;idxs=sys.binary_valve_2.Δp),2.6913001348648953e-10;atol=1e-06) &&
isapprox(sol(45;idxs=sys.binary_valve_1.Vdot),9.9999999973087e-9;atol=1e-06) &&
sol(45;idxs=sys.binary_valve_1.Vdot) == sol(45;idxs=sys.binary_valve_2.Vdot))
# Case 4: Both valves are closed
@test ( isapprox(sol(45;idxs=sys.binary_valve_1.Δp),0.5;atol=1e-06) &&
isapprox(sol(45;idxs=sys.binary_valve_2.Δp),0.5;atol=1e-06) &&
(sol(45;idxs=sys.binary_valve_1.Vdot) ≈ 5e-09) &&
sol(45;idxs=sys.binary_valve_1.Vdot) == sol(45;idxs=sys.binary_valve_2.Vdot))
| Δp ~ port_in.p - port_out.p | ||
| # System behavior | ||
| D(S) ~ 0.0 | ||
| Vdot ~ S * k_V * sign(Δp) * sqrt(abs(Δp) / p_ref * ρ_ref / ρ) + k_leakage * Δp # softplus alpha function to avoid negative values under the sqrt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Smooth version of this equation
Vdot ~ S*k_V*tanh(1175*Δp/p_ref)*sqrt( sqrt(Δp^2 + 0.001^2)/p_ref * ρ_ref/ρ) + k_leakage*Δp
|
@BenChung We can also start with a simpler example with just one valve to avoid the numerical breakdown issue. I'll make an example - just let me know. |
|
Hey @BenChung and @ChrisRackauckas, |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.