Heat_PINN¶
| Pretrained Model | Metrics |
|---|---|
| heat_pinn_pretrained.pdparams | norm MSE loss between the FDM and PINN is 1.30174e-03 |
1. Background Introduction¶
Heat conduction is a fundamental physical process with extensive applications in engineering and science. Accurate simulation of heat transfer is essential for optimizing energy efficiency, enhancing material properties, and designing thermal systems. The 2D steady heat conduction equation governs steady-state thermal distribution. While traditional numerical methods like Finite Element Method (FEM) or Finite Difference Method (FDM) require domain discretization and matrix solving, Physics-Informed Neural Networks (PINNs) offer a mesh-free alternative. PINNs leverage the flexibility of neural networks constrained by physical laws to solve partial differential equations directly in continuous domains.
2. Problem Definition¶
The 2D steady heat conduction problem is governed by the Laplace equation for temperature \(T(x, y)\):
defined on the domain:
subject to the Dirichlet boundary conditions:
3. Problem Solving¶
Next, we will explain how to convert the problem into PaddleScience code step by step and solve the problem using deep learning methods. In order to quickly understand PaddleScience, only key steps such as model construction, equation construction, and computational domain construction are described below, while other details please refer to API Documentation.
3.1 Model Construction¶
We aim to solve for the unknown temperature \(T\) at each coordinate \((x, y)\). We approximate the solution using a Multilayer Perceptron (MLP) to learn the mapping \(f: \mathbb{R}^2 \to \mathbb{R}^1\):
In the above formula, \(f\) is the MLP model itself, expressed in PaddleScience code as follows:
We define the model input keys as ("x", "y") and the output key as "u", ensuring consistency with the code.
The MLP is instantiated with 9 hidden layers, 20 neurons per layer, and the tanh activation function.
3.2 Equation Construction¶
Since the governing equation is the 2D Laplace equation, we utilize the built-in Laplace class in PaddleScience, setting dim=2.
3.3 Computational Domain Construction¶
The problem domain is a rectangle defined by corners (-1.0, -1.0) and (1.0, 1.0). We use the built-in Rectangle geometry to define this domain.
3.4 Constraint Construction¶
In this case, we use two constraints to guide the training of the model in the computational domain, namely the heat conduction equation constraint acting on the sampling points and the constraint acting on the boundary points.
Before defining constraints, you need to specify the number of sampling points for each constraint, indicating the number of sampled data for each constraint in its corresponding computational domain, as well as general sampling configuration.
3.4.1 Interior Point Constraint¶
Taking InteriorConstraint acting on internal points as an example, the code is as follows:
- Equation:
equation["Laplace"].equations(the residual of the Laplace equation). - Target: 0 (we aim to minimize the residual to zero).
- Domain:
geom["rect"](the rectangular domain). - Sampling: Full batch training with
batch_size=NPOINT_PDE(99x99 grid). - Loss: MSE with
reduction="mean". - Weight: 1.0.
- Equidistant: Enabled to ensure uniform sampling for better convergence.
- Name: "EQ".
3.4.2 Boundary Constraint¶
Similarly, we also need to construct constraints for the four boundaries of the rectangle. However, unlike constructing InteriorConstraint, since the action area is the boundary, we use the BoundaryConstraint class, code as follows:
- Constraint Object:
out["u"](the model output). - Target Value: The Dirichlet boundary values specified in Section 2.
Other parameters follow the same logic as InteriorConstraint.
After the differential equation constraint and boundary constraint are constructed, encapsulate them into a dictionary with the names we just named as keys for subsequent access.
3.5 Optimizer Construction¶
The training process will call the optimizer to update model parameters. Here, the more commonly used Adam optimizer is selected, and the learning rate is set to 0.0005.
3.6 Model Training¶
After completing the above settings, you only need to pass all the instantiated objects to ppsci.solver.Solver in order, and then start training.
3.7 Model Evaluation and Visualization¶
After the model training is completed, it is necessary to compare it with the result calculated by the formal FDM method. Here we use geom["rect"].sample_interior to sample the coordinate data required for testing.
Then, input the sampled coordinate data into the model to obtain the prediction result of the model, and finally compare the prediction result with the FDM result to obtain the error of the model.
4. Complete Code¶
| heat_pinn.py | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
5. Result Display¶
The figure compares the temperature distributions calculated by PINN and FDM. The results are highly consistent, with an MSE loss of only 0.0013, demonstrating PINN's effectiveness in solving this heat transfer problem.
The plots above show cross-sectional temperature profiles at various \(x\) and \(y\) locations ($ \pm 0.75, \pm 0.50, \pm 0.25, 0.00 $). The PINN predictions align closely with the FDM results.
