Solving the 3D Wave Equation Driven by PINN: MATLAB Code

Solving the 3D Wave Equation Driven by PINN: MATLAB Code

Reading time required

6minutes

Quick read only takes 2 minutes

Please respect the original labor resultsReprint must indicate the link to this articleand the author: Heart of Machine Learning

Abstract: MATLAB code for solving the 3D wave equation driven by PINN

1

Physics-Informed Neural Networks (PINNs) are a neural network method that combines deep learning with physical laws, aimed at solving problems involving partial differential equations (PDEs). Below is a detailed explanation of this problem:

1. Definition and Core Idea of Physics-Informed Neural Networks

Physics-Informed Neural Networks (PINNs) are a method that embeds physical laws into neural networks, guiding the training process of the neural network by using physical equations, boundary conditions, and initial conditions as constraints. This method can leverage known physical laws to enhance the model’s generalization ability, especially in cases of scarce or low-quality data.

2. Core Mechanism of PINNs

  • Embedding of Physical Constraints: PINNs embed physical equations (such as partial differential equations) and boundary conditions into the loss function of the neural network, ensuring that the model automatically satisfies physical constraints during training. For example, the loss function typically includes terms for physical residuals and boundary condition residuals.
    Solving the 3D Wave Equation Driven by PINN: MATLAB Code
  • Combination of Data-Driven and Physics-Driven Approaches: PINNs can utilize both data and physical knowledge for modeling, achieving good predictive results even with limited data.
  • Flexibility and Scalability: PINNs can handle nonlinear problems, parameterized problems, and multiscale problems, and can address complex physical systems such as fluid dynamics, materials science, and geophysics.

3. Application Areas of PINNs

PINNs have been widely applied in various fields, including but not limited to:

  • Fluid Mechanics and Fluid Dynamics: Used for simulating fluid flow, turbulence, wave propagation, etc.
    Solving the 3D Wave Equation Driven by PINN: MATLAB Code
  • Materials Science and Engineering: Used for simulating material behavior, microstructural mechanics, heterogeneous materials, etc.
  • Biomedical and Medical Imaging: Used for image reconstruction, medical imaging, biological signal processing, etc.
  • Energy and Environmental Science: Used for simulating energy systems, climate modeling, environmental dynamics, etc.

4. Advantages and Challenges of PINNs

  • Advantages:
    • High Data Efficiency: In cases of scarce data, PINNs can improve the model’s generalization ability through physical constraints.
    • Strong Interpretability: The introduction of physical constraints enhances the model’s interpretability, aiding in understanding the complex behavior of physical systems.
    • High Computational Efficiency: Compared to traditional numerical methods (such as finite element methods), PINNs can have higher computational efficiency in certain cases.
  • Challenges:
    • Optimization Difficulty: The training process of PINNs can be complex, requiring careful tuning of hyperparameters (such as loss function weights, learning rates, etc.).
    • Representation of Physical Equations: Accurately embedding complex physical equations and boundary conditions into the neural network remains a challenge.
      Solving the 3D Wave Equation Driven by PINN: MATLAB Code

5. Future Development Directions of PINNs

  • Self-Adaptive Physics-Informed Neural Networks (SAPINNs): By introducing adaptive weights and dynamically adjusting physical constraints, further enhancing the model’s flexibility and adaptability.
  • Multiscale and Multi-Physics Coupling: Developing PINNs models capable of handling multiscale and multi-physics coupling problems.
  • Integration with Quantum Computing: Exploring the combination of PINNs with quantum computing to solve more complex physical problems.

Conclusion

Physics-Informed Neural Networks (PINNs) are an innovative method that combines deep learning with physical laws, effectively solving complex problems involving partial differential equations. By embedding physical constraints into the neural network, PINNs have significant advantages in cases of scarce data, low data quality, or complex physical systems. Despite challenges in optimization and representation of physical equations, PINNs show great application prospects in various fields.

2

2.1

This MATLAB code implements a 3D wave equation solver based on Physics-Informed Neural Networks (PINN). Below is a detailed analysis:

🧠 I. Main Functions

Solving the 3D Wave Equation Driven by PINN: MATLAB Code

🔗 II. Logical Relationships

The code structure is clear and divided into five main parts:

  1. 1. Problem Definition and Data Generation: Define equation parameters, initial/boundary conditions, and generate training points.
  2. 2. Neural Network Construction: Construct a fully connected network with inputs as <span>(x, y, z, t)</span> and output as <span>u</span>.
  3. 3. Loss Function Definition: Includes three parts: PDE residual, initial condition, and boundary condition.
  4. 4. Training Loop: Train the network using the Adam optimizer.
  5. 5. Visualization: Plot loss curves, wave field slices, and generate propagation animations.

