A C++ simulation code for modeling 1D fluid plasma dynamics with coupled ion and electron perturbations using finite difference methods.
This project simulates the temporal evolution of a one-dimensional bi-species plasma system. It solves the coupled fluid equations for ion and electron density/velocity perturbations along with the electric field. The goal is to study wave propagation and instabilities in a plasma, keeping the second order terms.
The code solves the following system of equations:
- Continuity equation (for species s = i, e):
- Momentum equation (for species s = i, e):
With the pressure gradient:
- Poisson's equation:
Where:
n_s1: Density perturbation [m⁻³]u_s1: Velocity perturbation [m/s]E: Electric field [V/m]P_s: Pressure [Pa]q_s: Charge [C]m_s: Mass [kg]
The solver implements a 2nd-order 1D finite volume scheme for nonlinear electrostatic plasma dynamics:
- Spatial discretization: Conservative form with MUSCL reconstruction (minmod limiter) for 2nd-order accuracy while avoiding non-physical oscillations
- Numerical fluxes: Rusanov scheme (Local Lax–Friedrichs) at interfaces, ensuring robustness and stability
- Time integration: MacCormack-type predictor–corrector scheme (2nd-order), with predictor step (advection + sources) and corrector step (backward reconstruction + time averaging)
- Poisson's equation: Tridiagonal linear solver on centered finite differences, solved at each substep for self-consistent electric field evolution
- Boundary conditions: Periodic
- CFL condition:
where
- C++ compiler with C++11 support (g++, clang++)
- Eigen3 library (included in
include/Eigen/) - CMake (version 3.10 or higher)
- Python 3 with matplotlib and numpy (for visualization)
.
├── CMakeLists.txt # CMake configuration file
├── README.md # This file
├── include/
│ ├── constants.hpp # Physical constants
│ ├── plasma.hpp # PlasmaSystem class definition
│ └── Eigen/ # Eigen library headers
├── src/
│ ├── main.cpp # Main simulation program
├── plasmas.cpp # PlasmaSystem class implementation
│ └── plot_time.py # Python visualization script
├── build/ # Build directory
├── data/ # Output data files
└── image/ # Generated plots
-
Create and navigate to the build directory:
mkdir -p build cd build -
Configure with CMake:
cmake ..
-
Compile:
make
This will generate the bi_plasma executable in the build/ directory.
From the build/ directory:
./bi_plasmaThe program will:
- Initialize the plasma system with a Gaussian density perturbation
- Run the time evolution simulation
- Save data to
data/directory - Automatically run the visualization script to generate plots
The simulation generates the following data files in the data/ directory:
time.txt: Time array [s]x_grid.txt: Spatial grid [m]n_i1_time.txt: Ion density perturbation evolutionu_i1_time.txt: Ion velocity perturbation evolutionn_e1_time.txt: Electron density perturbation evolutionu_e1_time.txt: Electron velocity perturbation evolutionE_time.txt: Electric field evolution
Generated plots are saved in the image/ directory.
This project is licensed under the MIT License - see the LICENSE file for details.
Ewan Bataille
