lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.78k stars 760 forks source link

PINNs energy method #1714

Open HumbertHumbert7 opened 7 months ago

HumbertHumbert7 commented 7 months ago

I’m trying to use deepxde for pinns in the variational formulation. I started with a veruly trivial case: the potential energy of a beam under a distributed load that is just the integral between 0 and 1 of w_xx2 minus the integral of qw, where w is the unknown displacement and q the distributed load. I have computed the integral with tf.reduce_sum(w_xx2-qw,axis=1) and I have use this in the pde definition, instead of the strong form. The problem is that I always obtain zero displacement. How can I avoid this?

vl-dud commented 7 months ago

Could you show the code?

HumbertHumbert7 commented 7 months ago

I’ll upload it immediately

HumbertHumbert7 commented 7 months ago

import deepxde as dde import numpy as np

def ddy(x, y): return dde.grad.hessian(y, x)

def pde(x, y): dy_xx = ddy(x, y) eq=tf.reduce_sum(dy_xx**2-y,axis=1) return eq

def boundary_l(x, on_boundary): return on_boundary and dde.utils.isclose(x[0], 0)

def boundary_r(x, on_boundary): return on_boundary and dde.utils.isclose(x[0], 1)

geom = dde.geometry.Interval(0, 1)

bc1 = dde.icbc.DirichletBC(geom, lambda x: 0, boundary_l) bc2 = dde.icbc.NeumannBC(geom, lambda x: 0, boundaryr) bc3 = dde.icbc.OperatorBC(geom, lambda x, y, : ddy(x, y), boundaryr) bc4 = dde.icbc.OperatorBC(geom, lambda x, y, : ddy(x, y), boundary_l)

data = dde.data.PDE( geom, pde, [bc1, bc2, bc3, bc4], num_domain=100, num_boundary=2, num_test=100, ) layer_size = [1] + [20] * 3 + [1] activation = "tanh" initializer = "Glorot uniform" net = dde.nn.FNN(layer_size, activation, initializer)

model = dde.Model(data, net) model.compile("adam", lr=0.001, metrics=["l2 relative error"]) losshistory, train_state = model.train(iterations=10000)

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

It’s very easy, the energy is the integral of dy_xx*2-qy and q=1. I want to minimize it, but I always get 0

vl-dud commented 7 months ago

It seems that tf.reduce_sum(dy_xx**2-y,axis=1) is an incorrect representation of the integral for this problem.

HumbertHumbert7 commented 7 months ago

Thank you, so what can I use?

vl-dud commented 7 months ago

I don't think deepxde is suitable for equations with integral. But I could be wrong

HumbertHumbert7 commented 7 months ago

Ok, thank you. Then, I’ll make some other attemps if it won’t work I’ll remain just with the strong form

praksharma commented 7 months ago

hey I assume this is Euler-bernoulli beam. You can simply use the 4th order PDE instead of using the weak form.

HumbertHumbert7 commented 7 months ago

Hi prakaharma, thank you, I have already solved it using the 4-th order ODE and it works correctly, I was thinking about using the energy approach because it is more suitable for more complex cases, so I have decided to start from Euler-Bernoulli that is trivial to see if it works.

praksharma commented 7 months ago

Yes you can look at variational PINNs. This is probably not implemented in DeepXDE. You need to use your own code.

HumbertHumbert7 commented 7 months ago

Ok, thank you very much