Hi there,<br><br>I am having problems with the SNES, it seems that changing atol or rtol have no effect on the numbers of Newton Iterations. Do you think that it can be a problem of settings in snes solver or maybe a problem on the routines for Jacobian matrix evaluation? The linear solver do converge at each nonlinear iterations. <br>
<br><b>My Code</b><br><br> ierr = SNESCreate(PETSC_COMM_WORLD,&snes);CHKERRQ(ierr);<br><br> /********************************************************/<br> /* Creation of the matrix and vector data structures*/<br>
/********************************************************/<br> ierr = VecCreate(PETSC_COMM_WORLD,&x); CHKERRQ(ierr);<br> ierr = VecSetSizes(x,PETSC_DECIDE,2*input.grid.N); CHKERRQ(ierr);<br> ierr = VecSetFromOptions(x); CHKERRQ(ierr);<br>
ierr = VecDuplicate(x,&R);CHKERRQ(ierr);<br> <br> ierr = MatCreate(PETSC_COMM_WORLD,&J);CHKERRQ(ierr);<br> ierr = MatSetSizes(J,PETSC_DECIDE,PETSC_DECIDE,2*input.grid.N,2*input.grid.N);CHKERRQ(ierr);<br> ierr = MatSetFromOptions(J);CHKERRQ(ierr);<br>
<br><br> ///Set function evaluation routine and vector<br><br> // Assign global variable which is used in the static wrapper function<br> pt2Object = (void*) &system;<br> pt2Object2 = (void*) &system;<br> ierr = SNESSetFunction(snes,R,CSystem::Wrapper_to_FormFunction,&input);CHKERRQ(ierr);<br>
<br> // Set Jacobian matrix structure and Jacobian evaluation routine<br> ierr = SNESSetJacobian(snes,J,J,CSystem::Wrapper_to_FormJacobian,&input);CHKERRQ(ierr);<br><br> /** Customizr non linear solver; set runtime options ***/<br>
/* Set linear solver defaults for this problem. By extracting the KSP,and PC contexts from <br>the SNES context, we can then directly call any KSP and PC routines to set various options*/<br><br> ierr = SNESGetKSP(snes,&ksp);CHKERRQ(ierr);<br>
ierr = KSPGetPC(ksp,&pc);CHKERRQ(ierr);<br> ierr = PCSetType(pc,PCILU);CHKERRQ(ierr);<br> ierr = KSPSetTolerances(ksp,1.e-10,PETSC_DEFAULT,PETSC_DEFAULT,30);CHKERRQ(ierr);<br> ierr = KSPSetFromOptions(ksp);CHKERRQ(ierr);<br>
<br><br><br> /*<br> Set SNES/KSP/PC rountime options, e.g.,<br> -snes_view -snes_monitor -ksp_type <ksp> -pc_type <pc><br> These options will override thos specified above as lon as SNESSetFromOptoons is called _after_ any other customization routines.<br>
*/<br><br> ierr =SNESSetTolerances(snes,1e-100,1e-8,1e-1000,100,1000);CHKERRQ(ierr); <font size="4"><b><span style="color: rgb(255, 0, 0);"> No matter what I put here I am getting the same results (Residual Norm and number of iterations)</span></b></font><br>
ierr = SNESSetFromOptions(snes);CHKERRQ(ierr);<br><br> /*---------------------------------------------------------------<br> Evaluate initial guess; then solve nonlinear system<br> -----------------------------------------------------------------*/<br>
<br> <br> <span style="color: rgb(192, 192, 192);"> ierr = CSystem::Cells2Vec(x,input);CHKERRQ(ierr);</span><br><br><br><span style="color: rgb(192, 192, 192);"> for (int i=0;i<system.delta_t_V.size();i++){// for (int i=0;i<700;i++)</span><br style="color: rgb(192, 192, 192);">
<span style="color: rgb(192, 192, 192);"> system.delta_t = system.delta_t_V[i];</span><br style="color: rgb(192, 192, 192);"><span style="color: rgb(192, 192, 192);"> system.t = system.t_V[i];</span><br style="color: rgb(192, 192, 192);">
<span style="color: rgb(192, 192, 192);"> input.t = system.t;</span><br style="color: rgb(192, 192, 192);"><span style="color: rgb(192, 192, 192);"> input.delta_t = system.delta_t;</span><br style="color: rgb(192, 192, 192);">
<span style="color: rgb(192, 192, 192);"> /*\\\\\\\\\\\\\\Boundary conditions\\\\\\\\\\\\\\\\*/</span><br style="color: rgb(192, 192, 192);"><span style="color: rgb(192, 192, 192);"> Rate_tot = input.F_boundary(input.t,input.delta_t); </span><br style="color: rgb(192, 192, 192);">
<span style="color: rgb(192, 192, 192);"> input.bc.F(input.interfaces,Rate_tot);</span><br> <br> ierr = SNESSolve(snes,PETSC_NULL,x);CHKERRQ(ierr);<br> <span style="color: rgb(192, 192, 192);"> gauge.push_back(input.cells[0].water.p);</span><br>
}<br> <br><br> <br><br><br><br><br> ierr = VecDestroy(x);CHKERRQ(ierr);<br> ierr = VecDestroy(R);CHKERRQ(ierr);<br> ierr = MatDestroy(J);CHKERRQ(ierr);<br> ierr = SNESDestroy(snes);CHKERRQ(ierr);<br> ierr = PetscFinalize();CHKERRQ(ierr);<br>
return 0;<br>}<br><br><br><font size="4"><b>Output:</b></font><br>SNES Object:<br> type: ls<br> line search variant: SNESLineSearchCubic<br> alpha=0.0001, maxstep=1e+008, minlambda=1e-012<br> maximum iterations=20, maximum function evaluations=1000<br>
tolerances: relative=1e-008, absolute=1e-100, solution=0<br> total number of linear solver iterations=2<br> total number of function evaluations=13<br> KSP Object:<br> type: gmres<br> GMRES: restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement<br>
GMRES: happy breakdown tolerance 1e-030<br> maximum iterations=30, initial guess is zero<br> tolerances: relative=1e-010, 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> ILU: using diagonal shift to prevent zero pivot<br> ILU: using diagonal shift on blocks to prevent zero pivot<br>
out-of-place factorization<br> matrix ordering: natural<br> ILU: factor fill ratio needed 0<br> Factored matrix follows<br> Matrix Object:<br> type=seqbaij, rows=64, cols=64<br>
package used to perform factorization: petsc<br> total: nonzeros=376, allocated nonzeros=920<br> block size is 1<br> linear system matrix = precond matrix:<br> Matrix Object:<br>
type=seqbaij, rows=64, cols=64<br> total: nonzeros=376, allocated nonzeros=920<br> block size is 1<br>************************************************************************************************************************<br>
*** WIDEN YOUR WINDOW TO 120 CHARACTERS. Use 'enscript -r -fCourier9' to print this document ***<br>************************************************************************************************************************<br>
<br>---------------------------------------------- PETSc Performance Summary: ----------------------------------------------<br><br>ex2.exe on a cygwin-c- named IDROCP03 with 1 processor, by Administrator Wed Jul 22 13:25:47 2009<br>
Using Petsc Release Version 3.0.0, Patch 6, Fri Jun 5 13:31:12 CDT 2009<br><br> Max Max/Min Avg Total <br>Time (sec): 4.667e-001 1.00000 4.667e-001<br>Objects: 2.800e+001 1.00000 2.800e+001<br>
Flops: 1.417e+004 1.00000 1.417e+004 1.417e+004<br>Flops/sec: 3.037e+004 1.00000 3.037e+004 3.037e+004<br>Memory: 9.325e+004 1.00000 9.325e+004<br>
MPI Messages: 0.000e+000 0.00000 0.000e+000 0.000e+000<br>MPI Message Lengths: 0.000e+000 0.00000 0.000e+000 0.000e+000<br>MPI Reductions: 0.000e+000 0.00000<br><br>Flop counting convention: 1 flop = 1 real number operation of type (multiply/divide/add/subtract)<br>
e.g., VecAXPY() for real vectors of length N --> 2N flops<br> and VecAXPY() for complex vectors of length N --> 8N flops<br><br>Summary of Stages: ----- Time ------ ----- Flops ----- --- Messages --- -- Message Lengths -- -- Reductions --<br>
Avg %Total Avg %Total counts %Total Avg %Total counts %Total <br> 0: Main Stage: 4.6669e-001 100.0% 1.4174e+004 100.0% 0.000e+000 0.0% 0.000e+000 0.0% 0.000e+000 0.0% <br>
<br>------------------------------------------------------------------------------------------------------------------------<br>See the 'Profiling' chapter of the users' manual for details on interpreting output.<br>
Phase summary info:<br> Count: number of times phase was executed<br> Time and Flops: Max - maximum over all processors<br> Ratio - ratio of maximum to minimum over all processors<br> Mess: number of messages sent<br>
Avg. len: average message length<br> Reduct: number of global reductions<br> Global: entire computation<br> Stage: stages of a computation. Set stages with PetscLogStagePush() and PetscLogStagePop().<br> %T - percent time in this phase %F - percent flops in this phase<br>
%M - percent messages in this phase %L - percent message lengths in this phase<br> %R - percent reductions in this phase<br> Total Mflop/s: 10e-6 * (sum of flops over all processors)/(max time over all processors)<br>
------------------------------------------------------------------------------------------------------------------------<br><br><br> ##########################################################<br> # #<br>
# WARNING!!! #<br> # #<br> # This code was compiled with a debugging option, #<br> # To get timing results run config/configure.py #<br>
# using --with-debugging=no, the performance will #<br> # be generally two or three times faster. #<br> # #<br> ##########################################################<br>
<br><br>Event Count Time (sec) Flops --- Global --- --- Stage --- Total<br> Max Ratio Max Ratio Max Ratio Mess Avg len Reduct %T %F %M %L %R %T %F %M %L %R Mflop/s<br>
------------------------------------------------------------------------------------------------------------------------<br><br>--- Event Stage 0: Main Stage<br><br>SNESSolve 1 1.0 2.7082e-001 1.0 1.42e+004 1.0 0.0e+000 0.0e+000 0.0e+000 58100 0 0 0 58100 0 0 0 0<br>
SNESLineSearch 2 1.0 2.9807e-002 1.0 4.94e+003 1.0 0.0e+000 0.0e+000 0.0e+000 6 35 0 0 0 6 35 0 0 0 0<br>SNESFunctionEval 13 1.0 3.2095e-002 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 7 0 0 0 0 7 0 0 0 0 0<br>
SNESJacobianEval 2 1.0 2.5123e-003 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 1 0 0 0 0 1 0 0 0 0 0<br>VecView 2 1.0 2.3364e-001 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 50 0 0 0 0 50 0 0 0 0 0<br>
VecDot 2 1.0 1.2292e-005 1.0 2.54e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 2 0 0 0 0 2 0 0 0 21<br>VecMDot 2 1.0 1.0337e-005 1.0 2.54e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 2 0 0 0 0 2 0 0 0 25<br>
VecNorm 20 1.0 1.1873e-004 1.0 2.54e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 18 0 0 0 0 18 0 0 0 21<br>VecScale 4 1.0 1.7321e-005 1.0 2.56e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 2 0 0 0 0 2 0 0 0 15<br>
VecCopy 6 1.0 2.6819e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>VecSet 5 1.0 1.9835e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
VecAXPY 2 1.0 1.0337e-005 1.0 2.56e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 2 0 0 0 0 2 0 0 0 25<br>VecWAXPY 12 1.0 5.2521e-005 1.0 1.41e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 10 0 0 0 0 10 0 0 0 27<br>
VecMAXPY 4 1.0 1.7321e-005 1.0 5.12e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 4 0 0 0 0 4 0 0 0 30<br>VecAssemblyBegin 13 1.0 3.4641e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
VecAssemblyEnd 13 1.0 3.1848e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>VecReduceArith 2 1.0 1.7321e-005 1.0 2.54e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 2 0 0 0 0 2 0 0 0 15<br>
VecReduceComm 1 1.0 3.0730e-006 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>VecNormalize 4 1.0 8.4368e-005 1.0 7.64e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 5 0 0 0 0 5 0 0 0 9<br>
MatMult 4 1.0 4.4978e-005 1.0 2.75e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 19 0 0 0 0 19 0 0 0 61<br>MatMultTranspose 1 1.0 2.3467e-005 1.0 7.52e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 5 0 0 0 0 5 0 0 0 32<br>
MatSolve 4 1.0 5.6711e-005 1.0 2.75e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 19 0 0 0 0 19 0 0 0 49<br>MatLUFactorNum 2 1.0 7.7943e-005 1.0 2.06e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 15 0 0 0 0 15 0 0 0 26<br>
MatILUFactorSym 2 1.0 1.9975e-004 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>MatAssemblyBegin 2 1.0 6.7048e-006 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
MatAssemblyEnd 2 1.0 4.1346e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>MatGetRowIJ 2 1.0 1.0895e-005 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
MatGetOrdering 2 1.0 2.0254e-004 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>MatView 2 1.0 5.7549e-004 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
KSPGMRESOrthog 2 1.0 5.6152e-005 1.0 5.10e+002 1.0 0.0e+000 0.0e+000 0.0e+000 0 4 0 0 0 0 4 0 0 0 9<br>KSPSetup 2 1.0 1.5170e-004 1.0 0.00e+000 0.0 0.0e+000 0.0e+000 0.0e+000 0 0 0 0 0 0 0 0 0 0 0<br>
KSPSolve 2 1.0 1.8486e-003 1.0 7.97e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 56 0 0 0 0 56 0 0 0 4<br>PCSetUp 2 1.0 1.2032e-003 1.0 2.06e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 15 0 0 0 0 15 0 0 0 2<br>
PCApply 4 1.0 8.7441e-005 1.0 2.75e+003 1.0 0.0e+000 0.0e+000 0.0e+000 0 19 0 0 0 0 19 0 0 0 31<br>------------------------------------------------------------------------------------------------------------------------<br>
<br>Memory usage is given in bytes:<br><br>Object Type Creations Destructions Memory Descendants' Mem.<br><br>--- Event Stage 0: Main Stage<br><br> SNES 1 1 668 0<br>
Vec 11 11 13596 0<br> Matrix 3 3 7820 0<br> Krylov Solver 1 1 17392 0<br> Preconditioner 1 1 500 0<br>
Viewer 2 2 680 0<br> Draw 1 1 444 0<br> Axis 1 1 308 0<br> Line Graph 1 1 1908 0<br>
Index Set 6 6 3360 0<br>========================================================================================================================<br>Average time to get PetscTime(): 2.03937e-006<br>
#PETSc Option Table entries:<br>-log_summary<br>-mat_type baij<br>-snes_max_it 20<br>-snes_monitor_residual<br>-snes_view<br>#End o PETSc Option Table entries<br>Compiled without FORTRAN kernels<br>Compiled with full precision matrices (default)<br>
sizeof(short) 2 sizeof(int) 4 sizeof(long) 4 sizeof(void*) 4 sizeof(PetscScalar) 8<br>Configure run at: Mon Jul 6 16:28:41 2009<br>Configure options: --with-cc="win32fe cl --nodetect" --download-c-blas-lapack=1 --with-fc=0 --with-mpi=0 --useThreads=0 --with-shared=0<br>
-----------------------------------------<br>Libraries compiled on Mon Jul 6 16:39:57 2009 on Idrocp03 <br>Machine characteristics: CYGWIN_NT-5.1 Idrocp03 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin <br>Using PETSc directory: /home/Administrator/petsc<br>
Using PETSc arch: cygwin-c-debug<br>-----------------------------------------<br>Using C compiler: /home/Administrator/petsc/bin/win32fe/win32fe cl --nodetect -MT -wd4996 -Z7 <br>Using Fortran compiler: <br>-----------------------------------------<br>
Using include paths: -I/home/Administrator/petsc/cygwin-c-debug/include -I/home/Administrator/petsc/include -I/home/Administrator/petsc/include/mpiuni <br>------------------------------------------<br>Using C linker: /home/Administrator/petsc/bin/win32fe/win32fe cl --nodetect -MT -wd4996 -Z7 <br>
Using Fortran linker: <br>Using libraries: -L/home/Administrator/petsc/cygwin-c-debug/lib -L/home/Administrator/petsc/cygwin-c-debug/lib -lpetscts -lpetscsnes -lpetscksp -lpetscdm -lpetscmat -lpetscvec -lpetsc -L/home/Administrator/petsc/cygwin-c-debug/lib -lf2clapack -lf2cblas -lmpiuni Gdi32.lib User32.lib Advapi32.lib Kernel32.lib Ws2_32.lib <br>
------------------------------------------<br><br><br><br>Thank you in advance for your help,<br><br>Michel Cancelliere<br>Politecnico di Torino<br><br>