-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add PressureRatioCompressor and CommonPressureRatioSolver #1483
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
112 changes: 112 additions & 0 deletions
112
src/libecalc/domain/process/entities/process_units/pressure_ratio_compressor.py
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 |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| from libecalc.common.chart_type import ChartType | ||
| from libecalc.domain.component_validation_error import ( | ||
| ProcessChartTypeValidationException, | ||
| ) | ||
| from libecalc.domain.process.compressor.core.train.utils.enthalpy_calculations import ( | ||
| calculate_enthalpy_change_head_iteration, | ||
| ) | ||
| from libecalc.domain.process.process_solver.boundary import Boundary | ||
| from libecalc.domain.process.process_system.pressure_ratio_unit import PressureRatioUnit | ||
| from libecalc.domain.process.process_system.process_unit import ProcessUnitId | ||
| from libecalc.domain.process.value_objects.chart.chart import ChartData | ||
| from libecalc.domain.process.value_objects.chart.compressor import CompressorChart | ||
| from libecalc.domain.process.value_objects.fluid_stream import FluidService, FluidStream | ||
| from libecalc.domain.process.value_objects.fluid_stream.fluid import Fluid | ||
|
|
||
| _ALLOWED_CHART_TYPES = (ChartType.GENERIC_FROM_INPUT, ChartType.GENERIC_FROM_DESIGN_POINT) | ||
|
|
||
|
|
||
| class PressureRatioCompressor(PressureRatioUnit): | ||
| """Compressor stage that operates at a given pressure ratio. | ||
|
|
||
| Provides the two methods OutletPressureSolverRatio needs: | ||
| - propagate_stream_at_pressure_ratio() | ||
| - get_recirculation_range_at_pressure_ratio() | ||
|
|
||
| propagate_stream() raises NotImplementedError — a pressure ratio is always | ||
| required to evaluate this unit. | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| process_unit_id: ProcessUnitId, | ||
| compressor_chart: ChartData, | ||
| fluid_service: FluidService, | ||
| ) -> None: | ||
| if compressor_chart.origin_of_chart_data not in _ALLOWED_CHART_TYPES: | ||
| raise ProcessChartTypeValidationException( | ||
| f"PressureRatioCompressor requires a generic chart, " | ||
| f"got {compressor_chart.origin_of_chart_data.value}." | ||
| ) | ||
| self._id = process_unit_id | ||
| self._compressor_chart = CompressorChart(compressor_chart) | ||
| self._fluid_service = fluid_service | ||
|
|
||
| def get_id(self) -> ProcessUnitId: | ||
| return self._id | ||
|
|
||
| @property | ||
| def compressor_chart(self) -> CompressorChart: | ||
| return self._compressor_chart | ||
|
|
||
| def get_recirculation_range_at_pressure_ratio(self, inlet_stream: FluidStream, pressure_ratio: float) -> Boundary: | ||
| """Surge and stonewall boundaries at the given pressure ratio. | ||
|
|
||
| Uses head-based surge/stonewall limits — no shaft speed required. | ||
|
|
||
| Returns: | ||
| Boundary where: | ||
| min = additional rate (sm³/day) needed to reach the surge line | ||
| max = additional rate (sm³/day) available before stonewall | ||
| """ | ||
| outlet_pressure = inlet_stream.pressure_bara * pressure_ratio | ||
| enthalpy_change, polytropic_efficiency = calculate_enthalpy_change_head_iteration( | ||
| outlet_pressure=outlet_pressure, | ||
| polytropic_efficiency_vs_rate_and_head_function=self._compressor_chart.efficiency_as_function_of_rate_and_head, | ||
| inlet_streams=inlet_stream, | ||
| fluid_service=self._fluid_service, | ||
| ) | ||
| head_joule_per_kg = float(enthalpy_change * polytropic_efficiency) | ||
|
|
||
| min_actual_rate = float(self._compressor_chart.minimum_rate_as_function_of_head(head_joule_per_kg)) | ||
| max_actual_rate = float(self._compressor_chart.maximum_rate_as_function_of_head(head_joule_per_kg)) | ||
|
|
||
| density = inlet_stream.density | ||
| min_sm3_per_day = self._fluid_service.mass_rate_to_standard_rate( | ||
| fluid_model=inlet_stream.fluid_model, | ||
| mass_rate_kg_per_h=min_actual_rate * density, | ||
| ) | ||
| max_sm3_per_day = self._fluid_service.mass_rate_to_standard_rate( | ||
| fluid_model=inlet_stream.fluid_model, | ||
| mass_rate_kg_per_h=max_actual_rate * density, | ||
| ) | ||
| inlet_sm3_per_day = inlet_stream.standard_rate_sm3_per_day | ||
| return Boundary( | ||
| min=max(0.0, min_sm3_per_day - inlet_sm3_per_day), | ||
| max=max(0.0, max_sm3_per_day - inlet_sm3_per_day), | ||
| ) | ||
|
|
||
| def propagate_stream_at_pressure_ratio(self, inlet_stream: FluidStream, pressure_ratio: float) -> FluidStream: | ||
| """Propagate stream to an outlet pressure defined by a pressure ratio. | ||
|
|
||
| The operating point is determined purely from inlet conditions and the | ||
| target pressure ratio — no shaft speed required. | ||
|
|
||
| Args: | ||
| inlet_stream: The inlet fluid stream. | ||
| pressure_ratio: Target outlet/inlet pressure ratio (e.g. 2.0 means double the pressure). | ||
|
|
||
| Returns: | ||
| The outlet FluidStream at target_pressure = inlet.pressure * pressure_ratio. | ||
| """ | ||
| outlet_pressure = inlet_stream.pressure_bara * pressure_ratio | ||
| enthalpy_change_joule_per_kg, polytropic_efficiency = calculate_enthalpy_change_head_iteration( | ||
| outlet_pressure=outlet_pressure, | ||
| polytropic_efficiency_vs_rate_and_head_function=self._compressor_chart.efficiency_as_function_of_rate_and_head, | ||
| inlet_streams=inlet_stream, | ||
| fluid_service=self._fluid_service, | ||
| ) | ||
| target_enthalpy = float(inlet_stream.enthalpy_joule_per_kg + enthalpy_change_joule_per_kg) | ||
| props = self._fluid_service.flash_ph(inlet_stream.fluid_model, float(outlet_pressure), target_enthalpy) | ||
| outlet_fluid = Fluid(fluid_model=inlet_stream.fluid_model, properties=props) | ||
| return inlet_stream.with_new_fluid(outlet_fluid) | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Suggestion: Have a setter for pressure_ratio, and use propagate_stream() to fulfill the ProcessUnit contract. Other process units are already doing this, e.g. Choke (set_pressure_change).
Alternatively, split the ProcessUnit interface? e.g. RatioBasedUnit