Date: 2015-10-02T22:23:44+00:00

Actual source code: ksponly.c
petsc-3.6.2 2015-10-02
Report Typos and Errors

      2: #include <petsc/private/snesimpl.h>

      6: static PetscErrorCode SNESSolve_KSPONLY(SNES snes)
      7: {
      8:   PetscErrorCode     ierr;
      9:   PetscInt           lits;
     10:   Vec                Y,X,F;

     14:   if (snes->xl || snes->xu || snes->ops->computevariablebounds) {
     15:     SETERRQ1(PetscObjectComm((PetscObject)snes),PETSC_ERR_ARG_WRONGSTATE, "SNES solver %s does not support bounds", ((PetscObject)snes)->type_name);
     16:   }

     18:   snes->numFailures            = 0;
     19:   snes->numLinearSolveFailures = 0;
     20:   snes->reason                 = SNES_CONVERGED_ITERATING;
     21:   snes->iter                   = 0;
     22:   snes->norm                   = 0.0;

     24:   X = snes->vec_sol;
     25:   F = snes->vec_func;
     26:   Y = snes->vec_sol_update;

     28:   SNESComputeFunction(snes,X,F);
     29:   if (snes->numbermonitors) {
     30:     PetscReal fnorm;
     31:     VecNorm(F,NORM_2,&fnorm);
     32:     SNESMonitor(snes,0,fnorm);
     33:   }

     35:   /* Call general purpose update function */
     36:   if (snes->ops->update) {
     37:     (*snes->ops->update)(snes, 0);
     38:   }

     40:   /* Solve J Y = F, where J is Jacobian matrix */
     41:   SNESComputeJacobian(snes,X,snes->jacobian,snes->jacobian_pre);
     42:   KSPSetOperators(snes->ksp,snes->jacobian,snes->jacobian_pre);
     43:   KSPSolve(snes->ksp,F,Y);
     44:   snes->reason = SNES_CONVERGED_ITS;
     45:   SNESCheckKSPSolve(snes);

     47:   KSPGetIterationNumber(snes->ksp,&lits);
     48:   snes->linear_its += lits;
     49:   PetscInfo2(snes,"iter=%D, linear solve iterations=%D\n",snes->iter,lits);
     50:   snes->iter++;

     52:   /* Take the computed step. */
     53:   VecAXPY(X,-1.0,Y);
     54:   SNESComputeFunction(snes,X,F);
     55:   if (snes->numbermonitors) {
     56:     PetscReal fnorm;
     57:     VecNorm(F,NORM_2,&fnorm);
     58:     SNESMonitor(snes,1,fnorm);
     59:   }
     60:   return(0);
     61: }

     65: static PetscErrorCode SNESSetUp_KSPONLY(SNES snes)
     66: {

     70:   SNESSetUpMatrices(snes);
     71:   return(0);
     72: }

     76: static PetscErrorCode SNESDestroy_KSPONLY(SNES snes)
     77: {

     80:   return(0);
     81: }

     83: /* -------------------------------------------------------------------------- */
     84: /*MC
     85:       SNESKSPONLY - Nonlinear solver that only performs one Newton step and does not compute any norms.
     86:       The main purpose of this solver is to solve linear problems using the SNES interface, without
     87:       any additional overhead in the form of vector operations.

     89:    Level: beginner

     91: .seealso:  SNESCreate(), SNES, SNESSetType(), SNESNEWTONLS, SNESNEWTONTR
     92: M*/
     95: PETSC_EXTERN PetscErrorCode SNESCreate_KSPONLY(SNES snes)
     96: {

     99:   snes->ops->setup          = SNESSetUp_KSPONLY;
    100:   snes->ops->solve          = SNESSolve_KSPONLY;
    101:   snes->ops->destroy        = SNESDestroy_KSPONLY;
    102:   snes->ops->setfromoptions = 0;
    103:   snes->ops->view           = 0;
    104:   snes->ops->reset          = 0;

    106:   snes->usesksp = PETSC_TRUE;
    107:   snes->usespc  = PETSC_FALSE;

    109:   snes->data = 0;
    110:   return(0);
    111: }