Closed Mathadon closed 7 years ago
Or even better:
m_flow_der := (if noEvent(abs(dp)>dp_turbulent)
then 0.5*k/sqrt(abs(dp))
else 1.25*k/m_k-0.75*k/m_k^5*dp^2)*dp_der;
and using even fewer operations:
m_flow_der := (if noEvent(abs(dp)>dp_turbulent)
then 0.5*k/sqrt(abs(dp))
else k/m_k*(1.25-0.75*(dp/dp_turbulent)^2))*dp_der;
IBPSA.Fluid.BaseClasses.FlowModels.basicFlowFunction_dp_der
is currently implemented as:this is fine for modelica tools, but this causes problems in casadi, which always evaluated all branches of the if-then-else. Since all branches are always evaluated, the square root of negative numbers can be computed, which leads to problems. A reformulation that solves this is:
I don't think this affects computation time so it make sense to put this formulation in the library.