1 subroutine p_j_iteration(equil_in, equil_out, first, a, cx, cy, psaxis, &
2 xaxis, yaxis, nax, rax, sax)
48 type(type_equilibrium
),
intent(inout) :: equil_in, equil_out
51 logical,
intent(inout) :: first
53 real(r8),
intent(inout) :: a
54 real(r8),
intent(inout) :: xaxis, yaxis
55 real(r8),
intent(inout) :: cx, cy
56 real(r8),
intent(inout) :: rax, sax
58 real(r8),
intent(out) :: psaxis
59 integer(itm_i4),
intent(out) :: nax
62 real(r8),
parameter :: fdf_eps = 1.e-7_r8
64 character(len = 2) :: file_no
65 real(r8),
dimension(nr) :: psi_hat
66 real(r8),
dimension(size(equil_in%profiles_1d%psi)) :: rho_sqr_in
67 real(r8),
dimension(size(equil_out%profiles_1d%psi)) :: rho_sqr_out
68 real(r8),
dimension(npts) :: psi_tmp
69 real(r8),
dimension(npts) :: fdf_old
70 real(r8),
dimension(3) :: abltg
74 integer(itm_i4) :: i, j
75 integer(itm_i4) :: meshno
76 logical :: converged_current
79 converged_current = .false.
83 if (trim(input_type) ==
"p and j_tor")
then
84 if (.not.
associated(equil_in%profiles_1d%pressure))
then
85 write(iu6, *)
'ERROR in p_j_iteration: pressure not provided ', &
89 if (.not.
associated(equil_in%profiles_1d%jphi))
then
90 write(iu6, *)
'ERROR in p_j_iteration: jphi not provided on input.'
94 if (trim(radial_coordinate) ==
"psi")
then
96 if (.not.
associated(equil_in%profiles_1d%psi))
then
97 write(iu6, *)
'ERROR in p_j_iteration: psi not provided ', &
102 else if (trim(radial_coordinate) ==
"rho_vol")
then
104 if (.not.
associated(equil_in%profiles_1d%rho_vol))
then
105 write(iu6, *)
'ERROR in p_j_iteration: rho_vol not provided ', &
111 rho_sqr_in = equil_in%profiles_1d%rho_vol**2
113 rho_sqr_in, equil_out%profiles_1d%psi, &
114 rho_sqr_out, spline_type = 1, monotonic = .true.)
115 equil_out%profiles_1d%rho_vol = rho_sqr_out**0.5
117 else if (trim(radial_coordinate) ==
"rho_tor")
then
119 if (.not.
associated(equil_in%profiles_1d%rho_tor))
then
120 write(iu6, *)
'ERROR in p_j_iteration: rho_tor not provided ', &
126 rho_sqr_in = equil_in%profiles_1d%rho_tor**2
128 rho_sqr_in, equil_out%profiles_1d%psi, &
129 rho_sqr_out, spline_type = 1, monotonic = .true.)
130 equil_out%profiles_1d%rho_tor = rho_sqr_out**0.5
135 else if (trim(input_type) ==
"p' and j_tor")
then
137 if (.not.
associated(equil_in%profiles_1d%pprime))
then
138 write(iu6, *)
'ERROR in p_j_iteration: pprime not provided ', &
142 if (.not.
associated(equil_in%profiles_1d%jphi))
then
143 write(iu6, *)
'ERROR in p_j_iteration: jphi not provided on input.'
148 equil_in%profiles_1d%pprime, equil_out%profiles_1d%psi, &
149 equil_out%profiles_1d%pprime, spline_type = 1)
152 equil_in%profiles_1d%jphi, equil_out%profiles_1d%psi, &
153 equil_out%profiles_1d%jphi, spline_type = 1)
159 if (verbosity > 3)
then
160 write(file_no,
'(i2.2)') i
163 if (verbosity > 1)
then
164 write(iu6, *)
'input_type ', input_type
165 write(iu6, *)
'radial_coordinate ', radial_coordinate
168 if (trim(input_type) ==
"p and j_tor")
then
169 if (trim(radial_coordinate) ==
"rho_vol")
then
173 rho_sqr_in = equil_in%profiles_1d%rho_vol**2
174 rho_sqr_out = equil_out%profiles_1d%rho_vol**2
176 equil_out%profiles_1d%psi, rho_sqr_in, &
177 psi_tmp, spline_type = 1, monotonic = .true.)
179 if (verbosity > 2)
then
180 write(iu6, *)
'old cpsurfin = ', &
181 equil_in%profiles_1d%psi(
size(equil_in%profiles_1d%psi))
182 write(iu6, *)
'new cpsurfin = ', psi_tmp(
size(psi_tmp))
185 else if (trim(radial_coordinate) ==
"rho_tor")
then
189 rho_sqr_in = (equil_in%profiles_1d%rho_tor &
190 / equil_in%profiles_1d%rho_tor(nr))**2
191 rho_sqr_out = (equil_out%profiles_1d%rho_tor &
192 / equil_out%profiles_1d%rho_tor(nr))**2
194 equil_out%profiles_1d%psi, rho_sqr_in, &
195 psi_tmp, spline_type = 1, monotonic = .true.)
197 if (verbosity > 2)
then
198 write(iu6, *)
'old cpsurfin = ', &
199 equil_in%profiles_1d%psi(
size(equil_in%profiles_1d%psi))
200 write(iu6, *)
'new cpsurfin = ', psi_tmp(
size(psi_tmp))
201 write(iu6, *)
'old rho_tor(nr) = ', &
202 equil_in%profiles_1d%rho_tor(
size(equil_in%profiles_1d%rho_tor))
203 write(iu6, *)
'new rho_tor(nr) = ', &
204 equil_out%profiles_1d%rho_tor(
size(equil_out%profiles_1d%rho_tor))
208 else if (trim(radial_coordinate) ==
"psi")
then
211 psi_tmp = (equil_in%profiles_1d%psi &
212 / equil_in%profiles_1d%psi(
size(equil_in%profiles_1d%psi))) &
213 * equil_out%profiles_1d%psi(
size(equil_out%profiles_1d%psi))
220 equil_out%profiles_1d%psi, equil_out%profiles_1d%pressure, &
221 equil_out%profiles_1d%pprime, spline_type = 3)
226 equil_in%profiles_1d%pprime, equil_out%profiles_1d%psi, &
227 equil_out%profiles_1d%pprime, spline_type = 3)
229 if (xmgrace_output .and. verbosity > 3)
then
231 equil_in%profiles_1d%pressure,
size(equil_in%profiles_1d%psi), &
232 'xmgr_p_in_' // file_no)
234 equil_out%profiles_1d%pressure,
size(equil_out%profiles_1d%psi), &
235 'xmgr_p_out_' // file_no)
237 equil_out%profiles_1d%pprime,
size(equil_out%profiles_1d%psi), &
238 'xmgr_pprime_out_' // file_no)
243 equil_in%profiles_1d%psi = psi_tmp
245 equil_out%profiles_1d%pressure, psi_tmp, &
246 equil_in%profiles_1d%pressure, equil_in%profiles_1d%pprime, &
252 equil_out%profiles_1d%psi, equil_out%profiles_1d%jphi, spline_type = 3)
262 psi_hat = equil_out%profiles_1d%psi / equil_out%profiles_1d%psi(nr)
263 call
spline(nr, psi_hat, equil_out%profiles_1d%pprime, 0._r8, &
267 if (verbosity > 3)
then
268 write(iu6, *)
'npts = ', npts,
' nr = ', nr
272 dpres(j) =
spwert(nr, psivec(j), dp_spline, psi_hat, abltg, 0)
279 call
spline(npts, psivec, dpres, 0._r8, 0._r8, 2, dp_spline)
280 p_int =
integrate(dp_spline, psivec, npts, .true.) &
281 * sign(1._r8, cpsurfin)
282 if (verbosity >= 2) &
283 write(iu6, *)
'new pressure on axis ', p_int(1)
287 if (trim(input_type) ==
"p' and j_tor" &
288 .or. trim(input_type) ==
"p and j_tor" &
289 .or. trim(input_type) ==
"p' and q")
then
303 diff_fdf = diff_fdf + abs(fdf(j) - fdf_old(j)) / (fdf_eps &
304 + abs(fdf(j) + fdf_old(j)) / 2._r8)
308 write(iu6, *)
"residual for FF' = ", diff_fdf
311 if (diff_fdf < errcur) converged_current = .true.
317 call
spline(npts, psivec, dgam, 0._r8, 0._r8, 2, gam_spline)
319 gam_int =
integrate(gam_spline, psivec, npts, .true.) &
320 * sign(1._r8, cpsurfin)
325 write(iu6, *)
'old B = ', b_ref
327 b = 2._r8 * eps * equil_out%profiles_1d%pprime(1) &
328 / (equil_out%profiles_1d%pprime(1) &
329 + equil_out%profiles_1d%ffprime(1) / (mu0 * rvac**2))
331 b = mu0 * rvac**2 * equil_out%profiles_1d%pprime(1) &
332 / equil_out%profiles_1d%ffprime(1)
335 write(iu6, *)
'new B = ', b
340 write(iu6, *)
'new pscale = ', pscale
341 dpres = dpres / pscale
342 p_int = p_int / pscale
343 dp_spline%sp1 = dp_spline%sp1 / pscale
344 dp_spline%sp2 = dp_spline%sp2 / pscale
345 dp_spline%sp3 = dp_spline%sp3 / pscale
346 dp_spline%sp4 = dp_spline%sp4 / pscale
350 converged_current = .true.
363 call
remesh(a, nr, np, meshno, cx, cy, xaxis, yaxis, nax, rax, sax)
371 if (trim(input_type) ==
"p and j_tor")
then
373 if (trim(radial_coordinate) ==
"rho_tor")
then
375 call
q_calculation(xaxis, cx, cy, a, equil_out%profiles_1d%q)
378 call
spline(nr, equil_out%profiles_1d%psi, equil_out%profiles_1d%q, &
379 0._r8, 0._r8, 3, coeff)
380 equil_out%profiles_1d%phi =
integrate(coeff, &
381 equil_out%profiles_1d%psi, nr, .false.)
384 equil_out%profiles_1d%rho_tor = sqrt(equil_out%profiles_1d%phi / pi &
385 / equil_out%global_param%toroid_field%b0)
391 write(iu6, *)
'current iteration ', i,
' completed'
403 write(iu6, *)
"FF' converged? :", converged_current
405 if (converged_current)
exit
subroutine adapt_alfa(a, xaxis, cx, cy, npts)
subroutine dp_fdf_iteration(first, a, psaxis, xaxis, yaxis, nax, rax, sax)
subroutine, public q_calculation(xaxis, cx, cy, a, q)
real(r8) function, dimension(n), public integrate(f_spline, x, n, inv)
subroutine allocate_spline_coefficients(spline, n)
subroutine, public fill_equilibrium(a, xaxis, yaxis, current_averaging, equilibrium)
subroutine remesh(a, nrnew, npnew, meshno, cx, cy, xaxis, yaxis, nax, rax, sax)
subroutine spline(N, X, Y, ALFA, BETA, TYP, A, B, C, D)
REAL *8 function spwert(N, XWERT, A, B, C, D, X, ABLTG)
subroutine update_fdf(equilibrium, xaxis)
subroutine plot_data_1d(type_plot, x, y, np, printname, z)
subroutine deallocate_spline_coefficients(spline)
subroutine transfer_1d_profile(x_in, f_in, x_out, f_out, df_out, spline_type, monotonic)
subroutine, public current_calculations_destructor
subroutine p_j_iteration(equil_in, equil_out, first, a, cx, cy, psaxis, xaxis, yaxis, nax, rax, sax)
real(r8) function pressure(flux)
subroutine, public current_calculations_constructor(nr, np)