This project presents a physics-informed neural network (PINN) framework for control-oriented building thermal modeling. The approach combines data-driven learning with physical laws governing heat transfer to predict room temperature, power usage, and hidden thermal states with improved accuracy, robustness, and data efficiency.
The model integrates neural networks with explicit physics constraints, enabling physically consistent long-horizon predictions suitable for building energy management and predictive control applications.
- Develop control-oriented thermal models for buildings
- Reduce training data requirements through physics-informed learning
- Improve long-horizon temperature and energy predictions
- Maintain physical interpretability while leveraging neural networks
flowchart LR
%% ---------------- DATA ----------------
subgraph A[Data Layer]
A1[Experimental Data]
A2[Simulation Data]
A3[Boundary & Initial Conditions]
end
%% ---------------- PREPROCESSING ----------------
subgraph B[Preprocessing]
B1[Data Cleaning]
B2[Normalization]
B3[Feature Engineering]
end
%% ---------------- MODEL ----------------
subgraph C[Model]
C1[Neural Network\n - Temperature Predictor]
end
%% ---------------- PHYSICS ----------------
subgraph D[Physics Engine]
D1[Heat Transfer PDE]
D2[Boundary Constraints]
end
%% ---------------- LOSS ----------------
subgraph E[Loss Function]
E1[Data Loss - MSE]
E2[Physics Loss - PDE Residual]
E3[Total Loss]
end
%% ---------------- TRAINING ----------------
subgraph F[Training]
F1[Optimizer - Adam/LBFGS]
F2[Backpropagation]
F3[Weight Update]
end
%% ---------------- OUTPUT ----------------
subgraph G[Output]
G1[Model Evaluation]
G2[Temperature Distribution]
G3[Thermal Predictions]
end
%% FLOW CONNECTIONS
A1 --> B
A2 --> B
A3 --> B
B --> C1
B --> D
C1 --> E1
D --> E2
E1 --> E3
E2 --> E3
E3 --> F1
F1 --> F2 --> F3
F3 --> G1
G1 --> G2 --> G3
The core model is implemented using PyTorch Lightning and consists of:
- A data-driven MLP for state prediction
- Trainable physical parameters representing thermal dynamics
- A physics-based constraint block embedded in the loss function
The MLP receives the following inputs at time step k:
- Time index
- Current room temperature
T_r(k) - Previous room temperatures
T_r(k-1), T_r(k-2) - Control action
u(k) - Outside temperature
T_a(k)
The model predicts:
- Next-step room temperature
T_r(k+1) - Physical control input
u_phys(k) - Hidden thermal mass temperature
T_m(k)
The model includes learnable parameters representing thermal coefficients:
- Heat transfer coefficients (
c11,c12,c21,c22) - Control influence coefficient (
b1) - Additional thermal dynamics coefficients (
d11–d23)
These parameters are optimized jointly with the neural network while being constrained to remain physically valid.
A dedicated physics block enforces heat transfer dynamics by:
- Estimating temperature derivatives using finite differences
- Applying a physics-based equation to estimate thermal mass temperature
- Smoothing estimates using convolutional filtering
- Scaling outputs to match learned representations
This block ensures the latent thermal state adheres to realistic physical behavior.
The training objective is a physics-constrained composite loss:
Mean squared error (MSE) for:
- Room temperature prediction
- Control action prediction
MSE between:
- Neural network latent thermal state
- Physics-based thermal mass estimate
Hard physical constraints enforced via penalty terms:
- Positivity of thermal coefficients
- Stability constraints on parameter relationships
The total loss is a weighted sum:
Total Loss = λ₁ · Prediction Loss + λ₂ · Model Loss + λ₂ · Constraint Loss
- Optimizer: Adam
- Separate learning rates:
- Neural network parameters
- Physical parameters (smaller learning rate)
- Learning rate scheduler: ReduceLROnPlateau
- Framework: PyTorch Lightning
This setup stabilizes training while preserving physical interpretability.
- Load aggregated state and label data
- Construct time-shifted input-output pairs
- Forward pass through MLP
- Physics-based latent state estimation
- Compute constrained loss
- Update neural and physical parameters jointly
The model expects:
x_agg_k: Aggregated state at timeklabel_k: Ground truth at timekx_agg_k1: Aggregated state at timek+1label_k1: Ground truth at timek+1
Data is loaded using PyTorch TensorDataset and DataLoader.
- Temperature Prediction: Predict next-step room temperature
- Latent State Estimation: Infer hidden thermal mass temperature
- Model-Based Control: Enable downstream MPC or RL integration
- Physics-Consistency: Explicit enforcement of thermal laws
- Data Efficiency: Reduced reliance on large datasets
- Interpretability: Learnable parameters map to physical quantities
- Modularity: Clear separation of network, physics, and loss components
- Control-Oriented: Designed for predictive control applications
This framework can be extended to:
- Multi-zone building models
- HVAC system integration
- Reinforcement learning for energy optimization
- Model Predictive Control (MPC)
- Real-time building energy management systems
- Assumes lumped thermal dynamics
- Requires reasonably accurate sensor data
- Physics model structure must be predefined
- Designed primarily for control-oriented applications
- Python 3.8+
- PyTorch
- PyTorch Lightning
- NumPy
- Physics-informed neural networks improve thermal modeling accuracy
- Physical constraints enhance robustness and interpretability
- Latent thermal state estimation is critical for long-horizon prediction
- PINNs provide a practical balance between physics-based and data-driven models
This project is intended for educational and research use.
Refer to applicable licenses for PyTorch, PyTorch Lightning, and associated datasets.