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

InvocationEffectExit
lmfluid --versionPrint the name and version, for example lmfluid 0.2.20
lmfluid --noticesPrint the embedded third-party notices (MFEM, toolchain runtimes)0
lmfluid --lmcode-schema --jsonPrint the exact embedded schema JSON (schema version 2) that lmscript compiles against0
lmfluid --lmcode-schemaPrint the signature list, one per line (same as --lmcode-signatures)0
lmfluid --lmcode-signaturesPrint all registered signatures: 60 host lines plus the 206 standard ones0
lmfluid --lmcode FILE.dslb [FILE ...]Load every bytecode file, then run them in order; one result frame on stdout0, 3 or 4
lmfluid --dry-run --lmcode FILE.dslb [FILE ...]Load and verify bytecode without solving or writing files0 or 3
Anything else, an empty or missing file list, or an invalid LMFLUID_MAX_MEMORY_MBUsage text on stderr and a CLI_USAGE failure frame2

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.

CallReturnsPurpose
fluid.rect(nx, ny, lx, ly), fluid.box(nx, ny, nz, lx, ly, lz)MeshCartesian quad or hex mesh
fluid.load_mesh(path), mesh.save(path)Mesh, voidMFEM mesh v1.0/v1.2 text file input and output
mesh.dimension(), mesh.elements()intMesh metadata
fluid.poisson(mesh, order), fluid.heat(mesh, order), fluid.elasticity(mesh, order)ProblemFinite-element problem, order 1 to 3
problem.diffusion(expr), .source(expr), .initial(expr)ProblemScalar coefficient, source and heat initial condition
problem.dirichlet(attribute, expr)ProblemScalar essential boundary condition; attribute 0 selects all boundaries
problem.lame(lambda, mu), .force(fx, fy, fz), .displacement(attribute, ux, uy, uz)ProblemElastic material, body force and vector essential boundary condition
problem.tol(relative_tolerance, max_iterations)ProblemIterative linear solver controls
problem.solve(), problem.evolve(end_time, dt)FieldSteady Poisson or elasticity field; heat field at end time
field.value(x, y), field.value(x, y, z, component)floatValue at a mesh point
field.gradient(x, y, direction), field.gradient(x, y, z, component, direction)floatDerivative along x (0), y (1) or z (2)
field.l2_error(exact), field.l2_error_vector(ex, ey, ez)floatIntegrated L2 error against an exact expression
field.sample(nx, ny), field.sample(nx, ny, nz)MatrixSample the bounding-box grid
field.dofs(), .components(), .time()int, int, floatSolution metadata
fluid.channel(nx, ny, nu, g), fluid.cavity(nx, ny, nu, lid_speed), fluid.periodic(nx, ny, nu)LBMD2Q9 flow simulation in lattice units
flow.obstacle(expr), flow.init(ux_expr, uy_expr), flow.run(steps)LBMMark solid cells, set velocities, advance lattice steps
flow.velocity(ix, iy, component), .density(ix, iy), .is_solid(ix, iy)float, float, boolCell values, zero-based indices
flow.solid_force(component), .solid_cells()float, intMomentum-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()MatrixLattice data x, y, rho, ux, uy, speed; vorticity x, y, omega, solid
fluid.matrix(rows, cols), matrix.set(row, col, value)MatrixZero matrix for recording results
matrix.rows(), .cols(), .get(row, col), .save_csv(path)int, int, float, voidMatrix access and deterministic headerless CSV
fluid.eval(expr), fluid.assert_close(a, b, absolute_tolerance), fluid.assert_true(condition), fluid.print(text)float, voidExpression 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