VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
symforce.f90
Go to the documentation of this file.
1
4
28SUBROUTINE symforce(ars, brs, crs, azs, bzs, czs, bls, cls, rcs, zcs, &
29 ara, bra, cra, aza, bza, cza, bla, cla, rca, zca)
30 USE vmec_main, p5 => cp5
31
32 use dbgout
33
34 IMPLICIT NONE
35
36 REAL(rprec), DIMENSION(ns*nzeta,ntheta3,0:1), INTENT(inout) :: &
37 ars, brs, crs, azs, bzs, czs, bls, cls, rcs, zcs
38 REAL(rprec), DIMENSION(ns*nzeta,ntheta3,0:1), INTENT(out) :: &
39 ara, bra, cra, aza, bza, cza, bla, cla, rca, zca
40
41 INTEGER :: mpar, ir, i, jk, jka, j, k
42 REAL(rprec), DIMENSION(:), ALLOCATABLE :: ars_0, brs_0, azs_0, &
43 bzs_0, bls_0, rcs_0, zcs_0, crs_0, czs_0, cls_0
44
45 logical :: dbg_symforce
46
47 i = ns*nzeta
48 ALLOCATE (ars_0(i), brs_0(i), azs_0(i), bzs_0(i), bls_0(i), &
49 rcs_0(i), zcs_0(i), crs_0(i), czs_0(i), cls_0(i), stat=ir)
50
51 dbg_symforce = open_dbg_context("symforce")
52 if (dbg_symforce) then
53
54 call add_real_4d("ars", ns, 2, nzeta, ntheta3, ars, order=(/ 1, 3, 4, 2 /) )
55 call add_real_4d("brs", ns, 2, nzeta, ntheta3, brs, order=(/ 1, 3, 4, 2 /) )
56 call add_real_4d("azs", ns, 2, nzeta, ntheta3, azs, order=(/ 1, 3, 4, 2 /) )
57 call add_real_4d("bzs", ns, 2, nzeta, ntheta3, bzs, order=(/ 1, 3, 4, 2 /) )
58 call add_real_4d("bls", ns, 2, nzeta, ntheta3, bls, order=(/ 1, 3, 4, 2 /) )
59 call add_real_4d("rcs", ns, 2, nzeta, ntheta3, rcs, order=(/ 1, 3, 4, 2 /) )
60 call add_real_4d("zcs", ns, 2, nzeta, ntheta3, zcs, order=(/ 1, 3, 4, 2 /) )
61
62 if (lthreed) then
63 call add_real_4d("crs", ns, 2, nzeta, ntheta3, crs, order=(/ 1, 3, 4, 2 /) )
64 call add_real_4d("czs", ns, 2, nzeta, ntheta3, czs, order=(/ 1, 3, 4, 2 /) )
65 call add_real_4d("cls", ns, 2, nzeta, ntheta3, cls, order=(/ 1, 3, 4, 2 /) )
66 else
67 call add_null("crs")
68 call add_null("czs")
69 call add_null("cls")
70 end if
71
72 end if ! dump_symforce
73
74 ! SYMMETRIZE FORCES ON RESTRICTED THETA INTERVAL (0 <= u <= pi)
75 ! SO COS,SIN INTEGRALS CAN BE PERFORMED. FOR EXAMPLE,
76 !
77 ! ARS(v,u) = .5*( ARS(v,u) + ARS(-v,-u) ) ! * COS(mu - nv)
78 ! ARA(v,u) = .5*( ARS(v,u) - ARS(-v,-u) ) ! * SIN(mu - nv)
79 !
80 ! See also Theorem 26 (Parity Decomposition) in Boyd, "Chebychev and Fourier Spectral Methods".
81 DO mpar = 0, 1
82 DO i = 1, ntheta2
83
84 ! (ntheta1 + 1) - (i-1)
85 ir = ntheta1 + 2 - i !-theta
86 IF (i .eq. 1) ir = 1
87
88
89 DO jk = 1, ns*nzeta
90 jka = ireflect(jk) !-zeta
91
92 ara(jk,i,mpar) = p5*(ars(jk,i,mpar)-ars(jka,ir,mpar)) ! std. parity
93 ars_0(jk) = p5*(ars(jk,i,mpar)+ars(jka,ir,mpar))
94 bra(jk,i,mpar) = p5*(brs(jk,i,mpar)+brs(jka,ir,mpar)) ! rev. parity
95 brs_0(jk) = p5*(brs(jk,i,mpar)-brs(jka,ir,mpar))
96 ! cr only in lthreed case (see below)
97
98 aza(jk,i,mpar) = p5*(azs(jk,i,mpar)+azs(jka,ir,mpar)) ! rev. parity
99 azs_0(jk) = p5*(azs(jk,i,mpar)-azs(jka,ir,mpar))
100 bza(jk,i,mpar) = p5*(bzs(jk,i,mpar)-bzs(jka,ir,mpar)) ! std. parity
101 bzs_0(jk) = p5*(bzs(jk,i,mpar)+bzs(jka,ir,mpar))
102 ! cz only in lthreed case (see below)
103
104 bla(jk,i,mpar) = p5*(bls(jk,i,mpar)-bls(jka,ir,mpar)) ! std. parity
105 bls_0(jk) = p5*(bls(jk,i,mpar)+bls(jka,ir,mpar))
106 ! cl only in lthreed case (see below)
107
108 rca(jk,i,mpar) = p5*(rcs(jk,i,mpar)-rcs(jka,ir,mpar)) ! std. parity
109 rcs_0(jk) = p5*(rcs(jk,i,mpar)+rcs(jka,ir,mpar))
110 zca(jk,i,mpar) = p5*(zcs(jk,i,mpar)+zcs(jka,ir,mpar)) ! rev. parity
111 zcs_0(jk) = p5*(zcs(jk,i,mpar)-zcs(jka,ir,mpar))
112 END DO
113
114 ! need to store symmetric part in temp array,
115 ! since reflected indices must not be overwritten above!
116 ars(:,i,mpar) = ars_0(:)
117 brs(:,i,mpar) = brs_0(:)
118 azs(:,i,mpar) = azs_0(:)
119 bzs(:,i,mpar) = bzs_0(:)
120 bls(:,i,mpar) = bls_0(:)
121 rcs(:,i,mpar) = rcs_0(:)
122 zcs(:,i,mpar) = zcs_0(:)
123
124 IF (lthreed) THEN
125 DO jk = 1, ns*nzeta
126 jka = ireflect(jk)
127
128 cra(jk,i,mpar) = p5*(crs(jk,i,mpar)+crs(jka,ir,mpar)) ! rev. parity
129 crs_0(jk) = p5*(crs(jk,i,mpar)-crs(jka,ir,mpar))
130
131 cza(jk,i,mpar) = p5*(czs(jk,i,mpar)-czs(jka,ir,mpar)) ! std. parity
132 czs_0(jk) = p5*(czs(jk,i,mpar)+czs(jka,ir,mpar))
133
134 cla(jk,i,mpar) = p5*(cls(jk,i,mpar)-cls(jka,ir,mpar)) ! std. parity
135 cls_0(jk) = p5*(cls(jk,i,mpar)+cls(jka,ir,mpar))
136 END DO
137
138 crs(:,i,mpar) = crs_0(:)
139 czs(:,i,mpar) = czs_0(:)
140 cls(:,i,mpar) = cls_0(:)
141 ENDIF
142
143 END DO
144
145 ! clear remainder of arrays for debug output
146 DO i = ntheta2+1, ntheta3
147 ara(:,i,mpar) = 0.0_dp
148 bra(:,i,mpar) = 0.0_dp
149 aza(:,i,mpar) = 0.0_dp
150 bza(:,i,mpar) = 0.0_dp
151 bla(:,i,mpar) = 0.0_dp
152 rca(:,i,mpar) = 0.0_dp
153 zca(:,i,mpar) = 0.0_dp
154 if (lthreed) then
155 cra(:,i,mpar) = 0.0_dp
156 cza(:,i,mpar) = 0.0_dp
157 cla(:,i,mpar) = 0.0_dp
158 end if
159 end do
160 END DO
161
162 DEALLOCATE (ars_0, brs_0, azs_0, bzs_0, bls_0, &
163 rcs_0, zcs_0, crs_0, czs_0, cls_0, stat=ir)
164
165 if (dbg_symforce) then
166 call add_real_4d("ars_out", ns, 2, nzeta, ntheta3, ars, order=(/ 1, 3, 4, 2 /) )
167 call add_real_4d("ara_out", ns, 2, nzeta, ntheta3, ara, order=(/ 1, 3, 4, 2 /) )
168 call add_real_4d("brs_out", ns, 2, nzeta, ntheta3, brs, order=(/ 1, 3, 4, 2 /) )
169 call add_real_4d("bra_out", ns, 2, nzeta, ntheta3, bra, order=(/ 1, 3, 4, 2 /) )
170
171 call add_real_4d("azs_out", ns, 2, nzeta, ntheta3, azs, order=(/ 1, 3, 4, 2 /) )
172 call add_real_4d("aza_out", ns, 2, nzeta, ntheta3, aza, order=(/ 1, 3, 4, 2 /) )
173 call add_real_4d("bzs_out", ns, 2, nzeta, ntheta3, bzs, order=(/ 1, 3, 4, 2 /) )
174 call add_real_4d("bza_out", ns, 2, nzeta, ntheta3, bza, order=(/ 1, 3, 4, 2 /) )
175
176 call add_real_4d("bls_out", ns, 2, nzeta, ntheta3, bls, order=(/ 1, 3, 4, 2 /) )
177 call add_real_4d("bla_out", ns, 2, nzeta, ntheta3, bla, order=(/ 1, 3, 4, 2 /) )
178
179 call add_real_4d("rcs_out", ns, 2, nzeta, ntheta3, rcs, order=(/ 1, 3, 4, 2 /) )
180 call add_real_4d("rca_out", ns, 2, nzeta, ntheta3, rca, order=(/ 1, 3, 4, 2 /) )
181 call add_real_4d("zcs_out", ns, 2, nzeta, ntheta3, zcs, order=(/ 1, 3, 4, 2 /) )
182 call add_real_4d("zca_out", ns, 2, nzeta, ntheta3, zca, order=(/ 1, 3, 4, 2 /) )
183
184 if (lthreed) then
185 call add_real_4d("crs_out", ns, 2, nzeta, ntheta3, crs, order=(/ 1, 3, 4, 2 /) )
186 call add_real_4d("cra_out", ns, 2, nzeta, ntheta3, cra, order=(/ 1, 3, 4, 2 /) )
187 call add_real_4d("czs_out", ns, 2, nzeta, ntheta3, czs, order=(/ 1, 3, 4, 2 /) )
188 call add_real_4d("cza_out", ns, 2, nzeta, ntheta3, cza, order=(/ 1, 3, 4, 2 /) )
189 call add_real_4d("cls_out", ns, 2, nzeta, ntheta3, cls, order=(/ 1, 3, 4, 2 /) )
190 call add_real_4d("cla_out", ns, 2, nzeta, ntheta3, cla, order=(/ 1, 3, 4, 2 /) )
191 else
192 call add_null("crs_out")
193 call add_null("cra_out")
194 call add_null("czs_out")
195 call add_null("cza_out")
196 call add_null("cls_out")
197 call add_null("cla_out")
198 end if
199
200 call close_dbg_out()
201 end if ! dump_symforce
202
203END SUBROUTINE symforce
logical function open_dbg_context(context_name, repetition, id)
check if any output is desired for the current iteration check if the given context should be openend...
Definition dbgout.f90:17
integer, dimension(:), allocatable ireflect
two-dimensional array for computing 2pi-v angle
logical lthreed
subroutine symforce(ars, brs, crs, azs, bzs, czs, bls, cls, rcs, zcs, ara, bra, cra, aza, bza, cza, bla, cla, rca, zca)
Symmetrize forces on restricted interval so cos, sin integrals can be performed.
Definition symforce.f90:30