PINN求解固体力学问题——论文加代码
- 1. 训练
- 2. 可视化
论文:Physics-Informed Deep Learning and its Application in Computational Solid and Fluid Mechanics
基本问题:
网格:
1. 训练
# %load Plane_Stress_W-PINNs.py
"""
Forward Problem for Plane Stress Linear Elasticity Boundary Value Problem
Weighted-Physics-Informed Neural Networks (W-PINNs)
Author: Alexandros D.L Papados
In this code we solve for the deformation of a material with Young's Modulus
of E = 1.0 GPA and Poisson Ratio of nu = 0.3. The deformation are represented
by u and v in the x and y directions respectively. We solve the following PDE using
W-PINNs:
G[u_xx + u_yy] + G((1+nu)/(1-nu))[u_xx + v_yx] = sin(2pi*x)sin(2pi*y)
G[v_xx + v_yy] + G((1+nu)/(1-nu))[v_yy + u_xy] = sin(pi*x)+ sin(2pi*y)
with Dirichlet boundary conditions.
The Neural Network is constructed as follows:
( sigma(x,y,theta) )
( u(x,y) )
( x ) ( sigma(x,y,theta) ) ( )
Input: ----> Activation Layers: . ----> Output Layer: ( )
( y ) . ( )
. ( v(x,y) )
( sigma(x,y,theta) )
The final output will be [x,y,u,v,e_x,e_y], where e_x and e_y are the strains in the x and y directions
respectively.
Default example is Domain I (Square Domain, [0,1]^2)
"""
import torch
import torch.nn as nn
import numpy as np
import time
import scipy.io
torch.manual_seed(123456)
np.random.seed(123456)
E = 1 # Young's Modulus
nu = 0.3 # Poisson Ratio
G = ((E/(2*(1+nu)))) # LEBVP coefficient
class Model(nn.Module):
def __init__(self):
super(Model, self).__init__()
self.net = nn.Sequential() # Define neural network
self.net.add_module('Linear_layer_1', nn.Linear(2, 30)) # First linear layer
self.net.add_module('Tanh_layer_1', nn.Tanh()) # First activation Layer
for num in range(2, 7): # Number of layers (2 through 7)
self.net.add_module('Linear_layer_%d' % (num), nn.Linear(30, 30)) # Linear layer
self.net.add_module('Tanh_layer_%d' % (num), nn.Tanh()) # Activation Layer
self.net.add_module('Linear_layer_final', nn.Linear(30, 3)) # Output Layer
# Forward Feed
def forward(self, x):
return self.net(x)
# Loss of PDE and BCs
def loss(self, x, x_b, b_u,b_v,epoch):
y = self.net(x) # Interior Solution
y_b= (self.net(x_b)) # Boundary Solution
u_b, v_b = y_b[:, 0], y_b[:, 1] # u and v boundary
u,v = y[:,