meshing.generate — Generate a validated tetrahedral solver mesh from exact CAD geometry.
mesh = meshing.generate(geometry) and mesh = meshing.generate(geometry, Name, Value, ...) discretize a geometry.Asset into linear or quadratic tetrahedra and return an immutable meshing.Mesh whose solver artifact and stage evidence have passed joint validation.
Syntax
mesh = meshing.generate(geometry, Name, Value, ...)Inputs
geometry- Type
Any- Required
- Yes
- Default
- —
- Description
- geometry.Asset loaded from exact CAD (STEP, IGES, or BREP).
Name, Value- Type
Any- Required
- Variadic
- Default
- —
- Description
- TargetSize, MaximumDeviation, MaximumGradingRatio, ElementOrder, MaximumElements, or Seed.
Returns
mesh- Type
Any- Description
- Jointly validated meshing.Mesh object.
Errors
RunMat:meshing:InvalidInput- When
- A meshing object, path, option, artifact, or evidence contract is invalid, or meshing cannot produce a result that satisfies the request.
- Message
meshing operation failed
Behavior
geometry must be a geometry.Asset from geometry.load of exact CAD (STEP, IGES, or BREP) containing a closed solid. Meshing re-reads the source file recorded in the asset, checks it against the asset's SHA-256 so that the mesh always matches the geometry you loaded, and uses the asset's units. Tessellated formats such as STL can be displayed but not meshed for analysis.
Options are Name, Value pairs; names are case-insensitive and ignore underscores and spaces. TargetSize is the global target edge length in meters (default 0.01). MaximumDeviation is the maximum chordal distance in meters between the discrete boundary and the exact curves and surfaces (default 1e-4); curved geometry may need edges much shorter than TargetSize to meet it. MaximumGradingRatio limits how quickly element size may change between neighbors (default 1.3; lower is smoother but needs more elements). ElementOrder is 'tet4' (default) or 'tet10'. MaximumElements is a hard element ceiling (default 10000000), and Seed is the deterministic tie-breaking seed (default 0). A repeated option uses its last value.
TargetSize, MaximumDeviation, and MaximumGradingRatio must be finite and positive. MaximumElements must be a positive integer and Seed a nonnegative integer; both accept integer classes up to uint64 exactly, or a double holding an exact integer. Other budgets use canonical limits: 10,000,000 nodes, 512 MiB of memory, 512 MiB of scratch space, a 512 MiB artifact, and one hour of wall time.
Tet10 adds midside nodes, projects boundary midside nodes onto the exact CAD surface, and validates positive curved Jacobians. Boundary faces are Tri3 for Tet4 and Tri6 for Tet10.
Generation either returns a mesh that passed topology, geometry, sizing, quality, provenance, resource, and serialization checks, or fails without returning a mesh. A budget that cannot be met fails rather than truncating or coarsening the mesh. The same geometry, options, and seed produce the same canonical digest, so a mesh can be regenerated and compared exactly.
The result's public properties are canonical_digest (64 hexadecimal characters), node_count, element_count, and boundary_face_count (each uint64). Use meshing.nodes, meshing.elements, meshing.boundaryFaces, meshing.regions, meshing.quality, and meshing.evidence to inspect it, and mesh(solverMesh) to display it.
Meshing runs through the native meshing service that RunMat hosts install, using parallel native workers. A host without that service, including the browser, fails with a message saying the host cannot execute meshing.
Use in a study
Attach the mesh to a study with fea.study(id, part, model, "Mesh", solverMesh) using the same geometry.Asset; the model's regions are resolved onto the mesh through the persistent CAD identities the mesher records. Save the mesh and its evidence with meshing.save when results must be reproducible from the exact discretization.
Materials and boundary conditions are not meshing options. Assign them on geometry regions in the model; meshing only discretizes the geometry and preserves its regions.
Check mesh convergence for engineering conclusions: reduce TargetSize and MaximumDeviation systematically and confirm that the quantities of interest stop changing.
Errors
RunMat:meshing:InvalidInput reports every failure: a first argument that is not a geometry.Asset, malformed options, an unsupported element order, out-of-range values, a host without meshing, a changed or unreadable source file, and meshing failures such as invalid geometry, unsatisfiable constraints, unreachable quality, or an exceeded budget; the message names the cause and stage.
Examples
Generate a linear mesh of a 1 m x 2 m x 3 m block
part = geometry.load('box.brep', 'Units', 'm');
solverMesh = meshing.generate(part, 'TargetSize', 0.5, 'MaximumDeviation', 0.05, ...
'ElementOrder', 'tet4', 'Seed', 42);
solverMesh.element_countGenerate quadratic tetrahedra reproducibly
part = geometry.load('box.brep', 'Units', 'm');
settings = {'TargetSize', 0.5, 'MaximumDeviation', 0.05, 'ElementOrder', 'tet10', ...
'MaximumElements', uint64(100000), 'Seed', uint64(7)};
first = meshing.generate(part, settings{:});
second = meshing.generate(part, settings{:});
elements = meshing.elements(first);Using meshing.generate with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how meshing.generate changes the result.
Run a small meshing.generate example, explain the result, then change one input and compare the output.
FAQ
Which element order should I use?⌄
Use tet10 for stress, bending, and modal work, where linear tetrahedra are too stiff, and for curved geometry. Use tet4 for temperature fields and quick checks.
My mesh fails with a budget error. Can RunMat coarsen it automatically?⌄
No. A budget failure means the requested sizing cannot be met within the limit. Raise MaximumElements or relax TargetSize or MaximumDeviation deliberately; the mesher never silently reduces quality.
Are the size options in model units?⌄
No. TargetSize and MaximumDeviation are always meters, whatever units the CAD file uses.
Related Meshing functions
meshing.boundaryFaces · meshing.elements · meshing.evidence · meshing.load · meshing.nodes · meshing.quality · meshing.regions · meshing.save
Related guides
Source you can read
Every RunMat function's source is public. Read exactly how meshing.generate is executed, line by line, in Rust.
- View the source for meshing.generate in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.