Coder Social home page Coder Social logo

francesco-zeno-costanzo / pde Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 20.47 MB

small examples of solving simple pde

License: GNU General Public License v3.0

Python 44.91% Fortran 46.93% C 8.16%
pde waves heat animation transport diffusion-equation lax-wendroff burgers-equation crank-nicolson-method ftcs-explicit

pde's Introduction

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

pde's People

Contributors

francesco-zeno-costanzo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

arunkv7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.