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)

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:
| From | Quantity | To |
|---|---|---|
| Circular two-body orbit | position r (m) | Cylindrical Earth shadow |
| Sun direction | Sun direction ŝ | Cylindrical Earth shadow |
| Circular two-body orbit | r, v | Kinematic attitude modes |
| Sun direction | ŝ | Kinematic attitude modes |
| Kinematic attitude modes | face normals n̂ₖ | Body-mounted solar array |
| Cylindrical Earth shadow | shadow (0/1) | Body-mounted solar array |
| Sun direction | irradiance S (W/m²) | Body-mounted solar array |
| Body-mounted solar array | P_bus (W) | EPS balance, loads and modes |
| EPS balance, loads and modes | request P_b (W) | Battery energy reservoir |
| Battery energy reservoir | SOC threshold events | EPS balance, loads and modes |
| Battery energy reservoir | Ė (W) | One-node thermal balance |
| Body-mounted solar array | absorbed sunlight (W) | One-node thermal balance |
| One-node thermal balance | T (heater, sampled) | EPS balance, loads and modes |
Numerical method
Simulation time advances on a base grid , independent of wall-clock time and frame rate. Each sub-step :
- Evaluate the discrete state at : mode, heater, payload and contact windows, shadow, attitude, loads.
- Shorten to the next known breakpoint (window edge, dwell completion, end of run).
- If the shadow state changes, bisect to 1 ms and end the sub-step there.
- Array power as a Simpson mean: .
- Battery request ; if stored energy would cross a limit or threshold, end the sub-step at the crossing and redo 4–5.
- Integrate battery energy exactly and compute the electrical ledger terms.
- Thermal: classical RK4 from to with geometry evaluated at each stage.
- Record a sample (state, ledger rates, attitude quaternion, per-face values, provenance) and any events.
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:
| Model | ID | Version | Verification | Validation |
|---|---|---|---|---|
| Circular two-body orbit | orbit.circular.l1 | 1.0.0 | Verified (G2) | None |
| Sun direction | environment.sun.l1 | 1.0.0 | Verified (G2) | None |
| Cylindrical Earth shadow | environment.eclipse.cylindrical.l1 | 1.0.0 | Verified (G2) | None |
| Kinematic attitude modes | attitude.kinematic.l1 | 1.0.0 | Verified (G2) | None |
| Body-mounted solar array | solar.body-mounted.l1 | 1.0.0 | Verified (G2) | None |
| Battery energy reservoir | battery.energy.l1 | 1.0.0 | Verified (G2) | None |
| EPS balance, loads and modes | eps.balance-modes.l1 | 1.0.0 | Verified (G2) | None |
| One-node thermal balance | thermal.one-node.l1 | 1.0.0 | Verified (G2) | None |
| Hybrid runtime | runtime.hybrid.l1 | 1.0.0 | Verified (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· TypeScriptpackages/core/src/simulate.ts· Pythonpython/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
- 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.
- 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.
- 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.