fix clippy lints

This commit is contained in:
Magnus Ulimoen 2020-04-12 20:44:52 +02:00
parent 90f72847fb
commit 3e7b45b3be
4 changed files with 45 additions and 42 deletions

View File

@ -64,6 +64,17 @@ impl<T: operators::UpwindOperator> System<T> {
}
fn advance(&mut self, dt: Float, pool: &rayon::ThreadPool) {
type MT<'a> = (
&'a mut [(
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
)],
&'a mut [euler::BoundaryStorage],
);
let rhs = move |fut: &mut [euler::Field],
prev: &[euler::Field],
time: Float,
@ -72,17 +83,7 @@ impl<T: operators::UpwindOperator> System<T> {
&[grid::Metrics<_>],
&[euler::BoundaryCharacteristics],
),
mt: &mut (
&mut [(
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
euler::Field,
)],
&mut [euler::BoundaryStorage],
)| {
mt: &mut MT| {
let (grids, metrics, bt) = c;
let (wb, eb) = mt;
@ -229,7 +230,7 @@ fn main() {
let output = File::create(&opt.output, sys.grids.as_slice()).unwrap();
let mut output = OutputThread::new(output);
let bar = progressbar(opt.no_progressbar, ntime);
let progressbar = progressbar(opt.no_progressbar, ntime);
let timer = if opt.timings {
Some(std::time::Instant::now())
@ -241,10 +242,10 @@ fn main() {
if should_output(itime) {
output.add_timestep(itime, &sys.fnow);
}
bar.inc(1);
progressbar.inc(1);
sys.advance(dt, &pool);
}
bar.finish_and_clear();
progressbar.finish_and_clear();
if let Some(timer) = timer {
let duration = timer.elapsed();
@ -268,8 +269,8 @@ fn progressbar(dummy: bool, ntime: u64) -> indicatif::ProgressBar {
if dummy {
indicatif::ProgressBar::hidden()
} else {
let bar = indicatif::ProgressBar::new(ntime);
bar.with_style(
let progressbar = indicatif::ProgressBar::new(ntime);
progressbar.with_style(
indicatif::ProgressStyle::default_bar()
.template("{wide_bar:.cyan/blue} {pos}/{len} ({eta})"),
)

View File

@ -236,7 +236,7 @@ impl Field {
&mut self,
x: ArrayView2<Float>,
y: ArrayView2<Float>,
t: Float,
time: Float,
vortex_param: VortexParameters,
) {
assert_eq!(x.shape(), y.shape());
@ -253,7 +253,7 @@ impl Field {
e.into_shape((n,)).unwrap(),
x.into_shape((n,)).unwrap(),
y.into_shape((n,)).unwrap(),
t,
time,
vortex_param,
)
}
@ -293,7 +293,7 @@ impl Field {
);
// Repeating to get the form
// [[hx0, hx1, ..., hxn], [hx0, hx1, ..., hxn], ..., [hx0, hx1, ..., hxn]]
let hxiterator = hxiterator.into_iter().cycle().take(self.nx() * self.ny());
let hxiterator = hxiterator.cycle().take(self.nx() * self.ny());
let hyiterator = itermaker(
self.ny(),
@ -305,14 +305,11 @@ impl Field {
);
// Repeating to get the form
// [[hy0, hy0, ..., hy0], [hy1, hy1, ..., hy1], ..., [hym, hym, ..., hym]]
let hyiterator = hyiterator
.into_iter()
.flat_map(|x| std::iter::repeat(x).take(self.nx()));
let hyiterator = hyiterator.flat_map(|x| std::iter::repeat(x).take(self.nx()));
let diagiterator = hxiterator.into_iter().zip(hyiterator).cycle();
let diagiterator = hxiterator.zip(hyiterator).cycle();
diagiterator
.into_iter()
.zip(self.0.iter())
.zip(other.0.iter())
.map(|(((hx, hy), r0), r1)| (*r0 - *r1).powi(2) * hx * hy)
@ -344,6 +341,7 @@ pub struct VortexParameters {
pub mach: Float,
}
#[allow(clippy::too_many_arguments)]
pub fn vortex(
rho: ArrayViewMut1<Float>,
rhou: ArrayViewMut1<Float>,
@ -351,7 +349,7 @@ pub fn vortex(
e: ArrayViewMut1<Float>,
x: ArrayView1<Float>,
y: ArrayView1<Float>,
t: Float,
time: Float,
vortex_param: VortexParameters,
) {
assert_eq!(rho.len(), rhou.len());
@ -374,7 +372,7 @@ pub fn vortex(
{
use crate::consts::PI;
let dx = (x - vortex_param.x0) - t;
let dx = (x - vortex_param.x0) - time;
let dy = y - vortex_param.y0;
let f = (1.0 - (dx*dx + dy*dy))/(rstar*rstar);
@ -791,8 +789,8 @@ impl BoundaryStorage {
fn vortexify(
mut field: ndarray::ArrayViewMut2<Float>,
yx: (ndarray::ArrayView1<Float>, ndarray::ArrayView1<Float>),
v: VortexParameters,
t: Float,
vparams: VortexParameters,
time: Float,
) {
let mut fiter = field.outer_iter_mut();
let (rho, rhou, rhov, e) = (
@ -802,7 +800,7 @@ fn vortexify(
fiter.next().unwrap(),
);
let (y, x) = yx;
vortex(rho, rhou, rhov, e, x, y, t, v);
vortex(rho, rhou, rhov, e, x, y, time, vparams);
}
#[allow(non_snake_case)]

View File

@ -36,7 +36,9 @@ impl ButcherTableau for MidpointMethod {
const C: &'static [Float] = &[1.0 / 2.0];
}
/// Bit exessive...
/// Bit excessive...
#[allow(clippy::excessive_precision)]
#[allow(clippy::unreadable_literal)]
const SQRT_5: Float = 2.236067977499789696409173668731276235440618359611525724270897245410520925637804899414414408378782275;
pub struct Rk6;
impl ButcherTableau for Rk6 {
@ -85,6 +87,7 @@ impl ButcherTableau for Rk6 {
];
}
#[allow(clippy::too_many_arguments)]
pub fn integrate<'a, BTableau, F: 'a, RHS, MT, C>(
rhs: RHS,
prev: &F,
@ -142,6 +145,7 @@ pub fn integrate<'a, BTableau, F: 'a, RHS, MT, C>(
}
#[cfg(feature = "rayon")]
#[allow(clippy::too_many_arguments)]
pub fn integrate_multigrid<'a, BTableau, F: 'a, RHS, MT, C>(
rhs: RHS,
prev: &[F],

View File

@ -40,7 +40,7 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
Array2(ndarray::Array2<Float>),
}
if grid.is_empty() {
return Err(format!("empty object"));
return Err("empty object".to_string());
}
let name = grid.remove("name").take_string();
let dire = grid.remove("dirE").take_string();
@ -76,7 +76,7 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
None => return Err(format!("")),
};
if iter.next().is_some() {
return Err(format!("linspace: contained more than expected"));
return Err("linspace: contained more than expected".to_string());
}
Ok(ArrayForm::Array1(if h2 {
h2linspace(start, end, steps)
@ -84,29 +84,29 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
ndarray::Array::linspace(start, end, steps)
}))
} else {
Err(format!("Could not parse gridline"))
Err("Could not parse gridline".to_string())
}
} else if x.is_array() {
let arrlen = x.len();
if arrlen == 0 {
return Err(format!("gridline does not have any members"));
return Err("gridline does not have any members".to_string());
}
if !x[0].is_array() {
let v = x
.members()
.map(|x: &JsonValue| -> Result<Float, String> {
Ok(x.as_number().ok_or_else(|| format!("Array contained something that could not be converted to an array"))?.into())
Ok(x.as_number().ok_or_else(|| "Array contained something that could not be converted to an array".to_string())?.into())
})
.collect::<Result<Vec<Float>, _>>()?;
Ok(ArrayForm::Array1(ndarray::Array::from(v)))
} else {
let arrlen2 = x[0].len();
if arrlen2 == 0 {
return Err(format!("gridline does not have any members"));
return Err("gridline does not have any members".to_string());
}
for member in x.members() {
if arrlen2 != member.len() {
return Err(format!("some arrays seems to have differing lengths"));
return Err("some arrays seems to have differing lengths".to_string());
}
}
let mut arr = ndarray::Array::zeros((arrlen, arrlen2));
@ -115,7 +115,7 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
*a = m
.as_number()
.ok_or_else(|| {
format!("array contained something which was not a number")
"array contained something which was not a number".to_string()
})?
.into()
}
@ -123,19 +123,19 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
Ok(ArrayForm::Array2(arr))
}
} else {
Err(format!("Inner object was not a string value, or an array"))
Err("Inner object was not a string value, or an array".to_string())
}
};
let x = grid.remove("x");
if x.is_empty() {
return Err(format!("x was empty"));
return Err("x was empty".to_string());
}
let x = to_array_form(x)?;
let y = grid.remove("y");
if y.is_empty() {
return Err(format!("y was empty"));
return Err("y was empty".to_string());
}
let y = to_array_form(y)?;
@ -193,7 +193,7 @@ pub fn json_to_grids(json: JsonValue) -> Result<Vec<ExtendedGrid>, String> {
match json {
JsonValue::Array(a) => a
.into_iter()
.map(|g| json_to_grid(g))
.map(json_to_grid)
.collect::<Result<Vec<_>, _>>(),
grid => Ok(vec![json_to_grid(grid)?]),
}