@@ -2781,6 +2781,42 @@ algorithm
27812781 end match;
27822782end isOutsideStream;
27832783
2784+ protected function isZeroFlowMinMax
2785+ "Returns true if the given flow attribute of a connector is zero."
2786+ input DAE . ComponentRef inStreamCref;
2787+ input ConnectorElement inElement;
2788+ output Boolean isZero;
2789+ algorithm
2790+ if compareCrefStreamSet(inStreamCref, inElement) then
2791+ isZero := false ;
2792+ elseif isOutsideStream(inElement) then
2793+ isZero := isZeroFlow(inElement, "max" );
2794+ else
2795+ isZero := isZeroFlow(inElement, "min" );
2796+ end if ;
2797+ end isZeroFlowMinMax;
2798+
2799+ protected function isZeroFlow
2800+ "Returns true if the given flow attribute of a connector is zero."
2801+ input ConnectorElement inElement;
2802+ input String attr;
2803+ output Boolean isZero;
2804+ protected
2805+ DAE . Type ty;
2806+ Option < DAE . Exp > attr_oexp;
2807+ DAE . Exp flow_exp, attr_exp;
2808+ algorithm
2809+ flow_exp := flowExp(inElement);
2810+ ty := Expression . typeof(flow_exp);
2811+ attr_oexp := Types . lookupAttributeExp(Types . getAttributes(ty), attr);
2812+ if isSome(attr_oexp) then
2813+ SOME (attr_exp) := attr_oexp;
2814+ isZero := Expression . isZero(attr_exp);
2815+ else
2816+ isZero := false ;
2817+ end if ;
2818+ end isZeroFlow;
2819+
27842820protected function streamEquationGeneral
27852821 "Generates an equation for an outside stream connector element."
27862822 input list< ConnectorElement > inOutsideElements;
@@ -2822,60 +2858,28 @@ protected function streamSumEquationExp
28222858 output DAE . Exp outSumExp;
28232859protected
28242860 DAE . Exp outside_sum1, outside_sum2, inside_sum1, inside_sum2, res;
2825- list< ConnectorElement > insideElements, outsideElements;
2826- algorithm
2827- insideElements := List . filterOnFalse(inInsideElements, function isZeroFlow(attr= "min" ));
2828- outsideElements := List . filterOnFalse(inOutsideElements, function isZeroFlow(attr= "max" ));
2829- // adrpo: TODO! FIXME! HACK!
2830- // what happens if both these filtered lists are empty, what do we return?
2831- // Test with model: ThermoPower.PowerPlants.SteamTurbineGroup.Tests.TestST3LRh_bypass
2832- // as this seems to happen there! For now I unfilter the lists!
2833- if listEmpty(outsideElements) and listEmpty(insideElements) then
2834- insideElements := inInsideElements;
2835- outsideElements := inOutsideElements;
2836- end if ;
2837- if listEmpty(outsideElements) then
2861+ algorithm
2862+ if listEmpty(inOutsideElements) then
28382863 // No outside components.
2839- inside_sum1 := sumMap(insideElements , sumInside1, inFlowThreshold);
2840- inside_sum2 := sumMap(insideElements , sumInside2, inFlowThreshold);
2864+ inside_sum1 := sumMap(inInsideElements , sumInside1, inFlowThreshold);
2865+ inside_sum2 := sumMap(inInsideElements , sumInside2, inFlowThreshold);
28412866 outSumExp := Expression . expDiv(inside_sum1, inside_sum2);
2842- elseif listEmpty(insideElements ) then
2867+ elseif listEmpty(inInsideElements ) then
28432868 // No inside components.
2844- outside_sum1 := sumMap(outsideElements , sumOutside1, inFlowThreshold);
2845- outside_sum2 := sumMap(outsideElements , sumOutside2, inFlowThreshold);
2869+ outside_sum1 := sumMap(inOutsideElements , sumOutside1, inFlowThreshold);
2870+ outside_sum2 := sumMap(inOutsideElements , sumOutside2, inFlowThreshold);
28462871 outSumExp := Expression . expDiv(outside_sum1, outside_sum2);
28472872 else
28482873 // Both outside and inside components.
2849- outside_sum1 := sumMap(outsideElements , sumOutside1, inFlowThreshold);
2850- outside_sum2 := sumMap(outsideElements , sumOutside2, inFlowThreshold);
2851- inside_sum1 := sumMap(insideElements , sumInside1, inFlowThreshold);
2852- inside_sum2 := sumMap(insideElements , sumInside2, inFlowThreshold);
2874+ outside_sum1 := sumMap(inOutsideElements , sumOutside1, inFlowThreshold);
2875+ outside_sum2 := sumMap(inOutsideElements , sumOutside2, inFlowThreshold);
2876+ inside_sum1 := sumMap(inInsideElements , sumInside1, inFlowThreshold);
2877+ inside_sum2 := sumMap(inInsideElements , sumInside2, inFlowThreshold);
28532878 outSumExp := Expression . expDiv(Expression . expAdd(outside_sum1, inside_sum1),
28542879 Expression . expAdd(outside_sum2, inside_sum2));
28552880 end if ;
28562881end streamSumEquationExp;
28572882
2858- protected function isZeroFlow
2859- "Returns true if the given flow attribute of a connector is zero."
2860- input ConnectorElement inElement;
2861- input String attr;
2862- output Boolean isZero = false ;
2863- protected
2864- DAE . Type ty;
2865- Option < DAE . Exp > attr_oexp;
2866- DAE . Exp flow_exp, attr_exp;
2867- algorithm
2868- flow_exp := flowExp(inElement);
2869- ty := Expression . typeof(flow_exp);
2870- attr_oexp := Types . lookupAttributeExp(Types . getAttributes(ty), attr);
2871- if isSome(attr_oexp) then
2872- SOME (attr_exp) := attr_oexp;
2873- isZero := Expression . isZero(attr_exp);
2874- else
2875- isZero := false ;
2876- end if ;
2877- end isZeroFlow;
2878-
28792883protected function sumMap
28802884 "Creates a sum expression by applying the given function on the list of
28812885 elements and summing up the resulting expressions."
@@ -3210,8 +3214,11 @@ protected function generateInStreamExp
32103214 input array< Set > inSetArray;
32113215 input Real inFlowThreshold;
32123216 output DAE . Exp outExp;
3217+ protected
3218+ list< ConnectorElement > reducedStreams;
32133219algorithm
3214- outExp := match inStreams
3220+ reducedStreams := List . filterOnFalse(inStreams, function isZeroFlowMinMax(inStreamCref = inStreamCref));
3221+ outExp := match reducedStreams
32153222 local
32163223 DAE . ComponentRef c;
32173224 Connect . Face f1, f2;
@@ -3230,7 +3237,7 @@ algorithm
32303237 Connect . CONNECTOR_ELEMENT (face = Connect . INSIDE ())}
32313238 algorithm
32323239 {Connect . CONNECTOR_ELEMENT (name = c)} :=
3233- removeStreamSetElement(inStreamCref, inStreams );
3240+ removeStreamSetElement(inStreamCref, reducedStreams );
32343241 e := Expression . crefExp(c);
32353242 then
32363243 e;
@@ -3242,15 +3249,15 @@ algorithm
32423249 algorithm
32433250 false := faceEqual(f1, f2);
32443251 {Connect . CONNECTOR_ELEMENT (name = c)} :=
3245- removeStreamSetElement(inStreamCref, inStreams );
3252+ removeStreamSetElement(inStreamCref, reducedStreams );
32463253 e := evaluateInStream(c, inSets, inSetArray, inFlowThreshold);
32473254 then
32483255 e;
32493256
32503257 // The general case:
32513258 else
32523259 algorithm
3253- (outside, inside) := List . splitOnTrue(inStreams , isOutsideStream);
3260+ (outside, inside) := List . splitOnTrue(reducedStreams , isOutsideStream);
32543261 inside := removeStreamSetElement(inStreamCref, inside);
32553262 e := streamSumEquationExp(outside, inside, inFlowThreshold);
32563263 // Evaluate any inStream calls that were generated.
0 commit comments