Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying h_outflow calculation when allowFlowReversal = false #281

Closed
Mathadon opened this issue Jun 30, 2015 · 6 comments
Closed

Simplifying h_outflow calculation when allowFlowReversal = false #281

Mathadon opened this issue Jun 30, 2015 · 6 comments

Comments

@Mathadon
Copy link
Member

Currently Dymola is able to simplify some calculations when allowFlowReversal = false. Consider for instance the following equation.
H_in = semiLinear(m_flow, inStream(port_a.h_outflow), inStream(port_b.h_outflow))
allowFlowReversal typically sets the min attribute of m_flow equal to zero. Dymola can then detect that mass flow will never become negative and that therefore inStream(port_a.h_outflow) should always be used in the equation:
H_in = m_flow*inStream(port_a.h_outflow)
Since the equation now no longer depends on inStream(port_b.h_outflow) this can lead to smaller algebraic loops.

However there are some cases where the min and max attributes are not propagated properly by Dymola and therefore these simplifications are not made. Moreover OpenModelica does not make these simplifications at all. This can lead to large algebraic loops, which deteriorate simulation speed and stability.

I propose to make some changes in the code such that this simplification is always made. To this end I would like to change Annex60.Fluid.Interfaces.StaticTwoPortConservationEquation, Buildings.Fluid.BaseClasses.PartialResistance, Annex60.Fluid.Sensors.BaseClasses.PartialFlowSensor and similar models.

In the case of Annex60.Fluid.Sensors.BaseClasses.PartialFlowSensor the change would be to replace

  port_a.h_outflow = inStream(port_b.h_outflow);
  port_b.h_outflow = inStream(port_a.h_outflow);
  port_a.Xi_outflow = inStream(port_b.Xi_outflow);
  port_b.Xi_outflow = inStream(port_a.Xi_outflow);
  port_a.C_outflow = inStream(port_b.C_outflow);
  port_b.C_outflow = inStream(port_a.C_outflow);

by

  port_a.h_outflow = if not allowFlowReversal then Medium.h_default else inStream(port_b.h_outflow);
  port_b.h_outflow =  inStream(port_a.h_outflow);
  port_a.Xi_outflow = if not allowFlowReversal then Medium.Xi_default else  inStream(port_b.Xi_outflow);
  port_b.Xi_outflow = inStream(port_a.Xi_outflow);
  port_a.C_outflow = if not allowFlowReversal then Medium.C_default else  inStream(port_b.C_outflow);
  port_b.C_outflow = inStream(port_a.C_outflow);

It may actually be interesting the create a new partial that contains these equations since they are now repeated in a few partials.

I will add an example that demonstrates that this works.

@Mathadon
Copy link
Member Author

See example Annex60.Fluid.Interfaces.Examples.ReverseFlowAdvanced on https://github.com/Mathadon/modelica-annex60/tree/issue281_floRevCalc
Heat is injected in the mixing volume based on the upstream temperature of the fluid. Since mass flow is always in the same direction this temperature is known a priori. However since dymola thinks the flow can reverse (even with allowFlowReversal=false) a non-linear system is formed:

Sizes of nonlinear systems of equations: {3}
Sizes after manipulation of the nonlinear systems: {1}

This can be removed by setting

port_a.h_outflow = if not allowFlowReversal then Medium.h_default else inStream(port_b.h_outflow);

in Annex60.Fluid.Sensors.BaseClasses.PartialFlowSensor.

@Mathadon
Copy link
Member Author

If you agree with the proposed changes I can propose an implementation.

@Mathadon
Copy link
Member Author

Illustration:
screen shot 2015-06-30 at 11 24 18

@Mathadon
Copy link
Member Author

Mathadon commented Sep 3, 2015

I need to make a new pull request for this.

@rfranke
Copy link

rfranke commented Sep 8, 2015

Note that OpenModelica now considers the simplification. In fact any Modelica tool must do so in order to produce correct results for fluid models with absolute sensors, like Modelica.Fluid.Examples.{DrumBoiler, TraceSubstances.RoomCO2}.
See: https://trac.openmodelica.org/OpenModelica/ticket/3430

Mathadon added a commit that referenced this issue Sep 14, 2015
…rtialResistance and PartialFlowSensor

rewrote equations in StaticTwoPortConservationEquation for better readability
this is for #281
@Mathadon
Copy link
Member Author

Merged in #312

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants