17 USE hessian,
ONLY: inithess, compute_hessian_blocks, asym_index, levmarq_param
19 USE nscalingtools,
ONLY: myenvvariables, parsolver, disp, startglobrow, endglobrow, rcounts, mpi_err
27 USE descriptor_mod,
ONLY: iam, nprocs, lscalapack, inhessian, siesta_comm
28 USE v3_utilities,
ONLY:
assert
30 USE vmec_info,
ONLY: jcurrumnc, jcurrvmnc, jcurrumns, jcurrvmns
33 USE quantities,
ONLY: jacobh, jbsupsmnsh, jbsupumnch, jbsupvmnch, &
34 jbsupsmnch, jbsupumnsh, jbsupvmnsh
46 LOGICAL,
PARAMETER,
PRIVATE ::
l_asedge = .true.
49 INTEGER,
PRIVATE :: nsmin
50 INTEGER,
PRIVATE :: nsmax
51 INTEGER,
PRIVATE :: ns_match
54 LOGICAL,
PRIVATE :: linit
55 LOGICAL,
PRIVATE :: lhessian
56 REAL (dp),
PRIVATE :: bnorm = -1
57 REAL (dp),
PRIVATE :: line_bu
59 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsupsijh
60 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsupuijh
61 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsupvijh
62 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsubsijh
63 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsubuijh
64 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: bsubvijh
65 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: jacobmnch
66 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
PRIVATE :: jacobmnsh
78 USE diagnostics_mod,
ONLY: divb, divb_rms
79 USE vmec_info,
ONLY: vmec_curtor
89 LOGICAL :: lcolscale_save
92 REAL (dp),
PARAMETER :: levmarq_param_inital = 1.e-6_dp
99 lcolscale_save = lcolscale
111 levmarq_param = levmarq_param_inital
114 CALL compute_hessian_blocks(compute_forces_lin, .false.)
117 WRITE (*,1001) asym_index, toff - ton
126 WRITE (*,1002) toff - ton
139 nsmax = min(ns, endglobrow + 1)
140 CALL divb(nsmin, nsmax)
143 CALL mpi_allreduce(mpi_in_place,
siesta_curtor, 1, mpi_real8, mpi_sum
144 siesta_comm, mpi_err)
155 lcolscale = lcolscale_save
157 1000
FORMAT(/,
'-----------------------------------------------',
158 /,
'STARTING EXTERNAL B-FIELD CALCULATION (PCHELMS)',
159 /,
'-----------------------------------------------')
160 1001
FORMAT(
' ASYMMETRY INDEX: ',1p,e12.4,/,
161 ' PCHELMS HESSIAN COMPUTATION TIME: ',f10.1,
's')
162 1002
FORMAT(
' PCHELMS HESSIAN SOLVER TIME: ',f10.1,
's')
163 1003
FORMAT(/,
' |DivB| (normed) = ',1p,e12.3,/,
164 /,
' SIESTA Curtor : ',e12.4,
' VMEC Curtor : 'e12.4,
165 /,
'-----------------------------------------------',
167 /,
'-----------------------------------------------')
187 jbsupsmnh, jbsupumnh, jbsupvmnh, iparity)
188 USE utilities,
ONLY: curl_ftoh, set_bndy_fouier_m0, set_bndy_full_origin
194 REAL (dp),
DIMENSION(:,:,:),
POINTER :: Asubsmnf
195 REAL (dp),
DIMENSION(:,:,:),
POINTER :: Asubumnf
196 REAL (dp),
DIMENSION(:,:,:),
POINTER :: Asubvmnf
197 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupsmnh
198 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupumnh
199 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupvmnh
200 INTEGER,
INTENT(in) :: iparity
214 moff = lbound(asubsmnf, 1)
215 noff = ntor + lbound(asubsmnf, 2)
218 IF (iparity .EQ.
f_sin)
THEN
228 CALL set_bndy_fouier_m0(asubsmnf, asubumnf, asubvmnf, iparity)
229 IF (nsmin .EQ. 1)
THEN
230 CALL set_bndy_full_origin(asubsmnf, asubumnf, asubvmnf)
246 IF (nmin .le. ns_match .and. lhessian .and. .not.linit)
THEN
247 nmatch = min(ns_match, nsmax)
248 asubumnf(
m1 + moff,:,nmin:nmatch) = 0
249 asubvmnf(
m1 + moff,:,nmin:nmatch) = 0
252 CALL curl_ftoh(asubsmnf, asubumnf, asubvmnf,
253 jbsupsmnh, jbsupumnh, jbsupvmnh, iparity, nmin, nsmax
284 SUBROUTINE curlb_pchelms(ksupsmnf, ksupumnf, ksupvmnf, asubsmnf, &
285 bsupsmnh, iparity, curtor)
286 USE utilities,
ONLY: curl_htof, gradienthalf, set_bndy_fouier_m0
293 REAL(dp),
POINTER,
DIMENSION(:,:,:) :: ksupsmnf
294 REAL(dp),
POINTER,
DIMENSION(:,:,:) :: ksupumnf
295 REAL(dp),
POINTER,
DIMENSION(:,:,:) :: ksupvmnf
296 REAL(dp),
POINTER,
DIMENSION(:,:,:) :: asubsmnf
297 REAL(dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(IN) :: bsupsmnh
298 INTEGER,
INTENT(IN) :: iparity
299 REAL (dp),
INTENT(inout) :: curtor
316 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: dA_sds
317 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubsmnh
318 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubumnh
319 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: bsubvmnh
321 REAL (dp),
DIMENSION(nsp) :: t1(nsp)
324 IF (iparity .eq.
f_sin)
THEN
335 nmax = min(ns, endglobrow+1)
336 moff = lbound(ksupsmnf,1)
337 noff = lbound(ksupsmnf,2) + ntor
339 ALLOCATE(bsubsmnh(0:mpol,-ntor:ntor,nmin:nmax),
340 bsubumnh(0:mpol,-ntor:ntor,nmin:nmax),
341 bsubvmnh(0:mpol,-ntor:ntor,nmin:nmax), stat=istat)
342 CALL assert(istat .eq. 0,
'Allocation1 failed in CURLB_PCHELMS')
348 CALL set_bndy_fouier_m0(bsubsmnh, bsubumnh, bsubvmnh, fours)
351 IF (nmax .eq. ns .and. iparity .eq.
f_sin)
THEN
352 line_bu = bsubumnh(0,0,ns)
355 CALL curl_htof(bsubsmnh, bsubumnh, bsubvmnh,
356 ksupsmnf, ksupumnf, ksupvmnf,
357 iparity, nmin, nmax, .false., curtor)
360 DEALLOCATE (bsubsmnh, bsubumnh, bsubvmnh, stat=istat)
361 CALL assert_eq(0, istat,
'Deallocation failed in CURLB_PCHELMS')
365 np = max(1, nmin - 1)
366 mp = min(ns, nmax + 1)
367 ALLOCATE (da_sds(0:mpol,-ntor:ntor,np:mp))
368 CALL gradienthalf(da_sds, asubsmnf)
370 ksupsmnf(:,:,nmin:mp-1) = ksupsmnf(:,:,nmin:mp-1)
371 + diff*(da_sds(:,:,nmin+1:mp) -
372 da_sds(:,:,nmin:mp-1))
373 IF (nmax .eq. ns)
THEN
374 ksupsmnf(:,:,ns) = ksupsmnf(:,:,ns) - 2*diff*da_sds(:,:,ns)
376 IF (iparity .eq. isym)
THEN
377 ksupsmnf(
m0+moff,
n0+noff,nmin:nmax) = 0
383 IF (nh .GE. nmin)
THEN
391 t1(nl:nh) = diff*(bsupsmnh(m,n,nl:nh)
392 + bsupsmnh(m,n,nl+1:nh+1))
393 ksupumnf(m+moff,n+noff,nl:nh) = ksupumnf(m+moff,n+noff,nl
395 ksupvmnf(m+moff,n+noff,nl:nh) = ksupvmnf(m+moff,n+noff,nl
418 ksupsmnf(:,:,nmin:nmax) = -ksupsmnf(:,:,nmin:nmax)
419 ksupumnf(:,:,nmin:nmax) = -ksupumnf(:,:,nmin:nmax)
420 ksupvmnf(:,:,nmin:nmax) = -ksupvmnf(:,:,nmin:nmax)
440 SUBROUTINE cyl2vmec_a(A_r, A_p, A_z, cA_s, cA_u, cA_v)
445 REAL (dp),
DIMENSION(:,:),
INTENT(IN) :: A_r
446 REAL (dp),
DIMENSION(:,:),
INTENT(IN) :: A_p
447 REAL (dp),
DIMENSION(:,:),
INTENT(IN) :: A_z
448 REAL (dp),
DIMENSION(:,:),
INTENT(OUT) :: cA_s
449 REAL (dp),
DIMENSION(:,:),
INTENT(OUT) :: cA_u
450 REAL (dp),
DIMENSION(:,:),
INTENT(OUT) :: cA_v
453 REAL (dp),
DIMENSION(:,:),
ALLOCATABLE :: rs
454 REAL (dp),
DIMENSION(:,:),
ALLOCATABLE :: zs
460 ALLOCATE(rs(ntheta, nzeta))
461 ALLOCATE(zs(ntheta, nzeta))
462 rs = (
r1_i(:,:,ns) -
r1_i(:,:,ns - 1))*ohs
463 zs = (
z1_i(:,:,ns) -
z1_i(:,:,ns - 1))*ohs
465 ca_s(:,:) = a_r(:,:)*rs(:,:) + a_z(:,:)*zs(:,:)
466 ca_u(:,:) = a_r(:,:)*
ru_i(:,:,ns) + a_z(:,:)*
zu_i(:,:,ns)
467 ca_v(:,:) = a_r(:,:)*
rv_i(:,:,ns) + a_z(:,:)*
zv_i(:,:,ns)
468 + a_p(:,:)*
r1_i(:,:,ns)
494 SUBROUTINE init_a(cA_s, cA_u, cA_v, A_s, A_u, A_v, parity)
496 USE utilities,
ONLY: set_bndy_fouier_m0, set_bndy_full_origin
502 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: cA_s
503 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: cA_u
504 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: cA_v
505 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: A_s
506 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: A_u
507 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: A_v
508 INTEGER,
INTENT(IN) :: parity
527 IF (parity .EQ.
f_sin)
THEN
545 p1 = real(js-1,dp)/(ns-1)
551 a_s(m,n,js) = a_s(m,n,ns)*q1
552 a_u(m,n,js) = a_u(m,n,ns)*q1
553 a_v(m,n,js) = a_v(m,n,ns)*q1
554 IF (nmatch .gt. 0)
THEN
555 a_s(m,n,js) = t1*a_s(m,n,js) + (1 - t1)*a_s(m,n,nmatch
556 a_u(m,n,js) = t1*a_u(m,n,js) + (1 - t1)*a_u(m,n,nmatch
557 a_v(m,n,js) = t1*a_v(m,n,js) + (1 - t1)*a_v(m,n,nmatch
563 CALL set_bndy_fouier_m0(a_s, a_u, a_v, fours)
564 CALL set_bndy_full_origin(a_s, a_u, a_v)
585 SUBROUTINE init_f(Fsupsmn, Fsupumn, Fsupvmn, jcurrumn, jcurrvmn)
590 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: Fsupsmn
591 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: Fsupumn
592 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(out) :: Fsupvmn
593 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(in) :: jcurrumn
594 REAL (dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(in) :: jcurrvmn
606 CALL assert(all(jcurrumn(:,:,
nsp+1:).EQ.0._dp),
'jcurumn != 0 in vacuum!'
607 CALL assert(all(jcurrvmn(:,:,
nsp+1:).EQ.0._dp),
'jcurvmn != 0 in vacuum!'
609 fsupsmn(:,:,nsmin:nsmax) = 0
610 fsupumn(:,:,nsmin:nsmax) = jcurrumn(:,:,nsmin:nsmax)
611 fsupvmn(:,:,nsmin:nsmax) = jcurrvmn(:,:,nsmin:nsmax)
615 t1 = 1 - real(js-1,dp)/(
nsp-1)
616 fsupumn(:,:,js) = t1*fsupumn(:,:,js)
617 fsupvmn(:,:,js) = t1*fsupvmn(:,:,js)
656 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: Fsupumn
657 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: Fsupvmn
658 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: jcurrumn
659 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: jcurrvmn
675 ns_mid = (nsmin + nsmax)/2
677 CALL assert_eq(lbound(fsupumn,1), lbound(jcurrumn,1),
' LBOUND1 FAILED'
678 CALL assert_eq(lbound(fsupumn,2), lbound(jcurrumn,2),
' LBOUND2 FAILED'
680 WRITE (1000 + iam, 1000) ns_mid
682 noff = n + ntor + lbound(fsupumn,2)
684 moff = m + lbound(fsupumn,1)
686 WRITE (1000 + iam, 1001) m, n,
687 jcurrumn(moff,noff,ns_mid)*t1,
688 -fsupumn(moff,noff,ns_mid)*t1,
689 jcurrvmn(moff,noff,ns_mid)*t1,
690 -fsupvmn(moff,noff,ns_mid)*t1
694 1000
FORMAT(
' JS = ',i4,/
695 ' M N J^u F^u J^v F^v')
696 1001
FORMAT(2i6, 1p,4e12.4)
706 SUBROUTINE dump_a(js, iunit)
712 INTEGER,
INTENT(in) :: js
713 INTEGER,
INTENT(in) :: iunit
727 nsmin = lbound(asubsmnsf,3)
728 nsmax = ubound(asubsmnsf,3)
729 moff = lbound(asubsmnsf,1)
730 noff = lbound(asubsmnsf,2)
732 IF (js .lt. nsmin .or. js .gt. nsmax)
THEN
738 WRITE(iunit + 10, 1000)
744 IF (n .lt. 0 .and. m .eq. 0) cycle
745 WRITE(iunit + 10, 1001) n, m
747 WRITE(iunit + 10,1002) is,
748 asubsmnsf(mp,np,is) *
750 asubumncf(mp,np,is) *
752 asubvmncf(mp,np,is) *
760 WRITE(iunit, 1003) js, neqs
765 WRITE(iunit, 1004) m, n, asubsmnsf(mp,np,js) *
767 asubumncf(mp,np,js) *
769 asubvmncf(mp,np,js) *
775 IF (.not.
lasym) cycle
776 WRITE(iunit + 100, 1004) m, n, asubsmncf(mp,np,js) *
778 asubumnsf(mp,np,js) *
780 asubvmnsf(mp,np,js) *
791 1000
FORMAT(
' RAD A_s A_u A_v')
792 1001
FORMAT(
' N=',i2,
' M=',i2)
793 1002
FORMAT(i4,3(1p,e12.4))
794 1003
FORMAT(
' RADIUS(JS): ',i4,
' NEQS: ',i6,
795 /,
' M N A_s A_u A_v '
797 1004
FORMAT(2i8, 5(1p,e12.4))
807 SUBROUTINE dump_b(js, iunit)
818 INTEGER,
INTENT(IN) :: js
819 INTEGER,
INTENT(IN) :: iunit
841 ALLOCATE(jacobmnch(0:mpol,-ntor:ntor,ns))
844 ALLOCATE(jacobmnsh(0:mpol,-ntor:ntor,ns))
857 WRITE(iunit + 10,1000)
859 IF (endglobrow .EQ. ns)
THEN
863 IF (n.lt.0 .AND. m.eq.0) cycle
865 WRITE(iunit + 10, 1001) m, n,
866 (1.5_dp*jbsupsmnsh(m,n,is) -
867 0.5_dp*jbsupsmnsh(m,n,is - 1)
868 (1.5_dp*jbsupumnch(m,n,is) -
869 0.5_dp*jbsupumnch(m,n,is - 1)
870 (1.5_dp*jbsupvmnch(m,n,is) -
871 0.5_dp*jbsupvmnch(m,n,is - 1)
875 WRITE(iunit + 10,1002)
878 IF (n.LT.0 .AND. m.EQ.0) cycle
880 WRITE(iunit + 10,1003) n, m
882 WRITE(iunit + 10, 1004) is, jbsupsmnsh(m,n,is)*t1,
883 jbsupumnch(m,n,is)*t1,
884 jbsupvmnch(m,n,is)*t1
890 CALL flush(iunit + 10)
897 WRITE(iunit, 1005) js, neqs
901 WRITE(iunit + 100, 1007)
907 WRITE(iunit, 1008) m, n, jbsupsmnsh(m,n,js)*t1,
908 jbsupumnch(m,n,js)*t1,
909 jbsupvmnch(m,n,js)*t1,
912 WRITE(iunit+100, 1008) m, n, jbsupsmnch(m,n,js)*t1,
913 jbsupumnsh(m,n,js)*t1,
914 jbsupvmnsh(m,n,js)*t1,
934 DO is =
nsin + 1, ns - 1, 1
935 chipf_i(is) = -(jbsupumnch(0,0,is + 1) + jbsupumnch(0,0,is))*0.
936 phipf_i(is) = -(jbsupvmnch(0,0,is + 1) + jbsupvmnch(0,0,is))*0.
938 IF (ns .gt.
nsin)
THEN
939 chipf_i(ns) = -2.5*jbsupumnch(0,0,ns) + 1.5*jbsupumnch(0,0,ns -
940 phipf_i(ns) = -2.5*jbsupvmnch(0,0,ns) + 1.5*jbsupvmnch(0,0,ns -
956 rbsupv = rbsupv*r1_i(1,1,ns)/rjac
958 WRITE (*,1009) rjac, jacobh(1,1,ns), rbsupv
967 WRITE (*,1011) rho, 0.5_dp*(chipf_i(is) + chipf_i(is - 1)),
969 -(asubvmncf(1,ntor + 1,is - 1) -
970 asubvmncf(1,ntor + 1,is))*ohs,
971 0.5_dp*(phipf_i(is) + phipf_i(is - 1)),
973 -(asubumncf(1,ntor + 1,is) -
974 asubumncf(1,ntor + 1,is-1))*ohs
981 chipf_i(is) = -(jbsupumnch(0,0,is + 1) + jbsupumnch(0,0,is))*0.
982 phipf_i(is) = -(jbsupvmnch(0,0,is + 1) + jbsupvmnch(0,0,is))*0.
985 1000
FORMAT(
' EDGE VALUES OF jB^X FOR ALL M,N',/,
986 ' M N jB^s jB^u jB^v')
987 1001
FORMAT(2i4,3(1p,e10.2))
988 1002
FORMAT(/,
' RAD jB^s jB^u jB^v')
989 1003
FORMAT(
' N=',i2,
' M=',i2)
990 1004
FORMAT(i4,3(1p,e11.3))
991 1005
FORMAT(
'HALF RADIUS (JS): ',i4,
' NEQS: ',i6)
992 1006
FORMAT(
' M N jB^s(sin) jB^u(cos) jB^v(cos) jacob(cos)'
993 1007
FORMAT(
' M N jB^s(cos) jB^u(sin) jB^v(sin) jacob(sin)'
994 1008
FORMAT(2i8, 5(1p,e12.4))
995 1009
FORMAT(
' jac(u=0,v=0,ns): ',1p,e12.3,
' jacobh: ',1p,e12.3,/
996 ' R*B^v(u=0,v=0,ns) : ',1p,e12.3)
997 1010
FORMAT(/,
' RAD CHIP(WOUT) CHIP(PCH) CHIP(VP)'
998 ' PHIP(WOUT) PHIP(PCH) PHIP(VP)')
999 1011
FORMAT(f7.3,1p,6e14.3)
1006 SUBROUTINE getfsq_pchelms
1014 nsmin = startglobrow
1017 fsq_total = sum(
fsupsmnsf(:,:,nsmin:nsmax)**2 +
1021 fsq_total = fsq_total
1026 #if defined(MPI_OPT)
1027 CALL mpi_allreduce(mpi_in_place, fsq_total, 1, mpi_real8, mpi_sum,
1028 siesta_comm, mpi_err)
1030 IF (bnorm .GT. zero) fsq_total = fsq_total/bnorm
1043 DEALLOCATE(xc0, gc0)
1045 IF (
ALLOCATED(jacobmnch))
THEN
1046 DEALLOCATE(jacobmnch)
1048 IF (
lasym .and.
ALLOCATED(jacobmnsh))
THEN
1049 DEALLOCATE(jacobmnsh)
1052 DEALLOCATE(bsupsijh, bsupuijh, bsupvijh)
1053 DEALLOCATE(bsubsijh, bsubuijh, bsubvijh)
1064 SUBROUTINE check_current
1071 REAL (dp) :: currv_int
1075 IF (endglobrow .eq. ns)
THEN
1076 currv_int = hs*(sum(jcurrvmnc(0,0,1:ns - 1)) + jcurrvmnc(0,0,ns
1077 WRITE (*,1000) line_bu, currv_int, jsupvdota
1080 1000
FORMAT(
' Line Integral B_u: ',1p,e12.4,4x,
1081 ' Surface-integrated current: ',1p,e12.4,4x,
1082 ' VMEC Surface-integrated current: ',1p,e12.4)
1089 SUBROUTINE compute_forces_lin
1095 CALL compute_forces(.false.)
1114 CALL init_f(fsupsmnsf, fsupumncf, fsupvmncf,
1115 jcurrumnc, jcurrvmnc)
1117 CALL init_f(fsupsmncf, fsupumnsf, fsupvmnsf,
1118 jcurrumns, jcurrvmns)
1122 CALL compute_forces(.true.)
1125 IF (iam .EQ. 0)
THEN
1126 WRITE(*,1000) fsq_total, maxval(abs(gc)), sqrt(sum(xc*xc))
1129 1000
FORMAT(/,
' Back Solve Check',
1130 /,
' |F|^2: ',1p,e10.3,
' MAX |F|: ', 1pe10.3,
' |X|: ',1pe10
1137 SUBROUTINE init_pchelms
1139 USE descriptor_mod,
ONLY: iam, nprocs
1140 USE nscalingtools,
ONLY: initremap
1157 mblk_size = ndims*mnmax
1158 CALL initialize(ns, mblk_size)
1163 CALL init_ptrs(xc, asubsmnsf, asubumncf, asubvmncf,
1164 asubsmncf, asubumnsf, asubvmnsf)
1166 CALL init_ptrs(gc, fsupsmnsf, fsupumncf, fsupvmncf,
1167 fsupsmncf, fsupumnsf, fsupvmnsf)
1170 CALL initremap(mpol, ntor, ns, nprocs, iam)
1172 CALL compute_forces(.true.)
1183 SUBROUTINE compute_forces(lNLinear)
1197 LOGICAL,
INTENT(in) :: lNLinear
1202 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: A_r
1203 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: A_p
1204 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: A_z
1205 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: cA_s
1206 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: cA_u
1207 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: cA_v
1210 nsmin = startglobrow
1211 nsmax = min(ns,endglobrow + 1)
1215 IF (bnorm .LT. 0)
THEN
1217 IF (.NOT.
ALLOCATED(xc0))
THEN
1219 CALL assert(
ALLOCATED(jbsupsmnsh),
'B^S not allocated!')
1221 CALL assert(
ALLOCATED(jbsupsmnch),
'B^S not allocated!')
1223 ALLOCATE(bsupsijh(ntheta,nzeta,nsmin:nsmax),
1224 bsupuijh(ntheta,nzeta,nsmin:nsmax),
1225 bsupvijh(ntheta,nzeta,nsmin:nsmax),
1226 bsubsijh(ntheta,nzeta,nsmin:nsmax),
1227 bsubuijh(ntheta,nzeta,nsmin:nsmax),
1228 bsubvijh(ntheta,nzeta,nsmin:nsmax), stat=istat)
1229 CALL assert_eq(0, istat,
'Allocation failed in COMPUTE_FORCES'
1233 jcurrumnc, jcurrvmnc)
1236 jcurrumns, jcurrvmns)
1243 dphi = (2*pi)/(nfp*nzeta)
1244 ALLOCATE(a_r(ntheta,nzeta,1),
1245 a_p(ntheta,nzeta,1),
1246 a_z(ntheta,nzeta,1))
1251 ALLOCATE(ca_s(ntheta,nzeta,1),
1252 ca_u(ntheta,nzeta,1),
1253 ca_v(ntheta,nzeta,1))
1254 CALL cyl2vmec_a(a_r(:,:,1), a_p(:,:,1), a_z(:,:,1),
1255 ca_s(:,:,1), ca_u(:,:,1), ca_v(:,:,1))
1256 DEALLOCATE(a_r, a_p, a_z)
1263 DEALLOCATE(ca_s, ca_u, ca_v)
1272 nsmin = max(1, startglobrow - 1)
1273 nsmax = min(ns, endglobrow + 1)
1275 jbsupsmnsh, jbsupumnch, jbsupvmnch,
f_sin)
1278 jbsupsmnch, jbsupumnsh, jbsupvmnsh,
f_cos)
1282 nsmin = startglobrow
1284 bsupsijh = bsupsijh/jacobh(:,:,nsmin:nsmax)
1285 bsupuijh = bsupuijh/jacobh(:,:,nsmin:nsmax)
1286 bsupvijh = bsupvijh/jacobh(:,:,nsmin:nsmax)
1289 CALL tolowerh(bsupsijh, bsupuijh, bsupvijh,
1290 bsubsijh, bsubuijh, bsubvijh, nsmin, nsmax)
1295 nsmin = startglobrow
1296 nsmax = min(ns, endglobrow + 1)
1304 IF (nsmax .eq. ns)
THEN
1320 IF (linit .OR. lnlinear)
THEN
1337 IF (lnlinear .OR. linit)
THEN
1353 USE hessian,
ONLY: l_compute_hessian
1354 USE utilities,
ONLY: set_bndy_fouier_m0, set_bndy_full_origin
1359 REAL(dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(inout) :: Fsupsmn
1360 REAL(dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(inout) :: Fsupumn
1361 REAL(dp),
DIMENSION(0:mpol,-ntor:ntor,ns),
INTENT(inout) :: Fsupvmn
1362 INTEGER,
INTENT(in) :: iparity
1368 IF (endglobrow .EQ. ns)
THEN
1376 CALL set_bndy_fouier_m0(fsupsmn, fsupumn, fsupvmn, iparity)
1377 IF (startglobrow .eq. 1)
THEN
1378 CALL set_bndy_full_origin(fsupsmn, fsupumn, fsupvmn)
1382 IF (ns_match .GE. nsmin)
THEN
1383 nmatch = min(ns_match, nsmax)
1384 fsupumn(
m1,:,nsmin:nmatch) = 0
1385 fsupvmn(
m1,:,nsmin:nmatch) = 0
1396 USE descriptor_mod,
ONLY: siesta_comm, iam, nprocs
1397 USE gmres_lib,
ONLY:
gmres_info, gmres_par, gmres_ser
1398 USE hessian,
ONLY: apply_precond
1404 TYPE (gmres_info) :: gi
1408 REAL (dp),
DIMENSION(:),
ALLOCATABLE :: b
1409 REAL (dp),
DIMENSION(:),
ALLOCATABLE :: x0
1412 INTEGER,
PARAMETER :: noPrec = 0
1413 integer,
PARAMETER :: leftprec = 1
1414 INTEGER,
PARAMETER :: rightPrec = 2
1415 INTEGER,
PARAMETER :: dblePrec = 3
1416 REAL (dp),
PARAMETER :: one = 1
1417 REAL (dp),
PARAMETER :: ftol = 1.e-18_dp
1420 ALLOCATE(b(neqs), x0(neqs))
1424 CALL compute_forces(.true.)
1425 IF (iam .EQ. 0)
THEN
1428 WRITE (*,1001) 1, fsq_total, sqrt(sum(xc0**2))
1431 WRITE (
unit_out, 1001) 1, fsq_total, sqrt(sum(xc0**2))
1438 CALL init_dgmres(gi%icntl, gi%cntl)
1442 gi%cntl(1) = sqrt(ftol)
1448 gi%icntl(4) = rightprec
1460 gi%l_nonlinear = .false.
1473 gi%endglobrow = endglobrow
1474 gi%startglobrow = startglobrow
1475 gi%mblk_size = mblk_size
1476 gi%rcounts => rcounts
1479 gi%my_comm = siesta_comm
1480 gi%my_comm_world = siesta_comm
1493 1000
FORMAT(
' NEQS : ',i6)
1494 1001
FORMAT(
' ITER: ',i6,3x,
'|F|^2: ',1pe12.3,3x,
' |X| = ',1pe12.3)
1511 REAL(dp),
INTENT(IN) :: p(ndim)
1512 REAL(dp),
INTENT(OUT) :: Ap(ndim)
1513 INTEGER,
INTENT(IN) :: ndim
1516 CALL assert_eq(neqs, ndim,
' neqs != ndim')
1519 CALL compute_forces(.false.)
1532 USE hessian,
ONLY: eps_factor
1539 REAL(dp),
DIMENSION(nloc),
INTENT(IN) :: ploc
1540 REAL(dp),
DIMENSION(nloc),
INTENT(OUT) :: Ap
1541 INTEGER,
INTENT(IN) :: nloc
1544 INTEGER :: myrowstart
1547 REAL (dp),
DIMENSION(:),
ALLOCATABLE :: p
1550 istat = (endglobrow - startglobrow + 1)*mblk_size
1551 CALL assert_eq(istat, nloc,
'nloc wrong in matvec_par')
1553 myrowstart = (startglobrow - 1)*mblk_size + 1
1554 myrowend = myrowstart + nloc - 1
1556 ALLOCATE (p(ns*mblk_size), stat=istat)
1557 CALL assert_eq(0, istat,
'Allocation error in matvec_par')
1559 p(myrowstart:myrowend) = ploc
1560 CALL padsides(p, mblk_size, 1, 1)
1563 CALL compute_forces(.false.)
1564 ap = -gc(myrowstart:myrowend)
1582 REAL (dp),
DIMENSION(neqs),
INTENT(IN) :: xcstate
1583 REAL (dp),
INTENT(OUT) :: fsq_nl
1584 REAL (dp),
INTENT(IN) :: bnorm
1591 1000
FORMAT(
'PCHELMS should not get here.')