Coverage for backend/ahuora-builder/src/ahuora_builder/custom/custom_heater.py: 94%

26 statements  

« prev     ^ index     » next       coverage.py v7.10.7, created at 2026-07-22 05:22 +0000

1from idaes.core import declare_process_block_class 

2from idaes.models.unit_models.heater import HeaterData 

3from .add_initial_dynamics import add_initial_dynamics 

4from .inverted import add_inverted, disable_inverted, enable_inverted 

5import pyomo.environ as pyo 

6 

7@declare_process_block_class("DynamicHeater") 

8class DynamicHeaterData(HeaterData): 

9 """ 

10 Dynamic Heater unit model class. 

11 This extends the Heater class to include reference variables for initial holdup and initial accumulation.  

12 Which makes it easier for us to set initial conditions in the frontend. 

13 """ 

14 

15 def build(self,*args, **kwargs): 

16 """ 

17 Build method for the DynamicHeaterData class. 

18 This method initializes the control volume and sets up the model. 

19 """ 

20 super().build(*args, **kwargs) 

21 

22 if hasattr(self,"deltaP"): 

23 # else has_pressure_change is false 

24 add_inverted(self, "deltaP") 

25 

26 add_initial_dynamics(self) 

27 

28 def initialize_build( 

29 self,*args,**kwargs, 

30 ): 

31 """ 

32 Initialize method for the DynamicHeaterData class. 

33 This method initializes the control volume and sets up the model. 

34 """ 

35 temporarily_fixed_delta_p = [] 

36 if hasattr(self,"deltaP"): 

37 temporarily_fixed_delta_p = disable_inverted(self, "deltaP") 

38 

39 try: 

40 super().initialize_build(*args, **kwargs) 

41 finally: 

42 if hasattr(self,"deltaP"): 

43 enable_inverted(self, "deltaP", temporarily_fixed_delta_p) 

44 

45 def diagnose(self): 

46 problems = [] 

47 inlet_flow = pyo.value(self.control_volume.properties_in[0].flow_mol) or 0 

48 

49 if inlet_flow <= 0.0001: 49 ↛ 50line 49 didn't jump to line 50 because the condition on line 49 was never true

50 problems.append( 

51 ( 

52 self.control_volume.properties_in[0].flow_mol, 

53 f"Inlet flow ({inlet_flow:.2f} mol/s) is very low." 

54 ) 

55 ) 

56 return problems