Resources Numerical accuracy Calculation policy

Environment: gravity, ambient pressure and temperature

Sets the gravity, ambient pressure and ambient temperature the solvers use, and converts them to the solvers' units.

How the precision is kept

The conversions are single 64-bit products, quotients or differences. Earth uses standard gravity 9.80665 m/s² and the standard atmosphere 101325 Pa. The Moon and Mars figures are published values quoted to three digits, and each preset stores the text of its source. A job without an environment is returned unchanged.

Calculations under this policy

7 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.

env/env.js PartCraft 0.8.1 64-bit 7 calculations Reviewed

Tests tools/env-test/env.mjs

Preset figures

64-bit

The gravity, pressure and temperature each world starts from.

Earth uses 9.80665 m/s² and 101325 Pa, the defined standard values. Moon 1.62 m/s², Mars 3.71 m/s² and 636 Pa are rounded published figures; the source text for each is stored beside it.

  • env/env.js
  • lines 26 to 35
  • PartCraft 0.8.1
/**
 * Figures a preset starts from. `source` says where each comes from; the temperature of a world with no atmosphere to speak of is a
 * mean the designer is expected to replace with the case that matters (`range` is the swing to check against).
 */
export const PRESETS = {
  earth: { g: 9.80665, pressure: 101325, temperature: 20, range: [-89, 57], source: 'standard gravity (CGPM 1901), standard atmosphere (exact), 20 °C reference temperature (ISO 1)' },
  moon: { g: 1.62, pressure: 0, temperature: -23, range: [-173, 123], source: 'NASA lunar fact sheet: surface gravity 1.62 m/s², mean surface temperature about 250 K, 100–396 K between night and day' },
  mars: { g: 3.71, pressure: 636, temperature: -63, range: [-143, 27], source: 'NASA Mars fact sheet: surface gravity 3.71 m/s², mean surface pressure about 636 Pa, mean temperature about 210 K' },
  orbit: { g: 0, pressure: 0, temperature: 20, range: [-65, 125], source: 'free fall (no apparent weight; tidal terms ignored); no ambient pressure; 20 °C is an assumed interior temperature, not a figure' },
};

Gravity in solver units

64-bit

Gravity in mm/s² for a gravity load.

g mm/s² = g m/s² × 1000

One 64-bit product by the whole number 1000.

  • env/env.js
  • lines 70 to 71
  • PartCraft 0.8.1
/** Gravity in mm/s², the unit the solvers use. */
export const gravityMM = (env) => env.g * 1000;

Ambient pressure in MPa

64-bit

The ambient pressure in the solvers' unit.

p MPa = p Pa ÷ 10⁶

One 64-bit division by the whole number 1,000,000.

  • env/env.js
  • lines 72 to 73
  • PartCraft 0.8.1
/** Ambient pressure in MPa (N/mm²). */
export const pressureMPa = (env) => env.pressure / 1e6;

Gauge pressure

64-bit

The pressure that loads the wall of a sealed volume.

gauge = absolute − ambient

A plain difference in MPa. When the absolute pressure is close to ambient the difference loses leading digits, as any subtraction of nearly equal numbers does.

  • env/env.js
  • lines 74 to 75
  • PartCraft 0.8.1
/** Gauge pressure for a sealed volume at `absoluteMPa` inside: what loads the walls. Negative = the outside pushes harder. */
export const gaugeMPa = (env, absoluteMPa) => absoluteMPa - pressureMPa(env);

Weight of a mass

64-bit

Weight in newtons from a mass in kilograms.

W = m × g

One 64-bit product of the mass and the environment's gravity in m/s².

  • env/env.js
  • lines 76 to 77
  • PartCraft 0.8.1
/** Weight in newtons of a mass in kg. */
export const weightN = (env, kg) => kg * env.g;

Loads filled in from the environment

64-bit

Gives a solver job its gravity, gauge pressures and ambient temperatures.

Gravity loads without their own g get g × 1000 mm/s². Pressure loads marked absolute become gauge pressures and keep the original value as gaugeOf. Missing ambient and reference temperatures are set. Nothing is rounded, and the job is marked with the key so a second call changes nothing.

  • env/env.js
  • lines 113 to 137
  • PartCraft 0.8.1
/**
 * Fill in everything the environment decides. Returns a copy of `job` (the argument is not changed); a job with no `env` is
 * returned as it came. Safe to call twice (a second call finds nothing left to fill). The job shape is the solvers':
 *   job.bcs.loads[]  {type 'gravity', dir, g?} | {type 'pressure', p, absolute?} | …
 *   job.heat[]       {type 'convection'|'radiation', Tamb?} | …
 *   job.thermalLoad  {mode, dT, Tref?}
 *   job.env          the environment (readEnv shape)
 * `job.envApplied` is set to the key that was applied.
 */
export function applyEnv(job) {
  if (!job || !job.env) return job;
  const env = job.env, key = envKey(env);
  if (job.envApplied === key) return job;
  const out = { ...job, envApplied: key };
  if (job.bcs && Array.isArray(job.bcs.loads)) {
    out.bcs = { ...job.bcs, loads: job.bcs.loads.map((l) => {
      if (l.type === 'gravity' && (l.g === undefined || l.g === null)) return { ...l, g: gravityMM(env) };
      if (l.type === 'pressure' && l.absolute === true) { const { absolute, ...rest } = l; return { ...rest, p: gaugeMPa(env, l.p), gaugeOf: l.p }; }
      return l;
    }) };
  }
  if (Array.isArray(job.heat)) out.heat = job.heat.map((h) => ((h.type === 'convection' || h.type === 'radiation') && (h.Tamb === undefined || h.Tamb === null) ? { ...h, Tamb: env.temperature } : h));
  if (job.thermalLoad && (job.thermalLoad.Tref === undefined || job.thermalLoad.Tref === null)) out.thermalLoad = { ...job.thermalLoad, Tref: env.temperature };
  return out;
}

Cache key

64-bit

A short text that says whether the environment changed since a result was made.

Each field is rounded with toPrecision(10) for the key only. Two environments equal to 10 significant digits get the same key, and a job already marked with that key is not filled in again.

  • env/env.js
  • lines 67 to 68
  • PartCraft 0.8.1
/** A short stable string for caching ("did the environment change since this result?"). */
export const envKey = (env) => (env ? [env.g, env.pressure, env.temperature].map((v) => +v.toPrecision(10)).join('|') : 'none');

In detail

Method
applyEnv fills gravity loads, absolute pressure loads and missing ambient or reference temperatures from the environment and returns a copy of the job.
Number types
64-bit numbers. The environment is in m/s², Pa and °C; the solvers use mm/s² and MPa.
Limits
Moon 1.62 m/s², Mars 3.71 m/s² and 636 Pa are three-digit published figures. The cache key rounds each field to 10 significant digits.

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