deepxde icon indicating copy to clipboard operation
deepxde copied to clipboard

How to define the outer normal of the boundary of a disk for a time dependent 2D PDE?

Open WANGDI-1291 opened this issue 2 years ago • 4 comments

@lululxvi Hi~ When there is a time-dependent dynamical equation on the boundary of a 2D disk, how to define the outer normal of the boundary? The following is what I write:

1、Use "OperatorBC" to define the boundary condition: bc = dde.icbc.OperatorBC( geomtime, lambda x, y, _: outerboundary(x, y), lambda _, on_boundary: on_boundary, )

2、The outer normal of the boundary is defined in the "outerboundary(x, y)" function: def outerboundary(x, y): normal = geom.boundary_normal(x[:2]) # x[:2] represents the x-, y- Cartesian coordinates, x[2] is the time coordinate. normal = np.array([normal]).T ... ....

But if I write it in this way, this error occurs:

raise NotImplementedError( NotImplementedError: Cannot convert a symbolic Tensor (strided_slice_16:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

I've tried many ways to deal with this issue, but I've not figured it out. Do you have any idea? Thanks in advance!

WANGDI-1291 avatar Sep 10 '22 14:09 WANGDI-1291

Hi~ @lululxvi, I have another question, which is why you just use a column vector, whose length is the same as that of x and y in 2D, not a matrix to define a 2D function. For example, the code you present in "https://deepxde.readthedocs.io/en/latest/demos/pinn_forward/helmholtz.2d.neumann.hole.html": def pde(x, y): dy_xx = dde.grad.hessian(y, x, i=0, j=0) dy_yy = dde.grad.hessian(y, x, i=1, j=1) f = k02 * sin(k0 * x[:, 0:1]) * sin(k0 * x[:, 1:2]) return -dy_xx - dy_yy - k02 * y - f where f is just a vector.

If I assume f(x,y) in the above is defined in a square domain [0,1]x [0,1] and I want to use a function g(x,y) defined in the following to replace f(x,y): g(x,y) = sqrt(x2+y2), if sqrt(x2+y2) < 1/2, g(x,y) = 0, otherwise. how to allocate a memory for g(x,y), using just a column vector or using a matrix? What is the specific code for this question? Thanks!

WANGDI-1291 avatar Sep 10 '22 15:09 WANGDI-1291

Can you please use the code container?

bc = dde.icbc.OperatorBC(geomtime, lambda x, y, _: outerboundary(x, y), lambda _, on_boundary: on_boundary)
def outerboundary(x, y):
    normal = geom.boundary_normal(x[:2]) # x[:2] represents the x-, y- Cartesian coordinates, x[2] is the time coordinate.
    normal = np.array([normal]).T

YOUR FIRST POST:

You can use dde.icbc.NeumannBC for a Neumann BC. See this example.

YOUR SECOND POST:

In machine learning for a single feature we use 1 column. In a 2D problem, we have 2 input features i.e. $x$ and $y$, so we use 2 columns. Please learn basics of machine learning if you are unfamiliar with this practice.

praksharma avatar Sep 14 '22 10:09 praksharma

Thanks! My problem is that there is a time-dependent dynamical equation on the boundary of a 2D disk, not a Neumann BC on the boundary. And could you write a code for my second question asked in the above? Thank you!

WANGDI-1291 avatar Sep 16 '22 02:09 WANGDI-1291

The right hand side of Neumann BC can be time dependent.

lululxvi avatar Sep 22 '22 02:09 lululxvi