SA-PINNs icon indicating copy to clipboard operation
SA-PINNs copied to clipboard

Implementing the 1D wave equation

Open ShaikhaTheGreen opened this issue 3 years ago • 2 comments

Thank you for the great contribution. PINNs have been an amazing tool in scientific computing and this enhancement makes it better. I replicated the code of burger's equation and made changes to model the 1D wave equation with a source term:

@tf.function
def f_model(x,t):
    c = tf.constant(1, dtype = tf.float32)
    Amp = tf.constant(1, dtype = tf.float32)
    frequency = tf.constant(1, dtype = tf.float32)
    sigma = tf.constant(0.5, dtype = tf.float32)
    source_x_coord = tf.constant(0, dtype = tf.float32)
    
    Gaussian_impulse =  Amp * tf.exp(-(1/(sigma**2))*(x-source_x_coord)**2)
    S = Gaussian_impulse * tf.sin( 1 * tf.constant(math.pi)  * frequency * t )
    u = u_model(tf.concat([x,t], 1))
    u_x = tf.gradients(u,x)
    u_xx = tf.gradients(u_x, x)
    u_t = tf.gradients(u,t)
    u_tt = tf.gradients(u_t,t)
    f_u = u_tt + (c**2) * u_xx - S
    
    return f_u

However, the output is not quite what I expected.

Screen Shot 2022-02-25 at 12 09 51 PM

I tried a couple of network architectures and learning rates, but the result seems to be the same. What would you suggest to get more accurate results? Also, I saw how you placed the boundary conditions but I'm not sure how to specify the initial condition? Is it extracted from the exact solution?

Thanks again! Awaiting your feedback.

ShaikhaTheGreen avatar Feb 25 '22 17:02 ShaikhaTheGreen

@engsbk I would recommend trying TensorDiffEq to specify your own IC, etc. It can absolutely be done in the code here, however, by modifying x0 to be an [N0, 1] tensor representing your function of x. I do use the solution to pull the IC but that is not required and should likely be fixed.

The script to replicate this Burgers example in TDQ is here - https://github.com/tensordiffeq/TensorDiffEq/blob/main/examples/burgers-new.py

You would just modify func_ic to be your function of x.

Please let me know if that helps or if we need to discuss further.

Also, sorry for the delayed response, it's been a long week on my side.

levimcclenny avatar Mar 03 '22 23:03 levimcclenny

Thank you so much for your reply, @levimcclenny !

I actually tried it with modifications and it works great. I have some follow-ups that I'll post on the tensordiffeq page for consistency.

ShaikhaTheGreen avatar Mar 04 '22 07:03 ShaikhaTheGreen