Skip to content
CubeTwin

Documentation · Mathematical modelling and simulation

The CubeTwin engine: physics-based simulation of a CubeSat

CubeTwin's engine couples 9 small, separately specified models (orbit, Sun, eclipse, attitude, solar array, battery, power system, thermal and the runtime itself) into one deterministic simulation with located events and an energy ledger that closes to round-off. It is written twice, in TypeScript and Python, from the same specifications.

Implemented

  • 9 L1 models, each specified, implemented and verified (G2)
  • Deterministic hybrid runtime with event location
  • Electrical and thermal ledgers
  • Independent Python reference implementation of the same specifications
  • Runs in a Web Worker in the browser; up to 14 simulated days

Experimental

  • Synthetic telemetry (SYNTHETIC label) and a one-state Kalman SOC estimator as a method demonstration

Planned

  • L2 models: equivalent-circuit battery, numerical orbit, thermal network (R2–R3)
  • Parameter sweeps, sensitivity, Monte Carlo and solver comparison (R5)
  • Telemetry ingestion and calibration against a physical demonstrator (R4)
Integration
fixed base step (10 s in the reference mission) split at located events
Event location
eclipse entry and exit bisected to 1 ms; battery limits and SOC thresholds solved exactly
Determinism
identical parameters give a bit-identical trajectory; no randomness in the runtime
Energy closure, nominal 24 h
−9.5 × 10⁻¹² Wh electrical residual (engine)
The CubeTwin engineering platform: scenario, attitude and view controls on the left, the 3D CubeSat with live engine telemetry in the centre, and the run summary with the component list on the right.
The CubeTwin platform at /platform: every number on screen is computed by the CubeTwin engine (simulated data, not flight software).

Definition

Physics-based simulation computes a system's behaviour from equations derived from physical laws, rather than from fitted data alone. Mathematical modelling is the step before: choosing the variables, assumptions and equations, and stating where they are valid.

In CubeTwin each model has a written specification (equations, symbols, units, assumptions, validity range, numerical method, verification cases) and a credibility card. The code follows the specification, and independent fixtures generated from the specification test the code.

Engineering purpose

A coupled simulation answers questions no single model can: whether a spacecraft in a given attitude and operating plan keeps a positive energy balance over many orbits, when it would enter safe mode, how much energy is curtailed or unmet, and how warm it runs. Because every number the 3D platform, the Keynote, the lesson and the experiment show comes from this engine, they always agree with each other.

Architecture

The engine (packages/core) has no React, no three.js and no DOM. The renderer (packages/three) reads engine state and computes no physics. The Python package (python/cubesat_twin) implements the same specifications with the standard library only. Parameters come from one provenance-annotated file validated by a JSON Schema.

Physical principles and model graph

Each arrow is a quantity passed from one model to another, generated from the coupling table in the engine:

FromQuantityTo
Circular two-body orbitposition r (m)Cylindrical Earth shadow
Sun directionSun direction ŝCylindrical Earth shadow
Circular two-body orbitr, vKinematic attitude modes
Sun directionŝKinematic attitude modes
Kinematic attitude modesface normals n̂ₖBody-mounted solar array
Cylindrical Earth shadowshadow (0/1)Body-mounted solar array
Sun directionirradiance S (W/m²)Body-mounted solar array
Body-mounted solar arrayP_bus (W)EPS balance, loads and modes
EPS balance, loads and modesrequest P_b (W)Battery energy reservoir
Battery energy reservoirSOC threshold eventsEPS balance, loads and modes
Battery energy reservoirĖ (W)One-node thermal balance
Body-mounted solar arrayabsorbed sunlight (W)One-node thermal balance
One-node thermal balanceT (heater, sampled)EPS balance, loads and modes

Numerical method

Simulation time advances on a base grid tk=k Δtt_k = k\,\Delta t, independent of wall-clock time and frame rate. Each sub-step [t0,t1][t_0, t_1]:

  1. Evaluate the discrete state at t0t_0: mode, heater, payload and contact windows, shadow, attitude, loads.
  2. Shorten t1t_1 to the next known breakpoint (window edge, dwell completion, end of run).
  3. If the shadow state changes, bisect to 1 ms and end the sub-step there.
  4. Array power as a Simpson mean: Pˉ=(P0+4Pm+P1)/6\bar P = (P_0 + 4P_m + P_1)/6.
  5. Battery request Pb=Pload−PˉbusP_b = P_{load} - \bar P_{bus}; if stored energy would cross a limit or threshold, end the sub-step at the crossing and redo 4–5.
  6. Integrate battery energy exactly and compute the electrical ledger terms.
  7. Thermal: classical RK4 from t0t_0 to t1t_1 with geometry evaluated at each stage.
  8. Record a sample (state, ledger rates, attitude quaternion, per-face values, provenance) and any events.
