Skip to content

Unit consistency for s-parameter in Modelica.Fluid.Vessels.PartialLumpedVessel #4398

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HansOlsson
Copy link
Contributor

@HansOlsson HansOlsson commented Apr 24, 2024

There are multiple alternatives here, but this seemed like the smallest change.
Compare to Modelica.Electrical.Analog.Interfaces.IdealSemiconductor

The new indentation of "protected" is consistent with style-guide, previously it was indented less than the class.

Summary by CodeRabbit

  • New Features

    • Enhanced simulation behavior with standardized unit parameters that refine inflow computations for more consistent fluid flow outcomes.
  • Refactor

    • Reorganized internal configuration to streamline computational logic while maintaining visible functionality.

@HansOlsson HansOlsson added the L: Fluid Issue addresses Modelica.Fluid (excl. Dissipation) label Apr 24, 2024
Copy link
Member

@beutlich beutlich left a comment

Choose a reason for hiding this comment

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

Why is the curve parameter s unitless (of type Real) and not of type SI.Length or SI.PathLength?

@HansOlsson
Copy link
Contributor Author

Why is the curve parameter s unitless (of type Real) and not of type SI.Length or SI.PathLength?

It will be deduced to be of type mass-flow-rate ("kg/s") not "1". There are multiple ways of doing it, but I thought this was the less intrusive.

@beutlich
Copy link
Member

beutlich commented Jun 5, 2024

I am struggeling with the (deduced) unit of s. If the start value fluidLevel_max is of type SI.Height ist should be a length based unit, right?

@HansOlsson
Copy link
Contributor Author

I am struggeling with the (deduced) unit of s. If the start value fluidLevel_max is of type SI.Height ist should be a length based unit, right?

Ah, yes, I messed up.

Yes, it will be length-based i.e. "m", based on the other branch and for the mass-flow branch we do:
s[i] = ports[i].m_flow*(unitHeight/unitMassFlow); which means s[i] will be length-based here as well.

The alternative would be something like:

   ... s[..](each unit="1");
...
            s[i] = (fluidLevel - portsData_height[i])/unitHeight;
          elseif inFlow[i] then
            // ports[i] is above fluidLevel and has inflow
            ports[i].p = vessel_ps_static[i];
            s[i] = ports[i].m_flow;
            s[i] = ports[i].m_flow/unitMassFlow;

@beutlich
Copy link
Member

beutlich commented Jun 5, 2024

What about SI.Length[nPorts] s(each start = fluidLevel_max) to make it explicit and to not deduce the min attribute of SI.Height of the start value?

There are multiple alternatives here, but this seemed like the smallest change.
Compare to Modelica.Electrical.Analog.Interfaces.IdealSemiconductor
Copy link

coderabbitai bot commented Apr 9, 2025

Walkthrough

This pull request adds two constant parameters—unitMassFlow and unitHeight—to the OpenTank model in the Modelica/Fluid/Vessels.mo file. The change updates the inflow calculation by replacing the original state assignment with a scaled value: the mass flow rate is multiplied by the ratio of unitHeight to unitMassFlow. Additionally, minor formatting adjustments are made in the protected section.

Changes

File Path Change Summary
Modelica/Fluid/Vessels.mo Added constants unitMassFlow and unitHeight (with hidden results) in model OpenTank; modified the inflow condition to compute s[i] = ports[i].m_flow * (unitHeight/unitMassFlow); adjusted indentation in the protected section.

Sequence Diagram(s)

sequenceDiagram
    participant IE as Inflow Event
    participant OT as OpenTank Model
    participant CP as Calculation Process
    IE->>OT: Trigger inflow condition
    OT->>CP: Retrieve ports[i].m_flow, unitHeight, unitMassFlow
    CP-->>OT: Compute s[i] = ports[i].m_flow * (unitHeight/unitMassFlow)
    OT->>IE: Update state variable s[i]
Loading

Poem

I'm a rabbit hopping through the code so bright,
With constants new, my heart takes flight,
Unit mass and height now shine in view,
Inflow flows refined—oh what a breakthrough!
A nibble of joy in every commit, too! 🐰💻


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
Modelica/Fluid/Vessels.mo (1)

257-258: Consider an explicit type declaration for the s parameter.

While the current changes correctly address the unit consistency issue with s, you might want to consider Beutlich's suggestion to explicitly declare s with a specific unit type:

-Real[nPorts] s(each start = fluidLevel_max)
+"Curve parameters for port flows vs. port pressures; for further details see, Modelica Tutorial: Ideal switching devices";
+SI.Length[nPorts] s(each start = fluidLevel_max)
"Curve parameters for port flows vs. port pressures; for further details see, Modelica Tutorial: Ideal switching devices";

This would make the intended unit type more explicit and potentially avoid similar issues in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be949b2 and fc9e2d3.

📒 Files selected for processing (1)
  • Modelica/Fluid/Vessels.mo (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: external_c_checks_cmake_windows-msvc
  • GitHub Check: external_c_checks_cmake_windows-cygwin
🔇 Additional comments (3)
Modelica/Fluid/Vessels.mo (3)

271-271: Improved indentation in the protected section.

The indentation of the "protected" section has been corrected to match the style guide, making it consistent with the class indentation level.


295-296: Good addition of unit conversion constants.

These constants provide appropriate unit conversion factors to ensure consistency in the calculation of the s parameter. By setting both to 1 with appropriate units (unitMassFlow as mass flow rate and unitHeight as length), you provide the necessary dimensional conversion while maintaining numeric values. The HideResult=true annotation appropriately prevents these implementation details from appearing in simulation results.


379-379: Correctly implemented unit consistency for s-parameter.

This change addresses the unit consistency issue for the s parameter when there is inflow. Previously, s[i] would have been assigned a mass flow rate (kg/s), but now it's being scaled to have units of length (m) by multiplying by the ratio of unitHeight to unitMassFlow. This ensures that s[i] consistently has the same unit (length) across all branches of the conditional statement:

  • In regular flow: s[i] = fluidLevel - portsData_height[i] (length)
  • In inflow: s[i] = ports[i].m_flow*(unitHeight/unitMassFlow) (now length)
  • In no flow: s[i] = (ports[i].p - vessel_ps_static[i])/Medium.p_default*(portsData_height[i] - fluidLevel) (length)

This change eliminates the unit inconsistency identified in the PR discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L: Fluid Issue addresses Modelica.Fluid (excl. Dissipation)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants