Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/grid_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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);
}
}
8 changes: 2 additions & 6 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
}
7 changes: 4 additions & 3 deletions src/two_variable_polynomial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wave_eqation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Loading