VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
jacobian.f90
Go to the documentation of this file.
1
3
6SUBROUTINE jacobian
8 USE vmec_params, ONLY: meven, modd
10 USE realspace
11 USE vmec_dim, ONLY: ns, ntheta3
12 USE vforces, r12 => armn_o, ru12 => azmn_e, zu12 => armn_e, &
13 rs => bzmn_e, zs => brmn_e, tau => azmn_o
14
15 use dbgout
16
17 IMPLICIT NONE
18
19 REAL(rprec), PARAMETER :: zero=0.0_dp, p5=0.5_dp, p25=p5*p5
20
21 INTEGER :: l, js, ku, lk
22 REAL(rprec) :: taumax, taumin, dshalfds=p25, temp(nrzt/ns) ! TODO: nrzt/ns == nznt?
23
24 ! (RS, ZS)=(R, Z) SUB S, (RU12, ZU12)=(R, Z) SUB THETA(=U)
25 ! AND TAU=SQRT(G)/R ARE DIFFERENCED ON HALF MESH
26 !
27 ! SQRT(G) = R*TAU IS COMPUTED IN BCOVAR
28 !
29 ! HERE, TAU = (Ru * Zs - Rs * Zu).
30
31 ! THE DERIVATIVES OF SHALF = SQRT(s) WERE COMPUTED EXPLICITLY AS: d(shalf)/ds = .5/shalf
32 ! This can be understood by noting shalf(i) = sqrt(s_{i-1/2}),
33 ! leading to d/ds sqrt(s_{i-1/2}) = 1/2 * (s_{i-1/2})^{-1/2} = 0.5 / shalf.
34
35 ! initially, all good
36 first = 1
37
38 ! try to fix weird leftover stuff in first entry
39 r12(1) = 0.0_dp
40 ru12(1) = 0.0_dp
41 zu12(1) = 0.0_dp
42 rs(1) = 0.0_dp
43 zs(1) = 0.0_dp
44
45 DO l = 2,nrzt
46 r12(l) = p5*( r1(l,meven) + r1(l-1,meven) + shalf(l)*( r1(l,modd) + r1(l-1,modd)) ) ! R on half grid
47
48 ru12(l) = p5*( ru(l,meven) + ru(l-1,meven) + shalf(l)*( ru(l,modd) + ru(l-1,modd)) ) ! dR/du on half grid
49 zu12(l) = p5*( zu(l,meven) + zu(l-1,meven) + shalf(l)*( zu(l,modd) + zu(l-1,modd)) ) ! dZ/du on half grid
50
51 rs(l) = ohs*( r1(l,meven) - r1(l-1,meven) + shalf(l)*( r1(l,modd) - r1(l-1,modd)) ) ! dR/ds on half grid
52 zs(l) = ohs*( z1(l,meven) - z1(l-1,meven) + shalf(l)*( z1(l,modd) - z1(l-1,modd)) ) ! dZ/ds on half grid
53
54 ! TODO: the lower four lines of below expression could be split off into some separate variables...
55 tau(l) = ru12(l)*zs(l) - rs(l)*zu12(l) + dshalfds* &
56 ( ru(l,modd) *z1(l,modd) + ru(l-1,modd) *z1(l-1,modd) &
57 - zu(l,modd) *r1(l,modd) - zu(l-1,modd) *r1(l-1,modd) &
58 + ( ru(l,meven)*z1(l,modd) + ru(l-1,meven)*z1(l-1,modd) &
59 - zu(l,meven)*r1(l,modd) - zu(l-1,meven)*r1(l-1,modd) )/shalf(l) )
60 END DO
61
62 ! extrapolate as constant to axis
63 temp(:) = tau(2:nrzt:ns)
64 tau(1:nrzt:ns) = temp(:)
65
66! TEST FOR SIGN CHANGE IN JACOBIAN
67 taumax = maxval(tau(2:nrzt))
68 taumin = minval(tau(2:nrzt))
69 IF (taumax*taumin .lt. zero) then
70 ! bad jacobian !
71 first = 2
72 end if
73
74 ! check output from jacobian()
75 if (open_dbg_context("jacobian", num_eqsolve_retries)) then
76
77 call add_real_3d("r12", ns, nzeta, ntheta3, r12 )
78 call add_real_3d("ru12", ns, nzeta, ntheta3, ru12)
79 call add_real_3d("zu12", ns, nzeta, ntheta3, zu12)
80 call add_real_3d("rs", ns, nzeta, ntheta3, rs )
81 call add_real_3d("zs", ns, nzeta, ntheta3, zs )
82 call add_real_3d("tau", ns, nzeta, ntheta3, tau )
83
84 call add_real("taumax", taumax)
85 call add_real("taumin", taumin)
86 call add_int("irst", first)
87
88 call close_dbg_out()
89 end if
90
91END SUBROUTINE jacobian
subroutine jacobian
Evaulate the Jacobian of the transform from flux- to cylindrical coordinates.
Definition jacobian.f90:7
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 ru
Definition realspace.f90:9
real(rprec), dimension(:), allocatable shalf
sqrt(s) ,two-dimensional array on half-grid
Definition realspace.f90:31
real(rprec), dimension(:,:), allocatable, target z1
Definition realspace.f90:11
real(rprec), dimension(:,:), allocatable r1
Definition realspace.f90:8
real(rprec), dimension(:,:), allocatable zu
Definition realspace.f90:12
real(rprec), dimension(:), pointer azmn_o
Definition vforces.f90:27
real(rprec), dimension(:), pointer bzmn_e
Definition vforces.f90:28
real(rprec), dimension(:), pointer brmn_e
Definition vforces.f90:21
real(rprec), dimension(:), pointer azmn_e
Definition vforces.f90:26
real(rprec), dimension(:), pointer armn_o
Definition vforces.f90:20
real(rprec), dimension(:), pointer armn_e
Definition vforces.f90:19
integer ntheta3
effective number of poloidal grid points
Definition vmec_dim.f90:11
integer ns
number of flux surfaces
Definition vmec_dim.f90:17
integer nrzt
Definition vmec_dim.f90:13
logical dump_jacobian
character(len=100) input_extension
integer nzeta
real(rprec) ohs
Definition vmec_main.f90:87
integer first
"counter" monitoring sign of jacobian; resets R, Z, and Lambda when jacobian changes sign and decreas...
integer num_eqsolve_retries
integer iter2
total number of iterations
integer, parameter modd
parity selection label for odd poloidal modes of R and Z
integer, parameter meven
parity selection label for even poloidal modes of R and Z