VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
add_fluxes.f90
Go to the documentation of this file.
1
4
11SUBROUTINE add_fluxes(overg, bsupu, bsupv)
12 USE vmec_main
13 USE realspace, ONLY: wint, guu, guv, chip
14
15 use dbgout
16
17 IMPLICIT NONE
18
19 REAL(rprec), DIMENSION(nrzt), INTENT(in) :: overg
20 REAL(rprec), DIMENSION(nrzt), INTENT(inout) :: bsupu, bsupv
21
22 INTEGER :: js, l, ku, lk
23 REAL(rprec), dimension(3) :: topSum, botSum
24 REAL(rprec) :: top, bot
25
26 ! I think this is the "zero-current algorithm" published in section 2.3 of
27 ! Hirshman, Hogan, "ORMEC: A Three-Dimensional MHD Spectral Inverse Equilibrium Code" (1986), J. Comp. Phys. 63 (2), 329-352
28 ! https://doi.org/10.1016/0021-9991(86)90197-X
29
30 ! ADD MAGNETIC FLUX (CHIP, PHIP) TERMS TO BSUPU=-OVERG*LAM_V, BSUPV=OVERG*LAM_U
31 ! COMPUTE FLUX FROM ITOR = <B_u>, ITOR(s) = integrated toroidal current (icurv)
32 IF (ncurr .eq. 1) then
33 ! given current profile and lcurrent set --> compute fluxes, iota consistent with given current profile
34 DO js = 2, ns
35 ! solve Eqn. (11) of the ORMEC paper for each flux surface
36 top = icurv(js) ! offset: this makes the zero-current algorithm a constrained-current algorithm
37 bot = 0.0_dp
38 DO l = js, nrzt, ns
39 ! bsupu contains -d(lambda)/d( zeta)*lamscale+phipf on entry (?)
40 ! bsupv contains d(lambda)/d(theta)*lamscale on entry (?)
41 top = top - wint(l)*(guu(l)*bsupu(l) + guv(l)*bsupv(l))
42 bot = bot + wint(l)* guu(l)*overg(l)
43 END DO
44 IF (bot .ne. zero) then
45 chips(js) = top/bot
46 end if
47 IF (phips(js) .ne. zero) then
48 iotas(js) = chips(js)/phips(js)
49 end if
50 END DO ! js
51
52! stop
53 else ! ncurr .eq. 0
54 ! given iota profile: compute chips from iotas, phips
55 ! do not touch innermost/first entry in chips, which should not be used anyway
56 chips(2:ns) = iotas(2:ns)*phips(2:ns)
57 END IF
58
59 ! distribute chips (ns-sized array) into larger chip array (over full surface) (?)
60 DO js = 2, ns
61 chip(js:nrzt:ns) = chips(js)
62 END DO
63
64 ! half-grid to full-grid for chi-prime and iota below
65
66 chipf(2:ns1) = (chips(2:ns1) + chips(3:ns1+1))/2.0_dp
67 chipf(ns) = 2.0_dp*chips(ns)-chips(ns1)
68
69 ! Do not compute iota too near origin
70 iotaf(1) = c1p5*iotas(2) - cp5*iotas(3) !zero gradient near axis
71 iotaf(ns) = c1p5*iotas(ns) - cp5*iotas(ns-1)
72 DO js = 2, ns-1
73 iotaf(js) = cp5*(iotas(js) + iotas(js+1))
74 END DO
75
76 ! bsupu contains -dLambda/dZeta*lamscale and now needs to get chip/sqrt(g) added, as outlined in bcovar above the call to this routine.
77 bsupu(:nrzt) = bsupu(:nrzt) + chip(:nrzt)*overg(:nrzt)
78
79 if (open_dbg_context("add_fluxes", num_eqsolve_retries)) then
80
81 call add_real_1d("chips", ns-1, chips(2:ns)) ! half-grid
82 call add_real_1d("iotas", ns-1, iotas(2:ns)) ! half-grid
83 call add_real_1d("chipf", ns, chipf)
84 call add_real_1d("iotaf", ns, iotaf)
85
86 call add_real_3d("bsupu", ns, nzeta, ntheta3, bsupu)
87
88 call close_dbg_out()
89 end if
90
91END SUBROUTINE add_fluxes
subroutine add_fluxes(overg, bsupu, bsupv)
Add the magnetic fluxes to the tangential derivatives of to arrive at the contravariant magnetic fie...
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
real(rprec), dimension(:), allocatable wint
two-dimensional array for normalizing angle integrations
Definition realspace.f90:34
real(rprec), dimension(:), allocatable guv
metric element
Definition realspace.f90:21
real(rprec), dimension(:), allocatable chip
radial derivative of chi/(2*pi) on half-grid
Definition realspace.f90:30
real(rprec), dimension(:), allocatable guu
metric element
Definition realspace.f90:20
real(rprec), dimension(:), allocatable chips
poloidal flux (same as chip), one-dimensional array
Definition vmec_main.f90:67
real(rprec), dimension(:), allocatable iotaf
rotational transform (full grid)
Definition vmec_main.f90:34
real(rprec), dimension(:), allocatable chipf
radial derivative of poloidal magnetic flux (full grid)
Definition vmec_main.f90:36
integer num_eqsolve_retries
real(rprec), dimension(:), allocatable phips
toroidal flux (same as phip), one-dimensional array
Definition vmec_main.f90:68
real(rprec), dimension(:), allocatable iotas
rotational transform , on half radial mesh
Definition vmec_main.f90:69
real(rprec), dimension(:), allocatable icurv
(-)toroidal current inside flux surface (vanishes like s)
Definition vmec_main.f90:70