Debian Codegraph @

debian/external_deps/fetk/punc/src/pmg/src_f77/nsord.f

raw
1 c* ///////////////////////////////////////////////////////////////////////////
2 c* @file nsord.f
3 c* @author Michael Holst
4 c* @brief Nonlinear SOR iteration.
5 c* @version $Id: nsord.f,v 1.2 2010/08/12 05:45:39 fetk Exp $
6 c* @attention
7 c* @verbatim
8 c*
9 c* PMG -- Parallel algebraic MultiGrid
10 c* Copyright (C) 1994-- Michael Holst.
11 c*
12 c* Michael Holst <[email protected]>
13 c* University of California, San Diego
14 c* Department of Mathematics, 5739 AP&M
15 c* 9500 Gilman Drive, Dept. 0112
16 c* La Jolla, CA 92093-0112 USA
17 c* http://math.ucsd.edu/~mholst
18 c*
19 c* This file is part of PMG.
20 c*
21 c* PMG is free software; you can redistribute it and/or modify
22 c* it under the terms of the GNU General Public License as published by
23 c* the Free Software Foundation; either version 2 of the License, or
24 c* (at your option) any later version.
25 c*
26 c* PMG is distributed in the hope that it will be useful,
27 c* but WITHOUT ANY WARRANTY; without even the implied warranty of
28 c* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 c* GNU General Public License for more details.
30 c*
31 c* You should have received a copy of the GNU General Public License
32 c* along with PMG; if not, write to the Free Software
33 c* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 c*
35 c* Linking PMG statically or dynamically with other modules is making a
36 c* combined work based on PMG. Thus, the terms and conditions of the GNU
37 c* General Public License cover the whole combination.
38 c*
39 c* SPECIAL GPL EXCEPTION
40 c* In addition, as a special exception, the copyright holders of PMG
41 c* give you permission to combine the PMG program with free software
42 c* programs and libraries that are released under the GNU LGPL or with
43 c* code included in releases of ISIM, PMV, PyMOL, SMOL, VMD, and Vision.
44 c* Such combined software may be linked with PMG and redistributed together
45 c* in original or modified form as mere aggregation without requirement that
46 c* the entire work be under the scope of the GNU General Public License.
47 c* This special exception permission is also extended to any software listed
48 c* in the SPECIAL GPL EXCEPTION clauses by the FEtk and APBS libraries.
49 c*
50 c* Note that people who make modified versions of PMG are not obligated
51 c* to grant this special exception for their modified versions; it is
52 c* their choice whether to do so. The GNU General Public License gives
53 c* permission to release a modified version without this exception; this
54 c* exception also makes it possible to release a modified version which
55 c* carries forward this exception.
56 c*
57 c* @endverbatim
58 c* ///////////////////////////////////////////////////////////////////////////
59
60 subroutine nsor(nx,ny,nz,ipc,rpc,ac,cc,fc,x,w1,w2,r,
61 2 itmax,iters,errtol,omega,iresid,iadjoint)
62 c* *********************************************************************
63 c* purpose:
64 c*
65 c* call the fast diagonal iterative method.
66 c*
67 c* author: michael holst
68 c* *********************************************************************
69 implicit none
70 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
71 integer numdia
72 double precision omega,errtol
73 double precision rpc(*),ac(nx*ny*nz,*),cc(nx,ny,nz),fc(nx,ny,nz)
74 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
75 double precision r(nx,ny,nz)
76 c*
77 cmdir 0 0
78 c*
79 c* *** do in one step ***
80 numdia = ipc(11)
81 if (numdia .eq. 7) then
82 call nsor7(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc,
83 2 ac(1,2),ac(1,3),ac(1,4),
84 3 x,w1,w2,r,
85 4 itmax,iters,errtol,omega,iresid,iadjoint)
86 elseif (numdia .eq. 27) then
87 call nsor27(nx,ny,nz,ipc,rpc,ac(1,1),cc,fc,
88 2 ac(1,2),ac(1,3),ac(1,4),ac(1,5),ac(1,6),ac(1,7),ac(1,8),
89 3 ac(1,9),ac(1,10),ac(1,11),ac(1,12),ac(1,13),ac(1,14),
90 4 x,w1,w2,r,
91 5 itmax,iters,errtol,omega,iresid,iadjoint)
92 else
93 print*,'% NSOR: invalid stencil type given...'
94 endif
95 c*
96 c* *** return and end ***
97 return
98 end
99 subroutine nsor7(nx,ny,nz,ipc,rpc,
100 2 oC,cc,fc,
101 3 oE,oN,uC,
102 4 x,w1,w2,r,
103 5 itmax,iters,errtol,omega,iresid,iadjoint)
104 c* *********************************************************************
105 c* purpose:
106 c*
107 c* fast 7 diagonal nonlinear red/black sor routine.
108 c*
109 c* note that the interior grid points from 2,...,nx-1, etc.
110 c* we then begin coloring with a red point, and do a point red/black
111 c* coloring.
112 c*
113 c* the red points are:
114 c*
115 c* if ((j even) and (k even)) then
116 c* begin row at first point, i=2 (i even), or ioff = 0
117 c* else if ((j odd) and (k even)) then
118 c* begin row at second point, i=3 (i odd), or ioff = 1
119 c* else if ((j even) and (k odd)) then
120 c* begin row at second point, i=3 (i odd), or ioff = 1
121 c* else if ((j odd) and (k odd)) then
122 c* begin row at first point, i=2 (i even), or ioff = 0
123 c* endif
124 c* then: begin row at: i=2+ioff
125 c*
126 c* the appropriate ioff function for the red points is then:
127 c* ioff = dabs(mod(j,2)-mod(k,2))
128 c*
129 c* the appropriate ioff function for the black points is then:
130 c* ioff = 1 - dabs(mod(j,2)-mod(k,2))
131 c*
132 c*
133 c* alternatively, the red points are:
134 c*
135 c* those whose indices add up to an even number.
136 c* to see this, consider that all surrounding points are
137 c* only one index different, hence the sum will differ by one.
138 c* thus, if a given point has an even sum, then the surrounding
139 c* points will have an odd sum.
140 c*
141 c* thus, the black points are:
142 c*
143 c* therefore those whose indices add up to an odd number.
144 c*
145 c* algorithm parameters:
146 c* ---------------------
147 c*
148 c* U0 = initial guess
149 c* Llin = matrix representing linear part of equations
150 c* F = vector representing rhs of equations
151 c* nx = number of unknowns
152 c* itmax = number of iterations to perform
153 c* c_scal = function representing nonlinear part of equations
154 c* dc_scal = function representing derivative of nonlinear
155 c* part of equations
156 c* U = final result
157 c*
158 c* algorithm idea:
159 c* ---------------
160 c*
161 c* the ith nonlinear equation is represented as:
162 c*
163 c* N(UU) = AA * UU + c_scal(UU) - FF
164 c*
165 c* which is solved for UU using newton's method, where:
166 c*
167 c* AA = ith diagonal entry of Llin
168 c* FF = F(i), minus the nondiag of ith eqn of Llin times current U
169 c* UU = the unknown, initialized to U(i)
170 c*
171 c* algorithm (matlab language):
172 c* ----------------------------
173 c*
174 c* function [U,iterss,errors] = Zgs(U0,UTRUE,a,b,Llin,F,nx,tol,itmax,stp,plt);
175 c* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 c* %%% nonlinear sor-newton iteration (ortega-rheinboldt, page 219)
177 c* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178 c*
179 c* %%% initial guess
180 c* iters = 0;
181 c* error = 1.0d0;
182 c* U = U0;
183 c* Lnon = c_vec(b,U,nx);
184 c* N = Llin * U + Lnon - F ;
185 c* denom = 1.0d0; if (stp == 1) denom = norm(N); end;
186 c*
187 c* %%% loop
188 c* while ((error > tol) & (iters < itmax))
189 c* iters = iters + 1;
190 c*
191 c* %%% save old guys
192 c* Lnon_OLD = Lnon;
193 c* U_OLD = U;
194 c*
195 c* %%% relax each unknown
196 c* for i = 1:nx
197 c*
198 c* %%% define the 1d rhs
199 c* FF = F(i) - Llin(i,1:nx) * U + Llin(i,i) * U(i);
200 c* AA = Llin(i,i);
201 c* UU = U(i);
202 c* BB = b(i);
203 c*
204 c* %%% perform 1d newton's method
205 c* %%% note that in the linear case, this is equivalent to: FF/AA
206 c* nitmax = 10;
207 c* ntol = 1.0e-7;
208 c* niters = 0;
209 c* N = AA * UU + c_scal(BB,UU) - FF ;
210 c* ndenom = N;
211 c* if (ndenom == 0)
212 c* ndenom = 1;
213 c* end;
214 c* nerror = N / ndenom;
215 c*
216 c* while ((nerror > ntol) & (niters < nitmax))
217 c* niters = niters + 1;
218 c*
219 c* %%% construct jacobian matrix of N
220 c* DN = AA + dc_scal(BB,UU);
221 c*
222 c* %%% solve linear system
223 c* change = - N / DN;
224 c*
225 c* %%% update solution
226 c* UU = UU + change;
227 c*
228 c* %%% construct nonlinear residual
229 c* N = AA * UU + c_scal(BB,UU) - FF ;
230 c*
231 c* %%% compute residual
232 c* nerror = N / ndenom;
233 c* end
234 c*
235 c* %%% update the unknown
236 c* U(i) = UU;
237 c* end
238 c*
239 c* %%% new residual %%%
240 c* Lnon = c_vec(b,U,nx);
241 c* N = Llin * U + Lnon - F ;
242 c* delta = zeros(U);
243 c* delta_s = zeros(U);
244 c*
245 c* end
246 c*
247 c* author: michael holst
248 c* *********************************************************************
249 implicit none
250 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
251 integer i,j,k,ioff
252 double precision omega,errtol,fac
253 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
254 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
255 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
256 double precision r(nx,ny,nz)
257 double precision c_scal,dc_scal
258 double precision UU,AA,BB,FF,zNN,DzNN,zntol,zndenom,znerror
259 double precision change
260 integer nitmax,niters,ifail_tol,ipkey
261 c*
262 cmdir 0 0
263 c*
264 c* *** nonlinear iteration tolerance and itmax ***
265 nitmax = 10
266 zntol = 1.0e-5
267 ifail_tol = 0
268 ipkey = ipc(10)
269 c*
270 c* *** do the sor iteration itmax times ***
271 fac = 1.0d0 - omega
272 do 30 iters = 1, itmax
273 c*
274 c* *** do the red points ***
275 cmdir 3 1
276 do 10 k=2,nz-1
277 cmdir 3 2
278 do 11 j=2,ny-1
279 ioff = mod((j+k+2),2)
280 cmdir 3 3
281 do 12 i=2+ioff,nx-1, 2
282 c*
283 c* *** for this unknown, do a 1d newton's method
284 c*
285 c* *** determine the 1d equation
286 UU = x(i,j,k)
287 AA = oC(i,j,k)
288 BB = cc(i,j,k)
289 FF = fc(i,j,k)
290 2 + oN(i,j,k) * x(i,j+1,k)
291 3 + oN(i,j-1,k) * x(i,j-1,k)
292 4 + oE(i,j,k) * x(i+1,j,k)
293 5 + oE(i-1,j,k) * x(i-1,j,k)
294 6 + uC(i,j,k-1) * x(i,j,k-1)
295 7 + uC(i,j,k) * x(i,j,k+1)
296 c*
297 c* *** evaluate residual of 1d system
298 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
299 c*
300 c* *** setup for newton's method
301 niters = 0
302 zndenom = zNN
303 if (zndenom .eq. 0.0d0) zndenom = 1.0d0
304 znerror = zNN / zndenom
305 c*
306 c* *** the 1d newton's method ***
307 if (znerror .lt. zntol) goto 17
308 if (niters .gt. nitmax) goto 16
309 15 continue
310 niters = niters + 1
311 c*
312 c* *** construct jacobian matrix of NN ***
313 DzNN = AA + dc_scal(BB,UU,ipkey)
314 c*
315 c* *** solve the linear system ***
316 change = - zNN / DzNN
317 c*
318 c* *** update the solution ***
319 UU = UU + change
320 c*
321 c* *** evaluate residual of 1d system ***
322 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
323 c*
324 c* *** compute error ***
325 znerror = zNN / zndenom
326 c*
327 c* *** tolerance and itmax check ***
328 if (znerror .lt. zntol) goto 17
329 if (niters .gt. nitmax) goto 16
330 c*
331 c* *** loop ***
332 goto 15
333 c*
334 c* *** tolerance not reached ***
335 16 continue
336 ifail_tol = ifail_tol + 1
337 c*
338 c* *** tolerance reached ***
339 17 continue
340 c*
341 c* *** newton's method complete -- update solution value ***
342 x(i,j,k) = x(i,j,k)*fac + omega*UU
343 12 continue
344 11 continue
345 10 continue
346 c*
347 c* *** do the black points ***
348 cmdir 3 1
349 do 20 k=2,nz-1
350 cmdir 3 2
351 do 21 j=2,ny-1
352 ioff = 1 - mod((j+k+2),2)
353 cmdir 3 3
354 do 22 i=2+ioff,nx-1, 2
355 c*
356 c* *** for this unknown, do a 1d newton's method
357 c*
358 c* *** determine the 1d equation
359 UU = x(i,j,k)
360 AA = oC(i,j,k)
361 BB = cc(i,j,k)
362 FF = fc(i,j,k)
363 2 + oN(i,j,k) * x(i,j+1,k)
364 3 + oN(i,j-1,k) * x(i,j-1,k)
365 4 + oE(i,j,k) * x(i+1,j,k)
366 5 + oE(i-1,j,k) * x(i-1,j,k)
367 6 + uC(i,j,k-1) * x(i,j,k-1)
368 7 + uC(i,j,k) * x(i,j,k+1)
369 c*
370 c* *** evaluate residual of 1d system
371 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
372 c*
373 c* *** setup for newton's method
374 niters = 0
375 zndenom = zNN
376 if (zndenom .eq. 0.0d0) zndenom = 1.0d0
377 znerror = zNN / zndenom
378 c*
379 c* *** the 1d newton's method ***
380 if (znerror .lt. zntol) goto 27
381 if (niters .gt. nitmax) goto 26
382 25 continue
383 niters = niters + 1
384 c*
385 c* *** construct jacobian matrix of NN ***
386 DzNN = AA + dc_scal(BB,UU,ipkey)
387 c*
388 c* *** solve the linear system ***
389 change = - zNN / DzNN
390 c*
391 c* *** update the solution ***
392 UU = UU + change
393 c*
394 c* *** evaluate residual of 1d system ***
395 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
396 c*
397 c* *** compute error ***
398 znerror = zNN / zndenom
399 c*
400 c* *** tolerance and itmax check ***
401 if (znerror .lt. zntol) goto 27
402 if (niters .gt. nitmax) goto 26
403 c*
404 c* *** loop ***
405 goto 25
406 c*
407 c* *** tolerance not reached ***
408 26 continue
409 ifail_tol = ifail_tol + 1
410 c*
411 c* *** tolerance reached ***
412 27 continue
413 c*
414 c* *** newton's method complete -- update solution value ***
415 x(i,j,k) = x(i,j,k)*fac + omega*UU
416 22 continue
417 21 continue
418 20 continue
419 c*
420 c* *** main loop ***
421 30 continue
422 c*
423 c* *** if specified, return the new residual as well ***
424 if (iresid .eq. 1) then
425 call nmresid7_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,oE,oN,uC,x,r,w1)
426 endif
427 c*
428 c* *** messages ***
429 if (ifail_tol .gt. 0) then
430 print*,'% NSOR: 1d newton tolerance failures: ',ifail_tol
431 endif
432 c*
433 c* *** return and end ***
434 return
435 end
436 subroutine nsor27(nx,ny,nz,ipc,rpc,
437 2 oC,cc,fc,
438 3 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
439 4 x,w1,w2,r,
440 5 itmax,iters,errtol,omega,iresid,iadjoint)
441 c* *********************************************************************
442 c* purpose:
443 c*
444 c* 27 diagonal nonlinear sor routine.
445 c*
446 c* algorithm parameters:
447 c* ---------------------
448 c*
449 c* U0 = initial guess
450 c* Llin = matrix representing linear part of equations
451 c* F = vector representing rhs of equations
452 c* nx = number of unknowns
453 c* itmax = number of iterations to perform
454 c* c_scal = function representing nonlinear part of equations
455 c* dc_scal = function representing derivative of nonlinear
456 c* part of equations
457 c* U = final result
458 c*
459 c* algorithm idea:
460 c* ---------------
461 c*
462 c* the ith nonlinear equation is represented as:
463 c*
464 c* N(UU) = AA * UU + c_scal(UU) - FF
465 c*
466 c* which is solved for UU using newton's method, where:
467 c*
468 c* AA = ith diagonal entry of Llin
469 c* FF = F(i), minus the nondiag of ith eqn of Llin times current U
470 c* UU = the unknown, initialized to U(i)
471 c*
472 c* algorithm (matlab language):
473 c* ----------------------------
474 c*
475 c* function [U,iterss,errors] = Zgs(U0,UTRUE,a,b,Llin,F,nx,tol,itmax,stp,plt);
476 c* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
477 c* %%% nonlinear sor-newton iteration (ortega-rheinboldt, page 219)
478 c* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 c*
480 c* %%% initial guess
481 c* iters = 0;
482 c* error = 1.0d0;
483 c* U = U0;
484 c* Lnon = c_vec(b,U,nx);
485 c* N = Llin * U + Lnon - F ;
486 c* denom = 1.0d0; if (stp == 1) denom = norm(N); end;
487 c*
488 c* %%% loop
489 c* while ((error > tol) & (iters < itmax))
490 c* iters = iters + 1;
491 c*
492 c* %%% save old guys
493 c* Lnon_OLD = Lnon;
494 c* U_OLD = U;
495 c*
496 c* %%% relax each unknown
497 c* for i = 1:nx
498 c*
499 c* %%% define the 1d rhs
500 c* FF = F(i) - Llin(i,1:nx) * U + Llin(i,i) * U(i);
501 c* AA = Llin(i,i);
502 c* UU = U(i);
503 c* BB = b(i);
504 c*
505 c* %%% perform 1d newton's method
506 c* %%% note that in the linear case, this is equivalent to: FF/AA
507 c* nitmax = 10;
508 c* ntol = 1.0e-7;
509 c* niters = 0;
510 c* N = AA * UU + c_scal(BB,UU) - FF ;
511 c* ndenom = N;
512 c* if (ndenom == 0)
513 c* ndenom = 1;
514 c* end;
515 c* nerror = N / ndenom;
516 c*
517 c* while ((nerror > ntol) & (niters < nitmax))
518 c* niters = niters + 1;
519 c*
520 c* %%% construct jacobian matrix of N
521 c* DN = AA + dc_scal(BB,UU);
522 c*
523 c* %%% solve linear system
524 c* change = - N / DN;
525 c*
526 c* %%% update solution
527 c* UU = UU + change;
528 c*
529 c* %%% construct nonlinear residual
530 c* N = AA * UU + c_scal(BB,UU) - FF ;
531 c*
532 c* %%% compute residual
533 c* nerror = N / ndenom;
534 c* end
535 c*
536 c* %%% update the unknown
537 c* U(i) = UU;
538 c* end
539 c*
540 c* %%% new residual %%%
541 c* Lnon = c_vec(b,U,nx);
542 c* N = Llin * U + Lnon - F ;
543 c* delta = zeros(U);
544 c* delta_s = zeros(U);
545 c*
546 c* end
547 c*
548 c* author: michael holst
549 c* *********************************************************************
550 implicit none
551 integer ipc(*),itmax,iters,iresid,iadjoint,nx,ny,nz
552 integer i,j,k
553 double precision omega,errtol,fac
554 double precision rpc(*),oE(nx,ny,nz),oN(nx,ny,nz),uC(nx,ny,nz)
555 double precision oNE(nx,ny,nz),oNW(nx,ny,nz),uE(nx,ny,nz)
556 double precision uW(nx,ny,nz),uN(nx,ny,nz),uS(nx,ny,nz)
557 double precision uNE(nx,ny,nz),uNW(nx,ny,nz),uSE(nx,ny,nz)
558 double precision uSW(nx,ny,nz)
559 double precision fc(nx,ny,nz),oC(nx,ny,nz),cc(nx,ny,nz)
560 double precision x(nx,ny,nz),w1(nx,ny,nz),w2(nx,ny,nz)
561 double precision r(nx,ny,nz)
562 double precision c_scal,dc_scal
563 double precision UU,AA,BB,FF,zNN,DzNN,zntol,zndenom,znerror
564 double precision change
565 integer nitmax,niters,ifail_tol,ipkey
566 double precision tmpO,tmpU,tmpD
567 c*
568 cmdir 0 0
569 c*
570 c* *** nonlinear iteration tolerance and itmax ***
571 nitmax = 10
572 zntol = 1.0e-5
573 ifail_tol = 0
574 ipkey = ipc(10)
575 c*
576 c* *** do the sor iteration itmax times ***
577 fac = 1.0d0 - omega
578 do 30 iters = 1, itmax
579 c*
580 c* *** do all of the points ***
581 cmdir 3 1
582 do 10 k=2,nz-1
583 cmdir 3 2
584 do 11 j=2,ny-1
585 cmdir 3 3
586 do 12 i=2,nx-1
587 c*
588 c* *** for this unknown, do a 1d newton's method
589 c*
590 c* *** determine the 1d equation
591 UU = x(i,j,k)
592 AA = oC(i,j,k)
593 BB = cc(i,j,k)
594 tmpO =
595 2 + oN(i,j,k) * x(i,j+1,k)
596 3 + oN(i,j-1,k) * x(i,j-1,k)
597 4 + oE(i,j,k) * x(i+1,j,k)
598 5 + oE(i-1,j,k) * x(i-1,j,k)
599 6 + oNE(i,j,k) * x(i+1,j+1,k)
600 7 + oNW(i,j,k) * x(i-1,j+1,k)
601 8 + oNW(i+1,j-1,k) * x(i+1,j-1,k)
602 9 + oNE(i-1,j-1,k) * x(i-1,j-1,k)
603 tmpU =
604 2 + uC(i,j,k) * x(i,j,k+1)
605 3 + uN(i,j,k) * x(i,j+1,k+1)
606 4 + uS(i,j,k) * x(i,j-1,k+1)
607 5 + uE(i,j,k) * x(i+1,j,k+1)
608 6 + uW(i,j,k) * x(i-1,j,k+1)
609 7 + uNE(i,j,k) * x(i+1,j+1,k+1)
610 8 + uNW(i,j,k) * x(i-1,j+1,k+1)
611 9 + uSE(i,j,k) * x(i+1,j-1,k+1)
612 9 + uSW(i,j,k) * x(i-1,j-1,k+1)
613 tmpD =
614 2 + uC(i,j,k-1) * x(i,j,k-1)
615 3 + uS(i,j+1,k-1) * x(i,j+1,k-1)
616 4 + uN(i,j-1,k-1) * x(i,j-1,k-1)
617 5 + uW(i+1,j,k-1) * x(i+1,j,k-1)
618 6 + uE(i-1,j,k-1) * x(i-1,j,k-1)
619 7 + uSW(i+1,j+1,k-1) * x(i+1,j+1,k-1)
620 8 + uSE(i-1,j+1,k-1) * x(i-1,j+1,k-1)
621 9 + uNW(i+1,j-1,k-1) * x(i+1,j-1,k-1)
622 9 + uNE(i-1,j-1,k-1) * x(i-1,j-1,k-1)
623 FF = fc(i,j,k) + tmpO + tmpU + tmpD
624 c*
625 c* *** evaluate residual of 1d system
626 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
627 c*
628 c* *** setup for newton's method
629 niters = 0
630 zndenom = zNN
631 if (zndenom .eq. 0.0d0) zndenom = 1.0d0
632 znerror = zNN / zndenom
633 c*
634 c* *** the 1d newton's method ***
635 if (znerror .lt. zntol) goto 17
636 if (niters .gt. nitmax) goto 16
637 15 continue
638 niters = niters + 1
639 c*
640 c* *** construct jacobian matrix of NN ***
641 DzNN = AA + dc_scal(BB,UU,ipkey)
642 c*
643 c* *** solve the linear system ***
644 change = - zNN / DzNN
645 c*
646 c* *** update the solution ***
647 UU = UU + change
648 c*
649 c* *** evaluate residual of 1d system ***
650 zNN = AA * UU + c_scal(BB,UU,ipkey) - FF
651 c*
652 c* *** compute error ***
653 znerror = zNN / zndenom
654 c*
655 c* *** tolerance and itmax check ***
656 if (znerror .lt. zntol) goto 17
657 if (niters .gt. nitmax) goto 16
658 c*
659 c* *** loop ***
660 goto 15
661 c*
662 c* *** tolerance not reached ***
663 16 continue
664 ifail_tol = ifail_tol + 1
665 c*
666 c* *** tolerance reached ***
667 17 continue
668 c*
669 c* *** newton's method complete -- update solution value ***
670 x(i,j,k) = x(i,j,k)*fac + omega*UU
671 12 continue
672 11 continue
673 10 continue
674 c*
675 c* *** main loop ***
676 30 continue
677 c*
678 c* *** if specified, return the new residual as well ***
679 if (iresid .eq. 1) then
680 call nmresid27_1s(nx,ny,nz,ipc,rpc,oC,cc,fc,
681 2 oE,oN,uC,oNE,oNW,uE,uW,uN,uS,uNE,uNW,uSE,uSW,
682 3 x,r,w1)
683 endif
684 c*
685 c* *** messages ***
686 if (ifail_tol .gt. 0) then
687 print*,'% NSOR: 1d newton tolerance failures: ',ifail_tol
688 endif
689 c*
690 c* *** return and end ***
691 return
692 end