diff --git a/sbp/Cargo.toml b/sbp/Cargo.toml index 2e4533b..7b3738d 100644 --- a/sbp/Cargo.toml +++ b/sbp/Cargo.toml @@ -20,6 +20,7 @@ f32 = [] [dev-dependencies] criterion = "0.3.0" structopt = "0.3.12" +indicatif = "0.14.0" [[bench]] name = "maxwell" diff --git a/sbp/examples/multigrid.rs b/sbp/examples/multigrid.rs index f5c7ea2..0787a7c 100644 --- a/sbp/examples/multigrid.rs +++ b/sbp/examples/multigrid.rs @@ -158,6 +158,8 @@ impl System { #[derive(Debug, StructOpt)] struct Options { json: std::path::PathBuf, + #[structopt(long, help = "Disable the progressbar")] + no_progressbar: bool, } fn main() { @@ -189,6 +191,7 @@ fn main() { for grid in jgrids { grids.push(grid::Grid::new(grid.x, grid.y).unwrap()); } + let integration_time: f64 = json["integration_time"].as_number().unwrap().into(); let mut sys = System::new(grids, bt); sys.vortex( @@ -207,11 +210,24 @@ fn main() { let max_ny = sys.grids.iter().map(|g| g.ny()).max().unwrap(); std::cmp::max(max_nx, max_ny) }; - let t: f64 = json["integration_time"].as_number().unwrap().into(); let dt = 0.2 / (max_n as Float); - for _ in 0..(t / dt) as _ { + + let ntime = (integration_time / dt).round() as usize; + + let bar = if opt.no_progressbar { + indicatif::ProgressBar::hidden() + } else { + let bar = indicatif::ProgressBar::new(ntime as _); + bar.with_style( + indicatif::ProgressStyle::default_bar() + .template("{wide_bar:.cyan/blue} {pos}/{len} ({eta})"), + ) + }; + for _ in 0..ntime { + bar.inc(1); sys.advance(dt); } + bar.finish(); dump_to_file(&sys); } diff --git a/sbp/src/utils.rs b/sbp/src/utils.rs index d858dde..635ba9b 100644 --- a/sbp/src/utils.rs +++ b/sbp/src/utils.rs @@ -1,4 +1,5 @@ use crate::Float; +use json::JsonValue; #[derive(Debug, Clone)] pub struct SimpleGrid { @@ -27,8 +28,7 @@ pub struct SimpleGrid { /// Optional parameters: /// * name (for relating boundaries) /// * dir{e,w,n,s} (for boundary terms) -pub fn json_to_grids(json: json::JsonValue) -> Result, String> { - use json::JsonValue; +pub fn json_to_grids(json: JsonValue) -> Result, String> { fn json_to_grid(mut grid: JsonValue) -> Result { #[derive(Debug)] enum ArrayForm {