A MoonBit-native report layer for chemical engineering calculations.
moon update
moon check --target all --deny-warn
moon test --target all --deny-warn
moon run cmd/mainmoon run cmd/main| Area | Files | Responsibility |
|---|---|---|
| Domain model | moonbit-chemreport.mbt | Report records, enums, and constructors |
| Exporters | markdown_export.mbt, html_export.mbt, json_export.mbt, table.mbt | Deterministic human and machine output |
| Engineering math | units.mbt, balance.mbt, process_calculations.mbt | Units, balances, equipment and safety calculations |
| Scenario analysis | analytics.mbt, scenario_engine.mbt | Statistics, control limits, sweeps, and sensitivity |
| Quality | validate.mbt, quality.mbt, diagnostics.mbt | Validation, diagnostics, regression and publish gates |
| Integration | report_pipeline.mbt, benchmark.mbt | Builders, batches, and reproducible export measurements |
let result = benchmark_exports([example_chemreport()], 100)
println(result.to_markdown())moon test --target all --deny-warn
moon test --target native --enable-coverage
moon coverage report -f summary
moon coverage analyzepub struct ChemReport {
metadata : ReportMetadata
summary : String
assumptions : Array[Assumption]
inputs : Array[InputValue]
formulas : Array[FormulaNote]
results : Array[ResultValue]
warnings : Array[WarningNote]
sources : Array[SourceRef]
sections : Array[ReportSection]
tags : Array[String]
} derive(Eq, Debug)pub struct Diagnostic {
code : String
severity : DiagnosticSeverity
path : String
message : String
remediation : String
} derive(Eq, Debug)pub struct EnergyBalance {
inlet : Float
outlet : Float
residual : Float
streams : Array[EnergyStream]
} derive(Eq, Debug)fn EnergyBalance::specific_duty(self : EnergyBalance, mass : Quantity) -> Result[Quantity, QuantityError]pub struct EnergyStream {
name : String
duty : Quantity
direction : StreamDirection
} derive(Eq, Debug)pub struct MaterialBalance {
components : Array[ComponentBalance]
total_inlet : Float
total_outlet : Float
} derive(Eq, Debug)pub struct ProcessStream {
name : String
direction : StreamDirection
components : Array[ComponentFlow]
} derive(Eq, Debug)pub enum QuantityError {
IncompatibleDimensions(UnitDimension, UnitDimension)
BelowAbsoluteZero
InvalidValue
} derive(Eq, Debug)fn ReactorCase::is_safe(self : ReactorCase, temperature_limit : Float, pressure_limit : Float) -> Boolfn ReportBuilder::add_assumption(self : ReportBuilder, statement : String, impact : String) -> ReportBuilderfn ReportBuilder::add_formula(self : ReportBuilder, name : String, expression : String, explanation : String) -> ReportBuilderfn ReportBuilder::add_input(self : ReportBuilder, name : String, value : String, unit : String?, note : String?) -> ReportBuilderfn ReportBuilder::add_result(self : ReportBuilder, name : String, value : String, unit : String?, status : ResultStatus, note : String?) -> ReportBuilderfn ReportBuilder::add_section(self : ReportBuilder, title : String, kind : SectionKind, body : String) -> ReportBuilderfn ReportBuilder::add_source(self : ReportBuilder, label : String, kind : SourceKind, url : String?, license : String?, note : String?) -> ReportBuilderfn ReportBuilder::add_warning(self : ReportBuilder, code : String, severity : WarningSeverity, summary : String, action : String) -> ReportBuilderpub struct ResultValue {
name : String
value : String
unit : String?
status : ResultStatus
note : String?
} derive(Eq, Debug)pub struct ScenarioPoint {
name : String
input : Float
output : Float
score : Float
status : ResultStatus
note : String
} derive(Eq, Debug)pub struct ScenarioSeries {
name : String
points : Array[ScenarioPoint]
input_unit : String
output_unit : String
} derive(Eq, Debug)fn ScenarioSeries::quality_gate(self : ScenarioSeries, minimum_score : Float, maximum_flagged : Int) -> Boolpub struct SourceRef {
label : String
kind : SourceKind
url : String?
license : String?
note : String?
} derive(Eq, Debug)pub struct WarningNote {
code : String
severity : WarningSeverity
summary : String
action : String
} derive(Eq, Debug)fn diagnostic(code : String, severity : DiagnosticSeverity, path : String, message : String, remediation : String) -> Diagnosticfn distillation_case(feed_rate : Float, feed_fraction : Float, distillate_rate : Float, distillate_fraction : Float, bottoms_rate : Float, bottoms_fraction : Float, reflux_ratio : Float, stages : Int) -> DistillationCasefn elasticity(input_before : Float, input_after : Float, output_before : Float, output_after : Float) -> Floatfn heat_exchanger_case(hot_inlet : Float, hot_outlet : Float, cold_inlet : Float, cold_outlet : Float, hot_capacity_rate : Float, cold_capacity_rate : Float, area : Float, overall_u : Float) -> HeatExchangerCasefn interpolate_linear(x : Float, x_one : Float, y_one : Float, x_two : Float, y_two : Float) -> Floatfn latent_duty(mass_flow : Float, latent_heat : Float, vapor_fraction : Float) -> Floatfn log_mean_temperature_difference(delta_one : Float, delta_two : Float) -> Floatfn material_property(name : String, molecular_weight : Float, density : Float, heat_capacity : Float, boiling_point : Float, safety_limit : Float) -> MaterialPropertyfn pressure_drop_case(length : Float, diameter : Float, velocity : Float, density : Float, viscosity : Float, roughness : Float, fittings_k : Float) -> PressureDropCasefn pump_case(flow_rate : Float, differential_pressure : Float, efficiency : Float, fluid_density : Float, installed_power : Float) -> PumpCasefn reactor_case(name : String, feed : Float, product : Float, byproduct : Float, residence_time : Float, temperature : Float, pressure : Float) -> ReactorCasefn report(metadata : ReportMetadata, summary : String, assumptions : Array[Assumption], inputs : Array[InputValue], formulas : Array[FormulaNote], results : Array[ResultValue], warnings : Array[WarningNote], sources : Array[SourceRef], sections : Array[ReportSection], tags : Array[String]) -> ChemReportfn reynolds_number(density : Float, velocity : Float, diameter : Float, viscosity : Float) -> Floatfn safety_review(name : String, measured : Float, design_limit : Float, warning_fraction : Float, unit : String) -> SafetyReviewfn scenario_point(name : String, input : Float, output : Float, score : Float, status : ResultStatus, note : String) -> ScenarioPointfn scenario_series(name : String, points : Array[ScenarioPoint], input_unit : String, output_unit : String) -> ScenarioSeriesfn sensitivity(base : Float, delta : Float, response_base : Float, response_delta : Float) -> Floatfn stream(name : String, direction : StreamDirection, components : Array[ComponentFlow]) -> ProcessStreamfn thermal_duty(mass_flow : Float, heat_capacity : Float, inlet : Float, outlet : Float) -> Floatfn total_heat_duty(sensible : Float, latent : Float, reaction : Float) -> FloatA MoonBit-native report layer for chemical engineering calculations.