-
Notifications
You must be signed in to change notification settings - Fork 706
/
Poisson_Lshape.py
42 lines (31 loc) · 1.11 KB
/
Poisson_Lshape.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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
import tensorflow as tf
import deepxde as dde
def main():
def pde(x, y):
dy_x = tf.gradients(y, x)[0]
dy_x, dy_y = dy_x[:, 0:1], dy_x[:, 1:]
dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
dy_yy = tf.gradients(dy_y, x)[0][:, 1:]
return -dy_xx - dy_yy - 1
def boundary(x, on_boundary):
return on_boundary
def func(x):
return np.zeros([len(x), 1])
geom = dde.geometry.Polygon([[0, 0], [1, 0], [1, -1], [-1, -1], [-1, 1], [0, 1]])
bc = dde.DirichletBC(geom, func, boundary)
data = dde.data.PDE(
geom, 1, pde, bc, num_domain=1200, num_boundary=120, num_test=1500
)
net = dde.maps.FNN([2] + [50] * 4 + [1], "tanh", "Glorot uniform")
model = dde.Model(data, net)
model.compile("adam", lr=0.001)
model.train(epochs=50000)
model.compile("L-BFGS-B")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave=True, isplot=True)
if __name__ == "__main__":
main()