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

Replace PlugFlowPipe outlet from vectorized to single port #1503

Merged
merged 43 commits into from
Oct 12, 2021

Conversation

bravache
Copy link
Contributor

@bravache bravache commented Jul 12, 2021

Closes #1494

This PR addresses the problem of compatibility of IBPSA.Fluid.FixedResistances.PlugFlowPipe with other pipe classes, by changing its outlet port from a vectorized port to a single port.

The PR brings non-backward compatible changes, for which a conversion script is provided for Dymola users.

Validation results

The following example and validation models uses the PlugFlowPipe class and were updated to reflect that change:

  • IBPSA.Fluid.FixedResistances.Examples.PlugFlowPipe
  • IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.FlowReversal
  • IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.PlugFlowAIT
  • IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.PlugFlowULg
  • IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.TransportWaterAir

For most of the models, the only change required was to remove the parameter nPorts from the parameterization of PlugFlowPipe and update the outlet connection. Additionally, for PlugFlowAIT, two splitters had to be introduced to replace the connections out of pip1 and pip5.
The results of all example/validation models remained unchanged, with the exception of PlugFlowAIT which only shows an error in the initial step of the simulation, but no error for the remainder of the runtime.
image

On a side note, the pressure boundary condition for the FlowReversal example was updated to 5bar, to avoid negative pressure at the inlet when the flow is reversed. This does not change the expected results, but make the example more robust.

Backward compatibility

This change is non-backward compatible. A conversion script was written to redirect previous objects to the obsolete class.

@bravache bravache requested a review from AntoineGautier July 13, 2021 21:14
@bravache
Copy link
Contributor Author

@AntoineGautier Please take a look and let me know if I've missed something. Thanks!

Copy link
Contributor

@AntoineGautier AntoineGautier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bravache Please see my inline comments.
Also, and as proposed in the issue page, I would merge PlugFlowCore and PlugFlowPipe into one, making the fluid volume conditional to an advanced Boolean parameter which would be true by default. The two models are too similar in my opinion to justify keeping them both.

Comment on lines 285 to 287
<br/>
This mixing volume is not present in the
<a href=\"modelica://IBPSA.Fluid.FixedResistances.BaseClasses.PlugFlowCore\">PlugFlowCore</a> model,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would delete that sentence as we agreed that the mixing volume was necessary to represent the effect of the pipe wall capacitance (not only for decoupling the DAE between multiple instances).
Instead I would add something like:

Note that in order to model a branched network it is recommended to use IBPSA.Fluid.FixedResistances.Junction at each junction and to configure that component with a state (see for instance
<a href="modelica://IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.PlugFlowAIT">
IBPSA.Fluid.FixedResistances.Validation.PlugFlowPipes.PlugFlowAIT).
This will avoid the numerical Jacobian that is otherwise created when the inlet ports of two instances of the plug flow model are connected together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworded the whole documentation to incorporate part of the PlugFlowCore doc. Let me know if that works.

@@ -1,7 +1,7 @@
within IBPSA.Fluid.FixedResistances;
model PlugFlowPipe
"Pipe model using spatialDistribution for temperature delay"
extends IBPSA.Fluid.Interfaces.PartialTwoPortVector;
Copy link
Contributor

@AntoineGautier AntoineGautier Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IBPSA.Fluid.Interfaces.PartialTwoPortVector may be retired into Obsolete as it was only used by the plug flow model.
To be validated with the IBPSA team.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might keep it like that since it predates the PlugFlowPipe model. Also, in the same package, there is also the PartialFourPortParallel which is not in used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I filed a ticket so that it can be discussed before implemented here: #1504

@bravache
Copy link
Contributor Author

I've moved the PlugFlowCore to Obsolete, and expanded its content directly in PlugFlowPipe. I've made the mixing volume conditional on the value of have_PipCap, and was also able to reuse the former PlugFlowCore validation results to verify the results of the model when that Boolean is false.

Copy link
Contributor

@AntoineGautier AntoineGautier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just have one minor change request and a suggestion.
Otherwise the changes look good to me.

IBPSA/Fluid/FixedResistances/Examples/PlugFlowPipeNoMix.mo Outdated Show resolved Hide resolved
IBPSA/Fluid/FixedResistances/PlugFlowPipe.mo Outdated Show resolved Hide resolved
@bravache
Copy link
Contributor Author

@Mathadon @nytschgeusen @cvering @mwetter
This PR is ready to merge. Antoine had a couple of comments left, but those were addressed and he is now on break, so I think it is reasonable to move forward.

Let me know if you have any comments. Otherwise, this will be merged on 09/03/2021.

Content

The main change introduce is changing the vectorized outlet port of PlugFlowPipe to be a single outlet port, which is consistent with other pipe model in the same package.

Additionally, the Fluid.FixedResistances.BaseClasses.PlugFlowCore and Fluid.FixedResistances.PlugFlowPipe are combined into a single model (previously the latter was a wrapper around the former), and the outlet mixing volume is made conditional on a boolean parameter have_pipCap.

The previous classes were moved to Obsolete and a conversion script was written to update PlugFlowCore and PlugFlowPipe instances to these obsolete classes.

The existing unit tests stored output had to be updated to reflect the change in translation statistics, but the timeseries results remained unchanged.

@Mathadon
Copy link
Member

@bravache thanks for the summary! I have forwarded this to a colleague who uses this model more actively than I do.

@mwetter
Copy link
Contributor

mwetter commented Sep 13, 2021

Michael to merge after last review.

@mwetter
Copy link
Contributor

mwetter commented Sep 14, 2021

Todo

  • Consider removing constant computeFlowResistance in the new pipe model. This would require a refactoring in the Buildings library for the distributed pipe model, which would in turn allow eliminating states.

