uf_resistance_models.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import torch
  2. import numpy as np
  3. # ===== 膜阻力上升模型 =====
  4. class ResistanceIncreaseModel(torch.nn.Module):
  5. def __init__(self):
  6. super().__init__()
  7. def forward(self, p, L_s):
  8. """
  9. 计算膜阻力上升量 ΔR
  10. """
  11. A = 128 * 40.0
  12. J = p.q_UF / A / 3600
  13. # 膜阻力上升模型(已缩放)
  14. dR = p.nuK * J * L_s
  15. return float(dR)
  16. # ===== 膜阻力下降模型 =====
  17. class ResistanceDecreaseModel(torch.nn.Module):
  18. def __init__(self):
  19. super().__init__()
  20. def forward(self, p, R0, R_end, L_h_start, L_h_next_start, t_bw_s):
  21. """
  22. 计算物理反冲洗污染去除比例(受反洗时间影响),最大可去除的可逆膜阻力(受过滤时间影响)
  23. """
  24. # 计算单次不可逆膜阻力(线性依赖于进水时间)
  25. # 周期起点和下次起点的理论阻力
  26. R_start = R0 + p.slope * (L_h_start ** p.power)
  27. R_next_start = R0 + p.slope * (L_h_next_start ** p.power)
  28. # 不可逆污染(反洗后残余增加量)
  29. irreversible_R = max(R_next_start - R_start, 0.0)
  30. # 本周期的总污染增长量
  31. total_increase = max(R_end - R_start, 0.0)
  32. # 可逆污染量 = 本周期总增长 - 不可逆残留
  33. reversible_R = max(total_increase - irreversible_R, 0.0)
  34. # 时间因子:反洗时间越长,效果越充分
  35. time_gain = 1.0 - np.exp(- (t_bw_s / p.tau_bw_s))
  36. # 实际去除的膜阻力(随机在可去除区间内,乘以时间因子)
  37. dR_bw = reversible_R * time_gain
  38. return float(np.clip(dR_bw, 0.0, reversible_R))
  39. # ===== 主程序 =====
  40. if __name__ == "__main__":
  41. model_fp = ResistanceIncreaseModel()
  42. model_bw = ResistanceDecreaseModel()
  43. torch.save(model_fp.state_dict(), "resistance_model_fp.pth")
  44. torch.save(model_bw.state_dict(), "resistance_model_bw.pth")
  45. print("模型已安全保存为 resistance_model_fp.pth、resistance_model_bw.pth")