﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
5104	Further inStream optimizations	Francesco Casella	Vitalij Ruge	"The simplifyInStream module of the backend currently implements the substitutions listed in ticket:3885#comment:15

- `inStream` introduces positiveMax(cref, eps) and positiveMax(-cref, eps)
- simplify positiveMax in Backend after removeSimpleEquation and EvaluateParameter and before IndexReduction
- positiveMax(cref, eps) = cref where variable is constant >= 0
- positiveMax(-cref, eps) = -cref where variable is constant <= 0
- positiveMax(cref, eps) = 0 if variable(cref).max <= 0
- positiveMax(-cref, eps) = 0 if variable(cref).min >= 0

The idea of the last two substitutions is that if a fluid never flows out of the stream connector, its contribution is zero. In case of components with only one direction of flow, one can set min=0 at the inlet to activate this optimization.

In fact, when dealing with components without flow reversal, not only the fluid never flows out of the inlet, hence inlet.m_flow.min = 0, but also the fluid never flows in the outlet, hence outlet.m_flow.max = 0. This fact can be stated by setting the max attribute of the outlet port mass flow rate to zero. If this property holds, then

- positiveMax(cref, eps) = cref if variable(cref).min >= 0 // test: positiveMax(1, eps) = 1
- positiveMax(-cref, eps) = -cref if variable(cref).max <= 0 // test: positiveMax(-(-1), eps) = 1

These additional optimizations would allows to remove unnecessary positiveMax function calls, hence eliminating unnecessary hard nonlinearities from the model equations.

@vitalij, if you are willing to implement this, I can prepare the tests ASAP."	enhancement	closed	normal	1.13.0	Backend		fixed	inStream	
