13 ntor=>ntor_i, nfp=>nfp_i
26 INTERFACE to_full_mesh
27 MODULE PROCEDURE to_full_mesh2, to_full_mesh3
34 INTERFACE to_half_mesh
35 MODULE PROCEDURE to_half_mesh, to_half_mesh_p
42 INTERFACE gradienthalf
43 MODULE PROCEDURE gradienthalf, gradienthalf_p
51 MODULE PROCEDURE curl_htof, curl_htof_targ
60 INTERFACE set_bndy_half_to_full
61 MODULE PROCEDURE set_bndy_half_to_full, set_bndy_half_to_full_vec
70 INTERFACE set_bndy_half_to_full_ds
71 MODULE PROCEDURE set_bndy_half_to_full_ds, set_bndy_half_to_full_uv_ds
79 INTERFACE set_bndy_fouier_m0
80 MODULE PROCEDURE set_bndy_fouier_m0, set_bndy_fouier_m0_vec
96 SUBROUTINE gradienthalf(gradienth, vecf)
101 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: gradienth
102 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: vecf
109 nsmin = lbound(gradienth,3)
110 nsmax = ubound(gradienth,3)
112 gradienth(:,:,nsmin + 1:nsmax) = ohs*(vecf(:,:,nsmin + 1:nsmax)
113 - vecf(:,:,nsmin:nsmax - 1))
114 gradienth(:,:,nsmin) = 0
127 SUBROUTINE gradienthalf_p(gradienth, vecf)
132 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: gradienth
133 REAL (dp),
DIMENSION(:,:,:),
POINTER :: vecf
140 nsmin = lbound(gradienth,3)
141 nsmax = ubound(gradienth,3)
143 gradienth(:,:,nsmin + 1:nsmax) = ohs*(vecf(:,:,nsmin + 1:nsmax)
144 - vecf(:,:,nsmin:nsmax - 1))
145 gradienth(:,:,nsmin) = 0
157 SUBROUTINE gradientfull(gradientf, vech)
162 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: gradientf
163 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: vech
170 nsmin = lbound(vech,3)
171 nsmax = ubound(vech,3)
173 gradientf(:,:,nsmin:nsmax - 1) = ohs*(vech(:,:,nsmin + 1:nsmax)
174 - vech(:,:,nsmin:nsmax - 1))
176 IF (ubound(gradientf,3) .ge. nsmax)
THEN
177 gradientf(:,:,nsmax:) = 0
180 IF (nsmin .eq. 1)
THEN
184 IF (nsmax .eq. ns)
THEN
185 gradientf(:,:,ns) = gradientf(:,:,ns - 1)
198 SUBROUTINE to_half_mesh(vecf, vech)
203 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: vecf
204 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: vech
211 nsmin = lbound(vech,3)
212 nsmax = ubound(vech,3)
214 vech(:,:,nsmin + 1:nsmax) = (vecf(:,:,nsmin:nsmax - 1)
215 + vecf(:,:,nsmin + 1:nsmax))*0.5
229 SUBROUTINE to_half_mesh_p(vecf, vech)
234 REAL (dp),
DIMENSION(:,:,:),
POINTER :: vecf
235 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: vech
242 nsmin = lbound(vech,3)
243 nsmax = ubound(vech,3)
244 vech(:,:,nsmin + 1:nsmax) = (vecf(:,:,nsmin:nsmax - 1)
245 + vecf(:,:,nsmin + 1:nsmax))*0.5
260 SUBROUTINE to_full_mesh3(vech, vecf)
265 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: vech
266 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: vecf
273 nsmin = lbound(vecf, 3)
274 CALL assert(nsmin .ge. lbound(vech,3),
'LBOUND WRONG IN to_full_mesh3'
275 nsmax = ubound(vecf, 3)
276 CALL assert(nsmax .le. ubound(vech,3),
'UBOUND WRONG IN to_full_mesh3'
278 vecf(:,:,nsmin:nsmax - 1) = 0.5*(vech(:,:,nsmin + 1:nsmax)
279 + vech(:,:,nsmin:nsmax - 1))
281 IF (nsmin .eq. 1)
THEN
282 vecf(:,:,1) = vech(:,:,2)
284 IF (nsmax .eq. ns)
THEN
285 vecf(:,:,ns) = vech(:,:,ns)
300 SUBROUTINE to_full_mesh2(vech, vecf)
305 REAL (dp),
DIMENSION(:,:),
ALLOCATABLE,
INTENT(in) :: vech
306 REAL (dp),
DIMENSION(:,:),
ALLOCATABLE,
INTENT(inout) :: vecf
313 nsmin = lbound(vecf,2)
314 CALL assert(nsmin .ge. lbound(vech,2),
'LBOUND WRONG IN to_full_mesh2'
315 nsmax = ubound(vecf,2)
316 CALL assert(nsmax .le. ubound(vech,2),
'UBOUND WRONG IN to_full_mesh2'
318 vecf(:,nsmin:nsmax - 1) = 0.5*(vech(:,nsmin:nsmax - 1)
319 + vech(:,nsmin + 1:nsmax))
322 IF (nsmin .EQ. 1)
THEN
323 vecf(:,1) = vech(:,2)
325 IF (nsmax .EQ. ns)
THEN
326 vecf(:,ns)= vech(:,ns)
356 SUBROUTINE curl_ftoh(asubsmnf, asubumnf, asubvmnf, &
357 jbsupsmnh, jbsupumnh, jbsupvmnh, parity, &
359 USE nscalingtools,
ONLY: startglobrow
364 REAL (dp),
DIMENSION(:,:,:),
POINTER :: asubsmnf
365 REAL (dp),
DIMENSION(:,:,:),
POINTER :: asubumnf
366 REAL (dp),
DIMENSION(:,:,:),
POINTER :: asubvmnf
367 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupsmnh
368 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupumnh
369 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(inout) :: jbsupvmnh
370 INTEGER,
INTENT(IN) :: parity
371 INTEGER,
INTENT(IN) :: nsmin
372 INTEGER,
INTENT(IN) :: nsmax
383 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: asubsmnh
384 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: asubumnh
385 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: asubvmnh
386 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: da_uds
387 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:) :: da_vds
390 CALL assert(nsmax .le. ubound(jbsupsmnh,3),
'UBOUND wrong in curl_ftoh'
392 IF (parity .EQ.
f_sin)
THEN
400 ALLOCATE(asubsmnh(0:mpol,-ntor:ntor,nsmin:nsmax),
401 asubumnh(0:mpol,-ntor:ntor,nsmin:nsmax),
402 asubvmnh(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
403 CALL assert_eq(0, istat,
'Allocation1 failed in curl_ftoh')
405 CALL to_half_mesh(asubsmnf, asubsmnh)
406 CALL to_half_mesh(asubumnf, asubumnh)
407 CALL to_half_mesh(asubvmnf, asubvmnh)
409 CALL set_bndy_fouier_m0(asubsmnh, asubumnh, asubvmnh, parity)
412 ALLOCATE(da_uds(0:mpol,-ntor:ntor,nsmin:nsmax),
413 da_vds(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
414 CALL assert_eq(0, istat,
'Allocation2 failed in curl_ftoh')
418 CALL gradienthalf(da_uds, asubumnf)
419 CALL gradienthalf(da_vds, asubvmnf)
421 CALL set_bndy_fouier_m0(da_uds, fouruv)
422 CALL set_bndy_fouier_m0(da_vds, fouruv)
424 nmin = max(2, startglobrow)
425 CALL assert(nmin .ge. lbound(jbsupsmnh,3),
'LBOUND wrong in curl_ftoh'
432 jbsupsmnh(m,n,nmin:nsmax) = np*asubumnh(m,n,nmin:nsmax)
433 - mp*asubvmnh(m,n,nmin:nsmax)
434 jbsupumnh(m,n,nmin:nsmax) = np*asubsmnh(m,n,nmin:nsmax)
435 - da_vds(m,n,nmin:nsmax)
436 jbsupvmnh(m,n,nmin:nsmax) = da_uds(m,n,nmin:nsmax)
437 - mp*asubsmnh(m,n,nmin:nsmax)
441 DEALLOCATE (asubsmnh, asubumnh, asubvmnh, da_vds, da_uds, stat=istat
442 CALL assert_eq(0, istat,
'Deallocation failed in curl_ftoh')
444 IF (startglobrow .eq. 1)
THEN
450 CALL set_bndy_fouier_m0(jbsupsmnh, jbsupumnh, jbsupvmnh, parity)
481 SUBROUTINE curl_htof(asubsmnh, asubumnh, asubvmnh, &
482 jbsupsmnf, jbsupumnf, jbsupvmnf, parity, &
483 nsmin, nsmax, extend, curtor)
484 USE nscalingtools,
ONLY: endglobrow
490 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: asubsmnh
491 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: asubumnh
492 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
INTENT(in) :: asubvmnh
493 REAL (dp),
DIMENSION(:,:,:),
POINTER :: jbsupsmnf
494 REAL (dp),
DIMENSION(:,:,:),
POINTER :: jbsupumnf
495 REAL (dp),
DIMENSION(:,:,:),
POINTER :: jbsupvmnf
496 INTEGER,
INTENT(in) :: parity
497 INTEGER,
INTENT(in) :: nsmin
498 INTEGER,
INTENT(in) :: nsmax
499 LOGICAL,
INTENT(in) :: extend
500 REAL (dp),
INTENT(inout) :: curtor
514 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: asubsmnf
515 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: asubumnf
516 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: asubvmnf
517 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: da_uds
518 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE :: da_vds
523 CALL assert(nsmin .ge. lbound(jbsupsmnf,3),
'LBOUND wrong in curl_htof'
525 IF (parity .eq.
f_sin)
THEN
535 moff = lbound(jbsupsmnf,1)
536 noff = lbound(jbsupsmnf,2) + ntor
538 ALLOCATE(asubsmnf(0:mpol,-ntor:ntor,nsmin:nsmax),
539 asubumnf(0:mpol,-ntor:ntor,nsmin:nsmax),
540 asubvmnf(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
541 CALL assert_eq(0, istat,
'Allocation1 failed in curl_htof')
543 CALL to_full_mesh(asubsmnh, asubsmnf)
544 CALL to_full_mesh(asubumnh, asubumnf)
545 CALL to_full_mesh(asubvmnh, asubvmnf)
548 CALL set_bndy_half_to_full(asubsmnh, asubvmnh, nsmin, parity,
549 asubsmnf, asubumnf, asubvmnf)
552 IF (parity .eq.
f_sin .and. nsmax .eq. ns)
THEN
553 curtor = twopi*asubumnf(
m0,
n0,ns)/mu0
557 ALLOCATE(da_uds(0:mpol,-ntor:ntor,nsmin:nsmax),
558 da_vds(0:mpol,-ntor:ntor,nsmin:nsmax), stat=istat)
559 CALL assert_eq(0, istat,
'Allocation2 failed in curl_htof')
563 CALL gradientfull(da_uds, asubumnh)
564 CALL gradientfull(da_vds, asubvmnh)
566 CALL set_bndy_half_to_full_uv_ds(asubumnh, asubvmnh,
567 da_uds, da_vds, nsmin, fouruv)
570 nmax = min(ns, endglobrow + 1)
572 nmax = min(ns, endglobrow)
574 CALL assert(nmax .le. ubound(jbsupsmnf,3),
'UBOUND wrong in curl_htof'
583 jbsupsmnf(mo,no,nsmin:nmax) = np*asubumnf(m,n,nsmin:nmax)
584 - mp*asubvmnf(m,n,nsmin:nmax)
585 jbsupumnf(mo,no,nsmin:nmax) = np*asubsmnf(m,n,nsmin:nmax)
586 - da_vds(m,n,nsmin:nmax)
587 jbsupvmnf(mo,no,nsmin:nmax) = da_uds(m,n,nsmin:nmax)
588 - mp*asubsmnf(m,n,nsmin:nmax)
592 DEALLOCATE(asubsmnf, asubumnf, asubvmnf, da_uds, da_vds)
595 jbsupsmnf(:,:,nmax+1:ubound(jbsupsmnf,3)) = 0
596 jbsupumnf(:,:,nmax+1:ubound(jbsupsmnf,3)) = 0
597 jbsupvmnf(:,:,nmax+1:ubound(jbsupsmnf,3)) = 0
599 jbsupsmnf(:,:,lbound(jbsupsmnf,3):nsmin-1) = 0
600 jbsupumnf(:,:,lbound(jbsupsmnf,3):nsmin-1) = 0
601 jbsupvmnf(:,:,lbound(jbsupsmnf,3):nsmin-1) = 0
603 CALL set_bndy_fouier_m0(jbsupsmnf, jbsupumnf, jbsupvmnf, parity)
604 IF (nsmin .eq. 1)
THEN
605 CALL set_bndy_full_origin(jbsupsmnf, jbsupumnf, jbsupvmnf)
629 SUBROUTINE curl_htof_targ(asubsmnh, asubumnh, asubvmnh, &
630 jbsupsmnf, jbsupumnf, jbsupvmnf, &
631 parity, nsmin, nsmax, extend, curtor)
634 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: asubsmnh
635 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: asubumnh
636 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: asubvmnh
637 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
TARGET,
INTENT(inout) ::
639 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
TARGET,
INTENT(inout) ::
641 REAL (dp),
DIMENSION(:,:,:),
ALLOCATABLE,
TARGET,
INTENT(inout) ::
643 INTEGER,
INTENT(IN) :: parity
644 INTEGER,
INTENT(IN) :: nsmin
645 INTEGER,
INTENT(IN) :: nsmax
646 LOGICAL,
INTENT(in) :: extend
647 REAL (dp),
INTENT(inout) :: curtor
650 REAL (dp),
POINTER,
DIMENSION(:,:,:) :: jbsp
651 REAL (dp),
POINTER,
DIMENSION(:,:,:) :: jbup
652 REAL (dp),
POINTER,
DIMENSION(:,:,:) :: jbvp
658 CALL curl_htof(asubsmnh, asubumnh, asubvmnh,
659 jbsp, jbup, jbvp, parity, nsmin, nsmax, extend,
678 PURE SUBROUTINE set_bndy_half_to_full(amnh, amnf, nsmin, parity)
683 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: amnh
684 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: amnf
685 INTEGER,
INTENT(IN) :: nsmin
686 INTEGER,
INTENT(in) :: parity
689 IF (nsmin .eq. 1)
THEN
694 IF (parity .eq.
f_cos)
THEN
695 amnf(
m0,-ntor:-
n1,:) = 0.0
697 amnf(
m0,-ntor:
n0,:) = 0.0
718 PURE SUBROUTINE set_bndy_half_to_full_vec(asubsmnh, asubvmnh, &
720 asubsmnf, asubumnf, asubvmnf)
725 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: asubsmnh
726 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(in) :: asubvmnh
727 INTEGER,
INTENT(IN) :: nsmin
728 INTEGER,
INTENT(in) :: parity
729 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: asubsmnf
730 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: asubumnf
731 REAL (dp),
ALLOCATABLE,
DIMENSION(:,:,:),
INTENT(inout) :: asubvmnf
738 moffh = lbound(asubsmnh, 1)
739 mofff = lbound(asubsmnf, 1)
741 IF (nsmin .eq. 1)
THEN
743 asubsmnf(
m1 + mofff,:,1) = asubsmnh(
m1 + moffh,:,2)
748 asubvmnf(
m0 + mofff,:,1) = asubvmnh(
m0 + moffh,:,2)
751 CALL set_bndy_fouier_m0(asubsmnf, asubumnf, asubvmnf, parity)
769 PURE SUBROUTINE set_bndy_half_to_full_ds(amnh, amnf_ds, nsmin, parity)
774 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: amnh
775 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnf_ds
776 INTEGER,
INTENT(IN) :: nsmin
777 INTEGER,
INTENT(in) :: parity
783 IF (nsmin .eq. 1)
THEN
784 moff = lbound(amnh, 1)
787 amnf_ds(
m1 + moff,:,1) = 2.0*ohs*amnh(
m1 + moff,:,2)
790 CALL set_bndy_fouier_m0(amnf_ds, parity)
810 PURE SUBROUTINE set_bndy_half_to_full_uv_ds(aumnh, avmnh, &
811 aumnf_ds, avmnf_ds, &
817 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: aumnh
818 REAL (dp),
DIMENSION(:,:,:),
INTENT(in) :: avmnh
819 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: aumnf_ds
820 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: avmnf_ds
821 INTEGER,
INTENT(IN) :: nsmin
822 INTEGER,
INTENT(in) :: parity
828 IF (nsmin .eq. 1)
THEN
829 moff = lbound(aumnh, 1)
831 aumnf_ds(:,:,1) = 0.0
832 aumnf_ds(
m0 + moff,:,1) = 2.0*ohs*aumnh(
m0 + moff,:,2)
834 avmnf_ds(:,:,1) = 0.0
837 CALL set_bndy_fouier_m0(aumnf_ds, parity)
838 CALL set_bndy_fouier_m0(avmnf_ds, parity)
854 PURE SUBROUTINE set_bndy_full_origin(amnsf, amnuf, amnvf)
859 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnsf
860 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnuf
861 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnvf
867 moff = lbound(amnsf, 1)
869 amnsf(
m0 + moff,:,1) = 0
870 IF (
m2 + moff .lt. ubound(amnsf, 1))
THEN
871 amnsf(
m2 + moff:,:,1) = 0
876 amnvf(
m1 + moff:,:,1) = 0
890 PURE SUBROUTINE set_bndy_fouier_m0(amn, parity)
895 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amn
896 INTEGER,
INTENT(in) :: parity
903 moff = lbound(amn, 1)
904 noff = lbound(amn, 2) + ntor
906 IF (parity .eq.
f_cos)
THEN
907 amn(
m0 + moff,-ntor+noff:-
n1+noff,:) = 0
909 amn(
m0 + moff,-ntor+noff:
n0+noff,:) = 0
926 PURE SUBROUTINE set_bndy_fouier_m0_vec(amns, amnu, amnv, parity)
932 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amns
933 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnu
934 REAL (dp),
DIMENSION(:,:,:),
INTENT(inout) :: amnv
935 INTEGER,
INTENT(in) :: parity
938 IF (parity .eq.
f_cos)
THEN
939 CALL set_bndy_fouier_m0(amns,
f_cos)
940 CALL set_bndy_fouier_m0(amnu,
f_sin)
941 CALL set_bndy_fouier_m0(amnv,
f_sin)
943 CALL set_bndy_fouier_m0(amns,
f_sin)
944 CALL set_bndy_fouier_m0(amnu,
f_cos)
945 CALL set_bndy_fouier_m0(amnv,
f_cos)