Artificial Intelligence doing Part Validation and Scripted Optimization: Native Meshing, CalculiX and Elmer in mcpFreeCAD

06 Dec 2026 - tsp
Last update 06 Dec 2026
Reading time 14 mins

In the original article about giving an LLM access to FreeCAD, I described how the combination of an editable model, geometric inspection and rendered images allowed useful mechanical parts to be developed. With the later TechDraw integration, those parts could also be documented in technical drawings. There was still another open question in the real verification loop: how does the modeled part behave under its intended load? I wanted that question to become part of the same inspection and correction process, with numerical results that could also be evaluated independently of the agent.

Versions 0.0.4, 0.0.5 and 0.0.6 of mcpFreeCAD extend this workflow with native volume meshing and CalculiX and Elmer finite element analyses. A CAD solid can be discretized, material properties and boundary conditions can be assigned, and the calculated displacement, stress or temperature can be inspected directly through MCP. The same operations can then be repeated by a script while dimensions or loads are varied.

The practical consequence is that a design can be checked against explicit physical requirements during its development. The assumptions behind that check, the mesh used and the resulting numerical fields can be retained together, providing a basis for later review and auditing.

Numerical review of the selected double-eye tensile coupon, with stress contours and mesh refinement results

From a Solid to a Volume Mesh

A boundary representation describes the faces enclosing a solid. For a finite element method (FEM) analysis, the interior also needs to be divided into elements over which the physical problem can be approximated. Version 0.0.4 adds native tetrahedral volume mesh generation and export to the MCP interface.

Both four-node linear tetrahedra and ten-node quadratic tetrahedra are supported. Material regions and named boundary regions are carried with the mesh, so that a support, a loaded surface or a material interface can be identified in the solver input. The output can be retrieved as a native mesh archive or a CalculiX input include. The native archive contains the packed coordinates and connectivity together with a manifest describing their layout, source geometry and meshing settings.

Boundary selection becomes relevant when the geometry is changed repeatedly. A load attached to a saved face number can end up referring to a different face after a Boolean operation. Named regions can instead be described by geometric selectors, such as an outer plane facing a specified direction or the wall of a cylindrical bore. These selectors are resolved against the current geometry during mesh generation. Their resolved faces still need to be inspected, especially if the number of matches changes.

Meshing is performed in an isolated command line FreeCADCmd process using a snapshot of the selected geometry. Several meshing paths cover supported extrusions, revolved shapes, curved solids and partitioned geometries. Their applicability depends on the shape and the requested settings. Element and memory limits bound the work and unsupported geometry or conflicting size requirements are reported.

The mesh report includes geometric and element-quality information, such as CAD and mesh volumes, edge lengths and Jacobians. These checks help identify problems in the discretization. The dependence of the calculated result on that discretization then has to be investigated separately. For a curved boundary, both element size and the accuracy with which the CAD surface was sampled can affect the result.

Version 0.0.6 also adds a meshing path for coaxial stepped cylindrical solids, which is used for the vacuum domain in the Einzel lens example below. Named regions can combine several selectors, and cylindrical selections can be restricted to an axial interval. Separate electrode sections can therefore be identified even when their surfaces share an axis.

CalculiX Analyses

Version 0.0.5 adds solver execution and result inspection. The original CalculiX adapter covers static mechanical analyses and steady thermal conduction. Version 0.0.6 extends this with linear transient mechanics, transient thermal conduction and steady thermoelastic expansion. Mechanical inputs include elastic properties, displacement constraints, forces and pressure. Thermal inputs include conductivity, prescribed temperature, heat flux and volumetric heating.

For example, the displacement of a bracket can be calculated after its mounting surface has been constrained and a force has been assigned to the loaded interface. The resulting deformation and stress distribution can then be compared with the design requirements. In a thermal analysis, the temperature distribution and heat flux can be evaluated for specified material conductivities and thermal boundary conditions.

The target host is queried for solver capabilities before execution. CalculiX is located through the FreeCAD FEM preferences, and the supported analysis inputs are checked before a run is dispatched. Solver execution is asynchronous, with status queries, cancellation and resource limits. The native input and output files are retained for diagnosis.

