How joeeliang/3-body-problem works
Project type and purpose
• This is a scientific simulation tool (three‐body gravitational problem) that combines Python for orchestration and C++ for high‐performance computation. It simulates trajectories, computes the Lyapunov (proximity) function, stores results, and generates visualizations.
File structure
• Top‐level scripts:
• main.py – entry point that triggers the overall workflow
• system.py – orchestrates data flow between modules
• visualization.py – produces plots or animations
• utils.py – helper functions for file I/O, parameter parsing, etc.
• logicCode/ (heavy computation):
• normalprocessing.cpp – core C++ routines for integration and proximity computation
• pythonVersion.py – pure‐Python fallback implementation or prototype
• long_double.cpp – extended‐precision C++ routines (possibly used by normalprocessing.cpp)
• data/ – static CSV inputs (initial positions, parameter scans) and outputs (cut_positions.csv, fullMap.csv, zoom.csv)
• app/ – packaging or execution scripts (could hold CLI wrappers or config templates)
• requirements.txt – Python dependencies
README for additional insights
• Confirms dual‐language approach (Python + C++) for speed and flexibility
• Periodic orbits and chaotic behavior via Lyapunov exponent
Components
a. Frontend/orchestration layer (Python scripts)
• main.py
• system.py
• utils.py
b. Compute engine
• C++ modules (normalprocessing.cpp + long_double.cpp)
• Python fallback (logicCode/pythonVersion.py)
c. Data layer
• Input CSVs in data/
• Output CSVs generated at runtime
d. Visualization layer
• visualization.py
e. External/Infrastructure
• Python interpreter + required libraries (from requirements.txt)
• C++ compiler toolchain
• File system (for reading/writing CSVs)
Relationships and data flow
• main.py loads configuration (from utils) → invokes system.py
• system.py reads input CSVs → passes parameters to the compute engine
• Compute engine (via a Python → C++ binding or subprocess) runs simulation and proximity calculations → writes results back to data/
• visualization.py reads computed CSVs → generates plots/animations → writes to disk or displays
• If C++ binaries are unavailable, system.py falls back to logicCode/pythonVersion.py
Architectural patterns and design principles
• Layered architecture: clear separation between orchestration, computation, data persistence, and visualization
• Polyglot strategy: high‐performance C++ core wrapped by a Python “glue” layer for ease of use
• Single responsibility: each module handles one concern (I/O, computation, plotting)
• Extensibility point: logicCode/pythonVersion.py can be extended for new algorithms; app/ can hold CLI or GUI frontends
• Enumerate all modules and their interfaces
• Python‐to‐C++ invocation mechanism (binding or subprocess)
• Data files directory as a persistent store
• External requirements (Python libs, compiler)