deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

Specifying boundary points for 2D geometry

Open DeepaMahm opened this issue 1 year ago • 7 comments

I want to specify boundary conditions for 2D geometry like the below (geometry generated by specifying point cloud) image

I am unsure how to specify the coordinate points for the two ends of the geometry. On one end , I would like to specify the Dirichlet and Neumann on the other end.

For 1D, I do

bc_l = dde.icbc.DirichletBC(geom, lambda x: 5, boundary_l) bc_r = dde.icbc.NeumannBC(geom, lambda x: 0, boundary_r)

I would like to know if boundary_normal can be used for 2D.

DeepaMahm avatar Nov 07 '23 08:11 DeepaMahm

You can use PointSetBC. The inputs are

PointSetBC(points, values)

Here you can directly input the coordinates and the BCs.

praksharma avatar Nov 27 '23 14:11 praksharma

Hi @praksharma , Thanks so much for your reply.

Could you please let me know if there is a similar function for specifying Neumann BC to a set of points (in the source code PointSetBC is mentioned to be applicable for Dirichlet BC)?

DeepaMahm avatar Nov 27 '23 15:11 DeepaMahm

Good question. I am not entirely sure, but may be you could use the Operator BC. But I have never used PointSetOperatorBC.

If I you were you, I would try to modify the source code. This might need copying the class PointSetBC and add the capability to compute derivatives by simply copying the normal_derivative function here. This might take 10 mins of coding and debugging.

Anyways, it is better to ask the developer (@lululxvi ) about this. I am just a user like you.

praksharma avatar Nov 27 '23 16:11 praksharma

Thanks a lot for the suggestion. I will try PointSetOperatorBC.

@lululxvi , please have a look into this when it's possible for you.

DeepaMahm avatar Nov 27 '23 16:11 DeepaMahm

@praksharma 's suggestion sounds good to me.

lululxvi avatar Dec 10 '23 18:12 lululxvi

Hi @praksharma and @lululxvi ,

I'm sorry for the late reply. Thank you very much for all the suggestions and help.

I first tried PointSetBC for specifying Dirichlet bc,

"""Backend supported: tensorflow.compat.v1, tensorflow, pytorch, paddle"""
import deepxde as dde
import numpy as np
import matplotlib.pyplot as plt
from deepxde import config

# Backend tensorflow.compat.v1 or tensorflow
from deepxde.backend import tf
# from vedo import *
# from vedo import Points
# from vedo import plotter as vplt
#
# from pprint import pprint
# import matplotlib
# matplotlib.use('TkAgg')
#
# settings.use_parallel_projection = False


def pde(x, y):
    dc_t = dde.grad.jacobian(y, x, i=0, j=1)
    dc_xx = dde.grad.hessian(y, x, i=0, j=0)

    d = 1
    return (
        dc_t
        - d * dc_xx
    )


def get_lboundary_points():
    """
    """
    lbc_pids = [452, 402, 352, 302, 251, 201, 152, 99, 13, 96]

    lbc_vertices = [
        [0., 0.9, 0.],
        [0., 0.8, 0.],
        [0., 0.7, 0.],
        [0., 0.6, 0.],
        [0., 0.5, 0.],
        [0., 0.4, 0.],
        [0., 0.3, 0.],
        [0., 0.2, 0.],
        [0., 0.1, 0.],
        [0., 0., 0.]
    ]

    return lbc_vertices


def get_rboundary_points():
    """
    """
    rbc_pids = [499, 446, 396, 346, 293, 295, 244, 193, 146, 144]

    rbc_vertices = [
        [4.9, 0.9, 0.],
        [4.9, 0.8, 0.],
        [4.9, 0.7, 0.],
        [4.9, 0.6, 0.],
        [4.9, 0.5, 0.],
        [4.9, 0.4, 0.],
        [4.9, 0.3, 0.],
        [4.9, 0.2, 0.],
        [4.9, 0.1, 0.],
        [4.9, 0., 0.]
    ]
    return rbc_vertices


