﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
3430	Bug in implementation of stream connectors	Rüdiger Franke	Rüdiger Franke	"Currently the verification fails for some Fluid models that start with zero flow. See e.g. DrumBoiler and RoomCO2. The reason is that OpenModelica adds constants to the generated mixing equations.

Take DrumBoiler as example. OpenModelica generates:
{{{
massFlowRate.port_b.h_outflow = DIVISION(0.01680261163051938 + max(qm_S, 1e-07) * evaporator.h_v,
                                         2e-07 + max(qm_S, 1e-07))
temperature.T = someT(..., DIVISION(0.008401305815259689 + max(qm_S, 1e-07) * evaporator.h_v + max(-qm_S, 1e-07) * sink.ports[1].h_outflow,
                                    1e-07 + max(qm_S, 1e-07) + max(-qm_S, 1e-07)) )
}}}
This adds an additional spike to `massFlowRate.port_b.h_outflow` at initial time, while it eliminates the spike for `temperature.T` and its alias `T_S`.

The simulation results are correct when removing the constants from the two mixing equations. They should read:
{{{
massFlowRate.port_b.h_outflow = DIVISION(max(qm_S, 1e-07) * evaporator.h_v,
                                         max(qm_S, 1e-07))
temperature.T = someT(..., DIVISION(max(qm_S, 1e-07) * evaporator.h_v + max(-qm_S, 1e-07) * sink.ports[1].h_outflow,
                                    max(qm_S, 1e-07) + max(-qm_S, 1e-07)) )
}}}

Moreover note that the first equation simplifies to:
{{{
massFlowRate.port_b.h_outflow = evaporator.h_v
}}}

It appears that the constants stem from the absolute sensors `temperature` and `pressure`. They are first added to the mixing equations and then pre-evaluated basing on the attribute `m_flow(min=0)` in the respective connector. This attribute should be checked earlier, so that the absolute sensors don't appear in in the list of connector elements and in the mixing equations at all.

Alternatively, if the min attributes of the flow variables can't be checked earlier, then the generic `max(x, 1e-7)` could be replaced with specific `positiveMax(x)` in the generated equations and expanded later on -- and removed for connector elements with (absolute sensors):
    m_flow(min=0) 
or (other models -- allowFlowReversal has evaluate=true):
    m_flow(min = if allowFlowReversal then -Modelica.Constants.inf else 0).
"	defect	closed	high	1.9.3	Frontend	trunk	fixed		Adrian Pop Per Östlund
