5 real (r8),
pointer :: RR(:,:), ZZ(:,:), PSI(:,:)
6 real (r8) :: R_min, R_max, Z_min, Z_max
13 real (r8),
allocatable :: fr(:), R_bnd(:), Z_bnd(:)
14 real (r8) :: Bgeo, Rgeo, Zgeo, amin, eps, ellip, tria_u, tria_l, quad_u, quad_l
15 real (r8) :: Reast, Rwest
22 real (r8),
allocatable :: dp_dpsi(:),fdf_dpsi(:),p_psi(:),f_psi(:),zjz_psi(:),q(:)
29 integer :: n_elms, n_nodes
30 integer,
allocatable :: elm_list(:,:), index_list(:), index_inverse(:)
33 real (r8) :: H(4,4,4,4), HS(4,4,4,4), HR(4,4,4,4)
34 real (r8) :: HRS(4,4,4,4), HRR(4,4,4,4), HSS(4,4,4,4)
40 integer :: lda, n_matrix, n_diag
41 real (r8),
allocatable :: AA(:,:), BB(:)
47 real (r8) :: R_axis, Z_axis, ps_axis, r_ax, s_ax
48 real (r8) :: q_axis, B_axis, CRR_axis, CZZ_axis
55 integer :: n_psi_map, n_chi_map
56 real (r8),
allocatable :: gem11(:,:), gem12(:,:), gem22(:,:), gem33(:,:)
57 real (r8),
allocatable :: q_map(:), dq_map(:), p_map(:), dp_map(:), f_map(:), df_map(:)
58 real (r8),
allocatable :: RR_map(:,:),ZZ_map(:,:)
64 integer :: n_pieces_max
65 parameter(n_pieces_max = 1000)
69 integer :: elm(n_pieces_max)
70 real (r8) :: r(4,n_pieces_max), s(4,n_pieces_max)
74 real (r8) ,
allocatable :: psi_values(:)
82 real (r8) :: beta_p, beta_t, beta_n, current, volume, area
88 real (r8) :: xgauss(4),wgauss(4)
89 data xgauss /-0.861136311594053, -0.339981043584856, 0.339981043584856, 0.861136311594053 /
90 data wgauss / 0.347854845137454, 0.652145154862546, 0.652145154862546, 0.347854845137454 /
96 real (r8) :: PI, MU_zero
97 parameter( pi = 3.14159265358979323846264338327950288419716939937510 )
98 parameter( mu_zero = pi * 4.d-7)
109 real (r8) ::
fdfdpsi, psi_n, dpsi
112 dpsi = 1. /float(n_prof - 1)
114 n_int = max(int((n_prof-1)*psi_n) + 1,1)
115 n_int = min(n_int,n_prof-1)
117 fdfdpsi = ( fdf_dpsi(n_int) + (psi_n - dpsi * (n_int-1))/dpsi * (fdf_dpsi(n_int+1)-fdf_dpsi(n_int)) )
126 real (r8) ::
dpdpsi, psi_n, dpsi, tmp
129 dpsi = 1. /float(n_prof - 1)
131 n_int = max(int((n_prof-1)*psi_n) + 1,1)
132 n_int = min(n_int,n_prof-1)
145 real (r8) :: f2int, f0,
fdia, psi_n, dpsi
148 if (psi_n .lt. 0.)
write(*,*)
' FDIA : ',psi_n
150 dpsi = 1. /float(n_prof - 1)
152 n_int = max(int((n_prof-1)*psi_n) + 1,1)
153 n_int = min(n_int,n_prof-1)
155 f2int = ( f_psi(n_int) + (psi_n - dpsi * (n_int-1))/dpsi * (f_psi(n_int+1)-f_psi(n_int)) )
159 fdia = sqrt( abs(f0*f0 + 2. * f2int) )
172 dpsi = 1. /float(n_prof - 1)
174 n_int = max(int((n_prof-1)*psi_n) + 1,1)
175 n_int = min(n_int,n_prof-1)
177 pressure = ( p_psi(n_int) + (psi_n - dpsi * (n_int-1))/dpsi * (p_psi(n_int+1)-p_psi(n_int)) )
189 dpsi = 1. /float(n_prof - 1)
191 n_int = max(int((n_prof-1)*psi_n) + 1,1)
192 n_int = min(n_int,n_prof-1)
194 current_profile = zjz_psi(n_int) + (psi_n - dpsi * (n_int-1))/dpsi * (zjz_psi(n_int+1)-zjz_psi(n_int))
201 rgeo_in,zgeo_in, amin_in, &
202 ellip_in,tria_u_in,tria_l_in,quad_u_in,quad_l_in, &
204 psi_in, pprime_in, ffprime_in, &
205 pressure_in, fdia_in, current_in, n_prof_in, iopt_p, iopt_f, &
207 psi_out, pprime_out, ffprime_out, &
208 pressure_out, fdia_out, current_out, qprof_out, vprime, &
209 fraction_circ, moments, n_moments, &
210 surface_powers, surface_integrals, n_var_surfaces, n_int_surfaces, &
211 volume_powers, volume_integrals, n_var_volumes, n_int_volumes, n_psi_out, n_tht_out, &
212 amin_out, rgeo_out, zgeo_out, &
213 area_out, volume_out, betap_out, xip_out, xli_out, beta_out, &
214 r_axis_out, z_axis_out, b_axis_out, psi_axis_out, psi_bnd_out, &
215 rrflux,zzflux,psflux)
254 integer :: n_int_surfaces, n_int_volumes, n_var_surfaces, n_var_volumes, n_moments, n_psi_out, n_tht_out, ioption
255 real (r8) :: rrflux(4,*),zzflux(4,*),psflux(4,*)
256 real (r8) :: r_bnd_in(*),z_bnd_in(*),pressure_in(*),fdia_in(*),current_in(*),psi_in(*), pprime_in(*), ffprime_in(*)
257 real (r8) :: bgeo_in,rgeo_in,zgeo_in,amin_in,ellip_in,tria_u_in,tria_l_in,quad_u_in,quad_l_in
258 integer :: n_bnd_in, n_prof_in, nr_grid, np_grid, iopt_p, iopt_f
259 real (r8) :: surface_powers(n_var_surfaces,n_int_surfaces),surface_integrals(n_psi_out,n_int_surfaces)
260 real (r8) :: volume_powers(n_var_volumes,n_int_volumes), volume_integrals(n_psi_out,n_int_volumes)
261 real (r8) :: psi_n, psi_out(*), pressure_out(*), fdia_out(*), current_out(*), pprime_out(*), ffprime_out(*)
262 real (r8) :: qprof_out(*), vprime(*), fraction_circ(*),moments(n_moments,*)
263 integer :: i, j, index, n_iter, ifail, inode, n_chi, ileft, iright
264 real (r8) :: s, error_iteration, error_large, error_current, small, ss, psi_plot
265 real (r8) :: fdf_error, t1, t2, amix, fmix, ymin, ymax
266 logical :: solve_only, rhs_only
268 real (r8) :: amin_out, rgeo_out, zgeo_out, area_out, volume_out, betap_out, xip_out, xli_out, beta_out
269 real (r8) :: r_axis_out, z_axis_out, b_axis_out, psi_axis_out, psi_bnd_out
270 real (r8),
allocatable :: rho_out(:), xplot(:), qplot(:),
pplot(:)
276 write(*,*)
'**********************************************'
277 write(*,*)
'* HELENA 2.0 (alpha_21) *'
278 write(*,*)
'**********************************************'
280 write(*,*)
' nr, np : ',nr_grid,np_grid
281 write(*,*)
' n_var_surfaces,n_int_surfaces : ',n_var_surfaces,n_int_surfaces
282 write(*,*)
' n_var_volumes, n_int_volumes : ',n_var_volumes, n_int_volumes
283 write(*,*)
' n_psi, n_tht : ',n_psi_out,n_tht_out
287 np = 2*int((np_grid+1)/2)
290 error_iteration = 1.d-6
292 error_current = 1.d-4
296 write(*,*)
' Bgeo : ',bgeo
299 allocate(r_bnd(n_bnd),z_bnd(n_bnd))
300 r_bnd(1:n_bnd) = r_bnd_in(1:n_bnd)
301 z_bnd(1:n_bnd) = z_bnd_in(1:n_bnd)
308 call
initialise_profiles(n_prof_in,iopt_p,iopt_f,psi_in, pprime_in, ffprime_in,pressure_in, fdia_in, current_in)
320 if (iopt_f .eq. 3)
then
324 call
gs_solve(n_iter,rhs_only,solve_only,error_large,amix,ifail)
326 if (ifail .ne. 0 )
then
327 amix = (1.e0_r8 + amix) /2.e0_r8
328 write(*,
'(A,f8.3)')
' increasing amix : ',amix
333 write(*,
'(A,e14.6)')
' fdf_error : ',fdf_error
334 if (fdf_error .lt. error_current)
exit
344 call
gs_solve(n_iter,rhs_only,solve_only,error_iteration,amix,ifail)
351 n_psi = n_psi_out - 1
353 if (
allocated(psi_values))
deallocate(psi_values)
354 if (
allocated(flux_surfaces))
deallocate(flux_surfaces)
356 allocate(psi_values(n_psi))
359 write(*,*)
'main : i ss psi_values'
361 ss = float(i)/float(n_psi)
362 psi_values(i) = ps_axis - (1.e0_r8 - small) * ss*ss * ps_axis
363 write(*,
'(A,i4,2e14.6)')
' main : ',i,ss,psi_values(i)
376 write(*,*)
'profiles out : i psi_n psi_out fdia_out'
380 psi_out(i) = - ps_axis + psi_in(n_prof_in)
382 psi_n = -(psi_values(i-1) - ps_axis) / ps_axis
383 psi_out(i) = - psi_values(i-1) + psi_in(n_prof_in)
385 pprime_out(i) =
dpdpsi(psi_n)
386 ffprime_out(i) =
fdfdpsi(psi_n)
388 fdia_out(i) =
fdia(psi_n)
391 write(*,
'(A,i4,8e14.6)')
'profiles out : ',i,psi_n,psi_out(i),fdia_out(i)
399 surface_powers,n_int_surfaces,n_var_surfaces,surface_integrals, &
403 qprof_out(i) = fdia_out(i) * qprof_out(i) / (2.e0_r8*pi)
406 write(*,*)
' fluxsurface integrals (2) : ',n_int_surfaces
408 write(*,
'(i5,15e12.4)') i,surface_integrals(i,1:n_int_surfaces),qprof_out(i),vprime(i)
414 volume_powers,volume_integrals,n_var_volumes,n_int_volumes,n_psi+1)
416 allocate(rho_out(n_psi_out))
418 write(*,*)
'i psi_out rho_out volume_integrals(1:3) qprof_out qtmp abs(qtmp-qprof_out)/qprof_out fdia_out'
421 rho_out(i) = sqrt(volume_integrals(i,2)/ (2.e0_r8*pi) / (pi * bgeo_in))
424 if ( (i .gt. 1) .and. (i .lt. n_psi_out))
then
425 qtmp = -(volume_integrals(i+1,2) - volume_integrals(i-1,2)) / (4.*pi*pi) / (psi_out(i+1)-psi_out(i-1))
428 write(*,
'(i5,20f12.6)') i,psi_out(i),rho_out(i),volume_integrals(i,1:3),qprof_out(i),qtmp,abs(qtmp-qprof_out(i))/qprof_out(i),&
437 fraction_circ(1) = 1.e0_r8
448 psi_axis_out = ps_axis
449 psi_bnd_out = psi_out(n_psi_out)
455 allocate(xplot(2*n_psi_out),
pplot(2*n_psi_out),qplot(2*n_psi_out))
458 ileft = (i-1)*n_tht_out + n_tht_out /2.e0_r8 + 1
459 iright = (i-1)*n_tht_out + 1
460 xplot(n_psi_out+i) = rrflux(1,ileft)
461 xplot(n_psi_out-i+1) = rrflux(1,iright)
462 pplot(n_psi_out+i) = pressure_out(i)
463 pplot(n_psi_out-i+1) = pressure_out(i)
464 qplot(n_psi_out+i) = qprof_out(i)
465 qplot(n_psi_out-i+1) = qprof_out(i)
469 call
lplot(3,2,1,xplot,
pplot,2*n_psi_out,1,
'pressure [Pa]',13,
'R [m]',5,
' ',1)
472 call lblbot(
'HELENA_2(alpha)',15)
476 deallocate(aa,bb,fr,
dp_dpsi,fdf_dpsi,p_psi,f_psi)
477 deallocate(elm_list, index_list, index_inverse)
478 deallocate(rr, zz, psi)
480 deallocate(flux_surfaces,r_bnd,z_bnd,psi_values,zjz_psi)
499 real (r8) :: rr(4,*),zz(4,*),psi(4,*)
500 real (r8),
allocatable :: cchi(:,:), schi(:,:), xchi(:,:), ychi(:,:), chikn(:)
501 real (r8),
allocatable :: s_values(:)
502 integer,
allocatable :: ijchi(:,:)
505 real (r8) :: sumq, sumqr, zsumq, zsumqr, psi_n, psir, psirr, ejac, er, bigr
506 real (r8) :: s, maxerr, x, xr, xs, xrs, xrr, xss, y, yr, ys, yrs, yrr, yss
507 real (r8) :: dum, dum1, dum2, dum3, dum4, qq, dqq, rb, drb
508 real (r8) :: dchi, chir, chis, chirs, chirr, psix, psiy, chix, chiy, zchi
509 real (r8) :: errj, serr, cerr, chiss, ejac2, a0, a1, a2, a3, s1, s2, s3
510 integer :: n_tht, n_chi, i,j,k, i_elm, node1, node2, node3, node4, no, nom, nop
511 integer :: jbase, n1, n2, n3, n4, ierr, jerr, ifail
513 real (r8) :: psi_tmp,psir_tmp,psis_tmp,psirs_tmp,psirr_tmp,psiss_tmp
515 write(*,*)
'********************************'
516 write(*,*)
'* helena mapping *'
517 write(*,*)
'********************************'
518 write(*,*)
' n_tht, n_chi : ',n_tht, n_chi
524 allocate(s_values(n_psi+1),cchi(4,(n_psi+1)*n_tht),schi((n_psi+1),n_chi),xchi((n_psi+1),n_chi),ychi((n_psi+1),n_chi))
525 allocate(chikn(n_chi),ijchi((n_psi+1),n_chi))
526 allocate(q_map(n_psi+1),dq_map(n_psi+1))
529 s_values(i) = float(i)/float(n_psi)
539 psi_n = s_values(i-1)**2
541 psir = - ps_axis * 2.e0_r8*s_values(i-1) / (2.e0_r8*
REAL(n_psi))
542 psirr = - ps_axis * 2.e0_r8 / (2.e0_r8*
REAL(n_psi))**2
546 node1 = (i-2)*n_tht + j
548 node3 = node2 + n_tht
549 node4 = node1 + n_tht
551 write(*,
'(A,i5,4e16.8)')
' node 1 : ',node1,psi(:,node1)
552 write(*,
'(A,i5,4e16.8)')
' node 2 : ',node2,psi(:,node2)
553 write(*,
'(A,i5,4e16.8)')
' node 3 : ',node3,psi(:,node3)
554 write(*,
'(A,i5,4e16.8)')
' node 4 : ',node4,psi(:,node4)
560 CALL
interp(rr(1,node1),rr(1,node2),rr(1,node3),rr(1,node4),+1.e0_r8,s, x,xr,xs,xrs,xrr,xss)
561 CALL
interp(zz(1,node1),zz(1,node2),zz(1,node3),zz(1,node4),+1.e0_r8,s, y,yr,ys,yrs,yrr,yss)
563 CALL
interp(psi(1,node1),psi(1,node2),psi(1,node3),psi(1,node4),1.e0_r8,s,psi_tmp,psir_tmp,psis_tmp,psirs_tmp,psirr_tmp,psiss_tmp)
564 write(*,
'(A,i5,12e12.4)')
' 1 : ',i,s_values(i-1),s,ps_axis,psi_tmp,psir_tmp,psir,psirr_tmp,psirr
567 er = xrr*ys + xr*yrs - xrs*yr - xs*yrr
569 sumq = sumq - wgauss(k) * ejac / ( bigr * abs(psir))
570 sumqr = sumqr + psirr * ejac / ((psir**2)*bigr)* wgauss(k)
571 sumqr = sumqr - er / (bigr*psir) * wgauss(k)
572 sumqr = sumqr + ejac * xr / ((bigr**2)*psir) * wgauss(k)
576 cchi(1,(i-1)*n_tht+j+1) = sumq
577 cchi(2,(i-1)*n_tht+j+1) = sumqr
579 CALL
interp(rr(1,node1),rr(1,node2),rr(1,node3),rr(1,node4),+1.e0_r8,1.e0_r8,x,xr,xs,xrs,xrr,xss)
580 CALL
interp(zz(1,node1),zz(1,node2),zz(1,node3),zz(1,node4),+1.e0_r8,1.e0_r8,y,yr,ys,yrs,yrr,yss)
583 CALL
interp(psi(1,node1),psi(1,node2),psi(1,node3),psi(1,node4), &
584 1.e0_r8,1.e0_r8,psi_tmp,psir_tmp,psis_tmp,psirs_tmp,psirr_tmp,psiss_tmp)
585 write(*,
'(A,i5,12e12.4)')
' end : ',i,s_values(i-1),ps_axis,psi_tmp, &
586 psir_tmp,psir,psirr_tmp,psirr
590 er = xrr*ys + xr*yrs - xrs*yr - xs*yrr
593 zsumq = - ejac / ( bigr * abs(psir))
594 zsumqr = + psirr * ejac / (psir**2 *bigr) - er / (bigr*psir) + ejac*xr/((bigr**2) * psir)
596 cchi(3,(i-1)*n_tht+j+1) = zsumq
597 cchi(4,(i-1)*n_tht+j+1) = zsumqr
601 cchi(1,(i-1)*n_tht+1) = 0.e0_r8
602 cchi(2,(i-1)*n_tht+1) = 0.e0_r8
604 node1 = (i-1)*n_tht + 1
606 node3 = node2 + n_tht
607 node4 = node1 + n_tht
609 CALL
interp(rr(1,node1),rr(1,node2),rr(1,node3),rr(1,node4),+1.e0_r8,-1.e0_r8,x,xr,xs,xrs,xrr,xss)
610 CALL
interp(zz(1,node1),zz(1,node2),zz(1,node3),zz(1,node4),+1.e0_r8,-1.e0_r8,y,yr,ys,yrs,yrr,yss)
613 er = xrr*ys + xr*yrs - xrs*yr - xs*yrr
616 zsumq = - ejac / (bigr * abs(psir))
617 zsumqr = + psirr * ejac / (psir**2 *bigr) - er / (bigr*psir) + ejac*xr/((bigr**2) * psir)
619 cchi(3,(i-1)*n_tht+1) = zsumq
620 cchi(4,(i-1)*n_tht+1) = zsumqr
622 q_map(i) = 0.5e0_r8/pi * sumq *
fdia(psi_n)
623 dq_map(i) = 0.5e0_r8/pi * ( sumqr *
fdia(psi_n) + sumq*
fdfdpsi(psi_n)/
fdia(psi_n) /(2.e0_r8*(n_psi-1)))
625 write(*,*) i,q_map(i),dq_map(i)
629 q_map(1) =
fdia(0.e0_r8) /(2.e0_r8*sqrt(crr_axis*czz_axis)*r_axis)
634 psi_n = s_values(i)**2
638 dum = cchi(1,i*n_tht)
642 cchi(1,no) = 2.e0_r8*pi*cchi(1,no) / dum
643 dum2 = cchi(2,i*n_tht)
644 cchi(2,no) = 2.e0_r8*pi*cchi(2,no) / dum
645 cchi(3,no) = 2.e0_r8*pi*cchi(3,no) / dum
646 cchi(4,no) = 2.e0_r8*pi*cchi(4,no) / dum
651 drb =
fdfdpsi(psi_n) / rb / (2*(n_psi-1))
653 cchi(2,no)= +(dqq/qq - drb/rb) * cchi(1,no) - cchi(2,no)
654 cchi(4,no)= +(dqq/qq - drb/rb) * cchi(3,no) - cchi(4,no)
660 WRITE(*,
'(A,f8.4)')
' Q ON AXIS = ',q_map(1)
661 WRITE(*,
'(A,f8.4)')
' Q AT BOUNDARY = ',q_map(n_psi)
666 allocate(gem11(n_psi,n_chi),gem12(n_psi,n_chi),gem22(n_psi,n_chi),gem33(n_psi,n_chi))
667 allocate(rr_map(n_psi,n_chi), zz_map(n_psi,n_chi))
670 chikn(j) = 2.e0_r8 * pi *
REAL(j-1)/
REAL(n_chi)
675 psi_n = s_values(i+1)**2
676 psir = - ps_axis * 2.e0_r8 * s_values(i+1) / (2.e0_r8*
REAL(n_psi))
684 node1 = (i-1)*n_tht + k
686 node3 = node2 + n_tht
687 node4 = node1 + n_tht
689 CALL
interp(rr(1,node1),rr(1,node2),rr(1,node3),rr(1,node4),1.e0_r8,s,xchi(i,1),xr,xs,xrs,xrr,xss)
690 CALL
interp(zz(1,node1),zz(1,node2),zz(1,node3),zz(1,node4),1.e0_r8,s,ychi(i,1),yr,ys,yrs,yrr,yss)
691 CALL
interp(cchi(1,node1),cchi(1,node2),cchi(1,node3),cchi(1,node4),1.e0_r8,s,dchi,chir,chis,chirs,chirr,chiss)
693 CALL
interp(psi(1,node1),psi(1,node2),psi(1,node3),psi(1,node4),1.e0_r8,s,psi_tmp,psir_tmp,psis_tmp,psirs_tmp,psirr_tmp,psiss_tmp)
695 write(*,
'(A,i5,8e12.4)')
' 2 : ',i,s_values(i+1),ps_axis,psi_tmp,psir_tmp
702 psix = psir * ys / ejac
703 psiy = - psir * xs / ejac
704 chix = (chir * ys - chis * yr) / ejac
705 chiy = (-chir * xs + chis * xr)/ ejac
709 gem11(i,1) = psir**2 * (xs**2 + ys**2) / ejac2
710 gem12(i,1) = ( chir * psir * (xs**2 + ys**2) - chis * psir * (xr*xs + yr*ys) ) / ejac2
711 gem33(i,1) = xchi(i,1)
712 rr_map(i,1)= xchi(i,1)
713 zz_map(i,1)= ychi(i,1)
716 dum1 =
fdia(psi_n)**2 / (q_map(i)**2 * gem33(i,1))
717 dum2 = gem11(i,1) * (chix**2 + chiy**2)
719 dum4 = dum2 - dum3*dum3
720 errj = abs(dum4-dum1)
722 IF (errj.GT.maxerr)
THEN
741 IF (((cchi(1,(i-1)*n_tht+k).LE.zchi).AND.(cchi(1,(i-1)*n_tht+k+1) .GE.zchi)) )
THEN
744 nom = (i-1)*n_tht + k
746 a3 = (cchi(1,nom)+cchi(3,nom)-cchi(1,nop)+cchi(3,nop))/4.e0_r8
747 a2 = (- cchi(3,nom) + cchi(3,nop))/4.e0_r8
748 a1=(-3*cchi(1,nom)-cchi(3,nom)+3*cchi(1,nop)-cchi(3,nop))/4.e0_r8
749 a0=( 2*cchi(1,nom)+cchi(3,nom)+2*cchi(1,nop)-cchi(3,nop))/4.e0_r8 - zchi
751 CALL
solvp3(a0,a1,a2,a3,s,s2,s3,ifail)
758 node1 = (i-1)*n_tht + k
760 node3 = node2 + n_tht
761 node4 = node1 + n_tht
763 CALL
interp(rr(1,node1),rr(1,node2),rr(1,node3),rr(1,node4),-1.e0_r8,s,xchi(i,j),xr,xs,xrs,xrr,xss)
764 CALL
interp(zz(1,node1),zz(1,node2),zz(1,node3),zz(1,node4),-1.e0_r8,s,ychi(i,j),yr,ys,yrs,yrr,yss)
765 CALL
interp(cchi(1,node1),cchi(1,node2),cchi(1,node3),cchi(1,node4),-1.e0_r8,s,dchi,chir,chis,chirs,chirr,chiss)
772 psix = psir * ys / ejac
773 psiy = - psir * xs / ejac
774 chix = (chir * ys - chis * yr) / ejac
775 chiy = (-chir * xs + chis * xr)/ ejac
780 gem11(i,j) = psir**2 * (xs**2 + ys**2) / ejac2
781 gem12(i,j) = ( chir * psir * (xs**2 + ys**2) - chis * psir * (xr*xs + yr*ys) ) / ejac2
782 gem33(i,j) = xchi(i,j)**2
783 rr_map(i,j) = xchi(i,j)
784 zz_map(i,j) = ychi(i,j)
787 dum1 =
fdia(psi_n)**2 / (q_map(i)**2 * gem33(i,j))
788 dum2 = gem11(i,j) * (chix**2 + chiy**2)
790 dum4 = dum2 - dum3*dum3
791 errj = abs(dum4-dum1)
792 IF (errj.GT.maxerr)
THEN
801 WRITE(20,*)
'ERROR IN SOLVP3 I,J,K : ',i,j,k,s,s2,s3
802 WRITE(*,*) a0,a1,a2,a3,zchi
803 WRITE(*,*) cchi(1,(i-1)*n_tht+k),cchi(1,(i-1)*n_tht+k+1)
815 WRITE(*,*)
'***************************************************'
816 WRITE(*,
'(3e12.4,2i5)') maxerr,serr,cerr,ierr,jerr
817 WRITE(*,*)
'***************************************************'
843 real (r8) :: rrflux(4,*),zzflux(4,*),moments(n_moments,*)
844 integer :: nr_flux, np_flux, n_moments
845 real (r8) r,sum1,sum2,sumr,b02max,s,ws,rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss, &
846 zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,r_geo,z_geo,a_minor, &
847 zzm,zzmr,zzp,zzpr,aa,bb,cc,det,r_top,dummy,z_top, &
848 r_east,r_west,z_east,z_west,r_mid,z_mid,radius
849 integer i,j,n1,n2,n3,n4,ngs
853 r_geo = ( rrflux(1,(nr_flux-1)*np_flux + 1) + rrflux(1,(nr_flux-1)*np_flux + np_flux/2 + 1)) /2.
854 z_geo = ( zzflux(1,(nr_flux-1)*np_flux + 1) + zzflux(1,(nr_flux-1)*np_flux + np_flux/2 + 1)) /2.
855 a_minor = abs( rrflux(1,(nr_flux-1)*np_flux + 1) - rrflux(1,(nr_flux-1)*np_flux + np_flux/2 + 1)) /2.
857 write(*,*)
' moments : ',r_geo,z_geo
859 moments(n_moments,1:nr_flux) = 0.e0_r8
861 moments(1,1) = 0.e0_r8
862 moments(2,1) = rrflux(1,1) - r_geo
863 moments(3,1) = zzflux(1,1) - z_geo
864 moments(4,1) = sqrt(crr_axis / czz_axis)
865 moments(5,1) = sqrt(crr_axis / czz_axis)
866 moments(6,1) = 0.e0_r8
867 moments(7,1) = 0.e0_r8
871 do j = 1, np_flux - 1
873 n1 = (i-1)*np_flux + j
874 n2 = (i-1)*np_flux + j + 1
876 if (zzflux(3,n1)*zzflux(3,n2) .le. 0.e0_r8)
then
883 aa = 3.e0_r8 * (zzm + zzmr - zzp + zzpr ) / 4.e0_r8
884 bb = ( - zzmr + zzpr ) / 2.e0_r8
885 cc = ( - 3.e0_r8*zzm - zzmr + 3.e0_r8*zzp - zzpr) / 4.e0_r8
886 det = bb*bb - 4.e0_r8*aa*cc
887 s =
root(aa,bb,cc,det,1.e0_r8)
889 if (abs(s) .GT. 1.e0_r8)
then
890 s =
root(aa,bb,cc,det,-1.e0_r8)
893 call
cub1d(rrflux(1,n1),rrflux(3,n1),rrflux(1,n2),rrflux(3,n2),s,r_top,dummy)
894 call
cub1d(zzflux(1,n1),zzflux(3,n1),zzflux(1,n2),zzflux(3,n2),s,z_top,dummy)
896 r_east = rrflux(1,(i-1)*np_flux + 1)
897 r_west = rrflux(1,(i-1)*np_flux + np_flux/2 + 1)
898 z_east = zzflux(1,(i-1)*np_flux + 1)
899 z_west = zzflux(1,(i-1)*np_flux + np_flux/2 + 1)
901 r_mid = (r_east + r_west)/2.e0_r8
902 z_mid = (z_east + z_west)/2.e0_r8
903 radius = abs(r_east - r_west)/2.e0_r8
905 write(*,
'(A,i3,4f12.6)')
'mom : ',i,r_mid,z_mid,r_top,z_top
907 moments(1,i) = radius
908 moments(2,i) = (r_mid - r_geo)
909 moments(3,i) = (z_mid - z_geo)
911 if ( z_top - z_mid .gt. 0.e0_r8)
then
912 moments(4,i) = (z_top - z_mid) / radius
913 moments(6,i) = -(r_top - r_mid) / radius
915 moments(5,i) = -(z_top - z_mid) / radius
916 moments(7,i) = -(r_top - r_mid) / radius
941 real (r8),
allocatable:: b0max(:),b02av(:),rav(:),sumk(:)
942 real (r8) :: rrflux(4,*),zzflux(4,*),psflux(4,*),fraction_circ(*)
943 integer :: nr_flux, np_flux
945 real (r8) r,sum1,sum2,sumr,b02max,s,ws, &
946 rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss, &
947 zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss, &
948 psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss, &
949 rzjac,gradps2,zjdchi,psi_n,bphi,b02,b0,bm,zlam,sum
950 integer i,j,n1,n2,n3,n4,ngs,nk,k
954 allocate(b0max(nr_flux),b02av(nr_flux),rav(nr_flux))
967 n1 = (i-1)*np_flux + j
968 n2 = (i-1)*np_flux + j + 1
969 n3 = (i )*np_flux + j + 1
970 n4 = (i )*np_flux + j
972 if (j .eq. np_flux)
then
974 n2 = (i )*np_flux - np_flux + 1
975 n3 = (i )*np_flux + 1
976 n4 = (i )*np_flux + np_flux
985 CALL
interp(rrflux(1,n1),rrflux(1,n2),rrflux(1,n3),rrflux(1,n4),r,s,rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss)
986 CALL
interp(zzflux(1,n1),zzflux(1,n2),zzflux(1,n3),zzflux(1,n4),r,s,zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss)
987 CALL
interp(psflux(1,n1),psflux(1,n2),psflux(1,n3),psflux(1,n4),r,s,psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss)
989 rzjac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
991 gradps2 = dpsg1_dr**2 * (drrg1_ds**2 + dzzg1_ds**2) / rzjac**2
993 zjdchi = rrg1 * rzjac / dabs(dpsg1_dr)
995 psi_n = - (psg1 - ps_axis) / ps_axis
997 bphi =
fdia(psi_n) / rrg1
999 b02 = bphi**2 + gradps2/rrg1**2
1001 sum1 = sum1 - ws * zjdchi
1002 sum2 = sum2 - ws * zjdchi * b02
1003 sumr = sumr - ws * zjdchi * rrg1
1005 if (b02 .gt. b02max) b02max = b02
1011 b02av(i+1) = sum2 / sum1
1012 b0max(i+1) = dsqrt(dabs(b02max))
1013 rav(i+1) = sumr / sum1
1024 write(*,*)
'i+1 sqrt(psi_n) B02av B0max fraction_circ'
1033 n1 = (i-1)*np_flux + j
1034 n2 = (i-1)*np_flux + j + 1
1035 n3 = (i )*np_flux + j + 1
1036 n4 = (i )*np_flux + j
1038 if (j .eq. np_flux)
then
1040 n2 = (i )*np_flux - np_flux + 1
1041 n3 = (i )*np_flux + 1
1042 n4 = (i )*np_flux + np_flux
1051 call
interp(rrflux(1,n1),rrflux(1,n2),rrflux(1,n3),rrflux(1,n4),r,s,rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss)
1052 call
interp(zzflux(1,n1),zzflux(1,n2),zzflux(1,n3),zzflux(1,n4),r,s,zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss)
1053 call
interp(psflux(1,n1),psflux(1,n2),psflux(1,n3),psflux(1,n4),r,s,psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss)
1055 rzjac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
1057 gradps2 = dpsg1_dr**2 * (drrg1_ds**2 + dzzg1_ds**2) / rzjac**2
1059 zjdchi = rrg1 * rzjac / dabs(dpsg1_dr)
1061 psi_n = - (psg1 - ps_axis) / ps_axis
1063 bphi =
fdia(psi_n) / rrg1
1065 b02 = bphi**2 + gradps2/rrg1**2
1067 b0 = dsqrt(dabs(b02))
1072 zlam = dble(k-1)/dble(nk-1)
1074 sumk(k) = sumk(k) - ws*zjdchi*dsqrt(dabs(1.-zlam*b0/bm))
1078 sum1 = sum1 - ws * zjdchi
1088 zlam = float(k-1)/float(nk-1)
1089 sum = sum + zlam * sum1 / sumk(k)
1093 fraction_circ(i+1) = (sum + 0.5e0_r8 * sum1/sumk(nk)) / float(nk-1)
1094 fraction_circ(i+1) = 0.75e0_r8 * fraction_circ(i+1) * b02av(i+1) / b0max(i+1)**2
1097 psi_n = - (psg1 - ps_axis) / ps_axis
1098 write(*,
'(i5,4f12.6)') i+1,sqrt(psi_n),b02av(i+1),b0max(i+1),fraction_circ(i+1)
1108 powers,volume_integrals,n_var,n_int,n_psi)
1123 real (r8) :: rr_flux(4,*),zz_flux(4,*), ps_flux(4,*)
1124 real (r8) :: powers(n_var,n_int),volume_integrals(n_psi,n_int)
1125 integer :: nr_flux, np_flux, n_var, n_int, n_psi
1127 real (r8) r,wr,s,ws,rzjac,psi_n,bphi, &
1128 rrg1,drrg1_dr,drrg1_ds,zzg1,dzzg1_dr,dzzg1_ds,psg1,dpsg1_dr,dpsg1_ds
1129 integer i,j,n1,n2,n3,n4,ngr,ngs,m
1132 write(*,*)
' helena volume integrals : ',nr_flux,np_flux
1134 volume_integrals(1:n_psi,1:n_int) = 0.e0_r8
1138 volume_integrals(i+1,1:n_int) = volume_integrals(i,1:n_int)
1142 n1 = (i-1)*np_flux + j
1143 n2 = (i-1)*np_flux + j + 1
1144 n3 = (i )*np_flux + j + 1
1145 n4 = (i )*np_flux + j
1147 if (j .eq. np_flux)
then
1149 n2 = (i )*np_flux - np_flux + 1
1150 n3 = (i )*np_flux + 1
1151 n4 = (i )*np_flux + np_flux
1164 CALL
interp2(rr_flux(1,n1),rr_flux(1,n2),rr_flux(1,n3),rr_flux(1,n4),r,s,rrg1,drrg1_dr,drrg1_ds)
1165 CALL
interp2(zz_flux(1,n1),zz_flux(1,n2),zz_flux(1,n3),zz_flux(1,n4),r,s,zzg1,dzzg1_dr,dzzg1_ds)
1166 CALL
interp2(ps_flux(1,n1),ps_flux(1,n2),ps_flux(1,n3),ps_flux(1,n4),r,s,psg1,dpsg1_dr,dpsg1_ds)
1168 rzjac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
1169 psi_n = - (psg1 - ps_axis) / ps_axis
1171 bphi =
fdia(psi_n) / rrg1
1175 volume_integrals(i+1,m) = volume_integrals(i+1,m) &
1176 + rrg1**powers(1,m) * bphi**powers(2,m) * wr * ws * 2.e0_r8 *pi * rrg1 * rzjac
1202 real (r8) :: rrnew(4,*),zznew(4,*),psinew(4,*), abltg(3), xtmp, tol_t
1203 real (r8),
allocatable :: s_values(:),tht_start(:),tht_end(:)
1204 real (r8),
allocatable :: sp1(:),sp2(:),sp3(:),sp4(:)
1205 real (r8) pi,dpsi_ds,tht_min,tht_max,rr1,rr2,ss1,ss2, &
1206 rrg1,drrg1_dr,drrg1_ds,zzg1,dzzg1_dr,dzzg1_ds,rrg2,drrg2_dr, &
1207 drrg2_ds,zzg2,dzzg2_dr,dzzg2_ds,tht1,tht2,tht_tmp,theta, &
1208 drr1,dss1,drr2,dss2,drrg1_dt,dzzg1_dt,drrg2_dt,dzzg2_dt, &
1209 rz1,rz2,drz1,drz2,rz0,a3,a2,a1,a0,t,t2,t3,ri,dri,si, &
1210 dsi,drrg1_drs,drrg1_drr,drrg1_dss,dzzg1_drs,dzzg1_drr, &
1211 dzzg1_dss,psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss, &
1212 check,rad2,th_z,th_r,th_rr,th_zz,th_rz,dth_ds,dth_dr,dth_drr,dth_drs,dth_dss, &
1213 rzjac,ps_r,ps_z,ejac,ptjac,rt,st,dptjac_dr,dptjac_ds,rpt,spt, &
1214 dr_dpt,dz_dpt,dr_dz,dr_dr,ds_dz,ds_dr,dps_drr,dps_dzz,cx,cy,tn,tn2,cn
1215 integer nrnew,npnew,i,k,i_elm,node1,node2,node3,node4,j,ifail,inode
1217 if (nrnew .ne. n_psi+1)
write(*,*)
' MAJOR PROBLEM in REMESH! nrnew <> n_psi+1'
1219 write(*,*)
'**************************************'
1220 write(*,*)
'* helena remesh : ',nrnew,npnew,
'*'
1221 write(*,*)
'**************************************'
1225 allocate(s_values(n_psi+1),tht_start(n_pieces_max),tht_end(n_pieces_max))
1227 rrnew(1:4,1:nrnew*npnew) = 0.e0_r8
1228 zznew(1:4,1:nrnew*npnew) = 0.e0_r8
1229 psinew(1:4,1:nrnew*npnew) = 0.e0_r8
1231 pi = 2.e0_r8*asin(1.e0_r8)
1234 s_values(i) = float(i-1)/float(n_psi)
1237 allocate(sp1(n_psi+1),sp2(n_psi+1),sp3(n_psi+1),sp4(n_psi+1))
1246 dpsi_ds = - ps_axis * 2.e0_r8*s_values(i+1)
1251 do k=1, flux_surfaces(i)%n_pieces
1253 rr1 = flux_surfaces(i)%r(1,k)
1254 rr2 = flux_surfaces(i)%r(3,k)
1256 ss1 = flux_surfaces(i)%s(1,k)
1257 ss2 = flux_surfaces(i)%s(3,k)
1259 i_elm = flux_surfaces(i)%elm(k)
1261 node1 = elm_list(1,i_elm)
1262 node2 = elm_list(2,i_elm)
1263 node3 = elm_list(3,i_elm)
1264 node4 = elm_list(4,i_elm)
1266 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),rr1,ss1,rrg1,drrg1_dr,drrg1_ds)
1267 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),rr1,ss1,zzg1,dzzg1_dr,dzzg1_ds)
1268 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),rr2,ss2,rrg2,drrg2_dr,drrg2_ds)
1269 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),rr2,ss2,zzg2,dzzg2_dr,dzzg2_ds)
1271 tht1 = atan2(zzg1-z_axis,rrg1-r_axis)
1272 tht2 = atan2(zzg2-z_axis,rrg2-r_axis)
1274 if (tht1 .lt. 0.e0_r8) tht1 = tht1 + 2.e0_r8*pi
1275 if (tht2 .lt. 0.e0_r8) tht2 = tht2 + 2.e0_r8*pi
1277 tht_start(k) = min(tht1,tht2)
1278 tht_end(k) = max(tht1,tht2)
1280 if ((tht_end(k) - tht_start(k)) .gt. 3.e0_r8*pi/4.e0_r8)
then
1281 tht_tmp = tht_end(k)
1282 tht_end(k) = tht_start(k)
1283 tht_start(k) = tht_tmp - 2.e0_r8*pi
1286 tht_min = min(tht_min,tht_start(k))
1287 tht_max = max(tht_max,tht_end(k))
1293 theta = 2.e0_r8 * pi * float(j-1)/float(npnew)
1295 if (theta .gt. tht_max) theta = theta - 2.e0_r8*pi
1296 if (theta .lt. tht_min) theta = theta + 2.e0_r8*pi
1298 do k=1, flux_surfaces(i)%n_pieces
1300 if ( (theta .ge. tht_start(k)) .and. (theta .le. tht_end(k)) )
then
1302 rr1 = flux_surfaces(i)%r(1,k); ss1 = flux_surfaces(i)%s(1,k)
1303 drr1 = flux_surfaces(i)%r(2,k); dss1 = flux_surfaces(i)%s(2,k)
1304 rr2 = flux_surfaces(i)%r(3,k); ss2 = flux_surfaces(i)%s(3,k)
1305 drr2 = flux_surfaces(i)%r(4,k); dss2 = flux_surfaces(i)%s(4,k)
1307 i_elm = flux_surfaces(i)%elm(k)
1309 node1 = elm_list(1,i_elm)
1310 node2 = elm_list(2,i_elm)
1311 node3 = elm_list(3,i_elm)
1312 node4 = elm_list(4,i_elm)
1314 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),rr1,ss1,rrg1,drrg1_dr,drrg1_ds)
1315 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),rr1,ss1,zzg1,dzzg1_dr,dzzg1_ds)
1316 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),rr2,ss2,rrg2,drrg2_dr,drrg2_ds)
1317 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),rr2,ss2,zzg2,dzzg2_dr,dzzg2_ds)
1319 drrg1_dt = drrg1_dr * drr1 + drrg1_ds * dss1
1320 dzzg1_dt = dzzg1_dr * drr1 + dzzg1_ds * dss1
1321 drrg2_dt = drrg2_dr * drr2 + drrg2_ds * dss2
1322 dzzg2_dt = dzzg2_dr * drr2 + dzzg2_ds * dss2
1324 rz1 = rrg1 * tan(theta) - zzg1
1325 rz2 = rrg2 * tan(theta) - zzg2
1326 drz1 = drrg1_dt * tan(theta) - dzzg1_dt
1327 drz2 = drrg2_dt * tan(theta) - dzzg2_dt
1329 rz0 = r_axis * tan(theta) - z_axis
1331 a3 = ( rz1 + drz1 - rz2 + drz2 )/4.e0_r8
1332 a2 = ( - drz1 + drz2 )/4.e0_r8
1333 a1 = (-3.e0_r8*rz1 - drz1 + 3.e0_r8*rz2 - drz2 )/4.e0_r8
1334 a0 = ( 2.e0_r8*rz1 + drz1 + 2.e0_r8*rz2 - drz2 )/4.e0_r8 - rz0
1336 call
solvp3(a0,a1,a2,a3,t,t2,t3,ifail)
1338 if (abs(t) .le. 1.e0_r8+tol_t)
then
1340 call
cub1d(rr1, drr1, rr2, drr2, t, ri, dri)
1341 call
cub1d(ss1, dss1, ss2, dss2, t, si, dsi)
1343 call
interp(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),ri,si, &
1344 rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss)
1345 call
interp(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),ri,si, &
1346 zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss)
1347 call
interp(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4),ri,si, &
1348 psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss)
1350 check = atan2(zzg1- z_axis,rrg1-r_axis)
1351 if (check .lt. 0.e0_r8) check = check + 2.e0_r8*pi
1353 rad2 = (rrg1 - r_axis)**2 + (zzg1 - z_axis)**2
1354 th_z = (rrg1 - r_axis) / rad2
1355 th_r = - (zzg1 - z_axis) / rad2
1357 th_rr = 2*(zzg1 - z_axis) * (rrg1 - r_axis) / rad2**2
1359 th_rz = ( (zzg1 - z_axis)**2 - (rrg1 - r_axis)**2 ) / rad2**2
1361 dth_ds = th_r * drrg1_ds + th_z * dzzg1_ds
1362 dth_dr = th_r * drrg1_dr + th_z * dzzg1_dr
1364 dth_drr = th_rr * drrg1_dr * drrg1_dr + th_r * drrg1_drr + 2.* th_rz * drrg1_dr * dzzg1_dr &
1365 + th_zz * dzzg1_dr * dzzg1_dr + th_z * dzzg1_drr
1367 dth_drs = th_rr * drrg1_dr * drrg1_ds + th_rz * drrg1_dr * dzzg1_ds + th_r * drrg1_drs &
1368 + th_rz * dzzg1_dr * drrg1_ds + th_zz * dzzg1_dr * dzzg1_ds + th_z * dzzg1_drs
1370 dth_dss = th_rr * drrg1_ds * drrg1_ds + th_r * drrg1_dss + 2.* th_rz * drrg1_ds * dzzg1_ds &
1371 + th_zz * dzzg1_ds * dzzg1_ds + th_z * dzzg1_dss
1373 rzjac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
1375 ps_r = ( dzzg1_ds * dpsg1_dr - dzzg1_dr * dpsg1_ds) / rzjac
1376 ps_z = (- drrg1_ds * dpsg1_dr + drrg1_dr * dpsg1_ds) / rzjac
1378 ejac = (ps_r * th_z - ps_z * th_r)
1379 ptjac = (dpsg1_dr * dth_ds - dpsg1_ds * dth_dr)
1381 rt = - dpsg1_ds / ptjac
1382 st = dpsg1_dr / ptjac
1384 dptjac_dr = dpsg1_drr * dth_ds + dpsg1_dr * dth_drs - dpsg1_drs * dth_dr - dpsg1_ds * dth_drr
1386 dptjac_ds = dpsg1_drs * dth_ds + dpsg1_dr * dth_dss - dpsg1_dss * dth_dr - dpsg1_ds * dth_drs
1388 rpt = (-dptjac_dr * dth_ds / ptjac**2 + dth_drs/ptjac) * rt + (- dptjac_ds * dth_ds / ptjac**2 + dth_dss/ptjac) * st
1390 spt = ( dptjac_dr * dth_dr / ptjac**2 - dth_drr/ ptjac) * rt + ( dptjac_ds * dth_dr / ptjac**2 - dth_drs/ptjac) * st
1392 dr_dpt = - drrg1_drr * dth_ds * dpsg1_ds / ptjac**2 + drrg1_drs * (dth_ds * dpsg1_dr + dth_dr * dpsg1_ds) / ptjac**2 &
1393 + drrg1_dr * rpt + drrg1_ds * spt - drrg1_dss * dth_dr * dpsg1_dr / ptjac**2
1395 dz_dpt = - dzzg1_drr * dth_ds * dpsg1_ds / ptjac**2 + dzzg1_drs * (dth_ds * dpsg1_dr + dth_dr * dpsg1_ds) / ptjac**2 &
1396 + dzzg1_dr * rpt + dzzg1_ds * spt - dzzg1_dss * dth_dr * dpsg1_dr /ptjac**2
1399 rrnew(1,npnew*(i) + j) = rrg1
1400 zznew(1,npnew*(i) + j) = zzg1
1402 rrnew(2,npnew*(i) + j) = ( th_z / ejac) / (2.e0_r8*(nrnew-1)) * dpsi_ds
1403 zznew(2,npnew*(i) + j) = (- th_r / ejac) / (2.e0_r8*(nrnew-1)) * dpsi_ds
1405 rrnew(3,npnew*(i) + j) = + (- ps_z / ejac) / (npnew/pi)
1406 zznew(3,npnew*(i) + j) = + ( ps_r / ejac) / (npnew/pi)
1408 rrnew(4,npnew*(i) + j) = dr_dpt /(2.e0_r8*(nrnew-1)*(npnew)/pi) * dpsi_ds
1409 zznew(4,npnew*(i) + j) = dz_dpt /(2.e0_r8*(nrnew-1)*(npnew)/pi) * dpsi_ds
1411 psinew(1,npnew*(i) + j) = psi_values(i)
1412 psinew(2,npnew*(i) + j) = dpsi_ds / (2.e0_r8*(nrnew-1))
1413 psinew(3,npnew*(i) + j) = 0.e0_r8
1414 psinew(4,npnew*(i) + j) = 0.e0_r8
1418 write(*,*)
' T TOO BIG : ',t,t2,t3
1432 node1 = elm_list(1,ielm_ax)
1433 node2 = elm_list(2,ielm_ax)
1434 node3 = elm_list(3,ielm_ax)
1435 node4 = elm_list(4,ielm_ax)
1437 call
interp(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),r_ax,s_ax,rrg1,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss)
1438 call
interp(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),r_ax,s_ax,zzg1,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss)
1439 call
interp(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4),r_ax,s_ax,psg1,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss)
1441 ejac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
1442 dr_dz = - drrg1_ds / ejac
1443 dr_dr = + dzzg1_ds / ejac
1444 ds_dz = + drrg1_dr / ejac
1445 ds_dr = - dzzg1_dr / ejac
1447 dps_drr = dpsg1_drr * dr_dr * dr_dr + 2.*dpsg1_drs * dr_dr * ds_dr + dpsg1_dss * ds_dr * ds_dr
1448 dps_dzz = dpsg1_drr * dr_dz * dr_dz + 2.*dpsg1_drs * dr_dz * ds_dz + dpsg1_dss * ds_dz * ds_dz
1450 crr_axis = dps_drr / 2.e0_r8
1451 czz_axis = dps_dzz / 2.e0_r8
1461 rrnew(1,inode) = rrg1
1462 zznew(1,inode) = zzg1
1464 theta = float(j-1)/float(npnew) * 2.e0_r8*pi
1470 if (theta .eq. pi/2.e0_r8)
then
1471 rrnew(2,inode) = 0.e0_r8
1472 zznew(2,inode) = +1.e0_r8/(sqrt(abs(cy))*2.e0_r8*float(nrnew-1))
1473 rrnew(4,inode) = -1.e0_r8/(sqrt(abs(cy))*2.e0_r8*float(nrnew-1)*float(npnew)/pi)
1474 zznew(4,inode) = 0.e0_r8
1475 ELSEIF (theta .eq. (3.e0_r8*pi/2))
THEN
1476 rrnew(2,inode) = 0.e0_r8
1477 zznew(2,inode) = +1.e0_r8/(sqrt(abs(cy))*2.*float(nrnew-1))
1478 rrnew(4,inode) = -1.e0_r8/(sqrt(abs(cy))*2.*float(nrnew-1)*float(npnew)/pi)
1479 zznew(4,inode) = 0.e0_r8
1481 rrnew(2,inode) = + sign(1.e0_r8,cn)/(sqrt(abs(cx+cy*tn2))*2.e0_r8*float(nrnew-1))
1482 zznew(2,inode) = + abs(tn)/(sqrt(abs(cx+cy*tn2))*2.e0_r8*float(nrnew-1))
1483 rrnew(4,inode) = - (cx+cy*tn2)**(-1.5e0_r8) * cy * abs(tn) / (cn**2 * 2.e0_r8*float(nrnew-1)*float(npnew)/pi)
1484 zznew(4,inode) = + cx * (cx + cy*tn2)**(-1.5e0_r8) / (cn*abs(cn) * 2.e0_r8*float(nrnew-1)*float(npnew-1)/pi)
1486 IF (theta .gt. pi)
THEN
1487 zznew(2,inode) = - zznew(2,inode)
1488 rrnew(4,inode) = - rrnew(4,inode)
1490 rrnew(3,inode) = 0.e0_r8
1491 zznew(3,inode) = 0.e0_r8
1492 psinew(1,inode) = ps_axis
1513 write(*,*)
' export to HELENA namelist'
1515 open(20,file=
'helena.nml')
1516 write(20,*)
' &SHAPE IAS = 1, ISHAPE = 2,'
1517 write(20,
'(A,i5,A,i5)')
' MFM= ',mf,
', MHARM = ',mf/2
1519 write(20,
'(A,i4,A,e14.6,A,i4,A,e14.6)')
' FM(',2*i-1,
')=',fr(2*i-1)/amin,
' FM(',2*i,
')=',fr(2*i)/amin
1522 write(20,*)
' &PROFILE '
1523 write(20,*)
' IPAI=7, EPI=1.0, FPI=1.0'
1524 write(20,*)
' IGAM=7'
1525 write(20,*)
' ICUR=2, ECUR=1.0, FCUR=1.0'
1526 write(20,*)
' NPTS = ',n_prof
1528 write(20,
'(A,i4,A,e12.4,A,i4,A,e12.4,A,i4,A,e12.4)') &
1529 ' DPR(',i,
') = ',
dp_dpsi(i),
', DF2(',i,
') = ',fdf_dpsi(i),
', ZJZ(',i,
') = ',zjz_psi(i)
1532 write(20,*)
' &PHYS '
1533 write(20,
'(A,f10.6)')
' EPS = ',amin/rgeo
1534 write(20,
'(A,f10.6)')
' ALFA = ',abs(amin**2 * bgeo / ps_axis)
1535 write(20,
'(A,f10.6)')
' B = ',mu_zero * rgeo**2 *
dp_dpsi(1)/fdf_dpsi(1)
1536 write(20,
'(A,f10.6)')
' BETAP = ',beta_p
1537 write(20,
'(A,f10.6)')
' XIAB = ',mu_zero * abs(
current) / (amin * bgeo)
1538 write(20,
'(A,f10.6)')
' RVAC = ',rgeo
1539 write(20,
'(A,f10.6)')
' BVAC = ',bgeo
1542 write(20,*)
' NR = 51, NP = 33, NRMAP = 101, NPMAP = 129, NCHI = 128'
1543 write(20,*)
' NRCUR = 51, NPCUR = 33, ERRCUR = 1.e-5, NITER = 100, NMESH = 100'
1545 write(20,*)
' &PRI NPR1=1 &END '
1546 write(20,*)
' &PLOT NPL1=1 &END '
1547 write(20,*)
' &BALL &END '
1565 real (r8) :: xx(4,4), xr(4,4), xs(4,4), yr(4,4), ys(4,4), xjac(4,4), ps(4,4), psn(4,4)
1566 real (r8) :: sum_p_area, sum_p_vol, sum_c_area, sum_vol, sum_area, zjz
1567 integer :: ngr, ngs, kf, kv, i, vertex
1573 sum_p_area = 0.e0_r8
1574 sum_c_area = 0.e0_r8
1578 nodes(1) = elm_list(1,i)
1579 nodes(2) = elm_list(2,i)
1580 nodes(3) = elm_list(3,i)
1581 nodes(4) = elm_list(4,i)
1597 xx(ngr,ngs) = xx(ngr,ngs) + rr(kf,vertex) * h(ngr,ngs,kv,kf)
1598 ps(ngr,ngs) = ps(ngr,ngs) + psi(kf,vertex) * h(ngr,ngs,kv,kf)
1600 xr(ngr,ngs) = xr(ngr,ngs) + rr(kf,vertex) * hr(ngr,ngs,kv,kf)
1601 xs(ngr,ngs) = xs(ngr,ngs) + rr(kf,vertex) * hs(ngr,ngs,kv,kf)
1602 yr(ngr,ngs) = yr(ngr,ngs) + zz(kf,vertex) * hr(ngr,ngs,kv,kf)
1603 ys(ngr,ngs) = ys(ngr,ngs) + zz(kf,vertex) * hs(ngr,ngs,kv,kf)
1608 xjac(ngr,ngs) = xr(ngr,ngs)*ys(ngr,ngs) - xs(ngr,ngs)*yr(ngr,ngs)
1613 psn(:,:) = (ps_axis - ps(:,:)) / ps_axis
1618 sum_vol = sum_vol + wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs) * xx(ngr,ngs)
1619 sum_area = sum_area + wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs)
1621 sum_p_area = sum_p_area + wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs) *
pressure(psn(ngr,ngs))
1622 sum_p_vol = sum_p_vol + wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs) * xx(ngr,ngs) *
pressure(psn(ngr,ngs))
1624 zjz =
fdfdpsi(psn(ngr,ngs)) / (mu_zero * xx(ngr,ngs)) +
dpdpsi(psn(ngr,ngs)) * xx(ngr,ngs)
1626 sum_c_area = sum_c_area + wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs) * zjz
1633 volume = 2.e0_r8 * pi * sum_vol
1636 beta_p = 8.e0_r8 * pi / mu_zero * sum_p_area / (sum_c_area**2 )
1637 beta_t = 2.e0_r8 * mu_zero * sum_p_area / (sum_area * bgeo**2)
1638 beta_n = 100.e0_r8 * (4.e0_r8*pi/10.e0_r8) * beta_t / (mu_zero * abs(
current) / (amin * bgeo))
1640 write(*,
'(A,f16.8,A)')
' total volume : ',volume,
' m^3'
1641 write(*,
'(A,f16.8,A)')
' total area : ',area,
' m^2'
1642 write(*,
'(A,e12.4,A)')
' total current : ',
current,
' A'
1643 write(*,
'(A,f16.8)')
' poloidal beta : ',beta_p
1644 write(*,
'(A,f16.8)')
' toroidal beta : ',beta_t
1645 write(*,
'(A,f16.8)')
' normalised beta : ',beta_n
1646 write(*,
'(A,3f16.8)')
' magnetic axis : ',r_axis,z_axis,(r_axis-rgeo)/amin
1661 real (r8),
allocatable :: r_av(:),or_av(:)
1663 real (r8) :: psi_n, psi_n2, small, fdf_error, fdf_old, fmix
1666 write(*,*)
' UPDATE FDF'
1673 allocate(psi_values(n_psi),r_av(n_psi),or_av(n_psi))
1676 psi_n = float(i-1)/float(n_prof-1)
1677 psi_values(i) = ps_axis - (1. - small) * psi_n * ps_axis
1688 psi_n = 1. - psi_values(i)/ps_axis
1689 psi_n2 = float(i-1)/float(n_prof-1)
1691 fdf_old = fdf_dpsi(i)
1695 fdf_dpsi(i) = (1.-fmix)*fdf_dpsi(i) + fmix * fdf_old
1699 fdf_error= fdf_error + abs(fdf_old - fdf_dpsi(i))
1703 fdf_error = fdf_error / float(n_prof)
1707 deallocate(psi_values,r_av,or_av)
1712 subroutine gs_solve(n_iter,rhs_only,solve_only,error_iteration,amix,ifail)
1717 integer :: i, n_iter, ifail
1718 logical :: solve_only, rhs_only
1719 real (r8) :: error, error_iteration, amix, t_start, t_end
1723 call cpu_time(t_start)
1733 if (error .lt. error_iteration)
then
1734 write(*,
'(A,i5,3e16.8)')
' GS_solve : ',i,r_axis,ps_axis,error
1744 call cpu_time(t_end)
1746 if (error .gt. error_iteration)
then
1748 write(*,
'(A,i5,3e16.8)')
' GS_solve failed : ',i,r_axis,ps_axis,error
1751 write(*,
'(A,f12.8)')
' GS, CPU time : ',t_end-t_start
1765 real (r8) :: psimin, psimax, a0, a1, a2, a3
1766 real (r8) :: psi_test, dpsi_dr(4),dpsi_ds(4), drr_dr(4), drr_ds(4), dzz_dr(4), dzz_ds(4)
1767 real (r8) :: rr_psi(4), zz_psi(4), r_psi(4), s_psi(4), tht(4)
1768 real (r8) :: s, s2, s3, r_tmp, s_tmp, psr_tmp, pss_tmp, ttmp
1769 integer :: i, j, ifound, iv, im, is, n1, n2, n3
1770 integer :: ifail, itht(4), itmp
1773 write(*,*)
' find_flux_surfaces : ',n_psi
1775 if (.not.
allocated(flux_surfaces))
allocate(flux_surfaces(n_psi))
1778 flux_surfaces(j)%n_pieces = 0
1779 flux_surfaces(j)%elm = 0
1780 flux_surfaces(j)%r = 0
1781 flux_surfaces(j)%s = 0
1792 if ((psi_values(j) .ge. psimin) .and. (psi_values(j) .le. psimax))
then
1808 a3 = ( psi(1,n1) + psi(is,n1) - psi(1,n2) + psi(is,n2))/4.
1809 a2 = ( - psi(is,n1) + psi(is,n2))/4.
1810 a1 = (-3*psi(1,n1) - psi(is,n1) + 3*psi(1,n2) - psi(is,n2))/4.
1811 a0 = ( 2*psi(1,n1) + psi(is,n1) + 2*psi(1,n2) - psi(is,n2))/4. - psi_values(j)
1813 call
solvp3(a0,a1,a2,a3,s,s2,s3,ifail)
1815 if (abs(s) .le. 1.)
then
1823 if (abs(s2) .le. 1.)
then
1829 if (abs(s3) .le. 1.)
write(*,*)
' another solution : ',s3
1835 if (ifound .eq. 2)
then
1839 elseif (ifound .eq. 4)
then
1843 tht(1:4) = atan2(s_psi(1:4),r_psi(1:4))
1845 where (tht .lt. 0.) tht = tht + 2.e0_r8*pi
1847 itht(1)= 1; itht(2) = 2; itht(3) = 3; itht(4) = 4
1849 if (tht(2) .lt. tht(1))
then
1850 itmp = itht(1); itht(1) = itht(2) ; itht(2) = itmp;
1852 if (tht(4) .lt. tht(3))
then
1853 itmp = itht(3); itht(3) = itht(4) ; itht(4) = itmp;
1855 if (tht(itht(3)) .lt. tht(itht(2)))
then
1856 itmp = itht(2); itht(2) = itht(3) ; itht(3) = itmp;
1858 if (tht(itht(2)) .lt. tht(itht(1)))
then
1859 itmp = itht(1); itht(1) = itht(2) ; itht(2) = itmp;
1861 if (tht(itht(4)) .lt. tht(itht(3)))
then
1862 itmp = itht(3); itht(3) = itht(4) ; itht(4) = itmp;
1864 if (tht(itht(3)) .lt. tht(itht(2)))
then
1865 itmp = itht(2); itht(2) = itht(3) ; itht(3) = itmp;
1877 call
flux_surface_add_line(i,j,r_psi(itht(1:2)),s_psi(itht(1:2)),dpsi_dr(itht(1:2)),dpsi_ds(itht(1:2)))
1878 call
flux_surface_add_line(i,j,r_psi(itht(3:4)),s_psi(itht(3:4)),dpsi_dr(itht(3:4)),dpsi_ds(itht(3:4)))
1897 integer :: i, j,node1, node2, node3, node4
1898 real (r8) :: psi_value, r_psi(*), s_psi(*), dpsi_dr(*), dpsi_ds(*)
1899 real (r8) :: rr1, rr2, ss1, ss2,sgn, drs, xl1 ,xl2, drr1, drr2, dss1, dss2, t
1900 real (r8) :: ri, si, dri, dsi, delta_ri, delta_si,psi_test, dummy_r, dummy_s, dl1, dl2
1909 if ((rr1 .eq. -1.e0_r8).and. (dpsi_ds(1).lt. 0.e0_r8))
then
1911 elseif ((rr1 .eq. +1.e0_r8).and. (dpsi_ds(1).gt. 0.e0_r8))
then
1914 if ((ss1 .eq. -1.e0_r8).and. (dpsi_dr(1).gt. 0.e0_r8))
then
1916 elseif ((ss1 .eq. +1.e0_r8).and. (dpsi_dr(1).lt. 0.e0_r8))
then
1920 drs = sgn * sqrt((rr2-rr1)**2 + (ss2-ss1)**2)
1922 xl1 = 0.5e0_r8 * drs / sqrt(dpsi_dr(1)**2 + dpsi_ds(1)**2)
1923 xl2 = 0.5e0_r8 * drs / sqrt(dpsi_dr(2)**2 + dpsi_ds(2)**2)
1925 drr1 = xl1 * dpsi_ds(1)
1926 drr2 = xl2 * dpsi_ds(2)
1927 dss1 = - xl1 * dpsi_dr(1)
1928 dss2 = - xl2 * dpsi_dr(2)
1934 call
cub1d(rr1, drr1, rr2, drr2, t, ri, dri)
1935 call
cub1d(ss1, dss1, ss2, dss2, t, si, dsi)
1937 node1 = elm_list(1,i); node2 = elm_list(2,i); node3 = elm_list(3,i); node4 = elm_list(4,i)
1939 call
interp2(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4),ri,si,psi_test,dummy_r,dummy_s)
1941 delta_ri = 0.5e0_r8 * (psi_values(j) - psi_test) / dummy_r
1942 delta_si = 0.5e0_r8 * (psi_values(j) - psi_test) / dummy_s
1944 call
solvem2(0.25e0_r8*drr1,-0.25e0_r8*drr2,0.25e0_r8*dss1,-0.25e0_r8*dss2,delta_ri,delta_si,dl1,dl2)
1946 if ((abs(dl1) .lt. 0.1e0_r8) .and. (abs(dl2).lt.0.1e0_r8))
then
1948 drr1 = (1.e0_r8+ dl1) * drr1
1949 dss1 = (1.e0_r8+ dl1) * dss1
1950 drr2 = (1.e0_r8+ dl2) * drr2
1951 dss2 = (1.e0_r8+ dl2) * dss2
1955 flux_surfaces(j)%n_pieces = flux_surfaces(j)%n_pieces + 1
1956 flux_surfaces(j)%elm(flux_surfaces(j)%n_pieces) = i
1957 flux_surfaces(j)%r(1:4,flux_surfaces(j)%n_pieces) = (/ rr1, drr1, rr2, drr2 /)
1958 flux_surfaces(j)%s(1:4,flux_surfaces(j)%n_pieces) = (/ ss1, dss1, ss2, dss2 /)
1970 integer :: i, iv, ifound, node1, node2, node3, node4
1971 real (r8) :: s, r_psi(*), s_psi(*), dpsi_dr(*), dpsi_ds(*), psi_test
1974 r_psi(ifound) = -1.e0_r8 ; s_psi(ifound) = s
1975 elseif (iv .eq. 2)
then
1976 r_psi(ifound) = s ; s_psi(ifound) = 1.e0_r8
1977 elseif (iv .eq. 3)
then
1978 r_psi(ifound) = +1.e0_r8 ; s_psi(ifound) = s
1979 elseif (iv .eq. 4)
then
1980 r_psi(ifound) = s ; s_psi(ifound) = -1.e0_r8
1983 node1 = elm_list(1,i); node2 = elm_list(2,i); node3 = elm_list(3,i); node4 = elm_list(4,i)
1985 call
interp2(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4), &
1986 r_psi(ifound),s_psi(ifound),psi_test,dpsi_dr(ifound),dpsi_ds(ifound))
1997 integer :: j, k,ip, nplot, node1, node2, node3, node4, i_elm
1998 real (r8) :: t, rr1, rr2, drr1, drr2, ss1, ss2, dss1, dss2, ri, si, dri, dsi, dummy1, dummy2
1999 real (r8),
allocatable :: rplot(:), zplot(:)
2000 character*13 :: label
2003 allocate(rplot(nplot),zplot(nplot))
2005 label=
'Flux surfaces'
2007 if (((z_max-z_min)/(
r_max-
r_min)) .lt. 1.5e0_r8 )
then
2008 CALL
nframe(2,21,1,
r_min,
r_max,z_min,z_max,label,13,
'R [m]',5,
'Z [m]',5)
2010 CALL
nframe(22,1,1,
r_min,
r_max,z_min,z_max,label,13,
'R [m]',5,
'Z [m]',5)
2017 do k=1,flux_surfaces(j)%n_pieces
2019 i_elm = flux_surfaces(j)%elm(k)
2021 node1 = elm_list(1,i_elm)
2022 node2 = elm_list(2,i_elm)
2023 node3 = elm_list(3,i_elm)
2024 node4 = elm_list(4,i_elm)
2026 rr1 = flux_surfaces(j)%r(1,k)
2027 drr1 = flux_surfaces(j)%r(2,k)
2028 rr2 = flux_surfaces(j)%r(3,k)
2029 drr2 = flux_surfaces(j)%r(4,k)
2031 ss1 = flux_surfaces(j)%s(1,k)
2032 dss1 = flux_surfaces(j)%s(2,k)
2033 ss2 = flux_surfaces(j)%s(3,k)
2034 dss2 = flux_surfaces(j)%s(4,k)
2038 t = -1. + 2.*float(ip-1)/float(nplot-1)
2040 call
cub1d(rr1, drr1, rr2, drr2, t, ri, dri)
2041 call
cub1d(ss1, dss1, ss2, dss2, t, si, dsi)
2043 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),ri,si,rplot(ip),dummy1,dummy2)
2044 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),ri,si,zplot(ip),dummy1,dummy2)
2050 if (i_elm .eq. flux_surfaces(j)%elm(k-1))
then
2052 write(51,*)
' 1 setlinewidth '
2053 elseif (i_elm .eq. flux_surfaces(j)%elm(k+1))
then
2055 write(51,*)
' 2 setlinewidth '
2058 write(51,*)
' .5 setlinewidth '
2062 call
lplot6(22,1,rplot,zplot,-nplot,
' ')
2080 real (r8) :: r_av(*), or_av(*), sum_dl, sum_rav, sum_orav
2081 integer :: i_elm, j, k, n1, n2, n3, node1, node2, node3, node4
2082 real (r8) :: t,rr1, rr2, drr1, drr2, ss1, ss2, dss1, dss2, ri, si, dri, dsi, dl
2083 real (r8) :: rrgi, drrgi_dr, drrgi_ds, zzgi, dzzgi_dr, dzzgi_ds, drrgi_dt, dzzgi_dt
2084 real (r8) :: psgi, dpsgi_dr, dpsgi_ds, psi_r, psi_z, rzjac, grad_psi
2094 do k=1, flux_surfaces(j)%n_pieces
2100 rr1 = flux_surfaces(j)%r(1,k)
2101 drr1 = flux_surfaces(j)%r(2,k)
2102 rr2 = flux_surfaces(j)%r(3,k)
2103 drr2 = flux_surfaces(j)%r(4,k)
2105 ss1 = flux_surfaces(j)%s(1,k)
2106 dss1 = flux_surfaces(j)%s(2,k)
2107 ss2 = flux_surfaces(j)%s(3,k)
2108 dss2 = flux_surfaces(j)%s(4,k)
2110 call
cub1d(rr1, drr1, rr2, drr2, t, ri, dri)
2111 call
cub1d(ss1, dss1, ss2, dss2, t, si, dsi)
2113 i_elm = flux_surfaces(j)%elm(k)
2115 node1 = elm_list(1,i_elm)
2116 node2 = elm_list(2,i_elm)
2117 node3 = elm_list(3,i_elm)
2118 node4 = elm_list(4,i_elm)
2121 call
interp2(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4),ri,si,psgi,dpsgi_dr,dpsgi_ds)
2122 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),ri,si,rrgi,drrgi_dr,drrgi_ds)
2123 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),ri,si,zzgi,dzzgi_dr,dzzgi_ds)
2125 drrgi_dt = drrgi_dr * dri + drrgi_ds * dsi
2126 dzzgi_dt = dzzgi_dr * dri + dzzgi_ds * dsi
2128 dl = sqrt(drrgi_dt**2 + dzzgi_dt**2)
2130 rzjac = drrgi_dr * dzzgi_ds - drrgi_ds * dzzgi_dr
2132 psi_r = ( dpsgi_dr * dzzgi_ds - dpsgi_ds * dzzgi_dr ) / rzjac
2133 psi_z = ( - dpsgi_dr * drrgi_ds + dpsgi_ds * drrgi_dr ) / rzjac
2135 grad_psi = sqrt(psi_r * psi_r + psi_z * psi_z)
2138 sum_dl = sum_dl + wgauss(ig) * dl * rrgi / grad_psi
2139 sum_rav = sum_rav + wgauss(ig) * rrgi * dl * rrgi / grad_psi
2140 sum_orav = sum_orav + wgauss(ig) / rrgi * dl * rrgi / grad_psi
2146 r_av(j) = sum_rav / sum_dl
2147 or_av(j) = sum_orav / sum_dl
2152 or_av(1) = 1.e0_r8/ r_axis
2177 integer :: n_int,n_var
2178 real (r8) :: powers(n_var,n_int), results(n_psi+1,n_int)
2179 integer :: i_elm, j, k, n1, n2, n3, node1, node2, node3, node4
2180 real (r8) :: t,rr1, rr2, drr1, drr2, ss1, ss2, dss1, dss2, ri, si, dri, dsi, dl
2181 real (r8) :: rrgi, drrgi_dr, drrgi_ds, zzgi, dzzgi_dr, dzzgi_ds, drrgi_dt, dzzgi_dt
2182 real (r8) :: psgi, dpsgi_dr, dpsgi_ds, psi_r, psi_z, rzjac, grad_psi, psi_n
2183 real (r8) :: sum_dl, b_tot2
2184 integer :: i,m, ig, ip
2187 write(*,*)
' flux_surface_integrals : ',n_psi,n_int,n_var
2189 results(1:n_psi+1,1:n_int) = 0.e0_r8
2193 psi_n = 1.e0_r8 - psi_values(i)/ps_axis
2197 do k=1, flux_surfaces(i)%n_pieces
2203 rr1 = flux_surfaces(i)%r(1,k)
2204 drr1 = flux_surfaces(i)%r(2,k)
2205 rr2 = flux_surfaces(i)%r(3,k)
2206 drr2 = flux_surfaces(i)%r(4,k)
2208 ss1 = flux_surfaces(i)%s(1,k)
2209 dss1 = flux_surfaces(i)%s(2,k)
2210 ss2 = flux_surfaces(i)%s(3,k)
2211 dss2 = flux_surfaces(i)%s(4,k)
2213 call
cub1d(rr1, drr1, rr2, drr2, t, ri, dri)
2214 call
cub1d(ss1, dss1, ss2, dss2, t, si, dsi)
2216 i_elm = flux_surfaces(i)%elm(k)
2218 node1 = elm_list(1,i_elm)
2219 node2 = elm_list(2,i_elm)
2220 node3 = elm_list(3,i_elm)
2221 node4 = elm_list(4,i_elm)
2223 call
interp2(psi(:,node1),psi(:,node2),psi(:,node3),psi(:,node4),ri,si,psgi,dpsgi_dr,dpsgi_ds)
2224 call
interp2(rr(:,node1),rr(:,node2),rr(:,node3),rr(:,node4),ri,si,rrgi,drrgi_dr,drrgi_ds)
2225 call
interp2(zz(:,node1),zz(:,node2),zz(:,node3),zz(:,node4),ri,si,zzgi,dzzgi_dr,dzzgi_ds)
2227 drrgi_dt = drrgi_dr * dri + drrgi_ds * dsi
2228 dzzgi_dt = dzzgi_dr * dri + dzzgi_ds * dsi
2230 dl = sqrt(drrgi_dt**2 + dzzgi_dt**2)
2232 rzjac = drrgi_dr * dzzgi_ds - drrgi_ds * dzzgi_dr
2234 psi_r = ( dpsgi_dr * dzzgi_ds - dpsgi_ds * dzzgi_dr ) / rzjac
2235 psi_z = ( - dpsgi_dr * drrgi_ds + dpsgi_ds * drrgi_dr ) / rzjac
2237 grad_psi = sqrt(psi_r * psi_r + psi_z * psi_z)
2239 b_tot2 = (
fdia(psi_n) / rrgi)**2 + (grad_psi/ rrgi)**2
2241 sum_dl = sum_dl + wgauss(ig) * dl
2244 results(i+1,m) = results(i+1,m) + wgauss(ig) * dl &
2245 * rrgi**powers(1,m) &
2246 * b_tot2**powers(2,m) &
2247 * grad_psi**powers(3,m)
2263 results(1,m) = r_axis**powers(1,m) * b_axis**powers(2,m)
2265 if (powers(3,m) .eq. -1.e0_r8)
then
2266 results(1,m) = results(1,m) * pi / sqrt(crr_axis*czz_axis)
2267 elseif (powers(3,m) .gt. 0.e0_r8)
then
2268 results(1,m) = 0.e0_r8
2277 powers,n_int,n_var,results,q, vprime)
2299 real (r8) :: rr_flux(4,*),zz_flux(4,*),ps_flux(4,*)
2300 integer :: n_int,n_var, nr_flux, np_flux
2301 real (r8) :: powers(n_var,n_int), results(nr_flux,n_int), q(nr_flux), vprime(nr_flux)
2302 integer :: i, j, k, m, n1, n2, n3, n4, ngs
2303 real (r8) :: rrg1, drrg1_dr, drrg1_ds, zzg1, dzzg1_dr, dzzg1_ds, drrg1_dt, dzzg1_dt
2304 real (r8) :: psg1, dpsg1_dr, dpsg1_ds, psi_r, psi_z, rzjac, grad_psi, ws
2305 real (r8) :: r, s, dl, sum_dl, b_tot2, bphi, grad_psi2, zjdchi, psi_n
2308 write(*,*)
' flux_surface_integrals : ',n_psi,n_int,n_var
2309 write(*,*)
' nr_flux : ',nr_flux
2311 if (nr_flux .ne. n_psi+1)
write(*,*)
' MAJOR PORBLEM in helena_fluxsurface_integral',nr_flux,n_psi
2314 results(1:n_psi+1,1:n_int) = 0.e0_r8
2326 n1 = (i-1)*np_flux + j
2327 n2 = (i-1)*np_flux + j + 1
2328 n3 = (i )*np_flux + j + 1
2329 n4 = (i )*np_flux + j
2331 if (j .eq. np_flux)
then
2333 n2 = (i )*np_flux - np_flux + 1
2334 n3 = (i )*np_flux + 1
2335 n4 = (i )*np_flux + np_flux
2344 call
interp2(rr_flux(1,n1),rr_flux(1,n2),rr_flux(1,n3),rr_flux(1,n4),r,s,rrg1,drrg1_dr,drrg1_ds)
2345 call
interp2(zz_flux(1,n1),zz_flux(1,n2),zz_flux(1,n3),zz_flux(1,n4),r,s,zzg1,dzzg1_dr,dzzg1_ds)
2346 call
interp2(ps_flux(1,n1),ps_flux(1,n2),ps_flux(1,n3),ps_flux(1,n4),r,s,psg1,dpsg1_dr,dpsg1_ds)
2348 rzjac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
2350 dl = sqrt(drrg1_ds**2 + dzzg1_ds**2)
2352 if(rzjac .eq. 0.0_r8)
then
2353 write(*,*)
'Warning: RZjac == 0, grad_psi2 set to 0.0'
2356 grad_psi2= dpsg1_dr**2 * (drrg1_ds**2 + dzzg1_ds**2) / rzjac**2
2359 if(dpsg1_dr .eq. 0.0_r8)
then
2360 write(*,*)
'Warning: dPSg1_dr == 0, ZJDCHI set to 0.0'
2363 zjdchi = 2.e0_r8 * pi * rrg1 * rzjac / dabs(dpsg1_dr)
2366 psi_n = - (psg1 - ps_axis) / ps_axis
2368 bphi =
fdia(psi_n) / rrg1
2370 b_tot2 = bphi**2 + grad_psi2/rrg1**2
2372 sum_dl = sum_dl + ws * dl
2374 q(i+1) = q(i+1) + ws / (rrg1 * sqrt(grad_psi2)) * dl
2375 vprime(i+1) = vprime(i+1) + ws * zjdchi
2386 results(i+1,m) = results(i+1,m) + ws * zjdchi &
2387 * rrg1**powers(1,m) &
2388 * b_tot2**powers(2,m) &
2389 * sqrt(grad_psi2)**powers(3,m)
2397 results(i+1,1:n_int) = results(i+1,1:n_int) / vprime(i+1)
2402 q(1) = pi / (r_axis * sqrt(crr_axis*czz_axis))
2406 results(1,m) = r_axis**powers(1,m) * b_axis**powers(2,m)
2408 if (powers(3,m) .eq. -1.e0_r8)
then
2409 results(1,m) = results(1,m) * pi / sqrt(crr_axis*czz_axis)
2410 elseif (powers(3,m) .gt. 0.e0_r8)
then
2411 results(1,m) = 0.e0_r8
2424 real (r8) :: a,b,c,d,e,f,x,y, det
2428 if (det .ne. 0.e0_r8)
then
2429 x = ( d * e - b * f ) / det
2430 y = ( - c * e + a * f ) / det
2439 SUBROUTINE solvp3(C0,C1,C2,C3,X1,X2,X3,IFAIL)
2446 real (r8) :: c0, c1, c2, c3, x1, x2, x3, dum, tol, angle
2447 real (r8) :: a0, a1, a2, aa, bb, cc, det, pi,
p, q, u, v
2457 IF (abs(c3)/(abs(c1)+abs(c2)+abs(c3)) .LT. 1.d-9)
THEN
2461 det = bb**2 - 4*aa*cc
2463 x1 =
root(aa,bb,cc,det,1.e0_r8)
2464 IF (abs(x1).GT. 1.e0_r8 + tol)
THEN
2465 x1 =
root(aa,bb,cc,det,-1.e0_r8)
2473 pi = 2*asin(1.e0_r8)
2477 p = - (a2**2)/3.e0_r8 + a1
2478 q = 2.e0_r8/27.e0_r8*(a2**3) - a2 * a1/3.e0_r8 + a0
2479 det = (
p/3.e0_r8)**3 + (q/2.e0_r8)**2
2480 IF (det .GE. 0)
THEN
2481 u = sign(1.e0_r8,-q/2.e0_r8+sqrt(det))*abs(-q/2.e0_r8 + sqrt(det))**(1.e0_r8/3.e0_r8)
2482 v = sign(1.e0_r8,-q/2.e0_r8-sqrt(det))*abs(-q/2.e0_r8 - sqrt(det))**(1.e0_r8/3.e0_r8)
2483 x1 = u + v - a2/3.e0_r8
2484 IF (abs(x1) .GE. (1.e0_r8+tol)) ifail = 1
2487 angle = sign(1.e0_r8,
p)*acos((q/2.e0_r8)/sqrt(abs(
p)/3.e0_r8)**3)
2488 x1 = -2.e0_r8*sqrt(abs(
p)/3.e0_r8)*cos(angle/3.e0_r8) - a2/3.e0_r8
2489 x2 = -2.e0_r8*sqrt(abs(
p)/3.e0_r8)*cos(2*pi/3.e0_r8 - angle/3.e0_r8) - a2/3.e0_r8
2490 x3 = -2.e0_r8*sqrt(abs(
p)/3.e0_r8)*cos(2*pi/3.e0_r8 + angle/3.e0_r8) - a2/3.e0_r8
2492 IF (abs(x1) .GT. abs(x2))
THEN
2497 IF (abs(x2) .GT. abs(x3))
THEN
2502 IF (abs(x1) .GT. abs(x2))
THEN
2508 IF (abs(x1) .GT. (1.e0_r8 + tol)) ifail=1
2520 real (r8) ::
root,a, b, c, d, sgn
2522 IF (b*sgn .GE. 0.e0_r8)
THEN
2523 root = -2.e0_r8*c/(b+sgn*sqrt(d))
2525 root = (-b + sgn*sqrt(d)) / (2.e0_r8 * a)
2536 real (r8) :: psimin, psimax, psma, psmi, psmima, psim, psimr, psip, psipr
2537 real (r8) :: aa, bb, cc, det, r, dummy
2538 integer :: i, n, im, n1, n2
2554 ELSEif (i .eq. 2)
then
2559 ELSEIF (i .eq. 3)
then
2564 ELSEIF (i .eq. 4)
then
2571 psma = max(psim,psip)
2572 psmi = min(psim,psip)
2573 aa = 3.e0_r8 * (psim + psimr - psip + psipr ) / 4.e0_r8
2574 bb = ( - psimr + psipr ) / 2.e0_r8
2575 cc = ( - 3*psim - psimr + 3*psip - psipr) / 4.e0_r8
2576 det = bb**2 - 4*aa*cc
2577 IF (det .GE. 0.e0_r8)
THEN
2578 r = (-bb + sqrt(bb**2-4*aa*cc) ) / (2*aa)
2579 IF (abs(r) .GT. 1.e0_r8)
THEN
2580 r = (-bb - sqrt(bb**2-4*aa*cc) ) / (2*aa)
2582 IF (abs(r) .LE. 1.e0_r8)
THEN
2583 CALL
cub1d(psim,psimr,psip,psipr,r,psmima,dummy)
2584 psma = max(psma,psmima)
2585 psmi = min(psmi,psmima)
2588 psimin = min(psimin,psmi)
2589 psimax = max(psimax,psma)
2602 real (r8) :: thtmin, thtmax, theta
2603 integer :: i, node, n
2609 node = elm_list(i,n)
2610 theta = atan2(zz(1,node)-z_axis,rr(1,node)-r_axis)
2611 if (theta .lt. 0.)
then
2612 theta = theta + 2.e0_r8*pi
2614 thtmin = min(theta,thtmin)
2615 thtmax = max(theta,thtmax)
2621 subroutine initialise_profiles(n_prof_in,iopt_p,iopt_f,psi_in, pprime_in, ffprime_in,pressure_in, fdia_in, current_in)
2639 real (r8) :: psi, dpsi, sump, sumf, f0, f_old, f_tmp
2640 real (r8),
allocatable :: psi_norm(:), psi_prof(:), sp1(:) ,sp2(:), sp3(:), sp4(:)
2641 real (r8) :: pprime_in(*), ffprime_in(*), pressure_in(*), fdia_in(*), current_in(*), psi_in(*)
2642 integer :: i, n_prof_in, iopt_p, iopt_f
2643 real (r8) :: abltg(3), p_tmp, si, rbnd_av, orbnd_av, r_av, or_av, ps0, ps1
2646 write(*,
'(A)')
' **************************************'
2647 write(*,
'(A,i7,A)')
' * initialising profiles',n_prof_in,
' *'
2648 write(*,
'(A)')
' **************************************'
2651 ps1 = psi_in(n_prof_in)
2652 ps_axis = abs(ps1 - ps0)
2654 p_bnd = pressure_in(n_prof_in)
2656 allocate(psi_norm(n_prof_in))
2659 psi_norm(i) = (psi_in(i)- ps0)/(ps1 - ps0)
2663 allocate(sp1(n_prof_in),sp2(n_prof_in),sp3(n_prof_in),sp4(n_prof_in))
2666 allocate(psi_prof(n_prof),
dp_dpsi(n_prof), zjz_psi(n_prof), fdf_dpsi(n_prof))
2668 if (iopt_p .eq. 1)
then
2670 write(*,*)
' HELENA : using pressure profile as input'
2672 call
spline(n_prof_in,psi_norm,pressure_in,0.e0_r8,0.e0_r8,2,sp1,sp2,sp3,sp4)
2676 psi_prof(i) = float(i-1)/float(n_prof-1)
2678 p_tmp =
spwert(n_prof_in,psi_prof(i),sp1,sp2,sp3,sp4,psi_norm,abltg)
2680 dp_dpsi(i) = abltg(1) / abs(ps_axis)
2689 write(*,*)
' HELENA : using pprime profile as input'
2691 call
spline(n_prof_in,psi_norm,pprime_in,0.e0_r8,0.e0_r8,2,sp1,sp2,sp3,sp4)
2695 psi_prof(i) = float(i-1)/float(n_prof-1)
2697 dp_dpsi(i) =
spwert(n_prof_in,psi_prof(i),sp1,sp2,sp3,sp4,psi_norm,abltg)
2703 if (iopt_f .eq. 1)
then
2705 write(*,*)
' HELENA : using fdia profile as input'
2707 call
spline(n_prof_in,psi_norm,fdia_in,0.0_r8,0.0_r8,2,sp1,sp2,sp3,sp4)
2711 psi_prof(i) = float(i-1)/float(n_prof-1)
2713 f_tmp =
spwert(n_prof_in,psi_prof(i),sp1,sp2,sp3,sp4,psi_norm,abltg)
2715 fdf_dpsi(i) = f_tmp * abltg(1) / abs(ps_axis)
2719 fdf_dpsi(1) = fdf_dpsi(3)
2720 fdf_dpsi(2) = fdf_dpsi(3)
2722 elseif ((iopt_f .eq. 2) .or. (iopt_f .eq. 3))
then
2724 write(*,*)
' HELENA : using ffprime profile as input'
2726 call
spline(n_prof_in,psi_norm,ffprime_in,0.e0_r8,0.e0_r8,2,sp1,sp2,sp3,sp4)
2730 psi_prof(i) = float(i-1)/float(n_prof-1)
2732 fdf_dpsi(i) =
spwert(n_prof_in,psi_prof(i),sp1,sp2,sp3,sp4,psi_norm,abltg)
2736 elseif ((iopt_f .eq. 3) .or. (iopt_f .eq. 4))
then
2739 write(*,*)
' HELENA : using current profile as input'
2741 call
spline(n_prof_in,psi_norm,current_in,0.e0_r8,0.e0_r8,2,sp1,sp2,sp3,sp4)
2746 rbnd_av = rbnd_av + r_bnd(i)
2747 orbnd_av = orbnd_av + 1.e0_r8/ r_bnd(i)
2749 rbnd_av = rbnd_av / float(n_bnd)
2750 orbnd_av = orbnd_av / float(n_bnd)
2754 zjz_psi(i) =
spwert(n_prof_in,psi_prof(i),sp1,sp2,sp3,sp4,psi_norm,abltg)
2756 si = sqrt(psi_prof(i))
2758 r_av = rgeo + si * ( rbnd_av - rgeo)
2759 or_av = 1./rgeo + si * (orbnd_av - 1./rgeo)
2761 if (iopt_f .eq. 4) fdf_dpsi(i) = ( mu_zero * ( - zjz_psi(i) - r_av *
dp_dpsi(i) )/ or_av )
2767 allocate(p_psi(n_prof),f_psi(n_prof))
2769 dpsi = 1./float(n_prof)
2775 p_psi(n_prof) = p_bnd
2777 do i = 1, n_prof - 1
2779 p_psi(n_prof-i) = sump * abs(ps_axis) + p_bnd
2781 sumf = sumf - (fdf_dpsi(n_prof-i+1)+fdf_dpsi(n_prof-i))*dpsi/2.
2782 f_psi(n_prof-i) = sumf * abs(ps_axis)
2788 call
lplot6(2,3,psi_prof,fdf_dpsi,n_prof,
'fdf/dpsi')
2789 call
lplot6(3,2,psi_prof,p_psi,n_prof,
'pressure')
2790 call
lplot6(3,3,psi_prof,f_psi,n_prof,
'F**2-F0**2')
2800 integer :: i, ngr, ngs, kf, kv, vertex, nodes(4), nc
2801 real (r8) :: psi_max, psi_min, rmin, rmax, zmin, zmax, zc(3)
2802 real (r8) :: xx(4,4), yy(4,4), ps(4,4)
2803 character*19 :: label
2807 psi_max = maxval(psi(1,:))
2808 psi_min = minval(psi(1,:))
2810 CALL
nframe(22,11,1,
r_min,
r_max,z_min,z_max,label,19,
'R [m]',5,
'Z [m]',5)
2813 zc(1) = -max(abs(psi_max),abs(psi_min))
2819 nodes(1) = elm_list(1,i)
2820 nodes(2) = elm_list(2,i)
2821 nodes(3) = elm_list(3,i)
2822 nodes(4) = elm_list(4,i)
2836 xx(ngr,ngs) = xx(ngr,ngs) + rr(kf,vertex) * h(ngr,ngs,kv,kf)
2837 yy(ngr,ngs) = yy(ngr,ngs) + zz(kf,vertex) * h(ngr,ngs,kv,kf)
2838 ps(ngr,ngs) = ps(ngr,ngs) + psi(kf,vertex) * h(ngr,ngs,kv,kf)
2845 call
cplotm(2,1,-2,xx,yy,4,-4,1,1,ps,4,zc,nc,
'Solution',8,
'R [m]',5,
'Z [m]',5)
2858 integer :: i, n1, n2, n3, n4
2859 real (r8) :: rmin, rmax, zmin, zmax
2860 character*19 :: label
2862 label=
'FINITE ELEMENT GRID'
2864 rmin = minval(rr(1,1:nr*np)); rmax = maxval(rr(1,1:nr*np))
2865 zmin = minval(zz(1,1:nr*np)); zmax = maxval(zz(1,1:nr*np))
2867 CALL
nframe(22,11,1,rmin,rmax,zmin,zmax,label,19,
'R [m]',5,
'Z [m]',5)
2876 call
plotcu(rr(1,n1), rr(3,n1), zz(1,n1), zz(3,n1), rr(1,n2), rr(3,n2), zz(1,n2), zz(3,n2))
2877 call
plotcu(rr(1,n2), rr(2,n2), zz(1,n2), zz(2,n2), rr(1,n3), rr(2,n3), zz(1,n3), zz(2,n3))
2878 call
plotcu(rr(1,n4), rr(3,n4), zz(1,n4), zz(3,n4), rr(1,n3), rr(3,n3), zz(1,n3), zz(3,n3))
2879 call
plotcu(rr(1,n1), rr(2,n1), zz(1,n1), zz(2,n1), rr(1,n4), rr(2,n4), zz(1,n4), zz(2,n4))
2893 logical :: solve_only
2894 integer :: i, j, istart, info
2895 real (r8) :: error_iteration, amix
2899 if (.not. solve_only )
then
2900 call dpbtrf(
'L',n_matrix,n_diag,aa,lda,info)
2901 if (info .ne. 0)
write(*,*)
' dpbtrf : ',info
2904 call dpbtrs(
'L',n_matrix,n_diag,1,aa,lda,bb,n_matrix,info)
2905 if (info .ne. 0)
write(*,*)
' dpbtrs : ',info
2911 error_iteration = error_iteration + abs(psi(j,index_inverse(i)) - bb(4*(i-1)+j))
2912 psi(j,index_inverse(i)) = amix * psi(j,index_inverse(i)) + (1. - amix) * bb(4*(i-1)+j)
2916 error_iteration = error_iteration / float(4*n_nodes)
2933 real (r8) :: xx(4,4), xr(4,4), xs(4,4), yr(4,4), ys(4,4), xjac(4,4), ps(4,4), psn(4,4)
2934 real (r8) :: vx(4,4,4,4), vy(4,4,4,4), rhs(4,4)
2935 real (r8) :: ps_axis, sumq, sumk
2936 integer :: ngr, ngs, kf, kv, lf ,lv, i, vertex, nrow, nrow2, ncol, ncol2
2938 integer n_dof,noff,jstart,j
2943 n_diag = 4*(np+1) + 7
2945 if (.not.
allocated(aa))
allocate(aa(lda,n_dof))
2946 if (.not.
allocated(bb))
allocate(bb(n_dof))
2948 if (.not. rhs_only) aa = 0.
2953 nodes(1) = elm_list(1,i)
2954 nodes(2) = elm_list(2,i)
2955 nodes(3) = elm_list(3,i)
2956 nodes(4) = elm_list(4,i)
2972 xx(ngr,ngs) = xx(ngr,ngs) + rr(kf,vertex) * h(ngr,ngs,kv,kf)
2973 ps(ngr,ngs) = ps(ngr,ngs) + psi(kf,vertex) * h(ngr,ngs,kv,kf)
2975 xr(ngr,ngs) = xr(ngr,ngs) + rr(kf,vertex) * hr(ngr,ngs,kv,kf)
2976 xs(ngr,ngs) = xs(ngr,ngs) + rr(kf,vertex) * hs(ngr,ngs,kv,kf)
2977 yr(ngr,ngs) = yr(ngr,ngs) + zz(kf,vertex) * hr(ngr,ngs,kv,kf)
2978 ys(ngr,ngs) = ys(ngr,ngs) + zz(kf,vertex) * hs(ngr,ngs,kv,kf)
2983 xjac(ngr,ngs) = xr(ngr,ngs)*ys(ngr,ngs) - xs(ngr,ngs)*yr(ngr,ngs)
2988 psn(:,:) = (ps_axis - ps(:,:)) / ps_axis
2993 rhs(ngr,ngs) = - (
fdfdpsi(psn(ngr,ngs)) + mu_zero * xx(ngr,ngs)*xx(ngr,ngs)*
dpdpsi(psn(ngr,ngs)) ) &
2994 * wgauss(ngr)*wgauss(ngs) * xjac(ngr,ngs) / xx(ngr,ngs)
3004 vx(ngr,ngs,kf,kv) = ys(ngr,ngs) * hr(ngr,ngs,kv,kf) - yr(ngr,ngs) * hs(ngr,ngs,kv,kf)
3005 vy(ngr,ngs,kf,kv) = -xs(ngr,ngs) * hr(ngr,ngs,kv,kf) + xr(ngr,ngs) * hs(ngr,ngs,kv,kf)
3014 nrow = 4*(index_list(nodes(kv)) - 1)
3025 sumq = sumq - rhs(ngr,ngs) * h(ngr,ngs,kv,kf)
3030 bb(nrow2) = bb(nrow2) + sumq
3032 if (.not. rhs_only)
then
3036 ncol = 4*(index_list(nodes(lv)) - 1)
3042 noff = nrow2 - ncol2
3044 if (noff .ge. 0)
then
3051 sumk = sumk + wgauss(ngr)*wgauss(ngs) / (xjac(ngr,ngs) * xx(ngr,ngs)) &
3052 * (vx(ngr,ngs,lf,lv) * vx(ngr,ngs,kf,kv) + vy(ngr,ngs,lf,lv) * vy(ngr,ngs,kf,kv))
3057 aa(noff+1,ncol2) = aa(noff+1,ncol2) + sumk
3070 if (.not. rhs_only)
then
3071 jstart = 4.*(nr-1)*np
3073 aa(1,jstart+4*j-1) = 1.e20
3074 aa(1,jstart+4*j-3) = 1.e20
3087 integer :: i,j, ij1, ijn, jn, k, l, ngr, ngs, kv, kf, i0, j0
3088 real (r8) :: r, s, r0, s0
3092 allocate(elm_list(4,n_elms), index_list(n_nodes), index_inverse(n_nodes))
3098 elm_list(1,k) = (i-1)*np + j
3099 elm_list(2,k) = (i-1)*np + j + 1
3100 elm_list(3,k) = (i )*np + j + 1
3101 elm_list(4,k) = (i )*np + j
3104 elm_list(1,k) = (i )*np
3105 elm_list(2,k) = (i )*np - np + 1
3106 elm_list(3,k) = (i )*np + 1
3107 elm_list(4,k) = (i )*np + np
3110 write(*,*)
' number of elements : ',k
3115 index_list(ij1) = ij1
3116 index_inverse(ij1) = ij1
3119 ij1 = (i-1)*np + j + 1
3120 ijn = (i-1)*np + 2*j
3121 index_list(ij1) = ijn
3122 index_inverse(ijn) = ij1
3127 ijn = (i-1)*np + 2*j + 1
3128 index_list(ij1) = ijn
3129 index_inverse(ijn) = ij1
3134 rs(1,1) = -1.; rs(1,2) = -1.; rs(2,1) = -1.; rs(2,2) = +1.
3135 rs(3,1) = +1.; rs(3,2) = +1.; rs(4,1) = +1.; rs(4,2) = -1.
3136 ij(1,1) = 0; ij(1,2) = 0; ij(2,1) = 1; ij(2,2) = 0
3137 ij(3,1) = 0; ij(3,2) = 1; ij(4,1) = 1; ij(4,2) = 1
3154 call
cubich(i0,j0,r0,s0,r,s,h(ngr,ngs,kv,kf), hr(ngr,ngs,kv,kf), hs(ngr,ngs,kv,kf),&
3155 hrs(ngr,ngs,kv,kf),hrr(ngr,ngs,kv,kf),hss(ngr,ngs,kv,kf))
3176 integer :: i, j, m, node
3177 real (r8) :: theta(np), s(nr)
3178 real (r8) :: pi, dt, dr, rm, drm, drmt, drmtr, radius, thtj
3180 allocate(rr(4,nr*np),zz(4,nr*np),psi(4,nr*np))
3187 theta(j) = dt *
real(j-1)
3191 s(i) = float(i-1)/float(nr-1)
3200 rr(1,node) = rgeo + radius * fr(1) * cos(thtj) / 2.
3201 rr(2,node) = fr(1) * cos(thtj) / 2.
3202 rr(3,node) = - radius * fr(1) * sin(thtj) / 2.
3203 rr(4,node) = - fr(1) * sin(thtj) / 2.
3204 zz(1,node) = zgeo + radius * fr(1) * sin(thtj) / 2.
3205 zz(2,node) = fr(1) * sin(thtj) / 2.
3206 zz(3,node) = radius * fr(1) * cos(thtj) / 2.
3207 zz(4,node) = fr(1) * cos(thtj) / 2.
3212 rm = radius * ( fr(2*m-1) * cos((m-1)*thtj) + fr(2*m) * sin((m-1)*thtj) )
3213 drm = ( fr(2*m-1) * cos((m-1)*thtj) + fr(2*m) * sin((m-1)*thtj))
3214 drmt = radius * (-fr(2*m-1) * (m-1)*sin((m-1)*thtj) + fr(2*m) * (m-1)*cos((m-1)*thtj))
3215 drmtr= (-fr(2*m-1) * (m-1)*sin((m-1)*thtj) + fr(2*m) * (m-1)*cos((m-1)*thtj))
3217 rm = radius**(m-1) * ( fr(2*m-1) * cos((m-1)*thtj) + fr(2*m) * sin((m-1)*thtj) )
3218 drm =(m-1)*radius**(m-2) * ( fr(2*m-1) * cos((m-1)*thtj) + fr(2*m) * sin((m-1)*thtj))
3219 drmt = radius**(m-1) * (-fr(2*m-1) * (m-1)*sin((m-1)*thtj) + fr(2*m) *(m-1)*cos((m-1)*thtj))
3220 drmtr=(m-1)*radius**(m-2) * (-fr(2*m-1) * (m-1)*sin((m-1)*thtj) + fr(2*m) *(m-1)*cos((m-1)*thtj))
3222 rr(1,node) = rr(1,node) + rm * cos(thtj)
3223 zz(1,node) = zz(1,node) + rm * sin(thtj)
3224 rr(2,node) = rr(2,node) + drm * cos(thtj)
3225 zz(2,node) = zz(2,node) + drm * sin(thtj)
3226 rr(3,node) = rr(3,node) - rm * sin(thtj) + drmt * cos(thtj)
3227 zz(3,node) = zz(3,node) + rm * cos(thtj) + drmt * sin(thtj)
3228 rr(4,node) = rr(4,node) - drm * sin(thtj) + drmtr * cos(thtj)
3229 zz(4,node) = zz(4,node) + drm * cos(thtj) + drmtr * sin(thtj)
3231 rr(2,node) = rr(2,node) * dr/2.
3232 rr(3,node) = rr(3,node) * dt/2.
3233 rr(4,node) = rr(4,node) * dr/2. * dt/2.
3234 zz(2,node) = zz(2,node) * dr/2.
3235 zz(3,node) = zz(3,node) * dt/2.
3236 zz(4,node) = zz(4,node) * dr/2. * dt/2.
3238 psi(1,node) = radius **2 - 1.
3239 psi(2,node) = 2.* radius * dr / 2.
3246 r_min = minval(rr(1,:))
3247 r_max = maxval(rr(1,:))
3248 z_min = minval(zz(1,:))
3249 z_max = maxval(zz(1,:))
3260 real (r8) :: r(4,*),z(4,*), rmin, rmax, zmin, zmax
3261 character*19 :: label
3262 integer :: nr, np, nbase, i, j
3264 label=
'FINITE ELEMENT GRID'
3266 rmin = minval(r(1,1:nr*np)); rmax = maxval(r(1,1:nr*np))
3267 zmin = minval(z(1,1:nr*np)); zmax = maxval(z(1,1:nr*np))
3269 CALL
nframe(22,1,1,rmin,rmax,zmin,zmax,label,19,
'R [m]',5,
'Z [m]',5)
3273 nbase = j + (i-1)*np
3274 call
plotcu(r(1,nbase), r(3,nbase), z(1,nbase), z(3,nbase), &
3275 r(1,nbase+1),r(3,nbase+1),z(1,nbase+1),z(3,nbase+1))
3280 nbase = j + (i-1)*np
3281 call
plotcu(r(1,nbase), r(2,nbase), z(1,nbase), z(2,nbase), &
3282 r(1,nbase+np),r(2,nbase+np), z(1,nbase+np),z(2,nbase+np))
3290 subroutine plotcu(X1,X1S,Y1,Y1S,X2,X2S,Y2,Y2S)
3299 real (r8) :: x1,x1s,y1,y1s,x2,x2s,y2,y2s
3300 real (r8) :: xp(nplot),yp(nplot), s, dummy
3303 s = -1. + 2.*float(i-1)/float(nplot-1)
3304 call
cub1d(x1,x1s,x2,x2s,s,xp(i),dummy)
3305 call
cub1d(y1,y1s,y2,y2s,s,yp(i),dummy)
3307 call
lplot6(2,1,xp,yp,-nplot,
' ')
3312 SUBROUTINE cubich(I,J,R0,S0,R,S,H,HR,HS,HRS,HRR,HSS)
3320 real (r8) :: h,hr,hs,hrs,hi,hri,hj,hsj,hrr,hss,hrri,hssj, r0, s0, r, s
3323 hi = - (r+r0)**2 * (r*r0-2.) / 4.
3324 hri = - (r+r0)*(r*r0-2.)/2. - r0*(r+r0)**2 / 4.
3325 hrri = - 1.5 * r * r0
3327 hi = + r0 * (r+r0)**2 * (r*r0 - 1.) / 4.
3328 hri = + r0*(r+r0)*(r*r0-1.)/2. + (r+r0)**2 /4.
3329 hrri = 1.5*r + .5*r0
3332 hj = - (s+s0)**2 * (s*s0-2.) / 4.
3333 hsj = - (s+s0)*(s*s0-2.)/2. - s0*(s+s0)**2 / 4.
3334 hssj = - 1.5 * s * s0
3336 hj = + s0 * (s+s0)**2 * (s*s0 - 1.) / 4.
3337 hsj = + s0*(s+s0)*(s*s0-1.)/2. + (s+s0)**2 / 4.
3338 hssj = 1.5*s + .5*s0
3355 real (r8) :: x1,x1s,x2,x2s,s,x,xs
3356 real (r8) :: h0m,h0p,h1m,h1p,h0ms,h0ps,h1ms,h1ps
3358 h0m = (s-1.e0_r8)**2 *(s+2.e0_r8) * 0.25e0_r8
3359 h0ms = (s-1.e0_r8)*(s+2.e0_r8)/2.e0_r8 + (s-1.e0_r8)**2 * 0.25e0_r8
3360 h0p = -(s+1.e0_r8)**2 *(s-2.e0_r8) * 0.25e0_r8
3361 h0ps = -(s+1.e0_r8)*(s-2.e0_r8)/2.e0_r8 - (s+1.e0_r8)**2 * 0.25e0_r8
3362 h1m = (s-1.e0_r8)**2 *(s+1.e0_r8) * 0.25e0_r8
3363 h1ms = (s-1.e0_r8)*(s+1.e0_r8)/2. + (s-1.e0_r8)**2 * 0.25e0_r8
3364 h1p = (s+1.e0_r8)**2 *(s-1.e0_r8) * 0.25e0_r8
3365 h1ps = (s+1.e0_r8)*(s-1.e0_r8)/2.e0_r8 + (s+1.e0_r8)**2 * 0.25e0_r8
3367 x = x1*h0m + x1s*h1m + x2*h0p + x2s*h1p
3368 xs = x1*h0ms + x1s*h1ms + x2*h0ps + x2s*h1ps
3371 end subroutine cub1d
3381 real (r8) :: xj, yj, ga
3382 real (r8),
allocatable :: theta(:), gamma(:), xv(:),yv(:)
3383 real (r8) :: angle, error, gamm
3384 real (r8),
allocatable :: tht_tmp(:), fr_tmp(:), work(:)
3385 real (r8),
allocatable :: tht_sort(:), fr_sort(:), dfr_sort(:)
3386 integer,
allocatable :: index_order(:)
3387 real (r8) :: tht, rbnd_av, orbnd_av, values(4)
3388 integer :: m, igrinv, i, j, ishape, ieast(1), iwest(1), n_bnd_short
3389 parameter(error = 1.d-8)
3392 allocate(theta(mf),gamma(mf),xv(mf),yv(mf))
3394 if (n_bnd .gt. 1)
then
3396 write(*,*)
' fshape : (R,Z) set given on ',n_bnd,
' points'
3398 reast = maxval(r_bnd)
3399 rwest = minval(r_bnd)
3400 ieast = maxloc(r_bnd)
3401 iwest = minloc(r_bnd)
3402 rgeo = (reast + rwest) /2.
3403 zgeo = (z_bnd(ieast(1))+z_bnd(iwest(1)))/2.
3404 amin = (reast - rwest)/2.
3406 write(*,
'(A,3f12.8)')
' Rgeo, Zgeo : ',rgeo,zgeo,amin
3408 allocate(tht_tmp(n_bnd),fr_tmp(n_bnd),work(3*n_bnd+6))
3409 allocate(tht_sort(n_bnd+2),fr_sort(n_bnd+2),dfr_sort(n_bnd+2))
3410 allocate(index_order(n_bnd+2))
3417 tht_tmp(i) = atan2(z_bnd(i)-zgeo,r_bnd(i)-rgeo)
3423 fr_tmp(i) = sqrt((r_bnd(i)-rgeo)**2 + (z_bnd(i)-zgeo)**2)
3427 rbnd_av = rbnd_av + r_bnd(i)
3428 orbnd_av = orbnd_av + 1. / r_bnd(i)
3432 if (abs(tht_tmp(n_bnd) - tht_tmp(1)) .lt. 1.e-6) n_bnd = n_bnd - 1
3434 rbnd_av = rbnd_av / float(n_bnd)
3435 orbnd_av = orbnd_av / float(n_bnd)
3440 call
qsort2(index_order,n_bnd,tht_tmp)
3443 tht_sort(i) = tht_tmp(index_order(i))
3444 fr_sort(i) = fr_tmp(index_order(i))
3451 if ((tht_sort(i) - tht_sort(1)) .gt. 2.*pi)
then
3458 if (abs(tht_sort(n_bnd_short)- tht_sort(1)) .lt. 1.e-6)
then
3459 tht_sort(n_bnd_short) = tht_sort(1) + 2.*pi
3460 fr_sort(n_bnd_short) = fr_sort(1)
3462 tht_sort(n_bnd_short+1) = tht_sort(1) + 2.*pi
3463 fr_sort(n_bnd_short+1) = fr_sort(1)
3464 n_bnd_short = n_bnd_short + 1
3469 call
tb15a(n_bnd_short,tht_sort,fr_sort,dfr_sort,work,6)
3473 tht = 2.*pi * float(i-1)/float(mf)
3475 if (tht .lt. tht_sort(1)) tht = tht + 2.*pi
3476 if (tht .gt. tht_sort(n_bnd_short)) tht = tht - 2.*pi
3478 call
tg02a(0,n_bnd_short,tht_sort,fr_sort,dfr_sort,tht,values)
3485 write(*,*)
' fshape : using moments'
3490 ga = 2*pi*(j-1.)/
REAL(mf)
3492 if (ga .le. pi)
then
3493 xj= amin * cos(ga + tria_u*sin(ga) + quad_u*sin(2*ga))
3494 yj= ellip * amin * sin(ga)
3496 xj= amin * cos(ga + tria_l*sin(ga) + quad_l*sin(2*ga))
3497 yj= ellip * amin * sin(ga)
3499 theta(j) = atan2(yj,xj)
3504 CALL
grid2nv(theta,gamma,mf,error,igrinv)
3509 if (ga .le. pi)
then
3510 xv(j) = amin * cos(gamm + tria_u*sin(gamm) + quad_u*sin(2*gamm))
3511 yv(j) = ellip * amin * sin(gamm)
3513 xv(j) = amin * cos(gamm + tria_l*sin(gamm) + quad_l*sin(2*gamm))
3514 yv(j) = ellip * amin * sin(gamm)
3520 fr(j) = sqrt(xv(j)**2 + yv(j)**2)
3523 deallocate(theta, gamma, xv, yv)
3531 fr(m) = 2. * fr(m) / float(mf)
3549 real (r8) :: ps_tmp(4,4), psi_min, axis_min
3550 integer :: nodes(4), i, ngr, ngs, kf, kv, vertex, elm_min, ij_axis(2), ifail
3551 real (r8) :: x(2), r, s, xerr, ferr, rs_tolerance, zpsir, zpsis
3552 real (r8) :: drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss
3553 real (r8) :: dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss
3554 real (r8) :: dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss
3555 real (r8) :: ejac, dr_dz, dr_dr, ds_dz, ds_dr, dps_drr, dps_dzz
3556 integer :: node1, node2, node3, node4
3558 logical :: early_exit
3559 parameter(rs_tolerance = 1.d-8)
3561 early_exit = .false.
3563 if ((ielm_ax .ge. 1) .and. (ielm_ax .le. n_elms))
then
3564 nodes(1) = elm_list(1,ielm_ax)
3565 nodes(2) = elm_list(2,ielm_ax)
3566 nodes(3) = elm_list(3,ielm_ax)
3567 nodes(4) = elm_list(4,ielm_ax)
3569 call
mnewtax(psi(1:4,nodes(1)),psi(1:4,nodes(2)),psi(1:4,nodes(3)),psi(1:4,nodes(4)),r,s,xerr,ferr,ifail)
3571 if ((ifail .eq. 0) .and. ((abs(r)-1.) .le. rs_tolerance) .and. ((abs(s)-1.) .le. rs_tolerance))
then
3573 call
interp2(psi(1:4,nodes(1)),psi(1:4,nodes(2)),psi(1:4,nodes(3)),psi(1:4,nodes(4)),r,s,ps_axis,zpsir,zpsis)
3574 call
interp1(rr(1:4,nodes(1)),rr(1:4,nodes(2)),rr(1:4,nodes(3)),rr(1:4,nodes(4)),r,s,r_axis)
3575 call
interp1(zz(1:4,nodes(1)),zz(1:4,nodes(2)),zz(1:4,nodes(3)),zz(1:4,nodes(4)),r,s,z_axis)
3580 write(*,*)
' EARLY EXIT !'
3581 write(*,
'(A,3f12.8)')
' magnetic axis : ',r_axis,z_axis,ps_axis
3582 write(*,
'(A,f12.8)')
' delta (EARLY EXIT) : ',(r_axis-rgeo)/amin
3588 if (.not. early_exit)
then
3594 nodes(1) = elm_list(1,i)
3595 nodes(2) = elm_list(2,i)
3596 nodes(3) = elm_list(3,i)
3597 nodes(4) = elm_list(4,i)
3609 ps_tmp(ngr,ngs) = ps_tmp(ngr,ngs) + psi(kf,vertex) * h(ngr,ngs,kv,kf)
3616 axis_min = minval(ps_tmp)
3618 if (psi_min .gt. axis_min)
then
3621 ij_axis = minloc(ps_tmp)
3626 nodes(1) = elm_list(1,elm_min)
3627 nodes(2) = elm_list(2,elm_min)
3628 nodes(3) = elm_list(3,elm_min)
3629 nodes(4) = elm_list(4,elm_min)
3631 r=xgauss(ij_axis(1)) ; s=xgauss(ij_axis(2))
3635 call
mnewtax(psi(1:4,nodes(1)),psi(1:4,nodes(2)),psi(1:4,nodes(3)),psi(1:4,nodes(4)),r,s,xerr,ferr,ifail)
3637 if (ifail .ne. 0 )
write(*,*)
' MNEWTAX : ifail = ',ifail
3647 node1 = elm_list(1,ielm_ax)
3648 node2 = elm_list(2,ielm_ax)
3649 node3 = elm_list(3,ielm_ax)
3650 node4 = elm_list(4,ielm_ax)
3652 call
interp(rr(:,nodes(1)),rr(:,nodes(2)),rr(:,nodes(3)),rr(:,nodes(4)),r_ax,s_ax, &
3653 r_axis,drrg1_dr,drrg1_ds,drrg1_drs,drrg1_drr,drrg1_dss)
3654 call
interp(zz(:,nodes(1)),zz(:,nodes(2)),zz(:,nodes(3)),zz(:,nodes(4)),r_ax,s_ax, &
3655 z_axis,dzzg1_dr,dzzg1_ds,dzzg1_drs,dzzg1_drr,dzzg1_dss)
3656 call
interp(psi(:,nodes(1)),psi(:,nodes(2)),psi(:,nodes(3)),psi(:,nodes(4)),r_ax,s_ax, &
3657 ps_axis,dpsg1_dr,dpsg1_ds,dpsg1_drs,dpsg1_drr,dpsg1_dss)
3659 ejac = drrg1_dr * dzzg1_ds - drrg1_ds * dzzg1_dr
3661 if (ejac .ne. 0.e0_r8)
then
3662 dr_dz = - drrg1_ds / ejac
3663 dr_dr = + dzzg1_ds / ejac
3664 ds_dz = + drrg1_dr / ejac
3665 ds_dr = - dzzg1_dr / ejac
3667 dps_drr = dpsg1_drr * dr_dr * dr_dr + 2.e0_r8*dpsg1_drs * dr_dr * ds_dr + dpsg1_dss * ds_dr * ds_dr
3668 dps_dzz = dpsg1_drr * dr_dz * dr_dz + 2.e0_r8*dpsg1_drs * dr_dz * ds_dz + dpsg1_dss * ds_dz * ds_dz
3670 crr_axis = dps_drr / 2.
3671 czz_axis = dps_dzz / 2.
3673 b_axis =
fdia(0.e0_r8) / r_axis
3674 q_axis = b_axis /(2.e0_r8*sqrt(crr_axis*czz_axis))
3677 write(*,
'(A,4f14.8)')
' magnetic axis : ',r_axis,z_axis,ps_axis,q_axis
3682 SUBROUTINE mnewtax(ps1, ps2, ps3, ps4, r, s, errx, errf, ifail)
3690 REAL (R8) :: ps1(4), ps2(4), ps3(4), ps4(4)
3691 REAL (R8) :: r, s, x(2), fvec(2),fjac(2,2)
3692 REAL (R8) :: tolf,tolx, errf, errx
3693 INTEGER :: ntrial, i, k, ifail
3695 real (r8) zpsi,zpsir,zpsis,zpsirs,zpsirr,zpsiss,temp,dis
3708 call
interp(ps1,ps2,ps3,ps4,x(1),x(2),zpsi,zpsir,zpsis,zpsirs,zpsirr,zpsiss)
3719 errf=abs(fvec(1))+abs(fvec(2))
3721 if (errf .le. tolf)
then
3732 dis = fjac(2,2)*fjac(1,1)-fjac(1,2)*fjac(2,1)
3733 if (dis .ne. 0.e0_r8)
then
3734 p(1) = (fjac(2,2)*
p(1)-fjac(1,2)*
p(2))/dis
3735 p(2) = (fjac(1,1)*
p(2)-fjac(2,1)*temp)/dis
3738 errx=abs(
p(1)) + abs(
p(2))
3740 p = min(
p,+0.5e0_r8)
3741 p = max(
p,-0.5e0_r8)
3748 if (errx .le. tolx)
then
3761 SUBROUTINE interp(XN1,XN2,XN3,XN4,R,S,X,XR,XS,XRS,XRR,XSS)
3768 REAL (R8) :: xn1(4),xn2(4),xn3(4),xn4(4)
3769 REAL (R8) :: r,s,x,xr,xs,xrs,xrr,xss
3770 REAL (R8) :: hi0m,hri0m,hrri0m,hi1m,hri1m,hrri1m,hj0m,hsj0m,hssj0m,hj1m,hsj1m,hssj1m
3771 REAL (R8) :: hi0p,hri0p,hrri0p,hi1p,hri1p,hrri1p,hj0p,hsj0p,hssj0p,hj1p,hsj1p,hssj1p
3773 hi0m = - (r-1.e0_r8)**2 * (-r-2.e0_r8) * 0.25e0_r8
3774 hri0m = - (r-1.e0_r8)*(-r-2.e0_r8)*0.5e0_r8 +(r-1.e0_r8)**2 * 0.25e0_r8
3775 hrri0m = + 1.5e0_r8 * r
3776 hi1m = - (r-1.e0_r8)**2 * (-r-1.e0_r8) * 0.25e0_r8
3777 hri1m = - (r-1.e0_r8)*(-r-1.e0_r8)*0.5e0_r8 + (r-1.e0_r8)**2 *0.25e0_r8
3778 hrri1m = + 1.5e0_r8 * r - .5e0_r8
3780 hj0m = - (s-1.e0_r8)**2 * (-s-2.e0_r8) * 0.25e0_r8
3781 hsj0m = - (s-1.e0_r8)*(-s-2.e0_r8)*0.5 +(s-1.e0_r8)**2 * 0.25e0_r8
3782 hssj0m = + 1.5e0_r8 * s
3783 hj1m = - (s-1.e0_r8)**2 * (-s-1.e0_r8) * 0.25e0_r8
3784 hsj1m = - (s-1.e0_r8)*(-s-1.e0_r8)*0.5e0_r8 + (s-1.e0_r8)**2 * 0.25e0_r8
3785 hssj1m = + 1.5e0_r8 * s - .5e0_r8
3787 hi0p = - (r+1.e0_r8)**2 * (r-2.e0_r8) * 0.25e0_r8
3788 hri0p = - (r+1.e0_r8)*(r-2.e0_r8)*0.5e0_r8 - (r+1.e0_r8)**2 * 0.25e0_r8
3789 hrri0p = - 1.5e0_r8 * r
3790 hi1p = + (r+1.e0_r8)**2 * (r-1.e0_r8) * 0.25e0_r8
3791 hri1p = + (r+1.e0_r8)*(r-1.e0_r8)*0.5e0_r8 + (r+1.e0_r8)**2 * 0.25e0_r8
3792 hrri1p = + 1.5e0_r8 * r + .5e0_r8
3794 hj0p = - (s+1.e0_r8)**2 * (s-2.e0_r8) * 0.25e0_r8
3795 hsj0p = - (s+1.e0_r8)*(s-2.e0_r8)*0.5e0_r8 - (s+1.e0_r8)**2 * 0.25e0_r8
3796 hssj0p = - 1.5e0_r8 * s
3797 hj1p = + (s+1.e0_r8)**2 * (s-1.e0_r8) * 0.25e0_r8
3798 hsj1p = + (s+1.e0_r8)*(s-1.e0_r8)*0.5e0_r8 + (s+1.e0_r8)**2 * 0.25e0_r8
3799 hssj1p = + 1.5e0_r8 * s + .5e0_r8
3801 x = hi0m*hj0m * xn1(1) + hi1m*hj0m * xn1(2) + hi0m*hj1m * xn1(3) + hi1m*hj1m * xn1(4) &
3802 + hi0m*hj0p * xn2(1) + hi1m*hj0p * xn2(2) + hi0m*hj1p * xn2(3) + hi1m*hj1p * xn2(4) &
3803 + hi0p*hj0m * xn4(1) + hi1p*hj0m * xn4(2) + hi0p*hj1m * xn4(3) + hi1p*hj1m * xn4(4) &
3804 + hi0p*hj0p * xn3(1) + hi1p*hj0p * xn3(2) + hi0p*hj1p * xn3(3) + hi1p*hj1p * xn3(4)
3806 xr = hri0m*hj0m * xn1(1) + hri1m*hj0m * xn1(2) + hri0m*hj1m * xn1(3) + hri1m*hj1m * xn1(4) &
3807 + hri0m*hj0p * xn2(1) + hri1m*hj0p * xn2(2) + hri0m*hj1p * xn2(3) + hri1m*hj1p * xn2(4) &
3808 + hri0p*hj0m * xn4(1) + hri1p*hj0m * xn4(2) + hri0p*hj1m * xn4(3) + hri1p*hj1m * xn4(4) &
3809 + hri0p*hj0p * xn3(1) + hri1p*hj0p * xn3(2) + hri0p*hj1p * xn3(3) + hri1p*hj1p * xn3(4)
3811 xs = hi0m*hsj0m * xn1(1) + hi1m*hsj0m * xn1(2) + hi0m*hsj1m * xn1(3) + hi1m*hsj1m * xn1(4) &
3812 + hi0m*hsj0p * xn2(1) + hi1m*hsj0p * xn2(2) + hi0m*hsj1p * xn2(3) + hi1m*hsj1p * xn2(4) &
3813 + hi0p*hsj0m * xn4(1) + hi1p*hsj0m * xn4(2) + hi0p*hsj1m * xn4(3) + hi1p*hsj1m * xn4(4) &
3814 + hi0p*hsj0p * xn3(1) + hi1p*hsj0p * xn3(2) + hi0p*hsj1p * xn3(3) + hi1p*hsj1p * xn3(4)
3816 xrr = hrri0m*hj0m * xn1(1) + hrri1m*hj0m * xn1(2) + hrri0m*hj1m * xn1(3) + hrri1m*hj1m * xn1(4) &
3817 + hrri0m*hj0p * xn2(1) + hrri1m*hj0p * xn2(2) + hrri0m*hj1p * xn2(3) + hrri1m*hj1p * xn2(4) &
3818 + hrri0p*hj0m * xn4(1) + hrri1p*hj0m * xn4(2) + hrri0p*hj1m * xn4(3) + hrri1p*hj1m * xn4(4) &
3819 + hrri0p*hj0p * xn3(1) + hrri1p*hj0p * xn3(2) + hrri0p*hj1p * xn3(3) + hrri1p*hj1p * xn3(4)
3821 xss = hi0m*hssj0m * xn1(1) + hi1m*hssj0m * xn1(2) + hi0m*hssj1m * xn1(3) + hi1m*hssj1m * xn1(4) &
3822 + hi0m*hssj0p * xn2(1) + hi1m*hssj0p * xn2(2) + hi0m*hssj1p * xn2(3) + hi1m*hssj1p * xn2(4) &
3823 + hi0p*hssj0m * xn4(1) + hi1p*hssj0m * xn4(2) + hi0p*hssj1m * xn4(3) + hi1p*hssj1m * xn4(4) &
3824 + hi0p*hssj0p * xn3(1) + hi1p*hssj0p * xn3(2) + hi0p*hssj1p * xn3(3) + hi1p*hssj1p * xn3(4)
3826 xrs = hri0m*hsj0m * xn1(1) + hri1m*hsj0m * xn1(2) + hri0m*hsj1m * xn1(3) + hri1m*hsj1m * xn1(4) &
3827 + hri0m*hsj0p * xn2(1) + hri1m*hsj0p * xn2(2) + hri0m*hsj1p * xn2(3) + hri1m*hsj1p * xn2(4) &
3828 + hri0p*hsj0m * xn4(1) + hri1p*hsj0m * xn4(2) + hri0p*hsj1m * xn4(3) + hri1p*hsj1m * xn4(4) &
3829 + hri0p*hsj0p * xn3(1) + hri1p*hsj0p * xn3(2) + hri0p*hsj1p * xn3(3) + hri1p*hsj1p * xn3(4)
3842 REAL (R8) xn1(4),xn2(4),xn3(4),xn4(4)
3843 real (r8) r,s,x,hi0m,hi1m,hj0m,hj1m,hi0p,hi1p,hj0p,hj1p
3845 hi0m = - (r-1.)**2 * (-r-2.) * 0.25
3846 hi1m = - (r-1.)**2 * (-r-1.) * 0.25
3848 hj0m = - (s-1.)**2 * (-s-2.) * 0.25
3849 hj1m = - (s-1.)**2 * (-s-1.) * 0.25
3851 hi0p = - (r+1.)**2 * (r-2.) * 0.25
3852 hi1p = + (r+1.)**2 * (r-1.) * 0.25
3854 hj0p = - (s+1.)**2 * (s-2.) * 0.25
3855 hj1p = + (s+1.)**2 * (s-1.) * 0.25
3857 x = hi0m*hj0m * xn1(1) + hi1m*hj0m * xn1(2) + hi0m*hj1m * xn1(3) + hi1m*hj1m * xn1(4) &
3858 + hi0m*hj0p * xn2(1) + hi1m*hj0p * xn2(2) + hi0m*hj1p * xn2(3) + hi1m*hj1p * xn2(4) &
3859 + hi0p*hj0m * xn4(1) + hi1p*hj0m * xn4(2) + hi0p*hj1m * xn4(3) + hi1p*hj1m * xn4(4) &
3860 + hi0p*hj0p * xn3(1) + hi1p*hj0p * xn3(2) + hi0p*hj1p * xn3(3) + hi1p*hj1p * xn3(4)
3872 REAL (R8) xn1(4),xn2(4),xn3(4),xn4(4)
3873 real (r8) r,s,x,xr,xs,hi0m,hri0m,hi1m,hri1m,hj0m,hsj0m,hj1m,hsj1m,hi0p,hri0p, &
3874 hi1p,hri1p,hj0p,hsj0p,hj1p,hsj1p
3876 hi0m = - (r-1.)**2 * (-r-2.) * 0.25
3877 hri0m = - (r-1.)*(-r-2.)*0.5 +(r-1.)**2 * 0.25
3878 hi1m = - (r-1.)**2 * (-r-1.) * 0.25
3879 hri1m = - (r-1.)*(-r-1.)*0.5 + (r-1.)**2 * 0.25
3880 hj0m = - (s-1.)**2 * (-s-2.) * 0.25
3881 hsj0m = - (s-1.)*(-s-2.)*0.5 +(s-1.)**2 * 0.25
3882 hj1m = - (s-1.)**2 * (-s-1.) * 0.25
3883 hsj1m = - (s-1.)*(-s-1.)*0.5 + (s-1.)**2 * 0.25
3885 hi0p = - (r+1.)**2 * (r-2.) * 0.25
3886 hri0p = - (r+1.)*(r-2.)*0.5 - (r+1.)**2 * 0.25
3887 hi1p = + (r+1.)**2 * (r-1.) * 0.25
3888 hri1p = + (r+1.)*(r-1.)*0.5 + (r+1.)**2 * 0.25
3890 hj0p = - (s+1.)**2 * (s-2.) * 0.25
3891 hsj0p = - (s+1.)*(s-2.)*0.5 - (s+1.)**2 * 0.25
3892 hj1p = + (s+1.)**2 * (s-1.) * 0.25
3893 hsj1p = + (s+1.)*(s-1.)*0.5 + (s+1.)**2 * 0.25
3895 x = hi0m*hj0m * xn1(1) + hi1m*hj0m * xn1(2) + hi0m*hj1m * xn1(3) + hi1m*hj1m * xn1(4) &
3896 + hi0m*hj0p * xn2(1) + hi1m*hj0p * xn2(2) + hi0m*hj1p * xn2(3) + hi1m*hj1p * xn2(4) &
3897 + hi0p*hj0m * xn4(1) + hi1p*hj0m * xn4(2) + hi0p*hj1m * xn4(3) + hi1p*hj1m * xn4(4) &
3898 + hi0p*hj0p * xn3(1) + hi1p*hj0p * xn3(2) + hi0p*hj1p * xn3(3) + hi1p*hj1p * xn3(4)
3900 xr = hri0m*hj0m * xn1(1) + hri1m*hj0m * xn1(2) + hri0m*hj1m * xn1(3) + hri1m*hj1m * xn1(4) &
3901 + hri0m*hj0p * xn2(1) + hri1m*hj0p * xn2(2) + hri0m*hj1p * xn2(3) + hri1m*hj1p * xn2(4) &
3902 + hri0p*hj0m * xn4(1) + hri1p*hj0m * xn4(2) + hri0p*hj1m * xn4(3) + hri1p*hj1m * xn4(4) &
3903 + hri0p*hj0p * xn3(1) + hri1p*hj0p * xn3(2) + hri0p*hj1p * xn3(3) + hri1p*hj1p * xn3(4)
3905 xs = hi0m*hsj0m * xn1(1) + hi1m*hsj0m * xn1(2) + hi0m*hsj1m * xn1(3) + hi1m*hsj1m * xn1(4) &
3906 + hi0m*hsj0p * xn2(1) + hi1m*hsj0p * xn2(2) + hi0m*hsj1p * xn2(3) + hi1m*hsj1p * xn2(4) &
3907 + hi0p*hsj0m * xn4(1) + hi1p*hsj0m * xn4(2) + hi0p*hsj1m * xn4(3) + hi1p*hsj1m * xn4(4) &
3908 + hi0p*hsj0p * xn3(1) + hi1p*hsj0p * xn3(2) + hi0p*hsj1p * xn3(3) + hi1p*hsj1p * xn3(4)
3913 SUBROUTINE interp3(XN1,XN2,XN3,XN4,YN1,YN2,YN3,YN4,PN1,PN2,PN3,PN4,R,S, &
3921 REAL (R8) xn1(4),xn2(4),xn3(4),xn4(4)
3922 REAL (R8) yn1(4),yn2(4),yn3(4),yn4(4)
3923 REAL (R8) pn1(4),pn2(4),pn3(4),pn4(4)
3924 real (r8) r,s,x,xr,xs,yr,ys,ps,hi0m,hri0m,hi1m,hri1m,hj0m,hsj0m, &
3925 hj1m,hsj1m,hi0p,hri0p,hi1p,hri1p,hj0p,hsj0p,hj1p,hsj1p
3927 hi0m = - (r-1.)**2 * (-r-2.) * 0.25
3928 hri0m = - (r-1.)*(-r-2.)*0.5 +(r-1.)**2 * 0.25
3929 hi1m = - (r-1.)**2 * (-r-1.) * 0.25
3930 hri1m = - (r-1.)*(-r-1.)*0.5 + (r-1.)**2 * 0.25
3931 hj0m = - (s-1.)**2 * (-s-2.) * 0.25
3932 hsj0m = - (s-1.)*(-s-2.)*0.5 +(s-1.)**2 * 0.25
3933 hj1m = - (s-1.)**2 * (-s-1.) * 0.25
3934 hsj1m = - (s-1.)*(-s-1.)*0.5 + (s-1.)**2 * 0.25
3936 hi0p = - (r+1.)**2 * (r-2.) * 0.25
3937 hri0p = - (r+1.)*(r-2.)*0.5 - (r+1.)**2 * 0.25
3938 hi1p = + (r+1.)**2 * (r-1.) * 0.25
3939 hri1p = + (r+1.)*(r-1.)*0.5 + (r+1.)**2 * 0.25
3941 hj0p = - (s+1.)**2 * (s-2.) * 0.25
3942 hsj0p = - (s+1.)*(s-2.)*0.5 - (s+1.)**2 * 0.25
3943 hj1p = + (s+1.)**2 * (s-1.) * 0.25
3944 hsj1p = + (s+1.)*(s-1.)*0.5 + (s+1.)**2 * 0.25
3946 x = hi0m*hj0m * xn1(1) + hi1m*hj0m * xn1(2) + hi0m*hj1m * xn1(3) + hi1m*hj1m * xn1(4) &
3947 + hi0m*hj0p * xn2(1) + hi1m*hj0p * xn2(2) + hi0m*hj1p * xn2(3) + hi1m*hj1p * xn2(4) &
3948 + hi0p*hj0m * xn4(1) + hi1p*hj0m * xn4(2) + hi0p*hj1m * xn4(3) + hi1p*hj1m * xn4(4) &
3949 + hi0p*hj0p * xn3(1) + hi1p*hj0p * xn3(2) + hi0p*hj1p * xn3(3) + hi1p*hj1p * xn3(4)
3951 xr = hri0m*hj0m * xn1(1) + hri1m*hj0m * xn1(2) + hri0m*hj1m * xn1(3) + hri1m*hj1m * xn1(4) &
3952 + hri0m*hj0p * xn2(1) + hri1m*hj0p * xn2(2) + hri0m*hj1p * xn2(3) + hri1m*hj1p * xn2(4) &
3953 + hri0p*hj0m * xn4(1) + hri1p*hj0m * xn4(2) + hri0p*hj1m * xn4(3) + hri1p*hj1m * xn4(4) &
3954 + hri0p*hj0p * xn3(1) + hri1p*hj0p * xn3(2) + hri0p*hj1p * xn3(3) + hri1p*hj1p * xn3(4)
3956 xs = hi0m*hsj0m * xn1(1) + hi1m*hsj0m * xn1(2) + hi0m*hsj1m * xn1(3) + hi1m*hsj1m * xn1(4) &
3957 + hi0m*hsj0p * xn2(1) + hi1m*hsj0p * xn2(2) + hi0m*hsj1p * xn2(3) + hi1m*hsj1p * xn2(4) &
3958 + hi0p*hsj0m * xn4(1) + hi1p*hsj0m * xn4(2) + hi0p*hsj1m * xn4(3) + hi1p*hsj1m * xn4(4) &
3959 + hi0p*hsj0p * xn3(1) + hi1p*hsj0p * xn3(2) + hi0p*hsj1p * xn3(3) + hi1p*hsj1p * xn3(4)
3961 ps = hi0m*hj0m * pn1(1) + hi1m*hj0m * pn1(2) + hi0m*hj1m * pn1(3) + hi1m*hj1m * pn1(4) &
3962 + hi0m*hj0p * pn2(1) + hi1m*hj0p * pn2(2) + hi0m*hj1p * pn2(3) + hi1m*hj1p * pn2(4) &
3963 + hi0p*hj0m * pn4(1) + hi1p*hj0m * pn4(2) + hi0p*hj1m * pn4(3) + hi1p*hj1m * pn4(4) &
3964 + hi0p*hj0p * pn3(1) + hi1p*hj0p * pn3(2) + hi0p*hj1p * pn3(3) + hi1p*hj1p * pn3(4)
3966 yr = hri0m*hj0m * yn1(1) + hri1m*hj0m * yn1(2) + hri0m*hj1m * yn1(3) + hri1m*hj1m * yn1(4) &
3967 + hri0m*hj0p * yn2(1) + hri1m*hj0p * yn2(2) + hri0m*hj1p * yn2(3) + hri1m*hj1p * yn2(4) &
3968 + hri0p*hj0m * yn4(1) + hri1p*hj0m * yn4(2) + hri0p*hj1m * yn4(3) + hri1p*hj1m * yn4(4) &
3969 + hri0p*hj0p * yn3(1) + hri1p*hj0p * yn3(2) + hri0p*hj1p * yn3(3) + hri1p*hj1p * yn3(4)
3971 ys = hi0m*hsj0m * yn1(1) + hi1m*hsj0m * yn1(2) + hi0m*hsj1m * yn1(3) + hi1m*hsj1m * yn1(4) &
3972 + hi0m*hsj0p * yn2(1) + hi1m*hsj0p * yn2(2) + hi0m*hsj1p * yn2(3) + hi1m*hsj1p * yn2(4) &
3973 + hi0p*hsj0m * yn4(1) + hi1p*hsj0m * yn4(2) + hi0p*hsj1m * yn4(3) + hi1p*hsj1m * yn4(4) &
3974 + hi0p*hsj0p * yn3(1) + hi1p*hsj0p * yn3(2) + hi0p*hsj1p * yn3(3) + hi1p*hsj1p * yn3(4)
3996 real (r8) :: data(*)
3997 integer :: kr,nr, ktran
3999 CALL
fft2(
DATA(1),
DATA(kr+1),nr/2,-(kr+kr))
4000 CALL
rtran2(
DATA,nr,kr,1)
4013 real (r8) :: data(*), theta, dc, ds, ws, wc, sumr, difr, sumi, difi
4014 real (r8) :: tr, ti, wca
4015 integer :: nr, kr, ktran, ks, n, nmax, kmax, k, nk
4021 theta=1.5707963267949/float(n)
4026 IF (ktran .LE. 0)
THEN
4031 DATA(nmax-1)=
DATA(1)
4032 DATA(nmax-1+kr)=
DATA(kr+1)
4036 sumr=.5*(
DATA(k)+
DATA(nk))
4037 difr=.5*(
DATA(k)-
DATA(nk))
4038 sumi=.5*(
DATA(k+kr)+
DATA(nk+kr))
4039 difi=.5*(
DATA(k+kr)-
DATA(nk+kr))
4045 DATA(nk+kr)=-difi-ti
4053 SUBROUTINE fft2 (DATAR,DATAI,N,INC)
4059 real (r8) :: datar(*), datai(*)
4061 real (r8) tempr,tempi,theta,sinth,wstpr,wstpi,wr,wi
4062 integer inc,ktran,ks,ip0,ip3,irev,i,ibit,ip1,ip2,i1,i3,j0,j1
4074 datar(i)=datar(irev)
4075 datai(i)=datai(irev)
4080 10
IF(irev.GT.ibit)
THEN
4083 IF(ibit.GE.ip0) goto 10
4088 theta=
REAL(ktran)*3.1415926535898
4089 30
IF(ip1.GE.ip3)
return
4092 wstpr=-2.*sinth*sinth
4100 tempr=wr*datar(j1)-wi*datai(j1)
4101 tempi=wr*datai(j1)+wi*datar(j1)
4102 datar(j1)=datar(j0)-tempr
4103 datai(j1)=datai(j0)-tempi
4104 datar(j0)=datar(j0)+tempr
4105 datai(j0)=datai(j0)+tempi
4108 wr=wr*wstpr-wi*wstpi+wr
4109 wi=wi*wstpr+tempr*wstpi+wi
4118 SUBROUTINE fsum2(F,T,FFNUL,FFCOS,FFSIN,MHARM)
4125 real (r8) :: ffnul, ffcos(*), ffsin(*), f, t, s, c, co, ca, si, sum
4136 sum=sum+ffcos(m)*c + ffsin(m)*s
4140 END SUBROUTINE fsum2
4153 parameter(jmax=1024,ninv=100)
4154 dimension tin(*),tout(*),t(jmax+1),g(jmax+1),gfcos(jmax/2-1),gfsin(jmax/2-1)
4155 equivalence(t(1),g(1))
4156 real (r8) tin,tout,t,g,gfcos,gfsin,acc,pi,t1,sum1,y1,t0,y0,t2,sum2,y2,gfnul
4157 integer jpts,igrd,mharm,jj,i,j1,igrdnv,ifirst,icirc,j,n
4163 IF (tin(jj-1).GT.tin(jj)) tin(jj)=tin(jj)+2*pi
4167 g(i)=tin(i)-2.*pi*(i-1.)/jpts
4170 CALL
rft(g,gfnul,gfcos,gfsin,jpts,mharm)
4173 t(i)=2.*pi*(i-1.)/jpts
4178 icirc= - (int(tin(1)/(2*pi)+10000) - 9999)
4179 IF (abs(tin(1)).LT.1e-12) icirc=0
4183 t1=t(j) + icirc*2*pi
4184 CALL
fsum2(sum1,t1,gfnul,gfcos,gfsin,mharm)
4189 IF (abs(y0).LE.acc)
THEN
4193 IF (j.NE.jpts+1) goto 31
4194 IF (ifirst.EQ.0)
THEN
4202 t1=t(j) + icirc*2*pi
4203 CALL
fsum2(sum1,t1,gfnul,gfcos,gfsin,mharm)
4205 IF(sign(1.0_r8,y0).EQ.sign(1.0_r8,y1)) goto 30
4208 t2=t0-(t1-t0)*y0/(y1-y0)
4209 CALL
fsum2(sum2,t2,gfnul,gfcos,gfsin,mharm)
4211 IF(abs(y2).LE.acc) goto 50
4212 IF(sign(1.0_r8,y2).EQ.sign(1.0_r8,y1)) goto 45
4220 IF(n.GT.igrdnv) igrdnv=n
4226 SUBROUTINE rft(F,FFNUL,FFCOS,FFSIN,JPTS,MHARM)
4238 integer :: jpts, jmax, mharm, j, m
4239 parameter(jmax=1024)
4240 real (r8) :: f(*),ffnul,ffcos(*),ffsin(*),fstore(jmax+2)
4246 CALL
rft2(fstore,jpts,1)
4250 ffcos(m)=fstore(2*m+1)*fac
4251 ffsin(m) = - fstore(2*m+2)*fac
4256 SUBROUTINE spline(N,X,Y,ALFA,BETA,TYP,A,B,C,D)
4284 REAL (R8) x(n), y(n), alfa, beta, a(n), b(n), c(n), d(n)
4289 IF((typ.LT.0).OR.(typ.GT.3))
THEN
4290 WRITE(*,*)
' ERROR IN ROUTINE SPLINE: WRONG TYPE'
4295 WRITE(*,*)
' ERROR IN ROUTINE SPLINE: N < 3 '
4304 IF ( h(i).LE. 0.0)
THEN
4305 WRITE(*,*)
' NON-MONOTONIC COORDINATE IN SPLINE: X(I-1)>=X(I)'
4313 a(i) = 3.0 * ((y(i+2)-y(i+1)) / h(i+1) - (y(i+1)-y(i)) / h(i))
4316 d(i) = 2.0 * (h(i) + h(i+1))
4324 a(1) = a(1) * h(2) / (h(1) + h(2))
4325 a(n-2) = a(n-2) * h(n-2) / (h(n-1) + h(n-2))
4327 d(n-2) = d(n-2) - h(n-1)
4329 b(n-2) = b(n-2) - h(n-1)
4335 a(1) = a(1) - 1.5 * ((y(2)-y(1)) / h(1) - alfa)
4336 a(n-2) = a(n-2) - 1.5 * (beta - (y(n)-y(n-1)) / h(n-1))
4337 d(1) = d(1) - 0.5 * h(1)
4338 d(n-2) = d(n-2) - 0.5 * h(n-1)
4344 a(1) = a(1) - 0.5 * alfa * h(1)
4345 a(n-2) = a(n-2) - 0.5 * beta * h(n-1)
4351 a(1) = a(1) + 0.5 * alfa * h(1) * h(1)
4352 a(n-2) = a(n-2) - 0.5 * beta * h(n-1)* h(n-1)
4354 d(n-2) = d(n-2) + h(n-1)
4359 CALL
sgtsl(n-2,b,d,c,a,ierr)
4368 CALL dcopy(n-2,a,1,c(2),1)
4374 c(1) = c(2) + h(1) * (c(2)-c(3)) / h(2)
4375 c(n) = c(n-1) + h(n-1) * (c(n-1)-c(n-2)) / h(n-2)
4379 c(1) = 1.5*((y(2)-y(1)) / h(1) - alfa) / h(1) - 0.5 * c(2)
4380 c(n) = -1.5*((y(n)-y(n-1)) / h(n-1)-beta) / h(n-1)-0.5*c(n-1)
4389 c(1) = c(2) - 0.5 * alfa * h(1)
4390 c(n) = c(n-1) + 0.5 * beta * h(n-1)
4393 CALL dcopy(n,y,1,a,1)
4396 b(i) = (a(i+1)-a(i)) / h(i) - h(i) * (c(i+1)+2.0 * c(i)) / 3.0
4397 d(i) = (c(i+1)-c(i)) / (3.0 * h(i))
4400 b(n) = (3.0 * d(n-1) * h(n-1) + 2.0 * c(n-1)) * h(n-1) + b(n-1)
4404 21
FORMAT(1x,
'ERROR IN SGTSL: MATRIX SINGULAR')
4427 REAL (R8) xwert, a(n), b(n), c(n), d(n), x(n), abltg(3)
4439 IF(xwert.LT.x(m))
THEN
4449 abltg(1) = (3.0 * d(i) * xx + 2.0 * c(i)) * xx + b(i)
4450 abltg(2) = 6.0 * d(i) * xx + 2.0 * c(i)
4451 abltg(3) = 6.0 * d(i)
4453 spwert = ((d(i)*xx + c(i))*xx + b(i))*xx + a(i)
4462 REAL (R8) c(*),d(*),e(*),b(*)
4507 INTEGER k,kb,kp1,nm1,nm2
4514 IF (nm1 .LT. 1) go to 40
4524 IF (abs(c(kp1)) .LT. abs(c(k))) go to 10
4544 IF (c(k) .NE. 0.0e0) go to 20
4550 c(kp1) = d(kp1) + t*d(k)
4551 d(kp1) = e(kp1) + t*e(k)
4553 b(kp1) = b(kp1) + t*b(k)
4556 IF (c(n) .NE. 0.0e0) go to 50
4565 IF (n .EQ. 1) go to 80
4566 b(nm1) = (b(nm1) - d(nm1)*b(n))/c(nm1)
4567 IF (nm2 .LT. 1) go to 70
4570 b(k) = (b(k) - d(k)*b(k+1) - e(k)*b(k+2))/c(k)
4578 END SUBROUTINE sgtsl
4593 REAL (R8) zero,one,two,three
4594 parameter(
zero=0.0e0,one=1.0e0,two=2.0e0,three=3.0e0)
4596 REAL (R8) d(n),f(n),w(*),x(n)
4597 REAL (R8) a3n1,f1,f2,h1,h2,
p
4600 WRITE(*,*) f(1),f(n)
4602 WRITE (lp,
'(A39)')
'RETURN FROM TB15AD BECAUSE N TOO SMALL'
4607 IF (x(i).LE.x(i-1))
THEN
4608 WRITE (lp,
'(A29,I3,A13)')
' RETURN FROM TB15AD BECAUSE ',i,
' OUT OF ORDER'
4614 IF (f(1).NE.f(n))
THEN
4615 WRITE (lp,
'(A40)') .NE.
'RETURN FROM TB15AD BECAUSE F(1)F(N)'
4620 h1 = one/ (x(i)-x(i-1))
4623 h2 = one/ (x(2)-x(1))
4626 h2 = one/ (x(i+1)-x(i))
4630 w(3*i-1) = two* (h1+h2)
4632 d(i) = 3.0* (f2*h2*h2+f(i)* (h1*h1-h2*h2)-f1*h1*h1)
4639 w(k+3) = w(k+3) -
p*w(k+1)
4640 d(i+1) = d(i+1) -
p*d(i)
4643 a3n1 = -
p*w(k-1) + a3n1
4644 d(n) = d(n) -
p*d(i)
4647 p = (w(k+2)+w(k-1))/w(k)
4648 a3n1 = a3n1 -
p* (w(k+1)+w(k-1))
4649 d(n) = (d(n)-
p*d(n-1))/a3n1
4652 d(j) = (d(j)-w(3*j)*d(j+1)-w(3*j-2)*d(n))/w(3*j-1)
4657 END SUBROUTINE tb15a
4677 REAL (R8) d(*),s(*),u(*),v(*)
4678 REAL (R8) a,b,c,c3,e0_r8,d1,eps,gama,h,hr,hrr,phi,s0,s1,t,theta
4684 IF (x.LT.u(1)) go to 990
4685 IF (x.GT.u(n)) go to 991
4686 IF (ix.LT.0 .OR. iflg.EQ.0) go to 12
4687 IF (x.GT.u(j+1)) go to 1
4688 IF (x.GE.u(j)) go to 18
4692 11
IF (x.GT.u(j+1)) go to 1
4694 12 j = abs(x-u(1))/ (u(n)-u(1))* (n-1) + 1
4697 IF (x.GE.u(j)) go to 11
4699 IF (x.LT.u(j)) go to 2
4713 18 theta = (x-u(j))*hr
4716 gama = theta*b - phi*a
4717 v(1) = theta*s1 + phi*s0 + t*gama
4718 v(2) = theta*d1 + phi*e0_r8 + t*c3*hr
4719 v(3) = (c* (phi-theta)-gama)*hrr
4722 990
IF (x.LE.u(1)-eps*max(abs(u(1)),abs(u(n)))) go to 99
4725 991
IF (x.GE.u(n)+eps*max(abs(u(1)),abs(u(n)))) go to 995
4734 END SUBROUTINE tg02a
4754 dimension ord(n),poplst(2,20)
4764 REAL (R8) x,xx,z,zz,y
4765 integer n,ndeep,u1,l1,i,l,u,
p,q,yp,ix,iz,ip,iq
4772 2
IF (u1.GT.l1) go to 3
4791 5
IF (u-l.LE.1) go to 15
4802 IF (x.GE.xx) go to 8
4812 IF (z.LE.zz) go to 10
4821 10
IF (x.LE.z) go to 11
4828 11
IF (x.LE.xx) go to 12
4831 12
IF (z.GE.zz) go to 6
4839 IF (.NOT.(
p.NE.ix.AND.x.NE.xx)) go to 14
4844 IF (.NOT.(q.NE.iz.AND.z.NE.zz)) go to 15
4849 IF (u-q.LE.
p-l) go to 16
4858 IF (u1.LE.l1) go to 18
4866 18
IF (u.GT.l) go to 4
4870 IF (ndeep.EQ.0) go to 2
subroutine initialise_elements
subroutine helena_circulating(nr_flux, np_flux, RRflux, ZZflux, PSflux, fraction_circ)
subroutine interp(XN1, XN2, XN3, XN4, R, S, X, XR, XS, XRS, XRR, XSS)
real(r8) function r_min(rminor, xaxis, i)
subroutine helena_flux_surface_integrals(nr_flux, np_flux, RR_flux, ZZ_flux, PS_flux, powers, n_int, n_var, results, q, vprime)
subroutine grid2nv(tin, tout, jpts, acc, igrd, ll)
subroutine zero(x1, y1, x2, y2, func, err, x, y, izero, ll)
subroutine solve_matrix(amix, solve_only, error_iteration)
subroutine tg02a(ix, n, n_bnd, u, s, d, x, v)
subroutine fluxsurface_current(R_av, OR_av)
subroutine interp2(XN1, XN2, XN3, XN4, R, S, X, XR, XS)
subroutine matrix_gs(ps_axis, rhs_only)
subroutine interp1(XN1, XN2, XN3, XN4, R, S, X)
real(r8) function current_profile(psi_n)
subroutine qsort2(ORD, N, A)
subroutine initialise_profiles(n_prof_in, iopt_p, iopt_f, psi_in, pprime_in, ffprime_in, pressure_in, fdia_in, current_in)
real(r8) function dpdpsi(psi_n)
subroutine helena_remesh(nrnew, npnew, RRnew, ZZnew, PSInew)
subroutine solvem2(a, b, c, d, e, f, x, y)
subroutine cplotm(MX, MY, ILAB1, X, Y, NX, NY, INCX, INCY, Z, NDIM, ZC, NC, TITLE, NTITLE, XNAME, NXNAME, YNAME, NYNAME)
subroutine tb15a(n, n_bnd, x, f, d, w, lp)
subroutine flux_surface_add_point(s, i, iv, ifound, r_psi, s_psi, dpsi_dr, dpsi_ds)
subroutine spline(N, X, Y, ALFA, BETA, TYP, A, B, C, D)
subroutine helena_volume_integrals(nr_flux, np_flux, RR_flux, ZZ_flux, PS_flux, powers, volume_integrals, n_var, n_int, n_psi)
REAL *8 function spwert(N, XWERT, A, B, C, D, X, ABLTG)
subroutine rft2(data, nr, kr)
subroutine update_fdf(equilibrium, xaxis)
subroutine plot_flux_surfaces
subroutine helena_mapping(RR, ZZ, PSI, n_tht, n_chi)
subroutine rtran2(data, nr, kr, ktran)
subroutine fsum2(f, t, ffnul, ffcos, ffsin, mharm)
real(r8) function fdfdpsi(psi_n)
subroutine sgtsl(n, c, d, e, b, info)
subroutine current(GEOMETRY, PROFILES, TRANSPORT, SOURCES, EVOLUTION, CONTROL, j_boun, ifail, failstring)
CURRENT TRANSPORT EQUATION.
subroutine plotcu(X1, X1S, Y1, Y1S, X2, X2S, Y2, Y2S)
real(r8) function fdia(psi_n)
subroutine psi_minmax(n, psimin, psimax)
subroutine lplot6(MX, MY, X, Y, NPTS, TITLE)
real(r8) function, public root(a, b, c, d, sgn)
subroutine solvp3(C0, C1, C2, C3, X1, X2, X3, IFAIL)
subroutine nframe(MX, MY, IOP, XMIN, XMAX, YMIN, YMAX, TITLE, NTITLE, XNAME, NXNAME, YNAME, NYNAME)
subroutine gs_solve(n_iter, rhs_only, solve_only, error_iteration, amix, ifail)
real(r8) function p(a, x, xr, xs, yr, ys, psi, psir, F_dia)
subroutine plot_grid(R, Z, nr, np)
subroutine cub1d(X1, X1S, X2, X2S, S, X, XS)
subroutine flux_surface_add_line(i, j, r_psi, s_psi, dpsi_dr, dpsi_ds)
subroutine helena_moments(RRflux, ZZflux, nr_flux, np_flux, moments, n_moments)
subroutine rft(f, ffnul, ffcos, ffsin, jpts, mharm)
subroutine lplot(MX, MY, IOP, X, Y, NPTS, INC, TITLE, NTITLE, XNAME, NXNAME, YNAME, NYNAME)
subroutine initialise_grid
real(r8) function dp_dpsi(flux)
subroutine interp3(XN1, XN2, XN3, XN4, YN1, YN2, YN3, YN4, PN1, PN2, PN3, PN4, R, S, X, XR, XS, YR, YS, PS)
real(r8) function r_max(rminor, xaxis, i)
subroutine fft2(datar, datai, n, inc)
subroutine fluxsurface_integrals(powers, n_int, n_var, results)
subroutine mnewtax(ntrial, naxis, x, n, tolx, tolf, errx, errf)
real(r8) function pressure(flux)
subroutine tht_minmax(n, thtmin, thtmax)
subroutine pplot(MX, MY, X, Y, NPTS, INC)
subroutine find_flux_surfaces
subroutine cubich(I, J, R0, S0, R, S, H, HR, HS, HRS, HRR, HSS)
subroutine helena21(R_bnd_in, Z_bnd_in, n_bnd_in, Rgeo_in, Zgeo_in, amin_in, ellip_in, tria_u_in, tria_l_in, quad_u_in, quad_l_in, Bgeo_in, psi_in, pprime_in, ffprime_in, pressure_in, fdia_in, current_in, n_prof_in, iopt_p, iopt_f, nr_grid, np_grid, psi_out, pprime_out, ffprime_out, pressure_out, fdia_out, current_out, qprof_out, vprime, fraction_circ, moments, n_moments, surface_powers, surface_integrals, n_var_surfaces, n_int_surfaces, volume_powers, volume_integrals, n_var_volumes, n_int_volumes, n_psi_out, n_tht_out, amin_out, Rgeo_out, Zgeo_out, area_out, volume_out, betap_out, xip_out, xli_out, beta_out, R_axis_out, Z_axis_out, B_axis_out, psi_axis_out, psi_bnd_out, RRflux, ZZflux, PSflux)