📐 III. Algorithm Steps

  1. 1. Data Sampling:
  • • Internal Points: Randomly sample <span>(x, y, z, t)</span>
  • • Initial Condition Points:<span>t=0</span> sampled at <span>(x, y, z)</span>
  • • Boundary Condition Points: Sample <span>(x, y, z, t)</span> on six boundary surfaces.
  • 2. Network Forward Propagation:
    • • Input:<span>[x, y, z, t]</span> (converted to <span>dlarray</span> format, supporting automatic differentiation)
    • • Output:<span>u(x, y, z, t)</span>
  • 3. Loss Calculation:
    • PDE Residual Loss: Use automatic differentiation to compute second-order derivatives and construct the wave equation residual.
    • Initial Condition Loss: Ensure <span>u(x,y,z,0)</span> and <span>u_t(x,y,z,0)</span> meet the initial conditions.
    • Boundary Condition Loss: Ensure that on the boundary <span>u=0</span>.
  • 4. Backpropagation and Optimization:
    • • Use <span>dlgradient</span> to compute gradients, and <span>adamupdate</span> to update parameters.
  • 5. Visualization:
    • • Plot loss curves (logarithmic scale)
    • • Plot the wave field distribution on the <span>z=0</span> plane at different times
    • • Generate wave field propagation animations

    🧪 IV. Technical Route

    • PINN Framework: Embed physical equations into the loss function to guide the network in learning physical laws.
    • Automatic Differentiation (AD): Use <span>dlgradient</span> to compute higher-order derivatives, avoiding numerical differentiation errors.
    • Deep Learning Toolbox: Use <span>dlnetwork</span> to construct the network, supporting custom training loops.
    • Multi-Task Loss: Jointly optimize PDE residuals, initial conditions, and boundary conditions.

    📘 V. Formula Principles

    Solving the 3D Wave Equation Driven by PINN: MATLAB Code

    ⚙️ VI. Parameter Settings

    Parameter Value Description
    <span>c</span> 1.0 Wave speed
    <span>x_min, x_max</span> -1, 1 x range
    <span>y_min, y_max</span> -1, 1 y range
    <span>z_min, z_max</span> -1, 1 z range
    <span>t_min, t_max</span> 0, 1 Time range
    <span>N_r</span> 5000 Number of internal residual points
    <span>N_ic</span> 1000 Number of initial condition points
    <span>N_bc</span> 1000 Number of boundary condition points
    <span>numLayers</span> 5 Number of hidden layers
    <span>numNeurons</span> 100 Number of neurons per layer
    <span>numEpochs</span> 1000 Number of training epochs
    <span>learningRate</span> 1e-3 Learning rate

    💻 VII. Operating Environment

    • Software: MATLAB (recommended R2024 or higher)

    ✅ Summary

    This code implements a complete process for solving the 3D wave equation using PINN, combining deep learning with physical modeling, suitable for wave problems with no analytical solution or complex boundary conditions. By using automatic differentiation to compute higher-order derivatives, it avoids the discretization errors of traditional numerical methods, demonstrating strong generality and scalability.

    2.2

    Running Effects

    Solving the 3D Wave Equation Driven by PINN: MATLAB CodeSolving the 3D Wave Equation Driven by PINN: MATLAB CodeSolving the 3D Wave Equation Driven by PINN: MATLAB CodeSolving the 3D Wave Equation Driven by PINN: MATLAB Code

    Complete code link:It is recommended to copy the code link to a computer browser, use a certain F treasure to place an order, and click on the paid content to directly download the code):https://mbd.pub/o/bread/mbd-YZWXmJlrZw==

    Also can scan the QR code:

    Solving the 3D Wave Equation Driven by PINN: MATLAB Code

    3

    Partial Source Code

    30px; } .lineNode {font-size: 10pt; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-style: normal; font-weight: normal; }% Create a deeper neural network.rtcContent { padding: 30px; } .lineNode {font-size: 10pt; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-style: normal; font-weight: normal; }%% Define neural network architecture (input: x,y,z,t; output: u(x,y,z,t))% -------------------------------------------------------------------------inputSize = 4;    % Input dimension: [x,y,z,t]numLayers = 5;    % Number of hidden layersnumNeurons = 100; % Number of neurons per hidden layeroutputSize = 1;   % Output dimension: wave field u% Construct network layerslayers = featureInputLayer(inputSize, 'Normalization', 'none', 'Name', 'input');for i = 1:numLayers-1    layers = [layers              fullyConnectedLayer(numNeurons, 'Name', ['fc', num2str(i)])              tanhLayer('Name', ['tanh', num2str(i)])]; % tanh activation functionendlayers = [layers          fullyConnectedLayer(outputSize, 'Name', 'output')];% Convert to dlnetwork (supports automatic differentiation)net = dlnetwork(layers);analyzeNetwork(net); % View network structure

    Other Codes

    Well, the attentive you will find: https://mbd.pub/o/slowtrain/work

    Blog Expert Certification, Creator in the field of Machine Learning, 2023 Blog Star TOP50, mainly engaged in program design and case analysis of machine learning and deep learning time series, regression, classification, clustering, and dimensionality reduction.Research project model customization/horizontal project model simulation/academic paper guidance/model program explanation can contact me at QQ1153460737 (Others are all pirated and scammers, please be careful

    Technical exchange group: After purchasing any code from the blog or sharing the blog post to any third-party platform, you can add the author QQ to join the group

    Heart of Machine Learning onlyQQ number

    Solving the 3D Wave Equation Driven by PINN: MATLAB Code

    Heart of Machine Learning onlyChannel numberSolving the 3D Wave Equation Driven by PINN: MATLAB Code

    Past Reviews:

    MATLAB Code for Solving High-Order Partial Differential Equations Driven by PINN

    Innovative! Introducing a new paradigm for photovoltaic power prediction by embedding physical prior knowledge into learning! PINN Physics-Informed Neural Network for photovoltaic power prediction, MATLAB implementation

    Original unpublished! POD-PINN eigen orthogonal decomposition combined with Physics-Informed Neural Network multivariable regression prediction model, MATLAB implementation

    PINN Physics-Informed Neural Network for solving boundary value problems of second-order ordinary differential equations (ODE), MATLAB implementation

    Original! PINN Physics-Informed Neural Network for univariate time series prediction, MATLAB implementation

    Case study of solving the 3D heat conduction equation driven by PINN in MATLAB

    Exclusive original! PINN Physics-Informed Neural Network for multivariable time series prediction, MATLAB implementation

    Original premiere! PINN Physics-Informed Neural Network for multivariable regression prediction, MATLAB implementation

    Leave a Comment