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.
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.
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.
| Document | Scope |
|---|---|
| Emergent Physics Design | Master reference -- 90-page LaTeX document covering all physics systems |
| Integration Methods | Symplectic integrators, adaptive timestep, multi-rate schemes |
| Soft Contact Forces | Hertzian contact model, spring-damper collision response |
| Spring System Design | Dynamic spring networks, material properties, fatigue |
| Virtual Spring Design | Material-based spring generation, automatic bonding |
| Material Spring System | Material types, phase transitions, thermal coupling |
| Gravity and Spatial Topology | Particle Mesh gravity, toroidal boundary conditions |
| Multi-Range Force System | Three-tier force ranges: contact, local, global |
| Restorative Orbits | Orbital stability and perturbation damping |
| Document | Scope |
|---|---|
| Spatial Indexing Design | Multi-resolution spatial hashing, neighbor queries |
| Boundary Detection | Surface detection, composite boundary identification |
| Document | Scope |
|---|---|
| Composite Bodies Design | Union-Find discovery, rigid body approximation |
| Emergent Composite System | Self-assembling structures from particle interactions |
| Merger and Fission | Body merging, fragmentation, mass redistribution |
| Temperature Dynamics | Thermal conduction, radiation, phase transitions |
| Black Hole Design | Formation, accretion, Hawking radiation, event horizons |
| Ephemeral Particles | Short-lived particles for effects (sparks, debris, radiation) |
| Document | Scope |
|---|---|
| Particle Budget | Scale analysis, LOD strategies, memory constraints |
| Pool Design | Stable-ID particle pools, free-list allocation |
| Document | Scope |
|---|---|
| DSL Specification | Scheme-inspired simulation scripting language |
| Event System | Lock-free event bus, zero-copy transport, channel routing |
| Document | Scope |
|---|---|
| GPU/CPU Optimization | CUDA kernels, SIMD backends, force calculation pipeline |
| Backend Architecture | Abstract backend interface, multi-GPU, hybrid CPU/GPU |
| Document | Scope |
|---|---|
| Network and Observation | Multi-client observation, LOD streaming, event relay |
| Distributed Computation | Domain decomposition, latency, consistency challenges |
| Document | Scope |
|---|---|
| Target Architecture | Target directory layout and module decomposition |
| Integration Architecture | How all subsystems compose into a unified pipeline |
| Integrated Physics Spatial | Physics + spatial indexing co-design |
| Graphics Viewer | Real-time visualization, LOD rendering, camera systems |
| Document | Scope |
|---|---|
| Library Extraction Analysis | Which components are library-quality (Boost.Spatial proposal) |
| Refactoring Comparison | API design trade-offs for generic spatial hashing |
| Document | Scope |
|---|---|
| Future Vision | Where Cosmos Engine is headed and why it matters |
| Scale Rationale | Why mesoscale, not molecular |
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/refsA pre-built PDF is included at docs/emergent_physics_design.pdf.
Everything in Cosmos Engine runs through one pipeline per frame:
- Particles generate fields -- mass distributions create gravity fields (PM grid), kinetic energy creates temperature fields, charge creates EM fields
- Fields affect particles -- each particle samples all fields at its 3D position, accumulating forces from gradients
- Forces update particles -- symplectic integration (velocity Verlet or higher-order) preserves long-term energy conservation
- Contact resolution -- spatial hash detects overlapping particles, spring-damper model resolves penetration
- Structures evolve -- spring networks stretch, compress, and break; new bonds form when particles come into sustained contact
- 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.