Skip to content

Commit 639e7e8

Browse files
committed
fix: ensure shaft speed is set correctly after root-finding
1 parent db48551 commit 639e7e8

4 files changed

Lines changed: 406 additions & 404 deletions

File tree

src/libecalc/domain/process/compressor/core/train/compressor_train_common_shaft.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ def _calculate_train_result_given_speed_at_stone_wall(
453453
func=lambda x: _calculate_train_result_given_speed_at_stone_wall(speed=x).discharge_pressure
454454
- target_discharge_pressure,
455455
)
456+
self.shaft.set_speed(result_speed)
456457
compressor_train_result = _calculate_train_result_given_speed_at_stone_wall(speed=result_speed)
457458

458459
rate_to_return = compressor_train_result.mass_rate_kg_per_hour * (1 - RATE_CALCULATION_TOLERANCE)
@@ -1024,6 +1025,7 @@ def _calculate_compressor_train(_speed: float) -> CompressorTrainResultSingleTim
10241025

10251026
if not train_result_for_maximum_speed.within_capacity:
10261027
# will not find valid result - the rate is above maximum rate, return invalid results at maximum speed
1028+
self.shaft.set_speed(maximum_speed)
10271029
return maximum_speed
10281030
if not train_result_for_minimum_speed.within_capacity:
10291031
# rate is above maximum rate for minimum speed. Find the lowest minimum speed which gives a valid result
@@ -1048,15 +1050,17 @@ def _calculate_compressor_train(_speed: float) -> CompressorTrainResultSingleTim
10481050
upper_bound=maximum_speed,
10491051
func=lambda x: _calculate_compressor_train(_speed=x).discharge_pressure - target_discharge_pressure,
10501052
)
1051-
1053+
self.shaft.set_speed(speed)
10521054
return speed
10531055

10541056
# Solution 2, target pressure is too low:
10551057
if (
10561058
constraints.discharge_pressure is not None
10571059
and constraints.discharge_pressure < train_result_for_minimum_speed.discharge_pressure
10581060
):
1061+
self.shaft.set_speed(minimum_speed)
10591062
return minimum_speed
10601063

10611064
# Solution 3, target discharge pressure is too high
1065+
self.shaft.set_speed(maximum_speed)
10621066
return maximum_speed

src/libecalc/domain/process/compressor/core/train/compressor_train_common_shaft_multiple_streams_and_pressures.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,13 +589,12 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(
589589
stream_rates=std_rates_last_part,
590590
)
591591

592-
compressor_train_first_part.find_fixed_shaft_speed_given_constraints(
592+
# Get the speed found for the first part - will be used to compare with the last part
593+
shaft_speed_first_part = compressor_train_first_part.find_fixed_shaft_speed_given_constraints(
593594
constraints=constraints_first_part,
594595
lower_bound_for_speed=self.minimum_speed, # Only search for a solution within the bounds of the
595596
upper_bound_for_speed=self.maximum_speed, # original, complete compressor train
596597
)
597-
# Get the speed found for the first part - will be used to compare with the last part
598-
shaft_speed_first_part = compressor_train_first_part.shaft.get_speed()
599598

600599
if math.isclose(shaft_speed_first_part, self.minimum_speed, rel_tol=EPSILON):
601600
compressor_train_results_first_part_with_optimal_speed_result = (
@@ -625,14 +624,13 @@ def find_and_calculate_for_compressor_train_with_two_pressure_requirements(
625624
assert isinstance(compressor_train_last_part._fluid_model, list) # for mypy
626625
compressor_train_last_part._fluid_model[0] = compressor_train_last_part.streams[0].fluid_model
627626

628-
compressor_train_last_part.find_fixed_shaft_speed_given_constraints(
627+
shaft_speed_last_part = compressor_train_last_part.find_fixed_shaft_speed_given_constraints(
629628
constraints=constraints_last_part,
630629
lower_bound_for_speed=self.minimum_speed,
631630
upper_bound_for_speed=self.maximum_speed,
632631
)
633-
# Get the speed found for the last part - will be used to compare with the first part
634-
shaft_speed_last_part = compressor_train_last_part.shaft.get_speed()
635632

633+
# Get the speed found for the last part - will be used to compare with the first part
636634
if math.isclose(shaft_speed_last_part, self.minimum_speed, rel_tol=EPSILON):
637635
compressor_train_results_last_part_with_optimal_speed_result = (
638636
compressor_train_last_part.evaluate_with_pressure_control_given_constraints(

tests/libecalc/core/models/compressor_modelling/test_compressor_train_multiple_streams.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def test_evaluate_variable_speed_compressor_train_multiple_streams_and_pressures
514514

515515
result_first_stage = result.stage_results[0]
516516
result_last_stage = result.stage_results[1]
517-
assert result_first_stage.speed == pytest.approx([10825.72, 11100.26, 11313.19], abs=0.01)
517+
assert result_first_stage.speed == pytest.approx([10825.77, 11100.32, 11313.25], abs=0.01)
518518
assert result_first_stage.outlet_stream_condition.pressure == pytest.approx([30.0, 30.0, 30.0], abs=0.01)
519519
assert result_last_stage.asv_recirculation_loss_mw == pytest.approx([4.22, 4.39, 4.46], abs=0.01)
520520
assert result_first_stage.speed == result_last_stage.speed

0 commit comments

Comments
 (0)