Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice
TypeScript 3d-modeling3d-printing3d-printing-toolsagentagentic-aiai-cadcadcadqueryclaude-codecodexelectronfemllmmacdmakeropencodeparametric-designpythonsteptext-to-cad
App: Schrauben im Bericht, Skill und Test zu bolt() (E84)
Kai-Jungsthoefela462902bb226
diff --git a/app/resources/skills/fem.md b/app/resources/skills/fem.mdindex 969ab73..ceddedf 100644--- a/app/resources/skills/fem.md+++ b/app/resources/skills/fem.md@@ -1,12 +1,12 @@---title: Strength with FEMname: Strength with FEM-summary: Stresses, safety factor and deformation under load with the finite element method (soma analyze fem), also with parts pressing and sliding on each other (contact), load case as a Python file, colored result in the app.+summary: Stresses, safety factor and deformation under load with the finite element method (soma analyze fem), also with parts pressing and sliding on each other (contact) and preloaded screws (bolts), load case as a Python file, colored result in the app.order: 32category: Check and presentdefault: on-demandwhen: a part carries a real load and the user wants to know whether it holds, where it is weakest or how far it bends-topics: Load case; Parts that touch; Compute and read; Check the result; Limits; Feedback+topics: Load case; Parts that touch; Bolted joints; Compute and read; Check the result; Limits; Feedbackvar safety: 2 | | Safety factor | 1..10---# Skill: Strength with FEM@@ -46,8 +46,9 @@ study.force("Bracket", faces=">X", N=(0, 0, -49)) # total force on the face0.1 MPa = 1 bar.- `study.gravity()`: the weight of the parts themselves (`direction="-z"`).-Model a screw by holding the face under its head or the inside of its hole. Put a load where it really acts: on the-face the hand, the shelf or the shaft touches, not on a whole side.+Model a screw that holds the part to something outside the model by holding the face under its head or the inside+of its hole. Screws between parts of the model: see "Bolted joints". Put a load where it really acts: on the face the+hand, the shelf or the shaft touches, not on a whole side.## Parts that touch@@ -58,7 +59,7 @@ Decide for each pair how it is really joined:|---|---|| glued, welded, printed in one piece, press-fitted | nothing (bonded) || resting on each other, can lift off | `study.contact("Lid", "Housing")` |-| clamped or screwed together, sliding is the question | `study.contact("Lid", "Housing", friction=0.2)` |+| clamped or screwed together, sliding is the question | `study.contact("Lid", "Housing", friction=0.2)`, the screws with `study.bolt()` |- `study.contact(part_a, part_b, friction=0.0)`: the touching faces press on each other, can lift off and slide.Friction about 0.1 to 0.2 for steel or aluminium, 0.3 to 0.5 for plastics on plastics, 0.5 or more for rubber.@@ -67,13 +68,39 @@ Decide for each pair how it is really joined:- A part held only by a contact without friction can slide sideways: the command says so before it calculates. Give itfriction, a `fix()` or leave it bonded. If a part slides or lifts off for good under the load, the calculation stopsand says so.-- Friction only holds where the load itself presses the faces together. Screws have no pre-tension here, so friction- under a screw head or between screwed-on plates holds nothing: leave screwed faces bonded, or hold the face under- the head with `fix()`, and use `contact()` for faces the load presses on or lifts off.+- Friction only holds where something presses the faces together: the load, or screws with `study.bolt()`. Without+ it, friction between screwed-on plates holds nothing.- The result gives per contact the force it carries, the highest pressure, where it is open (gap) and where it slidesat the friction limit. In the app, "Contact pressure" colours the touching faces.- Contact takes longer: from about ten seconds to a few minutes, mostly with friction.+## Bolted joints++A screw from `soma.fasteners` (`Screw(...)` passed to `add_part`) becomes a preloaded bolt with `study.bolt()`. It is+tightened first, then the loads act. This shows whether a screwed joint opens or slips, and how much the screw carries.++```python+study.contact("Plate", "Block", friction=0.2) # the faces the screw clamps together+study.bolt("Screw 1") # preload automatic, property class 8.8+study.bolt("Screw 2", preload=3000, grade="10.9")+```++- `study.bolt(screw, preload=None, grade="8.8")`. `preload` in N. Without it: 70 % of the yield strength of the screw,+ at most what the part under the head bears (for printed plastics only a few hundred N for M3). Classes: 4.6, 5.6,+ 8.8, 10.9, 12.9, A2-70, A4-70, A2-80 ...+- The screw, its nut and washers get steel of that class. Nut, washers and the parts the screw touches are added to+ the study by themselves.+- Head and thread (tapped hole or nut) are bonded, the shank must sit in a clearance hole (`screw.clearance_hole()`),+ the thread in `screw.tap_hole()` or a `Nut`. A tap hole smaller than the shank is fine. Otherwise the command says+ what is missing.+- Give the faces between the clamped parts `study.contact(..., friction=0.2)`. Bonded, the joint can neither open nor+ slip, and the preload only stresses the parts.+- The result has a line per bolt: preload, pull and shear in the end, and the share of the yield strength (from pull+ and shear, without the torsion from tightening). Over 90 % it is reported. The contact line shows whether the joint+ opens (gap) or slips.+- Bolts take longer: two calculation steps, often a few minutes with contact. A coarser mesh (`Study(mesh=...)`) helps+ while trying things out.+## Compute and read1. `soma build`, then `soma analyze fem analyses/bracket.py`. Takes from seconds to about a minute. The summary lists the@@ -98,9 +125,11 @@ Decide for each pair how it is really joined:## Limits-- Linear-elastic: no yielding, no buckling, no pre-tension of screws, no creep of plastics. Contact assumes small- sliding (the faces stay opposite each other).-- Bearings, hinges and screws are modelled through supports, loads and contact, not as joints.+- Linear-elastic: no yielding, no buckling, no creep of plastics. Contact assumes small sliding (the faces stay+ opposite each other).+- Bolts: no thread geometry (the thread is bonded, the first turn shows a stress peak), the head is bonded (it cannot+ lift or slip under the head), no torsion from tightening, preload does not drop by settling.+- Bearings and hinges are modelled through supports, loads and contact, not as joints.- Even materials: printing infill, layer direction and wood grain are not modelled. Printed parts are therefore computedwith the weaker strength across layers. Infill below 100 % makes them weaker still.- Static loads only. Impacts, vibration and fatigue need more safety or a test.diff --git a/app/src/renderer/analysispanel.ts b/app/src/renderer/analysispanel.tsindex 68d275e..54c8d56 100644--- a/app/src/renderer/analysispanel.ts+++ b/app/src/renderer/analysispanel.ts@@ -200,6 +200,16 @@ export class AnalysisPanel {det.push(['Slip', `up to ${loc(c.maxSlip, 3)} mm`]);sec.append(...this.row(`contact${i}`, 'Contact', c.friction ? `Friction ${loc(c.friction, 2)}` : 'No friction', `${c.a} – ${c.b}`, det));});+ // Schrauben mit Vorspannung: Kraft am Ende, Auslastung (über 90 % gelb wie im Bericht von soma)+ (fem.bolts ?? []).forEach((b, i) => {+ const use = el('span', { className: b.utilization > 0.9 ? 'wc' : '', textContent: `${Math.round(100 * b.utilization)} % of the yield strength` });+ const det: [string, string | HTMLElement][] = [+ ['Screw', `${b.designation}, ${b.grade}`], ['Thread in', b.engaged],+ ['Preload', `${loc(b.preload, 0)} N${b.auto ? (b.limit && b.limit !== 'screw' ? `, limited by ${b.limit}` : ', automatic') : ''}`],+ ['In the end', `${loc(b.force, 0)} N pull, ${loc(b.shear, 0)} N across`], ['Load', use],+ ];+ sec.append(...this.row(`bolt${i}`, 'Bolt', `${loc(b.force, 0)} N`, b.part, det));+ });const bonded = (fem.touching ?? []).filter((t) => t.joint === 'bonded');if (bonded.length) {const det: [string, string][] = bonded.map((t) => [`${t.a} – ${t.b}`, `${loc(t.area, 1)} mm²`]);diff --git a/app/src/shared/types.ts b/app/src/shared/types.tsindex 7ca136d..de38950 100644--- a/app/src/shared/types.ts+++ b/app/src/shared/types.ts@@ -304,7 +304,7 @@ export interface FemBc {axes?: string; reaction?: number[]; total?: number[]; value?: number;}/** Teile, die sich berühren (E84): verklebt oder als Kontakt der Studie. Fläche in mm². */-export interface FemTouching { a: string; b: string; area: number; joint: 'bonded' | 'contact'; friction: number | null }+export interface FemTouching { a: string; b: string; area: number; joint: 'bonded' | 'contact' | 'bolt'; friction: number | null }/*** Kontaktpaar (E84): getragene Kraft (N), höchste Pressung (MPa), offene Fläche (mm², hebt ab) mit größtem Spalt (mm),* größter Gleitweg (mm), mit Reibung die Fläche, die an der Haftgrenze gleitet.@@ -313,6 +313,15 @@ export interface FemContact {a: string; b: string; friction: number; area: number; force: number; maxPressure: { value: number; at: number[] };openArea: number; maxGap: number; maxSlip: number; slideArea?: number;}+/**+ * Vorgespannte Schraube (bolt()): Vorspannung und Kraft am Ende (N), Querkraft im Schaft (N), Zugspannung im+ * Spannungsquerschnitt (MPa), Auslastung der Streckgrenze aus Zug und Schub (1 = 100 %). `limit`: was die automatische+ * Vorspannung begrenzt hat ("screw" oder das Teil unter dem Kopf).+ */+export interface FemBolt {+ part: string; designation: string; grade: string; preload: number; auto: boolean; limit: string | null;+ force: number; shear: number; stress: number; utilization: number; engaged: string; at: number[];+}export interface FemInfo {study: string; bcs: FemBc[]; applied: number[]; reaction: number[]; maxDisp: number; diag: number;/** `auto`: Die Studie gibt keine Netzgröße vor (fehlt bei älteren Ergebnissen). */@@ -320,7 +329,7 @@ export interface FemInfo {/** Abweichung des Gleichgewichts (0.001 = 0.1 %), gröberes Netz der Prüfung, Schwerkraft (m/s², null: ohne). */balance?: number; coarse?: { size: number; elements: number } | null; gravity?: number[] | null;/** Berührende Teile und Kontaktpaare (E84, fehlen bei älteren Ergebnissen). */- touching?: FemTouching[]; contacts?: FemContact[];+ touching?: FemTouching[]; contacts?: FemContact[]; bolts?: FemBolt[];}export interface ResultMeta {id: string; kind: string; title: string; quantity: string; unit: string;diff --git a/app/test/fem.mjs b/app/test/fem.mjsindex 12b1217..bed46ff 100644--- a/app/test/fem.mjs+++ b/app/test/fem.mjs@@ -19,6 +19,7 @@ const PY = process.env.SOMA_PYTHON || path.join(process.env.LOCALAPPDATA ?? '',// Konsole aus dem Beispiel im Skillconst MODEL = `import cadquery as cqfrom soma import add_part+from soma.fasteners import Screwadd_part("Balken", cq.Workplane().box(100, 10, 10, centered=(False, True, True)))fuss = cq.Workplane().box(60, 40, 5, centered=(True, True, False)).translate((0, 100, 0))@@ -32,6 +33,11 @@ add_part("Bracket", bracket)add_part("Grund", cq.Workplane().box(100, 100, 10, centered=(True, True, False)).translate((0, 250, -10)))add_part("Halter", cq.Workplane().box(60, 60, 8, centered=(True, True, False)).union(cq.Workplane().box(20, 12, 80, centered=(True, True, False)).translate((0, 0, 8))).translate((0, 250, 0)))+# Lasche mit einer Schraube M5 auf einem Sockel mit Gewinde (bolt())+screw = Screw("ISO 4762", "M5x16", at=(0, -250, 6))+add_part("Sockel", cq.Workplane().box(30, 30, 12, centered=(True, True, False)).translate((0, -250, -12)).cut(screw.tap_hole()))+add_part("Lasche", cq.Workplane().box(30, 30, 6, centered=(True, True, False)).translate((0, -250, 0)).cut(screw.clearance_hole()))+add_part("Schraube", screw)`;const BALKEN = (n) => `from soma.fem import Studystudy = Study("Balken unter Last", material="Aluminium 6082", safety=2)@@ -73,7 +79,7 @@ try {await waitFor('Projekt und Build', () => !!window.__t && !!window.__t.project() && window.__t.status().state === 'ok' && window.__t.partCount() > 0);const dir = (await ev(() => window.__t.project())).dir;fs.writeFileSync(path.join(dir, 'model.py'), MODEL);- await waitFor('Testmodell gebaut', () => window.__t.status().state === 'ok' && window.__t.partCount() === 6, 90000);+ await waitFor('Testmodell gebaut', () => window.__t.status().state === 'ok' && window.__t.partCount() === 9, 90000);const bridge = await ev(() => window.soma.test.bridge());const env = { ...process.env, ...bridge, PYTHONUTF8: '1', PYTHONIOENCODING: 'utf-8' };const soma = (args) => spawnSync(PY, ['-m', 'soma', ...args], { cwd: dir, env, encoding: 'utf8', timeout: 10 * 60 * 1000 });@@ -258,7 +264,7 @@ try {&& an.table.some((row) => row[0] === 'Balken' && /^0\.5[67]\d$/.test(row[3])), JSON.stringify(an));await domClick('btn-result-close');check('× in der Leiste: Analyse aus, Modell wieder sichtbar, Baum mit allen Teilen, Bericht wird zur Liste', !(await ev(() => window.__t.viewer.animViewState())).modelHidden- && (await ev(() => window.__t.tree())).names.length === 6 && (await ev(() => window.__t.analysis())).mode === 'list');+ && (await ev(() => window.__t.tree())).names.length === 9 && (await ev(() => window.__t.analysis())).mode === 'list');// Schnitt durch verschmolzene Teile: Jedes Netz ist für sich geschlossen, auch an der Fläche, an der die Wand auf dem Fuß// steht. Sonst füllt der Deckel des Schnitts auch Stellen, an denen der Blick durch diese Fläche geht@@ -334,6 +340,45 @@ study.contact("Grund", "Halter", friction=0.2)&& /contact: Grund – Halter \(3600\.0 mm², friction 0\.2\), carries 200\.0 N/.test(r.stdout) && r.stdout.includes('(in equilibrium)')&& !r.stdout.includes('softer one'), r.stdout + r.stderr);+ // Verschraubung: erst 3000 N Vorspannung, dann 1000 N Zug an der Lasche. Die Fuge trägt die Vorspannung minus den Zug+ const LASCHE = (extra) => `from soma.fem import Study+study = Study("Lasche verschraubt", material="Aluminium 6082", mesh=4, check_mesh=False)+study.fix("Sockel", faces="<Z")+study.force("Lasche", faces=">Z", N=(0, 0, 1000))+${extra}+`;+ study('lasche', LASCHE('study.contact("Sockel", "Lasche", friction=0.2)\nstudy.bolt("Schraube", preload=3000)'));+ r = soma(['analyze', 'fem', 'analyses/lasche.py']);+ const bf = Number(/bolt: Schraube \(ISO 4762 M5x16, 8\.8, thread in Sockel\), preload 3000 N \(given\), in the end (\d+) N pull/.exec(r.stdout)?.[1]);+ const jf = Number(/contact: Sockel – Lasche \([\d.]+ mm², friction 0\.2\), carries (\d+\.\d) N/.exec(r.stdout)?.[1]);+ check('bolt(): Vorspannung 3000 N, Schraube am Ende etwas mehr, Fuge trägt Schraubenkraft minus Zug, im Gleichgewicht', r.status === 0+ && bf >= 3000 && bf < 3300 && near(jf, bf - 1000, 15) && r.stdout.includes('linear elastic, with contact and bolts')+ && r.stdout.includes('touching: Lasche – Schraube') && r.stdout.includes('bonded (bolt: head and thread)')+ && r.stdout.includes('(in equilibrium)') && /2 load steps/.test(r.stdout), r.stdout + r.stderr);+ await ev(() => window.__t.refreshViewLists());+ await ev(() => window.__t.resultShow('lasche'));+ await waitFor('Ergebnis Lasche geladen', () => window.__t.result().id === 'lasche', 20000);+ await ev(() => window.__t.showPanel('analysis'));+ await waitFor('Bericht Lasche', () => window.__t.analysis().title === 'Lasche verschraubt', 20000);+ await ev(() => window.__t.analysisToggle('bolt0'));+ an = await ev(() => window.__t.analysis());+ check('Bericht: Zeile Bolt mit Kraft und Schraube, aufgeklappt Vorspannung und Auslastung', an.inputs.some((x) => x.startsWith('Bolt') && x.includes('· Schraube'))+ && an.details.some((x) => x.includes('Preload3,000 N') && x.includes('of the yield strength')), JSON.stringify(an));+ const boltIds = await ev(() => window.__t.viewer.partList().filter((p) => ['Sockel', 'Lasche', 'Schraube'].includes(p.name)).map((p) => p.id));+ await ev(() => window.__t.viewer.setSection({ normal: [0, 1, 0], constant: 250 }));+ await ev((ids) => window.__t.viewer.setView('front', ids), boltIds);+ await shot('fem-6-schraube');+ await ev(() => window.__t.viewer.setSection(null));+ await domClick('btn-result-close');+ // Ohne Kontakt und ohne Angabe: Vorspannung 70 % der Streckgrenze im Spannungsquerschnitt (0.7 x 640 x 14.18 mm²)+ study('lasche', LASCHE('study.bolt("Schraube")'));+ r = soma(['analyze', 'fem', 'analyses/lasche.py']);+ check('bolt() ohne preload: 6354 N automatisch, Schraube aus Stahl 8.8', r.status === 0 && r.stdout.includes('preload 6354 N (automatic)')+ && r.stdout.includes('Schraube (steel 8.8, E 210000 MPa, strength 640 MPa)'), r.stdout + r.stderr);+ study('lasche', LASCHE('study.bolt("Lasche")'));+ r = soma(['analyze', 'fem', 'analyses/lasche.py']);+ check('bolt() auf einem Teil, das keine Schraube ist: Meldung', r.status !== 0 && (r.stdout + r.stderr).includes("bolt('Lasche'): not a screw from soma.fasteners"), r.stdout + r.stderr);+// 8) Das Beispiel im Skill läuft so, wie es dastehtconst skill = fs.readFileSync(path.join(APP, 'resources', 'skills', 'fem.md'), 'utf8');const block = /```python\r?\n([\s\S]*?)\r?\n```/.exec(skill)?.[1] ?? '';