Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#5104 closed enhancement (fixed)

Further inStream optimizations

Reported by: Francesco Casella Owned by: Vitalij Ruge
Priority: normal Milestone: 1.13.0
Component: Backend Version:
Keywords: inStream Cc:

Description (last modified by 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.

Attachments (1)

TestStreamConnectorsNoActualStreamEvaluateParams.mo (35.4 KB ) - added by Francesco Casella 6 years ago.

Download all attachments as: .zip

Change History (17)

comment:1 by Vitalij Ruge, 6 years ago

Status: newaccepted

comment:2 by Vitalij Ruge, 6 years ago

Description: modified (diff)

comment:3 by Vitalij Ruge, 6 years ago

Description: modified (diff)

comment:4 by Vitalij Ruge, 6 years ago

maybe fixed with PR2624.

comment:5 by Vitalij Ruge, 6 years ago

@casella

if you are willing to implement this, I can prepare the tests ASAP.

that would be great!

comment:6 by Vitalij Ruge, 6 years ago

There was a side effect.

e.g. for BuildingSystems_Fluid_Examples_FlowSystem_Simplified6

tabsNorth2\[8\].port_b.h_outflow = (pmpNorth.m_flow*h)/(pmpNorth.m_flow +0.0)

where we have pmpNorth.m_flow at the place of max(pmpNorth.m_flow,eps).
No other module simplified it to the alias equation

tabsNorth2\[8\].port_b.h_outflow = h

comment:7 by Vitalij Ruge, 6 years ago

With PR2626 do simplify of expressions which were change in simplifyInStream.

in reply to:  5 comment:8 by Francesco Casella, 6 years ago

Replying to vitalij:

@casella

if you are willing to implement this, I can prepare the tests ASAP.

that would be great!

See attached updated package, Test12 and Test13. I wrote the expected optdaedump output in the documentation section, unfortunately I cannot test this myself now as the Windows nightly is currently broken.

Last edited 6 years ago by Francesco Casella (previous) (diff)

comment:9 by Vitalij Ruge, 6 years ago

I get a dismatch for Test13

pipe2.outlet.h_outflow = (max(-pipe3.inlet.m_flow, 1e-07) * sink3.h + pipe1.inlet.m_flow * source.h) / (max(-pipe3.inlet.m_flow, 1e-07) + pipe1.inlet.m_flow) 

where

1: pipe3.inlet.m_flow:VARIABLE(flow=true min = max(-1000000000.0, -1000000000.0) )  type: Real
6: pipe1.inlet.m_flow:VARIABLE(flow=true min = max(0.0, 0.0) )  type: Real

comment:10 by Francesco Casella, 6 years ago

@vitalij: my fault, what I wrote in the documentation was bogus. The output you reported in comment:9 is indeed correct.

I updated the attached library with the correct expected output, please update the test files on GitHub and close the ticket when you're done.

Last edited 6 years ago by Francesco Casella (previous) (diff)

comment:11 by anonymous, 6 years ago

Keywords: inStream added
Milestone: Future1.13.0

comment:12 by Vitalij Ruge, 6 years ago

Resolution: fixed
Status: acceptedclosed

new tests were added with PR1021

comment:13 by Francesco Casella, 6 years ago

@vitalij, I apologize, there was still a mistake in the documentation of Test13 that I catched just now. I have updated the attchment, do you mind updating it on GitHub?

Thanks!

comment:14 by Francesco Casella, 6 years ago

Resolution: fixed
Status: closedreopened

comment:15 by Vitalij Ruge, 6 years ago

Resolution: fixed
Status: reopenedclosed

fixed with PR1026

comment:16 by Francesco Casella, 6 years ago

Thanks @vitalij!

Note: See TracTickets for help on using tickets.