moonbit-chemreport

A reusable report layer for MoonBit chemical-engineering calculations.

chemical-engineering
report
benchmark
bundle
markdown
html
json
moon add Lyhdsba/moonbit-chemreport@0.2.0
Download zip
Author
Version
0.2.0
License
Apache-2.0
Last updated
6 days ago
Downloads
2
README

#moonbit-chemreport

MoonBit chemical-engineering calculations often start in focused packages: reactor sizing, distillation, mass balance, energy balance, property lookup, and equipment checks. moonbit-chemreport provides the report layer that those packages can share: a stable model for inputs, assumptions, formulas, results, warnings, and data sources, plus Markdown, HTML, and JSON exporters.

The project is intentionally small at the boundary and expandable inside. It is not a process simulator. It is the part a simulator, spreadsheet importer, or operator-facing CLI can call after the numbers are already computed.

#What It Provides

  • A reusable ChemReport data model.
  • Constructors for quantities, calculation inputs, assumptions, formulas, results, warnings, and data sources.
  • Markdown export for lab notes, GitHub issues, and handoff documents.
  • HTML export for dashboards and static report previews.
  • JSON export for integration tests, web frontends, and downstream tools.
  • Validation helpers that catch missing and empty report fields and highlight hazard-level warnings.
  • ReportMetrics for completeness counts and ReportBundle for batch validation, aggregate metrics, and combined Markdown/JSON output.
  • Worked examples for mass balance, energy balance, binary distillation, and reactor conversion.
  • Three NIST SRD 69 Antoine-equation benchmark records for water, ethanol, and benzene, each carrying CAS number, temperature range, coefficient values, and source URL.

#Quick Start

moon check --deny-warn moon test --deny-warn moon run cmd/main

The CLI prints the built-in CSTR mass-balance report as Markdown.

It also prints the NIST benchmark bundle summary so the repository has a repeatable, source-aware data path that can be exercised without network access.

#API Sketch

///|
let r = report(
"CSTR A-101 Mass Balance",
summary="A stable report record for a reactor inlet/outlet balance.",
inputs=[
input(
"feed flow",
quantity("100.0", "kmol/h"),
note="measured at battery limit",
),
],
assumptions=[assumption("steady state", "accumulation term is zero")],
formulas=[formula("A in", "F_A,in = F_feed * z_A", ["F_feed", "z_A"])],
results=[
result("A feed", quantity("42.0", "kmol/h"), procedure="100.0 * 0.42"),
],
warnings=[caution("conversion target should be reconciled before scale-up")],
sources=[source("design basis", "internal design basis document")],
)

///|
let markdown = r.to_markdown()

///|
let html = r.to_html_document()

///|
let json = r.to_json()

#Package Shape

  • model.mbt: report records and constructors.
  • validate.mbt: consistency checks and blocking issue detection.
  • markdown.mbt: Markdown renderer.
  • html.mbt: HTML fragment/document renderer.
  • json_export.mbt: stable JSON string renderer.
  • metrics.mbt: completeness metrics for one report.
  • bundle.mbt: batch report validation, aggregation, and export.
  • examples.mbt: mass-balance, energy-balance, distillation, and reactor examples.
  • benchmarks.mbt: NIST SRD 69 Antoine benchmark records.
  • cmd/main: simple runnable entry point.

#Competition Fit

This project targets the MoonBit ecosystem's engineering infrastructure and application-ecosystem directions. It avoids reimplementing chemical calculations already owned by future domain packages; instead it supplies the common reporting surface those packages need to present assumptions, formulas, warnings, and source traceability in one place.

Before development, keyword checks around chemreport, chemical report, massbalance, reactor, and distill on mooncakes.io did not show a mature package with the same report-layer scope. The benchmark data is deliberately kept as report fixtures rather than a new property database, so the project continues to complement, rather than duplicate, future chemical calculation packages.

#Quality Gates

The repository is prepared for the current MoonBit toolchain flow:

moon fmt --check moon check --deny-warn moon info moon test --deny-warn

The current MoonBit toolchain accepts strict warnings on moon check and moon test; moon info generates the checked-in public interface. CI runs these checks on Linux, macOS, and Windows.

#Source And Maintenance Notes

All source code in this repository is original for moonbit-chemreport, except for the initial project scaffold generated by moon new and the Apache-2.0 license text. The worked-example numbers are demonstration data, not design advice. The three Antoine coefficient records are source-aware benchmark fixtures transcribed from NIST Chemistry WebBook SRD 69; see docs/benchmarks.md for provenance, ranges, and limitations. The intended maintenance path is to add typed adapters for MoonBit chemical-engineering libraries as those packages appear, while keeping the core report schema stable.

#License

Apache-2.0.

#
Assumption

pub struct Assumption {
title : String
detail : String
} derive(Eq,
Debug
)

#
BenchmarkCase

pub struct BenchmarkCase {
id : String
category : String
report : ChemReport
} derive(Eq,
Debug
)

#
BundleIssue

pub struct BundleIssue {
report_index : Int
issue : ReportIssue
} derive(Eq,
Debug
)

#
BundleMetrics

pub struct BundleMetrics {
report_count : Int
publishable_count : Int
blocking_count : Int
input_count : Int
result_count : Int
source_count : Int
warning_count : Int
hazard_count : Int
} derive(Eq,
Debug
)

#
ChemInput

pub struct ChemInput {
name : String
value : Quantity
note : String
} derive(Eq,
Debug
)

#
ChemReport

pub struct ChemReport {
title : String
summary : String
inputs : Array[ChemInput]
assumptions : Array[Assumption]
formulas : Array[Formula]
results : Array[ChemResult]
warnings : Array[ReportWarning]
sources : Array[DataSource]
} derive(Eq,
Debug
)

#
ChemReport::has_blocking_issue

fn ChemReport::has_blocking_issue(self : ChemReport) -> Bool

#
ChemReport::is_publishable

fn ChemReport::is_publishable(self : ChemReport) -> Bool

#
ChemReport::metrics

fn ChemReport::metrics(self : ChemReport) -> ReportMetrics

#
ChemReport::to_html_document

fn ChemReport::to_html_document(self : ChemReport) -> String

#
ChemReport::to_html_fragment

fn ChemReport::to_html_fragment(self : ChemReport) -> String

#
ChemReport::to_json

fn ChemReport::to_json(self : ChemReport) -> String

#
ChemReport::to_markdown

fn ChemReport::to_markdown(self : ChemReport) -> String

#
ChemReport::validate

fn ChemReport::validate(self : ChemReport) -> Array[ReportIssue]

#
ChemResult

pub struct ChemResult {
name : String
value : Quantity
procedure : String
} derive(Eq,
Debug
)

#
DataSource

pub struct DataSource {
label : String
citation : String
url : String
} derive(Eq,
Debug
)

#
Formula

pub struct Formula {
name : String
expression : String
variables : Array[String]
} derive(Eq,
Debug
)

#
Quantity

pub struct Quantity {
value : String
unit : String
} derive(Eq,
Debug
)

#
ReportBundle

pub struct ReportBundle {
title : String
reports : Array[ChemReport]
} derive(Eq,
Debug
)

#
ReportBundle::has_blocking_issue

fn ReportBundle::has_blocking_issue(self : ReportBundle) -> Bool

#
ReportBundle::metrics

fn ReportBundle::metrics(self : ReportBundle) -> BundleMetrics

#
ReportBundle::to_json

fn ReportBundle::to_json(self : ReportBundle) -> String

#
ReportBundle::to_markdown

fn ReportBundle::to_markdown(self : ReportBundle) -> String

#
ReportBundle::validate

fn ReportBundle::validate(self : ReportBundle) -> Array[BundleIssue]

#
ReportIssue

pub struct ReportIssue {
kind : ReportIssueKind
message : String
} derive(Eq,
Debug
)

#
ReportIssueKind

pub enum ReportIssueKind {
MissingTitle
MissingInput
MissingResult
MissingSource
HazardWarning
EmptyInputName
EmptyInputValue
EmptyResultName
EmptyResultValue
EmptySourceCitation
} derive(Eq,
Debug
)

#
ReportMetrics

pub struct ReportMetrics {
input_count : Int
assumption_count : Int
formula_count : Int
result_count : Int
warning_count : Int
source_count : Int
issue_count : Int
hazard_count : Int
} derive(Eq,
Debug
)

#
ReportWarning

pub struct ReportWarning {
severity : Severity
message : String
} derive(Eq,
Debug
)

#
Severity

pub enum Severity {
Info
Caution
Hazard
} derive(Eq,
Debug
)

#
assumption

fn assumption(title : String, detail : String) -> Assumption

#
caution

fn caution(message : String) -> ReportWarning

#
formula

fn formula(name : String, expression : String, variables : Array[String]) -> Formula

#
hazard

fn hazard(message : String) -> ReportWarning

#
info

fn info(message : String) -> ReportWarning

#
input

fn input(name : String, value : Quantity, note? : String) -> ChemInput

#
issue

fn issue(kind : ReportIssueKind, message : String) -> ReportIssue

#
nist_benchmark_bundle

fn nist_benchmark_bundle() -> ReportBundle

#
nist_vapor_pressure_benchmarks

fn nist_vapor_pressure_benchmarks() -> Array[BenchmarkCase]

#
quantity

fn quantity(value : String, unit : String) -> Quantity

#
report

fn report(title : String, summary? : String, inputs? : Array[ChemInput], assumptions? : Array[Assumption], formulas? : Array[Formula], results? : Array[ChemResult], warnings? : Array[ReportWarning], sources? : Array[DataSource]) -> ChemReport

#
report_bundle

fn report_bundle(title : String, reports : Array[ChemReport]) -> ReportBundle

#
result

fn result(name : String, value : Quantity, procedure? : String) -> ChemResult

#
sample_distillation_report

fn sample_distillation_report() -> ChemReport

#
sample_energy_balance_report

fn sample_energy_balance_report() -> ChemReport

#
sample_mass_balance_report

fn sample_mass_balance_report() -> ChemReport

#
sample_reactor_conversion_report

fn sample_reactor_conversion_report() -> ChemReport

#
source

fn source(label : String, citation : String, url? : String) -> DataSource

#
warning

fn warning(severity : Severity, message : String) -> ReportWarning

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io