Here is a well-structured README.md for your Heated Pipe System with Heat Loss project, including key visuals and explanations:
Heated Pipe System with Heat Loss#
A tutorial on regulating the outlet temperature of a 450-meter heat pipe near its boiling point, comparing PI, MPC, and Reinforcement Learning control strategies.
π Overview#
This project demonstrates how to regulate the outlet temperature of a 450-meter heat pipe loop for bacteria decontamination, ensuring:
Outlet temperature > 85Β°C
Inlet temperature < 95Β°C
Heating rate of 2Β°C/min
No steam formation
The system is modeled, simulated, and controlled using three approaches: PI control, Model Predictive Control (MPC), and Reinforcement Learning (RL).
π System Description#
Physical Setup#
A 450-meter circular pipe with continuous water flow.
A heater at the entrance provides constant power.
Water loses heat to the environment via convection.
The water returns to the heater, creating a closed loop.
Challenges#
Stair-like temperature behavior due to water recirculation.
Significant delay (~12 min) between input and output.
Coupling between inlet and outlet temperatures.
Security constraints: Avoid boiling water or steam.

π System Modeling#
Physical Model#
The temperature evolution is governed by the PDE:
Simulation#
The pipe is divided into segments.
Each segmentβs temperature is updated based on neighbors and the environment.
The heater injects warmth, and the animation shows heat propagation.

ποΈ Control Strategies#
1. PI Control (Proportional-Integral)#
Equation:
Gain scheduling ensures inlet temperature stays below 95Β°C.
Performance: Excellent for constant setpoint tracking.

2. Model Predictive Control (MPC)#
Objective: Minimize tracking error and input usage over a prediction horizon.
Constraints: Inlet/outlet temperatures β€ 95Β°C, power β€ 33 kW.
Advantage: Handles constraints inherently.


3. Reinforcement Learning (RL)#
Environment: Heater power as action, temperatures as observations.
Reward: Balances setpoint tracking, smooth control, energy usage, and safety.
Algorithm: Soft Actor-Critic (SAC).
Performance: Struggles with precise tracking but is flexible.

π Comparison & Conclusion#
Criteria |
PI Control |
MPC |
RL |
|---|---|---|---|
Performance on Step |
β Excellent |
β Very good |
β Shaky |
Performance on Ramp |
β Needs tuning |
β Very good |
β Needs training |
Security |
β οΈ Gain scheduling |
β Inherent |
β Must be tested |
Complexity/Flexibility |
β Low |
β High |
β οΈ Retraining |
Running Frequency |
β 1Hz |
β 0.1Hz |
β 1Hz |
Step input comparison :

Ramp input comparison :

Key Takeaways#
PI control is simple and effective for constant setpoints.
MPC is robust and handles constraints but is computationally heavy.
RL is flexible but requires extensive training and validation.
π Appendix#
Parameters#
(x): Position (m)
(T(x, t)): Temperature (K)
(u): Fluid velocity (m/s)
(P): Heater power (W)
(K): Heat loss coefficient
Simulation Details#
Impact of heat loss coefficient and external temperature:

π§ How to Use#
Clone the repository.
Install all required libraries: numpt, matplotlib, cvxpy, gymnasium, stable-baselines3
Run the Jupyter notebook system_tutorial for simulations.
Tune parameters for your specific use case.
π‘ Which Controller Would You Choose?#
For simplicity and constant setpoints: PI control.
For robustness and constraints: MPC.
For flexibility and model-free scenarios: RL.