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 758 forks source link

Heat conduction equation with contact boundary and output-dependent parameters. #1604

Open HongtaoBi opened 10 months ago

HongtaoBi commented 10 months ago

Dear LuLu,

Recently I've been working on solving a heat conduction equation using PINN. I am stuck with several questions and I would really appreciate it if you could provide me with any help. My problem and PDE are as follows:

数学问题

I have rescaled r, z and T to 0-1 by multiplying some constants in PDE (r=2r, z=z/90, T=T/700) and I'm using tensorflow.compat.v1 backend. I cannot get good results due to 2 main problems:

  1. There is a contact boundary between region 1 and region 2, which means both T and k*dT/dr should be equivalent at r=0.9. I have no idea how to handle this and my current method is using tf.where to define 2 different PDE as PDE loss.
  2. The thermal conductivity in region1 is not a constant and it's a fuction of T, the network output. My PDE should be able to calculate k(T), dk/dr and dk/dz but my code seems to get incorrect results. Also, I get nan from k1 if k1 contains tf.exp.

My full code is:

import deepxde as dde
import numpy as np
import tensorflow as tf

left = 0.01
right = 1
down = 0
up = 1
k_2 = 0.3

def pde_hc(x, y):
    dy_rr = dde.grad.hessian(y, x, i=0, j=0)
    dy_zz = dde.grad.hessian(y, x, i=1, j=1)
    dy_r = dde.grad.jacobian(y, x, i=0, j=0)
    dy_z = dde.grad.jacobian(y, x, i=0, j=1)

    # k_1 = 1.158 / (7.5408 + 12.3844 * y + 1.770958 * (y ** 2)) + 74.105 * ((0.7 * y) ** -2.5) * tf.exp((-23.35714) / y)
    k_1 = 1.158 / (7.5408 + 12.3844 * y + 1.770958 * (y ** 2))
    dk_1_r = dde.grad.jacobian(k_1, x, i=0, j=0)
    dk_1_z = dde.grad.jacobian(k_1, x, i=0, j=1)
    hc1 = k_1 * (2800 * dy_rr + 7 / 81 * dy_zz) + (k_1 / x[:, 0:1] + dk_1_r) * 2800 * dy_r + 7 / 81 * dk_1_z * dy_z - 100
    hc2 = k_2 * (2800 * dy_rr + 7 / 81 * dy_zz) + k_2 / x[:, 0:1] * 2800 * dy_r
    return tf.where(x[:, 0:1] < 0.9, hc1, hc2)

def boundary_r_left(x, on_boundary):
    return on_boundary and np.isclose(x[0], left)

def boundary_r_right(x, on_boundary):
    return on_boundary and np.isclose(x[0], right)

def boundary_z_down(x, on_boundary):
    return on_boundary and np.isclose(x[1], down)

def boundary_z_up(x, on_boundary):
    return on_boundary and np.isclose(x[1], up)

geom1 = dde.geometry.Rectangle([left, down], [right, up])
bc_r_left = dde.icbc.NeumannBC(geom1, lambda x: 0.0, boundary_r_left)
bc_r_right = dde.icbc.DirichletBC(geom1, lambda x: 1.0, boundary_r_right)
bc_z_down = dde.icbc.NeumannBC(geom1, lambda x: 0.0, boundary_z_down)
bc_z_up = dde.icbc.NeumannBC(geom1, lambda x: 0.0, boundary_z_up)

bc = [bc_r_left, bc_r_right, bc_z_down, bc_z_up]
loss_weights = [1, 1, 1, 1, 1]

data = dde.data.PDE(
    geom1,
    pde_hc,
    bc,
    num_domain=1000,
    num_boundary=200,
    num_test=1500,
)

net = dde.nn.FNN([2] + 6 * [150] + [1], "tanh", "Glorot normal")
model = dde.Model(data, net)
model.compile("adam", lr=0.001, loss_weights=loss_weights)
losshistory, train_state = model.train(iterations=20000, display_every=1000)
dde.saveplot(losshistory, train_state, issave=True, isplot=True)

I'm not sure if my current code is correct for my PDE and problem. I'm a beginner of DeepXDE and Tensorflow and I'm not sure if some existing functions could solve my problem. I would also want some suggestions for my code and any help would be greatly appreciated.

Thank you very much!

HongtaoBi commented 9 months ago

Hi!

Thanks for your help! But unfortunately I still cannot get correct results, especially at the contact boundary. As for the parameters, switching from tensorflow to pytorch has been quite helpful. I still need some help for my code if possible.

----- 原始邮件 ----- 发件人: "farrate" @.> 收件人: "lululxvi/deepxde" @.> 抄送: "Bi Hongtao" @.>, "Manual" @.> 发送时间: 星期日, 2024年 1 月 14日 上午 2:50:46 主题: Re: [lululxvi/deepxde] Heat conduction equation with contact boundary and output-dependent parameters. (Issue #1604)

Hi:

Question: Did you find out what was wrong with your code? Because it looks good to me

-- Reply to this email directly or view it on GitHub: https://github.com/lululxvi/deepxde/issues/1604#issuecomment-1890701444 You are receiving this because you are subscribed to this thread.

Message ID: @.***>

lululxvi commented 9 months ago

Not sure what the problem is. For this type of complex problem, it is usually easier to start with a simplified 1D case.

HongtaoBi commented 9 months ago

@lululxvi Thanks for your reply!

After switching from tensorflow to pytorch, I have already solved the problem of thermal conductivity. But I still cannot deal with the contact boundary, which always has bad results. Do you have some suggestions on dealing with contact boundary? Are there any previous code examples?

Thanks a lot!