From 82c69b7ae15be9136a59e084cbe0a975c61fa3c6 Mon Sep 17 00:00:00 2001 From: Thomas Faour Date: Thu, 19 Jun 2025 23:56:14 -0400 Subject: [PATCH] Added a readme --- README.md | 117 +++++++++++++++++++++++++++++++++++++++++++++++ src/simulator.rs | 4 +- 2 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c1b36ec --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# Orbital Simulator + +A fast N-body orbital mechanics simulator written in Rust. +Simulate the motion of celestial bodies under Newtonian gravity, with easy configuration and efficient output for visualization. + +--- + +## Features + +- **N-body simulation** +- **Configurable initial conditions** via JSON +- **Binary trajectory files** +- **Progress bar** +- **Unit normalization** +- **Ready for visualization** (Coming Soon) + +--- + +## Getting Started + +### Prerequisites + +- [Rust](https://www.rust-lang.org/tools/install) (edition 2021 or later) +- Python (optional, for animation/visualization) + +### Build + +```bash +cargo build --release +``` + +### Run + +```bash +cargo run --release -- \ + --config path/to/your_config.json \ + --time 30d \ + --step-size 10.0 \ + --output-file trajectory.bin +``` + +**Arguments:** + +- `--config` (required): Path to your JSON config file with initial body states. +- `--time` (required): Total simulation time (e.g. `10s`, `5m`, `2h`, `100d`). +- `--step-size`: Simulation step size in seconds (default: `10.0`). +- `--output-file` (required): Where to save the trajectory data. +- `--steps-per-save`: How often to update the progress bar and save (default: `1000`). + +--- + +## Configuration + +The config file is a JSON file describing the initial state of each body. +Examples provided in config/ + +```json +{ + "bodies": [ + { + "name": "BodyName", + "mass": 1e10, //kg + "position": [0.0, 0.0, 0.0], //meters + "velocity": [0.0, 0.0, 0.0] // m/s + }, + ... + ] +} +``` + +- **Units:** + - Mass: kilograms (kg) + - Position: meters (m) + - Velocity: meters per second (m/s) + +--- + +## Output + +- The simulator writes binary snapshots of the system state to the output file using [bincode](https://docs.rs/bincode/). +- Each snapshot contains the simulation time and the real (de-normalized) positions, velocities, and masses of all bodies. + +--- + +## Animation + +Coming soon. + +--- + +## Extending + +- Add more bodies or change initial conditions in the config file. +- Adjust step size and simulation time for accuracy/performance trade-offs. +- The code is modular and ready for extension (e.g., new force laws, output formats, or integrators). + +--- + +## License + +MIT License + +--- + +## Acknowledgments + +- [Rust](https://www.rust-lang.org/) +- [glam](https://crates.io/crates/glam) for fast vector math +- [clap](https://crates.io/crates/clap) for CLI parsing +- [indicatif](https://crates.io/crates/indicatif) for progress bars +- [serde](https://crates.io/crates/serde) and [bincode](https://crates.io/crates/bincode) for serialization + +--- + +## Author + +- Thomas Faour \ No newline at end of file diff --git a/src/simulator.rs b/src/simulator.rs index a3f6fb5..beb05f7 100644 --- a/src/simulator.rs +++ b/src/simulator.rs @@ -49,7 +49,7 @@ impl Simulation { for i in 0..steps { debug!("Step: {}", i); self.reset_accelerations(); - self.caclulate_accelerations(); + self.calculate_accelerations(); self.step_bodies(); if i % self.steps_per_save == 0 { //save the state @@ -68,7 +68,7 @@ impl Simulation { } } - fn caclulate_accelerations(&mut self) { + fn calculate_accelerations(&mut self) { let r_hat_over_r3 = self.get_rhat_over_r_three(); let n = self.bodies.len(); for i in 0..(n-1) {