예제 #1
0
            ]

def boundary_space_left(x, on_boundary):
    return on_boundary and np.isclose(x[0],0) and not np.isclose(x[1], 0)

def boundary_space_right(x, on_boundary):
    return on_boundary and np.isclose(x[0],1) and not np.isclose(x[1], 0)

def boundary_time_left(x, on_boundary):
    return on_boundary and np.isclose(x[1], 0) and not (np.isclose(x[0], 0) or np.isclose(x[0], 1)) and x[0] <= 0.5

def boundary_time_right(x, on_boundary):
    return on_boundary and np.isclose(x[1], 0) and not (np.isclose(x[0], 0) or np.isclose(x[0], 1)) and x[0] > 0.5

geom = dde.geometry.Rectangle([0,0], [1,1.99])
bc1l = dde.DirichletBC(geom, lambda x: 1.4*np.ones((len(x),1)), boundary_space_left, component=0)
bc2l = dde.DirichletBC(geom, lambda x: 0.1*np.ones((len(x),1)), boundary_space_left, component=1)
bc3l = dde.DirichletBC(geom, lambda x: 1.79071429*np.ones((len(x),1)), boundary_space_left, component=2)

bc1r = dde.DirichletBC(geom, lambda x: 1.0*np.ones((len(x),1)), boundary_space_right, component=0)
bc2r = dde.DirichletBC(geom, lambda x: 0.1*np.ones((len(x),1)), boundary_space_right, component=1)
bc3r = dde.DirichletBC(geom, lambda x: 2.505*np.ones((len(x),1)), boundary_space_right, component=2)

ic1l = dde.ConstantWeightDirichletBC(geom, lambda x: 1.4*np.ones((len(x),1)), boundary_time_left, component=0)
ic2l = dde.ConstantWeightDirichletBC(geom, lambda x: 0.1*np.ones((len(x),1)), boundary_time_left, component=1)
ic3l = dde.ConstantWeightDirichletBC(geom, lambda x: 1.79071429*np.ones((len(x),1)), boundary_time_left, component=2)

ic1r = dde.ConstantWeightDirichletBC(geom, lambda x: 1.0*np.ones((len(x),1)), boundary_time_right, component=0)
ic2r = dde.ConstantWeightDirichletBC(geom, lambda x: 0.1*np.ones((len(x),1)), boundary_time_right, component=1)
ic3r = dde.ConstantWeightDirichletBC(geom, lambda x: 2.505*np.ones((len(x),1)), boundary_time_right, component=2)
예제 #2
0
def boundary_time_left(x, on_boundary):
    return on_boundary and np.isclose(
        x[1],
        0) and not (np.isclose(x[0], -1) or np.isclose(x[0], 1)) and x[0] <= 0


def boundary_time_right(x, on_boundary):
    return on_boundary and np.isclose(
        x[1],
        0) and not (np.isclose(x[0], -1) or np.isclose(x[0], 1)) and x[0] > 0


geom = dde.geometry.Rectangle([-1, 0], [1, 0.2])
bc1l = dde.DirichletBC(geom,
                       lambda x: np.ones((len(x), 1)),
                       boundary_space_left,
                       component=0)
bc2l = dde.DirichletBC(geom,
                       lambda x: np.zeros((len(x), 1)),
                       boundary_space_left,
                       component=1)
bc3l = dde.DirichletBC(geom,
                       lambda x: np.zeros((len(x), 1)),
                       boundary_space_left,
                       component=2)
bc4l = dde.DirichletBC(geom,
                       lambda x: np.zeros((len(x), 1)),
                       boundary_space_left,
                       component=3)
bc5l = dde.DirichletBC(geom,
                       lambda x: np.ones((len(x), 1)),
예제 #3
0
def pde(x, y):
    dy_x = tf.gradients(y, x)[0]
    dy_x, dy_t = dy_x[:, 0:1], dy_x[:, 1:2]
    dy_xx = tf.gradients(dy_x, x)[0][:, 0:1]
    dy_tt = tf.gradients(dy_t, x)[0][:, 1:2]
    return dy_tt - dy_xx

def space_boundary(x, on_boundary):
    return on_boundary and (np.isclose(x[0], -1) or np.isclose(x[0], 1))

def time_boundary(x, on_boundary):
    return on_boundary and np.isclose(x[1], 0) and not (np.isclose(x[0], -1) or np.isclose(x[0], 1))

geomtime = dde.geometry.Rectangle([-1, 0], [1, 2.49])

bc = dde.DirichletBC(geomtime, lambda x: np.zeros((len(x), 1)), space_boundary)
ic1 = dde.DirichletBC(geomtime, lambda x: -np.sin(np.pi * x[:, 0:1]), time_boundary)
ic2=dde.NeumannBC(geomtime, lambda x: np.zeros((len(x),1)), time_boundary)

data = dde.data.PDE(geomtime, 1, pde, [bc, ic1, ic2], num_domain=1000, num_boundary=600)
net = dde.maps.FNN([2] + [50] * 3 + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)

model.compile("adam", lr=1e-3)
model.train(epochs=20000) #was 15000 epochs
model.compile("L-BFGS-B")
losshistory, train_state = model.train(epochs=5000)
saveplot(losshistory, train_state, issave=True, isplot=True)

X, y_true = gen_testdata()
y_pred = model.predict(X)