active library

cosmos-engine

Design vision for a next-generation 3D emergent physics simulation platform targeting 10M+ particles — mesoscale force models, Particle Mesh gravity, spring networks, composite bodies, a Scheme-inspired DSL, and GPU architecture

Started 2026

Resources & Distribution

Source Code

Package Registries

Cosmos Engine

Emergent physics simulation at planetary scale.

10+ million particles forming composite structures with emergent properties. Stars that generate stellar wind from plasma dynamics. Planets with layered internal structure that deforms and fractures under tidal stress. Spacecraft that crumple and tear under impact – not from damage models, but from physics.

Cosmos Engine is a design vision for a next-generation 3D particle simulation platform where complex phenomena emerge from simple physical rules. This repository contains the complete design documentation – from mesoscale force models to GPU kernel architectures, from a Scheme-inspired scripting DSL to distributed computation strategies.

The Core Insight

Complexity emerges from simplicity. Rather than programming explicit behaviors for stars, planets, and collisions, Cosmos Engine defines a minimal set of physical interactions at the mesoscale:

  • Gravity via Particle Mesh (O(N) FFT-based, toroidal topology, GPU-native)
  • Contact forces via Hertzian spring-damper model
  • Structural bonds via dynamic spring networks with fatigue and plastic deformation
  • Thermal dynamics from kinetic energy distributions and radiation transfer
  • Electromagnetic forces from charge distributions and plasma currents

From these building blocks, everything else emerges: stellar wind, tidal disruption, crater formation, atmospheric drag, phase transitions, orbital resonances, crystal growth, and phenomena we haven’t anticipated.

Why Mesoscale?

Each Cosmos Engine particle represents a significant chunk of matter – 1000 tons of asteroid rock, 1 km^3 of planetary mantle, millions of tons of stellar plasma. This is deliberate. Molecular forces (Lennard-Jones, Morse potentials) belong at the atomic scale. At Cosmos Engine’s mesoscale, the emergent properties of molecular interactions are already baked into material properties: density, stiffness, breaking strength, thermal conductivity. See Scale Rationale for the full argument.

Design Documents

Core Physics

DocumentScope
Emergent Physics DesignMaster reference – 90-page LaTeX document covering all physics systems
Integration MethodsSymplectic integrators, adaptive timestep, multi-rate schemes
Soft Contact ForcesHertzian contact model, spring-damper collision response
Spring System DesignDynamic spring networks, material properties, fatigue
Virtual Spring DesignMaterial-based spring generation, automatic bonding
Material Spring SystemMaterial types, phase transitions, thermal coupling
Gravity and Spatial TopologyParticle Mesh gravity, toroidal boundary conditions
Multi-Range Force SystemThree-tier force ranges: contact, local, global
Restorative OrbitsOrbital stability and perturbation damping

Spatial Systems

DocumentScope
Spatial Indexing DesignMulti-resolution spatial hashing, neighbor queries
Boundary DetectionSurface detection, composite boundary identification

Composite Bodies & Stellar Physics

DocumentScope
Composite Bodies DesignUnion-Find discovery, rigid body approximation
Emergent Composite SystemSelf-assembling structures from particle interactions
Merger and FissionBody merging, fragmentation, mass redistribution
Temperature DynamicsThermal conduction, radiation, phase transitions
Black Hole DesignFormation, accretion, Hawking radiation, event horizons
Ephemeral ParticlesShort-lived particles for effects (sparks, debris, radiation)

Particle Management

DocumentScope
Particle BudgetScale analysis, LOD strategies, memory constraints
Pool DesignStable-ID particle pools, free-list allocation

Scripting & Events

DocumentScope
DSL SpecificationScheme-inspired simulation scripting language
Event SystemLock-free event bus, zero-copy transport, channel routing

GPU & Performance

DocumentScope
GPU/CPU OptimizationCUDA kernels, SIMD backends, force calculation pipeline
Backend ArchitectureAbstract backend interface, multi-GPU, hybrid CPU/GPU

Networking & Distribution

DocumentScope
Network and ObservationMulti-client observation, LOD streaming, event relay
Distributed ComputationDomain decomposition, latency, consistency challenges

Architecture

DocumentScope
Target ArchitectureTarget directory layout and module decomposition
Integration ArchitectureHow all subsystems compose into a unified pipeline
Integrated Physics SpatialPhysics + spatial indexing co-design
Graphics ViewerReal-time visualization, LOD rendering, camera systems

Library Design

DocumentScope
Library Extraction AnalysisWhich components are library-quality (Boost.Spatial proposal)
Refactoring ComparisonAPI design trade-offs for generic spatial hashing

Vision

DocumentScope
Future VisionWhere Cosmos Engine is headed and why it matters
Scale RationaleWhy mesoscale, not molecular

Building the Reference PDF

The master design document is a LaTeX file. Build it with:

cd docs
pdflatex emergent_physics_design.tex
pdflatex emergent_physics_design.tex   # second pass for TOC/refs

A pre-built PDF is included at docs/emergent_physics_design.pdf.

The Unified Simulation Loop

Everything in Cosmos Engine runs through one pipeline per frame:

  1. Particles generate fields – mass distributions create gravity fields (PM grid), kinetic energy creates temperature fields, charge creates EM fields
  2. Fields affect particles – each particle samples all fields at its 3D position, accumulating forces from gradients
  3. Forces update particles – symplectic integration (velocity Verlet or higher-order) preserves long-term energy conservation
  4. Contact resolution – spatial hash detects overlapping particles, spring-damper model resolves penetration
  5. Structures evolve – spring networks stretch, compress, and break; new bonds form when particles come into sustained contact
  6. Properties emerge – temperature, pressure, angular momentum, material phase arise from collective particle behavior

This loop runs at 60+ FPS on 10M+ particles via GPU-accelerated Particle Mesh gravity and multi-resolution spatial hashing.

Discussion