A MoonBit plasma numerics toolkit for teaching, research prototypes, and lightweight engineering calculations.
moon update
moon check --deny-warn
moon test --deny-warn
moon run cmd/main///|
test {
let grid = Grid1D::new(8, 1.0)
let state = PicState::new(grid, two_stream_particles(16, 1.0, 1.0e5))
let next = state.run(1.0e-12, 2)
assert_eq(next.particles.length(), 16)
}| Area | Representative modules |
|---|---|
| Physical relations and units | constants.mbt, formulas.mbt, physics_relations_ext.mbt, units.mbt |
| Grid and field numerics | grid*.mbt, interpolation.mbt, field*.mbt, poisson.mbt, solver_tools.mbt |
| Particle and distribution models | pic*.mbt, multispecies.mbt, sampling.mbt, shapes.mbt, vlasov*.mbt |
| Boundaries and dynamics | boundary*.mbt, integrators.mbt, magnetic.mbt, collisions.mbt, fluid.mbt |
| Analysis and export | moments.mbt, diagnostics*.mbt, spectra.mbt, phase_space.mbt, dataset.mbt, serialization.mbt |
| Reproducibility | scenarios.mbt, orchestration.mbt, benchmark_report.mbt, reproducibility.mbt, verification_bundle.mbt |
moon run cmd/mainmoon test acceptance_test.mbt
moon test advanced_test.mbt
moon test benchmark_test.mbt
moon test physics_test.mbt
moon test system_test.mbtpub(all) struct CollisionModel {
kind : CollisionKind
rate : Double
background_velocity : Double
thermal_speed : Double
} derive(ToJson, Debug)pub(all) struct ElectricFieldModel {
kind : ElectricFieldKind
amplitude : Double
offset : Double
wave_number : Double
center : Double
width : Double
slope : Double
} derive(ToJson, Debug)pub(all) struct EnsembleMember {
id : Int
seed : Int
diagnostics : Array[PicDiagnostics]
} derive(ToJson, Debug)fn ExperimentConfig::new(name : String, grid : Grid1D, steps : Int, dt : Double) -> ExperimentConfigpub(all) struct ExperimentReport {
name : String
samples : Array[ExperimentSample]
final_state : PicState
} derive(ToJson, Debug)fn FluidState::new(density : Double, velocity : Double, pressure : Double, energy : Double) -> FluidStatefn MagneticField3D::flux_through_area(field : MagneticField3D, position : Vector3, normal : Vector3, area : Double) -> Doublefn MultiSpeciesState::new(grid : Grid1D, populations : Array[SpeciesPopulation]) -> MultiSpeciesStatefn PhaseSpaceGrid::new(x_bins : Int, v_bins : Int, x_min : Double, x_max : Double, v_min : Double, v_max : Double) -> PhaseSpaceGridpub(all) struct PicConfig {
grid : Grid1D
dt : Double
steps : Int
shape : ShapeKind
boundary : Boundary1D
} derive(ToJson, Debug)pub(all) struct PipelineConfig {
name : String
grid : Grid1D
particles : Int
steps : Int
dt : Double
shape : ShapeKind
boundary : Boundary1D
} derive(ToJson, Debug)fn PipelineConfig::new(name : String, grid : Grid1D, particles : Int, steps : Int, dt : Double) -> PipelineConfigpub(all) struct PipelineFrame {
step : Int
state : PicState
diagnostics : PicDiagnostics
} derive(ToJson, Debug)pub(all) struct PipelineResult {
config : PipelineConfig
frames : Array[PipelineFrame]
} derive(ToJson, Debug)pub(all) struct PlasmaBenchmarkReport {
cases : Array[PlasmaBenchmarkCase]
total_steps : Int
} derive(ToJson, Debug)pub(all) struct Profile1D {
kind : ProfileKind
base : Double
amplitude : Double
center : Double
width : Double
wave_number : Double
floor : Double
} derive(ToJson, Debug)pub(all) struct ShapeWeights {
contributions : Array[ShapeContribution]
total : Double
count : Int
} derive(ToJson, Debug)pub(all) struct SimulationScenario {
name : String
grid : Grid1D
particles : Int
steps : Int
dt : Double
boundary : Boundary1D
shape : ShapeKind
seed : Int
} derive(ToJson, Debug)pub(all) struct ValidationReport {
valid : Bool
issues : Array[ValidationIssue]
} derive(ToJson, Debug)pub(all) struct VerificationBundle {
scenario : SimulationScenario
manifest : ReproducibilityManifest
fingerprint : ResultFingerprint
metrics : Array[QualityMetric]
invariants : Array[InvariantCheck]
} 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 advance_leapfrog(position : Double, velocity : Double, acceleration : Double, dt : Double) -> (Double, Double)fn alfven_speed(magnetic_field : Double, density : Double, mass : Double) -> Doublefn angular_frequency_from_frequency(frequency : Double) -> Doublefn apply_boundary_to_particle(grid : Grid1D, boundary : Boundary1D, particle : Particle) -> Particle?fn apply_collision(particle : Particle, model : CollisionModel, dt : Double, noise : Double) -> Particlefn apply_particle_boundary_batch(grid : Grid1D, boundary : Boundary1D, particles : ArrayView[Particle]) -> BoundaryBatchResultfn build_verification_bundle(scenario : SimulationScenario, toolchain : String) -> VerificationBundlefn central_interpolate(first : Double, second : Double, fraction : Double) -> Doublefn clamp_time_step(value : Double, minimum : Double, maximum : Double) -> Doublefn collision_frequency(density : Double, charge : Double, mass : Double, temperature : Double, log_lambda : Double) -> Doublefn collision_model(kind : CollisionKind, rate : Double, background_velocity : Double, thermal_speed : Double) -> CollisionModelfn collision_rate_for_species(species : Species, density : Double, temperature : Double, log_lambda : Double) -> Doublefn collision_summary(particles : ArrayView[Particle], model : CollisionModel, dt : Double) -> (Double, Double)fn combine_electric_models(first : ElectricFieldModel, second : ElectricFieldModel) -> ElectricFieldModelfn compare_metric_sets(first : ArrayView[QualityMetric], second : ArrayView[QualityMetric]) -> Doublefn conservation_report(charges : ArrayView[Double], energies : ArrayView[Double]) -> ConservationReportfn coulomb_logarithm(debye_length_m : Double, impact_parameter_m : Double) -> Doublefn 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 ensemble_passes(summary : EnsembleSummary, charge_tolerance : Double, energy_spread_tolerance : Double) -> Boolfn estimate_landau_rate(wave_number : Double, temperature : Double, density : Double) -> Doublefn field_model_work(model : ElectricFieldModel, charge : Double, start : Double, stop : Double, samples : Int) -> Doublefn fluid_cfl_dt(states : ArrayView[FluidState], gamma : Double, cell_width : Double, cfl : Double) -> Doublefn fluid_energy(density : Double, velocity : Double, pressure : Double, gamma : Double) -> Doublefn fluid_pressure(density : Double, temperature : Double, gas_constant : Double) -> Doublefn fluid_state_from_primitive(density : Double, velocity : Double, pressure : Double, gamma : Double) -> FluidStatefn fluid_update(state : FluidState, flux_difference : FluidFlux, dt : Double, cell_width : Double) -> FluidStatefn frequency_from_angular_frequency(angular : Double) -> Doublefn gaussian_electric_field(amplitude : Double, center : Double, width : Double, offset : Double) -> ElectricFieldModelfn gyro_frequency(charge_c : Double, magnetic_field_t : Double, mass_kg : Double) -> Doublefn gyroradius(mass : Double, speed : Double, charge : Double, magnetic : Double) -> Doublefn health_charge(grid : Grid1D, density : ArrayView[Double], expected : Double, tolerance : Double) -> HealthCheckfn health_check(name : String, metric : Double, threshold : Double, message : String) -> HealthCheckfn integrate_position(position : Double, velocity : Double, acceleration : Double, dt : Double) -> Doublefn integrate_velocity(velocity : Double, acceleration : Double, dt : Double) -> Doublefn interpolate_pair(left : Double, right : Double, fraction : Double, mode : InterpolationMode) -> Doublefn invariant_bounds(name : String, values : ArrayView[Double], low : Double, high : Double) -> InvariantCheckfn invariant_charge(grid : Grid1D, density : ArrayView[Double], expected : Double, tolerance : Double) -> InvariantCheckfn invariant_close(name : String, actual : Double, expected : Double, tolerance : Double) -> InvariantCheckfn invariant_zero_mean(name : String, values : ArrayView[Double], tolerance : Double) -> InvariantCheckfn kinetic_to_thermal_ratio(velocity : Double, temperature : Double, mass : Double) -> Doublefn landau_damping_rate(wave_number_m : Double, electron_temperature_k : Double, electron_density_m3 : Double) -> Doublefn lax_friedrichs_flux(left : FluidState, right : FluidState, gamma : Double, wave_speed : Double) -> FluidFluxfn linear_magnetic_field(origin : Vector3, uniform : Vector3, gradient : Vector3) -> MagneticField3Dfn make_landau_initial(config : VlasovConfig, density0~ : Double, thermal_speed~ : Double, perturbation? : Double, mode? : Int) -> VlasovStatefn manifest_from_scenario(scenario : SimulationScenario, toolchain : String) -> ReproducibilityManifestfn metric_l2(name : String, actual : ArrayView[Double], expected : ArrayView[Double], tolerance : Double) -> QualityMetricfn metric_relative(name : String, actual : Double, expected : Double, tolerance : Double) -> QualityMetricfn normalize_wave_number(wave_number : Double, debye : Double) -> Doublefn phase_space_energy(grid : PhaseSpaceGrid, histogram : ArrayView[Double], mass : Double) -> Doublefn pic_diagnostics_pass(values : ArrayView[PicDiagnostics], charge_tolerance : Double, energy_tolerance : Double) -> Boolfn plasma_beta(temperature : Double, density : Double, magnetic_field : Double) -> Doublefn plasma_frequency(density_m3 : Double, charge_c? : Double, mass_kg? : Double) -> Doublefn plasma_parameter(electron_density_m3 : Double, debye_length_m : Double) -> Doublefn plasma_parameter_from_state(temperature : Double, density : Double) -> Doublefn plasma_time_unit(scales : UnitScales, density : Double, mass : Double, charge : Double) -> Doublefn population_charge_density(grid : Grid1D, populations : ArrayView[SpeciesPopulation], kind : ShapeKind) -> Array[Double]fn profile_double_hump(base : Double, amplitude : Double, center : Double, width : Double) -> Profile1Dfn profile_gaussian(base : Double, amplitude : Double, center : Double, width : Double) -> Profile1Dfn profile_sinusoid(base : Double, amplitude : Double, wave_number : Double, phase : Double) -> Profile1Dfn pulse_electric_field(amplitude : Double, center : Double, width : Double, offset : Double) -> ElectricFieldModelfn reduction_error(source : Grid1D, values : ArrayView[Double], reduction : GridReduction) -> Doublefn reduction_errors(source : Grid1D, values : ArrayView[Double], reductions : ArrayView[GridReduction]) -> Array[Double]fn reduction_series(source : Grid1D, values : ArrayView[Double], resolutions : ArrayView[Int]) -> Array[GridReduction]fn relax_to_target(initial : Array[Double], target : Array[Double], factor : Double, max_iterations : Int) -> RelaxationResultfn resample_periodic(source_grid : Grid1D, source : ArrayView[Double], target_grid : Grid1D, mode : InterpolationMode) -> Array[Double]fn safe_ratio(numerator : Double, denominator : Double, fallback : Double) -> Doublefn sample_normal(count : Int, seed : Int, mean_value : Double, standard_deviation : Double) -> Array[Double]fn sample_periodic(grid : Grid1D, values : ArrayView[Double], x : Double, mode : InterpolationMode) -> 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 scenario_with_boundary(scenario : SimulationScenario, boundary : Boundary1D) -> SimulationScenariofn sinusoidal_electric_field(amplitude : Double, offset : Double, wave_number : Double, phase : Double) -> ElectricFieldModelfn solve_periodic_poisson(grid : Grid1D, source : ArrayView[Double], max_iterations? : Int, tolerance? : Double) -> PoissonResultfn solve_poisson_jacobi(grid : Grid1D, charge_density : ArrayView[Double], max_iterations : Int, tolerance : Double) -> PoissonResultfn solve_poisson_periodic(grid : Grid1D, charge_density : ArrayView[Double], max_iterations : Int, tolerance : Double) -> PoissonResultfn sound_speed_ideal(temperature : Double, mass : Double, gamma : Double) -> Doublefn stable_time_step(cell_width : Double, speed : Double, cfl : Double) -> Doublefn standard_scenario(name : String, cells : Int, particles : Int, steps : Int) -> SimulationScenariofn table_append_column(table : NumericTable, name : String, values : ArrayView[Double]) -> NumericTablefn table_filter_rows(table : NumericTable, column : Int, low : Double, high : Double) -> NumericTablefn thermal_debye_length(temperature : Double, density : Double, charge : Double) -> Doublefn thermal_speed_from_temperature(temperature : Double, mass : Double) -> Doublefn trace_field_line(position : Vector3, field : MagneticField3D, step : Double, count : Int) -> Array[Vector3]fn tridiagonal_jacobi(diagonal : ArrayView[Double], lower : ArrayView[Double], upper : ArrayView[Double], rhs : ArrayView[Double], iterations : Int) -> RelaxationResultfn validate_simulation_inputs(grid : Grid1D, dt : Double, particles : Int, steps : Int) -> ValidationReportfn verification_bundle_passes_thresholds(bundle : VerificationBundle, charge : Double, energy : Double) -> Boolfn wave_group_speed(omega_first : Double, omega_second : Double, wave_first : Double, wave_second : Double) -> Doublefn weighted_histogram_particles(grid : PhaseSpaceGrid, particles : ArrayView[Particle]) -> Array[Double]A MoonBit plasma numerics toolkit for teaching, research prototypes, and lightweight engineering calculations.