rust_rewrite #11
@ -8,5 +8,7 @@ authors = ["thomas"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.39", features = ["derive"] }
|
clap = { version = "4.5.39", features = ["derive"] }
|
||||||
|
env_logger = "0.11.8"
|
||||||
|
log = "0.4.27"
|
||||||
serde = { version = "1.0.219", features = ["derive"] }
|
serde = { version = "1.0.219", features = ["derive"] }
|
||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
|
@ -3,13 +3,13 @@ use serde::Deserialize;
|
|||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct Body {
|
pub struct Body {
|
||||||
name: String,
|
pub name: String,
|
||||||
mass: types::Mass,
|
pub mass: types::Mass,
|
||||||
position: types::Position,
|
pub position: types::Position,
|
||||||
velocity: types::Velocity,
|
pub velocity: types::Velocity,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct ConfigFile {
|
pub struct ConfigFile {
|
||||||
bodies: Vec<Body>,
|
pub bodies: Vec<Body>,
|
||||||
}
|
}
|
23
src/main.rs
23
src/main.rs
@ -1,13 +1,20 @@
|
|||||||
use clap::Parser;
|
// Standard library
|
||||||
|
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
// External crates
|
||||||
|
use clap::Parser;
|
||||||
|
use log::{info, warn, error, debug, trace};
|
||||||
|
|
||||||
|
// Internal modules
|
||||||
mod types;
|
mod types;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod simulator;
|
||||||
|
|
||||||
|
// Specific uses from modules
|
||||||
|
use crate::simulator::Simulator;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(
|
#[command(
|
||||||
@ -37,10 +44,18 @@ fn read_config<P: AsRef<Path>>(path: P) -> Result<config::ConfigFile, Box<dyn Er
|
|||||||
//fn parse_time(arg: &str)
|
//fn parse_time(arg: &str)
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
println!("Loading initial parameters from {}", args.config);
|
info!("Loading initial parameters from {}", args.config);
|
||||||
|
|
||||||
let conf = read_config(args.config).unwrap();
|
let conf = read_config(args.config).unwrap();
|
||||||
println!("{:#?}", conf);
|
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);
|
||||||
}
|
}
|
||||||
|
23
src/simulator.rs
Normal file
23
src/simulator.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
use log::{info, warn, error, debug, trace};
|
||||||
|
|
||||||
|
use crate::config::Body;
|
||||||
|
|
||||||
|
pub struct Simulator {
|
||||||
|
bodies: Vec<Body>,
|
||||||
|
step_size: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Simulator {
|
||||||
|
pub fn new(bodies: Vec<Body>, step_size: f32) -> Self{
|
||||||
|
Self {bodies, step_size}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&mut self, steps: usize){
|
||||||
|
for i in 0..steps {
|
||||||
|
debug!("Step: {}", i);
|
||||||
|
// for b in &self.bodies {
|
||||||
|
// println!("Body: {}", b.name);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user