بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ
In the name of Allah, the Compassionate, the Merciful
Flagship Modelica physical modeling and simulation compiler for ModelScript. Features a custom WebAssembly GLR incremental parser, high-performance AssemblyScript flattening kernel, direct DAE arena lowering, port balancing, unit verification, and bidirectional Triple Graph Grammar (TGG) rules for cross-domain synchronization.
- WASM GLR Incremental Parser: Generated by
@modelscript/dsl(buildParser), compiling directly to native WebAssembly (parser.wasm) for microsecond incremental parsing and syntax error recovery. - Arena-Native Flattening Pipeline: Implements
ModelicaFlattenercoordinated with an in-WASM AssemblyScript kernel (assembly/flattener.ts) supportinghybrid,wasm,ts, anddiffexecution modes. - Data-Oriented DAE Lowering: Direct lowering of equations, algorithms, and expressions into linear memory
DAEBuilderinteger IDs (ExprId,EqId,StmtId) with zero intermediate AST wrapper allocations. - Connection Balancing & Flow Variables: Rigorous topological port balancing via
ModelicaPortBalancersupporting standard and expandable connectors. - Unit & Dimensional Checking: Physical dimension inference and unit consistency verification across equations and component connections.
- Salsa Query Engine Integration: Demand-driven memoization of class instantiation, type resolution, variability, causality, and effective modifications.
- Polyglot TGG Rules: Declarative Triple Graph Grammar rules enabling bidirectional synchronization with SysML v2 blocks, OWL 2 ontological classes, and CSV telemetry datasets.
- Compiler Lints: Over 70+ static and semantic diagnostic rules aligned with OpenModelica error codes (
M1xxxthroughM6xxx).
| Path | Description |
|---|---|
src/language.ts |
Modelica 3.x grammar specification, lexer rules, and CST combinators for @modelscript/dsl (buildParser) |
src/flattener.ts |
TypeScript coordinator and hybrid bridge for the arena-native ModelicaFlattener (hybrid, wasm, ts, diff modes) |
assembly/flattener.ts |
In-WASM AssemblyScript flattening kernel lowering linear CST nodes directly into DAEBuilder |
src/queries.ts |
Salsa QueryEngine semantic queries (instantiate, classInstance, resolveSimpleName, variability, causality) |
src/connections.ts |
ModelicaPortBalancer for standard, stream, and expandable connector topological balancing |
src/units.ts |
Physical dimension inference and SI unit consistency verification |
src/lints/ |
Linear CST and semantic CompilerLint diagnostic rules (M1xxx–M6xxx) |
src/extensions/ |
Embedded multi-physics extensions: CSG (csg.ts), shapes (shape-flattener.ts), FEA/CFD studies (study-flattener.ts) |
transformers/ |
Bidirectional Triple Graph Grammar (TGG) transformers for SysML v2, OWL 2, and CSV |
tests/testsuite-runner.ts |
OpenModelica (omc) conformance testsuite runner |
tests/msl-comparison-runner.ts |
On-the-fly Modelica Standard Library (MSL) verification and benchmark runner |
- Arena-Native
ModelicaFlattener(hybrid|wasm|ts|diff): Equations, algorithm statements, and expressions are lowered directly from linear WebAssembly CST pointers intoDAEBuilderstruct-of-arrays tables without intermediate AST wrapper allocations. Combined with@modelscript/runtime, the pipeline performs constant folding (foldArenaConstants), alias elimination (eliminateArenaAliases), Pantelides index reduction, and Tarjan Block Lower Triangular (BLT) sorting. - Multi-File
WorkspaceIndex& Package Resolution: Cross-filewithinclauses,package.mo/package.orderhierarchies, and the full Modelica Standard Library (MSL) are unified into a workspace-wide symbol index with incremental Salsa dependency invalidation. - Embedded CSG, FEA & CFD Extensions: Supports native
shapeclasses and constructive solid geometry (src/extensions/csg.ts,shape-flattener.ts), automated 3D multibody mass/inertia tensor synthesis (multibody-generator.ts), and embedded continuum FEA/CFD study definitions (study-flattener.ts,studies.ts) bridged to STEP B-Rep CAD and CAE solvers.
import { Context } from "@modelscript/modelica/context";
import { createWasmParser } from "@modelscript/modelica/parser";
// 1. Initialize WASM GLR parser
const modelicaWasmPath = require.resolve("@modelscript/modelica/parser.wasm");
const { parser } = await createWasmParser(modelicaWasmPath);
Context.registerParser(".mo", parser);
// 2. Load and flatten a model
const context = new Context();
context.loadFile("file:///path/to/BouncingBall.mo", sourceCode);
// 3. Flatten directly into linear-memory DAEBuilder
const dae = context.flattenArena("BouncingBall");