Skip to content

Commit 7627831

Browse files
committed
Add torques field to TablePumpDescription for PCP pump support
Added optional 'torques' array field to TablePumpDescription class to support PCP (Progressive Cavity Pump) pump models. Changes: - Add torques field to TablePumpDescription with validation logic allowing either empty or matching array length - Update TablePumpDescription schema definition - Update documentation in TablePumpDescription.txt - Update test fixtures for schema and docstring generation - Add documentation reference for torque units - Update CHANGELOG.rst ASIM-6417
1 parent 3913e94 commit 7627831

File tree

9 files changed

+52
-2
lines changed

9 files changed

+52
-2
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88

99
* Types are now exported and can be verified by type-checkers such as ``mypy``.
1010
* Add ``progressive_cavity_pump`` as a new pump type option in ``PumpType`` enum.
11+
* Add ``torques`` field to ``TablePumpDescription`` to support PCP (Progressive Cavity Pump) pump models.
1112

1213

1314
1.3.0 (2025-10-07)

docs/source/alfacase_definitions/TablePumpDescription.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
heads: \ :class:`Array <barril.units.Array>`\ = Array(length, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 122.32415902140673, 101.9367991845056, 91.74311926605505, 76.4525993883792, 50.9683995922528, 0.0, 101.9367991845056, 91.74311926605505, 81.54943934760449, 61.162079510703364, 35.67787971457696, 0.0, 142.71151885830784, 122.32415902140673, 101.9367991845056, 81.54943934760449, 56.065239551478086, 0.0, 137.61467889908258, 114.16921508664628, 96.83995922528032, 77.47196738022426, 53.00713557594292, 0.0], m)
1313
efficiencies: \ :class:`Array <barril.units.Array>`\ = Array(dimensionless, [0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18, 0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18, 0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18], %)
1414
powers: \ :class:`Array <barril.units.Array>`\ = Array(power, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 160714.29, 160714.29, 176086.96, 187500.0, 173076.92, 0.0, 160714.29, 160714.29, 173913.04, 166666.67, 134615.38, 0.0, 192857.14, 192857.14, 195652.17, 200000.0, 190384.62, 0.0, 200000.0, 200000.0, 206521.74, 211111.11, 200000.0, 0.0], W)
15+
torques: \ :class:`Array <barril.units.Array>`\ = Array(moment of force, [], N.m)
1516

1617
.. tab:: Schema
1718

@@ -38,3 +39,6 @@
3839
powers: # optional
3940
values: [number]
4041
unit: string
42+
torques: # optional
43+
values: [number]
44+
unit: string

src/alfasim_sdk/_internal/alfacase/alfacase_to_case.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,6 +1437,7 @@ def load_table_pump_description(
14371437
"heads": get_array_loader(from_unit="m"),
14381438
"efficiencies": get_array_loader(from_unit="%"),
14391439
"powers": get_array_loader(from_unit="W"),
1440+
"torques": get_array_loader(from_unit="N.m"),
14401441
}
14411442
case_values = to_case_values(document, alfacase_to_case_description)
14421443
item_description = case_description.TablePumpDescription(**case_values)

