added logging, and started simulator struct
This commit is contained in:
parent
16b71407d2
commit
e07bb7c4a1
@ -8,5 +8,7 @@ authors = ["thomas"]
|
||||
|
||||
[dependencies]
|
||||
clap = { version = "4.5.39", features = ["derive"] }
|
||||
env_logger = "0.11.8"
|
||||
log = "0.4.27"
|
||||
serde = { version = "1.0.219", features = ["derive"] }
|
||||
serde_json = "1.0.140"
|
||||
|
@ -3,13 +3,13 @@ use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Body {
|
||||
name: String,
|
||||
mass: types::Mass,
|
||||
position: types::Position,
|
||||
velocity: types::Velocity,
|
||||
pub name: String,
|
||||
pub mass: types::Mass,
|
||||
pub position: types::Position,
|
||||
pub velocity: types::Velocity,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
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::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(
|
||||
@ -37,10 +44,18 @@ fn read_config<P: AsRef<Path>>(path: P) -> Result<config::ConfigFile, Box<dyn Er
|
||||
//fn parse_time(arg: &str)
|
||||
|
||||
fn main() {
|
||||
env_logger::init();
|
||||
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();
|
||||
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