lmfluid
lmfluid is a native lmcode host that solves Poisson, heat and linear-elasticity problems with serial MFEM finite elements and 2D low-Mach flow with a D2Q9 lattice-Boltzmann solver. An lmscript program writes the model in an _lmcode_ block, run_lmcode runs it in the lmfluid binary, and results come back as CSV files and a returned value.
Install and run
npm install -g @lmctl-ai/lmctl
mkdir try-lmfluid && cd try-lmfluid
lmctl https://raw.githubusercontent.com/lmctl-ai/lmfluid/main/examples/quickstart.lms
# or write your own script; lmscript downloads the released host named by install=
lmscript poisson.lms
lmscript --check poisson.lms
The latest release is lmfluid 0.2.2 for Linux x64 and arm64 (dynamic glibc 2.35 or newer), macOS arm64 and x64, and Windows x64. The first real run downloads the binary and caches its schema; after that, lmscript --check compiles blocks without running them. Installing @latest asks the GitHub API for the release, so set GITHUB_TOKEN before running many scripts.
Minimal example
prog = _lmcode_ cli="lmfluid" install="github:lmctl-ai/lmfluid@latest";
let field = fluid.poisson(fluid.rect(12, 12, 1.0, 1.0), 2).source("-4").dirichlet(0, "x*x+y*y").solve();
fluid.assert_close(field.value(0.5, 0.5), 0.5, 0.000001);
fluid.assert_close(field.l2_error("x*x+y*y"), 0.0, 0.000001);
field.sample(41, 41).save_csv("poisson.csv");
lmcode_return_put("center", field.value(0.5, 0.5));
lmcode_return_put("dofs", field.dofs());
end _lmcode_
r = run_lmcode(prog);
println(json_stringify(r));
assert(r.ok);
lmscript poisson.lms
{"ok":true,"result":{"center":0.4999999999940105,"dofs":625}}
Host CLI and protocol
| Invocation | Effect | Exit |
|---|---|---|
| lmfluid --version | Print the name and version, for example lmfluid 0.2.2 | 0 |
| lmfluid --notices | Print the embedded third-party notices (MFEM, toolchain runtimes) | 0 |
| lmfluid --lmcode-schema --json | Print the exact embedded schema JSON (schema version 2) that lmscript compiles against | 0 |
| lmfluid --lmcode-schema | Print the signature list, one per line (same as --lmcode-signatures) | 0 |
| lmfluid --lmcode-signatures | Print all registered signatures: 60 host lines plus the 206 standard ones | 0 |
| lmfluid --lmcode FILE.dslb [FILE ...] | Load every bytecode file, then run them in order; one result frame on stdout | 0, 3 or 4 |
| lmfluid --dry-run --lmcode FILE.dslb [FILE ...] | Load and verify bytecode without solving or writing files | 0 or 3 |
| Anything else, an empty or missing file list, or an invalid LMFLUID_MAX_MEMORY_MB | Usage text on stderr and a CLI_USAGE failure frame | 2 |
Scripts normally never call these directly: run_lmcode compiles the block, invokes the host and returns a map with ok and result, or ok false with phase, code, message, line and column. The environment variable LMFLUID_MAX_MEMORY_MB sets the total memory budget in MiB (default 4096).
Host API quick reference
The schema has one context object, fluid of type Fluid, and six types. Expressions are strings in x, y, z and t.
| Call | Returns | Purpose |
|---|---|---|
| fluid.rect(nx, ny, lx, ly), fluid.box(nx, ny, nz, lx, ly, lz) | Mesh | Cartesian quad or hex mesh |
| fluid.load_mesh(path), mesh.save(path) | Mesh, void | MFEM mesh v1.0/v1.2 text file input and output |
| mesh.dimension(), mesh.elements() | int | Mesh metadata |
| fluid.poisson(mesh, order), fluid.heat(mesh, order), fluid.elasticity(mesh, order) | Problem | Finite-element problem, order 1 to 3 |
| problem.diffusion(expr), .source(expr), .initial(expr) | Problem | Scalar coefficient, source and heat initial condition |
| problem.dirichlet(attribute, expr) | Problem | Scalar essential boundary condition; attribute 0 selects all boundaries |
| problem.lame(lambda, mu), .force(fx, fy, fz), .displacement(attribute, ux, uy, uz) | Problem | Elastic material, body force and vector essential boundary condition |
| problem.tol(relative_tolerance, max_iterations) | Problem | Iterative linear solver controls |
| problem.solve(), problem.evolve(end_time, dt) | Field | Steady Poisson or elasticity field; heat field at end time |
| field.value(x, y), field.value(x, y, z, component) | float | Value at a mesh point |
| field.gradient(x, y, direction), field.gradient(x, y, z, component, direction) | float | Derivative along x (0), y (1) or z (2) |
| field.l2_error(exact), field.l2_error_vector(ex, ey, ez) | float | Integrated L2 error against an exact expression |
| field.sample(nx, ny), field.sample(nx, ny, nz) | Matrix | Sample the bounding-box grid |
| field.dofs(), .components(), .time() | int, int, float | Solution metadata |
| fluid.channel(nx, ny, nu, g), fluid.cavity(nx, ny, nu, lid_speed), fluid.periodic(nx, ny, nu) | LBM | D2Q9 flow simulation in lattice units |
| flow.obstacle(expr), flow.init(ux_expr, uy_expr), flow.run(steps) | LBM | Mark solid cells, set velocities, advance lattice steps |
| flow.velocity(ix, iy, component), .density(ix, iy), .is_solid(ix, iy) | float, float, bool | Cell values, zero-based indices |
| flow.solid_force(component), .solid_cells() | float, int | Momentum-exchange force on obstacles averaged over the last run; solid cell count |
| flow.mass(), .max_speed(), .mach(), .tau(), .kinetic_energy(), .steps() | float (steps: int) | Diagnostics over fluid cells |
| flow.sample(), flow.vorticity() | Matrix | Lattice data x, y, rho, ux, uy, speed; vorticity x, y, omega, solid |
| fluid.matrix(rows, cols), matrix.set(row, col, value) | Matrix | Zero matrix for recording results |
| matrix.rows(), .cols(), .get(row, col), .save_csv(path) | int, int, float, void | Matrix access and deterministic headerless CSV |
| fluid.eval(expr), fluid.assert_close(a, b, absolute_tolerance), fluid.assert_true(condition), fluid.print(text) | float, void | Expression helper, assertions, stderr message |
lmfluid 0.2.2 also ships the standard library lmcode_std_v3 with 206 signatures (strings, math, files, collections, Json, result sink), for example float_list and lmcode_return_put. The current lmcode_std_v3 catalog has 226 signatures including the standard REST and CLI interfaces; lmfluid picks those up when it next syncs its SDK and releases.
More documentation
- Skill: install, commands, safety rules, worked examples, exit codes and verification for agents
- Guide: concepts, architecture, domain model, boundary numbering, numerics and limits
- Reference: every type, method, CLI flag, exit code, limit and the standard library tables
- GitHub repository: source, 17 example scripts and the picture gallery