Results are returned in a portable archive with explicit quantities, units, sampling locations and mesh identities. Displacement is associated with mesh nodes; stress and strain are available at integration points. Numerical summaries and bounded sample queries can be requested directly through MCP. The fields can also be retrieved for evaluation by an external script.

For visual inspection, native FreeCAD overlays provide scalar contours, vector displays, slices and displaced geometry. The original CAD object is preserved. A deformation factor of one shows the calculated physical displacement; an enlarged factor can be used to make small deformations visible and is recorded with the image.

Elmer and Additional FEM Domains

Version 0.0.6 adds Elmer as another optional solver backend. The same analysis definitions, mesh identities and numerical result interface are used, so that the existing inspection and scripted study procedure can also be applied to the additional physical models.

The supported Elmer families include electrostatics, stationary electric conduction, magnetostatics, mass transport, steady incompressible flow and mechanical, acoustic and electromagnetic eigenmodes. Static and transient mechanics, thermal conduction and steady thermoelastic expansion are available through both adapters. The applicable element orders, material properties and boundary conditions are returned by solver capability discovery.

Each family represents a defined physical model. For example, the scalar magnetic formulation is restricted to current-free regions, while the impressed-current formulation uses a homogeneous material and constant current density. The electromagnetic eigenmode model describes a lossless cavity with perfectly conducting walls. Those assumptions need to be checked against the intended problem before a result can be used.

Transient results carry explicit time samples, and eigenmode results identify their mode indices. Numerical summaries and overlays can be requested for the selected sample. Mesh refinement remains relevant, and the time step also needs to be examined for transient studies. Steady thermoelastic analysis provides a temperature calculation followed by linear thermal expansion; more general coupling between solvers still requires the separate standalone runtime.

An Einzel Lens Voltage Sweep

An electrostatic example is shown in the following video. An idealized Einzel lens vacuum domain is modeled, with grounded outer electrodes and a variable central electrode potential. The central bias is increased from 0 to 300 V in 6 V increments and then reduced back to 0 V. The resulting potential and electric field are inspected on sections through the domain.

The sequence contains 101 stationary Elmer calculations on the same mesh of 21,120 quadratic tetrahedra. The two field sections were obtained from 202 native MCP captures. The camera and color ranges are held fixed, allowing the change in field strength to be followed as the voltage is varied. This progression describes independent stationary cases; no time-dependent electrode drive is assumed.

The potential is shown as a nodal field. The electric-field magnitude is displayed using element averages, while the separately labeled peak is taken from the original quadrature samples. An independent coarse/fine comparison of 17 on-axis potential samples at 300 V gives a maximum difference of 1.34 V. This is a refinement comparison for the selected observable and does not establish convergence of every local field maximum.

The vacuum domain is truncated at its axial ends. Charged-particle trajectories and fringing fields beyond the modeled domain remain outside the example. The calculated fields provide another numerical representation that can be inspected and compared with the geometry, boundary conditions and an independent physical estimate.

Validation and Auditing

The purpose of adding FEM is to extend the existing part-validation process with a physical model. Geometry checks establish properties of the constructed solid. A mechanical analysis adds a prediction of its response under specified loads and supports. The usefulness of that prediction depends on how well those assumptions represent the intended application.

Consider a force transmitted through a bolt hole. Its distribution over the bore wall affects the local stress field. A prescribed traction, a contact model and a real bolted joint introduce different assumptions. Material properties, the constrained directions and the chosen load cases therefore belong in the analysis record. Their selection remains an engineering decision.

Mesh dependence also needs an explicit check. A successful solve on one mesh leaves convergence unassessed. The quantity used for acceptance, such as displacement at an interface or sampled stress in a selected region, should be compared across refinements. Automatic refinement support provides another means of investigating discretization error, while the result still needs to be interpreted for the particular model and quantity of interest.

The reporting interface brings the analysis definition, source geometry and mesh metadata, solver diagnostics and numerical summaries together. Meshes and results are identified by their SHA-256 digests, allowing a field to be associated with the exact discretization on which it was calculated. Retained images can be included as additional review artifacts.

This association is important when several variants have been evaluated. A stress plot should be traceable to the dimensions, material assumptions and boundary conditions that produced it. The numerical queries retain the original solver samples, while the display records its averaging or interpolation method. For integration-point contours, element means are used for visualization. Acceptance metrics can therefore be evaluated from the original samples with their sampling convention stated explicitly.

