A MoonBit plasma numerics toolkit for teaching, research prototypes, and lightweight engineering calculations.
moon check
moon test
moon run cmd/main///|
test {
let lambda = debye_length(11604.51812, 1.0e18)
assert_true(lambda > 1.0e-7)
assert_true(lambda < 1.0e-4)
let omega = electron_plasma_frequency(1.0e18)
assert_true(omega > 1.0e10)
}///|
test {
let grid = Grid1D::new(32, 1.0)
let particles = two_stream_particles(64, 1.0, 1.0e5)
let state = PicState::new(grid, particles).run(1.0e-12, 4)
assert_eq(state.particles.length(), 64)
assert_eq(state.field.electric.length(), 32)
}///|
test {
let config = VlasovConfig::new(
Grid1D::new(16, 1.0),
velocity_min=-4.0,
velocity_max=4.0,
velocity_bins=8,
dt=0.002,
)
let state = make_landau_initial(config, density0=1.0e12, thermal_speed=1.0)
let next = state.step()
assert_true(next.time > state.time)
}///|
test {
let grid = Grid1D::new(8, 1.0)
let state = PicState::new(grid, two_stream_particles(8, 1.0, 2.0))
let samples = trace_pic(state, 1.0e-12, 2)
assert_eq(samples.length(), 3)
}moon fmt --check
moon check --deny-warn
moon test --deny-warn
moon info --target allpub(all) struct PlasmaBenchmarkReport {
cases : Array[PlasmaBenchmarkCase]
total_steps : Int
} derive(ToJson, Debug)fn VlasovConfig::new(grid : Grid1D, velocity_min~ : Double, velocity_max~ : Double, velocity_bins~ : Int, dt~ : Double) -> VlasovConfigpub(all) struct VlasovState {
config : VlasovConfig
distribution : Array[Double]
charge_density : Array[Double]
time : Double
} derive(ToJson, Debug)fn apply_boundary_to_particle(grid : Grid1D, boundary : Boundary1D, particle : Particle) -> Particle?fn debye_length(electron_temperature_k : Double, electron_density_m3 : Double) -> Doublefn distribution_mass_error(config : VlasovConfig, left : ArrayView[Double], right : ArrayView[Double]) -> Doublefn electron_plasma_frequency(electron_density_m3 : Double) -> Doublefn gyro_frequency(charge_c : Double, magnetic_field_t : Double, mass_kg : Double) -> Doublefn landau_damping_rate(wave_number_m : Double, electron_temperature_k : Double, electron_density_m3 : Double) -> Doublefn make_landau_initial(config : VlasovConfig, density0~ : Double, thermal_speed~ : Double, perturbation? : Double, mode? : Int) -> VlasovStatefn plasma_frequency(density_m3 : Double, charge_c? : Double, mass_kg? : Double) -> Doublefn plasma_parameter(electron_density_m3 : Double, debye_length_m : Double) -> Doublefn sampled_beam(config : VlasovConfig, density~ : Double, center_velocity~ : Double, thermal_speed~ : Double) -> Array[Double]fn sampled_maxwellian(config : VlasovConfig, density~ : Double, thermal_speed~ : Double) -> Array[Double]fn solve_periodic_poisson(grid : Grid1D, source : ArrayView[Double], max_iterations? : Int, tolerance? : Double) -> PoissonResultA MoonBit plasma numerics toolkit for teaching, research prototypes, and lightweight engineering calculations.