This repository contains implementations in C++ to solve partial differential equations.
Linear Advection equation in 2D using Euler time integration |
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.
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
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
For each integration step it calculates the system energy using
.
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
The code integrates the difussion equation
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
1D advection equation
The code performs a numerical integration of the linear advection equation in one dimention
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
To compile and run the code:
$ g++ adv-2D.cpp -o adv-2D.x
$ ./adv-1D.x