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

PDE with additional parameters #1762

Open HumbertHumbert7 opened 5 months ago

HumbertHumbert7 commented 5 months ago

Hi, how can I do if I want to solve a parametric PDE in deepxde? For instance, how can I give as additional input to the network a material parameter? Thank you

praksharma commented 5 months ago

Use dde.Variable(). Check out this example. https://deepxde.readthedocs.io/en/latest/demos/pinn_inverse/diffusion.1d.inverse.html

HumbertHumbert7 commented 5 months ago

Hi, thank you. However I am not solving an inverse problem, but a parametric one. Following your example I don’t want to find the value of C, but I would like to use it as an additional parameter together with x and y. So I want to give a certain range of variation for C, like for x and y and then solve the PDE with variables x,y,C. It’s like the time, but instead of solving an equation in Omega x T, I want to solve the equation in Omega x Paramter space. How can I do with DeepXDE?

praksharma commented 5 months ago

Sorry, my bad. Here you can find issues to solve parametric problems. https://deepxde.readthedocs.io/en/latest/user/faq.html

HumbertHumbert7 commented 5 months ago

Thank you very much. The suggestion is to use hypercube and include also the parameter as an additional input. Also my initial idea was this, however in my case it doesn’t work: I have a circular domain, instead with hypercube I have to work with a rectangular one, this is not a problem because I can sample the points from only from my real physical domain, however how can I set the boundary conditions on my circle? The circular boundary cannot be included using hypercube. I was thinking about using the parameter as the time in order to work with arbitrary geometry and BCs. Is this function included in DeepXDE or do you think I have to try to modify the source code in order to try to include it?

praksharma commented 5 months ago

The easiest way to handle complex geometry is to not use CSG tool provided in DeepXDE but create your own dataset separately. Use any tool such as simple looping in python or may be simulation tools such as hypermesh or Salome Meca to create your coordinates for your geometry. Personally, I have used salome meca to generate a geometry it has nice buttons to extract csv file of nodal coordinates of any boundary, but you can always use python if the geometry is not too complicated.

All you need is two arrays of coordinates for your boundary points and collocation points. This can be a numpy array. To add the parametric term create a 1D array of the parameter range and use itertool.product() to multiply this parameter list with your nodal coordiantes.

Let us assume your nodal coordinates (x,y) are of shape (100, 2) and the parameter array is (10,1). When you use itertool.multiply you will get a training dataset of (1000,3), where the columns are (x,y, param)

Now in deepxde.data.pde you need to set both num_boundary and num_domain to 0 and pass your manually generated training dataset as follows:

data = dde.data.PDE(
    geom,
    pde,
    [bc_array],
    num_domain = 0,
    num_boundary = 0,
    anchors=nodes
)
HumbertHumbert7 commented 5 months ago

Thank you very much. I can try in this way. If I have more than one parameter, you think I can work the same way?

praksharma commented 5 months ago

yes if you have n parameters in your parametric problem, you can do itertools the same way. itertools.product(nodal_coordinates, parameters1, parameters2)

Say nodal_coordinates has a shape of (100,2) and both parameter has a shape of (10,1), you will end up with a training dataset of shape (100 10 10 , 2+1 +1) or simply (10000, 4).

Please choose the geometrynd as geometry in deepxde.data.pde with dimension equal to number of coordinate axes in your problem, for 2D time independent it is 2, plus the number of parameters, in the above example it is 4.

HumbertHumbert7 commented 5 months ago

Thank you very much