lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.76k stars 760 forks source link

deepxde solve fourth order PDE #489

Closed whtwu closed 2 years ago

whtwu commented 2 years ago

Dear doctor lu@lululxvi: I am a new to deep learning ,I am using deepxde to sovle the flowing question, I need you help urgently, the problem setup is as follows: PDE and here is my code and the running result. firstly i am not sure whether the code is correct, also the training and the test loss are too large, the curves don't drop, can you give me some advices? thanks for your precious time. `import deepxde as dde import numpy as np from deepxde.backend import tf def main(): e = 2E+11 i = 1 / 3 pow(10, -8) rou = 7850 l = 0.5 s = 4E-04 f = 50000 omiga = 40 np.pi

def ddx(x, y):
    return dde.grad.hessian(y, x, i=0, j=0)
def ddt(x, y):
    return dde.grad.hessian(y, x, i=0, j=1)
def pde(x, y):
    f_xt = f * tf.sin(20 * np.pi * x[:, 1:])
    dy_tt = ddt(x,y)
    dy_xx = ddx(x,y)
    dy_xxxx = dde.grad.hessian(dy_xx, x, i=0, j=0)
    return e * i * dy_xxxx + rou * s * dy_tt - f_xt

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], 0.5)

def func_m(x):
    sum = 0
    for n in range(1,21):
        omiga_i = ((n ** 2 * np.pi ** 2) / l ** 2) * (e * i / (rou * s)) ** 0.5
        solve = (2 / (rou * s * l) * f / (omiga_i ** 2 - omiga ** 2) * np.sin((n * np.pi * l_i) / l) * \
        np.sin((n * np.pi * x[:, 0:1]) / l) * (np.sin(omiga * x[:, 1:]) - omiga / omiga_i * np.sin(omiga_i * x[:, 1:])))
        sum += solve
    return sum

geom = dde.geometry.Interval(0, 0.5)
timedomain = dde.geometry.TimeDomain(0, 24)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)

bc1 = dde.DirichletBC(geomtime, lambda x: 0, boundary_l)
bc2 = dde.OperatorBC(geomtime, lambda x, y, _: ddx(x, y), boundary_l)
bc3 = dde.DirichletBC(geomtime, lambda x: 0, boundary_r)
bc4 = dde.OperatorBC(geomtime, lambda x, y, _: ddx(x, y), boundary_r)

data = dde.data.TimePDE(
    geomtime,
    pde,
    [bc1, bc2, bc3, bc4],
    num_domain=200,
    num_boundary=200,
    solution=func_m,
    num_test=500,

)

layer_size = [2] + [32] * 4 + [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)

if name == "main": main()` Step Train loss Test loss Test metric
0 [1.31e+09, 1.48e-01, 5.53e-03, 1.14e-01, 1.01e-02] [1.25e+09, 1.48e-01, 5.53e-03, 1.14e-01, 1.01e-02] [4.28e+00]
1000 [1.09e+09, 1.08e+01, 6.23e+00, 9.60e+00, 2.73e+00] [1.71e+09, 1.08e+01, 6.23e+00, 9.60e+00, 2.73e+00] [3.70e+01]
2000 [1.06e+09, 1.28e+01, 7.93e+00, 1.22e+01, 6.97e+00] [1.62e+09, 1.28e+01, 7.93e+00, 1.22e+01, 6.97e+00] [4.09e+01]
3000 [9.84e+08, 1.20e+01, 1.01e+01, 1.12e+01, 8.89e+00] [1.61e+09, 1.20e+01, 1.01e+01, 1.12e+01, 8.89e+00] [3.93e+01]
4000 [9.60e+08, 7.78e+00, 1.09e+01, 7.56e+00, 8.44e+00] [1.70e+09, 7.78e+00, 1.09e+01, 7.56e+00, 8.44e+00] [3.18e+01]
5000 [9.49e+08, 7.20e+00, 1.16e+01, 7.77e+00, 9.19e+00] [1.71e+09, 7.20e+00, 1.16e+01, 7.77e+00, 9.19e+00] [3.14e+01]
6000 [9.37e+08, 7.64e+00, 1.30e+01, 8.51e+00, 9.84e+00] [1.65e+09, 7.64e+00, 1.30e+01, 8.51e+00, 9.84e+00] [3.25e+01]
7000 [9.15e+08, 7.12e+00, 8.50e+00, 7.90e+00, 6.55e+00] [1.66e+09, 7.12e+00, 8.50e+00, 7.90e+00, 6.55e+00] [3.14e+01]
8000 [8.54e+08, 6.00e+00, 1.10e+01, 7.34e+00, 9.29e+00] [1.84e+09, 6.00e+00, 1.10e+01, 7.34e+00, 9.29e+00] [2.96e+01]
9000 [8.23e+08, 4.92e+00, 1.10e+01, 5.93e+00, 9.17e+00] [1.85e+09, 4.92e+00, 1.10e+01, 5.93e+00, 9.17e+00] [2.67e+01]
10000 [7.89e+08, 5.11e+00, 1.13e+01, 6.11e+00, 1.13e+01] [2.03e+09, 5.11e+00, 1.13e+01, 6.11e+00, 1.13e+01] [2.72e+01]

Best model at step 10000: train loss: 7.89e+08 test loss: 2.03e+09 test metric: [2.72e+01] image thanks a lot wuteng

Saransh-cpp commented 2 years ago

@whtwu, some suggestions (I am also new at DeepXDE) -

louhz commented 2 years ago

@whtwu, did you solve this issue?

whtwu commented 2 years ago

@whtwu, did you solve this issue? Actually not yet, because recently I have been troubled by the problem of adding the Dirac function to the PDE of the original problem, so the work is stagnant; My engineering problem is that I need to add an excitation at a certain point in the beam, I need to use the Dirac function in the PDE, as the follows shows and I don't know how to implement it in code; image I tried the code like below, but got an error。 image

whtwu commented 2 years ago

@Saransh-cpp,Thank you very much for your suggestion, I didn't continue at that time due to the new problem, I will continue after the problem is solved.

FZUcipher commented 2 years ago

@whtwu, did you solve this issue?

FZUcipher commented 2 years ago

I think # def ddt(x, y): return dde.grad.hessian(y, x, i=0, j=1) # is wrong. It should be i=1,j=1

whtwu commented 2 years ago

@FZUcipher yes, you're right, I have changed the constants of the problem to let the EI and ps to be the same order and other operations like less timedomain, etc. Lastly, the result is not very good.

happyzhouch commented 2 years ago

@whtwu I also need to incorporate the Dirac delta function in PINN. May I ask how you defined the delta function in pde? In addition, for the numerical methods, such as the finite difference method, how to deal with the delta function? I am new to this research area. Could you mind sharing some experience about this problem?

whtwu commented 2 years ago

@whtwu I also need to incorporate the Dirac delta function in PINN. May I ask how you defined the delta function in pde? In addition, for the numerical methods, such as the finite difference method, how to deal with the delta function? I am new to this research area. Could you mind sharing some experience about this problem?

sorry, actually, I don't know how to solve the problem, you can have a look at this issue #200.

happyzhouch commented 2 years ago

@whtwu Thanks for your reply. From what I have searched, a common practice is to use a normal distribution to approximate the delta function. image Happy to discuss with you!