Coverage for backend/idaes_service/solver/custom/valve_wrapper.py: 85%

19 statements  

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

1from .custom_valve import Valve as CustomValve, ValveFunctionType 

2from idaes.models.unit_models.pressure_changer import ThermodynamicAssumption 

3from .custom_pressure_changer import CustomPressureChanger 

4 

5VALVE_FUNCTION_MAP = { 

6 "linear": ValveFunctionType.linear, 

7 "quick_opening": ValveFunctionType.quick_opening, 

8 "equal_percentage": ValveFunctionType.equal_percentage, 

9} 

10 

11def ValveWrapper(**kwargs): 

12 enable_coefficients = kwargs.pop('enable_coefficients', False) 

13 valve_function = kwargs.pop('valve_function', None) 

14 

15 # Set default valve function if none provided 

16 if valve_function is None: 

17 valve_function = "linear" 

18 

19 # Check if valve_function is a string and map it to the corresponding callback 

20 if isinstance(valve_function, str): 20 ↛ 27line 20 didn't jump to line 27 because the condition on line 20 was always true

21 if valve_function in VALVE_FUNCTION_MAP: 21 ↛ 24line 21 didn't jump to line 24 because the condition on line 21 was always true

22 valve_function_callback = VALVE_FUNCTION_MAP[valve_function] 

23 else: 

24 raise ValueError(f"Unknown valve_function: {valve_function}") 

25 else: 

26 # just in case it is already a enum or a callback 

27 valve_function_callback = valve_function 

28 

29 if enable_coefficients: 

30 # use the custom valve model in full 

31 return CustomValve(valve_function_callback=valve_function_callback, **kwargs) 

32 else: 

33 # add thermodynamic_assumption kwarg to 

34 # the PressureChanger model 

35 kwargs['thermodynamic_assumption'] = ThermodynamicAssumption.adiabatic 

36 kwargs['compressor'] = False 

37 # just use a pressure changer 

38 return CustomPressureChanger(**kwargs)