62 lines
1.4 KiB
Rust
62 lines
1.4 KiB
Rust
// Standard library
|
|
use std::error::Error;
|
|
use std::fs::File;
|
|
use std::io::BufReader;
|
|
use std::path::Path;
|
|
|
|
// External crates
|
|
use clap::Parser;
|
|
use log::{info, warn, error, debug, trace};
|
|
|
|
// Internal modules
|
|
mod types;
|
|
mod config;
|
|
mod simulator;
|
|
|
|
// Specific uses from modules
|
|
use crate::simulator::Simulator;
|
|
|
|
#[derive(Parser, Debug)]
|
|
#[command(
|
|
version,
|
|
about="Orbital mechanics simulator",
|
|
long_about = "Given initial conditions you provide to --config, \
|
|
this program will numerically integrate and determinate their \
|
|
paths based off Newton's law of gravity.")]
|
|
struct Args {
|
|
///Config file for initial conditions
|
|
#[arg(short, long)]
|
|
config: String,
|
|
|
|
///Step size for simulation (seconds)
|
|
#[arg(short, long, default_value_t = 10)]
|
|
step_size: u8,
|
|
}
|
|
|
|
fn read_config<P: AsRef<Path>>(path: P) -> Result<config::ConfigFile, Box<dyn Error>> {
|
|
let file = File::open(path)?;
|
|
let reader = BufReader::new(file);
|
|
|
|
let u = serde_json::from_reader(reader)?;
|
|
|
|
Ok(u)
|
|
}
|
|
//fn parse_time(arg: &str)
|
|
|
|
fn main() {
|
|
env_logger::init();
|
|
let args = Args::parse();
|
|
|
|
info!("Loading initial parameters from {}", args.config);
|
|
|
|
let conf = read_config(args.config).unwrap();
|
|
for body in &conf.bodies {
|
|
info!("Loaded {} with mass {:.3e} kg", body.name, body.mass);
|
|
debug!("R_i = {:?}, V_i = {:?}", body.position, body.velocity);
|
|
}
|
|
|
|
|
|
let mut sim = Simulator::new(conf.bodies, 0.5);
|
|
sim.run(2);
|
|
}
|