Skip to content

elifons/met-nums-pdes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Numerical methods for PDEs

This repository contains implementations in C++ to solve partial differential equations.

advc
Linear Advection equation in 2D using Euler time integration

1. Finite differences

Calculates first and second derivatives using centered finite differences.

  • derive.cpp is the main code
  • derive.inp is the input file with main parameters (number of steps $N$ and step size $DX$).

To compile and run the code:

$ g++ derive-inc.cpp -o derive.x
$ ./derive.x

Output:

func.dat, der.dat, der2.dat are the files with the function, first derivative and second derivative, respectively.

2. ODEs

The following codes perform numerical integration of Ordinary Differential Equations. In all cases cond.inp is the input file with main parameters.

First order

The code performs a numerical integration of a first order differential equation
\Large \frac{dq}{dt}=-k
using three different schemes Euler, Heun and Leapfrog. To compile and run the code:

$ g++ temp-scheme.cpp -o temp-scheme.x
$ ./temp-scheme.x

Second order

The code performs a numerical integration of a second order differential equation
\Large \frac{d^2q}{dt^2}=-\omega_0^2q

For each integration step it calculates the system energy using
\Large E=\frac{1}{2}m\dot{q}^2+\frac{1}{2}m\omega_0^2q^2.
To compile and run the code:

$ g++ temp-scheme-SO.cpp -o temp-scheme-SO.x
$ ./temp-scheme-SO.x

Pendulum The code performs a numerical integration of the pendulum equation. To compile and run the code:

$ g++ pendulum.cpp -o pendulum.x
$ ./pendulum.x

3. Diffusion equation

The code integrates the difussion equation
\Large \frac{\partial \varphi}{\partial t}(x,t)=\alpha \frac{\partial^2 \varphi}{\partial x^2}(x,t)
using the FTCS scheme (forward-time central-space), ie, temporal Euler and centered space scheme.

To compile and run the code:

$ g++ FTCS.cpp -o FTCS.x
$ ./FTCS.x

4. Advection equation

1D advection equation

The code performs a numerical integration of the linear advection equation in one dimention
\Large \frac{\partial u}{\partial t} + v \frac{\partial u}{\partial x} = 0
using a centered space scheme and four temporal schemes Euler (FTCS), Heun, Lax and Leapfrog.

To compile and run the code:

$ g++ adv-1D.cpp -o adv-1D.x
$ ./adv-1D.x

2D advection equation

The code performs a numerical integration of the 2D advection equation
\Large \frac{\partial u}{\partial t}(x,y,t) + \vec{v} \vec{\nabla} u(x,y,t) = 0

\Large \frac{\partial u}{\partial t} + v_x \frac{\partial u}{\partial x} + v_y \frac{\partial u}{\partial y} = 0
using an FTCS scheme.

To compile and run the code:

$ g++ adv-2D.cpp -o adv-2D.x
$ ./adv-1D.x

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages