[petsc-users] nonzero prescribed boundary condition

Tian(ICT) rongtian at ncic.ac.cn
Thu May 12 06:01:24 CDT 2011


  char msg[125];
  SNES snes;
  ApplicationCtx ctx;
  PetscErrorCode ierr;
  PetscReal      abstol,rtol,stol;
  PetscInt       its,maxit,maxf;
  PetscReal none = -1.0;
  PetscScalar zero = 0;
  ctx.pDomain = this;

  pPhyDomain->Initialize(ASSEMBLY_FREE_MESH);
  PetscInt  N    = pPhyDomain->GetEquCount();

  Mat J;
  Vec u,r;

  SNESCreate(PETSC_COMM_WORLD,&snes);
 

  VecCreate(PETSC_COMM_WORLD,&u); 
  VecSetSizes(u,N,N);
  VecSetFromOptions(u);
  VecDuplicate(u,&r);
  VecDuplicate(u,&ctx.oldu);

  SNESSetFunction(snes,r,FormFunction,&ctx);

  MatCreate(PETSC_COMM_WORLD,&J);
  MatSetSizes(J,PETSC_DECIDE,PETSC_DECIDE,N,N);
  MatSetFromOptions(J);

  SNESSetJacobian(snes,J,J,FormJacobian,&ctx);
  
  PetscObjectSetName((PetscObject)u,"Approximate Solution");
  SNESSetFromOptions(snes);

  
  ierr = SNESGetTolerances(snes,&abstol,&rtol,&stol,&maxit,&maxf);CHKERRQ(ierr);
  ierr = PetscPrintf(PETSC_COMM_WORLD,"atol=%G, rtol=%G, stol=%G, maxit=%D, maxf=%D\n",abstol,rtol,stol,maxit,maxf);CHKERRQ(ierr);

  
  //incremental lambda
  int step = 0;
  ctx.dlambda = 1.0/ctx.pDomain->contrl.loadSteps;
  for(double lambda = ctx.dlambda; lambda <= 1.0; lambda += ctx.dlambda){
    
    ctx.lambda = lambda * ctx.pDomain->contrl.loadScaler;

    //initialize previous displacment
    VecSet(ctx.oldu,0.0);
   
    ierr = FormInitialGuess(u);CHKERRQ(ierr);

    //solve
    ierr = SNESSolve(snes,PETSC_NULL,u);CHKERRQ(ierr);
    SNESGetIterationNumber(snes,&its);
    sprintf(msg,"STEP %d (Newton iterations: %d)\n\n",step, its); Log::Send(Log::Info, msg);
    ierr = PetscPrintf(PETSC_COMM_WORLD,"STEP %D (Newton iterations: %D)\n\n",step, its);CHKERRQ(ierr);
    
    //postprocess
    if(step % ctx.pDomain->contrl.outputFrequency == 0){
      pPhyDomain->WriteConfiguration(step);
      pPhyDomain->WriteResultFiles(step);
    }

    //convergence test
    SNESConvergedReason reason;
    SNESGetConvergedReason(snes, &reason);
    if(reason < 0){//diverged
      Log::Send(Log::Info, " calculation diverged");
      cout << "diverged reason: " << reason << endl;
      break;
    }

    //advance
    step ++;
  }

  VecDestroy(r);
  MatDestroy(J);
  VecDestroy(u);
  SNESDestroy(snes);

  PetscFunctionReturn(0);
}


  total number of function evaluations=4
  KSP Object:
    type: gmres
      GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonaliza
tion with no iterative refinement
      GMRES: happy breakdown tolerance 1e-030
    maximum iterations=10000, initial guess is zero
    tolerances:  relative=1e-005, absolute=1e-050, divergence=10000
    left preconditioning
  PC Object:
    type: ilu
      ILU: 0 levels of fill
      ILU: factor fill ratio allocated 1
      ILU: tolerance for zero pivot 1e-012
           out-of-place factorization
           matrix ordering: natural
      ILU: factor fill ratio needed 1
           Factored matrix follows
          Matrix Object:
            type=seqaij, rows=24, cols=24
            total: nonzeros=392, allocated nonzeros=840
              using I-node routines: found 15 nodes, limit used is 5
    linear system matrix = precond matrix:
    Matrix Object:
      type=seqaij, rows=24, cols=24
      total: nonzeros=392, allocated nonzeros=3480
        using I-node routines: found 15 nodes, limit used is 5
