Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Units

FieldCraft stores every quantity in SI and converts only where a number crosses into or out of the program, through one table: crates/model/src/units/ (#579).

The rule

Store SI, convert only at boundaries through crates/model/src/units. The model, the result types and every solver work in metres, kilograms, seconds, newtons, pascals, kelvin and radians. A conversion factor written anywhere else is a bug, and cargo xtask unit-factors (part of cargo xtask ci) refuses one; see the end of this page.

The display system

Numbers are shown and typed in a display system: a preset with optional per-quantity overrides (fieldcraft_model::DisplaySystem).

PresetLengthMassTimeForceStressTemperature
mm-t-s-N-MPa (default)mmtsNMPa°C
m-kg-s-N-Pa (SI)mkgsNPaK
mm-kg-ms-kN-GPammkgmskNGPa°C
mm-g-ms-N-MPammgmsNMPa°C
in-lbf-s-psiinlbf·s²/inslbfpsi°F

Every other quantity’s unit follows from the preset (Quantity lists them; energy in mJ for mm-t-s, J for SI, …). Angles are radians in every preset; an override such as {"preset": "mm-t-s-N-MPa", "overrides": {"angle": "deg", "energy": "J"}} changes one quantity.

Which system applies, in order:

  1. the model’s own (model.units {system, overrides}, saved in the model as display_units),
  2. the user’s setting (Settings › General, prefs.json; ui.settings {set: {units}}),
  3. mm-t-s-N-MPa with °C.

A model migrated from format 2 keeps the system its file declared (unspecified displays as mm-t-s-N-MPa), so it shows the numbers it showed before. The defaults are pending the owner’s confirmation.

Boundaries: where conversion happens

  • Command parameters (crates/engine/src/units.rs): a bare number is in the display unit of its field’s quantity (the form schema knows it, schema::Dim); "210 GPa" or {"value": 210, "unit": "GPa"} carries its own unit. The parameters are converted field by field into the system the command works in (Frame): SI for the model and the solvers, millimetres for the geometry commands and the meshers. A value of the wrong dimension or an unknown unit is refused, naming the field. Numbers inside a JSON-valued field (a polygon, a block grid, a mesh plan object) are described by the field’s numbers and converted alike. Only Dim::Degree fields have a fixed unit.
  • The geometry frame: the geometry commands and the meshers work in millimetres, the unit SolidCraft designs are in and the meshers’ absolute floors were tuned for; the frame is internal. Their parameters, their replies (units::REPLIES, with a units map) and their messages (units::shown; the meshers’ errors keep their lengths, areas, volumes and points as data, fieldcraft_mesh::message, and EngineError::shown renders them at the command’s boundary) are in the display system like every other command’s: a datum, a mesh size or a tolerance typed as 1 in an inch display is an inch. A journal of a model from before SI storage (its header has model_units) built on a design or 3MF meshes typed the numbers of its geometry and mesher commands in millimetres whatever its system, as its stored datums, plans, seeds and size controls migrate: replay reads them in millimetres (without a design, in the declared unit), and a command typed into such a journal now is recorded with its units (Session::journal_reads).
  • Replies: each command’s dimensional reply fields are listed in units::REPLIES and converted into the display system, with a units map naming the unit of each. A fluid step’s steady-state monitor history follows its monitors, so solve.fluid converts it per monitor (velocity, temperature change, mass flow, force, heat, mean temperature) and names each one’s unit in stop.units.
  • Forms, panels, legends, probes, XY plots: the UI reads the model and results in SI and shows them through the display system (describe.rs, results.rs, results_panel.rs); an edit form is filled with the definition converted to the display system, so OK without a change gives back the same model.
  • Viewport: the scene is drawn in metres; a click that places something (a relax sphere, a node drag) writes the display units into the form. ui.camera’s distance and target and ui.worldToScreen’s points are in the display units.
  • Exports: CSV headers name their unit (fx [N]); VTU files carry a <!-- units: … --> comment and their values are in the display units; an STL file (which has no unit of its own) is in the display length, and mesh.export.stl replies with it.
  • Solver decks: written in one consistent system (deck.write {units}, default the display preset), stated in the header; Nastran gets PARAM,WTMASS,1.0, LS-DYNA *CONTROL_UNITS. Written in a model’s old system, a deck is byte-identical to before apart from the unit lines.
  • Files: .fieldcraft format 3 stores SI (see below).
  • SolidCraft’s own text (a feature’s rebuild error, the kernel’s boolean diagnostics, a feature’s stored definition) is passed on as SolidCraft wrote it, in the design’s units, and marked as SolidCraft’s (SolidCraft: …).
  • Geometry: SolidCraft designs and imported surfaces are in millimetres; their tessellations become metres where they meet the model (units::geometry_point), and the meshers run in millimetres inside the geometry frame (above). 3MF files are read in their declared unit through the table.

Fluid solver summaries

solve.fluid.max_speed is the maximum across stored frames; final_max_speed is the last frame’s maximum. Both use the display velocity unit, for CPU and GPU solves. max_speed_time is physical time in the display time unit, including ms in the millisecond presets.

To compare the final value with the viewport, open the original flow-past sample, run solve.fluid {"step":"Flow","backend":"gpu"}, select results.frame {"step":"Flow","frame":10}, and set results.contour {"step":"Flow","field":"velocity","range":"auto"}. Save existing work before opening the sample. Its 184,320-cell laminar bracket flow stores eleven physical-time frames over 16 seconds. In its default mm-t-s-N-MPa display, both speeds are in mm/s and the last-frame contour maximum matches final_max_speed. The all-frame peak can differ from it. This checks result reporting; it does not establish steady convergence or exchanger accuracy.

Where conversion never happens

The model (fieldcraft-model), the solvers (fieldcraft-solver, -fem, -explicit, -lbm, -lbm-gpu) and the result types never convert. Solver tolerances are relative (to the model’s size, the load, the stiffness) so a model in metres converges as it did in millimetres; the camera’s clipping and minimum sizes are relative or in metres (render::MIN_SIZE).

Relative is not enough where two dimensions meet in one norm. A nonlinear step’s convergence test measures each kind of freedom against its own scale (docs/manual/structural/nonlinear-static.md, Algorithm): residual forces against the largest force, residual moments against the largest moment (at least the force scale times the model’s size L), translations of a correction against the increment’s translation, rotations in radians against the increment’s rotation (at least the translation over L). One norm over newtons and newton-metres, or metres and radians, would change with the unit system and the part’s size, since a moment scales as a force times a length and a rotation not at all. The arc length of an arc-length step weighs rotations by L² for the same reason.

Exactness

A typed value is scaled on its shortest decimal form (units/decimal.rs): 3.97 mm is stored as the double nearest 0.00397 m and shown again as 3.97, for any value of up to 15 significant digits. Longer values (computed coordinates, results) are scaled by one correctly rounded operation by an exact power of ten. Offsets (°C, °F) are added in decimal: 20 °C is 293.15 K exactly, and an absolute °F, (F + 459.67) × 5/9, is worked out in decimal where the result is a short decimal (68 °F is 293.15 K). Factors that are not powers of ten (inch, pound) are applied in binary.

A command on the geometry runs on the model expressed in millimetres: the millimetre image of the stored metres, a function of the stored model alone. So a session, its undo, a saved and reopened model, a journal replay and a crash replay all give a mesher the same input, and the same result. The meshers alone (tet, hex, cells, mesh.plan.apply) give what FieldCraft 0.7 gave, and a stored model is unchanged by the move to SI. But a mesher-computed coordinate does not always survive mm → m → mm: 6–18% of them come back one ulp off. A relaxation of such a mesh (guarded or strong) amplifies that, as a 1-ulp nudge does on 0.7 itself: on the samples, relaxed nodes land up to about 2 mm from where 0.7 put them (the crank: 1.87 mm guarded, 1.09 mm strong). Results after a relaxation are not those of 0.7, bit for bit or to the micrometre.

Temperatures

Absolute temperatures are kelvin; a temperature difference (a film coefficient’s per-degree, an expansion coefficient) has no offset. Left out, an initial or reference temperature is 0 °C (273.15 K), and a plane-strain thickness 1 mm: the defaults of the default display system. The lattice-Boltzmann thermal solver runs its temperature lattice relative to the zero of the temperature unit the model is shown in (its own display units, else °C): 0 °C for the millimetre systems, 0 K for SI, 0 °F for in-lbf-s-psi. Its walls are not invariant under a shift of the temperature scale, and before SI storage it ran on the numbers as typed, so every model gives the results it gave.

The file format and old files

Format 3 (fieldcraft/3, docs/formats/fieldcraft.md) stores SI: model.json in SI, mesh.bin as MCMESH02 with coordinates in metres. migrate::step 2 → 3 (crates/io/src/migrate/v2_to_v3.rs) reads the declared units of the file and scales every dimensional field with its own frozen field → quantity map and its own copy of the MCMESH01 codec, so a later change to the model types cannot change how an old file migrates; a number it does not know is refused. Datums, mesh plans, seeds and size controls migrate from millimetres in a file built on a design or 3MF meshes (the notes below). The journal’s numbers are not rewritten: the step gives it a header naming the system they were typed in, and replay reads them through it, so replaying the journal gives the migrated model (but for the last bits of coordinates a mesher computed on another mesher’s mesh, above). Where such a journal’s commands left out a field whose format 2 default meant a number in that system (a reference temperature of 0, a plane-strain thickness of 1, a Johnson–Cook reference strain rate of 1, an initial temperature of 0), replay writes that default in, from a table frozen with the step (migrate::format_2_defaults). In a model built on a design or 3MF meshes the geometry and mesher commands’ numbers are read as millimetres, as they were then; one that acted on a block typed in another unit (beside a mesh of the design) cannot be replayed exactly and is refused, naming the block.

Notes on migrating older files:

  • An m-kg-s-N-Pa file’s temperatures are read as kelvin, the system’s own unit (the release that wrote it labelled them “°C or K”; its solvers depended only on differences, and its fluid solver’s heat lattice keeps counting from 0 K, as it did, through the domain’s temperature_zero). An in-lbf-s-psi file’s are °F, the millimetre systems’ °C.
  • A model that declared metres or inches but holds a mesh made from a SolidCraft design or a 3MF file: format 2 never scaled such a mesh, so its numbers are millimetres and the part solved was 1000× (25.4×) the design. Each body is migrated by its origin, traced through the journal: a mesh of the geometry from millimetres (so it overlays the design again and agrees with the datums, mesh plans, seeds and size controls), a block (mesh.block, tagged elements, and what was mirrored or extruded from them) from the declared unit, and a relaxation field with the mesh it was made on (its corners, else its bodies, else where it lies). A body the journal does not explain is read as the geometry’s, and the note says so. Opening such a file says so (in the open reply, the status line and the document’s migrated-from note): results will differ from the old ones. The first save keeps the old file beside the new one.
  • A node shared by a mesh of the geometry and a block typed in metres or inches (a block joined onto a face of the design’s mesh) has no consistent scale: such a file is refused, naming the bodies, and is not changed; it still opens in FieldCraft 0.7.x.
  • Datums, mesh plans, seeds and size controls were typed against the geometry: millimetres in a file built on a design or 3MF meshes, the declared unit in one that was not.

Literal factors

cargo xtask unit-factors (xtask/src/unit_factors.rs, a gate of cargo xtask ci) fails on a float literal equal to a common conversion factor (1e-3, 1e6, 1e-9, 1e12, 273.15, 459.67, 25.4, 0.0254, 9.80665, 9.81, 9810) written outside crates/model/src/units/. It reads the sources as syntax trees: comments, strings (help texts, WGSL) and test code (#[cfg(test)] and #[test] items, and the module files a #[cfg(test)] mod declares) are not code that converts.

What a number that looks like a factor must be instead:

  • A conversion goes through the table: DisplaySystem::to_si/express, Quantity::parse, or units::Typed, a constant written with its unit (Typed::new(1.0, "mm")) and converted where it is used. The plane-strain default thickness is Typed 1 mm; the display tessellation’s range is 1 µm–1 mm expressed in the geometry frame.
  • A tolerance or a cap is a named constant whose line carries the marker // unit-factors: <what it is>: relative (relative to the model's size), dimensionless (the sine of an angle, a component of a unit vector), or an absolute amount in SI with its unit stated (render::MIN_SIZE, 1 µm in metres, the scene's unit (SI)). An absolute amount in another system is a Typed. Bytes and wall-clock times for messages are marked as not model quantities.
  • A sample’s physical constant is written with its unit: "young": STEEL_YOUNG (210 GPa), "density": "1100 kg/m^3", sample::GRAVITY (9.81 m/s²). A script that computes with one converts it once into the samples’ mm-t-s system (sample::sample_value): the drop test’s speed √(2 g h) from 9810 mm/s².

The marker is the only exemption a line gets; one without a reason, or on a line without a factor, fails the check. One file is named in the checker with its reason: crates/io/src/migrate/v2_to_v3.rs, the frozen 2 → 3 step: it keeps its own copy of the old factors so a later change to the table cannot change how an old file migrates. Only this file is exempt, not the io crate.

The geometry frame (the geometry and mesher crates and the engine’s geometry and mesh commands, which work in millimetres) is checked like everything else: its tolerances are relative or dimensionless, and an absolute amount of it is a Typed in millimetres, taken in the frame through fieldcraft_model::units::geometry_amount (with MIN_GEOMETRY_LENGTH, the floor against a zero size), which the geometry, mesh and engine crates share.