SPINN (helmholtz3d)¶
| Pretrained Model | Metrics |
|---|---|
| spinn_helmholtz3d.pdparams | l2_err: 0.0183 rmse: 0.0064 |
1. Background Introduction¶
The Helmholtz equation is an important partial differential equation widely used in physics and engineering, especially in wave theory and vibration problems. It is named after the German physicist Hermann von Helmholtz. The standard form of the Helmholtz equation is as follows:
Here:
- \(\nabla^2\) is the Laplace operator (also known as the Laplacian), which in a three-dimensional Cartesian coordinate system takes the form: \(\nabla^2 = \frac{\partial^2 }{\partial x^2} + \frac{\partial^2 }{\partial y^2} + \frac{\partial^2 }{\partial z^2}\)
- \(u\) is the function to be solved, usually representing the amplitude of a physical quantity, such as electromagnetic field, acoustic pressure, or quantum wave function.
- \(k\) is the wave number, defined as \(k = \frac{2\pi}{\lambda}\), where \(\lambda\) is the wavelength.
- \(q\) is the source term, usually representing the interaction between physical quantities and time and space derivatives.
This case solves the following three-dimensional Helmholtz equation:
2. Problem Definition¶
The computational domain of this problem is within a unit cube \([-1, 1] ^3\). For the interior points of the computational domain, the above Helmholtz equation is required to be satisfied, and for the boundary points of the computational domain, \(u = 0\) is required.
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¶
The model structure design of SPINN is as follows:
In the Helmholtz problem, each known coordinate point \((x, y, z)\) has a corresponding unknown quantity \(u\) to be solved (here we use \(u\) instead). Here, SPINN is used to represent the mapping function \(f: \mathbb{R}^3 \to \mathbb{R}^1\) from \((x, y, z)\) to \((u)\), that is:
In the above formula, \(m\) is the SPINN model itself, expressed in PaddleScience code as follows
In order to accurately and quickly access the value of specific variables during calculation, we specify here that the input variable names of the network model are ("x", "y", "z"), and the output variable name is ("u"). These names are consistent with subsequent code.
Then by specifying the number of layers and neurons of SPINN, we instantiate a neural network model model with 4 fully connected layers, each with 64 neurons, and the hidden layer feature dimension r of each output variable is 32, and tanh is used as the activation function.
3.2 Equation Construction¶
The Helmholtz differential equation can be represented by the following code:
Note: Here we need to manually pass the model to equation["Helmholtz"] because the Helmholtz equation needs to use the forward differentiation function.
3.3 Constraint Construction¶
3.3.1 Interior Point Constraint¶
Taking SupervisedConstraint acting on interior points as an example, the code for generating interior point training data is as follows:
The code for constructing interior point constraints is as follows:
The first parameter of SupervisedConstraint is the data configuration used for training. Since we use real-time randomly generated data instead of fixed data points, we fill in the custom input data/label generation function;
The second parameter is the equation expression, so pass in the Helmholtz equation object;
The third parameter is the loss function, here MSELoss is selected;
The fourth parameter is the name of the constraint condition. Each constraint condition needs to be named for subsequent indexing. Here it is named "PDE".
3.3.2 Boundary Value Constraint¶
The third constraint condition is the boundary value constraint, and the code is as follows:
3.4 Hyperparameter Setting¶
Next, we need to specify the number of training epochs and learning rate. Here, based on experimental experience, we use 50 training epochs, 1000 steps per epoch, and an initial learning rate of 0.001.
3.5 Optimizer Construction¶
The training process will call the optimizer to update model parameters. Here, the commonly used Adam optimizer is selected, and the ExponentialDecay learning rate adjustment strategy commonly used in machine learning is used together.
3.6 Model Training, Evaluation and Visualization¶
After completing the above settings, you only need to pass the instantiated objects to ppsci.solver.Solver in order, and then start training, evaluation, and visualization.
4. Complete Code¶
| helmholtz3d.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 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
5. Result Display¶
Sample \(100^3\) points uniformly on the computational domain, and their prediction results and analytical solutions are shown in the figure below.
The error predicted by the model in this problem is l2_err = 0.0183, rmse = 0.0064, which is small and basically consistent with the analytical solution error.

