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

2D Poisson equation with variable coefficient #21

Closed
tangqi opened this issue Mar 27, 2020 · 13 comments
Closed

2D Poisson equation with variable coefficient #21

tangqi opened this issue Mar 27, 2020 · 13 comments

Comments

@tangqi
Copy link
Contributor

tangqi commented Mar 27, 2020

Hi, I am interested in solving some practical problems with your solver. As a first test, I would like to solve -div(coeff*grad y) = 1, where coeff=1+x1+x2. (a similar 1D case works fine.) The computational domain is [0,1]^2.

Here is the simple code:

def main():
    def pde(x, y):
        x1=x[:,0]
        x2=x[:,1]
        coeff=1+x1+x2
        dy_x = tf.gradients(y, x)[0]
        dy_x, dy_y = dy_x[:, 0:1], dy_x[:, 1:]
        dy_xx = tf.gradients(coeff*dy_x, x)[0][:, 0:1]
        dy_yy = tf.gradients(coeff*dy_y, x)[0][:, 1:]
        return -dy_xx-dy_yy-1

    def boundary(x, on_boundary):
        return on_boundary

    def func(x):
        return np.zeros([len(x), 1])

    geom = dde.geometry.Rectangle([0,0],[1,1])
    bc = dde.DirichletBC(geom, func, boundary)

    data = dde.data.PDE(
        geom, 1, pde, bc, num_domain=1200, num_boundary=120, num_test=1500
    )
    net = dde.maps.FNN([2] + [50] * 4 + [1], "tanh", "Glorot uniform")
    model = dde.Model(data, net)

    model.compile("adam", lr=0.001)
    model.train(epochs=50000)
    model.compile("L-BFGS-B")
    losshistory, train_state = model.train()
    dde.saveplot(losshistory, train_state, issave=True, isplot=True)

But the solver converges to the wrong solution. One obvious mistake is the boundary condition is not 0 and also the solution is quite off. I also tried the non conserved version of the problem, it give me an even worse solution.

The solver has no issue to solve a problem of -dy_xx-dy_yy-dy_x-dy_y=1, which is very close to the problem I failed. Therefore, I do not quite understand why the solver fails so badly for the problem I set up. I am new to tensorflow, so it is likely I may miss something obvious. Any suggestions?

Thanks!
Qi

@lululxvi
Copy link
Owner

Could you change x1=x[:,0] and x2=x[:,1] to x1=x[:, 0:1] and x2=x[:, 1:], so that x1 and x2 are column vectors?

@tangqi
Copy link
Contributor Author

tangqi commented Mar 27, 2020

Thanks a lot! That appears to be the bug.

Do you happen to have a 3D case or a time-dependent 2D example by any chance, or have you ever tried it?

-Qi

@tangqi tangqi closed this as completed Mar 27, 2020
@lululxvi
Copy link
Owner

Yes, we have time-dependent 2D example, but the code is not online.

@tangqi
Copy link
Contributor Author

tangqi commented Mar 27, 2020

Great! Looking forward to it. Thanks again for the help.

@tangqi
Copy link
Contributor Author

tangqi commented Mar 28, 2020

Hi Lu, is there any chance to share a simple 2D time dependent case, like the one in the arxiv paper for us to try? Thanks, -Qi

@lululxvi
Copy link
Owner

I will upload these days. 2D time case should be very similar to 1D case.

@tangqi
Copy link
Contributor Author

tangqi commented Mar 28, 2020

Thank you! That would be great!

@Fayaud
Copy link

Fayaud commented Sep 8, 2021

Hello Lulu!

Please where can I find an example of a time dependent 2D domain.

best regards,

@Fayaud
Copy link

Fayaud commented Sep 8, 2021

Hello Lulu!

Please is this the right syntax to fix the time-periodicity condition for a PDE problem in 2D in space?

Spatial_domain = dde.geometry.Rectangle(xmin=[-1, -1], xmax=[1, 1])
Temporal_domain = dde.geometry.TimeDomain(0, 2*np.pi)
Spatio_temporal_domain = dde.geometry.GeometryXTime(Spatial_domain, Temporal_domain)
boundary_condition_u = dde.DirichletBC(Spatio_temporal_domain, u_func, lambda _, on_boundary: on_boundary, component=0)
boundary_condition_v = dde.DirichletBC(Spatio_temporal_domain, v_func, lambda _, on_boundary: on_boundary, component=1)

periodic_condition_u = dde.PeriodicBC(Spatio_temporal_domain, 1, lambda _, on_boundary: on_boundary, component=0)???
periodic_condition_v = dde.PeriodicBC(Spatio_temporal_domain, 1, lambda _, on_boundary: on_boundary, component=1)???

I only want to check the two last line for: u(x, y, 0) = u(x, y, 2pi); v(x, y, 0) = v(x, y, 2pi)

thank you very much!

best,

@Fayaud
Copy link

Fayaud commented Sep 8, 2021

Or should I instead use this syntax for the time-periodicity for a problem in 2D in space ?

periodic_condition_u = dde.PeriodicBC(Spatio_temporal_domain, 1, lambda _, on_periodic: on_periodic, component=0)???
periodic_condition_v = dde.PeriodicBC(Spatio_temporal_domain, 1, lambda _, on_periodic: on_periodic, component=1)???

Thank you very much!

best,

@lululxvi
Copy link
Owner

lululxvi commented Sep 16, 2021

For the periodic in x and y, why "u(x, y, 0) = u(x, y, 2pi); v(x, y, 0) = v(x, y, 2pi)"? Should it be

  • u(-1, y, t) = u(1, y, t), v(-1, y, t) = v(1, y, t)
  • u(x, -1, 0) = u(x, 1, t), v(x, -1, 0) = v(x, 1, t)
    ?

@Fayaud
Copy link

Fayaud commented Sep 16, 2021

Hello Professor!

Thank you for replying. I want to enforce the periodic in time. So, my problem is in 2 dimension in space and the third dimension is the time as: (x, y, t). I actually want to write:

u(x, y, 0) = u(x, y, 2pi); v(x, y, 0) = v(x, y, 2pi) for all (x, y).

best regards!

Fayaud!

@Fayaud
Copy link

Fayaud commented Sep 16, 2021

For more precision, I am solving the following time-dependent Navier-Stokes equation:

File.pdf

best,

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

3 participants