Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么表示这个边界条件呢:∂(Δu)/∂v = 0 #1945

Open
yogo64 opened this issue Feb 9, 2025 · 0 comments
Open

怎么表示这个边界条件呢:∂(Δu)/∂v = 0 #1945

yogo64 opened this issue Feb 9, 2025 · 0 comments

Comments

@yogo64
Copy link

yogo64 commented Feb 9, 2025

我知道∂(u)/∂v = 0这个条件的用法,但是怎么表示这个边界条件呢:∂(Δu)/∂v = 0

我有两个AI给出的结果但好像都不对

# Neumann 边界条件:∂(Δu)/∂v = 0
def biharmonic_boundary(x, u, on_boundary):
    # 使用 tf.cond 或 tf.where 来处理条件判断
    def true_fn():
        # 计算 Δu 的梯度
        u_xx = dde.grad.hessian(u, x, i=0, j=0)
        u_yy = dde.grad.hessian(u, x, i=1, j=1)
        delta_u = u_xx + u_yy

        grad_delta_u_x = dde.grad.jacobian(delta_u, x, i=0, j=0)
        grad_delta_u_y = dde.grad.jacobian(delta_u, x, i=0, j=1)


        return grad_delta_u_x + grad_delta_u_y

    def false_fn():
        return tf.zeros_like(u)

    # 使用 tf.cond 进行条件判断
    return tf.cond(tf.reduce_all(on_boundary), true_fn, false_fn)#

bc_delta_u = dde.OperatorBC(geomtime, biharmonic_boundary, boundary)#用这一段可以运行但损失直接为0(想一想总觉得不太对),用下面一段会出现类似形状不匹配的问题
# def biharmonic_boundary(x, u, boundary_normal):
#     # 计算 Δu
#     u_xx = dde.grad.hessian(u, x, i=0, j=0)
#     u_yy = dde.grad.hessian(u, x, i=1, j=1)
#     delta_u = u_xx + u_yy
#
#     # 计算 Δu 的梯度
#     grad_delta_u_x = dde.grad.jacobian(delta_u, x, i=0, j=0)
#     grad_delta_u_y = dde.grad.jacobian(delta_u, x, i=1, j=1)#i=0?or1?
#
#     # 计算法向导数
#     normal_derivative = boundary_normal[:, 0:1] * grad_delta_u_x + boundary_normal[:, 1:2] * grad_delta_u_y
#
#     # 返回法向导数,确保其为零
#     return normal_derivative
#
# # 获取边界法向量
# def boundary_normal(x):
#     return dde.geometry.get_normal(x, geom)
# # 定义自定义边界条件
# bc_delta_u = dde.OperatorBC(geom, lambda x, u: biharmonic_boundary(x, u, boundary_normal(x)), boundary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant