- MATLAB 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| README.md | ||
| stochastic_mhd_2d_model.m | ||
| stochastic_mhd_3d.m | ||
Stochastic Magnetohydrodynamics (MHD) Simulation in MATLAB
This repository contains MATLAB implementations of two-dimensional and three-dimensional stochastic magnetohydrodynamic (MHD) models, solved on uniform Cartesian grids using finite-difference methods and explicit time stepping.
The codes evolve the density, velocity, and magnetic fields in time while accounting for nonlinear transport, viscous effects, pressure forces, quantum pressure, Lorentz forces, and stochastic perturbations.
📌 Model Overview
The repository includes both 2D and 3D MHD formulations.
Three-Dimensional Model
The 3D system consists of:
- Density field:
ρ(x,y,z,t) - Velocity field:
u = (u, v, w) - Magnetic field:
B = (Bx, By, Bz)
Two-Dimensional Model
The 2D system consists of:
- Velocity field:
u = (u, v) - Magnetic field:
B = (Bx, By)
The governing dynamics include:
- Nonlinear advection terms
- Viscous dissipation and pressure gradients
- Quantum pressure contribution
- Magnetic Lorentz force
(∇ × B) × B - Stochastic forcing driven by Wiener processes
Periodic boundary conditions are implicitly assumed through the use of finite-difference shifting operators.
🧮 Numerical Method
-
Spatial discretization:
Second-order central finite differences on uniform 2D and 3D grids -
Differential operators:
Computed usinggradient,del2, and manual finite-difference stencils -
Time integration:
Explicit Euler–Maruyama scheme for stochastic differential equations -
Stochastic terms:
Noise is modeled using Gaussian random fields and truncated Fourier-type basis functions
🔄 Time-Stepping Procedure
At each time step:
- Compute spatial derivatives (gradient, divergence, curl, Laplacian)
- Evaluate deterministic forces (advection, viscosity, pressure, quantum pressure)
- Accumulate stochastic forcing terms
- Update the velocity field
- Update the magnetic field using diffusion and
curl(u × B) - Advance all fields to the next time level
📊 Visualization
After the simulation:
- 2D model: vector field plots of velocity and magnetic fields
- 3D model: mid-plane contour and surface plots of the density field
These visualizations illustrate the spatial structure and temporal evolution of the simulated fields.
⚙️ Requirements
- MATLAB (R2020a or newer recommended)
- No external toolboxes required
🚀 Usage
- Clone the repository
- Open the desired 2D or 3D MATLAB script
- Run the script to start the simulation
- View the generated figures for results
📄 Notes
- The implementations prioritize clarity and modularity over performance
- Explicit time stepping may require small time steps for stability
- The codes are intended for research and educational purposes
📝 License
This project is provided for academic and research use.
Please cite or acknowledge the source if you use or adapt this code.