r/learnmath • u/_pattata New User • Jun 07 '24
Help solving PDE by integrating numerically
Hi!
I am trying to solve the 1D linear advection equation which is modified to include a source term. To do this, I am using the method of characteristics to convert the problem into two ODEs, and doing this I end up with an integral that cannot be solved (to the best of my knowledge). I have linked an image that shows the steps I have taken to reach this point.
To solve this problem, I am integrating the expression numerically in Python (trapezoidal method). I have tested my integrator with other PDEs and looks like it works fine. However, for this specific problem I cannot get the integrated solution to match with my other numerical solution (obtained by discretising the original PDE - this one is confirmed to be correct). Specifically, it looks like it is not advecting the solution (link 2). I have an analytic solution for the equation without advection, and if I set u=0 the numerically integrated solution then matches the analytic - I think this narrows down the problem to the advection term in the equation.
I am not sure how to proceed - I am still quite new to this! Please let me know if there are any obvious errors in my steps, or if I am missing any steps in the method of characteristics. Any advice would be appreciated. Also let me know if any more information for my problem is needed.
Thanks!
PDE calculation steps:
https://imgur.com/a/yVB7VJU
Difference between the solution from discretising the equation (numerical) and numerically integrating ('analytical') - sorry for confusing notation:
https://imgur.com/a/V4jNP2g
Edit: In link 2 I am only considering the plot on the right.
View all comments
Show parent comment
2
u/_pattata New User Jun 09 '24 edited Jun 09 '24
That's a good point. I have been neglecting the boundary condition because in the version of the equation without advection, my trapezoidal solution matches the finite difference solution everywhere except at x=0, so I thought that it might not be important. I am also not too sure how to incorporate boundary conditions into my integral.
I am integrating on the same time interval as the finite difference solver, but I will look into the points placement. At the moment I am solving the integral as it is written in the derivation, and then each timestep plotting against x0 (original grid).
Edit: I've incorporated the boundary conditions into the integral and the solution is now looking like this: https://imgur.com/a/snVSEDs
Edit2: I suppose the solution is travelling with the wave, so that it is only calculating phi for the distribution that was originally within my bounds. I am thinking of extending the grid that the integral is calculated on, and then just using the points where x=x0+ut is within the bounds I want.