13 use deallocate_structures
21 type (type_equilibrium
) :: equilibrium
22 integer,
parameter :: nr=65, nz=129
23 integer :: npsi, ndim1, ndim2
24 integer :: idim1, idim2
26 real (R8),
allocatable :: psi_in(:,:), f_dia_in(:,:), w(:,:)
28 real (R8),
allocatable :: r(:), z(:), ans(:), tx(:), ty(:), c(:), &
29 wrk1(:), wrk2(:), wrk(:)
30 integer,
allocatable :: iwrk(:), jwrk(:)
32 real (R8) :: rmin, rmax, zmin, zmax, dr, dz, fp, s, r0, b0, psi_ax, psi_bnd, sign_psi
33 integer :: kx, ky, m,nxest, nyest, nmax, u, v, km, ne, bx, by, &
34 b1,
b2, lwrk1, lwrk2, lwrk, kwrk, mwrk, nx, ny, ier, i, j
37 npsi =
size(equilibrium%profiles_1d%psi, dim=1)
38 ndim1 =
size(equilibrium%coord_sys%position%R, dim=1)
39 ndim2 =
size(equilibrium%coord_sys%position%R, dim=2)
41 if(npsi.ne.ndim1)
then
42 write(*,*)
'NPSI <> NDIM1: ',npsi, ndim1
46 r0=equilibrium%global_param%toroid_field%r0
47 b0=equilibrium%global_param%toroid_field%b0
48 psi_ax=equilibrium%profiles_1d%psi(1)
49 psi_bnd=equilibrium%profiles_1d%psi(npsi)
50 sign_psi=sign(1.0_r8, psi_bnd-psi_ax)
52 allocate(psi_in(ndim1,ndim2), f_dia_in(ndim1,ndim2), w(ndim1,ndim2))
53 allocate(r(nr), z(nz))
56 psi_in(:,idim2) = equilibrium%profiles_1d%psi(:)
57 f_dia_in(:,idim2) = equilibrium%profiles_1d%f_dia(:)
62 rmin=minval(equilibrium%coord_sys%position%R)
63 rmax=maxval(equilibrium%coord_sys%position%R)
64 zmin=minval(equilibrium%coord_sys%position%Z)
65 zmax=maxval(equilibrium%coord_sys%position%Z)
89 nxest = max(2*(kx+1),kx+1+int(sqrt(m/2.0_r8)))
90 nyest = max(2*(ky+1),ky+1+int(sqrt(m/2.0_r8)))
91 nmax = max(nxest, nyest)
105 lwrk1 = u*v*(2+b1+
b2)+2*(u+v+km*(m+ne)+ne-kx-ky)+
b2+1
106 lwrk2 = u*v*(
b2+1)+
b2
107 kwrk = m+(nxest-2*kx-1)*(nyest-2*ky-1)
109 allocate(tx(nmax), ty(nmax), c((nxest-kx-1)*(nyest-ky-1)), &
110 wrk1(lwrk1), wrk2(lwrk2), iwrk(kwrk))
112 s = sqrt(
real(m,r8))/100
116 equilibrium%coord_sys%position%R, equilibrium%coord_sys%position%Z, psi_in, &
117 w, rmin, rmax, zmin, zmax, kx, ky, s, nxest, nyest, nmax, 1e-15_r8, &
118 nx, tx, ny, ty, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier)
120 write(*,*)
'surfit returned ier = ', ier
121 write(*,*)
'nx, ny, fp = ', nx, ny, fp
123 lwrk = nr*(kx+1)+nz*(ky+1)+(nx-1)*(ny-1)
126 allocate(wrk(lwrk), jwrk(mwrk), ans(nr*nz))
128 call
bispev(tx, nx, ty, ny, c, kx, ky, r, nr, z, nz, ans, wrk, lwrk, jwrk, mwrk, ier)
130 write(*,*)
'bispev returned ier = ', ier
132 if(
associated(equilibrium%profiles_2d)) call deallocate_cpo(equilibrium%profiles_2d)
133 allocate(equilibrium%profiles_2d(1))
135 allocate(equilibrium%profiles_2d(1)%psi(nr,nz))
138 equilibrium%profiles_2d(1)%psi(i,j) = ans(nz*(i-1)+j)
143 call
parder(tx, nx, ty, ny, c, kx, ky, 0, 1, r, nr, z, nz, ans, wrk, lwrk, jwrk, mwrk, ier)
145 write(*,*)
'parder returned ier = ', ier
147 allocate(equilibrium%profiles_2d(1)%br(nr,nz))
150 equilibrium%profiles_2d(1)%br(i,j) = -ans(nz*(i-1)+j)/r(i)/2.0_r8/itm_pi
155 call
parder(tx, nx, ty, ny, c, kx, ky, 1, 0, r, nr, z, nz, ans, wrk, lwrk, jwrk, mwrk, ier)
157 write(*,*)
'parder returned ier = ', ier
159 allocate(equilibrium%profiles_2d(1)%bz(nr,nz))
162 equilibrium%profiles_2d(1)%bz(i,j) = ans(nz*(i-1)+j)/r(i)/2.0_r8/itm_pi
166 s = sqrt(
real(m,r8))/10000
170 equilibrium%coord_sys%position%R, equilibrium%coord_sys%position%Z, f_dia_in, &
171 w, rmin, rmax, zmin, zmax, kx, ky, s, nxest, nyest, nmax, 1e-15_r8, &
172 nx, tx, ny, ty, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier)
174 write(*,*)
'surfit returned ier = ', ier
175 write(*,*)
'nx, ny, fp = ', nx, ny, fp
177 deallocate(wrk, jwrk, ans)
179 lwrk = nr*(kx+1)+nz*(ky+1)+(nx-1)*(ny-1)
182 allocate(wrk(lwrk), jwrk(mwrk), ans(nr*nz))
184 call
bispev(tx, nx, ty, ny, c, kx, ky, r, nr, z, nz, ans, wrk, lwrk, jwrk, mwrk, ier)
186 write(*,*)
'bispev returned ier = ', ier
188 allocate(equilibrium%profiles_2d(1)%bphi(nr,nz))
191 if(equilibrium%profiles_2d(1)%psi(i,j)*sign_psi .gt. psi_bnd*sign_psi)
then
192 equilibrium%profiles_2d(1)%bphi(i,j) = r0*b0/r(i)
194 equilibrium%profiles_2d(1)%bphi(i,j) = ans(nz*(i-1)+j)/r(i)
199 allocate(equilibrium%profiles_2d(1)%grid_type(4))
200 allocate(equilibrium%profiles_2d(1)%grid%dim1(nr))
201 allocate(equilibrium%profiles_2d(1)%grid%dim2(nz))
202 equilibrium%profiles_2d(1)%grid_type(1)=
'1'
203 equilibrium%profiles_2d(1)%grid_type(2)=
'rectangular'
204 equilibrium%profiles_2d(1)%grid_type(3)=
'0'
205 equilibrium%profiles_2d(1)%grid_type(4)=
'not relevant'
206 equilibrium%profiles_2d(1)%grid%dim1=r
207 equilibrium%profiles_2d(1)%grid%dim2=z
subroutine bispev(tx, nx, ty, ny, c, kx, ky, x, mx, y, my, z, wrk, lwrk, iwrk, kwrk, ier)
subroutine augment_psi_rz(equilibrium)
real(r8) function b2(a, x, xr, xs, yr, ys, psi, psir, F_dia)
Augment an inverse equilibrium with psi, Br, Bz and Bphi as a function of R and Z.
subroutine surfit(iopt, m, x, y, z, w, xb, xe, yb, ye, kx, ky, s, nxest, nyest, nmax, eps, nx, tx, ny, ty, c, fp, wrk1, lwrk1, wrk2, lwrk2, iwrk, kwrk, ier)
subroutine parder(tx, nx, ty, ny, c, kx, ky, nux, nuy, x, mx, y, my, z, wrk, lwrk, iwrk, kwrk, ier)