lmphysics guide

Project Chrono contact formulations, integrator and solver selection, mechanism modeling, pose export, and the standard lmcode_std_v3 library for lmphysics.

Overview

lmphysics embeds Project Chrono, Bullet collision detection, Eigen linear algebra, an expression evaluator for time-dependent loads and motors, and the lmcode-cpp runtime into a single executable. Scripts construct a System world using either non-smooth contact complementarity (nsc) or smooth penalty contact (smc), attach bodies and joints, step forward at a fixed time step, verify conservation or closed-form oracles, and export CSV time series.

Contact formulations, integrators, and solvers

Choosing the right combination of contact mode, time integrator, and solver is essential for physical accuracy and numerical stability:

ScenarioRecommended configurationBehavior and trade-offs
Collisions, sliding friction, and stacks (NSC)phys.system("nsc"), default integrator("euler"), solver("psor", 100) or solver("apgd", 200)Handles non-smooth impacts and Coulomb friction cone complementarity; use apgd with higher iterations for tall stacks.
Smooth mechanisms and energy conservationintegrator("hht") (presets sparse_lu, 30 Newton iterations, rtol 1e-6, atol 1e-9)Conserves pendulum and gyroscope mechanical energy closely; cannot be used with active NSC contacts or over-constrained 3D planar loops.
Constant acceleration, springs, and redundant planar linkagesintegrator("trapezoidal") with default PSOR solverExact for constant forces and stable for planar four-bar or slider-crank linkages built from 3D joints.
Penalty contact with material stiffness (SMC)phys.system("smc") with material(name, mu, e) and stiffness(name, young, poisson)Resolves contact via Hertzian spring-dashpot forces using Young's modulus (default 2e7 Pa) and Poisson ratio (default 0.3).

Practical contact and mechanism rules

Multi-host plotting and 3D pose rendering

System.record(name, columns) logs comma-separated body or joint columns at t = 0 and after every recorded step (controlled by System.record_every(n)), and System.save_csv(path) flushes the table to disk. Body columns include mass, x, y, z, qw, qx, qy, qz (Hamilton quaternion, scalar first), vx, vy, vz, wx, wy, wz, lx, ly, lz, speed, and ke. Joint columns include angle, travel, length, force, torque, effort, fx, fy, fz, tx, ty, and tz. Subsequent _lmcode_ blocks in the same LMScript file can plot curves with lmplot, draw free-body diagrams with lmdraw, or pass recorded positions and quaternions to lmcad and lmblender.

Standard lmcode_std_v3 library

Alongside context phys: Phys, lmphysics includes the standard lmcode_std_v3 catalog (cpp/std/lmcode-std.schema.json) of string, encoding, math, collection (IntList, FloatList, StrList, IntMap, FloatMap, StrMap, stacks, queues, priority queues), JSON, template, file, and return-framing functions. The pinned catalog in this repository does not include the REST and CLI interfaces (RestGet, CliCommand, rest_serve and related functions).