def get_points():
   pts = [[0., 0., 0.],
          [0.1, 0., 0.],
          [0.2, 0., 0.],
          [0.3, 0., 0.],
          [0.4, 0., 0.],
          [0.5, 0., 0.],
          [0.6, 0., 0.],
          [0.7, 0., 0.],
          [0.8, 0., 0.],
          [0.9, 0., 0.],
          [1., 0., 0.],
          [1.1, 0., 0.],
          [1.2, 0., 0.],
          [1.3, 0., 0.],
          [1.4, 0., 0.],
          [1.5, 0., 0.],
          [1.6, 0., 0.],
          [1.7, 0., 0.],
          [1.8, 0., 0.],
          [1.9, 0., 0.],
          [2., 0., 0.],
          [2.1, 0., 0.],
          [2.2, 0., 0.],
          [2.3, 0., 0.],
          [2.4, 0., 0.],
          [2.5, 0., 0.],
          [2.6, 0., 0.],
          [2.7, 0., 0.],
          [2.8, 0., 0.],
          [2.9, 0., 0.],
          [3., 0., 0.],
          [3.1, 0., 0.],
          [3.2, 0., 0.],
          [3.3, 0., 0.],
          [3.4, 0., 0.],
          [3.5, 0., 0.],
          [3.6, 0., 0.],
          [3.7, 0., 0.],
          [3.8, 0., 0.],
          [3.9, 0., 0.],
          [4., 0., 0.],
          [4.1, 0., 0.],
          [4.2, 0., 0.],
          [4.3, 0., 0.],
          [4.4, 0., 0.],
          [4.5, 0., 0.],
          [4.6, 0., 0.],
          [4.7, 0., 0.],
          [4.8, 0., 0.],
          [4.9, 0., 0.],
          [0., 0.1, 0.],
          [0.1, 0.1, 0.],
          [0.2, 0.1, 0.],
          [0.3, 0.1, 0.],
          [0.4, 0.1, 0.],
          [0.5, 0.1, 0.],
          [0.6, 0.1, 0.],
          [0.7, 0.1, 0.],
          [0.8, 0.1, 0.],
          [0.9, 0.1, 0.],
          [1., 0.1, 0.],
          [1.1, 0.1, 0.],
          [1.2, 0.1, 0.],
          [1.3, 0.1, 0.],
          [1.4, 0.1, 0.],
          [1.5, 0.1, 0.],
          [1.6, 0.1, 0.],
          [1.7, 0.1, 0.],
          [1.8, 0.1, 0.],
          [1.9, 0.1, 0.],
          [2., 0.1, 0.],
          [2.1, 0.1, 0.],
          [2.2, 0.1, 0.],
          [2.3, 0.1, 0.],
          [2.4, 0.1, 0.],
          [2.5, 0.1, 0.],
          [2.6, 0.1, 0.],
          [2.7, 0.1, 0.],
          [2.8, 0.1, 0.],
          [2.9, 0.1, 0.],
          [3., 0.1, 0.],
          [3.1, 0.1, 0.],
          [3.2, 0.1, 0.],
          [3.3, 0.1, 0.],
          [3.4, 0.1, 0.],
          [3.5, 0.1, 0.],
          [3.6, 0.1, 0.],
          [3.7, 0.1, 0.],
          [3.8, 0.1, 0.],
          [3.9, 0.1, 0.],
          [4., 0.1, 0.],
          [4.1, 0.1, 0.],
          [4.2, 0.1, 0.],
          [4.3, 0.1, 0.],
          [4.4, 0.1, 0.],
          [4.5, 0.1, 0.],
          [4.6, 0.1, 0.],
          [4.7, 0.1, 0.],
          [4.8, 0.1, 0.],
          [4.9, 0.1, 0.],
          [0., 0.2, 0.],
          [0.1, 0.2, 0.],
          [0.2, 0.2, 0.],
          [0.3, 0.2, 0.],
          [0.4, 0.2, 0.],
          [0.5, 0.2, 0.],
          [0.6, 0.2, 0.],
          [0.7, 0.2, 0.],
          [0.8, 0.2, 0.],
          [0.9, 0.2, 0.],
          [1., 0.2, 0.],
          [1.1, 0.2, 0.],
          [1.2, 0.2, 0.],
          [1.3, 0.2, 0.],
          [1.4, 0.2, 0.],
          [1.5, 0.2, 0.],
          [1.6, 0.2, 0.],
          [1.7, 0.2, 0.],
          [1.8, 0.2, 0.],
          [1.9, 0.2, 0.],
          [2., 0.2, 0.],
          [2.1, 0.2, 0.],
          [2.2, 0.2, 0.],
          [2.3, 0.2, 0.],
          [2.4, 0.2, 0.],
          [2.5, 0.2, 0.],
          [2.6, 0.2, 0.],
          [2.7, 0.2, 0.],
          [2.8, 0.2, 0.],
          [2.9, 0.2, 0.],
          [3., 0.2, 0.],
          [3.1, 0.2, 0.],
          [3.2, 0.2, 0.],
          [3.3, 0.2, 0.],
          [3.4, 0.2, 0.],
          [3.5, 0.2, 0.],
          [3.6, 0.2, 0.],
          [3.7, 0.2, 0.],
          [3.8, 0.2, 0.],
          [3.9, 0.2, 0.],
          [4., 0.2, 0.],
          [4.1, 0.2, 0.],
          [4.2, 0.2, 0.],
          [4.3, 0.2, 0.],
          [4.4, 0.2, 0.],
          [4.5, 0.2, 0.],
          [4.6, 0.2, 0.],
          [4.7, 0.2, 0.],
          [4.8, 0.2, 0.],
          [4.9, 0.2, 0.],
          [0., 0.3, 0.],
          [0.1, 0.3, 0.],
          [0.2, 0.3, 0.],
          [0.3, 0.3, 0.],
          [0.4, 0.3, 0.],
          [0.5, 0.3, 0.],
          [0.6, 0.3, 0.],
          [0.7, 0.3, 0.],
          [0.8, 0.3, 0.],
          [0.9, 0.3, 0.],
          [1., 0.3, 0.],
          [1.1, 0.3, 0.],
          [1.2, 0.3, 0.],
          [1.3, 0.3, 0.],
          [1.4, 0.3, 0.],
          [1.5, 0.3, 0.],
          [1.6, 0.3, 0.],
          [1.7, 0.3, 0.],
          [1.8, 0.3, 0.],
          [1.9, 0.3, 0.],
          [2., 0.3, 0.],
          [2.1, 0.3, 0.],
          [2.2, 0.3, 0.],
          [2.3, 0.3, 0.],
          [2.4, 0.3, 0.],
          [2.5, 0.3, 0.],
          [2.6, 0.3, 0.],
          [2.7, 0.3, 0.],
          [2.8, 0.3, 0.],
          [2.9, 0.3, 0.],
          [3., 0.3, 0.],
          [3.1, 0.3, 0.],
          [3.2, 0.3, 0.],
          [3.3, 0.3, 0.],
          [3.4, 0.3, 0.],
          [3.5, 0.3, 0.],
          [3.6, 0.3, 0.],
          [3.7, 0.3, 0.],
          [3.8, 0.3, 0.],
          [3.9, 0.3, 0.],
          [4., 0.3, 0.],
          [4.1, 0.3, 0.],
          [4.2, 0.3, 0.],
          [4.3, 0.3, 0.],
          [4.4, 0.3, 0.],
          [4.5, 0.3, 0.],
          [4.6, 0.3, 0.],
          [4.7, 0.3, 0.],
          [4.8, 0.3, 0.],
          [4.9, 0.3, 0.],
          [0., 0.4, 0.],
          [0.1, 0.4, 0.],
          [0.2, 0.4, 0.],
          [0.3, 0.4, 0.],
          [0.4, 0.4, 0.],
          [0.5, 0.4, 0.],
          [0.6, 0.4, 0.],
          [0.7, 0.4, 0.],
          [0.8, 0.4, 0.],
          [0.9, 0.4, 0.],
          [1., 0.4, 0.],
          [1.1, 0.4, 0.],
          [1.2, 0.4, 0.],
          [1.3, 0.4, 0.],
          [1.4, 0.4, 0.],
          [1.5, 0.4, 0.],
          [1.6, 0.4, 0.],
          [1.7, 0.4, 0.],
          [1.8, 0.4, 0.],
          [1.9, 0.4, 0.],
          [2., 0.4, 0.],
          [2.1, 0.4, 0.],
          [2.2, 0.4, 0.],
          [2.3, 0.4, 0.],
          [2.4, 0.4, 0.],
          [2.5, 0.4, 0.],
          [2.6, 0.4, 0.],
          [2.7, 0.4, 0.],
          [2.8, 0.4, 0.],
          [2.9, 0.4, 0.],
          [3., 0.4, 0.],
          [3.1, 0.4, 0.],
          [3.2, 0.4, 0.],
          [3.3, 0.4, 0.],
          [3.4, 0.4, 0.],
          [3.5, 0.4, 0.],
          [3.6, 0.4, 0.],
          [3.7, 0.4, 0.],
          [3.8, 0.4, 0.],
          [3.9, 0.4, 0.],
          [4., 0.4, 0.],
          [4.1, 0.4, 0.],
          [4.2, 0.4, 0.],
          [4.3, 0.4, 0.],
          [4.4, 0.4, 0.],
          [4.5, 0.4, 0.],
          [4.6, 0.4, 0.],
          [4.7, 0.4, 0.],
          [4.8, 0.4, 0.],
          [4.9, 0.4, 0.],
          [0., 0.5, 0.],
          [0.1, 0.5, 0.],
          [0.2, 0.5, 0.],
          [0.3, 0.5, 0.],
          [0.4, 0.5, 0.],
          [0.5, 0.5, 0.],
          [0.6, 0.5, 0.],
          [0.7, 0.5, 0.],
          [0.8, 0.5, 0.],
          [0.9, 0.5, 0.],
          [1., 0.5, 0.],
          [1.1, 0.5, 0.],
          [1.2, 0.5, 0.],
          [1.3, 0.5, 0.],
          [1.4, 0.5, 0.],
          [1.5, 0.5, 0.],
          [1.6, 0.5, 0.],
          [1.7, 0.5, 0.],
          [1.8, 0.5, 0.],
          [1.9, 0.5, 0.],
          [2., 0.5, 0.],
          [2.1, 0.5, 0.],
          [2.2, 0.5, 0.],
          [2.3, 0.5, 0.],
          [2.4, 0.5, 0.],
          [2.5, 0.5, 0.],
          [2.6, 0.5, 0.],
          [2.7, 0.5, 0.],
          [2.8, 0.5, 0.],
          [2.9, 0.5, 0.],
          [3., 0.5, 0.],
          [3.1, 0.5, 0.],
          [3.2, 0.5, 0.],
          [3.3, 0.5, 0.],
          [3.4, 0.5, 0.],
          [3.5, 0.5, 0.],
          [3.6, 0.5, 0.],
          [3.7, 0.5, 0.],
          [3.8, 0.5, 0.],
          [3.9, 0.5, 0.],
          [4., 0.5, 0.],
          [4.1, 0.5, 0.],
          [4.2, 0.5, 0.],
          [4.3, 0.5, 0.],
          [4.4, 0.5, 0.],
          [4.5, 0.5, 0.],
          [4.6, 0.5, 0.],
          [4.7, 0.5, 0.],
          [4.8, 0.5, 0.],
          [4.9, 0.5, 0.],
          [0., 0.6, 0.],
          [0.1, 0.6, 0.],
          [0.2, 0.6, 0.],
          [0.3, 0.6, 0.],
          [0.4, 0.6, 0.],
          [0.5, 0.6, 0.],
          [0.6, 0.6, 0.],
          [0.7, 0.6, 0.],
          [0.8, 0.6, 0.],
          [0.9, 0.6, 0.],
          [1., 0.6, 0.],
          [1.1, 0.6, 0.],
          [1.2, 0.6, 0.],
          [1.3, 0.6, 0.],
          [1.4, 0.6, 0.],
          [1.5, 0.6, 0.],
          [1.6, 0.6, 0.],
          [1.7, 0.6, 0.],
          [1.8, 0.6, 0.],
          [1.9, 0.6, 0.],
          [2., 0.6, 0.],
          [2.1, 0.6, 0.],
          [2.2, 0.6, 0.],
          [2.3, 0.6, 0.],
          [2.4, 0.6, 0.],
          [2.5, 0.6, 0.],
          [2.6, 0.6, 0.],
          [2.7, 0.6, 0.],
          [2.8, 0.6, 0.],
          [2.9, 0.6, 0.],
          [3., 0.6, 0.],
          [3.1, 0.6, 0.],
          [3.2, 0.6, 0.],
          [3.3, 0.6, 0.],
          [3.4, 0.6, 0.],
          [3.5, 0.6, 0.],
          [3.6, 0.6, 0.],
          [3.7, 0.6, 0.],
          [3.8, 0.6, 0.],
          [3.9, 0.6, 0.],
          [4., 0.6, 0.],
          [4.1, 0.6, 0.],
          [4.2, 0.6, 0.],
          [4.3, 0.6, 0.],
          [4.4, 0.6, 0.],
          [4.5, 0.6, 0.],
          [4.6, 0.6, 0.],
          [4.7, 0.6, 0.],
          [4.8, 0.6, 0.],
          [4.9, 0.6, 0.],
          [0., 0.7, 0.],
          [0.1, 0.7, 0.],
          [0.2, 0.7, 0.],
          [0.3, 0.7, 0.],
          [0.4, 0.7, 0.],
          [0.5, 0.7, 0.],
          [0.6, 0.7, 0.],
          [0.7, 0.7, 0.],
          [0.8, 0.7, 0.],
          [0.9, 0.7, 0.],
          [1., 0.7, 0.],
          [1.1, 0.7, 0.],
          [1.2, 0.7, 0.],
          [1.3, 0.7, 0.],
          [1.4, 0.7, 0.],
          [1.5, 0.7, 0.],
          [1.6, 0.7, 0.],
          [1.7, 0.7, 0.],
          [1.8, 0.7, 0.],
          [1.9, 0.7, 0.],
          [2., 0.7, 0.],
          [2.1, 0.7, 0.],
          [2.2, 0.7, 0.],
          [2.3, 0.7, 0.],
          [2.4, 0.7, 0.],
          [2.5, 0.7, 0.],
          [2.6, 0.7, 0.],
          [2.7, 0.7, 0.],
          [2.8, 0.7, 0.],
          [2.9, 0.7, 0.],
          [3., 0.7, 0.],
          [3.1, 0.7, 0.],
          [3.2, 0.7, 0.],
          [3.3, 0.7, 0.],
          [3.4, 0.7, 0.],
          [3.5, 0.7, 0.],
          [3.6, 0.7, 0.],
          [3.7, 0.7, 0.],
          [3.8, 0.7, 0.],
          [3.9, 0.7, 0.],
          [4., 0.7, 0.],
          [4.1, 0.7, 0.],
          [4.2, 0.7, 0.],
          [4.3, 0.7, 0.],
          [4.4, 0.7, 0.],
          [4.5, 0.7, 0.],
          [4.6, 0.7, 0.],
          [4.7, 0.7, 0.],
          [4.8, 0.7, 0.],
          [4.9, 0.7, 0.],
          [0., 0.8, 0.],
          [0.1, 0.8, 0.],
          [0.2, 0.8, 0.],
          [0.3, 0.8, 0.],
          [0.4, 0.8, 0.],
          [0.5, 0.8, 0.],
          [0.6, 0.8, 0.],
          [0.7, 0.8, 0.],
          [0.8, 0.8, 0.],
          [0.9, 0.8, 0.],
          [1., 0.8, 0.],
          [1.1, 0.8, 0.],
          [1.2, 0.8, 0.],
          [1.3, 0.8, 0.],
          [1.4, 0.8, 0.],
          [1.5, 0.8, 0.],
          [1.6, 0.8, 0.],
          [1.7, 0.8, 0.],
          [1.8, 0.8, 0.],
          [1.9, 0.8, 0.],
          [2., 0.8, 0.],
          [2.1, 0.8, 0.],
          [2.2, 0.8, 0.],
          [2.3, 0.8, 0.],
          [2.4, 0.8, 0.],
          [2.5, 0.8, 0.],
          [2.6, 0.8, 0.],
          [2.7, 0.8, 0.],
          [2.8, 0.8, 0.],
          [2.9, 0.8, 0.],
          [3., 0.8, 0.],
          [3.1, 0.8, 0.],
          [3.2, 0.8, 0.],
          [3.3, 0.8, 0.],
          [3.4, 0.8, 0.],
          [3.5, 0.8, 0.],
          [3.6, 0.8, 0.],
          [3.7, 0.8, 0.],
          [3.8, 0.8, 0.],
          [3.9, 0.8, 0.],
          [4., 0.8, 0.],
          [4.1, 0.8, 0.],
          [4.2, 0.8, 0.],
          [4.3, 0.8, 0.],
          [4.4, 0.8, 0.],
          [4.5, 0.8, 0.],
          [4.6, 0.8, 0.],
          [4.7, 0.8, 0.],
          [4.8, 0.8, 0.],
          [4.9, 0.8, 0.],
          [0., 0.9, 0.],
          [0.1, 0.9, 0.],
          [0.2, 0.9, 0.],
          [0.3, 0.9, 0.],
          [0.4, 0.9, 0.],
          [0.5, 0.9, 0.],
          [0.6, 0.9, 0.],
          [0.7, 0.9, 0.],
          [0.8, 0.9, 0.],
          [0.9, 0.9, 0.],
          [1., 0.9, 0.],
          [1.1, 0.9, 0.],
          [1.2, 0.9, 0.],
          [1.3, 0.9, 0.],
          [1.4, 0.9, 0.],
          [1.5, 0.9, 0.],
          [1.6, 0.9, 0.],
          [1.7, 0.9, 0.],
          [1.8, 0.9, 0.],
          [1.9, 0.9, 0.],
          [2., 0.9, 0.],
          [2.1, 0.9, 0.],
          [2.2, 0.9, 0.],
          [2.3, 0.9, 0.],
          [2.4, 0.9, 0.],
          [2.5, 0.9, 0.],
          [2.6, 0.9, 0.],
          [2.7, 0.9, 0.],
          [2.8, 0.9, 0.],
          [2.9, 0.9, 0.],
          [3., 0.9, 0.],
          [3.1, 0.9, 0.],
          [3.2, 0.9, 0.],
          [3.3, 0.9, 0.],
          [3.4, 0.9, 0.],
          [3.5, 0.9, 0.],
          [3.6, 0.9, 0.],
          [3.7, 0.9, 0.],
          [3.8, 0.9, 0.],
          [3.9, 0.9, 0.],
          [4., 0.9, 0.],
          [4.1, 0.9, 0.],
          [4.2, 0.9, 0.],
          [4.3, 0.9, 0.],
          [4.4, 0.9, 0.],
          [4.5, 0.9, 0.],
          [4.6, 0.9, 0.],
          [4.7, 0.9, 0.],
          [4.8, 0.9, 0.],
          [4.9, 0.9, 0.]]

   return pts


