/[escript]/trunk/paso/src/NewtonGMRES.c
ViewVC logotype

Contents of /trunk/paso/src/NewtonGMRES.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3005 - (show annotations)
Thu Apr 22 05:59:31 2010 UTC (9 years, 6 months ago) by gross
File MIME type: text/plain
File size: 6175 byte(s)
early call of setPreconditioner in FCT solver removed.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /*
16 * Purpose
17 * =======
18 *
19 * NewtonGMRES solves the non-linear system F(x)=0 using the
20 * restarted GMRES method.
21 *
22 * Convergence test: norm(F(x))< rtol*norm(F(x0))+atol
23 *
24 * x input initial guess
25 * output solution approximation
26 *
27 * based on code by C. T. Kelley, July 1, 1994.
28 *
29 */
30
31 #include "Common.h"
32 #include "Solver.h"
33 #include "PasoUtil.h"
34 #ifdef _OPENMP
35 #include <omp.h>
36 #endif
37 err_t Paso_Solver_NewtonGMRES(
38 Paso_Function *F, /* function evaluation */
39 double *x, /* in: initial guess, out: new approximation */
40 Paso_Options* options,
41 Paso_Performance* pp)
42
43 {
44 const double inner_tolerance_safety=.9;
45 dim_t gmres_iter;
46 double stop_tol, norm2_f,norm2_fo, normsup_f,reduction_f, gmres_tol, rtmp, quad_tolerance;
47 bool_t convergeFlag=FALSE, maxIterFlag=FALSE, breakFlag=FALSE;
48 double *f=NULL, *step=NULL;
49 err_t Status=SOLVER_NO_ERROR;
50 const bool_t debug=options->verbose;
51 const dim_t n = F->n;
52 dim_t iteration_count=0;
53 const double atol=options->absolute_tolerance; /* absolute tolerance */
54 const double rtol=options->tolerance; /* relative tolerance */
55 const dim_t maxit=options->iter_max; /* max iteration counter */
56 const dim_t lmaxit=options->inner_iter_max*10; /* max inner iteration counter */
57 const bool_t adapt_inner_tolerance=options->adapt_inner_tolerance;
58 const double max_inner_tolerance=options->inner_tolerance *1.e-11;
59 double inner_tolerance=max_inner_tolerance;
60 /*
61 * max_inner_tolerance = Maximum error tolerance for residual in inner
62 * iteration. The inner iteration terminates
63 * when the relative linear residual is smaller than inner_tolerance*| F(x_c) |. inner_tolerance is determined
64 * by the modified Eisenstat-Walker formula, if adapt_inner_tolerance is set, otherwise
65 * inner_tolerance = max_inner_tolerance iteration.
66 */
67
68 f=TMPMEMALLOC(n,double);
69 step=TMPMEMALLOC(n,double);
70 if (f==NULL || step ==NULL) {
71 Status=SOLVER_MEMORY_ERROR;
72 } else {
73 /*
74 * initial evaluation of F
75 */
76 Paso_FunctionCall(F,f,x,pp);
77 iteration_count++;
78 norm2_f=Paso_l2(n,f,F->mpi_info);
79 normsup_f=Paso_lsup(n,f,F->mpi_info);
80 /*
81 * stoping criterium:
82 */
83 stop_tol=atol + rtol*normsup_f;
84 if (stop_tol<=0) {
85 Status=SOLVER_INPUT_ERROR;
86 if (debug) printf("NewtonGMRES: zero tolerance given.\n");
87 } else {
88 iteration_count=1;
89 if (debug) {
90 printf("NewtonGMRES: Start Jacobi-free Newton scheme\n");
91 printf("NewtonGMRES: lsup tolerance rel/abs= %e/%e\n",rtol,atol);
92 printf("NewtonGMRES: lsup stopping tolerance = %e\n",stop_tol);
93
94 printf("NewtonGMRES: max. inner iterations (GMRES) = %d\n",lmaxit);
95 if (adapt_inner_tolerance) {
96 printf("NewtonGMRES: inner tolerance is adapted.\n");
97 printf("NewtonGMRES: max. inner l2 tolerance (GMRES) = %e\n",max_inner_tolerance);
98 } else {
99 printf("NewtonGMRES: inner l2 tolerance (GMRES) = %e\n",inner_tolerance);
100 }
101 }
102 /*
103 * main iteration loop
104 */
105 while (! (convergeFlag || maxIterFlag || breakFlag)) {
106 /*
107 * keep track of the ratio (reduction_f = norm2_f/norm2_fo) of successive residual norms and
108 * the iteration counter (iteration_count)
109 */
110 if (debug) printf("NewtonGMRES: iteration step %d: lsup-norm of F =%e\n",iteration_count,normsup_f);
111 /*
112 * call GMRES to get increment
113 */
114 gmres_iter=lmaxit;
115 gmres_tol=inner_tolerance;
116 Status=Paso_Solver_GMRES2(F,f,x,step,&gmres_iter,&gmres_tol,pp);
117 inner_tolerance=MAX(inner_tolerance, gmres_tol/norm2_f);
118 printf("NewtonGMRES: actual rel. inner tolerance = %e\n",inner_tolerance);
119 iteration_count+=gmres_iter;
120 if ((Status==SOLVER_NO_ERROR) || (Status==SOLVER_MAXITER_REACHED)) {
121 Status=SOLVER_NO_ERROR;
122 /*
123 * update x:
124 */
125 norm2_fo=norm2_f;
126 Paso_Update(n,1.,x,1.,step);
127 Paso_FunctionCall(F,f,x,pp);
128 iteration_count++;
129 norm2_f=Paso_l2(n,f,F->mpi_info);
130 normsup_f=Paso_lsup(n,f,F->mpi_info);
131 reduction_f=norm2_f/norm2_fo;
132 /*
133 * adjust inner_tolerance
134 */
135 if (adapt_inner_tolerance) {
136 quad_tolerance = inner_tolerance_safety * reduction_f * reduction_f;
137 rtmp=inner_tolerance_safety * inner_tolerance * inner_tolerance;
138 if (rtmp>.1) {
139 inner_tolerance=MIN(max_inner_tolerance, MAX(quad_tolerance,rtmp));
140 } else {
141 inner_tolerance=MIN(max_inner_tolerance, quad_tolerance);
142 }
143 inner_tolerance=MIN(max_inner_tolerance, MAX(inner_tolerance, .5*stop_tol/normsup_f));
144 }
145 convergeFlag = (normsup_f <= stop_tol);
146 } else {
147 breakFlag=TRUE;
148 }
149 maxIterFlag = (iteration_count > maxit);
150 }
151 if (debug) {
152 printf("NewtonGMRES: iteration step %d: lsup-norm of F =%e\n",iteration_count,normsup_f);
153
154 if (convergeFlag) printf("NewtonGMRES: convergence reached after %d steps.\n",iteration_count);
155 if (breakFlag) printf("NewtonGMRES: iteration break down after %d steps.\n",iteration_count);
156 if (maxIterFlag) printf("NewtonGMRES: maximum number of iteration step %d is reached.\n",maxit);
157 }
158 if (breakFlag) Status=SOLVER_BREAKDOWN;
159 if (maxIterFlag) Status=SOLVER_MAXITER_REACHED;
160 }
161 }
162 TMPMEMFREE(f);
163 TMPMEMFREE(step);
164 if (debug) printf("NewtonGMRES: STATUS return = %d\n",Status);
165 return Status;
166 }

  ViewVC Help
Powered by ViewVC 1.1.26