Skip to content

Commit

Permalink
fix for very small entries on diagonal causing issues in jacobi preco…
Browse files Browse the repository at this point in the history
…nditioner
  • Loading branch information
wgurecky committed Apr 11, 2024
1 parent 32feec0 commit 722b82a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/ex_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ fn main() {
let x0 = faer::Mat::zeros(216, 1);

// solve the system
let (res_x, err, iters) = gmres(a_test.as_ref(), rhs.as_ref(), x0.as_ref(), 500, 1e-8, None).unwrap();
let jacobi_pre = JacobiPreconLinOp::new(a_test.as_ref());
let (res_x, err, iters) = gmres(a_test.as_ref(), rhs.as_ref(), x0.as_ref(), 500, 1e-8, Some(&jacobi_pre)).unwrap();
println!("Result x: {:?}", res_x);
println!("Error x: {:?}", err);
println!("Iters : {:?}", iters);
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ impl <'a, T> LinOp<T> for JacobiPreconLinOp<'a, T>
T: faer::RealField + Float + faer::SimpleEntity
{
fn apply_linop_to_vec(&self, mut target: MatMut<T>) {
let eps = T::from(1e-20).unwrap();
let eps = T::from(1e-12).unwrap();
let one_c = T::from(1.0).unwrap();
let zero_c = T::from(0.0).unwrap();
for i in 0..target.nrows()
{
let v = target.read(i, 0);
target.write(i, 0,
v * (one_c / (*self.m.as_ref().get(i, i).unwrap_or(&zero_c) + eps) ));
v * (one_c / (*self.m.as_ref().get(i, i).unwrap_or(&one_c) + eps) ));
}
}
}
Expand Down Expand Up @@ -171,7 +171,7 @@ fn arnoldi<'a, T>(
let mut h = Vec::with_capacity(k + 2);
for i in 0..=k {
let qci: MatRef<T> = q[i].as_ref();
let ht = qv.transpose() * &qci;
let ht = qv.transpose() * qci;
h.push( ht.read(0, 0) );
qv = qv - (qci * faer::scale(h[i]));
}
Expand Down

0 comments on commit 722b82a

Please sign in to comment.