Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing the 1D wave equation #4

Open
engsbk opened this issue Feb 25, 2022 · 2 comments
Open

Implementing the 1D wave equation #4

engsbk opened this issue Feb 25, 2022 · 2 comments

Comments

@engsbk
Copy link

engsbk commented Feb 25, 2022

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.

@levimcclenny
Copy link
Owner

@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.

@engsbk
Copy link
Author

engsbk commented Mar 4, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants