moonshock

    纯 MoonBit 一维理想气体 Euler 求解、精确 Riemann 参照与守恒诊断

    numerical
    Euler
    Riemann
    finite-volume
    Download zip
    Version
    0.1.0
    License
    MIT
    Last updated
    7 hours ago
    Downloads
    5

    No dependencies

    #MoonShock

    纯 MoonBit 的一维可压缩理想气体 Euler 方程库。它将精确 Riemann 参照、有限体积时间推进、守恒诊断、恢复与数据交换放在同一套可校验的接口中,供数值方法开发、科学计算教学和嵌入式仿真工具复用。

    模块:ZJH-666-ZJH/moonshock@0.1.0。许可证:MIT。源码与问题反馈:GitHub。MoonCakes。

    #解决什么问题

    编写一个激波管样例后,通常还需要自己处理物理状态校验、误差参照、边界通量记账、断点恢复和网格比较。MoonShock 提供可复用的库接口和三个带断言的完整工作流:

    • 数值方法开发者输入 Sod/Lax/自定义左右状态,运行 HLL 或 Rusanov,取得精确解误差和守恒残差。
    • 教学者输入周期熵波和一组分辨率,与解析单元平均值比较,观察误差与实测收敛阶。
    • 应用开发者导入严格实验 JSON,批量运行、按时间采样,通过 checkpoint 恢复、CSV 交换或守恒重映射接入后续计算。

    #环境与安装

    发布版本要求 moonc 0.10.20+65efd5b93(高于赛事要求的 0.10.16),采用该版本的 #derive 语法;CI 固定使用该编译器,不随 latest 漂移。可在 MoonBit 官网 安装工具链,并运行 moon version --all 核对编译器。JS 运行需要 Node.js;native 需要 C 编译器。库无第三方运行依赖。

    创建一个空目录并执行:

    moon new moonshock-consumer cd moonshock-consumer moon add ZJH-666-ZJH/moonshock@0.1.0

    在消费者的 cmd/main/moon.pkg 中导入模块(若生成的目录不同,以自己的主程序目录为准):

    import {
    "ZJH-666-ZJH/moonshock" @gas,
    }

    options("is-main": true)

    将该目录下的 main.mbt 替换为:

    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}")
    }
    }

    运行 moon run cmd/main --target wasm-gc。输出四列 x,rho,velocity,pressure 数值表。该片段也是仓库 Sod 示例 的简化消费方式。

    #实现范围

    守恒变量为密度、动量密度、总能量密度;原始变量为密度、速度、压力,采用常数热容比 gamma > 1 的理想气体状态方程。所有输入应使用一致单位。

    能力接口与行为
    热力学与通量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;解析周期波误差、观测阶与守恒审计

    pkg.generated.mbti 是完整公开接口清单。设计说明 说明数值约束与误差语义;格式说明 给出 JSON/CSV 和恢复约定。

    #可运行的工作流

    克隆仓库后运行以下命令;每个示例均包含结果断言,失败会以非零状态退出。

    moon run examples/sod --target wasm-gc moon run examples/restart --target wasm-gc moon run examples/study --target wasm-gc

    • sod:96 单元演化至 0.15,比较非真空精确参照,检查边界尚未影响参照和守恒残差。默认策略下密度归一化 L1 误差约 0.00541。
    • restart:计算至 0.05,JSON 保存/恢复,再按 0.075/0.1 采样;检查相同时间分段的结果、CSV 往返及 48→96 单元重映射的积分守恒。
    • study:24/48/96 单元周期熵波,输出实测误差与阶;再验证完整配置往返和独立批量运行。默认设置下末级观测阶约 2.06,该数值只对应本例,不代表所有间断解都有二阶收敛。

    更改数值策略的例子:

    let 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,
    )

    实验配置采用 experiment.json_config() 导出,再以 @gas.parse_experiment(text).run() 消费,避免手写不完整配置。checkpoint 不包含数值策略;恢复后须显式提供 SolverConfig。run_until 返回新快照,错误不会改变输入快照;cells() 返回数组副本。

    #检查、构建与测试

    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.py

    将 wasm-gc 替换为 wasm、js、native 可检查其余后端。CI 对四个后端分别执行严格检查、构建、全部测试、三个示例及独立数值对照,另外检查格式和最低编译器版本。当前有 44 项测试,包含 12 种数值策略组合的恒定态、强激波、双稀疏波、壁面碰撞、守恒、恢复与严格解析路径。

    独立对照脚本仅用 Python 标准库,采用带导数的 Newton 求根,与库的二分算法不同;42 组确定性初值覆盖不同热容比、密度、速度、压力,输出 378 个状态,并检查 Rankine–Hugoniot 激波条件与稀疏扇不变量。它提供有界差分与物理不变量证据,不声称形式证明或覆盖全部浮点输入。

    #数值与资源限制

    • 只实现一维、无粘、单种常热容比理想气体。无真空生成解,无多维网格、化学反应、重力、GPU 或工程安全认证。真空输入明确返回错误。
    • 数值解使用单元平均值;激波实验误差参照取单元中心的精确点值,间断附近存在采样约定误差。周期熵波收敛研究使用解析单元平均值。
    • reference_unaffected_by_boundaries 仅在双端流出且精确波尚未到边界时为真;为假时不能把该误差当作有限域的物理精度证据。HLL/Rusanov 的数值扩散会拓宽激波和接触间断。
    • 正性检查与缩步重试是失败检测与恢复机制,不构成任意输入的全局正性证明。极端浮点范围、不可表示网格/时间、预算耗尽会报错。
    • 网格 2..1,000,000 单元;单次最多 10,000,000 接受步,单步最多 40 次缩步;累计步数及重试不超过 1,000,000,000。大坐标偏移要求 dx ≥ 3.6e-15 × max(abs(left),abs(right)),以保留可分辨坐标。
    • 批量实验最多 1,000 项;输入规模和时间预算由调用者控制。checkpoint/CSV 至多 256,000,000 UTF-16 代码单元,实验 JSON 至多 1,000,000。不能将这些上限直接用作不可信公网服务的内存/CPU 配额。
    • 固定 CSV 只接受数值四列,不支持引号/注释/任意列名。重映射是同一物理区间的分片常量投影,会损失亚单元结构;重网格开启新的守恒账本。
    • checkpoint 不是签名格式;内部边界账本用于数值审计,不证明数据来源可信。反序列化拒绝重复、缺失、额外字段和非物理单元。

    #许可证、参考和 AI 使用

    项目源码按 MIT 发布。MoonBit core 为官方运行依赖。数学设计参考 Clawpack Riemann Book 的 Euler 章节,本项目独立实现算法及测试,没有复制其代码或测试数据,也不声明为 Clawpack 的完整移植。详见 来源与边界。

    项目在参与者授权下使用 AI 编程代理协助选题检索、实现、测试、文档和发布;质量结论以可运行测试、公开 CI 与发布消费者验证为依据。查重范围与相邻方案差异记录在 选题证据,不宣称穷尽生态或绝对唯一。

    GasError

    pub suberror GasError {
    Invalid(String)
    Numerical(String)
    } derive(
    Debug
    )

    Recoverable invalid input or numerical failure. No invalid state is silently clipped.

    GasError::to_repr

    BatchOutcome

    pub(all) enum BatchOutcome {
    Succeeded(ExperimentResult)
    Failed(String, String)
    } derive(
    Debug
    )

    Boundaries

    pub(all) enum Boundaries {
    Periodic
    Ends(EndBoundary, EndBoundary)
    } derive(Eq,
    Debug
    )

    Boundaries::equal

    fn Boundaries::equal(Boundaries, Boundaries) -> Bool

    Boundaries::not_equal

    fn Boundaries::not_equal(x : Boundaries, y : Boundaries) -> Bool

    Conserved

    pub(all) struct Conserved {
    mass : Double
    momentum : Double
    energy : Double
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Cell average or integrated flux: density, momentum and total energy.

    Conserved::equal

    fn Conserved::equal(Conserved, Conserved) -> Bool

    Conserved::max_abs

    fn Conserved::max_abs(self : Conserved) -> Double

    Conserved::minus

    fn Conserved::minus(self : Conserved, other : Conserved) -> Conserved

    Conserved::not_equal

    fn Conserved::not_equal(x : Conserved, y : Conserved) -> Bool

    Conserved::plus

    fn Conserved::plus(self : Conserved, other : Conserved) -> Conserved

    Conserved::scaled

    fn Conserved::scaled(self : Conserved, factor : Double) -> Conserved

    Conserved::to_json

    Conserved::zero

    fn Conserved::zero() -> Conserved

    ConvergenceRow

    pub(all) struct ConvergenceRow {
    cells : Int
    dx : Double
    error : ErrorNorm
    observed_order : Double?
    steps : Int
    conservation_residual : Conserved
    } derive(
    Debug
    )

    One completed resolution of an analytic periodic entropy-wave study.

    Diagnostics

    pub(all) struct Diagnostics {
    totals : Conserved
    min_density : Double
    min_pressure : Double
    max_mach : Double
    max_speed : Double
    density_variation : Double
    kinetic_energy : Double
    entropy_integral : Double
    } derive(
    Debug
    ,
    ToJson
    )

    Integrated conserved quantities, minima and resolution-independent diagnostics.

    EndBoundary

    pub(all) enum EndBoundary {
    Outflow
    Wall
    } derive(Eq,
    Debug
    )

    Both ends are periodic together, or each end independently transmits/reflects.

    EndBoundary::equal

    fn EndBoundary::equal(EndBoundary, EndBoundary) -> Bool

    EndBoundary::not_equal

    fn EndBoundary::not_equal(x : EndBoundary, y : EndBoundary) -> Bool

    ErrorNorm

    pub(all) struct ErrorNorm {
    l1 : Double
    l2 : Double
    linf : Double
    } derive(
    Debug
    ,
    ToJson
    )

    ErrorNorm::to_json

    Experiment

    pub struct Experiment {
    name : String
    gas : Gas
    mesh : Mesh
    left : Primitive
    right : Primitive
    interface_at : Double
    end_time : Double
    config : SolverConfig
    } derive(
    Debug
    )

    A complete named shock-tube experiment. Construction validates all inputs.

    Experiment::json_config

    fn Experiment::json_config(self : Experiment) -> String

    Portable JSON describing precisely the validated inputs used by this experiment.

    Experiment::new

    fn Experiment::new(name : String, gas : Gas, mesh : Mesh, left : Primitive, right : Primitive, interface_at : Double, end_time : Double, config : SolverConfig) -> Experiment raise GasError

    Experiment::run

    Runs a gas experiment and labels whether waves have reached either boundary. Exact Riemann comparisons are meaningful only before boundary interactions, and for an outflow experiment; the flag encodes both conditions.

    ExperimentResult

    pub(all) struct ExperimentResult {
    name : String
    simulation : Simulation
    density_error : ErrorNorm
    reference_unaffected_by_boundaries : Bool
    } derive(
    Debug
    )

    FluxMethod

    pub(all) enum FluxMethod {
    Hll
    Rusanov
    } derive(Eq,
    Debug
    )

    HLL uses two signal speeds; Rusanov uses a symmetric local maximum.

    FluxMethod::equal

    fn FluxMethod::equal(FluxMethod, FluxMethod) -> Bool

    FluxMethod::not_equal

    fn FluxMethod::not_equal(x : FluxMethod, y : FluxMethod) -> Bool

    Gas

    pub struct Gas {
    gamma : Double
    } derive(Eq,
    Debug
    )

    A finite heat capacity ratio greater than one.

    Gas::advance

    fn Gas::advance(self : Gas, mesh : Mesh, cells : Array[Conserved], dt : Double, bc : Boundaries, mode : Reconstruction, scheme : FluxMethod, integrator : Integrator) -> StepResult raise GasError

    The input array is never mutated, including when a stage fails. Stage CFL is checked for both RK evaluations; caller may retry with a smaller dt.

    Gas::conserved

    fn Gas::conserved(self : Gas, q : Primitive) -> Conserved raise GasError

    Gas::density_error

    fn Gas::density_error(self : Gas, mesh : Mesh, cells : Array[Conserved], reference : Array[Primitive]) -> ErrorNorm raise GasError

    Compare cell-average primitives to an exact center-value reference. At discontinuities this reports the chosen sample convention, not a rigorous bound.

    Gas::diagnostics

    fn Gas::diagnostics(self : Gas, mesh : Mesh, cells : Array[Conserved]) -> Diagnostics raise GasError

    Gas::entropy_convergence

    fn 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 GasError

    Run a resolution study against analytic cell averages, not midpoint samples. Resolutions must strictly increase. An order is reported only for positive successive errors; a zero error cannot yield a meaningful logarithmic ratio. Periodicity is required so the reference remains valid after a full transit.

    Gas::entropy_wave

    fn Gas::entropy_wave(self : Gas, mesh : Mesh, mean_density : Double, amplitude : Double, velocity : Double, pressure : Double, phase : Double) -> Array[Conserved] raise GasError

    A periodic smooth entropy wave: constant pressure and velocity, varying density. Integral cell averages use analytic averaging of the sinusoid.

    Gas::equal

    fn Gas::equal(Gas, Gas) -> Bool

    Gas::gamma

    fn Gas::gamma(self : Gas) -> Double

    Gas::import_csv

    fn Gas::import_csv(self : Gas, mesh : Mesh, text : String) -> Array[Conserved] raise GasError

    Import primitive cell averages on a supplied mesh. Coordinates must match centers. Quoting, comments, extra columns/rows and blank interior rows are rejected.

    Gas::integrate

    fn Gas::integrate(self : Gas, mesh : Mesh, cells : Array[Conserved], left : Double, right : Double) -> Conserved raise GasError

    Integrate an interval of piecewise constant conserved cell averages.

    Gas::interface_fluxes

    fn Gas::interface_fluxes(self : Gas, mesh : Mesh, states : Array[Conserved], boundaries : Boundaries, mode : Reconstruction, scheme : FluxMethod) -> Array[Conserved] raise GasError

    Gas::mach

    fn Gas::mach(self : Gas, q : Primitive) -> Double raise GasError

    Gas::max_speed

    fn Gas::max_speed(self : Gas, q : Primitive) -> Double raise GasError

    Gas::new

    fn Gas::new(gamma : Double) -> Gas raise GasError

    Gas::not_equal

    fn Gas::not_equal(x : Gas, y : Gas) -> Bool

    Gas::numerical_flux

    fn Gas::numerical_flux(self : Gas, left : Primitive, right : Primitive, scheme : FluxMethod) -> Conserved raise GasError

    Gas::physical_flux

    fn Gas::physical_flux(self : Gas, q : Primitive) -> Conserved raise GasError

    Gas::primitive

    fn Gas::primitive(self : Gas, u : Conserved) -> Primitive raise GasError

    Gas::remap

    fn Gas::remap(self : Gas, source : Mesh, cells : Array[Conserved], target : Mesh) -> Array[Conserved] raise GasError

    Conservative piecewise-constant overlap remapping on the exact same domain. Integrated mass/momentum/energy are preserved to floating-point summation error.

    Gas::riemann

    fn Gas::riemann(self : Gas, left : Primitive, right : Primitive) -> Riemann raise GasError

    Bracketed bisection avoids a negative Newton pressure and reports nonconvergence.

    Gas::shock_tube

    fn Gas::shock_tube(self : Gas, mesh : Mesh, left : Primitive, right : Primitive, interface_at : Double) -> Array[Conserved] raise GasError

    Piecewise-constant cell averages integrate a discontinuity even inside a cell.

    Gas::sound_speed

    fn Gas::sound_speed(self : Gas, q : Primitive) -> Double raise GasError

    Gas::specific_energy

    fn Gas::specific_energy(self : Gas, q : Primitive) -> Double raise GasError

    Gas::stable_dt

    fn Gas::stable_dt(self : Gas, mesh : Mesh, states : Array[Conserved], cfl : Double) -> Double raise GasError

    Gas::to_repr

    Gas::uniform

    fn Gas::uniform(self : Gas, mesh : Mesh, state : Primitive) -> Array[Conserved] raise GasError

    Gas::validate_cells

    fn Gas::validate_cells(self : Gas, mesh : Mesh, states : Array[Conserved]) -> Unit raise GasError

    Integrator

    pub(all) enum Integrator {
    ForwardEuler
    SspRk2
    } derive(Eq,
    Debug
    )

    Explicit Euler or strong-stability-preserving two-stage Runge-Kutta.

    Integrator::equal

    fn Integrator::equal(Integrator, Integrator) -> Bool

    Integrator::not_equal

    fn Integrator::not_equal(x : Integrator, y : Integrator) -> Bool

    Mesh

    pub struct Mesh {
    left : Double
    right : Double
    cells : Int
    dx : Double
    } derive(Eq,
    Debug
    )

    A bounded uniform mesh; coordinates describe cell edges.

    Mesh::cells

    fn Mesh::cells(self : Mesh) -> Int

    Mesh::center

    fn Mesh::center(self : Mesh, index : Int) -> Double raise GasError

    Mesh::dx

    fn Mesh::dx(self : Mesh) -> Double

    Mesh::edge

    fn Mesh::edge(self : Mesh, index : Int) -> Double raise GasError

    Mesh::equal

    fn Mesh::equal(Mesh, Mesh) -> Bool

    Mesh::left

    fn Mesh::left(self : Mesh) -> Double

    Mesh::locate

    fn Mesh::locate(self : Mesh, x : Double) -> Int raise GasError

    Mesh::new

    fn Mesh::new(left : Double, right : Double, cells : Int) -> Mesh raise GasError

    Mesh::not_equal

    fn Mesh::not_equal(x : Mesh, y : Mesh) -> Bool

    Mesh::right

    fn Mesh::right(self : Mesh) -> Double

    Mesh::to_repr

    Monitor

    pub(all) struct Monitor {
    time : Double
    steps : Int
    retries : Int
    diagnostics : Diagnostics
    conservation_residual : Conserved
    probes : Array[Probe]
    } derive(
    Debug
    ,
    ToJson
    )

    Lightweight monitor entry; no full cell array is retained.

    Monitor::to_json

    Monitor::to_repr

    Primitive

    pub(all) struct Primitive {
    rho : Double
    velocity : Double
    pressure : Double
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    Primitive state for one ideal gas. Units must be consistent across the experiment.

    Primitive::equal

    fn Primitive::equal(Primitive, Primitive) -> Bool

    Primitive::new

    fn Primitive::new(rho : Double, velocity : Double, pressure : Double) -> Primitive raise GasError

    Primitive::not_equal

    fn Primitive::not_equal(x : Primitive, y : Primitive) -> Bool

    Primitive::to_json

    Primitive::validate

    fn Primitive::validate(self : Primitive) -> Unit raise GasError

    Probe

    pub(all) struct Probe {
    x : Double
    index : Int
    state : Primitive
    mach : Double
    } derive(
    Debug
    ,
    ToJson
    )

    A spatial cell-average probe with no interpolation across discontinuities.

    Probe::to_json

    Probe::to_repr

    Reconstruction

    pub(all) enum Reconstruction {
    Constant
    Minmod
    MonotonizedCentral
    } derive(Eq,
    Debug
    )

    Limited piecewise linear primitive reconstruction, or piecewise constant.

    Reconstruction::equal

    Reconstruction::not_equal

    fn Reconstruction::not_equal(x : Reconstruction, y : Reconstruction) -> Bool

    Riemann

    pub struct Riemann {
    gas : Gas
    left : Primitive
    right : Primitive
    pressure : Double
    velocity : Double
    residual : Double
    iterations : Int
    } derive(
    Debug
    )

    Exact non-vacuum ideal-gas Riemann star state and root residual.

    Riemann::at

    fn Riemann::at(self : Riemann, x : Double, time : Double, interface_at : Double) -> Primitive raise GasError

    Riemann::iterations

    fn Riemann::iterations(self : Riemann) -> Int

    Riemann::pressure

    fn Riemann::pressure(self : Riemann) -> Double

    Riemann::profile

    fn Riemann::profile(self : Riemann, mesh : Mesh, time : Double, interface_at : Double) -> Array[Primitive] raise GasError

    Midpoint point values for an exact reference; these are not exact cell averages.

    Riemann::residual

    fn Riemann::residual(self : Riemann) -> Double

    Riemann::sample

    fn Riemann::sample(self : Riemann, xi : Double) -> Primitive raise GasError

    Sample the self-similar exact solution at xi=(x-interface)/t. At the contact itself the left star state is returned.

    Riemann::star_density

    fn Riemann::star_density(self : Riemann, left_side : Bool) -> Double raise GasError

    Riemann::to_repr

    Riemann::velocity

    fn Riemann::velocity(self : Riemann) -> Double

    Riemann::wave_speeds

    fn Riemann::wave_speeds(self : Riemann) -> Array[Double] raise GasError

    Four moving edges: left wave head/tail, right wave tail/head. A shock occupies a single speed, represented twice.

    Simulation

    pub struct Simulation {
    gas : Gas
    mesh : Mesh
    cells : Array[Conserved]
    time : Double
    steps : Int
    retries : Int
    boundary_change : Conserved
    initial_totals : Conserved
    } derive(
    Debug
    )

    An immutable snapshot accessor always returns a copy of its mutable array.

    Simulation::cells

    fn Simulation::cells(self : Simulation) -> Array[Conserved]

    Simulation::checkpoint

    fn Simulation::checkpoint(self : Simulation) -> String raise GasError

    Portable checkpoint v1. Full integrated boundary ledger is included so conservation audits survive restart. It contains no solver configuration.

    Simulation::conservation_residual

    fn Simulation::conservation_residual(self : Simulation) -> Conserved raise GasError

    Simulation::diagnostics

    fn Simulation::diagnostics(self : Simulation) -> Diagnostics raise GasError

    Simulation::gas

    fn Simulation::gas(self : Simulation) -> Gas

    Simulation::mesh

    fn Simulation::mesh(self : Simulation) -> Mesh

    Simulation::monitor

    fn Simulation::monitor(self : Simulation, coordinates : Array[Double]) -> Monitor raise GasError

    Simulation::new

    fn Simulation::new(gas : Gas, mesh : Mesh, cells : Array[Conserved], time? : Double) -> Simulation raise GasError

    Simulation::observe

    fn Simulation::observe(self : Simulation, times : Array[Double], coordinates : Array[Double], config : SolverConfig) -> (Simulation, Array[Monitor]) raise GasError

    Ordered output times permit equal entries, but reject backward or nonfinite times. Evolution is continuous between observations; every source snapshot is immutable.

    Simulation::probes

    fn Simulation::probes(self : Simulation, coordinates : Array[Double]) -> Array[Probe] raise GasError

    Simulation::profile_csv

    fn Simulation::profile_csv(self : Simulation) -> String raise GasError

    A deliberately fixed numeric table rather than a general CSV dialect. Columns: x,rho,velocity,pressure; CRLF and a single terminal newline accepted.

    Simulation::remeshed

    fn Simulation::remeshed(self : Simulation, target : Mesh) -> Simulation raise GasError

    Remapping starts a new conservation ledger at the same physical time. Accepted-step/retry counters restart; source checkpoint remains unchanged.

    Simulation::retries

    fn Simulation::retries(self : Simulation) -> Int

    Simulation::run_until

    fn Simulation::run_until(self : Simulation, end_time : Double, config : SolverConfig) -> Simulation raise GasError

    Runs transactionally: errors do not mutate the source simulation. Step budget applies to this call; cumulative accepted steps remain in the returned value.

    Simulation::steps

    fn Simulation::steps(self : Simulation) -> Int

    Simulation::time

    fn Simulation::time(self : Simulation) -> Double

    SolverConfig

    pub struct SolverConfig {
    boundaries : Boundaries
    reconstruction : Reconstruction
    flux : FluxMethod
    integrator : Integrator
    cfl : Double
    max_steps : Int
    max_retries : Int
    } derive(
    Debug
    )

    Validated policy for a bounded simulation. Read-only after construction.

    SolverConfig::new

    fn SolverConfig::new(boundaries : Boundaries, reconstruction : Reconstruction, flux : FluxMethod, integrator : Integrator, cfl? : Double, max_steps? : Int, max_retries? : Int) -> SolverConfig raise GasError

    SolverConfig::standard

    fn SolverConfig::standard() -> SolverConfig

    StepResult

    pub(all) struct StepResult {
    cells : Array[Conserved]
    boundary_change : Conserved
    } derive(
    Debug
    )

    A candidate step and the boundary contribution used in its conservation audit.

    TubeCase

    pub(all) enum TubeCase {
    Sod
    Lax
    Contact
    } derive(Eq,
    Debug
    )

    TubeCase::equal

    fn TubeCase::equal(TubeCase, TubeCase) -> Bool

    TubeCase::not_equal

    fn TubeCase::not_equal(x : TubeCase, y : TubeCase) -> Bool

    TubeCase::states

    fn TubeCase::states(self : TubeCase) -> (Primitive, Primitive)

    TubeCase::to_repr

    boundary_state

    fn boundary_state(q : Array[Primitive], index : Int, bc : Boundaries) -> Primitive raise GasError

    monitors_json

    fn monitors_json(monitors : Array[Monitor]) -> String

    parse_experiment

    fn parse_experiment(text : String) -> Experiment raise GasError

    Strict versioned experiment input. Rejects unknown/missing/duplicate fields, fractional counts, unrecognized policies and configurations outside budgets. The document represents inputs only; it never claims a run was successful.

    reconstruct

    fn reconstruct(states : Array[Primitive], boundaries : Boundaries, mode : Reconstruction) -> (Array[Primitive], Array[Primitive]) raise GasError

    Returns left and right face traces for each cell. Density/pressure positivity follows from limiting between neighboring positive cell primitive values.

    restore_checkpoint

    fn restore_checkpoint(text : String) -> Simulation raise GasError

    Rejects duplicate keys, unknown/missing fields, nonphysical states and huge input.

    run_batch

    fn run_batch(experiments : Array[Experiment]) -> Array[BatchOutcome] raise GasError

    Isolated outcomes let an embedding application report a numerical failure without dropping later experiments. Every individual run retains its budgets.