Skip to content

Commit

Permalink
chore: make sure that pressure calculation tolerances are the same at…
Browse files Browse the repository at this point in the history
… different places in the code (#577)

chore: update snapshots

ECALC-1533
  • Loading branch information
olelod authored Aug 26, 2024
1 parent c4b1a2d commit 55bf4fc
Show file tree
Hide file tree
Showing 5 changed files with 2,022 additions and 2,023 deletions.
5 changes: 2 additions & 3 deletions src/libecalc/core/models/compressor/train/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
calculate_outlet_pressure_campbell,
)

OUTLET_PRESSURE_CONVERGENCE_TOLERANCE = 1e-2
PRESSURE_CALCULATION_TOLERANCE = 1e-3
POWER_CALCULATION_TOLERANCE = 1e-3
RATE_CALCULATION_TOLERANCE = 1e-3
Expand Down Expand Up @@ -122,7 +121,7 @@ def calculate_outlet_pressure_and_stream(

diff = abs(outlet_pressure_previous - outlet_pressure_this_stage_bara) / outlet_pressure_this_stage_bara

converged = diff < OUTLET_PRESSURE_CONVERGENCE_TOLERANCE
converged = diff < PRESSURE_CALCULATION_TOLERANCE

i += 1

Expand All @@ -137,7 +136,7 @@ def calculate_outlet_pressure_and_stream(
f" molar_mass_kg_per_mol: {inlet_stream.molar_mass_kg_per_mol}."
f" inlet_temperature_kelvin: {inlet_stream.temperature_kelvin}."
f" inlet_pressure_bara: {inlet_stream.pressure_bara}."
f" Final diff between target and result was {diff}, while expected convergence diff criteria is set to diff lower than {OUTLET_PRESSURE_CONVERGENCE_TOLERANCE}"
f" Final diff between target and result was {diff}, while expected convergence diff criteria is set to diff lower than {PRESSURE_CALCULATION_TOLERANCE}"
f" NOTE! We will use as the closest result we got for target for further calculations."
" This should normally not happen. Please contact eCalc support."
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def test_evaluate_rate_ps_pd_downstream_choke_pressure_control(
)
np.testing.assert_almost_equal(
result.outlet_stream.pressure,
[300.0, 304.948, 300.0, 216.268],
decimal=3,
[300.0, 305.0, 300.0, 216.9],
decimal=1,
)
assert list(result.outlet_stream.pressure_before_choking) == pytest.approx(
[304.9384, 304.9384, 367.546, 216.268], rel=0.0001
np.testing.assert_almost_equal(
result.outlet_stream.pressure_before_choking, [305.0, 305.0, 367.7, 216.9], decimal=1
)
assert result.inlet_stream.pressure == pytest.approx(suction_pressures)
assert result.power == pytest.approx([14.54498, 14.54498, 16.05248, 14.6864], rel=0.0001)
Expand Down Expand Up @@ -156,19 +156,19 @@ def test_evaluate_rate_ps_pd_downstream_choke_pressure_control_and_maximum_disch
)
np.testing.assert_almost_equal(
result.outlet_stream.pressure,
[300.0, 304.948, 300.0, 216.268],
decimal=3,
[300.0, 305.0, 300.0, 216.9],
decimal=1,
)
np.testing.assert_almost_equal(
result.outlet_stream.pressure_before_choking,
[304.948, 304.948, 350.0, 216.268],
decimal=3,
[305.0, 305.0, 350.0, 216.9],
decimal=1,
)

np.testing.assert_almost_equal(result.inlet_stream.pressure, [80.0, 80.0, 75.80998, 80.0], decimal=5)
np.testing.assert_almost_equal(result.inlet_stream.pressure, [80.0, 80.0, 75.8, 80.0], decimal=1)
np.testing.assert_almost_equal(
result.power,
[14.544982226011612, 14.544982226011612, 15.185817372522788, 14.686402097735332],
[14.545, 14.545, 15.178, 14.686],
decimal=3,
)

Expand Down Expand Up @@ -218,13 +218,13 @@ def test_evaluate_rate_ps_pd_asv_rate_control(self, single_speed_compressor_trai
)
np.testing.assert_almost_equal(
result.outlet_stream.pressure,
[166.96, 300.00, 304.95, 300.00, 219.73],
decimal=2,
[167.0, 300.00, 305.0, 300.00, 220.4],
decimal=1,
)
np.testing.assert_almost_equal(
result.outlet_stream.pressure_before_choking,
[166.96, 300.00, 304.95, 300.00, 219.73],
decimal=2,
[167.0, 300.00, 305.0, 300.00, 220.4],
decimal=1,
)

assert result.failure_status == [
Expand All @@ -248,8 +248,8 @@ def test_evaluate_rate_ps_pd_asv_pressure_control(

np.testing.assert_almost_equal(
result.outlet_stream.pressure,
[300.00, 310.00, 292.67, 240.38, 231.92],
decimal=2,
[300.0, 310.0, 292.5, 240.4, 231.9],
decimal=1,
)
assert result.failure_status == [
CompressorTrainCommonShaftFailureStatus.NO_FAILURE,
Expand All @@ -270,8 +270,8 @@ def test_evaluate_rate_ps_pd_common_asv(self, single_speed_compressor_train_comm

np.testing.assert_almost_equal(
result.outlet_stream.pressure,
[238.25, 270.0, 277.23, 219.7185],
decimal=2,
[238.2, 270.0, 277.2, 220.4],
decimal=1,
)

assert result.failure_status == [
Expand Down Expand Up @@ -302,10 +302,10 @@ def test_rate_below_minimum_chart_rate(self, single_speed_compressor_train_stage
assert result.inlet_actual_rate_m3_per_hour == pytest.approx(1148.7960837804026)
assert result.inlet_actual_rate_asv_corrected_m3_per_hour == 1735.0
assert result.chart_area_flag == ChartAreaFlag.BELOW_MINIMUM_FLOW_RATE
assert result.power_megawatt == pytest.approx(4.832668696214711)
assert result.outlet_stream.pressure_bara == pytest.approx(173.36907, rel=0.00001)
assert result.outlet_stream.temperature_kelvin == pytest.approx(374.70675, rel=0.00001)
assert result.outlet_stream.density_kg_per_m3 == pytest.approx(117.13761, rel=0.00001)
assert result.power_megawatt == pytest.approx(4.83, rel=0.001)
assert result.outlet_stream.pressure_bara == pytest.approx(173.36, rel=0.001)
assert result.outlet_stream.temperature_kelvin == pytest.approx(374.71, rel=0.001)
assert result.outlet_stream.density_kg_per_m3 == pytest.approx(117.14, rel=0.001)

def test_rate_within_chart_curve_range(self, single_speed_compressor_train_stage, medium_fluid):
mass_rate_kg_per_hour = 200000.0
Expand Down Expand Up @@ -350,10 +350,10 @@ def test_calculate_single_speed_train(single_speed_compressor_train):
)

# Stability tests
assert result.power_megawatt == pytest.approx(14.5148, rel=0.00001)
assert result.discharge_pressure == pytest.approx(304.1049, rel=0.00001)
assert result.stage_results[0].outlet_stream.pressure_bara == pytest.approx(140.1095, rel=0.00001)
assert result.stage_results[1].inlet_stream.pressure_bara == pytest.approx(140.1095, rel=0.00001)
assert result.power_megawatt == pytest.approx(14.51, rel=0.001)
assert result.discharge_pressure == pytest.approx(304.10, rel=0.001)
assert result.stage_results[0].outlet_stream.pressure_bara == pytest.approx(140.11, rel=0.001)
assert result.stage_results[1].inlet_stream.pressure_bara == pytest.approx(140.11, rel=0.001)
assert result.stage_results[0].chart_area_flag == ChartAreaFlag.INTERNAL_POINT
assert result.stage_results[1].chart_area_flag == ChartAreaFlag.BELOW_MINIMUM_FLOW_RATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_get_maximum_standard_rate_max_speed_curve(

np.testing.assert_allclose(middle_of_max_speed_curve, 4396383, rtol=0.001)

np.testing.assert_allclose(left_end_of_max_speed_curve, 3164249, rtol=0.001)
np.testing.assert_allclose(left_end_of_max_speed_curve, 3154507, rtol=0.001)


@pytest.mark.slow
Expand Down
Loading

0 comments on commit 55bf4fc

Please sign in to comment.