Resources Numerical accuracy Calculation policy

Magnetics add-on: readouts in the panel

Formats the flux density, forces and flux per line that the magnet study shows, and states the size of the air box.

How the precision is kept

The study is solved elsewhere, through magnetSolve in phys-worker.js; this file formats the 64-bit results for the panel. Readouts are shortened with toPrecision, 4 significant digits by default. The exported CSV and VTK files are written by lib/results.js.

Calculations under this policy

2 calculations in 1 source file. The code is read from the released app when this page loads. It is the calculation people run, not a copy kept for this page.

addons/magnetics/main.js PartCraft 0.8.1 64-bit 2 calculations Reviewed

Tests tools/addons-test/browser-magnetics.mjs

Readout rounding and flux units

64-bit

The text of each number in the results panel.

text = v to p significant digits (p = 4 by default); flux in mWb when |Φ| ≥ 10⁻³ Wb, else µWb

toPrecision(p) on the 64-bit result, converted back to a number to drop trailing zeros. Flux is multiplied by 1e3 or 1e6 before rounding. These are display texts; the solver's values are not changed.

  • addons/magnetics/main.js
  • lines 120 to 121
  • PartCraft 0.8.1
const fmt = (v, p = 4) => String(+Number(v).toPrecision(p));
function fmtFlux(wb) { const a = Math.abs(wb); return a >= 1e-3 ? fmt(wb * 1e3) + ' mWb' : fmt(wb * 1e6) + ' µWb'; }   // i18n-ignore: units

Air box size

64-bit

The width and height of the air box shown under the setup.

margin = max(width, height) × pad; box = extent + 2 × margin

The extent is the minimum and maximum over every loop vertex in 64-bit. The text shows 4 significant digits.

  • addons/magnetics/main.js
  • lines 232 to 239
  • PartCraft 0.8.1
// the air box: its margin and size
let boxText = '';
if (su.loops && su.loops.length) {
  let x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity;
  for (const l of su.loops) for (const [x, y] of l) { x0 = Math.min(x0, x); y0 = Math.min(y0, y); x1 = Math.max(x1, x); y1 = Math.max(y1, y); }
  const m = Math.max(x1 - x0, y1 - y0) * st.pad;
  boxText = t('box.size', { w: fmt(x1 - x0 + 2 * m, 4), h: fmt(y1 - y0 + 2 * m, 4) });
}

In detail

Method
Results are formatted with toPrecision and converted back to a number, which drops trailing zeros.
Number types
64-bit numbers; text with 3 or 4 significant digits in the panel.
Limits
Panel readouts show 4 significant digits by default and 3 for the mean and maximum flux density of a body.

Approach: 64-bit, direct

Every value is a 64-bit number from input to result. Formulas are closed form or a direct solve, and every comparison uses a stated tolerance.

Every policy that takes this approach