VMEC
8.52
3D Equilibrium solver with nested flux surfaces.
Toggle main menu visibility
Loading...
Searching...
No Matches
becoil.f90
Go to the documentation of this file.
1
!> \file
2
!> \brief Compute the cylindrical components of the magnetic field due to external coils
3
!> by bi-linear interpolation of the \c mgrid file.
4
5
!> \brief Compute the cylindrical components of the magnetic field due to external coils.
6
!> by bi-linear interpolation of the \c mgrid file.
7
!>
8
!> @param rad \f$R\f$ at which to evaluate the external magnetic field
9
!> @param zee \f$Z\f$ at which to evaluate the external magnetic field
10
!> @param brvac cylindrical component of external magnetic field \f$B^R\f$
11
!> @param bpvac cylindrical component of external magnetic field \f$B^\varphi\f$
12
!> @param bzvac cylindrical component of external magnetic field \f$B^Z\f$
13
SUBROUTINE
becoil
(rad, zee, brvac, bpvac, bzvac)
14
15
! USE vparams, ONLY: nthreed
16
USE
vacmod
17
USE
mgrid_mod
,
ONLY
:
nr0b
,
np0b
,
nz0b
,
rminb
,
zminb
,
rmaxb
,
zmaxb
,
delrb
,
delzb
18
19
use
json
20
21
IMPLICIT NONE
22
23
REAL
(rprec),
DIMENSION(nuv2)
,
INTENT(in)
:: rad, zee
24
REAL
(rprec),
DIMENSION(nr0b,nz0b,np0b)
,
INTENT(in)
:: brvac, bpvac, bzvac
25
26
CHARACTER(LEN=50)
,
PARAMETER
:: warning =
'Plasma Boundary exceeded Vacuum Grid Size'
27
28
INTEGER
,
SAVE
:: icount = 0
29
INTEGER
:: i, kv, ir, jz, ir1, jz1
30
REAL
(rprec) :: rad0, zee0, ri, zj, pr, qz, w22, w21, w12, w11
31
32
! DETERMINE THE CYLINDRICAL COMPONENTS OF THE EXTERNAL
33
! MAGNETIC FIELD (BR, BP, BZ) AT A FIXED PHI PLANE BY
34
! USING 2-D INTERPOLATION BASED ON THE FOUR POINT FORMULA
35
! IN ABRAMOWITZ AND STEGUN, EQ. 25.2.66
36
!
37
! BRVAC, BPVAC, BZVAC: CYLINDRICAL COMPONENTS OF VACUUM B-FIELD
38
! STORED ON R, Z, PHI GRID
39
!
40
! RAD, ZEE: ARRAY OF R, Z VALUES (ON FLUX SURFACE)
41
! AT WHICH B-FIELD IS TO BE DETERMINED
42
43
! if (icount .eq. 0) then
44
! ! dump MGRID contents to text file for comparison with re-created file
45
!
46
! call open_dbg_out("mgrid.json")
47
!
48
! call add_int("nr0b", nr0b)
49
! call add_int("nz0b", nz0b)
50
! call add_int("np0b", np0b)
51
!
52
! call add_real_3d("brvac", nr0b, nz0b, np0b, brvac)
53
! call add_real_3d("bpvac", nr0b, nz0b, np0b, bpvac)
54
! call add_real_3d("bzvac", nr0b, nz0b, np0b, bzvac)
55
!
56
! call close_dbg_out()
57
! end if
58
59
icount = icount + 1
60
61
DO
i = 1, nuv2
62
63
! CHECK THAT BOUNDARY POINTS ARE INSIDE VACUUM GRID.
64
! IF NOT, SET THEM EQUAL TO LARGEST (OR SMALLEST) VACUUM GRID POINTS
65
rad0 = min(rad(i),
rmaxb
)
66
rad0 = max(rad0,
rminb
)
67
zee0 = min(zee(i),
zmaxb
)
68
zee0 = max(zee0,
zminb
)
69
70
! DETERMINE PHI-PLANE, KV (MUST LIE IN FIRST FIELD PERIOD)
71
kv = 1 + mod(i - 1,nv)
72
73
! Axi-symmetric special case
74
kv = min(kv,
np0b
)
75
76
! DETERMINE INTEGER INDICES (IR,JZ) FOR LOWER LEFT R, Z CORNER GRID POINT
77
ir = int((rad0 -
rminb
)/
delrb
) + 1
78
jz = int((zee0 -
zminb
)/
delzb
) + 1
79
ir1 = min(
nr0b
,ir + 1)
80
jz1 = min(
nz0b
,jz + 1)
81
82
! COMPUTE RI, ZJ AND PR , QZ AT GRID POINT (IR , JZ)
83
! ALSO, COMPUTE WEIGHTS WIJ FOR 4 CORNER GRID POINTS
84
ri =
rminb
+ (ir - 1)*
delrb
85
zj =
zminb
+ (jz - 1)*
delzb
86
pr = (rad0 - ri)/
delrb
87
qz = (zee0 - zj)/
delzb
88
w22 = pr*qz
! p * q
89
w21 = pr - w22
! p *(1-q)
90
w12 = qz - w22
! (1-p)* q
91
w11 = 1 + w22 - (pr + qz)
! (1-p)*(1-q)
92
93
! COMPUTE B FIELD AT R, PHI, Z BY INTERPOLATION
94
brad
(i) = w11*brvac(ir,jz,kv) + w22*brvac(ir1,jz1,kv) + w21*brvac(ir1,jz,kv) + w12*brvac(ir,jz1,kv)
95
bphi
(i) = w11*bpvac(ir,jz,kv) + w22*bpvac(ir1,jz1,kv) + w21*bpvac(ir1,jz,kv) + w12*bpvac(ir,jz1,kv)
96
bz
(i) = w11*bzvac(ir,jz,kv) + w22*bzvac(ir1,jz1,kv) + w21*bzvac(ir1,jz,kv) + w12*bzvac(ir,jz1,kv)
97
98
END DO
99
100
IF
(mod(icount,25).eq.0)
THEN
101
! PRINT INFO IF R, Z OUT OF BOX
102
i = 0
103
rad0 = maxval(rad)
104
zee0 = maxval(zee)
105
IF
(rad0 .gt.
rmaxb
) i = 1
106
IF
(zee0 .gt.
zmaxb
) i = i + 2
107
ri = minval(rad)
108
zj = minval(zee)
109
IF
(ri .lt.
rminb
) i = i + 4
110
IF
(zj .lt.
zminb
) i = i + 8
111
IF
(i .ne. 0)
THEN
112
print *, warning
113
! WRITE (nthreed, *) warning
114
IF
(i/8 .ne. 0) print *,
' zmin = '
, zj
115
i = mod(i,8)
116
IF
(i/4 .ne. 0) print *,
' rmin = '
, ri
117
i = mod(i,4)
118
IF
(i/2 .ne. 0) print *,
' zmax = '
, zee0
119
i = mod(i,2)
120
IF
(i .ne. 0) print *,
' rmax = '
, rad0
121
END IF
122
ENDIF
123
124
END SUBROUTINE
becoil
becoil
subroutine becoil(rad, zee, brvac, bpvac, bzvac)
Compute the cylindrical components of the magnetic field due to external coils. by bi-linear interpol...
Definition
becoil.f90:14
mgrid_mod
Definition
mgrid_mod.f:1
mgrid_mod::delzb
real(rprec) delzb
Definition
mgrid_mod.f:84
mgrid_mod::nr0b
integer nr0b
Definition
mgrid_mod.f:77
mgrid_mod::zminb
real(rprec) zminb
Definition
mgrid_mod.f:84
mgrid_mod::zmaxb
real(rprec) zmaxb
Definition
mgrid_mod.f:84
mgrid_mod::rminb
real(rprec) rminb
Definition
mgrid_mod.f:84
mgrid_mod::rmaxb
real(rprec) rmaxb
Definition
mgrid_mod.f:84
mgrid_mod::nz0b
integer nz0b
Definition
mgrid_mod.f:77
mgrid_mod::delrb
real(rprec) delrb
Definition
mgrid_mod.f:84
mgrid_mod::np0b
integer np0b
Definition
mgrid_mod.f:77
vacmod
Definition
vacmod.f90:2
vacmod::bphi
real(rprec), dimension(:), allocatable bphi
Definition
vacmod.f90:95
vacmod::bz
real(rprec), dimension(:), allocatable bz
Definition
vacmod.f90:96
vacmod::brad
real(rprec), dimension(:), allocatable brad
Definition
vacmod.f90:94
src
NESTOR
becoil.f90
Generated on
for VMEC by
1.17.0