Skip to content

Control Volume 1D Scaler#1673

Merged
dallan-keylogic merged 12 commits intoIDAES:scaling_toolboxfrom
dallan-keylogic:control_volume_1D_scaler
Oct 15, 2025
Merged

Control Volume 1D Scaler#1673
dallan-keylogic merged 12 commits intoIDAES:scaling_toolboxfrom
dallan-keylogic:control_volume_1D_scaler

Conversation

@dallan-keylogic
Copy link
Contributor

@dallan-keylogic dallan-keylogic commented Sep 26, 2025

Fixes

  • Allows submodel scalers to be called on BlockData directly, not just IndexedBlocks

Summary/Motivation:

Adds a scaler for the ControlVolume1D.

Changes proposed in this PR:

  • Adds scaler for ControlVolume1D
  • Adds public flow_direction property to allow public access to the _flow_direction attribute.

Legal Acknowledgement

By contributing to this software project, I agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the license terms described in the LICENSE.txt file at the top level of this directory.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link

codecov bot commented Sep 26, 2025

Codecov Report

❌ Patch coverage is 99.15966% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.15%. Comparing base (ca3c1fd) to head (321fae0).
⚠️ Report is 27 commits behind head on scaling_toolbox.

Files with missing lines Patch % Lines
idaes/core/base/control_volume_base.py 97.61% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           scaling_toolbox    #1673      +/-   ##
===================================================
+ Coverage            77.09%   77.15%   +0.05%     
===================================================
  Files                  395      395              
  Lines                63182    63278      +96     
  Branches             10380    10418      +38     
===================================================
+ Hits                 48713    48824     +111     
+ Misses               12021    12012       -9     
+ Partials              2448     2442       -6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dallan-keylogic dallan-keylogic changed the title Control volume 1D Scaler Control Volume 1D Scaler Sep 29, 2025
Comment on lines +175 to +200
# if hasattr(self, "elemental_flow_term"):
# for (t, x, e), v in self.elemental_flow_term.items():
# flow_basis = self.properties[t, x].get_material_flow_basis()

# sf = iscale.min_scaling_factor(
# [
# self.properties[t, x].get_material_density_terms(p, j)
# for (p, j) in phase_component_set
# ],
# default=1,
# warning=True,
# )
# if flow_basis == MaterialFlowBasis.molar:
# sf *= 1
# elif flow_basis == MaterialFlowBasis.mass:
# # MW scaling factor is the inverse of its value
# sf *= value(self.properties[t, x].mw_comp[j])

# iscale.set_scaling_factor(v, sf)

# if hasattr(self, "elemental_flow_dx"):
# for (t, x, e), v in self.elemental_flow_dx.items():
# if iscale.get_scaling_factor(v) is None:
# # As domain is normalized, scale should be equal to flow
# sf = iscale.get_scaling_factor(self.elemental_flow_term[t, x, e])
# iscale.set_scaling_factor(v, sf)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this be implemented in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Since the Gibbs reactor is the only unit model using element balances, I was hoping that @agarciadiego would take care of it when he revisited the Gibbs reactor scaling. If not, I'll take care of it.

However, many unit models depend on the ControlVolume1D, so I'd rather make this scaler available now and then revisit element balance scaling later.


if hasattr(model, "_flow_terms"): # pylint: disable=protected-access
for idx, v in model._flow_terms.items():
self.scale_variable_by_definition_constraint(
Copy link
Contributor

Choose a reason for hiding this comment

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

scale_variable_by_definition_constraint is a new capability right? I don't see it in main, but I also don't see it being added to custom_scaler_base.py in this PR. As in, I see that the version of custom_scaler_base.py in this PR has this new functionality, but it's not appearing as one of the changed lines. Why is this happening?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It lives in the scaling_toolbox feature branch right here. That's where we've been merging all the scaling PRs, and that's where this PR is pointed.

Comment on lines +168 to +169
scaler_obj.default_scaling_factors["area"] = 1 / 83
scaler_obj.default_scaling_factors["length"] = 1 / 599
Copy link
Contributor

Choose a reason for hiding this comment

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

These are marked as having a required user input. What happens if a user does not supply scaling factors for these? Does an error or warning pop up. If so, is this being tested somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

An error pops up.

I don't think the error is being tested specifically for the ControlVolume1D, but the general feature is being tested here.

Copy link
Contributor

Choose a reason for hiding this comment

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

As long as it's being tested somewhere, I think it's fine

Copy link
Contributor

@MarcusHolly MarcusHolly left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Ryan-Hughes-8 Ryan-Hughes-8 left a comment

Choose a reason for hiding this comment

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

This looks good to me. I didn't get a chance to test this locally on any examples, but I assume the incoming unit model scalers will be additional stress tests.

Comment on lines +137 to +147
self.propagate_state_scaling(
target_state=model.properties,
source_state=model.properties[x_in],
overwrite=overwrite,
)
self.call_submodel_scaler_method(
submodel=model.properties,
submodel_scalers=submodel_scalers,
method="variable_scaling_routine",
overwrite=overwrite,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

When you call these methods on an indexed component, will it iterate through the indices and apply to each of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it will. The original method wouldn't even let you call it on BlockData children of an IndexedBlock, but this PR adds a change that allows you to call it both on an IndexedBlock and BlockData.

Copy link
Contributor

@aostace01 aostace01 left a comment

Choose a reason for hiding this comment

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

The PR looks great!

A question for perhaps a future PR: are there user-facing docs that need updating to explain how to use this scaler and what inputs are required?

@dallan-keylogic dallan-keylogic merged commit 0a8eed3 into IDAES:scaling_toolbox Oct 15, 2025
109 checks passed
@dallan-keylogic
Copy link
Contributor Author

The PR looks great!

A question for perhaps a future PR: are there user-facing docs that need updating to explain how to use this scaler and what inputs are required?

Yes, we need to update the documentation soon. At some point, I am hoping to create a method that automatically tells you which scaling factors are expected by a Scaler object but making sure all the scalers exist is the first priority. Also, I'd like to see them get used in the projects to see if we need to make any changes to the interface to make them easier to use. After they reach their final form, we can update the documentation.

dallan-keylogic added a commit that referenced this pull request Nov 6, 2025
* additional test for propagating scaling factors within a block

* Control Volume 1D scaler

* phase material balance cv0d

* test for submodel scaler for blockdata

* Tests for flow direction attribute

* black and typo

* remove unused variables

* protected property error message depends on python version

* test no override

* test propagate scaling factors

* additional test coverage
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

Successfully merging this pull request may close these issues.

4 participants