generated from github/haikus-for-codespaces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PINN (DeepXDE) for solving VDP equation
41 lines (32 loc) · 1.05 KB
/
PINN (DeepXDE) for solving VDP equation
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
"""Backend supported: tensorflow.compat.v1, tensorflow, pytorch"""
import deepxde as dde
import numpy as np
def pde(x, y):
dy_xx = dde.grad.hessian(y, x)
dy_x=dde.grad.jacobian(y,x)
return (
dy_xx
-1*(1-y**2)*dy_x
+y
)
timedomain = dde.geometry.TimeDomain(0, 10)
def boundary_l(x,on_initial):
return on_initial and np.isclose(x[0],0)
ic1 = dde.icbc.IC(
timedomain, lambda x:2,lambda _, on_initial: on_initial
)
#Define the initial condition, set the derivative of the network at 0
def bc_func2(inputs, outputs, X):
return dde.grad.jacobian(outputs,inputs,i=0,j=None)
ic2=dde.icbc.OperatorBC(timedomain,bc_func2,boundary_l)
data = dde.data.TimePDE(
timedomain, pde, [ic1, ic2], num_domain=1000, num_boundary=2,
#num_initial=160
)
net = dde.nn.FNN([1] + [60] * 3 + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)
model.compile("adam", lr=1e-3)
model.train(epochs=10000)
model.compile("L-BFGS")
losshistory, train_state = model.train()
dde.saveplot(losshistory, train_state, issave=True, isplot=True)