@rulecad/cad 0.7.10 → 0.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -371,7 +371,8 @@ worked out again when something it depends on changes.
371
371
 
372
372
  A 3D result with a build direction is made printable before it's drawn: built up layer by layer from the bed, every
373
373
  cell that nothing holds up (an icicle, a loose bit, a sheet hanging under an edge: whatever the optimiser's smooth
374
- overhang filter let through) is emptied, with whatever rested on it; a bridge may run out half the printer's span.
374
+ overhang filter let through) is emptied, with whatever rested on it; a bridge may run out half the printer's span,
375
+ in the optimiser's filter and in the cleaning alike, so a flat underside can open into holes that wide.
375
376
  Kept regions always stay, and the optimiser is made to hold them up: a kept cell with nothing under it costs it as
376
377
  much as the whole part's compliance. If there wasn't material enough to stand a kept region on, `cad optimise` says
377
378
  how much of it is left hanging. Then the drawn surface is tipped back to the printer's overhang limit and any tip left
@@ -425,8 +426,11 @@ Both take expressions, so a variant can lie the part down:
425
426
  "analysis": [{ "problem": "bracket", "rotate": ["0 - 90 * side", 0, 0], "move": [0, "0 - side * bench.bracket_h / 2", 0] }]
426
427
  ```
427
428
 
428
- Grids in 3D are solved by multigrid. A 16 × 16 × 40 grid (about 10,000 cubes) takes a second or two a step, so a whole
429
- optimisation takes a few minutes. The result is kept, so it's worked out once.
429
+ Grids in 3D are solved by multigrid, with the solver's products shared over the machine's cores. A 16 × 16 × 40 grid
430
+ (about 10,000 cubes) takes a second or two a step, a 32 × 32 × 40 one (41,000 cubes) about five seconds on an eight-core
431
+ laptop and a 40 × 40 × 48 one (77,000 cubes) about thirteen, so a whole optimisation of a few hundred steps takes from a
432
+ few minutes to an hour. Finer cells cost more than their number: each step's solve takes longer to settle too. The
433
+ result is kept, so it's worked out once.
430
434
 
431
435
  ### Analysis
432
436
 
package/lib/optimise.mjs CHANGED
@@ -12,6 +12,7 @@ import { paths, printerOf } from './workspace.mjs';
12
12
  import { resolve, evaluate } from './rules.mjs';
13
13
  import { located } from './errors.mjs';
14
14
  import { discretise, optimise, outlines, surface, area, bounds, resultant, printable } from '@rulecad/topopt';
15
+ import { threadsBackend } from '@rulecad/fea/threads'; // the solver's products shared over the machine's cores
15
16
  import { grid as makeGrid, analyse, positions } from '@rulecad/fea';
16
17
 
17
18
  const VERSION = 2, source = (m) => fs.readFileSync(new URL(import.meta.resolve(m)), 'utf8'); // the solver's code: a change remakes results
@@ -75,7 +76,7 @@ export async function readProblem(project, ref) {
75
76
  if (dim === 2 && !(problem.thickness > 0)) throw new Error(`${path.basename(file)}: a flat (2D) problem needs a thickness`);
76
77
  const outline = { smooth: p.outline?.smooth ?? 4, minArea: p.outline?.min_area != null ? ev(p.outline.min_area) : problem.cell ** 2 * 2 };
77
78
  // A printable solid's surface is kept within the printer's overhang limit too (smoothing can tip faces past it)
78
- if (dim === 3 && problem.overhang) { const n = printerOf(project), pr = resolve({ uses: [n] }).values[n]; outline.overhang = { up: problem.overhang, angle: pr?.overhang ?? 45, bridge: pr?.bridge ?? 5 }; }
79
+ if (dim === 3 && problem.overhang) { const n = printerOf(project), pr = resolve({ uses: [n] }).values[n]; outline.overhang = { up: problem.overhang, angle: pr?.overhang ?? 45, bridge: pr?.bridge ?? 5 }; problem.bridge = outline.overhang.bridge; } // (the optimiser bridges half that)
79
80
  return { ref, name, variant, file, dim, title: p.title || name, material: { name: p.material, ...m }, problem, outline, critical: !!p.critical };
80
81
  }
81
82
 
@@ -94,7 +95,7 @@ export async function optimised(project, ref, { onStep, fresh = false } = {}) {
94
95
  const hash = digest([VERSION, r.problem, r.outline, topopt, source('@rulecad/fea'), fs.readFileSync(new URL(import.meta.url), 'utf8')]), file = paths.cache('optimise', `${hash}.json`);
95
96
  if (!fresh && !process.env.CAD_NO_CACHE && host.exists(file)) return { ...JSON.parse(host.readText(file)), cached: true };
96
97
  const spec = discretise(r.problem), densities = paths.cache('densities', `${digest([VERSION, r.problem, solver, source('@rulecad/fea')])}.json`);
97
- const o = !fresh && !process.env.CAD_NO_CACHE && host.exists(densities) ? (({ density, ...x }) => ({ ...x, density: Float64Array.from(density) }))(JSON.parse(host.readText(densities))) : optimise(spec, { onStep: onStep && ((st) => onStep({ ...st, grid: spec.grid })) });
98
+ const o = !fresh && !process.env.CAD_NO_CACHE && host.exists(densities) ? (({ density, ...x }) => ({ ...x, density: Float64Array.from(density) }))(JSON.parse(host.readText(densities))) : optimise(spec, { backend: threadsBackend, onStep: onStep && ((st) => onStep({ ...st, grid: spec.grid })) });
98
99
  if (!host.exists(densities)) host.writeText(densities, JSON.stringify({ ...o, density: Array.from(o.density) }));
99
100
  // Regions as data: a part's triangles are named, not copied
100
101
  const named = (list) => list.map(({ triangles, ...x }) => x);
@@ -198,7 +199,7 @@ function analyseSolid(triangles, r, cell) {
198
199
  const { problem } = r, spec = discretise({ ...problem, cell, space: { triangles }, keep: [], avoid: [], volume: 1 });
199
200
  const g = makeGrid(spec.grid), density = solidFill(triangles, spec.grid, spec.origin);
200
201
  if (!density.some((d) => d)) throw new Error('the part is smaller than one cell of the problem: use a smaller cell');
201
- const a = analyse({ grid: g, density, material: problem.material, fixed: spec.fixed, loads: spec.loads.map((l) => l.force) });
202
+ const a = analyse({ grid: g, density, material: problem.material, fixed: spec.fixed, loads: spec.loads.map((l) => l.force), backend: threadsBackend });
202
203
  const cases = spec.loads.map((l, c) => measures(l.name, l.size, l.moment, a, c, density, spec.grid, spec.origin));
203
204
  return { problem: r.ref, dim: 3, material: r.material, critical: r.critical, cases, volume: volume(triangles), grid: spec.grid, origin: spec.origin, density };
204
205
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.10",
3
+ "version": "0.7.12",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {