Coverage for backend/idaes_service/solver/custom/heat_exchanger_1d_wrapper.py: 20%

14 statements  

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

1from .custom_heat_exchanger_1d import CustomHeatExchanger1D 

2from idaes.models.unit_models.heat_exchanger import HeatExchangerFlowPattern 

3 

4# Map frontend string values to IDAES enums 

5FLOW_TYPE_MAP = { 

6 "countercurrent": HeatExchangerFlowPattern.countercurrent, 

7 "cocurrent": HeatExchangerFlowPattern.cocurrent, 

8} 

9 

10def HeatExchanger1DWrapper(**kwargs): 

11 """ 

12 Wrapper for CustomHeatExchanger1D that handles string-to-enum conversion 

13 and provides default values for required parameters, defaulting to collocation. 

14 """ 

15 # Convert flow_type string to enum 

16 flow_type = kwargs.pop('flow_type', None) 

17 if flow_type is None: 

18 flow_type = "countercurrent" 

19 

20 if isinstance(flow_type, str): 

21 if flow_type.lower() in FLOW_TYPE_MAP: 

22 flow_type_enum = FLOW_TYPE_MAP[flow_type.lower()] 

23 else: 

24 raise ValueError(f"Unknown flow_type: {flow_type}. Must be one of: {list(FLOW_TYPE_MAP.keys())}") 

25 else: 

26 flow_type_enum = flow_type 

27 

28 kwargs['flow_type'] = flow_type_enum 

29 

30 # Return the heat exchanger with fixed parameters 

31 return CustomHeatExchanger1D(**kwargs)