Resources Numerical accuracy Calculation policy

Flowsheet variant metrics

Works out the heating, cooling and shaft power, the hourly operating cost and the hourly CO2 of one solved flowsheet variant, the numbers an optimization study ranks by.

How the precision is kept

Unit duties in watts are summed in 64-bit and scaled by powers of ten and by 3600. Prices and emission factors are the person's own; a missing one makes the metric that needs it NaN, and makeStudy refuses an objective whose prices or factors were not given.

Calculations under this policy

1 calculation 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/optimise.js CadCraft 0.8.2 64-bit 1 calculation Reviewed

Tests tools/process-test/test-link.mjs, tools/process-test/test-chemmount5.mjs

Energy, cost and CO2 of a variant

64-bit

The totals a variant is judged by: heating, cooling and shaft power in kW, operating cost per hour and kg CO2 per hour.

cost/h = (heat × p_heat + cool × p_cool) × 3600 ÷ 1e9 + (shaft ÷ 1e3) × p_power; CO2/h = (heat × 3600 ÷ 1e9) × f_heat + (shaft ÷ 1e3) × f_power

Duties are summed over the units in order, in 64-bit; the scale factors 1e3, 1e9 and 3600 are exact. A price or factor that is missing enters as NaN, so the result is NaN and not a default.

  • process/optimise.js
  • lines 24 to 33
  • CadCraft 0.8.2
export function metricsOf(result, metrics, { prices = null, factors = null, th = null } = {}) {
  let heat = 0, cool = 0, shaft = 0;
  for (const u of Object.values(result.units || {})) { const Q = u.Q || 0, W = u.W || 0; if (Q > 0) heat += Q; else cool += -Q; if (W > 0) shaft += W; }
  const all = { heat_kW: heat / 1e3, cool_kW: cool / 1e3, shaft_kW: shaft / 1e3, energy_kW: (heat + cool + shaft) / 1e3 };
  if (prices) all.operating_per_h = ((heat * (prices.heat ?? NaN) + cool * (prices.cool ?? NaN)) * 3600 / 1e9) + (shaft / 1e3) * (prices.power ?? NaN);
  if (factors) all.co2_kg_h = (heat * 3600 / 1e9) * (factors.heat ?? NaN) + (shaft / 1e3) * (factors.power ?? NaN);
  const out = {};
  for (const m of metrics) out[m.key] = typeof m.metric === 'string' ? all[m.metric] : propOf(th, result, m.metric);
  return out;
}

In detail

Method
heat = Σ positive Q; cool = Σ of the negative Q, sign changed; shaft = Σ positive W; cost per hour = (heat × heat price + cool × cooling price) × 3600 ÷ 1e9 + shaft ÷ 1e3 × power price; CO2 per hour = heat × 3600 ÷ 1e9 × heat factor + shaft ÷ 1e3 × power factor.
Number types
64-bit numbers.
Limits
Negative shaft work (power produced) is not counted.

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