Skip to content

Commit

Permalink
refactor: remove pressure before choking (#609)
Browse files Browse the repository at this point in the history
chore: update snapshots

ECALC-1584
  • Loading branch information
olelod authored Sep 16, 2024
1 parent c27e5bd commit 02f9099
Show file tree
Hide file tree
Showing 22 changed files with 74 additions and 5,245 deletions.
10 changes: 0 additions & 10 deletions src/libecalc/core/consumers/compressor/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from libecalc.common.units import Unit
from libecalc.common.utils.rates import (
TimeSeriesBoolean,
TimeSeriesFloat,
TimeSeriesStreamDayRate,
)
from libecalc.core.consumers.base import BaseConsumerWithoutOperationalSettings
Expand Down Expand Up @@ -65,14 +64,6 @@ def evaluate(
unit=model_result.energy_usage_unit,
)

outlet_pressure_before_choke = TimeSeriesFloat(
values=model_result.outlet_pressure_before_choking
if model_result.outlet_pressure_before_choking
else [np.nan],
timesteps=[current_timestep],
unit=Unit.BARA,
)

component_result = core_results.CompressorResult(
timesteps=[current_timestep],
power=TimeSeriesStreamDayRate(
Expand All @@ -93,7 +84,6 @@ def evaluate(
timesteps=[current_timestep],
unit=Unit.NONE,
),
outlet_pressure_before_choking=outlet_pressure_before_choke,
streams=[
TimeSeriesStreamConditions.from_stream_condition(total_requested_inlet_stream),
*[
Expand Down
17 changes: 0 additions & 17 deletions src/libecalc/core/consumers/legacy_consumer/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,9 @@ def get_consumer_result(
new_time_vector=timesteps,
)
)
outlet_pressure_before_choking = (
aggregated_result.energy_function_result.outlet_pressure_before_choking
if aggregated_result.energy_function_result.outlet_pressure_before_choking is not None
else [math.nan] * len(timesteps)
)

outlet_pressure_before_choking = array_to_list(
self.reindex_time_vector(
values=outlet_pressure_before_choking,
time_vector=aggregated_result.time_vector,
new_time_vector=timesteps,
)
)
else:
recirculation_loss = [math.nan] * len(timesteps)
rate_exceeds_maximum = [False] * len(timesteps)
outlet_pressure_before_choking = [math.nan] * len(timesteps)

consumer_result = CompressorResult(
id=self.id,
Expand All @@ -221,9 +207,6 @@ def get_consumer_result(
rate_exceeds_maximum=TimeSeriesBoolean(
timesteps=timesteps, values=rate_exceeds_maximum, unit=Unit.NONE
),
outlet_pressure_before_choking=TimeSeriesFloat(
timesteps=timesteps, values=outlet_pressure_before_choking, unit=Unit.BARA
),
)

else:
Expand Down
25 changes: 1 addition & 24 deletions src/libecalc/core/models/compressor/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class CompressorTrainStageResultSingleTimeStep(BaseModel):
pressure_is_choked: Optional[bool] = None
head_exceeds_maximum: Optional[bool] = None

inlet_pressure_before_choking: float
outlet_pressure_before_choking: float

point_is_valid: bool
model_config = ConfigDict(extra="forbid")

Expand Down Expand Up @@ -88,8 +85,6 @@ def create_empty(cls) -> CompressorTrainStageResultSingleTimeStep:
rate_exceeds_maximum=False,
pressure_is_choked=False,
head_exceeds_maximum=False,
inlet_pressure_before_choking=np.nan,
outlet_pressure_before_choking=np.nan,
point_is_valid=True,
)

Expand Down Expand Up @@ -194,11 +189,6 @@ def from_result_list_to_dto(
else np.nan
for t in range(len(result_list))
]
inlet_stream_condition_per_stage[i].pressure_before_choking = [
result_list[t].stage_results[i].inlet_pressure_before_choking
for t in range(len(result_list))
if result_list[t].stage_results[i].inlet_pressure_before_choking is not None
]
# Note: Here we reverse the lingo from "before ASV" to "ASV corrected"
inlet_stream_condition_per_stage[i].actual_rate_m3_per_hr = [
result_list[t].stage_results[i].inlet_actual_rate_asv_corrected_m3_per_hour
Expand Down Expand Up @@ -257,11 +247,6 @@ def from_result_list_to_dto(
else np.nan
for t in range(len(result_list))
]
outlet_stream_condition_per_stage[i].pressure_before_choking = [
result_list[t].stage_results[i].outlet_pressure_before_choking
for t in range(len(result_list))
if result_list[t].stage_results[i].outlet_pressure_before_choking is not None
]
outlet_stream_condition_per_stage[i].actual_rate_m3_per_hr = [
result_list[t].stage_results[i].outlet_actual_rate_asv_corrected_m3_per_hour
for t in range(len(result_list))
Expand Down Expand Up @@ -529,21 +514,13 @@ def discharge_pressure(self) -> float:
else:
return np.nan

@property
def discharge_pressure_before_choking(self) -> float:
return np.nan # not relevant here

@property
def suction_pressure(self) -> float:
if self.inlet_stream is not None:
return self.inlet_stream.pressure_bara
else:
return np.nan

@property
def suction_pressure_before_choking(self) -> float:
return np.nan # not relevant here

@property
def mass_rate_kg_per_hour(self) -> float:
return self.stage_results[0].mass_rate_kg_per_hour
Expand Down Expand Up @@ -666,7 +643,7 @@ def rate_exceeds_maximum(self) -> bool:
@property
def pressure_is_choked(self) -> bool:
# Small margin when checking for choke in order to avoid false positives.
return self.discharge_pressure < (self.discharge_pressure_before_choking - 1e-5) or any(
return self.discharge_pressure < self.stage_results[0].discharge_pressure or any(
stage.pressure_is_choked for stage in self.stage_results
)

Expand Down
2 changes: 0 additions & 2 deletions src/libecalc/core/models/compressor/train/simplified_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,6 @@ def efficiency_as_function_of_rate_and_head(rates, heads):
rate_exceeds_maximum=rate_exceeds_maximum[i],
pressure_is_choked=pressure_is_choked[i],
head_exceeds_maximum=head_exceeds_maximum[i],
inlet_pressure_before_choking=np.nan, # We do not have this value here
outlet_pressure_before_choking=np.nan, # We do not have this value here
# Assuming choking and ASV. Valid points are to the left and below the compressor chart.
point_is_valid=~np.isnan(power_mw[i]), # power_mw is set to np.NaN if invalid step.
)
Expand Down
2 changes: 0 additions & 2 deletions src/libecalc/core/models/compressor/train/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ def evaluate(
power_megawatt=power_megawatt,
point_is_valid=compressor_chart_head_and_efficiency_result.is_valid,
polytropic_enthalpy_change_before_choke_kJ_per_kg=enthalpy_change_J_per_kg / 1000,
inlet_pressure_before_choking=inlet_stream_compressor.pressure_bara,
outlet_pressure_before_choking=outlet_stream.pressure_bara,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1475,9 +1475,9 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(

# check if target pressures are met
target_pressure_status = self.check_target_pressures(
calculated_suction_pressure=compressor_train_results_to_return_first_part.suction_pressure_before_choking,
calculated_discharge_pressure=compressor_train_results_to_return_last_part.discharge_pressure,
calculated_intermediate_pressure=compressor_train_results_to_return_first_part.discharge_pressure,
calculated_suction_pressure=compressor_train_results_to_return_first_part.inlet_stream.pressure_bara,
calculated_discharge_pressure=compressor_train_results_to_return_last_part.outlet_stream.pressure_bara,
calculated_intermediate_pressure=compressor_train_results_to_return_first_part.outlet_stream.pressure_bara,
)

return CompressorTrainResultSingleTimeStep(
Expand Down
14 changes: 0 additions & 14 deletions src/libecalc/core/models/results/compressor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import math
from enum import Enum
from math import isnan
from typing import Dict, List, Optional, Union
Expand Down Expand Up @@ -50,7 +49,6 @@ class TargetPressureStatus(str, Enum):

class CompressorStreamCondition(EnergyModelBaseResult):
pressure: Optional[List[Optional[float]]] = None
pressure_before_choking: Optional[List[Optional[float]]] = None
actual_rate_m3_per_hr: Optional[List[Optional[float]]] = None
actual_rate_before_asv_m3_per_hr: Optional[List[Optional[float]]] = None
standard_rate_sm3_per_day: Optional[List[Optional[float]]] = None
Expand All @@ -65,7 +63,6 @@ def create_empty(cls, number_of_timesteps) -> CompressorStreamCondition:
nans = [np.nan] * number_of_timesteps
return cls(
pressure=nans,
pressure_before_choking=nans,
actual_rate_m3_per_hr=nans,
actual_rate_before_asv_m3_per_hr=nans,
standard_rate_sm3_per_day=nans,
Expand Down Expand Up @@ -259,14 +256,3 @@ def recirculation_loss(self) -> List[float]:
@property
def rate_exceeds_maximum(self) -> List[bool]:
return list(np.any([stage.rate_exceeds_maximum for stage in self.stage_results], axis=0))

@property
def outlet_pressure_before_choking(self) -> Optional[List[float]]:
return (
[
pressure if pressure is not None else math.nan
for pressure in self.stage_results[-1].outlet_stream_condition.pressure_before_choking
]
if self.stage_results[-1].outlet_stream_condition.pressure_before_choking is not None
else None
)
2 changes: 0 additions & 2 deletions src/libecalc/core/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class CompressorResult(GenericComponentResult):
typ: Literal["comp"] = "comp"
recirculation_loss: TimeSeriesStreamDayRate
rate_exceeds_maximum: TimeSeriesBoolean
outlet_pressure_before_choking: TimeSeriesFloat
streams: Optional[List[TimeSeriesStreamConditions]] = None # Optional because only in v2

def get_subset(self, indices: List[int]) -> Self:
Expand All @@ -84,7 +83,6 @@ def get_subset(self, indices: List[int]) -> Self:
power=self.power[indices] if self.power is not None else None,
recirculation_loss=self.recirculation_loss[indices],
rate_exceeds_maximum=self.rate_exceeds_maximum[indices],
outlet_pressure_before_choking=self.outlet_pressure_before_choking[indices],
)


Expand Down
29 changes: 0 additions & 29 deletions src/libecalc/presentation/json_result/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,13 +635,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
pressure_before_choking=TimeSeriesFloat(
timesteps=model.timesteps,
values=stage_result.inlet_stream_condition.pressure_before_choking
if stage_result.inlet_stream_condition.pressure_before_choking is not None
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
temperature_kelvin=TimeSeriesFloat(
timesteps=model.timesteps,
values=stage_result.inlet_stream_condition.temperature_kelvin
Expand Down Expand Up @@ -713,13 +706,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
pressure_before_choking=TimeSeriesFloat(
timesteps=model.timesteps,
values=stage_result.outlet_stream_condition.pressure_before_choking
if stage_result.outlet_stream_condition.pressure_before_choking is not None
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
temperature_kelvin=TimeSeriesFloat(
timesteps=model.timesteps,
values=stage_result.outlet_stream_condition.temperature_kelvin
Expand Down Expand Up @@ -859,13 +845,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
pressure_before_choking=TimeSeriesFloat(
timesteps=model.timesteps,
values=model.inlet_stream_condition.pressure_before_choking
if model.inlet_stream_condition.pressure_before_choking is not None
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
temperature_kelvin=TimeSeriesFloat(
timesteps=model.timesteps,
values=model.inlet_stream_condition.temperature_kelvin
Expand Down Expand Up @@ -934,13 +913,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
pressure_before_choking=TimeSeriesFloat(
timesteps=model.timesteps,
values=model.outlet_stream_condition.pressure_before_choking
if model.outlet_stream_condition.pressure_before_choking is not None
else [math.nan] * len(model.timesteps),
unit=Unit.BARA,
),
temperature_kelvin=TimeSeriesFloat(
timesteps=model.timesteps,
values=model.outlet_stream_condition.temperature_kelvin
Expand Down Expand Up @@ -1255,7 +1227,6 @@ def get_asset_result(graph_result: GraphResult) -> libecalc.presentation.json_re
consumer_result.component_result.recirculation_loss, regularity=regularity
),
rate_exceeds_maximum=consumer_result.component_result.rate_exceeds_maximum,
outlet_pressure_before_choking=consumer_result.component_result.outlet_pressure_before_choking,
timesteps=consumer_result.component_result.timesteps,
id=consumer_result.component_result.id,
is_valid=consumer_result.component_result.is_valid,
Expand Down
2 changes: 0 additions & 2 deletions src/libecalc/presentation/json_result/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ class CompressorResult(EquipmentResultBase):
componentType: Literal[ComponentType.COMPRESSOR]
recirculation_loss: TimeSeriesRate
rate_exceeds_maximum: TimeSeriesBoolean
outlet_pressure_before_choking: TimeSeriesFloat

streams: Optional[List[TimeSeriesStreamConditions]] # Optional because only in v2

Expand Down Expand Up @@ -186,7 +185,6 @@ class CompressorStreamConditionResult(TabularTimeSeries):
kappa: TimeSeriesFloat
density_kg_per_m3: TimeSeriesFloat
pressure: TimeSeriesFloat
pressure_before_choking: TimeSeriesFloat
temperature_kelvin: TimeSeriesFloat
z: TimeSeriesFloat

Expand Down
Loading

0 comments on commit 02f9099

Please sign in to comment.