Resources Numerical accuracy Calculation policy

Fitting losses summed from a pack

Adds up the loss coefficients K of the fittings on a pipe link and turns K into a head loss.

How the precision is kept

The sum and the head loss are 64-bit. The constants K1, Kinf, Ki and Kd come from a pack and k2K and k3K (in transient.js, not in this review) turn them into K, so the accuracy is set by the pack, which the code marks as a draft.

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.

process/equip/fittingk.js CadCraft 0.8.2 64-bit 2 calculations Reviewed

Tests tools/process-test/test-fittingk.mjs

Summed K of a list of fittings

64-bit

The total loss coefficient of the fittings on one link at its own Reynolds number and diameter.

K = Σ nᵢ × Kᵢ(Re, D)

Adds count times K for each fitting in order in a 64-bit sum; K for each comes from k2K or k3K. 3-K uses the row nominal size nps when it is given, otherwise the link diameter.

  • process/equip/fittingk.js
  • lines 74 to 85
  • CadCraft 0.8.2
export function kOfList(pack, list, Re, Dinch) {
  let c = cleaned.get(pack); if (!c) { c = cleanFittingPack(pack); cleaned.set(pack, c); }
  if (!c.ok) throw needs(c.problems.join('; '));
  let K = 0;
  for (const f of list || []) {
    const method = f.method === '2K' ? '2K' : '3K', row = c.pack.methods[method].fittings.find((x) => x.id === f.id);
    if (!row) throw new Error(`No fitting "${f.id}" in the ${method} table of the fitting pack.`);
    const n = f.count == null ? 1 : +f.count; if (!(n >= 0)) throw new Error('a fitting count must be zero or more');
    K += n * (method === '2K' ? k2K(row, Re, Dinch) : k3K(row, Re, f.nps > 0 ? f.nps : Dinch));
  }
  return K;
}

Head loss of a fitting

64-bit

The head loss in meters from K and the velocity.

h = K × v² ÷ (2g)

Uses g = 9.80665 m/s², the standard gravity value, written as the constant G; evaluated K × v × v ÷ (2 × G) in 64-bit.

  • process/equip/fittingk.js
  • line 64
  • CadCraft 0.8.2
if (v != null) { if (!(v >= 0)) throw new Error('v must be a velocity in m/s'); out.headLoss_m = K * v * v / (2 * G); }

In detail

Method
K = Σ count × K of each fitting by the 2-K or 3-K form; head loss = K v² ÷ (2g).
Number types
64-bit numbers; the count is read with unary plus and must be zero or more.
Tolerances
None; a fitting that is not in the pack throws instead of counting as K = 0. A Reynolds number below 100 only adds a note.
Limits
The bundled pack is a draft that the code says is not checked against the papers. The 2-K form takes the actual inside diameter and the 3-K form the nominal size, in inches.

Approach: 64-bit, stated limit

The arithmetic is 64-bit, but the method or the data sets the accuracy: a solver tolerance, a mesh, a step size, a datum shift, a table. The limit is stated where the result is shown.

Every policy that takes this approach