-
Notifications
You must be signed in to change notification settings - Fork 10
chore: poc of state / memento pattern #1547
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
Draft
tj098895
wants to merge
1
commit into
main
Choose a base branch
from
friend_of_the_state
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| from typing import Final | ||
|
|
||
| from libecalc.common.ddd import value_object | ||
| from libecalc.domain.process.compressor.core.train.utils.common import ( | ||
| RECIRCULATION_BOUNDARY_TOLERANCE, | ||
| calculate_outlet_pressure_and_stream, | ||
|
|
@@ -13,7 +14,20 @@ | |
| from libecalc.process.process_solver.boundary import Boundary | ||
|
|
||
|
|
||
| class Compressor(ProcessUnit): | ||
| @value_object | ||
| class OperatingPoint: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct "input params"? |
||
| inlet_stream: FluidStream | ||
| speed: float | ||
|
|
||
|
|
||
| @value_object | ||
| class CompressorSnapshot: | ||
| outlet_stream: FluidStream | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. relevant "minimum" output params? |
||
| polytropic_head_joule_per_kg: float | ||
| polytropic_efficiency: float | ||
|
|
||
|
|
||
| class Compressor(ProcessUnit[CompressorSnapshot]): | ||
| def __init__( | ||
| self, | ||
| compressor_chart: ChartData, | ||
|
|
@@ -25,10 +39,34 @@ def __init__( | |
| self._fluid_service = fluid_service | ||
| self._speed: float | None = None | ||
|
|
||
| # Both, for different purposes? | ||
| self._snapshots: dict[OperatingPoint, CompressorSnapshot] = {} | ||
| self._history: list[CompressorSnapshot] = [] | ||
|
|
||
| def get_id(self) -> ProcessUnitId: | ||
| return self._id | ||
|
|
||
| def _record_snapshot(self, key: object, snapshot: CompressorSnapshot) -> None: | ||
| if not isinstance(key, OperatingPoint): | ||
| raise ValueError("Key must be of type OperatingPoint") | ||
| self._snapshots[key] = snapshot | ||
| self._history.append(snapshot) | ||
|
|
||
| def snapshot_for(self, key: object) -> CompressorSnapshot | None: | ||
| if not isinstance(key, OperatingPoint): | ||
| raise ValueError("Key must be of type OperatingPoint") | ||
| return self._snapshots.get(key, None) | ||
|
|
||
| @property | ||
| def history(self) -> list[CompressorSnapshot]: | ||
| return self._history | ||
|
|
||
| def propagate_stream(self, inlet_stream: FluidStream) -> FluidStream: | ||
| if ( | ||
| cached_snapshot := self.snapshot_for(OperatingPoint(inlet_stream=inlet_stream, speed=self.speed)) | ||
| ) is not None: | ||
| return cached_snapshot.outlet_stream | ||
|
|
||
| actual_rate = inlet_stream.volumetric_rate_m3_per_hour | ||
| if actual_rate < self.minimum_flow_rate: | ||
| raise RateTooLowError( | ||
|
|
@@ -56,13 +94,25 @@ def propagate_stream(self, inlet_stream: FluidStream) -> FluidStream: | |
| rate=actual_rate, | ||
| ) | ||
|
|
||
| return calculate_outlet_pressure_and_stream( | ||
| outlet_stream = calculate_outlet_pressure_and_stream( | ||
| polytropic_efficiency=polytropic_efficiency, | ||
| polytropic_head_joule_per_kg=polytropic_head, | ||
| inlet_stream=inlet_stream, | ||
| fluid_service=self._fluid_service, | ||
| ) | ||
|
|
||
| # Ok that it is explicit, or decorator? | ||
| self._record_snapshot( | ||
| key=OperatingPoint(inlet_stream=inlet_stream, speed=self.speed), | ||
| snapshot=CompressorSnapshot( | ||
| outlet_stream=outlet_stream, | ||
| polytropic_head_joule_per_kg=polytropic_head, | ||
| polytropic_efficiency=polytropic_efficiency, | ||
| ), | ||
| ) | ||
|
|
||
| return outlet_stream | ||
|
|
||
| @property | ||
| def compressor_chart(self) -> CompressorChart: | ||
| return self._compressor_chart | ||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TSnapshot, or TInput and TOutput? for a snapshot?