src/alfasim_sdk/_internal/alfacase/case_description.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,16 @@ class TablePumpDescription:
690690
Pump power values. There a relation between other pump variables and power. In SI units:
691691
BHP [W] = P [Pa] * Q [m^3/s] / eff [%]
692692
693+
:ivar torques:
694+
Pump torque values. Used for PCP pumps.
695+
693696
.. include:: /alfacase_definitions/TablePumpDescription.txt
694697
695698
.. include:: /alfacase_definitions/list_of_unit_for_angle_per_time.txt
696699
.. include:: /alfacase_definitions/list_of_unit_for_volume_flow_rate.txt
697700
.. include:: /alfacase_definitions/list_of_unit_for_volume_fraction.txt
698701
.. include:: /alfacase_definitions/list_of_unit_for_pressure.txt
702+
.. include:: /alfacase_definitions/list_of_unit_for_torque.txt
699703
"""
700704
speeds: Array = attrib_array(Array("angle per time", [0.0] * 12 + [400.0] * 12 + [600.0] * 12, 'rpm'))
701705
void_fractions: Array = attrib_array(Array("volume fraction", ([0.0] * 6 + [0.1] * 6) * 3, '-'))
@@ -741,12 +745,15 @@ class TablePumpDescription:
741745
)
742746
)
743747

748+
torques: Array = attrib_array(Array([], 'N.m'))
744749

745750

746751
def __attrs_post_init__(self):
747752
expected_length = len(self.speeds)
748753
all_fields = list(attr.fields_dict(self.__class__).keys())
749-
if any(len(getattr(self, field)) != expected_length for field in all_fields):
754+
# torques is optional, so it can be empty or have the expected length
755+
fields_to_check = [field for field in all_fields if field != 'torques']
756+
if any(len(getattr(self, field)) != expected_length for field in fields_to_check):
750757
msg = (
751758
f"speeds, void_fractions, flow_rates, pressure_boosts, heads, efficiencies and powers must have the "
752759
f"same size, got:\n"
@@ -759,6 +766,16 @@ def __attrs_post_init__(self):
759766
f" - {len(self.powers)} items for powers\n"
760767
)
761768
raise ValueError(msg)
769+
770+
# Validate torques separately: if not empty, it must have the expected length
771+
torques_length = len(self.torques)
772+
if torques_length != 0 and torques_length != expected_length:
773+
msg = (
774+
f"torques must be either empty or have the same size as other fields, got:\n"
775+
f" - {expected_length} items expected\n"
776+
f" - {torques_length} items for torques\n"
777+
)
778+
raise ValueError(msg)
762779

763780
# fmt: on
764781

src/alfasim_sdk/_internal/alfacase/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,7 @@
757757
Optional("heads"): Map({"values": Seq(Float()), "unit": Str()}),
758758
Optional("efficiencies"): Map({"values": Seq(Float()), "unit": Str()}),
759759
Optional("powers"): Map({"values": Seq(Float()), "unit": Str()}),
760+
Optional("torques"): Map({"values": Seq(Float()), "unit": Str()}),
760761
}
761762
)
762763
temperatures_container_description_schema = Map(
@@ -1238,4 +1239,4 @@
12381239
Optional("walls"): Seq(wall_description_schema),
12391240
}
12401241
)
1241-
# [[[end]]] (sum: R2T4gbe3ct)
1242+
# [[[end]]] (sum: pPP2WuWNdo)

tests/alfacase/test_case_description.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ def test_table_pump_description_length():
100100
efficiencies=Array([1], "-"),
101101
powers=Array([1], "W"),
102102
)
103+
104+
# Test torques validation separately
105+
expected_msg_torques = dedent(
106+
"""\
107+
torques must be either empty or have the same size as other fields, got:
108+
- 2 items expected
109+
- 1 items for torques
110+
"""
111+
)
112+
with pytest.raises(ValueError, match=re.escape(expected_msg_torques)):
113+
case_description.TablePumpDescription(
114+
speeds=Array([1, 2], "rpm"),
115+
void_fractions=Array([1, 2], "-"),
116+
flow_rates=Array([1, 2], "m3/s"),
117+
pressure_boosts=Array([1, 2], "bar"),
118+
heads=Array([1, 2], "m"),
119+
efficiencies=Array([1, 2], "-"),
120+
powers=Array([1, 2], "W"),
121+
torques=Array([1], "N.m"),
122+
)
103123

104124
# Check if the defaults values works well
105125
case_description.TablePumpDescription()

tests/alfacase/test_generate_case_description_docstring/test_generate_case_description_docstring_TablePumpDescription_.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
heads: \ :class:`Array <barril.units.Array>`\ = Array(length, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 122.32415902140673, 101.9367991845056, 91.74311926605505, 76.4525993883792, 50.9683995922528, 0.0, 101.9367991845056, 91.74311926605505, 81.54943934760449, 61.162079510703364, 35.67787971457696, 0.0, 142.71151885830784, 122.32415902140673, 101.9367991845056, 81.54943934760449, 56.065239551478086, 0.0, 137.61467889908258, 114.16921508664628, 96.83995922528032, 77.47196738022426, 53.00713557594292, 0.0], m)
1313
efficiencies: \ :class:`Array <barril.units.Array>`\ = Array(dimensionless, [0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18, 0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18, 0.0, 0.311, 0.511, 0.6, 0.578, 0.2, 0.0, 0.28, 0.46, 0.54, 0.52, 0.18], %)
1414
powers: \ :class:`Array <barril.units.Array>`\ = Array(power, [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 160714.29, 160714.29, 176086.96, 187500.0, 173076.92, 0.0, 160714.29, 160714.29, 173913.04, 166666.67, 134615.38, 0.0, 192857.14, 192857.14, 195652.17, 200000.0, 190384.62, 0.0, 200000.0, 200000.0, 206521.74, 211111.11, 200000.0, 0.0], W)
15+
torques: \ :class:`Array <barril.units.Array>`\ = Array(moment of force, [], N.m)
1516

1617
.. tab:: Schema
1718

@@ -38,3 +39,6 @@
3839
powers: # optional
3940
values: [number]
4041
unit: string
42+
torques: # optional
43+
values: [number]
44+
unit: string

tests/alfacase/test_generate_case_schema/test_generate_schema_for_all_cases.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ table_pump_description_schema = Map(
790790
Optional("heads"): Map({"values": Seq(Float()), "unit": Str()}),
791791
Optional("efficiencies"): Map({"values": Seq(Float()), "unit": Str()}),
792792
Optional("powers"): Map({"values": Seq(Float()), "unit": Str()}),
793+
Optional("torques"): Map({"values": Seq(Float()), "unit": Str()}),
793794
}
794795
)
795796

tests/common_testing/alfasim_sdk_common_testing/filled_case_descriptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@
426426
heads=Array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], "m") * 1.0e5 / (9.8 * 1000.0),
427427
efficiencies=Array([0.01, 0.2, 0.4, 0.2, 0.009, 0.18, 0.36, 0.18], "-"),
428428
powers=Array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0], "W"),
429+
torques=Array([0.0, 0.0, 0.0, 0.0, 19.1, 22.9, 26.7, 30.6], "N.m"),
429430
)
430431
SURGE_VOLUME_OPTIONS_DESCRIPTION = case_description.SurgeVolumeOptionsDescription(
431432
time_mode=constants.SurgeVolumeTimeMode.UserDefined,

0 commit comments

Comments
 (0)