@rulecad/cad 0.7.2 → 0.7.3
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/AGENTS.md +2 -0
- package/README.md +6 -0
- package/bin/cad.mjs +2 -1
- package/lib/optimise.mjs +2 -2
- package/package.json +3 -3
- package/schemas/problem.schema.json +7 -3
package/AGENTS.md
CHANGED
|
@@ -93,6 +93,8 @@ variable says which rule it comes from. Follow these steps; they're what makes a
|
|
|
93
93
|
- Before reporting numbers for a final shape, verify them: give the `analysis` a smaller `cell` (solids: about a
|
|
94
94
|
third of the problem's) and check the stiffness has settled (`fea.settled`). Report the verified numbers, the safety
|
|
95
95
|
factor, and where the peak stress is.
|
|
96
|
+
- For a part that must not break (a lever, a pedal), give its problem a `"stress"` limit (the material's strength
|
|
97
|
+
over a safety factor) instead of a `"volume"`: the lightest layout under it. Then verify it on finer cells.
|
|
96
98
|
- Mark a problem `"critical": true` if the part could hurt someone if it broke. Say plainly that the analysis is a
|
|
97
99
|
design aid and the material values are data-sheet figures: such a part needs testing, recorded under
|
|
98
100
|
`"verification"`, not just a check.
|
package/README.md
CHANGED
|
@@ -357,6 +357,12 @@ with numbers as expressions like an object's (schema: `schemas/problem.schema.js
|
|
|
357
357
|
`ss304`, `ti64` come with rulecad. Printed values vary: measure yours.
|
|
358
358
|
- **Settings:** `volume`, the share of the space to fill; `cell`, the grid (smaller is finer and slower: a 140 × 40
|
|
359
359
|
grid takes about half a minute); `filter`, about the thinnest member, in mm.
|
|
360
|
+
- **Or a stress limit instead of a volume:** `"stress": "pla.strength / 3"` (MPa) finds the lightest layout that keeps
|
|
361
|
+
every cell's von Mises stress under it, which rounds off the sharp inside corners where cracks start. It takes about
|
|
362
|
+
a thousand steps, each with two solves, so it's slower: give it a coarse cell first. Give supports and loads some
|
|
363
|
+
area (a hole's edge, a pad), as stress where a load meets a point has no limit. `cad optimise` reports the peak
|
|
364
|
+
stress against the limit. Check the final part with an `analysis` on a finer `cell`: a sharp corner that's
|
|
365
|
+
within the limit on the optimiser's cells can still be over it on finer ones.
|
|
360
366
|
- **Variants**, picked as `name:variant`, set variables that have a tweak range, as an object's do.
|
|
361
367
|
|
|
362
368
|
`cad optimise <project>/<problem>` runs it, reports how far each load case moves its load and the stiffness that
|
package/bin/cad.mjs
CHANGED
|
@@ -125,7 +125,7 @@ async function optimiseProblem(ref) {
|
|
|
125
125
|
if (live) process.stderr.write('\r\x1b[K');
|
|
126
126
|
const p = await readProblem(project, name), cells = r.dim === 3 ? `${r.grid.nx} × ${r.grid.ny} × ${r.grid.nz}` : `${r.grid.nx} × ${r.grid.ny}`;
|
|
127
127
|
const lines = [`${p.material.name}${r.dim === 2 ? `, ${fmt(r.thickness)} mm thick` : ''}: ${r.cases.map((c) => `${c.name} ${sig(c.deflection)} mm (${sig(c.stiffness)} N/mm)`).join(', ')}`,
|
|
128
|
-
`${fmt(r.volume * 100)}% of the space, ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? '' : ' (stopped: not settled)'}${r.overhang ? `, printable built ${r.overhang}` : ''}`];
|
|
128
|
+
`${fmt(r.volume * 100)}% of the space, ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? '' : ' (stopped: not settled)'}${r.overhang ? `, printable built ${r.overhang}` : ''}${r.stress ? `, peak stress ${sig(r.stress.peak)} MPa (limit ${sig(r.stress.limit)})` : ''}`];
|
|
129
129
|
let out;
|
|
130
130
|
if (r.dim === 3) {
|
|
131
131
|
out = paths.preview(project, `${name.replace(':', '-')}-optimised.png`);
|
|
@@ -139,6 +139,7 @@ async function optimiseProblem(ref) {
|
|
|
139
139
|
if (opt('json')) return console.log(JSON.stringify((({ density, history, mesh, ...x }) => x)(r), null, 2));
|
|
140
140
|
console.log(`${r.title}${r.cached ? ' (cached)' : ` (${fmt(r.seconds)} s)`}`);
|
|
141
141
|
for (const c of r.cases) console.log(` ${c.name}: moves ${sig(c.deflection)} mm along its load, ${sig(c.stiffness)} N/mm`);
|
|
142
|
+
if (r.stress) console.log(` peak stress ${sig(r.stress.peak)} MPa, the limit ${sig(r.stress.limit)} MPa${r.stress.peak > r.stress.limit * 1.02 ? ': over it (raise the volume, ease the limit, or use a smaller cell)' : ''}`);
|
|
142
143
|
if (r.dim === 3) console.log(` ${fmt(r.volume * 100)}% of the space filled: ${fmt(r.solid / 1000)} cm³ (${fmt(r.solid / 1000 * (p.material.density || 0))} g of ${p.material.name})${r.overhang ? `, printable built ${r.overhang}` : ''}`);
|
|
143
144
|
else console.log(` ${fmt(r.volume * 100)}% of the space filled, outline ${fmt(r.area)} mm² (${fmt(r.area * r.thickness / 1000)} cm³ before bosses and holes are made exact)`);
|
|
144
145
|
console.log(` ${cells} cells of ${fmt(r.grid.h)} mm, ${r.steps} steps${r.converged ? ', settled' : ': stopped before it settled (raise steps)'}`);
|
package/lib/optimise.mjs
CHANGED
|
@@ -67,7 +67,7 @@ export async function readProblem(project, ref) {
|
|
|
67
67
|
supports: await Promise.all(p.supports.map(async (s) => ({ ...(await region(s)), fix: s.fix || 'xyz'.slice(0, dim) }))),
|
|
68
68
|
loads: await Promise.all(p.loads.map(async (l) => ({ ...(await region(l)), force: pt(l.force), case: l.case || 'load' }))),
|
|
69
69
|
cases: Object.fromEntries(Object.entries(p.cases || {}).map(([k, w]) => [k, ev(w)])),
|
|
70
|
-
material: { E: m.modulus, nu: m.poisson }, ...(dim === 2 ? { thickness: ev(p.thickness) } : {}), cell: ev(p.cell), volume: ev(p.volume),
|
|
70
|
+
material: { E: m.modulus, nu: m.poisson }, ...(dim === 2 ? { thickness: ev(p.thickness) } : {}), cell: ev(p.cell), ...(p.volume != null ? { volume: ev(p.volume) } : {}), ...(p.stress != null ? { stress: ev(p.stress) } : {}),
|
|
71
71
|
...(p.filter != null ? { filter: ev(p.filter) } : {}), ...(p.penal != null ? { penal: ev(p.penal) } : {}),
|
|
72
72
|
...(p.projection != null ? { projection: p.projection } : {}), ...(p.steps != null ? { steps: p.steps } : {}),
|
|
73
73
|
...(overhang && overhang !== 'none' ? { overhang } : {}),
|
|
@@ -115,7 +115,7 @@ export async function optimised(project, ref, { onStep, fresh = false } = {}) {
|
|
|
115
115
|
const result = {
|
|
116
116
|
problem: ref, title: r.title, hash, dim: r.dim, material: r.material.name, ...(r.dim === 2 ? { thickness: r.problem.thickness } : {}),
|
|
117
117
|
grid: spec.grid, origin: spec.origin, regions: { keep: named(spec.regions.keep), avoid: named(spec.regions.avoid) }, ...shape,
|
|
118
|
-
volume: o.volume, compliance: o.compliance, cases: o.cases, overhang: r.problem.overhang || null,
|
|
118
|
+
volume: o.volume, compliance: o.compliance, cases: o.cases, ...(o.stress ? { stress: o.stress } : {}), overhang: r.problem.overhang || null,
|
|
119
119
|
steps: o.steps, converged: o.converged, seconds: o.seconds, history: o.history, density: Array.from(o.density, (d) => round(d, 3)),
|
|
120
120
|
supports: named(r.problem.supports), loads: named(r.problem.loads),
|
|
121
121
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/cad",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
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": {
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@rulecad/rules": "^0.3.0",
|
|
55
55
|
"@jscad/modeling": "^2.12.0",
|
|
56
56
|
"three": "^0.186.1",
|
|
57
|
-
"@rulecad/fea": "^0.2.
|
|
58
|
-
"@rulecad/topopt": "^0.2.
|
|
57
|
+
"@rulecad/fea": "^0.2.1",
|
|
58
|
+
"@rulecad/topopt": "^0.2.2"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@rulecad/pcb": "^0.1.0 || ^0.2.0 || ^0.3.0"
|
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
"required": [
|
|
8
8
|
"material",
|
|
9
9
|
"cell",
|
|
10
|
-
"volume",
|
|
11
10
|
"space",
|
|
12
11
|
"supports",
|
|
13
12
|
"loads"
|
|
@@ -55,7 +54,11 @@
|
|
|
55
54
|
},
|
|
56
55
|
"volume": {
|
|
57
56
|
"$ref": "#/$defs/expr",
|
|
58
|
-
"description": "The share of the space to fill, 0 to 1 (keep regions count towards it)"
|
|
57
|
+
"description": "The share of the space to fill, 0 to 1 (keep regions count towards it): the stiffest layout that fills it. Give this or a stress limit"
|
|
58
|
+
},
|
|
59
|
+
"stress": {
|
|
60
|
+
"$ref": "#/$defs/expr",
|
|
61
|
+
"description": "A limit on von Mises stress (MPa), such as \"pla.strength / 3\": the lightest layout that keeps every cell under it (Senhora et al. 2020). Give this or a volume"
|
|
59
62
|
},
|
|
60
63
|
"filter": {
|
|
61
64
|
"$ref": "#/$defs/expr",
|
|
@@ -339,5 +342,6 @@
|
|
|
339
342
|
}
|
|
340
343
|
}
|
|
341
344
|
}
|
|
342
|
-
}
|
|
345
|
+
},
|
|
346
|
+
"anyOf": [{ "required": ["volume"] }, { "required": ["stress"] }]
|
|
343
347
|
}
|