More rigorous treatment of extensive states #330
Draft
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.
This is something I wanted to improve on since running into some issues in phase equilibrium algorithms. The core ideas:
I actually tried to do this at compile-time, which worked and actually helped a lot identifying all problems that would only be visible in run-time now. However, having yet another generic parameter to ultimately avoid some errors in edge cases is simply not worth it.
The key for evaluating extensive properties is
All state methods for extensive properties have to call this method at which point they will panic if the size of the state is not known. This is a hard error (a panic even), because it is a fundamentally wrong usage on the user side. Some previous fields of
Stateare now getters instead (volume,moles,partial_density).The field
total_moles: Option<Moles<D>>is set depending on the inputs with which the state is created. This is done via theCompositionandFullCompositiontraits.state creations that need the full composition (e.g., tp flash or TVN) can require the
FullCompositiontrait. As mentioned before compile-time checks for this only apply to the creation of the state.The
Compositiontrait is implemented for the following structs:()Molesf64OVector<f64,N>&OVector<f64,N>OVector<f64,N-1>Dynonly&OVector<f64,N-1>DynonlyMoles<OVector<f64,N>>&Moles<OVector<f64,N>>Density<OVector<f64,N>>Composition::densityis only needed in some specific cases to avoid overspecifying the density of a state.This gives the opportunity to organize the state creator methods a bit. The following methods are now implemented:
With a lot of the logic being moved to the new traits, the use cases for the
StateBuilderdwindle and I suggest to remove it.