Skip to content

Commit

Permalink
Converted alfacase to case to use autoloaders in some parts
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon committed Dec 15, 2021
1 parent cab1837 commit 6cf9c9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 44 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ History
0.12.0 (unreleased)
===================

* **Breaking Change**: Change in ``AnnulusDescription`` to support different types of annulus equipments. Now ``AnnulusDescription``` has an attribute ``AnnulusEquipmentDescription``, which holds a dict that can contain multiple different equipment types, for which the current available options are:

- ``LeakEquipmentDescription``;
- ``GasLiftValveEquipmentDescription``;

* Removed *force per square velocity* unit definition, it is present in the new barril version.


Expand Down
19 changes: 2 additions & 17 deletions src/alfasim_sdk/_internal/alfacase/alfacase_to_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def load_dict_of_instance(alfacase_content: DescriptionDocument, class_: Type[T]

@lru_cache(maxsize=None)
def get_dict_of_instance_loader(*, class_: type) -> Callable:
print('here')
return partial(load_dict_of_instance, class_=class_)


Expand Down Expand Up @@ -1737,22 +1736,8 @@ def load_wall_description(
def load_equipment_description(
document: DescriptionDocument,
) -> case_description.EquipmentDescription:
alfacase_to_case_description = {
"mass_sources": load_mass_source_equipment_description,
"pigs": load_pig_equipment_description,
"pumps": load_pump_equipment_description,
"valves": load_valve_equipment_description,
"reservoir_inflows": load_reservoir_inflow_equipment_description,
"heat_sources": load_heat_source_equipment_description,
"compressors": load_compressor_equipment_description,
"leaks": get_dict_of_instance_loader(class_=case_description.LeakEquipmentDescription),
}
return _generate_description(
document,
alfacase_to_case_description,
case_description.EquipmentDescription,
)

return load_instance(document, case_description.EquipmentDescription)


def load_x_and_y_description(
document: DescriptionDocument,
Expand Down
38 changes: 11 additions & 27 deletions src/alfasim_sdk/_internal/alfacase/case_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,8 @@ class SpeedCurveDescription:
"""

time: Array = attr.ib(default=Array([0], "s"), validator=instance_of(Array))
speed: Array = attr.ib(default=Array([500], "rpm"), validator=instance_of(Array))
time = attrib_array(Array([0], "s"))
speed = attrib_array(Array([500], "rpm"))


# fmt: off
Expand All @@ -540,26 +540,18 @@ class TablePumpDescription:
.. include:: /alfacase_definitions/list_of_unit_for_volume_fraction.txt
.. include:: /alfacase_definitions/list_of_unit_for_pressure.txt
"""
speeds: Array = attr.ib(
default=Array([0.0] * 12 + [400.0] * 12 + [600.0] * 12, 'rpm'), validator=instance_of(Array)
)
void_fractions: Array = attr.ib(
default=Array(([0.0] * 6 + [0.1] * 6) * 3, '-'), validator=instance_of(Array)
)
flow_rates: Array = attr.ib(
default=Array([0.0, 0.05, 0.1, 0.15, 0.2, 0.3] * 6, 'm3/s'), validator=instance_of(Array)
)
speeds = attrib_array(Array([0.0] * 12 + [400.0] * 12 + [600.0] * 12, 'rpm'))
void_fractions = attrib_array(Array(([0.0] * 6 + [0.1] * 6) * 3, '-'))
flow_rates = attrib_array(Array([0.0, 0.05, 0.1, 0.15, 0.2, 0.3] * 6, 'm3/s'))

pressure_boosts: Array = attr.ib(
default=Array(
pressure_boosts = attrib_array(Array(
[0.0] * 12
+[
12.0, 10.0, 9.0, 7.5, 5.0, 0.0, 10.0, 9.0, 8.0, 6.0, 3.5, 0.0,
14.0, 12.0, 10.0, 8.0, 5.5, 0.0, 13.5, 11.2, 9.5, 7.6, 5.2, 0.0,
],
'bar',
),
validator=instance_of(Array),
)
)

def __attrs_post_init__(self):
Expand Down Expand Up @@ -613,18 +605,10 @@ class CompressorPressureTableDescription:
.. include:: /alfacase_definitions/list_of_unit_for_dimensionless.txt
"""

speed_entries: Array = attr.ib(
default=Array([0], "rpm"), validator=instance_of(Array)
)
corrected_mass_flow_rate_entries: Array = attr.ib(
default=Array([0], "kg/s"), validator=instance_of(Array)
)
pressure_ratio_table: Array = attr.ib(
default=Array([1.0], "-"), validator=instance_of(Array)
)
isentropic_efficiency_table: Array = attr.ib(
default=Array([1.0], "-"), validator=instance_of(Array)
)
speed_entries = attrib_array(Array([0], "rpm"))
corrected_mass_flow_rate_entries = attrib_array(Array([0], "kg/s"))
pressure_ratio_table = attrib_array(Array([1.0], "-"))
isentropic_efficiency_table = attrib_array(Array([1.0], "-"))

def __attrs_post_init__(self):
expected_length = len(self.speed_entries)
Expand Down

0 comments on commit 6cf9c9a

Please sign in to comment.