VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
becoil.f90
Go to the documentation of this file.
1
4
13SUBROUTINE becoil(rad, zee, brvac, bpvac, bzvac)
14
15 ! USE vparams, ONLY: nthreed
16 USE vacmod
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
124END SUBROUTINE 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
real(rprec) delzb
Definition mgrid_mod.f:84
integer nr0b
Definition mgrid_mod.f:77
real(rprec) zminb
Definition mgrid_mod.f:84
real(rprec) zmaxb
Definition mgrid_mod.f:84
real(rprec) rminb
Definition mgrid_mod.f:84
real(rprec) rmaxb
Definition mgrid_mod.f:84
integer nz0b
Definition mgrid_mod.f:77
real(rprec) delrb
Definition mgrid_mod.f:84
integer np0b
Definition mgrid_mod.f:77
real(rprec), dimension(:), allocatable bphi
Definition vacmod.f90:95
real(rprec), dimension(:), allocatable bz
Definition vacmod.f90:96
real(rprec), dimension(:), allocatable brad
Definition vacmod.f90:94