Generic property package: Using constraints to define state variables #1554
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes # .
Summary/Motivation:
As part of Ahuora we are using the generic property package framework to build custom property packages.
The code looks something like this:
Suppose that we know the value for
flow_mass
and want to use that instead. We can do this using aConstraint
:However, this ends up running into issues during initialization:
flow_mol
gets fixed anyway, and the block becomes over-defined. However, we are able to prevent this by setting the kwargstate_vars_fixed=True
, which means initialization will skip trying to fix the state variables (and just check for 0 degrees of freedom). So this is not an issue at this stage.flow_mass_constraint
gets deactivated during the "Bubble, dew, and critical point initialization" step (which is fine), but needs to be activated for the "Phase equilibrium initialization" step, to ensure 0 degrees of freedom.The specific error I get is
Changes proposed in this PR:
flow_mass_constraint
(or other constraints as needed) before the "Phase equilibrium initialization" step. This is done by "tagging" the constraint withdefining_state_var = True
to indicate that this constraint defines a state variable, and should be activated.For example,
I added this check to both the
_GenericStateBlock
andModularPropertiesInitializer
initialize methods. I am not too sure how theModularPropertiesInitializer
class is used (seems to be the same logic) but I assume the code fits in both.Comments on this approach would be useful.
Legal Acknowledgement
By contributing to this software project, I agree to the following terms and conditions for my contribution: