I am studying PDE using PINN and constructed a code with Tensorflow. Morespecific, I deal with Heat equation in 3-dimensional spaces (2 dim spaces + 1 dim time). However, the results are not very good.
I guess there is a problem with the twice derivative. Here, I attached my code.
import tensorflow as tf
from tensorflow import keras
from keras.models import Sequential
from keras.layers import Dense
from keras.layers import Input
from tensorflow.keras import layers
NN = Sequential()
NN.add(Input((3,)))
NN.add(Dense(units = 36, activation = 'tanh'))
NN.add(Dense(units = 60, activation = 'tanh'))
NN.add(Dense(units = 1))
def dim3_neural_network(self, neural_network, train):
with tf.GradientTape(persistent=True) as tape2:
with tf.GradientTape(persistent=True) as tape1:
x = tf.Variable(train[0], trainable=True)
y = tf.Variable(train[1], trainable=True)
z = tf.Variable(train[2], trainable=True)
u = tf.transpose(neural_network(tf.transpose(tf.stack([x, y, z], axis=0))))
du_dx = tape1.gradient(u, x, unconnected_gradients=tf.UnconnectedGradients.ZERO)
du_dy = tape1.gradient(u, y, unconnected_gradients=tf.UnconnectedGradients.ZERO)
du_dz = tape1.gradient(u, z, unconnected_gradients=tf.UnconnectedGradients.ZERO)
d2u_dxx = tape2.gradient(du_dx, x, unconnected_gradients=tf.UnconnectedGradients.ZERO)
d2u_dyy = tape2.gradient(du_dy, y, unconnected_gradients=tf.UnconnectedGradients.ZERO)
d2u_dzz = tape2.gradient(du_dz, z, unconnected_gradients=tf.UnconnectedGradients.ZERO)
result = tf.convert_to_tensor([x.numpy(), y.numpy(), z.numpy(), u.numpy(),
du_dx.numpy(), du_dy.numpy(), du_dz.numpy(),
d2u_dxx.numpy(), d2u_dyy.numpy(), d2u_dzz.numpy()],
dtype=tf.float32)
Since my code is too long, I did not attacted the whole code. However, you can see the whole code in my GitHub. Whole Code
I am expecting to discover any problem.
Thanks.
Tensorflow verision : 2.10.0
Python version : 3.8.8