Opened 7 years ago
#4740 new defect
"if noEvent()" won't protect sqrt from being called
Reported by: | hkiel | Owned by: | lochel |
---|---|---|---|
Priority: | high | Milestone: | Future |
Component: | Backend | Version: | |
Keywords: | Cc: | wbraun, lochel |
Description
model behaelter parameter Real A = 5; parameter Real V0 = 0; parameter Real g = 9.81; parameter Real k = 0.1; Real h, fout, fin, v, V; initial equation V=V0; equation der(V) = -fout+fin; if noEvent(V >= 0)then A*h = V; v = sqrt(2*g*h); fout = k*v; else fout = 0; h = 0; v = 0; end if; end behaelter;
model wasserkette behaelter b1(V0 = 1); equation if noEvent(time < 10)then b1.fin = 0.25; else b1.fin = 0; end if; end wasserkette;
When I simulate(wasserkette,stopTime=20) I get the following output:
record SimulationResult resultFile = "wasserkette_res.mat", messages = "assert | debug | division leads to inf or nan at time 0, (a=6.93672) / (b=0), where divisor b is: sqrt(b1.g * b1.h) LOG_SUCCESS | info | The initialization finished successfully without homotopy method. assert | warning | The following assertion has been violated at time 10.560000 assert | debug | Model error: Argument of sqrt(b1.g * b1.h) was -0.186758 should be >= 0 assert | warning | The following assertion has been violated at time 10.560000 assert | debug | Model error: Argument of sqrt(b1.g * b1.h) was -0.154058 should be >= 0 assert | debug | division leads to inf or nan at time 21.9614, (a=0) / (b=0), where divisor b is: sqrt(b1.g * b1.h) assert | debug | division leads to inf or nan at time 20.1835, (a=0) / (b=0), where divisor b is: sqrt(b1.g * b1.h) LOG_SUCCESS | info | The simulation finished successfully. " end SimulationResult; "Warning: Iteration variables with default zero start attribute in equation system w/o analytic Jacobian: b1.v:VARIABLE() type: Real b1.h:VARIABLE() type: Real b1.fout:VARIABLE() type: Real "
Moving either A*H=V or fout=k*v out of the if expression (and removing the corresponding equation from else branch) leads to successfull simulation.
Note: See
TracTickets for help on using
tickets.