STEP 3 (Newton iterations: 3)

SNES Object:
  type: ls
    line search variant: SNESLineSearchCubic
    alpha=0.0001, maxstep=1e+008, steptol=1e-012
  maximum iterations=50, maximum function evaluations=10000
  tolerances: relative=1e-008, absolute=1e-050, solution=1e-008
  total number of linear solver iterations=3
  total number of function evaluations=4
  KSP Object:
    type: gmres
      GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonaliza
tion with no iterative refinement
      GMRES: happy breakdown tolerance 1e-030
    maximum iterations=10000, initial guess is zero


The output:

C:\cygwin\home\rabbit\pGFEM-test>pgfem -snes_view -options_tableclear
atol=1e-050, rtol=1e-008, stol=1e-008, maxit=50, maxf=10000
SNES Object:
  type: ls
    line search variant: SNESLineSearchCubic
    alpha=0.0001, maxstep=1e+008, steptol=1e-012
  maximum iterations=50, maximum function evaluations=10000
  tolerances: relative=1e-008, absolute=1e-050, solution=1e-008
  total number of linear solver iterations=3
  total number of function evaluations=4
  KSP Object:
    type: gmres
      GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonaliza
tion with no iterative refinement
      GMRES: happy breakdown tolerance 1e-030
    maximum iterations=10000, initial guess is zero
    tolerances:  relative=1e-005, absolute=1e-050, divergence=10000
    left preconditioning
  PC Object:
    type: ilu
      ILU: 0 levels of fill
      ILU: factor fill ratio allocated 1
      ILU: tolerance for zero pivot 1e-012
           out-of-place factorization
           matrix ordering: natural
      ILU: factor fill ratio needed 1
           Factored matrix follows
          Matrix Object:
            type=seqaij, rows=24, cols=24
            total: nonzeros=392, allocated nonzeros=840
              using I-node routines: found 15 nodes, limit used is 5
    linear system matrix = precond matrix:
    Matrix Object:
      type=seqaij, rows=24, cols=24
      total: nonzeros=392, allocated nonzeros=1320
        using I-node routines: found 15 nodes, limit used is 5
STEP 0 (Newton iterations: 3)

SNES Object:
  type: ls
    line search variant: SNESLineSearchCubic
    alpha=0.0001, maxstep=1e+008, steptol=1e-012
  maximum iterations=50, maximum function evaluations=10000
  tolerances: relative=1e-008, absolute=1e-050, solution=1e-008
  total number of linear solver iterations=3
  total number of function evaluations=4
  KSP Object:
    type: gmres
      GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonaliza
tion with no iterative refinement
      GMRES: happy breakdown tolerance 1e-030
    maximum iterations=10000, initial guess is zero
    tolerances:  relative=1e-005, absolute=1e-050, divergence=10000
    left preconditioning
  PC Object:
    type: ilu
      ILU: 0 levels of fill
      ILU: factor fill ratio allocated 1
      ILU: tolerance for zero pivot 1e-012
           out-of-place factorization
           matrix ordering: natural
      ILU: factor fill ratio needed 1
           Factored matrix follows
          Matrix Object:
            type=seqaij, rows=24, cols=24
            total: nonzeros=392, allocated nonzeros=840
              using I-node routines: found 15 nodes, limit used is 5
    linear system matrix = precond matrix:
    Matrix Object:
      type=seqaij, rows=24, cols=24
      total: nonzeros=392, allocated nonzeros=2040
        using I-node routines: found 15 nodes, limit used is 5
STEP 1 (Newton iterations: 3)

^C
C:\cygwin\home\rabbit\pGFEM-test>



  ----- Original Message ----- 
  From: Jed Brown 
  To: PETSc users list 
  Sent: Thursday, May 12, 2011 6:41 PM
  Subject: Re: [petsc-users] nonzero prescribed boundary condition


  On Thu, May 12, 2011 at 06:35, Tian(ICT) <rongtian at ncic.ac.cn> wrote:

    Without any option, SNES converges never calling FormJacobian,
    and the solution seems correct.

    What is the reason for that the SNES solver never calls FormJacobian (mf option was not used)?


  Please send the following:


  1. The code where you configure the solver, everything from SNESCreate to SNESSolve


  2. The complete command line that you run with.


  3. Output when you add "-snes_view -options_table" to the command line
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110512/d213e476/attachment-0001.htm>


More information about the petsc-users mailing list