moonbit-relief

Comprehensive MoonBit Safety Relief Calculation & Sizing Library for Process Safety Engineering

safety
relief-valve
chemical-engineering
thermodynamics
api520
moon add wjcoomk/moonbit-relief@0.1.0
Download zip
Author
Version
0.1.0
License
Apache-2.0
Last updated
12 hours ago
Downloads
1
README

#moonbit-relief

CI License MoonBit

moonbit-relief is a native MoonBit engineering library for pressure-relief device sizing and process-safety review. It combines API 520/521/526 calculations, thermodynamic property models, two-phase flashing, piping hydraulics, device selection, validation, and report generation behind composable packages.

The project is intended for engineering studies, design automation, and reproducible calculation workflows. It is not a substitute for a licensed engineer's review, governing code edition, site data, or the final design approval process.

#Capabilities

AreaFunctionality
Gas and vaporAPI 520 critical/subcritical sizing, real-gas correction, steam tables, fire heat load, blowdown and dust venting
LiquidIncompressible sizing, viscosity iteration, backpressure and overpressure corrections, thermal expansion and subcooled flashing
Two-phaseDIERS Leung Omega, TPHEM, Henry-Fauske, slip ratio, void fraction and flow-regime classification
ThermodynamicsPeng-Robinson/SRK EoS, PT/PH/PS flash solvers, Rachford-Rice, DIPPR correlations and matrix solvers
DevicesAPI 520 orifices, API 526 catalog data, spring mechanics, pilot-operated configuration, bellows and rupture disks
PipingColebrook/Darcy-Weisbach, inlet 3% rule, discharge Mach check, flare headers, water hammer and ASME B31.3 wall thickness
AssuranceInput bounds, scenario rules, API 520 checklist, LOPA/PSM review, governing envelopes and pressure sensitivity
ReportsMarkdown, HTML, text, CSV, LaTeX and SPI XML calculation outputs

#Package layout

PackagePathResponsibility
Core typessrc/typesProcess conditions, fluid properties, scenarios, errors and units
Thermodynamicssrc/thermoEoS, flash solvers, property correlations and matrix algorithms
Gassrc/gasGas/vapor and fire-case sizing
Liquidsrc/liquidLiquid sizing, viscosity and thermal relief
Two-phasesrc/twophaseDIERS and flashing-flow models
Devicessrc/devicesOrifice/device catalogs and mechanical checks
Pipingsrc/pipingRelief inlet, outlet and flare-network hydraulics
Validationsrc/validationBounds, scenarios, envelopes and safety audits
Workflowsrc/workflowTyped end-to-end case evaluation and sensitivity analysis
Reportssrc/reportEngineering report renderers
Benchmarkssrc/benchmarksStandard and textbook regression cases

#Quick start

The locally verified compiler is moonc v0.10.10+; the project verification floor is MoonBit 0.10.9 or newer within the compatible 0.10.x line.

moon version --all moon check --target all moon test --target all moon run cmd/benchmark --target native

The benchmark runner prints deterministic engineering records. See docs/benchmarks.md for the recorded command, case inputs and observed output.

#Engineering workflow API

The workflow package validates a named case, dispatches it to the phase-specific sizing engine, selects an API standard orifice, and preserves warnings for engineering review.

import {
"wjcoomk/moonbit-relief/src/types",
"wjcoomk/moonbit-relief/src/workflow",
}

fn main {
let case = @workflow.api520_gas_reference("PSV-101")
match @workflow.evaluate_case(case) {
Ok(result) => {
println("Area: \{result.required_area_mm2} mm2")
println("Orifice: \{result.selected_orifice.letter}")
println("Margin: \{result.margin_percent}%")
}
Err(error) => println(error.message())
}
}

For a custom case, construct one of the typed SizingInput variants:

let request = @workflow.SizingInput::Liquid(
proc=process_conditions,
fluid=fluid_properties,
specific_gravity=0.92,
kd=0.65,
kc=1.0,
)
let case : @workflow.ReliefDesignCase = {
tag: "P-204",
scenario: @types.ReliefScenario::ThermalExpansion,
sizing: request,
}

For multiple scenarios, call @workflow.evaluate_envelope to retain every result and identify the first maximum required area. Use @workflow.evaluate_sensitivity to inspect how a case changes under pressure offsets.

#Verification and benchmarks

The current checkout contains 7,442 lines of production MoonBit, excluding test files and src/benchmarks. It contains 100 test cases, with all four supported targets passing in the local verification run. The source count is measured rather than inferred:

$files = Get-ChildItem src -Recurse -Filter '*.mbt' | Where-Object { $_.FullName -notmatch '\\benchmarks\\' -and $_.Name -notmatch '_test\.mbt$' } ($files | Get-Content | Measure-Object -Line).Lines

The strict local checks are:

moon check --target all moon test --target all moon check --deny-warn moon test --deny-warn moon fmt --check moon info moon build --target native moon run cmd/benchmark --target native

CI repeats the all-target checks on Linux, macOS and Windows, verifies the MoonBit compatibility floor, checks formatting and generated public interfaces, and runs the native benchmark on Linux.

#Development

See CONTRIBUTING.md for the local quality gate. Keep calculations in the package that owns their domain, add black-box tests for public behavior, and document the standard or reference behind a new formula or data record.

Useful commands:

moon fmt --check moon check --deny-warn moon test --deny-warn moon info moon run cmd/benchmark --target native

Build outputs are ignored by .gitignore; do not commit _build, target, .mooncakes or generated temporary files.

#Standards and references

The implementation organizes publicly documented engineering formulations associated with:

  • API Standard 520, Parts I and II;
  • API Standard 521 and API Standard 526;
  • ASME Boiler and Pressure Vessel Code, Section VIII and ASME B31.3;
  • ISO 4126-1;
  • AIChE DIERS Leung Omega methodology;
  • Crane Technical Paper No. 410;
  • IAPWS-IF97 steam property formulations.

Standards are referenced for engineering context. Users must verify the applicable edition, jurisdictional requirements, coefficients, material data and project-specific assumptions before using a result for design.

#License

moonbit-relief is distributed under the Apache-2.0 License. Engineering references and project attribution notes are listed in NOTICE.md.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io