Commits

Peter Brune committed 9105210

Fix accidental creation of the matrices in SNESNCG used for linear analogue LS.

  • Participants
  • Parent commits 5154939

Comments (0)

Files changed (1)

File src/snes/impls/ncg/snesncg.c

   PetscFunctionReturn(0);
 }
 
-#define SNESLINESEARCHNCGLINEAR "linear"
+#define SNESLINESEARCHNCGLINEAR "ncglinear"
 
 /*
   SNESDestroy_NCG - Destroys the private SNES_NCG context that was created with SNESCreate_NCG().
 
   PetscFunctionBegin;
   ierr = SNESSetWorkVecs(snes,2);CHKERRQ(ierr);
-  ierr = SNESSetUpMatrices(snes);CHKERRQ(ierr);
-  ierr = SNESLineSearchRegister(SNESLINESEARCHNCGLINEAR, SNESLineSearchCreate_NCGLinear);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 /*
       ierr = SNESLineSearchSetType(linesearch, SNESLINESEARCHL2);CHKERRQ(ierr);
     }
   }
+  ierr = SNESLineSearchRegister(SNESLINESEARCHNCGLINEAR, SNESLineSearchCreate_NCGLinear);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }
 
   xnorm = &linesearch->xnorm;
   ynorm = &linesearch->ynorm;
 
+  if (!snes->jacobian) {
+    ierr = SNESSetUpMatrices(snes);CHKERRQ(ierr);
+  }
+
   /*
 
    The exact step size for unpreconditioned linear CG is just:
   ierr  = MatMult(snes->jacobian, Y, W);CHKERRQ(ierr);
   ierr  = VecDot(Y, W, &ptAp);CHKERRQ(ierr);
   alpha = alpha / ptAp;
-  ierr  = PetscPrintf(PetscObjectComm((PetscObject)snes), "alpha: %G\n", PetscRealPart(alpha));CHKERRQ(ierr);
-  ierr  = VecAXPY(X, alpha, Y);CHKERRQ(ierr);
-  ierr  = SNESComputeFunction(snes, X, F);CHKERRQ(ierr);
+  ierr  = VecAXPY(X,-alpha,Y);CHKERRQ(ierr);
+  ierr  = SNESComputeFunction(snes,X,F);CHKERRQ(ierr);
 
-  ierr = VecNorm(F, NORM_2, fnorm);CHKERRQ(ierr);
-  ierr = VecNorm(X, NORM_2, xnorm);CHKERRQ(ierr);
-  ierr = VecNorm(Y, NORM_2, ynorm);CHKERRQ(ierr);
+  ierr = VecNorm(F,NORM_2,fnorm);CHKERRQ(ierr);
+  ierr = VecNorm(X,NORM_2,xnorm);CHKERRQ(ierr);
+  ierr = VecNorm(Y,NORM_2,ynorm);CHKERRQ(ierr);
   PetscFunctionReturn(0);
 }