lululxvi / deepxde

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

Variable initial conditions #99

Closed ViktorC closed 3 years ago

ViktorC commented 3 years ago

Hi @lululxvi,

Is there a way to use DeepXDE with variable initial conditions? E.g. in the case of an ODE, is it possible to train a PINN on just the ODE (or just the ODE and a range of different initial conditions) so that the initial condition is one of the input variables of the model? If not, could you please advise on what changes would need to be made to allow for this (if it's possible at all)?

Many thanks, Viktor

lululxvi commented 3 years ago

No, DeepXDE doesn't support variable ICs. You need to modify the code. Is the IC a number or a function?

ViktorC commented 3 years ago

Generally, it would be a function (which could be discretised if that helps). However, for ODEs, it would be just a scalar and for ODE systems, a vector.

lululxvi commented 3 years ago

Then you have to modify the code. As you can see in data/pde.py, the training points are generated only once in the beginning. To support variable ICs, basically in each iteration, we need to use different training points. you need to modify PDE.train_next_batch() such that each batch uses different data.

ViktorC commented 3 years ago

Great, thank you. So once the caching in PDE.train_next_batch() is disabled, I can use an IC with a dynamic function that may return different values for the same input, right? But is there a way to make the map aware of the current IC somehow (at least for ODEs where the ICs are discrete)? I imagine the input layer would require an extra neuron (or multiple extra neurons for systems of ODEs) and it would require some code changes to propagate the ICs to the map.

lululxvi commented 3 years ago

Yes, you are right.

It may be also helpful to look at the "Q: More details about DeepXDE source code" at FAQ.

ViktorC commented 3 years ago

That all makes sense. Thank you for your input. I'll make sure to check the FAQ out.

On a side note, it should be possible to extend this to PDEs as well by discretising the ICs, right? E.g. in the case of a time-dependent PDE with 2 spatial dimensions and Dirichlet ICs, one could fit a 2D grid onto the ICs and include the values at the vertices of this grid in the input layer of the map.

lululxvi commented 3 years ago

Yes. If IC is a function, then you can either use vertices values or (maybe better) coefficients of some spectral basis.

On the other hand, you may be interested in DeepONet (https://arxiv.org/abs/1910.03193).

ViktorC commented 3 years ago

Great, thank you for confirming.

Thanks for the link, skimming through the paper, I noticed that Figure 1 A illustrates exactly what we just discussed. 🙂 I'll definitely give it a good read.