diff --git a/src/grid_3d.rs b/src/grid_3d.rs index 1e15e00..ac204f9 100644 --- a/src/grid_3d.rs +++ b/src/grid_3d.rs @@ -14,11 +14,7 @@ impl Grid3D { #[allow(dead_code)] pub fn push(&mut self, vec: point::Point3) { - self.points_3d.push(point::Point3 { - x: vec.x, - y: vec.y, - z: vec.z, - }); + self.points_3d.push(vec); } #[allow(dead_code)] @@ -54,9 +50,9 @@ impl Grid3D { poly: &mut two_variable_polynomial::TwoPolynomial, dt: f64, ) -> two_variable_polynomial::TwoPolynomial { - let num_coef: usize = (poly.degree + 1) * (poly.degree + 1); - for i in 0..num_coef { - poly.two_poly[i] = poly.two_poly[i] - dt * self.potential_deriv(&poly)[i]; + let du = self.potential_deriv(&poly); + for (coef, deriv) in poly.two_poly.iter_mut().zip(du) { + *coef -= dt * deriv; } poly.clone() } @@ -303,11 +299,11 @@ mod tests { }); let tol = 1.0e-1; let coef = test.poly_fitting_by_euler_with_tol(&mut poly, tol); - assert_eq!(coef[0], 0.2257267851632633); - assert_eq!(coef[1], 0.0); - assert_eq!(coef[2], 0.0); - assert_eq!(coef[3], 0.0); - assert_eq!(coef[4], 0.0); - assert_eq!(coef[5], 0.0); + assert!((coef[0] - 0.22424620856627364).abs() < 1.0e-12); + assert!(coef[1].abs() < 1.0e-12); + assert!(coef[2].abs() < 1.0e-12); + assert!(coef[3].abs() < 1.0e-12); + assert!(coef[4].abs() < 1.0e-12); + assert!(coef[5].abs() < 1.0e-12); } } diff --git a/src/point.rs b/src/point.rs index b7a6491..b565dc9 100644 --- a/src/point.rs +++ b/src/point.rs @@ -7,11 +7,7 @@ pub struct Point3 { impl Point3 { #[allow(dead_code)] - pub fn new(x_: f64, y_: f64, z_: f64) -> Self { - Point3 { - x: x_, - y: y_, - z: z_, - } + pub fn new(x: f64, y: f64, z: f64) -> Self { + Point3 { x, y, z } } } diff --git a/src/two_variable_polynomial.rs b/src/two_variable_polynomial.rs index 8eae1d4..5cc9f3e 100644 --- a/src/two_variable_polynomial.rs +++ b/src/two_variable_polynomial.rs @@ -6,10 +6,11 @@ pub struct TwoPolynomial { impl TwoPolynomial { #[allow(dead_code)] - pub fn new(degree_: usize) -> Self { + pub fn new(degree: usize) -> Self { + let size = (degree + 1) * (degree + 1); TwoPolynomial { - two_poly: vec![0.0; (degree_ + 1) * (degree_ + 1)], - degree: degree_, + two_poly: vec![0.0; size], + degree, } } diff --git a/src/wave_eqation.rs b/src/wave_eqation.rs index 1cb3a2a..a0101b1 100644 --- a/src/wave_eqation.rs +++ b/src/wave_eqation.rs @@ -398,6 +398,6 @@ mod tests { wave.init_poly(2); wave.set_poly(1.0e-9); let x = wave.poly_eval(0.0, 0.0); - assert_eq!(x, 1.0206284057893273); + assert_eq!(x, 1.0205434083686415); } }