V3FIT
inguess.f
1  SUBROUTINE inguess(rin, zin, angle)
2 C-----------------------------------------------
3 C M o d u l e s
4 C-----------------------------------------------
5  USE vname0
6  USE vname1
7  IMPLICIT NONE
8 C-----------------------------------------------
9 C D u m m y A r g u m e n t s
10 C-----------------------------------------------
11  REAL(rprec), DIMENSION(ntheta,nphi) :: rin, zin, angle
12 C-----------------------------------------------
13 C L o c a l V a r i a b l e s
14 C-----------------------------------------------
15  INTEGER :: i, inside, jskip, j1, j2
16 C-----------------------------------------------
17 c**********************************************************************
18 c this subroutine obtains initial guesses for the centroid at each
19 c toroidal plane. By default, the polar axis is set equal to this
20 c centroid. It is imperative that the polar axis be enclosed by
21 c the surface (otherwise the computed theta angles will not span
22 c [0,2pi]). For certain complex cross-sections, this simple estimate
23 c of the polar axis may fail, and the user must supply values for
24 c raxis(i),zaxis(i). In addition, for non-starlike domains, the
25 c points along the curve must be monitonically increasing as a
26 c function of the arclength from any fixed point on the curve. this
27 c ordering is attempted by the subroutine order, but may fail in
28 c general if too few theta points are used.
29 c
30 c modified 8/13/97, j. breslau. the subroutine now tries several guesses
31 c for the magnetic axis position if the first fails. the mean position
32 c of pairs of points is taken until one is found to be inside.
33 c**********************************************************************
34 c COMPUTE CENTROID AND
35 c ORDER POINTS ON FLUX SURFACE AT EACH TOROIDAL ANGLE
36 c**********************************************************************
37  print *, 'ORDERING SURFACE POINTS'
38  DO i = 1, nphi
39  r0n(i) = r0n(i) + sum(rin(:,i))/real(ntheta,rprec)
40  z0n(i) = z0n(i) + sum(zin(:,i))/real(ntheta,rprec)
41  raxis(i) = r0n(i)
42  zaxis(i) = z0n(i)
43  CALL order (rin(1,i), zin(1,i), raxis(i), zaxis(i), inside)
44  IF (inside .eq. 0) THEN
45  jskip = ntheta/2
46  40 CONTINUE
47  jskip = jskip - 1
48  IF (jskip .le. 0) THEN
49  print *, 'Could not find internal point'
50  WRITE (3, *) 'Could not find internal point'
51  stop
52  ENDIF
53  j1 = 1
54  j2 = j1 + jskip
55  50 CONTINUE
56  raxis(i) = 0.5_dp*(rin(j1,i)+rin(j2,i))
57  zaxis(i) = 0.5_dp*(zin(j1,i)+zin(j2,i))
58  CALL order (rin(1,i), zin(1,i), raxis(i), zaxis(i), inside)
59  IF (inside .eq. 1) THEN
60  r0n(i) = raxis(i)
61  z0n(i) = zaxis(i)
62  ELSE
63  j1 = j1 + 1
64  IF (j1 .gt. ntheta) GOTO 40
65  j2 = j2 + 1
66  IF (j2 .gt. ntheta) j2 = 1
67  GOTO 50
68  ENDIF
69  ENDIF
70  END DO
71 c**********************************************************************
72 c COMPUTE OPTIMUM ANGLE OFFSETS FOR M = 1 MODES
73 c**********************************************************************
74  CALL getangle (rin, zin, angle, r0n, z0n)
75 
76  END SUBROUTINE inguess