Tutorials PartCraft help Walkthroughs

The analysis library

The library of readable analysis scripts in the Script workspace: what is in each group, opening a function read-only, its header with method, references and a check, making your own copy, and how a copy takes over from the library function.

Written for PartCraft 0.3. The same help is inside the app: press F1.

The analysis library is a set of scripts, each a function you can read from top to bottom: how the stiffness matrix is assembled, where the boundary conditions go, which solver runs, how the results are worked out. Nothing in it is hidden in a black box; only the fast inner loops (element matrices, sparse solvers, meshing) are built in.

Start with an example

The Examples group holds four short scripts that use the library end to end. Click one, press Open (read-only), then F5F5: each clears the view, shows a result on the canvas and a plot in the sub-displays.

ExampleWhat it shows
Cantilever stressA steel bar 100 × 10 × 10 mm under a 100 N tip load: von Mises stress on the deformed bar, and the tip deflection against beam theory at four element sizes (plotted)
MBB beam topologyThe classic 60 × 20 topology optimization: the design forming, the compliance falling, the final layout (94 iterations, compliance 203.19)
Capacitor fieldTwo plates 4 mm wide, 1 mm apart: potential and field, the capacitance with fringing against the ideal value and Palmer's formula
Channel flowLattice Boltzmann flow past a post in a channel: the velocity field and the convergence history

Groups

GroupFunctionsWhat they do
Meshingbox_mesh, cylinder_mesh, voxel_mesh, tet_mesh, mesh_quality, nodes_at, face_nodesBoxes and cylinders as hexahedra, cubes or tetrahedra; cubes or tetrahedra of any model (the part, a body, a loaded STL); element volumes and quality; picking nodes on a plane or a face
Static stressstatic_voxel, static_tetLinear static stress on cubes or on 10-node tetrahedra: displacements, stresses, von Mises, reactions
Vibrationmodal_tetNatural frequencies and mode shapes
Heatheat_steady, heat_transient, heat_systemSteady and transient conduction with fixed temperatures, heat input, generation, flux and convection
Topology optimizationtop88, top99, topopt3dThe published 88- and 99-line 2-D codes, and the same method in 3-D on cubes
Electromagneticspoisson2d, magnetostatic2d2-D electrostatics (potential, field, capacitance, charge) and magnetostatics (vector potential, flux density)
Fluid flowlbm2d, lbm3dLattice Boltzmann flow: 2-D written out in the script, 3-D on PartCraft's own flow kernel

Every function's header gives its exact arguments. Units are those of PartCraft's studies unless the header says otherwise: millimetres, newtons, megapascals, tonnes per cubic millimetre for density, watts and kelvin for heat. The electromagnetic and lattice Boltzmann functions work in any consistent units; their headers say how.

How the library is checked

Each function's header ends with a check: a small case with a known answer. PartCraft's tests run every one of them, and where PartCraft has its own study for the same job the script's answer is compared with that study on the same mesh:

  • the cantilever's tip deflection against beam theory (within 0.2 % with cubes, 0.05 % with tetrahedra), and against the Simulation workspace's solvers on the same mesh (the same to many digits);
  • the cantilever's first frequency against beam theory (0.24 % lower, as expected for a short beam) and against Simulation's modal solver;
  • heat: a heated plane wall exactly, a small body cooling as the lumped-capacity formula says, a slab's temperature dying away as theory says;
  • topology optimization: top88 reproduces the paper's 94 iterations and compliance 203.1925 (and 218.8032 with the density filter); topopt3d ends at the same compliance as the Generative workspace with the same settings;
  • a capacitor's capacitance and a long solenoid's field against their textbook values;
  • channel flow against the exact parabolic profile.

Read a function

  1. Open the Library tab of the script panel.
  2. Click a function. Its header shows: what it computes, the method, units, assumptions and limits, the references (book or paper, with equation numbers) and a check — a small case with a known answer that PartCraft's own tests run.
  3. Open (read-only) opens the whole script in a tab with a dashed border. You can run it, select and run parts of it, but not change it.

Change one

Press Make a copy (or Make a copy to edit above a read-only tab). The copy is a script in your part with the same name, so it is saved with the part, and every call to that function now uses your copy — the editor says so above the script. Rename the copy to keep both.

Use one

Call a library function from any script by its name, like a built-in function:

xPhys = top88(60, 20, 0.5, 3.0, 1.5, 1);

Results come back as values in the workspace; plots and fields it shows appear in the view and the sub-displays.

A static analysis of the open part, for example, takes a few lines:

v = voxel_mesh(part(), 2);                   % 2 mm cubes
X = meshNodes(v);
bc = struct('fixed', nodes_at(v, 2, min(X(:, 2))));   % hold the bottom
top = nodes_at(v, 2, max(X(:, 2)));
bc.loads = {struct('nodes', top, 'force', [0 -500 0])};   % 500 N down on the top
r = static_voxel(v, 210000, 0.3, bc);       % steel

r holds the displacements, stresses and reactions; the von Mises stress is drawn on the deformed part. For curved parts use tet_mesh and static_tet, which can also load and hold whole faces (face_nodes).