ehsanhaghighat / sciann

Deep learning for Engineers - Physics Informed Deep Learning
htttp://sciann.com
Other
323 stars 115 forks source link

Variational PINN #20

Open LucasPa opened 3 years ago

LucasPa commented 3 years ago

Hi!

I tried to use Sciann for variational PINN but without success. I tried to copy the example in the article (it seems to me that no example can be found on the Github). I first generated the grid:

import numpy as np
X, Y = np.meshgrid(np.linspace(-1, 1, 70), np.linspace(-1, 1, 70))
x_data = X.flatten()
y_data = Y.flatten()
Q_data = np.random.rand(x_data.size)

And then copied the code of the article:

import sciann as sn
from sciann.utils.math import diff, sign, sin

x = sn.Variable('x')
y = sn.Variable('y')
Q = sn.Functional ("Q", [x ,y] , 4*[20] , "sigmoid")
m = sn.SciModel ([x, y ] , [Q])
m.train ([ x_data , y_data ] , [Q_data])
Q.set_trainable (False)

T = sn.Functional("T", [x , y ] , 4*[20] , "tanh")
Q_x, Q_y = diff (Q, x), diff (Q, y)
T_x, T_y = diff (T, x), diff (T, y)
# New variables for body force and volume information
fxy = sn.Variable ("fxy")
vol = sn.Variable ("vol")
# The variational target
J = ( Q_x * T_x + Q_y * T_y + Q * fxy ) * vol

m = sn.SciModel ([ x , y , vol ] , [J , T ] , "mse")
m.train(
  [ x_data , y_data , vol_data , fxy_data ] ,
  ["zeros", ( bc_ids , bc_vals )],
  )

But the following error is raised when setting up the model:

>>> m = sn.SciModel ([ x , y , vol ] , [J , T ] , "mse")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/stck/fpascal/.local/lib/python3.6/site-packages/sciann/models/model.py", line 124, in __init__
    **kwargs
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/training.py", line 242, in __new__
    return functional.Functional(*args, **kwargs)
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/functional.py", line 115, in __init__
    self._init_graph_network(inputs, outputs)
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 457, in _method_wrapper
    result = method(self, *args, **kwargs)
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/functional.py", line 191, in _init_graph_network
    self.inputs, self.outputs)
  File "/stck/fpascal/.local/lib/python3.6/site-packages/tensorflow/python/keras/engine/functional.py", line 931, in _map_graph_network
    str(layers_with_complete_input))
ValueError: Graph disconnected: cannot obtain value for tensor Tensor("fxy_1:0", shape=(None, 1), dtype=float32) at layer "mul_11". The following previous layers were accessed without issue: ['conct_4', 'conct_3', 'D20b_13', 'D20b_9', 'sci_activation_15', 'sci_activation_10', 'D20b_14', 'D20b_10', 'sci_activation_16', 'sci_activation_11', 'D20b_15', 'D20b_11', 'sci_activation_17', 'sci_activation_12', 'D20b_16', 'D20b_12', 'sci_activation_18', 'sci_activation_13', 'Q', 'T', 'Grad__6', 'Grad__8', 'Grad__5', 'Grad__7', 'mul_9', 'mul_10', 'add_5']

Did I do something wrong? Is there a full example of use of vPINN available?

Best,

Lucas

ehsanhaghighat commented 3 years ago

The second does not include fxy as input:

sn.SciModel ([ x , y , vol, **fxy** ] , [J , T ] , "mse")

LucasPa commented 3 years ago

Thanks, that helps!

However it is not clear to me what is expect for vol_data, could you please me explain such that I can reproduce the example given in the article (I will then push this on the Github https://github.com/sciann/sciann-applications so other people could understand how to use vPINN with Sciann).

Best,

Lucas

LucasPa commented 3 years ago

Hi!

I'm still stuck here, could you please help me by explaining me how to define vol_data?

Best,

Lucas

LucasPa commented 3 years ago

For those interested to run an example of vPINN, the Github repository https://github.com/ehsankharazmi/hp-VPINNs gives such example.

Stephanepag commented 1 year ago

Hello, I am interested in the previous example using sciann. could you reproduce the example given in the article? Could you give me the python code for the variational form? My best