纯 MoonBit 一维理想气体 Euler 求解、精确 Riemann 参照与守恒诊断
moon new moonshock-consumer
cd moonshock-consumer
moon add ZJH-666-ZJH/moonshock@0.1.0import {
"ZJH-666-ZJH/moonshock" @gas,
}
options("is-main": true)fn main {
try {
let gas = @gas.Gas::new(1.4)
let mesh = @gas.Mesh::new(0.0, 1.0, 96)
let (left, right) = @gas.TubeCase::Sod.states()
let initial = gas.shock_tube(mesh, left, right, 0.5)
let result = @gas.Simulation::new(gas, mesh, initial)
.run_until(0.15, @gas.SolverConfig::standard())
assert_true(result.conservation_residual().max_abs() < 1.0e-11)
println(result.profile_csv())
} catch {
error => abort("MoonShock: \{error}")
}
}| 能力 | 接口与行为 |
|---|---|
| 热力学与通量 | Gas::new、Primitive::new、conserved、primitive、physical_flux;拒绝非有限数和非正密度/压力 |
| 精确参照 | riemann 用带括号二分求解非真空星区,提供波速、星区密度、空间/相似坐标采样;有迭代上限与残差检查 |
| 数值演化 | HLL/Rusanov,Constant/Minmod/MonotonizedCentral,ForwardEuler/SSPRK2;CFL (0,0.5]、阶段物理状态校验和有界重试 |
| 边界 | 周期;左右独立流出或反射壁;反射速度,记录积分边界通量 |
| 诊断 | 总质量/动量/能量、最小密度/压力、最大 Mach/波速、密度总变差、动能、熵积分、守恒残差 |
| 完整实验 | Experiment::new / run / json_config、parse_experiment、run_batch,每个失败不取消后续实验 |
| 恢复与交换 | checkpoint / restore_checkpoint、profile_csv / import_csv、remeshed / remap / integrate |
| 观测与验证 | probe、observe、entropy_convergence;解析周期波误差、观测阶与守恒审计 |
moon run examples/sod --target wasm-gc
moon run examples/restart --target wasm-gc
moon run examples/study --target wasm-gclet config = @gas.SolverConfig::new(
@gas.Boundaries::Periodic,
@gas.Reconstruction::Minmod,
@gas.FluxMethod::Rusanov,
@gas.Integrator::SspRk2,
cfl=0.3,
max_steps=10000,
max_retries=20,
)moon info
moon fmt --check
moon check --deny-warn
moon test --target wasm-gc --deny-warn
moon build --target wasm-gc --deny-warn
python3 scripts/verify_oracle.py --target wasm-gc
python3 scripts/source_inventory.pyfn Experiment::new(name : String, gas : Gas, mesh : Mesh, left : Primitive, right : Primitive, interface_at : Double, end_time : Double, config : SolverConfig) -> Experiment raise GasErrorpub(all) struct ExperimentResult {
name : String
simulation : Simulation
density_error : ErrorNorm
reference_unaffected_by_boundaries : Bool
} derive(Debug)fn Gas::advance(self : Gas, mesh : Mesh, cells : Array[Conserved], dt : Double, bc : Boundaries, mode : Reconstruction, scheme : FluxMethod, integrator : Integrator) -> StepResult raise GasErrorfn Gas::entropy_convergence(self : Gas, left : Double, right : Double, resolutions : Array[Int], mean_density : Double, amplitude : Double, velocity : Double, pressure : Double, end_time : Double, config : SolverConfig) -> Array[ConvergenceRow] raise GasErrorfn Gas::interface_fluxes(self : Gas, mesh : Mesh, states : Array[Conserved], boundaries : Boundaries, mode : Reconstruction, scheme : FluxMethod) -> Array[Conserved] raise GasErrorfn Simulation::new(gas : Gas, mesh : Mesh, cells : Array[Conserved], time? : Double) -> Simulation raise GasErrorfn Simulation::observe(self : Simulation, times : Array[Double], coordinates : Array[Double], config : SolverConfig) -> (Simulation, Array[Monitor]) raise GasErrorfn Simulation::probes(self : Simulation, coordinates : Array[Double]) -> Array[Probe] raise GasErrorfn Simulation::run_until(self : Simulation, end_time : Double, config : SolverConfig) -> Simulation raise GasErrorpub struct SolverConfig {
boundaries : Boundaries
reconstruction : Reconstruction
flux : FluxMethod
integrator : Integrator
cfl : Double
max_steps : Int
max_retries : Int
} derive(Debug)fn SolverConfig::new(boundaries : Boundaries, reconstruction : Reconstruction, flux : FluxMethod, integrator : Integrator, cfl? : Double, max_steps? : Int, max_retries? : Int) -> SolverConfig raise GasErrorfn reconstruct(states : Array[Primitive], boundaries : Boundaries, mode : Reconstruction) -> (Array[Primitive], Array[Primitive]) raise GasError