def BC_func(self, dim, geomtime): if dim == 1: bc = dde.NeumannBC(geomtime, lambda x: np.zeros((len(x), 1)), lambda _, on_boundary: on_boundary, component=0) elif dim == 2: bc = dde.NeumannBC(geomtime, lambda x: np.zeros((len(x), 1)), self.boundary_func_2d, component=0) return bc
def main(): def pde(x, y): dy_xx = dde.grad.hessian(y, x) return dy_xx - 2 def boundary_l(x, on_boundary): return on_boundary and np.isclose(x[0], -1) def boundary_r(x, on_boundary): return on_boundary and np.isclose(x[0], 1) def func(x): return (x + 1)**2 geom = dde.geometry.Interval(-1, 1) bc_l = dde.DirichletBC(geom, func, boundary_l) bc_r = dde.NeumannBC(geom, lambda X: 2 * (X + 1), boundary_r) data = dde.data.PDE(geom, pde, [bc_l, bc_r], 16, 2, solution=func, num_test=100) layer_size = [1] + [50] * 3 + [1] activation = "tanh" initializer = "Glorot uniform" net = dde.maps.FNN(layer_size, activation, initializer) model = dde.Model(data, net) model.compile("adam", lr=0.001, metrics=["l2 relative error"]) losshistory, train_state = model.train(epochs=10000) dde.saveplot(losshistory, train_state, issave=True, isplot=True)
def main(): def ddy(x, y): dy_x = tf.gradients(y, x)[0] return tf.gradients(dy_x, x)[0] def dddy(x, y): return tf.gradients(ddy(x, y), x)[0] def pde(x, y): dy_xxxx = tf.gradients(dddy(x, y), x)[0] return dy_xxxx + 1 def boundary_l(x, on_boundary): return on_boundary and np.isclose(x[0], 0) def boundary_r(x, on_boundary): return on_boundary and np.isclose(x[0], 1) def func(x): return -x ** 4 / 24 + x ** 3 / 6 - x ** 2 / 4 geom = dde.geometry.Interval(0, 1) zero_func = lambda x: np.zeros((len(x), 1)) bc1 = dde.DirichletBC(geom, zero_func, boundary_l) bc2 = dde.NeumannBC(geom, zero_func, boundary_l) bc3 = dde.OperatorBC(geom, lambda x, y, _: ddy(x, y), boundary_r) bc4 = dde.OperatorBC(geom, lambda x, y, _: dddy(x, y), boundary_r) data = dde.data.PDE( geom, 1, pde, [bc1, bc2, bc3, bc4], num_domain=10, num_boundary=2, func=func, num_test=100, ) layer_size = [1] + [20] * 3 + [1] activation = "tanh" initializer = "Glorot uniform" net = dde.maps.FNN(layer_size, activation, initializer) model = dde.Model(data, net) model.compile("adam", lr=0.001, metrics=["l2 relative error"]) losshistory, train_state = model.train(epochs=10000) dde.saveplot(losshistory, train_state, issave=True, isplot=True)
return dy_xx - 2 def boundary_l(x, on_boundary): return on_boundary and np.isclose(x[0], -1) def boundary_r(x, on_boundary): return on_boundary and np.isclose(x[0], 1) def func(x): return (x + 1) ** 2 geom = dde.geometry.Interval(-1, 1) bc_l = dde.DirichletBC(geom, func, boundary_l) bc_r = dde.NeumannBC(geom, lambda X: 2 * (X + 1), boundary_r) data = dde.data.PDE(geom, pde, [bc_l, bc_r], 16, 2, solution=func, num_test=100) layer_size = [1] + [50] * 3 + [1] activation = "tanh" initializer = "Glorot uniform" net = dde.maps.FNN(layer_size, activation, initializer) model = dde.Model(data, net) model.compile("adam", lr=0.001, metrics=["l2 relative error"]) losshistory, train_state = model.train(epochs=10000) dde.saveplot(losshistory, train_state, issave=True, isplot=True)