mabuseif commited on
Commit
72815ba
·
verified ·
1 Parent(s): 10c760b

Upload heat_transfer.py

Browse files
Files changed (1) hide show
  1. utils/heat_transfer.py +18 -10
utils/heat_transfer.py CHANGED
@@ -475,8 +475,8 @@ class HeatTransferCalculations:
475
  return q
476
 
477
  def infiltration_latent_heat_transfer(self, flow_rate: Union[float, np.ndarray], delta_w: Union[float, np.ndarray],
478
- t_db: Union[float, np.ndarray], # Temp for density/hfg calc
479
- p_atm: Union[float, np.ndarray] = ATMOSPHERIC_PRESSURE) -> Union[float, np.ndarray]:
480
  """
481
  Calculate latent heat transfer due to infiltration or ventilation.
482
  Reference: ASHRAE Handbook—Fundamentals (2017), Chapter 18, Equation 18.6.
@@ -484,25 +484,33 @@ class HeatTransferCalculations:
484
  flow_rate: Air flow rate(s) in m³/s
485
  delta_w: Humidity ratio difference(s) in kg/kg
486
  t_db: Dry-bulb temperature(s) for air properties in °C
487
- p_atm: Atmospheric pressure(s) in Pa
 
488
  Returns:
489
  Latent heat transfer rate(s) in W
490
  """
491
- is_array = any(isinstance(arg, np.ndarray) for arg in [flow_rate, delta_w, t_db, p_atm])
492
  if is_array:
493
  flow_rate = np.asarray(flow_rate)
494
  delta_w = np.asarray(delta_w)
495
  t_db = np.asarray(t_db)
 
496
  p_atm = np.asarray(p_atm)
497
  if np.any(flow_rate < 0):
498
- raise ValueError("Flow rate cannot be negative")
 
 
499
  # Delta_w can be negative (humidification)
500
- elif flow_rate < 0:
501
- raise ValueError("Flow rate cannot be negative")
 
 
 
502
 
503
  # Calculate air density and latent heat
504
- rho = self.psychrometrics.density(t_db, w=0.008, p_atm=p_atm) # Approximate density
505
- h_fg = self.psychrometrics.latent_heat_of_vaporization(t_db) # J/kg
 
506
 
507
  q = flow_rate * rho * h_fg * delta_w
508
  return q
@@ -601,7 +609,7 @@ if __name__ == "__main__":
601
 
602
  # Example infiltration calculation (Latent)
603
  delta_w_inf = 0.002 # kg/kg
604
- q_inf_lat = heat_transfer.infiltration_latent_heat_transfer(flow_rate, delta_w_inf, t_db_inf)
605
  logger.info(f"Infiltration latent heat transfer: {q_inf_lat:.2f} W")
606
 
607
  # Example Solar Calculation
 
475
  return q
476
 
477
  def infiltration_latent_heat_transfer(self, flow_rate: Union[float, np.ndarray], delta_w: Union[float, np.ndarray],
478
+ t_db: Union[float, np.ndarray], rh: Union[float, np.ndarray] = 40.0,
479
+ p_atm: Union[float, np.ndarray] = ATMOSPHERIC_PRESSURE) -> Union[float, np.ndarray]:
480
  """
481
  Calculate latent heat transfer due to infiltration or ventilation.
482
  Reference: ASHRAE Handbook—Fundamentals (2017), Chapter 18, Equation 18.6.
 
484
  flow_rate: Air flow rate(s) in m³/s
485
  delta_w: Humidity ratio difference(s) in kg/kg
486
  t_db: Dry-bulb temperature(s) for air properties in °C
487
+ rh: Relative humidity(ies) in % (0-100), default 40%
488
+ p_atm: Atmospheric pressure(s) in Pa, default 101325 Pa
489
  Returns:
490
  Latent heat transfer rate(s) in W
491
  """
492
+ is_array = any(isinstance(arg, np.ndarray) for arg in [flow_rate, delta_w, t_db, rh, p_atm])
493
  if is_array:
494
  flow_rate = np.asarray(flow_rate)
495
  delta_w = np.asarray(delta_w)
496
  t_db = np.asarray(t_db)
497
+ rh = np.asarray(rh)
498
  p_atm = np.asarray(p_atm)
499
  if np.any(flow_rate < 0):
500
+ raise ValueError("Flow rate cannot be negative")
501
+ if np.any(rh < 0) or np.any(rh > 100):
502
+ raise ValueError("Relative humidity must be between 0 and 100%")
503
  # Delta_w can be negative (humidification)
504
+ else:
505
+ if flow_rate < 0:
506
+ raise ValueError("Flow rate cannot be negative")
507
+ if not 0 <= rh <= 100:
508
+ raise ValueError("Relative humidity must be between 0 and 100%")
509
 
510
  # Calculate air density and latent heat
511
+ w = self.psychrometrics.humidity_ratio(t_db, rh, p_atm) # Calculate humidity ratio from rh
512
+ rho = self.psychrometrics.density(t_db, w, p_atm) # Use actual humidity ratio for density
513
+ h_fg = self.psychrometrics.latent_heat_of_vaporization(t_db) # J/kg
514
 
515
  q = flow_rate * rho * h_fg * delta_w
516
  return q
 
609
 
610
  # Example infiltration calculation (Latent)
611
  delta_w_inf = 0.002 # kg/kg
612
+ q_inf_lat = heat_transfer.infiltration_latent_heat_transfer(flow_rate, delta_w_inf, t_db_inf, rh_inf)
613
  logger.info(f"Infiltration latent heat transfer: {q_inf_lat:.2f} W")
614
 
615
  # Example Solar Calculation