Tn+1=Tn+h6(k1+2k2+2k3+k4)T_{n+1} = T_n + \tfrac{h}{6}\left(k_1 + 2k_2 + 2k_3 + k_4\right)

Coupling order within a sub-step: environment → attitude → solar → loads and modes → EPS → battery → thermal. Temperature affects the next sub-step's heater decision (sampled, delay ≤ Δt); state of charge affects the mode only through located threshold events.

System behaviour and operating conditions

Outputs: the full trajectory, events, ledgers, metrics and provenance (engine and parameter versions). Seeking and scrubbing read stored samples, with linear interpolation of continuous states and zero-order hold of discrete ones; nothing is reconstructed by reversing an animation. Telemetry resampled for charts is labelled origin: SIMULATED.

Limits: duration up to 14 days and at most 500 000 base steps.

Interfaces and dependencies

Input: the parameter file spec/parameters/reference-3u.json plus scenario overrides. Output consumers: the 3D platform, the Keynote, the lesson and the experiment (the last three run the engine in a Web Worker), CSV and JSON exports, and the cross-runtime reference fixtures.

Failure scenarios

The engine reports its own numerical health: event iterations, unconverged event steps and threshold corrections are recorded as diagnostics with every run. Physical fault scenarios are on the fault scenarios page.

Model fidelity, assumptions and limitations

All models are L1: the simplest physically meaningful level. The models used by each subsystem page:

ModelIDVersionVerificationValidation
Circular two-body orbitorbit.circular.l11.0.0Verified (G2)None
Sun directionenvironment.sun.l11.0.0Verified (G2)None
Cylindrical Earth shadowenvironment.eclipse.cylindrical.l11.0.0Verified (G2)None
Kinematic attitude modesattitude.kinematic.l11.0.0Verified (G2)None
Body-mounted solar arraysolar.body-mounted.l11.0.0Verified (G2)None
Battery energy reservoirbattery.energy.l11.0.0Verified (G2)None
EPS balance, loads and modeseps.balance-modes.l11.0.0Verified (G2)None
One-node thermal balancethermal.one-node.l11.0.0Verified (G2)None
Hybrid runtimeruntime.hybrid.l11.0.0Verified (G2)None

Hybrid runtime runtime.hybrid.l1 v1.0.0

Intended use
Deterministic coupled simulation with located events
Assumptions
  • Fixed base step with event splitting
Limitations
  • Threshold events exact only within the averaged-power approximation
  • Heater thermostat sampled (delay ≤ Δt)
Verification
Verified (G2): independent fixtures pass in the TypeScript and Python implementations
Validation
None. No measured data from an identified spacecraft exists (internal maturity M2).
Specification
spec/models/runtime.md · TypeScript packages/core/src/simulate.ts · Python python/cubesat_twin/simulate.py

Verification and validation evidence

Two runs give bit-identical output; event times, final state of charge and ledgers converge as the base step halves (10, 5, 2.5 s); the electrical ledger closes within 10⁻⁹ Wh per 24 h; TypeScript and Python agree on eight reference cases at relative 10⁻⁹. Full evidence: verification and validation.

References

  1. NASA-STD-7009B NASA Office of the Chief Engineer. Standard for Models and Simulations, NASA-STD-7009B, approved 5 March 2024. standards.nasa.gov/sites/default/files/standards/NASA/B/1/NASA-STD-7009B-Final-3-5-2024.pdf (opens in a new tab) Used for: Definitions of verification and validation; the structure of CubeTwin's model credibility cards. No compliance with the standard is claimed. Verified.
  2. NASEM2024 National Academies of Sciences, Engineering, and Medicine (2024). Foundational Research Gaps and Future Directions for Digital Twins. The National Academies Press. doi.org/10.17226/26894 (opens in a new tab) Used for: Definition of a digital twin and the role of verification, validation and uncertainty quantification (VVUQ). Verified.
  3. Kritzinger2018 Kritzinger, W., Karner, M., Traar, G., Henjes, J., Sihn, W. (2018). Digital Twin in manufacturing: A categorical literature review and classification. IFAC-PapersOnLine 51(11), 1016–1022. doi.org/10.1016/j.ifacol.2018.08.474 (opens in a new tab) Used for: Digital model, digital shadow and digital twin distinguished by the level of data integration. Verified.

Run it in CubeTwin