Physical measurements and tests remain a further validation step. The numerical analysis provides a reproducible prediction whose assumptions and agreement with the actual part can be investigated.

Scripted Optimization Loops

Once a candidate can be constructed and evaluated consistently, the same procedure can be repeated over a parameter space. A study specifies the editable dimensions or analysis inputs, their bounds, the quantities to extract and the objectives and constraints used for comparison.

A simple example is minimizing material volume while limiting maximum displacement and sampled stress. For each candidate, the CAD model is recomputed, the selected solid and named regions are checked, a mesh is generated and the analysis is run. The resulting metrics are then compared with the declared criteria. Geometry changes require the mesh identity to be reconsidered; load-only changes can reuse an identical verified mesh.

The implemented candidate generators include explicit parameter sequences, multidimensional grids and a bounded coordinate search. The latter varies parameters along individual directions and reduces its step size when no improvement is found. Feasible candidates take precedence in the ranking, and the declared objectives determine their ordering.

Each evaluation is performed from an immutable document snapshot. Candidate parameters, numerical results and failures are retained in a journal. A study can be resumed from its recorded state, and an individual candidate can be reproduced independently for comparison.

The repeated evaluation is executed by a script, so a model invocation is unnecessary for every candidate. The agent can prepare the specification, inspect the outcome and revise the engineering problem when needed. The numerical loop itself follows the declared procedure and budgets.

An Example Parameter Study

The following demonstration uses an illustrative double-eye tensile coupon whose outline was inspired by a figure-eight descender. Bridge width and ring width are varied over a two-dimensional grid. Material volume is minimized subject to the declared numerical screening criteria.

A candidate from the parameter study that exceeds the illustrative sampled-stress limit

Sixteen parameter combinations have been evaluated. Ten solves complete, one candidate has invalid CAD geometry and five reach their solver time limit. Two evaluated candidates satisfy the declared numerical screening criterion. Keeping the unsuccessful evaluations in the record makes the coverage of the search visible.

The lowest-volume feasible candidate is then subjected to an independent mesh review. Increasing the mesh from 17,919 to 29,316 quadratic tetrahedra changes its peak sampled von Mises stress from approximately 119.1 to 118.8 MPa. This provides a concrete refinement comparison for that model and quantity. A wider search or additional load cases may change which candidate is preferred.

Scripted Animation Loops

The study infrastructure also supports ordered frame sequences. CAD geometry can be captured for a parameter sweep, or FEM fields can be rendered from the retained candidate results. Completed studies can be rendered again without repeating their solves, so changes to the presentation can be separated from numerical evaluation.

Comparability requires consistent visualization settings. Camera pose, projection, image dimensions, contour range and deformation scale are held fixed across a sequence. Otherwise a changing color scale or automatic view fit could make small differences appear substantial or conceal a relevant change. The frame records retain these settings together with candidate parameters and result identities.

This permits scripted animation loops for inspecting design changes or a sequence of independent load cases. A sequence of static solutions describes the selected parameter progression. Transient behavior requires a suitable dynamic physical model and solver capability. Version 0.0.6 also exposes transient mechanical and thermal studies through CalculiX and Elmer, with explicit time samples. Elmer additionally provides normalized mechanical, acoustic and electromagnetic modes. A mode shape can be displayed at a chosen illustrative amplitude; its normalization and display factor need to be retained when interpreting the animation.

Missing results are represented with diagnostics. A failed candidate is therefore visible as a gap in the sequence. Frames can be retrieved through MCP for inspection and assembled into a video separately, as in the demonstration above.

What comes next

We are also moving towards the manufacturing floor, where the connection between a validated design and the production of a physical part becomes the next practical question. We may write up that work in a paper, so a detailed account may take some time. For now, the public releases provide the meshing, analysis and scripted study tools needed to investigate the part before that next step.

References

This article is tagged:


Data protection policy

Dipl.-Ing. Thomas Spielauer, Wien (webcomplainsQu98equt9ewh@tspi.at)

This webpage is also available via TOR at http://rh6v563nt2dnxd5h2vhhqkudmyvjaevgiv77c62xflas52d5omtkxuid.onion/

Valid HTML 4.01 Strict Powered by FreeBSD IPv6 support