def model(gdata):
    geom = dde.geometry.PointCloud(gdata)
    timedomain = dde.geometry.TimeDomain(0, 60)
    geomtime = dde.geometry.GeometryXTime(geom, timedomain)

    # left_bc = dde.DirichletBC(geomtime, func_lbc, lambda _, on_boundary: on_boundary)
    # right_bc = dde.NeumannBC(geomtime, func_rbc, lambda _, on_boundary: on_boundary)
    # bc_left = dde.DirichletBC(geomtime, lambda x: 0, lambda x, _: np.isclose(x[0], 0))
    # bc_right = dde.DirichletBC(geomtime, lambda x: 1, lambda x, _: np.isclose(x[0], 1))

    lbc_vertices = get_lboundary_points()
    lbc_pts = np.array(lbc_vertices, dtype=config.real(np))
    lbc_values = np.array([5]*len(lbc_vertices),  dtype=config.real(np))
    bc_l = dde.icbc.PointSetBC(lbc_pts, lbc_values, component=0)

    # rbc_vertices = get_rboundary_points()
    # rbc_pts = np.array(rbc_vertices, dtype=config.real(np))
    # rbc_values = [1]*len(rbc_vertices)
    # bc_r = dde.icbc.PointSetBC(rbc_pts, rbc_values, component=0)

    ic = dde.icbc.IC(geomtime, lambda x: 1, lambda _, on_initial: on_initial, component=0)

    data = dde.data.TimePDE(
        geomtime,
        pde,
        [bc_l, ic],
        num_domain=320,
        num_test=80000
    )

    layer_size = [2] + [30] * 6 + [1]
    activation = "tanh"
    initializer = "Glorot uniform"
    net = dde.nn.FNN(layer_size, activation, initializer)

    model = dde.Model(data, net)
    model.compile("adam", lr=1e-3, metrics=["l2 relative error"])
    losshistory, train_state = model.train(iterations=200)

    dde.saveplot(losshistory, train_state, issave=True, isplot=True)


