/PDE

small examples of solving simple pde

Primary LanguageFortranGNU General Public License v3.0GPL-3.0

PDE

These codes show various methods of solving different PDEs; Let's start with the transport equation:

Transport equation

if we used:

we can see that the apmlitude of solution diverges for any choice of \Deltat and \Deltax; we can therefore use the Lax method where the value of the solution at time n and position j is replaced with the average of the values ​​of the solution at position j + 1 and j-1:

which has as a condition of stability:

An example is in the code trasp_lax.f

The Lax method to prevent divergences introduces a numerical diffusion in fact it is the Forward Time Centered Space of a diffusion equation. To reduce the diffusion we can use the Lax – Wendroff method which is of the second order both in time and in space:

An example is in the code trasp_lw.f

If desired, the method can be generalized to an equation such as:

For example in the code traspnl_lw.f is solved:

It is therefore possible to see the formation and breakage of the wave front, (and of the code when the front is vertical).The plot.py code can be used to analyze the results of fortran codes.

Heat equation

Another interesting equation to deal with is the heat equation, which is a diffusion equation:

this time we can use the Forward Time Centered Space that produce:

the stability analysis shows that the scheme is stable if:

we can also adopt an implicit scheme:

Examples of explicit and implicit schema are found respectively in: calore1D_exp.py and calore1D_imp.py. Also in calore1D_imp.f is implemented the implicit scheme and to show solution can be used calore.py.

It is possible use both implicit and explicit method via the crank_nicolson method:

Burger equation

Wanting to combine transport and diffusion, we obtain the burger equation:

In the code burger1D_FTCS this equation is solved with the scheme:

Another possible thing is to pass a Fourier transform in space in order to make the pde become an ode: then we calculate the spatial dierivates in transform make the inverse and then we evolve over time.

Wave equation

" On the other hand, even if we cannot see beauty in particular measured results, we can already claim to see a certain beauty in the equations which describe general physical laws. For example, in the wave equation, there's something nice about the regularity of the appearance of the x, y, z, and t. And this nice symmetry in appearance of the x, y, z, and t suggests to the mind still a greater beauty which has to do with the four d1mensions, the possibility that space has four-dimensional symmetry, the possibility of analyzing that and the developments of the special theory of relativity. So there is plenty of intellectual beauty associated with the equations. "

Feynman R. Feynman's Lectures On Physics Volume 2, chapter 20.3.

Let's start with the one-dimensional equation:

we can use the FTCS in the first instance as shown in the code onde1D_FTCS.py

that requies:

But with some manipulation is possible to write:

which are two coupled transport equations that we can solve with lax wendroff as seen above. With some reworking:

with:

Laplace equation

From electrostatics to gravity we frequently see this equation (would be the poisson equation, the laplace equation is the associated homogeneous):

in two dimensions we can discretize with the usual rule and obtain:

if we choose the spatial spacings on equal x and y we can rearrange the problem in a linear system like:

i.e. a block triadiagonal matrix where the blocks on the diagonal are tridiagonal matrices NxN and those on the other diagonals are the identity NxN. in the laplace2D.py code the resolution occurs through the numpy library, while in the laplace2D.f code the succesive over relaxation algorithm is implemented to solve the system. As always there is also the python code to display the result of the fortran program, in this case: laplaceplot.py