set_petsc_operators bugs when solving with different operator size

Issue #140 wontfix
Chaffra Affouda created an issue

I found that when I run the same NewtonSolver to solve problems of different jacobian size, petsc gives an error but Epetra and uBLAS work fine. This is my hack to solve it:

//-----------------------------------------------------------------------------
void PETScLUSolver::set_operator(const boost::shared_ptr<const GenericLinearOperator> A)
{
  boost::shared_ptr<const PETScMatrix> B = as_type<const PETScMatrix>(require_matrix(A));
  set_operator(B);
}
//-----------------------------------------------------------------------------
void PETScLUSolver::set_operator(const boost::shared_ptr<const PETScMatrix> A)
{
  _A = A;
  dolfin_assert(_A);

  Mat Amat;
  KSPGetOperators(*_ksp,&Amat,PETSC_NULL,PETSC_NULL);
  PetscInt m;
  MatGetSize(Amat,&m,PETSC_NULL);
  if (m != _A->size(0)) {
      init_solver(_method);
  }
} 

Comments (1)

  1. Prof Garth Wells

    This isn't a robust fix in parallel.

    It's appropriate that NewtonSolver throws an error when the system size changes.

  2. Log in to comment