json parse vortex parameters

This commit is contained in:
Magnus Ulimoen 2020-04-02 22:49:27 +02:00
parent 18ebbfde75
commit a31ca3ff3e
3 changed files with 34 additions and 11 deletions

View File

@ -193,17 +193,10 @@ fn main() {
}
let integration_time: f64 = json["integration_time"].as_number().unwrap().into();
let vortexparams = utils::json_to_vortex(json["vortex"].clone());
let mut sys = System::new(grids, bt);
sys.vortex(
0.0,
euler::VortexParameters {
x0: 0.0,
y0: 0.0,
mach: 0.5,
rstar: 0.5,
eps: 1.0,
},
);
sys.vortex(0.0, vortexparams);
let max_n = {
let max_nx = sys.grids.iter().map(|g| g.nx()).max().unwrap();

View File

@ -37,5 +37,12 @@
"dirW": "grid0"
}
],
"integration_time": 2.0
"integration_time": 2.0,
"vortex": {
"x0": 0.0,
"y0": 0.0,
"mach": 0.5,
"rstar": 0.5,
"eps": 1.0
}
}

View File

@ -246,3 +246,26 @@ fn parse_err() {
json_to_grids(r#"{"x": "linspace:1.2:3.1:412.2", "y": [0.1, 0.2]}"#).unwrap_err();
json_to_grids(r#"{"x": [-2, -3, "dfd"], "y": [0.1, 0.2]}"#).unwrap_err();
}
pub fn json_to_vortex(mut json: JsonValue) -> super::euler::VortexParameters {
let x0 = json.remove("x0").as_number().unwrap().into();
let y0 = json.remove("y0").as_number().unwrap().into();
let mach = json.remove("mach").as_number().unwrap().into();
let rstar = json.remove("rstar").as_number().unwrap().into();
let eps = json.remove("eps").as_number().unwrap().into();
if !json.is_empty() {
eprintln!("Found unused items when parsing vortex");
for (name, val) in json.entries() {
eprintln!("\t{} {}", name, val.dump());
}
}
super::euler::VortexParameters {
x0,
y0,
mach,
rstar,
eps,
}
}