V3FIT
init_modular_coils.f
1  SUBROUTINE init_modular_coils (nvariables, xvariables, nfp)
2 !-----------------------------------------------
3 ! M o d u l e s
4 !-----------------------------------------------
5  USE modular_coils
6  IMPLICIT NONE
7 !-----------------------------------------------
8 ! L o c a l V a r i a b l e s
9 !-----------------------------------------------
10  INTEGER :: nc, i, n, nfp
11  INTEGER :: nvariables, modes
12  REAL(rprec) :: xvariables(*)
13 !-----------------------------------------------
14 
15  nc = nmod_coils_per_period
16 
17  nfper = nfp
18  nmod_coils = nc*nfper
19  nmid = (nc+1)/2
20  nodd = mod(nc,2)
21  IF ((nodd.EQ.0) .AND. (.NOT.lsymm)) nmid = nmid + 1
22 
23  nvariables = 0
24  nmod_coeffs = 0
25 
26  IF (nc .LE. 0) RETURN
27 
28 ! Initialize the variables to values of unique coil parameters
29 ! and count the number of variables
30 
31  n = 0
32 
33 ! First consider the CASE with coils on both symmetry planes at
34 ! phi = 0 and phi = pi/nfp (lsymm = F). This implies that the number
35 ! of coils per field period must be even (nodd = 0).
36 
37  IF ((nodd .EQ. 0) .AND. (.NOT.lsymm)) THEN
38 
39 ! Symmetry coil at phi = 0.
40 
41  i = 1
42  DO modes = 1, nf_phi
43  n = n + 1
44  xvariables(n) = phis(i,modes)
45  END DO
46 
47  DO modes = 1, nf_rho
48  n = n + 1
49  xvariables(n) = rhos(i,modes)
50  END DO
51 
52 ! Coils 2 through nmid-1.
53  DO i = 2, nmid-1
54  n = n + 1
55  xvariables(n) = phic(i,0)
56  DO modes = 1,nf_phi
57  n = n + 1
58  xvariables(n) = phic(i,modes)
59  n = n + 1
60  xvariables(n) = phis(i,modes)
61  END DO
62 
63  n = n + 1
64  xvariables(n) = rhoc(i,0)
65  DO modes = 1,nf_rho
66  n = n + 1
67  xvariables(n) = rhoc(i,modes)
68  n = n + 1
69  xvariables(n) = rhos(i,modes)
70  END DO
71  END DO
72 
73 ! Symmetry coil at phi = pi/nfp.
74  i = nmid
75  DO modes = 1, nf_phi
76  n = n + 1
77  xvariables(n) = phis(i,modes)
78  END DO
79 
80  DO modes = 1, nf_rho
81  n = n + 1
82  xvariables(n) = rhos(i,modes)
83  END DO
84 
85 ! Next consider the cases with a coil on phi = 0 (lsymm = T), or
86 ! on phi = pi/nfp (lsymm = F), but not both. Then there may be an
87 ! even number of coils per period (nodd = 0) or an odd number of
88 ! coils per period (nodd = 1).
89 
90  ELSE
91 
92  DO i = 1, nmid-nodd
93  n = n + 1
94  xvariables(n) = phic(i,0)
95  DO modes = 1,nf_phi
96  n = n + 1
97  xvariables(n) = phic(i,modes)
98  n = n + 1
99  xvariables(n) = phis(i,modes)
100  END DO
101 
102  n = n + 1
103  xvariables(n) = rhoc(i,0)
104  DO modes = 1,nf_rho
105  n = n + 1
106  xvariables(n) = rhoc(i,modes)
107  n = n + 1
108  xvariables(n) = rhos(i,modes)
109  END DO
110  END DO
111 
112  IF (nodd .EQ. 1) THEN
113  i = nmid
114  DO modes = 1, nf_phi
115  n = n + 1
116  xvariables(n) = phis(i,modes)
117  END DO
118 
119  DO modes = 1, nf_rho
120  n = n + 1
121  xvariables(n) = rhos(i,modes)
122  END DO
123  END IF
124 
125  END IF ! END IF ((nodd .eq. 0) .and. (lsymm .eqv. .false.))
126 
127  nmod_coeffs = n
128  nvariables = n
129 
130  END SUBROUTINE init_modular_coils