Control Volume 1D Scaler#1673
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
| # 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) |
There was a problem hiding this comment.
Will this be implemented in a separate PR?
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| scaler_obj.default_scaling_factors["area"] = 1 / 83 | ||
| scaler_obj.default_scaling_factors["length"] = 1 / 599 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
As long as it's being tested somewhere, I think it's fine
Ryan-Hughes-8
left a comment
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
When you call these methods on an indexed component, will it iterate through the indices and apply to each of them?
There was a problem hiding this comment.
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.
aostace01
left a comment
There was a problem hiding this comment.
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 |
* 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
Fixes
BlockDatadirectly, not justIndexedBlocksSummary/Motivation:
Adds a scaler for the
ControlVolume1D.Changes proposed in this PR:
ControlVolume1Dflow_directionproperty to allow public access to the_flow_directionattribute.Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: