Sovereign 8s.is mirror of standardgalactic/stochastic-mhd-matlab
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
divyabalak2023-create cec3c0af1d
Update README.md
2026-02-25 10:46:26 +05:30
README.md Update README.md 2026-02-25 10:46:26 +05:30
stochastic_mhd_2d_model.m Create stochastic_mhd_2d_model.m 2026-02-25 10:41:48 +05:30
stochastic_mhd_3d.m Rename stochastic_mhd_2d.m to stochastic_mhd_3d.m 2026-02-25 10:42:39 +05:30

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 using gradient, 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:

  1. Compute spatial derivatives (gradient, divergence, curl, Laplacian)
  2. Evaluate deterministic forces (advection, viscosity, pressure, quantum pressure)
  3. Accumulate stochastic forcing terms
  4. Update the velocity field
  5. Update the magnetic field using diffusion and curl(u × B)
  6. 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

  1. Clone the repository
  2. Open the desired 2D or 3D MATLAB script
  3. Run the script to start the simulation
  4. 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.