Coverage for backend/idaes_service/solver/properties_manager.py: 96%

23 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2025-11-06 23:27 +0000

1from common.models.idaes.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 = None # TODO: Type 

21 

22 

23class PropertiesManager: 

24 def __init__(self): 

25 self.properties : dict[PropertyValueId,PropertyComponent] = {} 

26 

27 def add(self, id: PropertyValueId, indexed_component: IndexedComponent, name : str, unknown_units=False)-> IndexedComponent: 

28 self.properties[id] = PropertyComponent(name, indexed_component, unknown_units) 

29 

30 def get(self, id: PropertyValueId): 

31 return self.properties[id] 

32 

33 def get_component(self, id: PropertyValueId): 

34 return self.get(id).component 

35 

36 def get_constraint(self, id: PropertyValueId): 

37 return self.get(id).corresponding_constraint 

38 

39 def add_constraint(self, id: PropertyValueId, constraint): 

40 # assumes the property has already been added 

41 self.get(id).corresponding_constraint = constraint 

42 

43 def items(self): 

44 return self.properties.items()