Skip to content

Commit

Permalink
Backend paddle: Support elasticity_plate example
Browse files Browse the repository at this point in the history
  • Loading branch information
lijialin03 committed Oct 18, 2023
1 parent d6e7168 commit c895133
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions examples/pinn_forward/elasticity_plate.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
"""Backend supported: pytorch
"""Backend supported: pytorch, paddle
Implementation of the linear elasticity 2D example in paper https://doi.org/10.1016/j.cma.2021.113741.
References:
https://github.com/sciann/sciann-applications/blob/master/SciANN-Elasticity/Elasticity-Forward.ipynb.
"""
import deepxde as dde
import numpy as np
import torch

lmbd = 1.0
mu = 0.5
Q = 4.0
pi = torch.pi

# Define function
if dde.backend.backend_name == "pytorch":
import torch

sin = torch.sin
cos = torch.cos
elif dde.backend.backend_name == "paddle":
import paddle

sin = paddle.sin
cos = paddle.cos

geom = dde.geometry.Rectangle([0, 0], [1, 1])

Expand All @@ -35,10 +45,10 @@ def boundary_bottom(x, on_boundary):
# Exact solutions
def func(x):
ux = np.cos(2 * np.pi * x[:, 0:1]) * np.sin(np.pi * x[:, 1:2])
uy = np.sin(pi * x[:, 0:1]) * Q * x[:, 1:2] ** 4 / 4
uy = np.sin(np.pi * x[:, 0:1]) * Q * x[:, 1:2] ** 4 / 4

E_xx = -2 * np.pi * np.sin(2 * np.pi * x[:, 0:1]) * np.sin(np.pi * x[:, 1:2])
E_yy = np.sin(pi * x[:, 0:1]) * Q * x[:, 1:2] ** 3
E_yy = np.sin(np.pi * x[:, 0:1]) * Q * x[:, 1:2] ** 3
E_xy = 0.5 * (
np.pi * np.cos(2 * np.pi * x[:, 0:1]) * np.cos(np.pi * x[:, 1:2])
+ np.pi * np.cos(np.pi * x[:, 0:1]) * Q * x[:, 1:2] ** 4 / 4
Expand All @@ -60,7 +70,7 @@ def func(x):
sxx_right_bc = dde.icbc.DirichletBC(geom, lambda x: 0, boundary_right, component=2)
syy_top_bc = dde.icbc.DirichletBC(
geom,
lambda x: (2 * mu + lmbd) * Q * np.sin(pi * x[:, 0:1]),
lambda x: (2 * mu + lmbd) * Q * np.sin(np.pi * x[:, 0:1]),
boundary_top,
component=3,
)
Expand All @@ -70,31 +80,31 @@ def fx(x):
return (
-lmbd
* (
4 * pi**2 * torch.cos(2 * pi * x[:, 0:1]) * torch.sin(pi * x[:, 1:2])
- Q * x[:, 1:2] ** 3 * pi * torch.cos(pi * x[:, 0:1])
4 * np.pi**2 * cos(2 * np.pi * x[:, 0:1]) * sin(np.pi * x[:, 1:2])
- Q * x[:, 1:2] ** 3 * np.pi * cos(np.pi * x[:, 0:1])
)
- mu
* (
pi**2 * torch.cos(2 * pi * x[:, 0:1]) * torch.sin(pi * x[:, 1:2])
- Q * x[:, 1:2] ** 3 * pi * torch.cos(pi * x[:, 0:1])
np.pi**2 * cos(2 * np.pi * x[:, 0:1]) * sin(np.pi * x[:, 1:2])
- Q * x[:, 1:2] ** 3 * np.pi * cos(np.pi * x[:, 0:1])
)
- 8 * mu * pi**2 * torch.cos(2 * pi * x[:, 0:1]) * torch.sin(pi * x[:, 1:2])
- 8 * mu * np.pi**2 * cos(2 * np.pi * x[:, 0:1]) * sin(np.pi * x[:, 1:2])
)


def fy(x):
return (
lmbd
* (
3 * Q * x[:, 1:2] ** 2 * torch.sin(pi * x[:, 0:1])
- 2 * pi**2 * torch.cos(pi * x[:, 1:2]) * torch.sin(2 * pi * x[:, 0:1])
3 * Q * x[:, 1:2] ** 2 * sin(np.pi * x[:, 0:1])
- 2 * np.pi**2 * cos(np.pi * x[:, 1:2]) * sin(2 * np.pi * x[:, 0:1])
)
- mu
* (
2 * pi**2 * torch.cos(pi * x[:, 1:2]) * torch.sin(2 * pi * x[:, 0:1])
+ (Q * x[:, 1:2] ** 4 * pi**2 * torch.sin(pi * x[:, 0:1])) / 4
2 * np.pi**2 * cos(np.pi * x[:, 1:2]) * sin(2 * np.pi * x[:, 0:1])
+ (Q * x[:, 1:2] ** 4 * np.pi**2 * sin(np.pi * x[:, 0:1])) / 4
)
+ 6 * Q * mu * x[:, 1:2] ** 2 * torch.sin(pi * x[:, 0:1])
+ 6 * Q * mu * x[:, 1:2] ** 2 * sin(np.pi * x[:, 0:1])
)


Expand Down

0 comments on commit c895133

Please sign in to comment.