@mwetter
Copy link
Contributor

mwetter commented Sep 15, 2021

@Mathadon : This is ready to merge from my point of view, but I think it would be good to have another approvals as during the clean up, I changed in PlugFlowPipe most instances to be protected, and instead exposed and/or introduced new variables QEnv_flow (for heat exchange with environment), dp, m_flow and v.
QEnv_flow = heatPort.Q_flow was introduced because in Buildings (and maybe soon in IBPSA) there is a discretized version of this model, in which QEnv_flow = sum(heatPort[:].Q_flow). By introducing this variable, both models have the same high level variables.

@Mathadon
Copy link
Member

@mwetter I'll try to review this tomorrow!

Copy link
Member

@Mathadon Mathadon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My largest concern is that the model IBPSA.Fluid.FixedResistances.PlugFlowPipe is not yet symmetric: a mixing volume consists at just one of the two pipe outlets/inlets. I propose to use two mixing volumes, each with half the mass.

@@ -48,8 +49,7 @@ initial equation
t0 = time;

equation
u = m_flow/(rho*(dh^2)/4*Modelica.Constants.pi)/length;

u = m_flow * conUM;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

annotation (Placement(transformation(extent={{-30,10},{-10,30}})));
Sensors.TemperatureTwoPort senTemInNoMix(
redeclare package Medium = Medium,
m_flow_nominal=1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could use tau=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for all temperature sensors.

annotation (Placement(transformation(extent={{0,-30},{20,-10}})));
Sensors.TemperatureTwoPort senTemOutNoMix(
redeclare package Medium = Medium,
m_flow_nominal=1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tau=0?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for all other examples to be honest: the filter slows down the model and skews the results.

"Control volume connected to port_b. Represents equivalent pipe wall thermal capacity."
annotation (Placement(transformation(extent={{70,20},{90,40}})));

LosslessPipe noMixPip(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use a simple connection instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I've written it like that to conserve a symmetrical syntax between the case with the mixing volume (have_pipCap) and the case without a mixing volume (not have_pipCap).
Also, in the graphical editor of Dymola, you get an annotation in the hover tooltip when a component is optional (screenshot below), but not when a connect statement is optional, which makes that structure a bit more explicit.
conditionalPip

That being said, if there is a computational or syntax issue with that format, I can switch back to an optional connect.

redeclare package Medium = Medium,
m_flow_nominal={pip1.m_flow_nominal,pip5.m_flow_nominal,pip4.m_flow_nominal},
from_dp=true,
linearized=true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this has no purpose if dp_nominal=0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Good catch. Removed for both junctions in this model.

package Validation "Collection of validation models"
extends Modelica.Icons.ExamplesPackage;

model PlugFlowCore "Simple example of plug flow pipe core"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to split this package in multiple .mo files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated

Copy link
Contributor Author

@bravache bravache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Filip, I've reviewed your inline comments.
With regard with the symmetry of the model, I was reluctant to introduce it because when I implement it naively, models that have two PlugFlowPipe in series become structurally singular because of the two connected mixing volumes.
I am discussing this with Michael and will update you if we come up to a solution.

Edit: Actually you can disregard that message, the structural singularity was a different issue from my rushed implementation.

"Control volume connected to port_b. Represents equivalent pipe wall thermal capacity."
annotation (Placement(transformation(extent={{70,20},{90,40}})));

LosslessPipe noMixPip(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I've written it like that to conserve a symmetrical syntax between the case with the mixing volume (have_pipCap) and the case without a mixing volume (not have_pipCap).
Also, in the graphical editor of Dymola, you get an annotation in the hover tooltip when a component is optional (screenshot below), but not when a connect statement is optional, which makes that structure a bit more explicit.
conditionalPip

That being said, if there is a computational or syntax issue with that format, I can switch back to an optional connect.

annotation (Placement(transformation(extent={{-30,10},{-10,30}})));
Sensors.TemperatureTwoPort senTemInNoMix(
redeclare package Medium = Medium,
m_flow_nominal=1,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for all temperature sensors.

redeclare package Medium = Medium,
m_flow_nominal={pip1.m_flow_nominal,pip5.m_flow_nominal,pip4.m_flow_nominal},
from_dp=true,
linearized=true,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed! Good catch. Removed for both junctions in this model.

package Validation "Collection of validation models"
extends Modelica.Icons.ExamplesPackage;

model PlugFlowCore "Simple example of plug flow pipe core"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Updated

@mwetter
Copy link
Contributor

mwetter commented Sep 23, 2021

@bravache : Above, there is the declaration:

Sensors.TemperatureTwoPort senTemInNoMix(
    redeclare package Medium = Medium,
    m_flow_nominal=1,

This looks wrong. All models use m_flow_nominal = 1 kg/s, but the source uses 3 kg/s. This should be made consistent.

@bravache
Copy link
Contributor Author

bravache commented Oct 5, 2021

@mwetter
Following our conversation and the test that showed that the computational impact was low in a sufficiently detailed model, I've implemented the symmetry in the PlugFlowPipe class. I've also added an advanced boolean flag have_symmetry which allows disabling the inlet mixing volume.
In addition, I've made the model extends from PartialTwoPortInterface rather than PartialTwoPort, since the former is more constraining, and adds show_T as a parameter.

bravache and others added 6 commits October 5, 2021 14:25
Using single line entries avoids very long strings (they will be cut with '...', see FlowReversal model)
Providing the full class name allows refactoring scripts to update them
@mwetter mwetter merged commit 6505919 into master Oct 12, 2021
@mwetter mwetter deleted the issue1494_plugflowpipe_singleoutlet branch October 12, 2021 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resolve PlugFlowPipe compatibility with PartialTwoPortInterface
4 participants