<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19019">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=2> char msg[125];<BR> SNES snes;<BR>
ApplicationCtx ctx;<BR> PetscErrorCode ierr;<BR>
PetscReal abstol,rtol,stol;<BR>
PetscInt its,maxit,maxf;<BR> PetscReal
none = -1.0;<BR> PetscScalar zero = 0;<BR> ctx.pDomain =
this;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>
pPhyDomain->Initialize(ASSEMBLY_FREE_MESH);<BR> PetscInt
N = pPhyDomain->GetEquCount();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Mat J;<BR> Vec u,r;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>
SNESCreate(PETSC_COMM_WORLD,&snes);<BR> </FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> VecCreate(PETSC_COMM_WORLD,&u); <BR>
VecSetSizes(u,N,N);<BR> VecSetFromOptions(u);<BR>
VecDuplicate(u,&r);<BR> VecDuplicate(u,&ctx.oldu);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>
SNESSetFunction(snes,r,FormFunction,&ctx);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> MatCreate(PETSC_COMM_WORLD,&J);<BR>
MatSetSizes(J,PETSC_DECIDE,PETSC_DECIDE,N,N);<BR>
MatSetFromOptions(J);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>
SNESSetJacobian(snes,J,J,FormJacobian,&ctx);<BR> <BR>
PetscObjectSetName((PetscObject)u,"Approximate Solution");<BR>
SNESSetFromOptions(snes);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> <BR> ierr =
SNESGetTolerances(snes,&abstol,&rtol,&stol,&maxit,&maxf);CHKERRQ(ierr);<BR>
ierr = PetscPrintf(PETSC_COMM_WORLD,"atol=%G, rtol=%G, stol=%G, maxit=%D,
maxf=%D\n",abstol,rtol,stol,maxit,maxf);CHKERRQ(ierr);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> </FONT></DIV>
<DIV><FONT size=2> //incremental lambda<BR> int step = 0;<BR>
ctx.dlambda = 1.0/ctx.pDomain->contrl.loadSteps;<BR> for(double lambda
= ctx.dlambda; lambda <= 1.0; lambda += ctx.dlambda){<BR>
<BR> ctx.lambda = lambda *
ctx.pDomain->contrl.loadScaler;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> //initialize previous
displacment<BR> VecSet(ctx.oldu,0.0);<BR>
<BR> ierr = FormInitialGuess(u);CHKERRQ(ierr);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> //solve<BR> ierr =
SNESSolve(snes,PETSC_NULL,u);CHKERRQ(ierr);<BR>
SNESGetIterationNumber(snes,&its);<BR> sprintf(msg,"STEP
%d (Newton iterations: %d)\n\n",step, its); Log::Send(Log::Info,
msg);<BR> ierr = PetscPrintf(PETSC_COMM_WORLD,"STEP %D (Newton
iterations: %D)\n\n",step, its);CHKERRQ(ierr);<BR>
<BR> //postprocess<BR> if(step %
ctx.pDomain->contrl.outputFrequency == 0){<BR>
pPhyDomain->WriteConfiguration(step);<BR>
pPhyDomain->WriteResultFiles(step);<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> //convergence test<BR>
SNESConvergedReason reason;<BR> SNESGetConvergedReason(snes,
&reason);<BR> if(reason <
0){//diverged<BR> Log::Send(Log::Info, "
calculation diverged");<BR> cout <<
"diverged reason: " << reason <<
endl;<BR> break;<BR>
}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> //advance<BR> step
++;<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> VecDestroy(r);<BR> MatDestroy(J);<BR>
VecDestroy(u);<BR> SNESDestroy(snes);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> PetscFunctionReturn(0);<BR>}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2> total number of function evaluations=4<BR> KSP
Object:<BR> type: gmres<BR>
GMRES: restart=30, using Classical (unmodified) Gram-Schmidt
Orthogonaliza<BR>tion with no iterative
refinement<BR> GMRES: happy breakdown tolerance
1e-030<BR> maximum iterations=10000, initial guess is
zero<BR> tolerances: relative=1e-005, absolute=1e-050,
divergence=10000<BR> left preconditioning<BR> PC
Object:<BR> type: ilu<BR> ILU: 0
levels of fill<BR> ILU: factor fill ratio
allocated 1<BR> ILU: tolerance for zero pivot
1e-012<BR>
out-of-place
factorization<BR>
matrix ordering: natural<BR> ILU: factor fill
ratio needed 1<BR>
Factored matrix
follows<BR> Matrix
Object:<BR>
type=seqaij, rows=24,
cols=24<BR>
total: nonzeros=392, allocated
nonzeros=840<BR>
using I-node routines: found 15 nodes, limit used is 5<BR>
linear system matrix = precond matrix:<BR> Matrix
Object:<BR> type=seqaij, rows=24,
cols=24<BR> total: nonzeros=392, allocated
nonzeros=3480<BR> using I-node
routines: found 15 nodes, limit used is 5<BR>STEP 3 (Newton iterations:
3)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>SNES Object:<BR> type: ls<BR> line
search variant: SNESLineSearchCubic<BR> alpha=0.0001,
maxstep=1e+008, steptol=1e-012<BR> maximum iterations=50, maximum function
evaluations=10000<BR> tolerances: relative=1e-008, absolute=1e-050,
solution=1e-008<BR> total number of linear solver iterations=3<BR>
total number of function evaluations=4<BR> KSP
Object:<BR> type: gmres<BR>
GMRES: restart=30, using Classical (unmodified) Gram-Schmidt
Orthogonaliza<BR>tion with no iterative
refinement<BR> GMRES: happy breakdown tolerance
1e-030<BR> maximum iterations=10000, initial guess is
zero</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>The output:</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>C:\cygwin\home\rabbit\pGFEM-test>pgfem -snes_view
-options_tableclear<BR>atol=1e-050, rtol=1e-008, stol=1e-008, maxit=50,
maxf=10000<BR>SNES Object:<BR> type: ls<BR> line search
variant: SNESLineSearchCubic<BR> alpha=0.0001, maxstep=1e+008,
steptol=1e-012<BR> maximum iterations=50, maximum function
evaluations=10000<BR> tolerances: relative=1e-008, absolute=1e-050,
solution=1e-008<BR> total number of linear solver iterations=3<BR>
total number of function evaluations=4<BR> KSP
Object:<BR> type: gmres<BR>
GMRES: restart=30, using Classical (unmodified) Gram-Schmidt
Orthogonaliza<BR>tion with no iterative
refinement<BR> GMRES: happy breakdown tolerance
1e-030<BR> maximum iterations=10000, initial guess is
zero<BR> tolerances: relative=1e-005, absolute=1e-050,
divergence=10000<BR> left preconditioning<BR> PC
Object:<BR> type: ilu<BR> ILU: 0
levels of fill<BR> ILU: factor fill ratio
allocated 1<BR> ILU: tolerance for zero pivot
1e-012<BR>
out-of-place
factorization<BR>
matrix ordering: natural<BR> ILU: factor fill
ratio needed 1<BR>
Factored matrix
follows<BR> Matrix
Object:<BR>
type=seqaij, rows=24,
cols=24<BR>
total: nonzeros=392, allocated
nonzeros=840<BR>
using I-node routines: found 15 nodes, limit used is 5<BR>
linear system matrix = precond matrix:<BR> Matrix
Object:<BR> type=seqaij, rows=24,
cols=24<BR> total: nonzeros=392, allocated
nonzeros=1320<BR> using I-node
routines: found 15 nodes, limit used is 5<BR>STEP 0 (Newton iterations:
3)</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>SNES Object:<BR> type: ls<BR> line
search variant: SNESLineSearchCubic<BR> alpha=0.0001,
maxstep=1e+008, steptol=1e-012<BR> maximum iterations=50, maximum function
evaluations=10000<BR> tolerances: relative=1e-008, absolute=1e-050,
solution=1e-008<BR> total number of linear solver iterations=3<BR>
total number of function evaluations=4<BR> KSP
Object:<BR> type: gmres<BR>
GMRES: restart=30, using Classical (unmodified) Gram-Schmidt
Orthogonaliza<BR>tion with no iterative
refinement<BR> GMRES: happy breakdown tolerance
1e-030<BR> maximum iterations=10000, initial guess is
zero<BR> tolerances: relative=1e-005, absolute=1e-050,
divergence=10000<BR> left preconditioning<BR> PC
Object:<BR> type: ilu<BR> ILU: 0
levels of fill<BR> ILU: factor fill ratio
allocated 1<BR> ILU: tolerance for zero pivot
1e-012<BR>
out-of-place
factorization<BR>
matrix ordering: natural<BR> ILU: factor fill
ratio needed 1<BR>
Factored matrix
follows<BR> Matrix
Object:<BR>
type=seqaij, rows=24,
cols=24<BR>
total: nonzeros=392, allocated
nonzeros=840<BR>
using I-node routines: found 15 nodes, limit used is 5<BR>
linear system matrix = precond matrix:<BR> Matrix
Object:<BR> type=seqaij, rows=24,
cols=24<BR> total: nonzeros=392, allocated
nonzeros=2040<BR> using I-node
routines: found 15 nodes, limit used is 5<BR>STEP 1 (Newton iterations:
3)</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2>^C<BR>C:\cygwin\home\rabbit\pGFEM-test></FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2></FONT> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #000000 2px solid; PADDING-LEFT: 5px; PADDING-RIGHT: 0px; MARGIN-LEFT: 5px; MARGIN-RIGHT: 0px"
dir=ltr>
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="FONT: 10pt arial; BACKGROUND: #e4e4e4; font-color: black"><B>From:</B>
<A title=jed@59A2.org href="mailto:jed@59A2.org">Jed Brown</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=petsc-users@mcs.anl.gov
href="mailto:petsc-users@mcs.anl.gov">PETSc users list</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Thursday, May 12, 2011 6:41
PM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> Re: [petsc-users] nonzero
prescribed boundary condition</DIV>
<DIV><BR></DIV>
<DIV class=gmail_quote>On Thu, May 12, 2011 at 06:35, Tian(ICT) <SPAN
dir=ltr><<A
href="mailto:rongtian@ncic.ac.cn">rongtian@ncic.ac.cn</A>></SPAN>
wrote:<BR>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV id=:2h5>Without any option, SNES converges never calling
FormJacobian,<BR>and the solution seems correct.<BR><BR>What is the reason
for that the SNES solver never calls FormJacobian (mf option was not
used)?</DIV></BLOCKQUOTE></DIV><BR>
<DIV>Please send the following:</DIV>
<DIV><BR></DIV>
<DIV>1. The code where you configure the solver, everything from SNESCreate to
SNESSolve</DIV>
<DIV><BR></DIV>
<DIV>2. The complete command line that you run with.</DIV>
<DIV><BR></DIV>
<DIV>3. Output when you add "-snes_view -options_table" to the command
line</DIV></BLOCKQUOTE></BODY></HTML>