Coverage for backend/ahuora-builder/src/ahuora_builder/properties_manager.py: 96%
23 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-03-26 20:57 +0000
1from ahuora_builder_types.id_types import PropertyValueId
2from pyomo.core.base.indexed_component import IndexedComponent
3class PropertyComponent:
4 def __init__(self, name: str, component : IndexedComponent, unknown_units=False):
5 """
6 Args:
7 - name (str): The name of the property component (for debugging purposes)
8 - component (Component): The Pyomo component; i.e., Expression, Var
9 - unknown_units (bool): If units are unknown, idaes_factory will do some
10 additional processing to determine the unit category.
11 - corresponding_constraint (Constraint | Var | None): The component
12 (Var or Constraint) that was fixed or activated to set the value of
13 this property. Given an id in the properties dictionary, this field
14 can be used to unfix or deactivate the corresponding constraint.
15 Defaults to None (allowed for properties that are not fixed).
16 """
17 self.name: str = name
18 self.component: IndexedComponent = component
19 self.unknown_units = unknown_units
20 self.corresponding_constraint : list[ScalarVar | ScalarConstraint] = None # TODO: Type
23class PropertiesManager:
24 """
25 The properties manager is responsible for keeping track of all the properties in the model that we have fixed.
26 This allows us to unfix/deactivate them as needed, for example when we want to initialise the model.
27 You should be able to access this from model.fs.properties_map, or from the FlowsheetManager.PropertiesManager after the flowsheet is loaded.
28 """
29 def __init__(self):
30 self.properties : dict[PropertyValueId,PropertyComponent] = {}
32 def add(self, id: PropertyValueId, indexed_component: IndexedComponent, name : str, unknown_units=False)-> IndexedComponent:
33 self.properties[id] = PropertyComponent(name, indexed_component, unknown_units)
35 def get(self, id: PropertyValueId):
36 return self.properties[id]
38 def get_component(self, id: PropertyValueId):
39 return self.get(id).component
41 def get_constraint(self, id: PropertyValueId):
42 return self.get(id).corresponding_constraint
44 def add_constraint(self, id: PropertyValueId, constraint):
45 # assumes the property has already been added
46 self.get(id).corresponding_constraint = constraint
48 def items(self):
49 return self.properties.items()