if __name__ == '__main__':

    pts = get_points()
    gdata = np.array(pts)
    model(gdata=gdata)

    # pcloud = Points(pts, c='k', alpha=0.5)
    # vplt.show(pcloud)

Unfortunately, there is a concat error


Traceback (most recent call last):
  File "I:\xxx\xxx\simdeep_2d_pipe.py", line 624, in <module>
    model(gdata=gdata)
  File "I:\xxx\xxx\simdeep_2d_pipe.py", line 600, in model
    data = dde.data.TimePDE(
           ^^^^^^^^^^^^^^^^^
  File "I:\xxxx\venv\Lib\site-packages\deepxde\data\pde.py", line 322, in __init__
    super().__init__(
  File "I:\xxxx\venv\Lib\site-packages\deepxde\data\pde.py", line 127, in __init__
    self.train_next_batch()
  File "I:\xxxx\venv\Lib\site-packages\deepxde\utils\internal.py", line 38, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\xxxx\venv\Lib\site-packages\deepxde\data\pde.py", line 176, in train_next_batch
    self.bc_points()  # Generate self.num_bcs and self.train_x_bc
    ^^^^^^^^^^^^^^^^
  File "I:\xxxx\venv\Lib\site-packages\deepxde\utils\internal.py", line 38, in wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "I:\xxxx\venv\Lib\site-packages\deepxde\data\pde.py", line 285, in bc_points
    np.vstack(x_bcs)
  File "<__array_function__ internals>", line 200, in vstack
  File "I:\xxxx\venv\Lib\site-packages\numpy\core\shape_base.py", line 296, in vstack
    return _nx.concatenate(arrs, 0, dtype=dtype, casting=casting)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<__array_function__ internals>", line 200, in concatenate
ValueError: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 3 and the array at index 1 has size 4

I am not sure how to fix the error, I double checked the size of lbc_pts and lbc_values . It is of same length.

    lbc_vertices = get_lboundary_points()
    lbc_pts = np.array(lbc_vertices, dtype=config.real(np))
    lbc_values = np.array([5]*len(lbc_vertices),  dtype=config.real(np))
    bc_l = dde.icbc.PointSetBC(lbc_pts, lbc_values, component=0)

I couldn't figure out the source of the error. The geometry is a rectangular domain, pts includes the coordinates of points in the domain. get_lboundary_points function returns the coordinates of the points that lie on the left boundary of the domain.

Could you please have a look when it is possible for you?

DeepaMahm avatar Dec 13 '23 10:12 DeepaMahm

lbc_values should be column vector.

lululxvi avatar Jan 01 '24 03:01 lululxvi

Prof. @lululxvi ,

Sorry for the really late post.

I tried to convert to a column vector of the following form

lbc_values = np.array([5] * len(lbc_vertices), dtype=config.real(np)).reshape(-1, 1)

But I get the same error unfortunately

DeepaMahm avatar Mar 11 '24 16:03 DeepaMahm

Hello @DeepaMahm, did you manage to implement NeumannBC on a Pointcloud geometry ? If you did I would be glad to ask you a few questions about it.

Thanks, Greg

Gregouare avatar May 14 '24 08:05 Gregouare

Hi @Gregouare,

To set up the NeumannBC on a pointcloud, I computed the boundary normals and assigned it to the PointCloud function.

geom = dde.geometry.PointCloud(
    points=np.asarray(domain_points),
    # boundary_points=np.asarray(lbc_points),
    boundary_points=boundary_points,
    boundary_normals=boundary_normals
)


For a simply geometry like a rectangle, we could do the following to define NeumannBC.

top_bc = dde.icbc.NeumannBC(geomtime, func_neumann_bc, boundary_top)

def boundary_top(x, on_boundary):
    """
    NC boundary for model_v1
    :param x:
    :param on_boundary:
    :return:
    """
    return on_boundary and np.isclose(x[1], 5)

I am not sure, how to set this up for a complex geometry defined using pointcloud. If you have some thoughts, I would like to discuss.

DeepaMahm avatar May 14 '24 10:05 DeepaMahm

Hi, thanks for the quick answer !

So far I have been trying to set up a dummy 3D case of a cube of size one, which has but one non zero heat flux face. (So that I can compare with the same network built with the geometry.cuboid class.

Here is a snippet for the implementation of the geom and BCs :

geom = dde.geometry.PointCloud(points = X_, boundary_points = boundary_p, 
                               boundary_normals = boundary_n)

timedomain = dde.geometry.TimeDomain(0, 1)
geomtime = dde.geometry.GeometryXTime(geom, timedomain)

def boundary_x_in(x, on_boundary):
    return (on_boundary and np.isclose(x[0], -l))

def boundary_x_out(x, on_boundary):
    return (on_boundary and np.isclose(x[0], l))

def boundary_y_in(x, on_boundary):
    return (on_boundary and np.isclose(x[1], -l))

def boundary_y_out(x, on_boundary):
    return (on_boundary and np.isclose(x[1], l))

def boundary_z_in(x, on_boundary):
    return (on_boundary and np.isclose(x[2], -l))

def boundary_z_out(x, on_boundary):
    return (on_boundary and np.isclose(x[2], l))

### Initial and boundary conditions:
bc_x_in = dde.icbc.NeumannBC(geomtime, lambda X: 1 , boundary_x_in)
bc_x_out = dde.icbc.NeumannBC(geomtime, lambda X: 0, boundary_x_out) 
bc_y_in = dde.icbc.NeumannBC(geomtime, lambda X: 0, boundary_y_in) 
bc_y_out = dde.icbc.NeumannBC(geomtime, lambda X: 0, boundary_y_out) 
bc_z_in = dde.icbc.NeumannBC(geomtime, lambda X: 0, boundary_z_in) 
bc_z_out = dde.icbc.NeumannBC(geomtime, lambda X: 0, boundary_z_out) 

But when it comes to the compilation, I have the error message : "NotImplementedError: PointCloud.boundary_normal to be implemented".

Could you maybe help me with the format of boundary_normals ? Or is the problem coming from another part of the code (it happens during the compilation) ? Then I will try a more complex geometry, still 3D. But if you have questions do not hesitate maybe I will be able to help a bit !

Gregouare avatar May 14 '24 10:05 Gregouare

@Gregouare You are probably using an older version of DeepXDE. The PointCloud class has boundary_normal defined. https://github.com/lululxvi/deepxde/blob/3810a9888d13e04cecf114e93a00dfbf90021472/deepxde/geometry/pointcloud.py#L65

Depending on whether you are using conda or just python virtualenv the upgrade procedure may vary. You can take help of ChatGPT to upgrade DeepXDE, as they just launched free GPT4 for public yesterday.:)

Additionally, please share the entire error traceback. Providing just "NotImplementedError: PointCloud.boundary_normal to be implemented" isn't very helpful as it requires us to make many assumptions.

praksharma avatar May 14 '24 11:05 praksharma

@Gregouare , boundary normals for 2D looks like: https://github.com/lululxvi/deepxde/issues/1688#issuecomment-2028288049

[ [-1, 0], [-1, 0], [-1, 0], ]

As @praksharma pointed out,

The normals are undefined on the corners, so just exclude those points. Mathematically, the derivative is undefined on corners. https://github.com/lululxvi/deepxde/issues/1688#issuecomment-2028379855

DeepaMahm avatar May 14 '24 11:05 DeepaMahm

Understood, I am going to look into it and see whether it is a version problem (which it seems) or not . Sorry for the partial Traceback by the way, I thought it wouldn't be needed.

@DeepaMahm Sounds good, that is how I defined it. One last question regarding this matter for the moment : I already excluded the normal vectors corresponding to the points on the edges of the domain, can you confirm that I also have to delete those points from the points defining the domain before passing them into dde.geometry.PointCloud ?

Thanks a lot for your help !

Gregouare avatar May 14 '24 12:05 Gregouare

@Gregouare , Yes, in the below, points excludes the boundary_points

geom = dde.geometry.PointCloud(
    points=np.asarray(domain_points),
    boundary_points=boundary_points,
    boundary_normals=boundary_normals
)

DeepaMahm avatar May 14 '24 12:05 DeepaMahm

My bad, I actually meant to exclude the edges points from boundary points... But in order to have the arrays (boundary_points & boundary_normals) of same size it seems natural to do so. Thanks a lot for your quick answers, I will try and let you know if the code runs and converges in 3D.

Gregouare avatar May 14 '24 12:05 Gregouare