[petsc-users] Residual calculation in Richardson

John Fettig john.fettig at gmail.com
Tue Jun 5 14:02:02 CDT 2012


When using the defaults for Richardson, it calculates the
(unpreconditioned) residual directly on line 138.  However, this isn't
made available to the convergence monitor because
ksp->ops->buildresidual          = KSPDefaultBuildResidual;

So if you build the residual explicitly in the convergence monitor it
must calculate it again.  Could we do this instead?

#undef __FUNCT__
#define __FUNCT__ "KSPBuildResidual_Richardson"
PetscErrorCode  KSPBuildResidual_Richardson(KSP ksp, Vec t, Vec v, Vec *V)
{
  PetscErrorCode ierr;
  KSP_Richardson *ctx;

  PetscFunctionBegin;
  ctx = (KSP_Richardson *)ksp->data;
  if (ctx->selfscale) {
    KSPDefaultBuildResidual(ksp,t,v,V);
  }  else {
    if (v) {
      ierr = VecCopy( ksp->work[0], v );CHKERRQ(ierr);
      if (V) *V = v;
    } else if (V) {
      *V = ksp->work[0];
    }
  }
  PetscFunctionReturn(0);
}

John


More information about the petsc-users mailing list