diff --git a/src/advance_field.F90 b/src/advance_field.F90 index b5429068b017229ab8fef641749ec0cd79f7ab8b..77c8b76043c38fadc0f1913f2a1239cd20022906 100644 --- a/src/advance_field.F90 +++ b/src/advance_field.F90 @@ -30,27 +30,27 @@ CONTAINS SELECT CASE (updatetlevel) CASE(1) DO istage=1,ntimelevel - moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,1) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,1) & - + dt*b_E(istage)*moments_rhs_e(ips_e:ipe_e,ijs_e:ije_e,:,:,istage) + moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,1) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,1) & + + dt*b_E(istage)*moments_rhs_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,istage) END DO ! Advance ions DO istage=1,ntimelevel - moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,1) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,1) & - + dt*b_E(istage)*moments_rhs_i(ips_i:ipe_i,ijs_i:ije_i,:,:,istage) + moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,1) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,1) & + + dt*b_E(istage)*moments_rhs_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,istage) END DO CASE DEFAULT ! Advance electrons - moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,updatetlevel) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,1); + moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,updatetlevel) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,1); DO istage=1,updatetlevel-1 - moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,updatetlevel) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,updatetlevel) & - + dt*A_E(updatetlevel,istage)*moments_rhs_e(ips_e:ipe_e,ijs_e:ije_e,:,:,istage) + moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,updatetlevel) = moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,updatetlevel) & + + dt*A_E(updatetlevel,istage)*moments_rhs_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,istage) END DO ! Advance ions - moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,updatetlevel) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,1); + moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,updatetlevel) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,1); DO istage=1,updatetlevel-1 - moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,updatetlevel) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,updatetlevel) & - + dt*A_E(updatetlevel,istage)*moments_rhs_i(ips_i:ipe_i,ijs_i:ije_i,:,:,istage) + moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,updatetlevel) = moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,updatetlevel) & + + dt*A_E(updatetlevel,istage)*moments_rhs_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,istage) END DO END SELECT ! Execution time end @@ -68,26 +68,30 @@ CONTAINS use prec_const IMPLICIT NONE - COMPLEX(dp), DIMENSION ( ikrs:ikre, ikzs:ikze, ntimelevel ) :: f - COMPLEX(dp), DIMENSION ( ikrs:ikre, ikzs:ikze, ntimelevel ) :: f_rhs + COMPLEX(dp), DIMENSION ( ikxs:ikxe, ikys:ikye, izs:ize, ntimelevel ) :: f + COMPLEX(dp), DIMENSION ( ikxs:ikxe, ikys:ikye, izs:ize, ntimelevel ) :: f_rhs INTEGER :: istage SELECT CASE (updatetlevel) CASE(1) - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre - DO istage=1,ntimelevel - f(ikr,ikz,1) = f(ikr,ikz,1) + dt*b_E(istage)*f_rhs(ikr,ikz,istage) + DO iky=ikys,ikye + DO ikx=ikxs,ikxe + DO iz=izs,ize + DO istage=1,ntimelevel + f(ikx,iky,iz,1) = f(ikx,iky,iz,1) + dt*b_E(istage)*f_rhs(ikx,iky,iz,istage) + END DO END DO END DO END DO CASE DEFAULT - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre - f(ikr,ikz,updatetlevel) = f(ikr,ikz,1); - DO istage=1,updatetlevel-1 - f(ikr,ikz,updatetlevel) = f(ikr,ikz,updatetlevel) + & - dt*A_E(updatetlevel,istage)*f_rhs(ikr,ikz,istage) + DO iky=ikys,ikye + DO ikx=ikxs,ikxe + DO iz=izs,ize + f(ikx,iky,iz,updatetlevel) = f(ikx,iky,iz,1); + DO istage=1,updatetlevel-1 + f(ikx,iky,iz,updatetlevel) = f(ikx,iky,iz,updatetlevel) + & + dt*A_E(updatetlevel,istage)*f_rhs(ikx,iky,iz,istage) + END DO END DO END DO END DO diff --git a/src/advance_field_adapt.F90 b/src/advance_field_adapt.F90 index 238090440aabdcd715c182bf021a17f52446ade0..aed2a7e3d243058e6c05cb152617437cf7e59f80 100644 --- a/src/advance_field_adapt.F90 +++ b/src/advance_field_adapt.F90 @@ -27,8 +27,8 @@ CONTAINS use prec_const IMPLICIT NONE - COMPLEX(dp), DIMENSION ( ikrs:ikre, ikzs:ikze, ntimelevel ) :: f - COMPLEX(dp), DIMENSION ( ikrs:ikre, ikzs:ikze, ntimelevel ) :: f_rhs + COMPLEX(dp), DIMENSION ( ikxs:ikxe, ikys:ikye, ntimelevel ) :: f + COMPLEX(dp), DIMENSION ( ikxs:ikxe, ikys:ikye, ntimelevel ) :: f_rhs REAL(dp) :: error INTEGER :: istage @@ -39,37 +39,37 @@ CONTAINS CASE ('DOPRI5_ADAPT') error = 0._dp - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre - fs = f(ikr,ikz,1) + DO iky=ikys,ikye + DO ikx=ikxs,ikxe + fs = f(ikx,iky,1) DO istage=1,ntimelevel - f(ikr,ikz,1) = f(ikr,ikz,1) + dt*b_E(istage)*f_rhs(ikr,ikz,istage) - fs = fs + dt*b_Es(istage)*f_rhs(ikr,ikz,istage) + f(ikx,iky,1) = f(ikx,iky,1) + dt*b_E(istage)*f_rhs(ikx,iky,istage) + fs = fs + dt*b_Es(istage)*f_rhs(ikx,iky,istage) END DO - IF ( ABS(f(ikr,ikz,1) - fs) .GT. error ) THEN - error = ABS(f(ikr,ikz,1) - fs) + IF ( ABS(f(ikx,iky,1) - fs) .GT. error ) THEN + error = ABS(f(ikx,iky,1) - fs) ENDIF END DO END DO IF (error > TOL) CASE DEFAULT - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre - fs = f(ikr,ikz,1) + DO iky=ikys,ikye + DO ikx=ikxs,ikxe + fs = f(ikx,iky,1) DO istage=1,ntimelevel - f(ikr,ikz,1) = f(ikr,ikz,1) + dt*b_E(istage)*f_rhs(ikr,ikz,istage) + f(ikx,iky,1) = f(ikx,iky,1) + dt*b_E(istage)*f_rhs(ikx,iky,istage) END DO END DO END DO END SELECT CASE DEFAULT - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre - f(ikr,ikz,updatetlevel) = f(ikr,ikz,1); + DO iky=ikys,ikye + DO ikx=ikxs,ikxe + f(ikx,iky,updatetlevel) = f(ikx,iky,1); DO istage=1,updatetlevel-1 - f(ikr,ikz,updatetlevel) = f(ikr,ikz,updatetlevel) + & - dt*A_E(updatetlevel,istage)*f_rhs(ikr,ikz,istage) + f(ikx,iky,updatetlevel) = f(ikx,iky,updatetlevel) + & + dt*A_E(updatetlevel,istage)*f_rhs(ikx,iky,istage) END DO END DO END DO diff --git a/src/array_mod.F90 b/src/array_mod.F90 index 85560f4ae61c996f58ed1e886ed108a53d224670..1cb6d141da980927dcce532bea67e626bbc25672 100644 --- a/src/array_mod.F90 +++ b/src/array_mod.F90 @@ -3,41 +3,50 @@ MODULE array use prec_const implicit none - ! Arrays to store the rhs, for time integration - COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_rhs_e ! (ip,ij,ikr,ikz,updatetlevel) - COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_rhs_i ! (ip,ij,ikr,ikz,updatetlevel) + ! Arrays to store the rhs, for time integration (ip,ij,ikx,iky,iz,updatetlevel) + COMPLEX(dp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: moments_rhs_e + COMPLEX(dp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: moments_rhs_i - ! To load collision matrix + ! To load collision matrix (ip1,ij1,ip2,ij2) REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: Ceepj, CeipjT REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: CeipjF REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: Ciipj, CiepjT REAL(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: CiepjF - ! Collision term - COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: TColl_e, TColl_i - COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: TColl_e_local, TColl_i_local + ! Collision term (ip,ij,ikx,iky,iz) + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: TColl_e, TColl_i + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: TColl_e_local, TColl_i_local ! dnjs coefficient storage (in, ij, is) COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: dnjs - ! Kernel function evaluation + ! lin rhs p,j coefficient storage (ip,ij) + REAL(dp), DIMENSION(:,:), ALLOCATABLE :: xnepj,xnipj + REAL(dp), DIMENSION(:), ALLOCATABLE :: xnepp1j, xnepm1j, xnepp2j, xnepm2j, xnepjp1, xnepjm1 + REAL(dp), DIMENSION(:), ALLOCATABLE :: xnipp1j, xnipm1j, xnipp2j, xnipm2j, xnipjp1, xnipjm1 + REAL(dp), DIMENSION(:,:), ALLOCATABLE :: xphij, xphijp1, xphijm1 + + ! Curvature array + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: Ckxky + + ! Kernel function evaluation (ij,ikx,iky) REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: kernel_e REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: kernel_i - ! Non linear term array (ip,ij,ikr,ikz) - COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: Sepj ! electron - COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: Sipj ! ion + ! Non linear term array (ip,ij,ikx,iky,iz) + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: Sepj ! electron + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: Sipj ! ion - ! Gyrocenter density for electron and ions (meant for 2D output) - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: Ne00 - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: Ni00 + ! Gyrocenter density for electron and ions (ikx,iky,iz) + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: Ne00 + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: Ni00 - ! particle density for electron and ions (meant for 2D output) - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: dens_e - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: dens_i + ! particle density for electron and ions (ikx,iky,iz) + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: dens_e + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: dens_i - ! particle temperature for electron and ions (meant for 2D output) - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: temp_e - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: temp_i + ! particle temperature for electron and ions (ikx,iky,iz) + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: temp_e + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: temp_i END MODULE array diff --git a/src/auxval.F90 b/src/auxval.F90 index ff50aba0e1210a7ebbcfb67a68c2b6eb9bb659ce..f1c3fd6935474a90b282e8297dff3cc3241ab2aa 100644 --- a/src/auxval.F90 +++ b/src/auxval.F90 @@ -7,49 +7,60 @@ subroutine auxval USE model USE fourier, ONLY: init_grid_distr_and_plans, alloc_local_1, alloc_local_2 use prec_const + USE numerics IMPLICIT NONE INTEGER :: irows,irowe, irow, icol, i_ IF (my_id .EQ. 0) WRITE(*,*) '=== Set auxiliary values ===' IF (NON_LIN) THEN - CALL init_grid_distr_and_plans(Nr,Nz) + CALL init_grid_distr_and_plans(Nx,Ny) ELSE CALL init_1Dgrid_distr ENDIF + ! Init the grids + CALL set_pgrid ! parallel kin (MPI distributed) + CALL set_jgrid ! perp kin - CALL set_pgrid - CALL set_jgrid - - CALL set_krgrid ! MPI Distributed dimension - CALL set_kzgrid - CALL set_kpgrid + CALL set_kxgrid ! radial modes (MPI distributed by FFTW) + CALL set_kygrid ! azymuthal modes + CALL set_kpgrid ! perpendicular modes + CALL set_zgrid ! field aligned angle CALL memory ! Allocate memory for global arrays + CALL lin_coeff_and_geometry ! precompute coeff for lin equation and geometry + + CALL evaluate_kernels ! precompute the kernels + + IF ( NON_LIN ) THEN; + CALL build_dnjs_table ! precompute the Laguerre nonlin product coeffs + ENDIF + !! Display parallel settings DO i_ = 0,num_procs-1 CALL mpi_barrier(MPI_COMM_WORLD, ierr) IF (my_id .EQ. i_) THEN IF (my_id .EQ. 0) WRITE(*,*) '' IF (my_id .EQ. 0) WRITE(*,*) '--------- Parallel environement ----------' - IF (my_id .EQ. 0) WRITE(*,'(A9,I3,A10,I3,A10,I3)') 'n_procs= ', num_procs, ', num_procs_p = ', num_procs_p, ', num_procs_kr = ', num_procs_kr + IF (my_id .EQ. 0) WRITE(*,'(A9,I3,A10,I3,A10,I3)') 'n_procs= ', num_procs, ', num_procs_p = ', num_procs_p, ', num_procs_kx = ', num_procs_kx IF (my_id .EQ. 0) WRITE(*,*) '' WRITE(*,'(A9,I3,A10,I3,A10,I3)')& - 'my_id = ', my_id, ', rank_p = ', rank_p, ', rank_kr = ', rank_kr - WRITE(*,'(A22,I3,A10,I3)')& - ' ips_e = ', ips_e, ', ikrs = ', ikrs - WRITE(*,'(A22,I3,A10,I3)')& - ' ipe_e = ', ipe_e, ', ikre = ', ikre - WRITE(*,'(A22,I3,A10,I3)')& - ' ips_i = ', ips_i, ', ikzs = ', ikzs - WRITE(*,'(A22,I3,A10,I3)')& - ' ipe_i = ', ipe_i, ', ikze = ', ikze - - ! WRITE(*,'(A9,I3,A10,I3,A10,I3,A10,I3)')& - ! ' ips_e = ',ips_e,', ipe_e = ',ipe_e,', ips_i = ',ips_i,', ipe_i = ',ipe_i - ! WRITE (*,'(A9,I3,A10,I3,A10,I3,A10,I3,A10,I3)') & - ! ' ikrs = ', ikrs, ', ikre = ', ikre, ', ikzs = ', ikzs, ', ikze = ', ikze + 'my_id = ', my_id, ', rank_p = ', rank_p, ', rank_kx = ', rank_kx + WRITE(*,'(A22,I3,A11,I3)')& + ' ips_e = ', ips_e, ', ipe_e = ', ipe_e + WRITE(*,'(A22,I3,A11,I3)')& + ' ijs_e = ', ijs_e, ', ije_e = ', ije_e + WRITE(*,'(A22,I3,A11,I3)')& + ' ips_i = ', ips_i, ', ipe_i = ', ipe_i + WRITE(*,'(A22,I3,A11,I3)')& + ' ijs_i = ', ijs_i, ', ije_i = ', ije_i + WRITE(*,'(A22,I3,A11,I3)')& + ' ikxs = ', ikxs , ', ikxe = ', ikxe + WRITE(*,'(A22,I3,A11,I3)')& + ' ikys = ', ikys , ', ikye = ', ikye + WRITE(*,'(A22,I3,A11,I3)')& + ' izs = ', izs , ', ize = ', ize IF (my_id .NE. num_procs-1) WRITE (*,*) '' IF (my_id .EQ. num_procs-1) WRITE(*,*) '------------------------------------------' ENDIF diff --git a/src/basic_mod.F90 b/src/basic_mod.F90 index 4516673bf603346bc75e74b0a3e8450a92271602..29f0d4f0cc46573dd8c0fb09eec9905020c43325 100644 --- a/src/basic_mod.F90 +++ b/src/basic_mod.F90 @@ -12,8 +12,8 @@ MODULE basic real(dp) :: time = 0 ! Current simulation time (Init from restart file) INTEGER :: comm0 ! Default communicator with a topology - INTEGER :: comm_p, comm_kr ! Communicators for 1-dim cartesian subgrids of comm0 - INTEGER :: commr_p0 ! Communicators along kr for only rank 0 on p + INTEGER :: comm_p, comm_kx ! Communicators for 1-dim cartesian subgrids of comm0 + INTEGER :: commr_p0 ! Communicators along kx for only rank 0 on p INTEGER :: jobnum = 0 ! Job number INTEGER :: step = 0 ! Calculation step of this run @@ -26,10 +26,10 @@ MODULE basic INTEGER :: my_id ! Rank in COMM_WORLD INTEGER :: num_procs ! number of MPI processes INTEGER :: num_procs_p ! Number of processes in p - INTEGER :: num_procs_kr ! Number of processes in r - INTEGER :: rank_0, rank_p, rank_kr! Ranks in comm0, comm_p, comm_kr + INTEGER :: num_procs_kx ! Number of processes in r + INTEGER :: rank_0, rank_p, rank_kx! Ranks in comm0, comm_p, comm_kx INTEGER :: nbr_L, nbr_R ! Left and right neighbours (along p) - INTEGER :: nbr_T, nbr_B ! Top and bottom neighbours (along kr) + INTEGER :: nbr_T, nbr_B ! Top and bottom neighbours (along kx) INTEGER :: iframe0d ! counting the number of times 0d datasets are outputed (for diagnose) INTEGER :: iframe1d ! counting the number of times 1d datasets are outputed (for diagnose) @@ -52,8 +52,8 @@ MODULE basic real(dp) :: maxruntime = 1e9 ! Maximum simulation CPU time INTERFACE allocate_array - MODULE PROCEDURE allocate_array_dp1,allocate_array_dp2,allocate_array_dp3,allocate_array_dp4 - MODULE PROCEDURE allocate_array_dc1,allocate_array_dc2,allocate_array_dc3,allocate_array_dc4, allocate_array_dc5 + MODULE PROCEDURE allocate_array_dp1,allocate_array_dp2,allocate_array_dp3,allocate_array_dp4, allocate_array_dp5, allocate_array_dp6 + MODULE PROCEDURE allocate_array_dc1,allocate_array_dc2,allocate_array_dc3,allocate_array_dc4, allocate_array_dc5, allocate_array_dc6 MODULE PROCEDURE allocate_array_i1,allocate_array_i2,allocate_array_i3,allocate_array_i4 MODULE PROCEDURE allocate_array_l1,allocate_array_l2,allocate_array_l3,allocate_array_l4 END INTERFACE allocate_array @@ -168,6 +168,13 @@ CONTAINS a=0.0_dp END SUBROUTINE allocate_array_dp5 + SUBROUTINE allocate_array_dp6(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5,is6,ie6) + IMPLICIT NONE + real(dp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a + INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5,is6,ie6 + ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5,is6:ie6)) + a=0.0_dp + END SUBROUTINE allocate_array_dp6 !======================================== SUBROUTINE allocate_array_dc1(a,is1,ie1) @@ -210,6 +217,13 @@ CONTAINS a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc5 + SUBROUTINE allocate_array_dc6(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5,is6,ie6) + IMPLICIT NONE + DOUBLE COMPLEX, DIMENSION(:,:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a + INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5,is6,ie6 + ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5,is6:ie6)) + a=CMPLX(0.0_dp,0.0_dp) + END SUBROUTINE allocate_array_dc6 !======================================== SUBROUTINE allocate_array_i1(a,is1,ie1) diff --git a/src/closure_mod.F90 b/src/closure_mod.F90 index f8846d4a0ee44df96cc02e0d6ff22bc05e580bba..4185a1a1b7080a16ea79d708546cbe624aeb53a8 100644 --- a/src/closure_mod.F90 +++ b/src/closure_mod.F90 @@ -15,84 +15,73 @@ CONTAINS ! Positive Oob indices are approximated with a model SUBROUTINE apply_closure_model IMPLICIT NONE - complex(dp) :: i_kz - real(dp) :: taue_qe_etaB_nu, taui_qi_etaB_nu - real(dp) :: sqpp2pp1_e, sqpp2pp1_i, sqpp1p_e, sqpp1p_i - real(dp) :: p_dp, j_dp - ! Spare some computations - taue_qe_etaB_nu = tau_e*eta_B/q_e/nu - taui_qi_etaB_nu = tau_i*eta_B/q_i/nu - sqpp2pp1_e = SQRT((pmaxe_dp+2)*(pmaxe_dp+1)) - sqpp2pp1_i = SQRT((pmaxi_dp+2)*(pmaxi_dp+1)) - sqpp1p_e = SQRT((pmaxe_dp+1)*(pmaxe_dp)) - sqpp1p_i = SQRT((pmaxi_dp+1)*(pmaxi_dp)) CALL cpu_time(t0_clos) ! zero truncation, An+1=0 for n+1>nmax IF (CLOS .EQ. 0) THEN - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + DO iz = izs,ize + DO ip = ipsg_e,ipeg_e + moments_e(ip,ijsg_e,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ip,ijeg_e,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + DO ij = ijsg_e,ijeg_e + moments_e(ipsg_e+1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipsg_e ,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipeg_e-1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipeg_e ,ij,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + kernel_e(ijsg_e,ikx,iky) = 0._dp + kernel_e(ijeg_e,ikx,iky) = 0._dp - DO ip = ipsg_e,ipeg_e - moments_e(ip,ijsg_e,ikr,ikz,updatetlevel) = 0._dp - moments_e(ip,ijeg_e,ikr,ikz,updatetlevel) = 0._dp + DO ip = ipsg_i,ipeg_i + moments_i(ip,ijsg_i,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ip,ijeg_i,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + DO ij = ijsg_i,ijeg_i + moments_i(ipsg_i+1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipsg_i ,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipeg_i-1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipeg_i ,ij,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + kernel_i(ijsg_i,ikx,iky) = 0._dp + kernel_i(ijeg_i,ikx,iky) = 0._dp ENDDO - DO ij = ijsg_e,ijeg_e - moments_e(ipsg_e+1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipsg_e ,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipeg_e-1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipeg_e ,ij,ikr,ikz,updatetlevel) = 0._dp - ENDDO - kernel_e(ijsg_e,ikr,ikz) = 0._dp - kernel_e(ijeg_e,ikr,ikz) = 0._dp - - DO ip = ipsg_i,ipeg_i - moments_i(ip,ijsg_i,ikr,ikz,updatetlevel) = 0._dp - moments_i(ip,ijeg_i,ikr,ikz,updatetlevel) = 0._dp - ENDDO - DO ij = ijsg_i,ijeg_i - moments_i(ipsg_i+1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipsg_i ,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipeg_i-1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipeg_i ,ij,ikr,ikz,updatetlevel) = 0._dp - ENDDO - kernel_i(ijsg_i,ikr,ikz) = 0._dp - kernel_i(ijeg_i,ikr,ikz) = 0._dp - ENDDO ENDDO ! zero truncation, An+1=0 for n+1>nmax ELSEIF (CLOS .EQ. 1) THEN - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + DO iz = izs,ize + DO ip = ipsg_e,ipeg_e + moments_e(ip,ijsg_e,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ip,ijeg_e,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + DO ij = ijsg_e,ijeg_e + moments_e(ipsg_e+1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipsg_e ,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipeg_e-1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_e(ipeg_e ,ij,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + kernel_e(ijsg_e,ikx,iky) = 0._dp + kernel_e(ijeg_e,ikx,iky) = 0._dp - DO ip = ipsg_e,ipeg_e - moments_e(ip,ijsg_e,ikr,ikz,updatetlevel) = 0._dp - moments_e(ip,ijeg_e,ikr,ikz,updatetlevel) = 0._dp + DO ip = ipsg_i,ipeg_i + moments_i(ip,ijsg_i,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ip,ijeg_i,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + DO ij = ijsg_i,ijeg_i + moments_i(ipsg_i+1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipsg_i ,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipeg_i-1,ij,ikx,iky,iz,updatetlevel) = 0._dp + moments_i(ipeg_i ,ij,ikx,iky,iz,updatetlevel) = 0._dp + ENDDO + kernel_i(ijsg_i,ikx,iky) = 0._dp + kernel_i(ijeg_i,ikx,iky) = 0._dp ENDDO - DO ij = ijsg_e,ijeg_e - moments_e(ipsg_e+1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipsg_e ,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipeg_e-1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_e(ipeg_e ,ij,ikr,ikz,updatetlevel) = 0._dp - ENDDO - kernel_e(ijsg_e,ikr,ikz) = 0._dp - kernel_e(ijeg_e,ikr,ikz) = 0._dp - - DO ip = ipsg_i,ipeg_i - moments_i(ip,ijsg_i,ikr,ikz,updatetlevel) = 0._dp - moments_i(ip,ijeg_i,ikr,ikz,updatetlevel) = 0._dp - ENDDO - DO ij = ijsg_i,ijeg_i - moments_i(ipsg_i+1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipsg_i ,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipeg_i-1,ij,ikr,ikz,updatetlevel) = 0._dp - moments_i(ipeg_i ,ij,ikr,ikz,updatetlevel) = 0._dp - ENDDO - kernel_i(ijsg_i,ikr,ikz) = 0._dp - kernel_i(ijeg_i,ikr,ikz) = 0._dp - ENDDO ENDDO ELSE diff --git a/src/collision_mod.F90 b/src/collision_mod.F90 index 668e32c710cf334542c1a7fc77190c16a069f647..b6dca64698d3a81f74a91b5b42f8487668a93fda 100644 --- a/src/collision_mod.F90 +++ b/src/collision_mod.F90 @@ -1,13 +1,5 @@ module collision ! contains the Hermite-Laguerre collision operators. Solved using COSOlver. -USE fields -USE array -USE basic -USE grid -USE prec_const -USE time_integration -USE model -USE utility IMPLICIT NONE PUBLIC :: compute_TColl @@ -20,34 +12,38 @@ CONTAINS !******************************************************************************! !! Doughtery gyrokinetic collision operator for electrons !******************************************************************************! - SUBROUTINE DoughertyGK_e(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE DoughertyGK_e(ip_,ij_,ikx_,iky_,iz_,TColl_) + USE fields, ONLY: moments_e, phi + USE grid, ONLY: parray_e, jarray_e, kxarray, kyarray, Jmaxe + USE array, ONLY: kernel_e + USE basic + USE model, ONLY: sigmae2_taue_o2, qe_taue, nu_ee + USE time_integration, ONLY : updatetlevel IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_,ij_,ikr_,ikz_ - COMPLEX(dp), INTENT(OUT) :: TColl_ + INTEGER, INTENT(IN) :: ip_,ij_,ikx_,iky_,iz_ + COMPLEX(dp), INTENT(OUT) :: TColl_ COMPLEX(dp) :: n_,upar_,uperp_,Tpar_, Tperp_, T_ COMPLEX(dp) :: nadiab_moment_0j REAL(dp) :: Knp0, Knp1, Knm1 INTEGER :: in_ - REAL(dp) :: n_dp, j_dp, p_dp, be_, be_2, q_e_tau_e + REAL(dp) :: n_dp, j_dp, p_dp, be_, be_2 !** Auxiliary variables ** p_dp = REAL(parray_e(ip_),dp) j_dp = REAL(jarray_e(ij_),dp) - be_2 = (krarray(ikr_)**2 + kzarray(ikz_)**2) * sigmae2_taue_o2 ! this is (be/2)^2 - ! ibe_ = imagu*2._dp*SQRT(be_2) + be_2 = (kxarray(ikx_)**2 + kyarray(iky_)**2) * sigmae2_taue_o2 ! this is (be/2)^2 be_ = 2_dp*SQRT(be_2) ! this is be - q_e_tau_e = q_e/tau_e !** Assembling collison operator ** ! Velocity-space diffusion (similar to Lenhard Bernstein) ! -nuee (p + 2j + b^2/2) Nepj - TColl_ = -(p_dp + 2._dp*j_dp + 2._dp*be_2)*moments_e(ip_,ij_,ikr_,ikz_,updatetlevel) + TColl_ = -(p_dp + 2._dp*j_dp + 2._dp*be_2)*moments_e(ip_,ij_,ikx_,iky_,iz_,updatetlevel) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IF( p_dp .EQ. 0 ) THEN ! Kronecker p0 ! Get adiabatic moment - TColl_ = TColl_ - (p_dp + 2._dp*j_dp + 2._dp*be_2) * q_e_tau_e * Kernel_e(ij_,ikr_,ikz_)*phi(ikr_,ikz_) + TColl_ = TColl_ - (p_dp + 2._dp*j_dp + 2._dp*be_2) * qe_taue * Kernel_e(ij_,ikx_,iky_)*phi(ikx_,iky_,iz_) !** build required fluid moments ** n_ = 0._dp upar_ = 0._dp; uperp_ = 0._dp @@ -55,26 +51,26 @@ CONTAINS DO in_ = 1,jmaxe+1 n_dp = REAL(in_-1,dp) ! Store the kernels for sparing readings - Knp0 = Kernel_e(in_,ikr_,ikz_) - Knp1 = Kernel_e(in_+1,ikr_,ikz_) - Knm1 = Kernel_e(in_-1,ikr_,ikz_) + Knp0 = Kernel_e(in_,ikx_,iky_) + Knp1 = Kernel_e(in_+1,ikx_,iky_) + Knm1 = Kernel_e(in_-1,ikx_,iky_) ! Nonadiabatic moments (only different from moments when p=0) - nadiab_moment_0j = moments_e(1,in_ ,ikr_,ikz_,updatetlevel) + q_e_tau_e * Knp0 *phi(ikr_,ikz_) + nadiab_moment_0j = moments_e(1,in_ ,ikx_,iky_,iz_,updatetlevel) + qe_taue*Knp0*phi(ikx_,iky_,iz_) ! Density n_ = n_ + Knp0 * nadiab_moment_0j ! Perpendicular velocity uperp_ = uperp_ + be_*0.5_dp*(Knp0 - Knm1) * nadiab_moment_0j ! Parallel temperature - Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_e(3,in_,ikr_,ikz_,updatetlevel) + nadiab_moment_0j) + Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_e(3,in_,ikx_,iky_,iz_,updatetlevel) + nadiab_moment_0j) ! Perpendicular temperature Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1._dp)*Knp1 - n_dp*Knm1)*nadiab_moment_0j ENDDO T_ = (Tpar_ + 2._dp*Tperp_)/3._dp - n_ ! Add energy restoring term - TColl_ = TColl_ + T_* 4._dp * j_dp * Kernel_e(ij_,ikr_,ikz_) - TColl_ = TColl_ - T_* 2._dp * (j_dp + 1._dp) * Kernel_e(ij_+1,ikr_,ikz_) - TColl_ = TColl_ - T_* 2._dp * j_dp * Kernel_e(ij_-1,ikr_,ikz_) - TColl_ = TColl_ + uperp_*be_* (Kernel_e(ij_,ikr_,ikz_) - Kernel_e(ij_-1,ikr_,ikz_)) + TColl_ = TColl_ + T_* 4._dp * j_dp * Kernel_e(ij_ ,ikx_,iky_) + TColl_ = TColl_ - T_* 2._dp * (j_dp + 1._dp) * Kernel_e(ij_+1,ikx_,iky_) + TColl_ = TColl_ - T_* 2._dp * j_dp * Kernel_e(ij_-1,ikx_,iky_) + TColl_ = TColl_ + uperp_*be_* (Kernel_e(ij_,ikx_,iky_) - Kernel_e(ij_-1,ikx_,iky_)) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -83,9 +79,9 @@ CONTAINS upar_ = 0._dp DO in_ = 1,jmaxe+1 ! Parallel velocity - upar_ = upar_ + Kernel_e(in_,ikr_,ikz_) * moments_e(2,in_,ikr_,ikz_,updatetlevel) + upar_ = upar_ + Kernel_e(in_,ikx_,iky_) * moments_e(2,in_,ikx_,iky_,iz_,updatetlevel) ENDDO - TColl_ = TColl_ + upar_*Kernel_e(ij_,ikr_,ikz_) + TColl_ = TColl_ + upar_*Kernel_e(ij_,ikx_,iky_) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -97,20 +93,20 @@ CONTAINS DO in_ = 1,jmaxe+1 n_dp = REAL(in_-1,dp) ! Store the kernels for sparing readings - Knp0 = Kernel_e(in_,ikr_,ikz_) - Knp1 = Kernel_e(in_+1,ikr_,ikz_) - Knm1 = Kernel_e(in_-1,ikr_,ikz_) + Knp0 = Kernel_e(in_ ,ikx_,iky_) + Knp1 = Kernel_e(in_+1,ikx_,iky_) + Knm1 = Kernel_e(in_-1,ikx_,iky_) ! Nonadiabatic moments (only different from moments when p=0) - nadiab_moment_0j = moments_e(1,in_ ,ikr_,ikz_,updatetlevel) + q_e_tau_e*Knp0*phi(ikr_,ikz_) + nadiab_moment_0j = moments_e(1,in_,ikx_,iky_,iz_,updatetlevel) + qe_taue*Knp0*phi(ikx_,iky_,iz_) ! Density n_ = n_ + Knp0 * nadiab_moment_0j ! Parallel temperature - Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_e(3,in_,ikr_,ikz_,updatetlevel) + nadiab_moment_0j) + Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_e(3,in_,ikx_,iky_,iz_,updatetlevel) + nadiab_moment_0j) ! Perpendicular temperature - Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1) * Knp1 - n_dp * Knm1)*nadiab_moment_0j + Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1._dp)*Knp1 - n_dp*Knm1)*nadiab_moment_0j ENDDO T_ = (Tpar_ + 2._dp*Tperp_)/3._dp - n_ - TColl_ = TColl_ + T_*SQRT2*Kernel_e(ij_,ikr_,ikz_) + TColl_ = TColl_ + T_*SQRT2*Kernel_e(ij_,ikx_,iky_) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDIF @@ -121,33 +117,39 @@ CONTAINS !******************************************************************************! !! Doughtery gyrokinetic collision operator for ions !******************************************************************************! - SUBROUTINE DoughertyGK_i(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE DoughertyGK_i(ip_,ij_,ikx_,iky_,iz_,TColl_) + USE fields, ONLY: moments_i, phi + USE grid, ONLY: parray_i, jarray_i, kxarray, kyarray, Jmaxi + USE array, ONLY: kernel_i + USE basic + USE model, ONLY: sigmai2_taui_o2, qi_taui, nu_i + USE time_integration, ONLY : updatetlevel IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_,ij_,ikr_,ikz_ - COMPLEX(dp), INTENT(OUT) :: TColl_ + INTEGER, INTENT(IN) :: ip_,ij_,ikx_,iky_,iz_ + COMPLEX(dp), INTENT(OUT) :: TColl_ COMPLEX(dp) :: n_,upar_,uperp_,Tpar_, Tperp_, T_ + COMPLEX(dp) :: bi_, bi_2 COMPLEX(dp) :: nadiab_moment_0j REAL(dp) :: Knp0, Knp1, Knm1 INTEGER :: in_ - REAL(dp) :: n_dp, j_dp, p_dp, bi_, bi_2, q_i_tau_i + REAL(dp) :: n_dp, j_dp, p_dp !** Auxiliary variables ** p_dp = REAL(parray_i(ip_),dp) j_dp = REAL(jarray_i(ij_),dp) - bi_2 = (krarray(ikr_)**2 + kzarray(ikz_)**2) * sigmai2_taui_o2 ! this is (bi/2)^2 + bi_2 = (kxarray(ikx_)**2 + kyarray(iky_)**2) * sigmai2_taui_o2 ! this is (bi/2)^2 bi_ = 2_dp*SQRT(bi_2) ! this is be - q_i_tau_i = q_i/tau_i !** Assembling collison operator ** ! Velocity-space diffusion (similar to Lenhard Bernstein) ! -nui (p + 2j + b^2/2) Nipj - TColl_ = -(p_dp + 2._dp*j_dp + 2._dp*bi_2)*moments_i(ip_,ij_,ikr_,ikz_,updatetlevel) + TColl_ = -(p_dp + 2._dp*j_dp + 2._dp*bi_2)*moments_i(ip_,ij_,ikx_,iky_,iz_,updatetlevel) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 0 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IF( p_dp .EQ. 0 ) THEN ! Kronecker p0 ! Get adiabatic moment - TColl_ = TColl_ - (p_dp + 2._dp*j_dp + 2._dp*bi_2) * q_i_tau_i * Kernel_i(ij_,ikr_,ikz_)*phi(ikr_,ikz_) + TColl_ = TColl_ - (p_dp + 2._dp*j_dp + 2._dp*bi_2) * qi_taui * Kernel_i(ij_,ikx_,iky_)*phi(ikx_,iky_,iz_) !** build required fluid moments ** n_ = 0._dp upar_ = 0._dp; uperp_ = 0._dp @@ -155,46 +157,41 @@ CONTAINS DO in_ = 1,jmaxi+1 n_dp = REAL(in_-1,dp) ! Store the kernels for sparing readings - Knp0 = Kernel_i(in_,ikr_,ikz_) - Knp1 = Kernel_i(in_+1,ikr_,ikz_) - Knm1 = Kernel_i(in_-1,ikr_,ikz_) + Knp0 = Kernel_i(in_,ikx_,iky_) + Knp1 = Kernel_i(in_+1,ikx_,iky_) + Knm1 = Kernel_i(in_-1,ikx_,iky_) ! Nonadiabatic moments (only different from moments when p=0) - nadiab_moment_0j = moments_i(1,in_ ,ikr_,ikz_,updatetlevel) + q_i_tau_i * Knp0 *phi(ikr_,ikz_) + nadiab_moment_0j = moments_i(1,in_ ,ikx_,iky_,iz_,updatetlevel) + qi_taui*Knp0*phi(ikx_,iky_,iz_) ! Density n_ = n_ + Knp0 * nadiab_moment_0j ! Perpendicular velocity - ! uperp_ = uperp_ + ibi_*0.5_dp*Kernel_i(in_,ikr_,ikz_) * (nadiab_moment_0j - nadiab_moment_0jp1) - ! uperp_ = uperp_ + b_i*0.5_dp*Kernel_i(in_,ikr_,ikz_) * (nadiab_moment_0j - nadiab_moment_0jp1) uperp_ = uperp_ + bi_*0.5_dp*(Knp0 - Knm1) * nadiab_moment_0j ! Parallel temperature - Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_i(3,in_,ikr_,ikz_,updatetlevel) + nadiab_moment_0j) + Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_i(3,in_,ikx_,iky_,iz_,updatetlevel) + nadiab_moment_0j) ! Perpendicular temperature - ! Tperp_ = Tperp_ + Kernel_i(in_,ikr_,ikz_) * ((2._dp*n_dp+1._dp)* nadiab_moment_0j & - ! - n_dp * nadiab_moment_0jm1 & - ! - (n_dp+1)* nadiab_moment_0jp1) - Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1) * Knp1 - n_dp * Knm1)*nadiab_moment_0j + Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1._dp)*Knp1 - n_dp*Knm1)*nadiab_moment_0j ENDDO T_ = (Tpar_ + 2._dp*Tperp_)/3._dp - n_ ! Add energy restoring term - TColl_ = TColl_ + T_* 4._dp * j_dp * Kernel_i(ij_,ikr_,ikz_) - TColl_ = TColl_ - T_* 2._dp * (j_dp + 1._dp) * Kernel_i(ij_+1,ikr_,ikz_) - TColl_ = TColl_ - T_* 2._dp * j_dp * Kernel_i(ij_-1,ikr_,ikz_) - TColl_ = TColl_ + uperp_*bi_* (Kernel_i(ij_,ikr_,ikz_) - Kernel_i(ij_-1,ikr_,ikz_)) + TColl_ = TColl_ + T_* 4._dp * j_dp * Kernel_i(ij_ ,ikx_,iky_) + TColl_ = TColl_ - T_* 2._dp * (j_dp + 1._dp) * Kernel_i(ij_+1,ikx_,iky_) + TColl_ = TColl_ - T_* 2._dp * j_dp * Kernel_i(ij_-1,ikx_,iky_) + TColl_ = TColl_ + uperp_*bi_* (Kernel_i(ij_,ikx_,iky_) - Kernel_i(ij_-1,ikx_,iky_)) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - ELSEIF( p_dp .eq. 1 ) THEN ! kronecker p1 + ELSEIF( p_dp .eq. 1 ) THEN ! kxonecker p1 !** build required fluid moments ** upar_ = 0._dp DO in_ = 1,jmaxi+1 ! Parallel velocity - upar_ = upar_ + Kernel_i(in_,ikr_,ikz_) * moments_i(2,in_,ikr_,ikz_,updatetlevel) + upar_ = upar_ + Kernel_i(in_,ikx_,iky_) * moments_i(2,in_,ikx_,iky_,iz_,updatetlevel) ENDDO - TColl_ = TColl_ + upar_*Kernel_i(ij_,ikr_,ikz_) + TColl_ = TColl_ + upar_*Kernel_i(ij_,ikx_,iky_) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Non zero term for p = 2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - ELSEIF( p_dp .eq. 2 ) THEN ! kronecker p2 + ELSEIF( p_dp .eq. 2 ) THEN ! kxonecker p2 !** build required fluid moments ** n_ = 0._dp upar_ = 0._dp; uperp_ = 0._dp @@ -202,20 +199,20 @@ CONTAINS DO in_ = 1,jmaxi+1 n_dp = REAL(in_-1,dp) ! Store the kernels for sparing readings - Knp0 = Kernel_i(in_,ikr_,ikz_) - Knp1 = Kernel_i(in_+1,ikr_,ikz_) - Knm1 = Kernel_i(in_-1,ikr_,ikz_) + Knp0 = Kernel_i(in_ ,ikx_,iky_) + Knp1 = Kernel_i(in_+1,ikx_,iky_) + Knm1 = Kernel_i(in_-1,ikx_,iky_) ! Nonadiabatic moments (only different from moments when p=0) - nadiab_moment_0j = moments_i(1,in_ ,ikr_,ikz_,updatetlevel) + q_i_tau_i * Knp0*phi(ikr_,ikz_) + nadiab_moment_0j = moments_i(1,in_,ikx_,iky_,iz_,updatetlevel) + qi_taui*Knp0*phi(ikx_,iky_,iz_) ! Density n_ = n_ + Knp0 * nadiab_moment_0j ! Parallel temperature - Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_i(3,in_,ikr_,ikz_,updatetlevel) + nadiab_moment_0j) + Tpar_ = Tpar_ + Knp0 * (SQRT2*moments_i(3,in_,ikx_,iky_,iz_,updatetlevel) + nadiab_moment_0j) ! Perpendicular temperature - Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1) * Knp1 - n_dp * Knm1)*nadiab_moment_0j + Tperp_ = Tperp_ + ((2._dp*n_dp+1._dp)*Knp0 - (n_dp+1._dp)*Knp1 - n_dp*Knm1)*nadiab_moment_0j ENDDO T_ = (Tpar_ + 2._dp*Tperp_)/3._dp - n_ - TColl_ = TColl_ + T_*SQRT2*Kernel_i(ij_,ikr_,ikz_) + TColl_ = TColl_ + T_*SQRT2*Kernel_i(ij_,ikx_,iky_) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ENDIF @@ -225,66 +222,76 @@ CONTAINS END SUBROUTINE DoughertyGK_i !******************************************************************************! - !! compute the collision terms in a (Np x Nj x Nkr x Nkz) matrix all at once + !! compute the collision terms in a (Np x Nj x Nkx x Nky) matrix all at once !******************************************************************************! SUBROUTINE compute_TColl + USE fields + USE grid + USE array + USE basic + USE prec_const + USE time_integration + USE model + USE utility IMPLICIT NONE COMPLEX(dp), DIMENSION(1:pmaxe+1) :: local_sum_e, buffer_e, total_sum_e COMPLEX(dp), DIMENSION(ips_e:ipe_e) :: TColl_distr_e COMPLEX(dp), DIMENSION(1:pmaxi+1) :: local_sum_i, buffer_i, total_sum_i COMPLEX(dp), DIMENSION(ips_i:ipe_i) :: TColl_distr_i COMPLEX(dp) :: TColl - INTEGER :: ikrs_C, ikre_C, ikzs_C, ikze_C + INTEGER :: ikxs_C, ikxe_C, ikys_C, ikye_C ! Execution time start CALL cpu_time(t0_coll) IF (ABS(CO) .GE. 2) THEN !compute only if COSOlver matrices are used - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - ! Electrons - DO ij = 1,Jmaxe+1 - ! Loop over all p to compute sub collision term - DO ip = 1,Pmaxe+1 - CALL apply_COSOlver_mat_e(ip,ij,ikr,ikz,TColl) - local_sum_e(ip) = TColl + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + DO iz = izs,ize + ! Electrons + DO ij = 1,Jmaxe+1 + ! Loop over all p to compute sub collision term + DO ip = 1,Pmaxe+1 + CALL apply_COSOlver_mat_e(ip,ij,ikx,iky,iz,TColl) + local_sum_e(ip) = TColl + ENDDO + IF (num_procs_p .GT. 1) THEN + ! Sum up all the sub collision terms on root 0 + CALL MPI_REDUCE(local_sum_e, buffer_e, pmaxe+1, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm_p, ierr) + ! distribute the sum over the process among p + CALL MPI_SCATTERV(buffer_e, counts_np_e, displs_np_e, MPI_DOUBLE_COMPLEX,& + TColl_distr_e, local_np_e, MPI_DOUBLE_COMPLEX,& + 0, comm_p, ierr) + ELSE + TColl_distr_e = local_sum_e + ENDIF + ! Write in output variable + DO ip = ips_e,ipe_e + TColl_e(ip,ij,ikx,iky,iz) = TColl_distr_e(ip) + ENDDO ENDDO - IF (num_procs_p .GT. 1) THEN - ! Sum up all the sub collision terms on root 0 - CALL MPI_REDUCE(local_sum_e, buffer_e, pmaxe+1, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm_p, ierr) - ! distribute the sum over the process among p - CALL MPI_SCATTERV(buffer_e, counts_np_e, displs_np_e, MPI_DOUBLE_COMPLEX,& - TColl_distr_e, local_np_e, MPI_DOUBLE_COMPLEX,& - 0, comm_p, ierr) - ELSE - TColl_distr_e = local_sum_e - ENDIF - ! Write in output variable - DO ip = ips_e,ipe_e - TColl_e(ip,ij,ikr,ikz) = TColl_distr_e(ip) - ENDDO - ENDDO - ! Ions - DO ij = 1,Jmaxi+1 - DO ip = 1,Pmaxi+1 - CALL apply_COSOlver_mat_i(ip,ij,ikr,ikz,TColl) - local_sum_i(ip) = TColl - ENDDO - IF (num_procs_p .GT. 1) THEN - ! Reduce the local_sums to root = 0 - CALL MPI_REDUCE(local_sum_i, buffer_i, pmaxi+1, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm_p, ierr) - ! buffer contains the entire collision term along p, we scatter it between - ! the other processes (use of scatterv since Pmax/Np is not an integer) - CALL MPI_SCATTERV(buffer_i, counts_np_i, displs_np_i, MPI_DOUBLE_COMPLEX,& - TColl_distr_i, local_np_i, MPI_DOUBLE_COMPLEX, & - 0, comm_p, ierr) - ELSE - TColl_distr_i = local_sum_i - ENDIF - ! Write in output variable - DO ip = ips_i,ipe_i - TColl_i(ip,ij,ikr,ikz) = TColl_distr_i(ip) + ! Ions + DO ij = 1,Jmaxi+1 + DO ip = 1,Pmaxi+1 + CALL apply_COSOlver_mat_i(ip,ij,ikx,iky,iz,TColl) + local_sum_i(ip) = TColl + ENDDO + IF (num_procs_p .GT. 1) THEN + ! Reduce the local_sums to root = 0 + CALL MPI_REDUCE(local_sum_i, buffer_i, pmaxi+1, MPI_DOUBLE_COMPLEX, MPI_SUM, 0, comm_p, ierr) + ! buffer contains the entire collision term along p, we scatter it between + ! the other processes (use of scatterv since Pmax/Np is not an integer) + CALL MPI_SCATTERV(buffer_i, counts_np_i, displs_np_i, MPI_DOUBLE_COMPLEX,& + TColl_distr_i, local_np_i, MPI_DOUBLE_COMPLEX, & + 0, comm_p, ierr) + ELSE + TColl_distr_i = local_sum_i + ENDIF + ! Write in output variable + DO ip = ips_i,ipe_i + TColl_i(ip,ij,ikx,iky,iz) = TColl_distr_i(ip) + ENDDO ENDDO ENDDO ENDDO @@ -299,19 +306,26 @@ CONTAINS !******************************************************************************! !!!!!!! Compute ion collision term !******************************************************************************! - SUBROUTINE apply_COSOlver_mat_e(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE apply_COSOlver_mat_e(ip_,ij_,ikx_,iky_,iz_,TColl_) + USE fields, ONLY: moments_e, moments_i + USE grid + USE array + USE basic + USE time_integration, ONLY: updatetlevel + USE utility + USE model, ONLY: CO, nu_e, nu_ee IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_, ij_ ,ikr_, ikz_ + INTEGER, INTENT(IN) :: ip_, ij_ ,ikx_, iky_, iz_ COMPLEX(dp), INTENT(OUT) :: TColl_ - INTEGER :: ip2,ij2, p_int,j_int, p2_int,j2_int, ikr_C, ikz_C + INTEGER :: ip2,ij2, p_int,j_int, p2_int,j2_int, ikx_C, iky_C p_int = ip_-1; j_int = ij_-1 IF (CO .GT. 0) THEN ! GK operator (k-dependant) - ikr_C = ikr_; ikz_C = ikz_ + ikx_C = ikx_; iky_C = iky_ ELSEIF (CO .LT. 0) THEN ! DK operator (only one mat for every k) - ikr_C = 1; ikz_C = 1 + ikx_C = 1; iky_C = 1 ENDIF TColl_ = 0._dp ! Initialization of the local sum @@ -321,9 +335,9 @@ CONTAINS p2_int = parray_e(ip2) jloopee: DO ij2 = ijs_e,ije_e j2_int = jarray_e(ij2) - TColl_ = TColl_ + moments_e(ip2,ij2,ikr_,ikz_,updatetlevel) & - *( nu_e * CeipjT(bare(p_int,j_int), bare(p2_int,j2_int),ikr_C, ikz_C) & - +nu_ee * Ceepj (bare(p_int,j_int), bare(p2_int,j2_int),ikr_C, ikz_C)) + TColl_ = TColl_ + moments_e(ip2,ij2,ikx_,iky_,iz_,updatetlevel) & + *( nu_e * CeipjT(bare(p_int,j_int), bare(p2_int,j2_int),ikx_C, iky_C) & + +nu_ee * Ceepj (bare(p_int,j_int), bare(p2_int,j2_int),ikx_C, iky_C)) ENDDO jloopee ENDDO ploopee @@ -332,8 +346,8 @@ CONTAINS p2_int = parray_i(ip2) jloopei: DO ij2 = ijs_i,ije_i j2_int = jarray_i(ij2) - TColl_ = TColl_ + moments_i(ip2,ij2,ikr_,ikz_,updatetlevel) & - *(nu_e * CeipjF(bare(p_int,j_int), bari(p2_int,j2_int),ikr_C, ikz_C)) + TColl_ = TColl_ + moments_i(ip2,ij2,ikx_,iky_,iz_,updatetlevel) & + *(nu_e * CeipjF(bare(p_int,j_int), bari(p2_int,j2_int),ikx_C, iky_C)) END DO jloopei ENDDO ploopei @@ -342,19 +356,25 @@ CONTAINS !******************************************************************************! !!!!!!! Compute ion collision term !******************************************************************************! - SUBROUTINE apply_COSOlver_mat_i(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE apply_COSOlver_mat_i(ip_,ij_,ikx_,iky_,iz_,TColl_) + USE fields, ONLY : moments_e, moments_i + USE grid + USE array + USE basic + USE time_integration, ONLY : updatetlevel + USE utility + USE model, ONLY: CO, nu_i, nu_ie IMPLICIT NONE - - INTEGER, INTENT(IN) :: ip_, ij_ ,ikr_, ikz_ + INTEGER, INTENT(IN) :: ip_, ij_ ,ikx_, iky_, iz_ COMPLEX(dp), INTENT(OUT) :: TColl_ - INTEGER :: ip2,ij2, p_int,j_int, p2_int,j2_int, ikr_C, ikz_C + INTEGER :: ip2,ij2, p_int,j_int, p2_int,j2_int, ikx_C, iky_C p_int = ip_-1; j_int = ij_-1 IF (CO .GT. 0) THEN ! GK operator (k-dependant) - ikr_C = ikr_; ikz_C = ikz_ + ikx_C = ikx_; iky_C = iky_ ELSEIF (CO .LT. 0) THEN ! DK operator (only one mat for every k) - ikr_C = 1; ikz_C = 1 + ikx_C = 1; iky_C = 1 ENDIF TColl_ = 0._dp ! Initialization @@ -363,9 +383,9 @@ CONTAINS p2_int = parray_i(ip2) jloopii: DO ij2 = ijs_i,ije_i j2_int = jarray_i(ij2) - TColl_ = TColl_ + moments_i(ip2,ij2,ikr_,ikz_,updatetlevel) & - *( nu_ie * CiepjT(bari(p_int,j_int), bari(p2_int,j2_int), ikr_C, ikz_C) & - +nu_i * Ciipj (bari(p_int,j_int), bari(p2_int,j2_int), ikr_C, ikz_C)) + TColl_ = TColl_ + moments_i(ip2,ij2,ikx_,iky_,iz_,updatetlevel) & + *( nu_ie * CiepjT(bari(p_int,j_int), bari(p2_int,j2_int), ikx_C, iky_C) & + +nu_i * Ciipj (bari(p_int,j_int), bari(p2_int,j2_int), ikx_C, iky_C)) ENDDO jloopii ENDDO ploopii @@ -373,8 +393,8 @@ CONTAINS p2_int = parray_e(ip2) jloopie: DO ij2 = ijs_e,ije_e j2_int = jarray_e(ij2) - TColl_ = TColl_ + moments_e(ip2,ij2,ikr_,ikz_,updatetlevel) & - *(nu_ie * CiepjF(bari(p_int,j_int), bare(p2_int,j2_int), ikr_C, ikz_C)) + TColl_ = TColl_ + moments_e(ip2,ij2,ikx_,iky_,iz_,updatetlevel) & + *(nu_ie * CiepjF(bari(p_int,j_int), bare(p2_int,j2_int), ikx_C, iky_C)) ENDDO jloopie ENDDO ploopie @@ -386,6 +406,12 @@ CONTAINS SUBROUTINE load_COSOlver_mat ! Load a sub matrix from iCa files (works for pmaxa,jmaxa<=P_full,J_full) use futils use initial_par + USE grid + USE array, ONLY: Ceepj, Ciipj, CeipjF, CeipjT, CiepjF, CiepjT + USE basic + USE time_integration, ONLY : updatetlevel + USE utility + USE model, ONLY: CO, NON_LIN IMPLICIT NONE ! Indices for row and columns of the COSOlver matrix (4D compressed 2D matrices) INTEGER :: irow_sub, irow_full, icol_sub, icol_full @@ -591,11 +617,11 @@ CONTAINS ENDDO CALL closef(fid) - IF (CO .GT. 0) THEN ! Interpolation of the kperp matrix values on kr kz grid - IF (my_id .EQ. 0 ) WRITE(*,*) '...Interpolation from matrices kperp to simulation kr,kz...' - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - kperp_sim = SQRT(krarray(ikr)**2+kzarray(ikz)**2) ! current simulation kperp + IF (CO .GT. 0) THEN ! Interpolation of the kperp matrix values on kx ky grid + IF (my_id .EQ. 0 ) WRITE(*,*) '...Interpolation from matrices kperp to simulation kx,ky...' + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + kperp_sim = SQRT(kxarray(ikx)**2+kyarray(iky)**2) ! current simulation kperp ! Find the interval in kp grid mat where kperp_sim is contained ! Loop over the whole kp mat grid to find the smallest kperp that is @@ -614,12 +640,12 @@ CONTAINS zerotoone = (kperp_sim - kp_grid_mat(ikp_prev))/(kp_grid_mat(ikp_next) - kp_grid_mat(ikp_prev)) ! Linear interpolation between previous and next kperp matrix values - Ceepj (:,:,ikr,ikz) = (Ceepj__kp(:,:,ikp_next) - Ceepj__kp(:,:,ikp_prev))*zerotoone + Ceepj__kp(:,:,ikp_prev) - CeipjT(:,:,ikr,ikz) = (CeipjT_kp(:,:,ikp_next) - CeipjT_kp(:,:,ikp_prev))*zerotoone + CeipjT_kp(:,:,ikp_prev) - CeipjF(:,:,ikr,ikz) = (CeipjF_kp(:,:,ikp_next) - CeipjF_kp(:,:,ikp_prev))*zerotoone + CeipjF_kp(:,:,ikp_prev) - Ciipj (:,:,ikr,ikz) = (Ciipj__kp(:,:,ikp_next) - Ciipj__kp(:,:,ikp_prev))*zerotoone + Ciipj__kp(:,:,ikp_prev) - CiepjT(:,:,ikr,ikz) = (CiepjT_kp(:,:,ikp_next) - CiepjT_kp(:,:,ikp_prev))*zerotoone + CiepjT_kp(:,:,ikp_prev) - CiepjF(:,:,ikr,ikz) = (CiepjF_kp(:,:,ikp_next) - CiepjF_kp(:,:,ikp_prev))*zerotoone + CiepjF_kp(:,:,ikp_prev) + Ceepj (:,:,ikx,iky) = (Ceepj__kp(:,:,ikp_next) - Ceepj__kp(:,:,ikp_prev))*zerotoone + Ceepj__kp(:,:,ikp_prev) + CeipjT(:,:,ikx,iky) = (CeipjT_kp(:,:,ikp_next) - CeipjT_kp(:,:,ikp_prev))*zerotoone + CeipjT_kp(:,:,ikp_prev) + CeipjF(:,:,ikx,iky) = (CeipjF_kp(:,:,ikp_next) - CeipjF_kp(:,:,ikp_prev))*zerotoone + CeipjF_kp(:,:,ikp_prev) + Ciipj (:,:,ikx,iky) = (Ciipj__kp(:,:,ikp_next) - Ciipj__kp(:,:,ikp_prev))*zerotoone + Ciipj__kp(:,:,ikp_prev) + CiepjT(:,:,ikx,iky) = (CiepjT_kp(:,:,ikp_next) - CiepjT_kp(:,:,ikp_prev))*zerotoone + CiepjT_kp(:,:,ikp_prev) + CiepjF(:,:,ikx,iky) = (CiepjF_kp(:,:,ikp_next) - CiepjF_kp(:,:,ikp_prev))*zerotoone + CiepjF_kp(:,:,ikp_prev) ENDDO ENDDO ELSE ! DK -> No kperp dep, copy simply to final collision matrices diff --git a/src/compute_Sapj.F90 b/src/compute_Sapj.F90 index 4ef4f87d92ce026335a723accff7703344c000ee..e66080a71e5cc09d09bb39307d3a55f680718839 100644 --- a/src/compute_Sapj.F90 +++ b/src/compute_Sapj.F90 @@ -1,7 +1,7 @@ SUBROUTINE compute_Sapj ! This routine is meant to compute the non linear term for each specie and degree !! In real space Sapj ~ b*(grad(phi) x grad(g)) which in moments in fourier becomes - !! Sapj = Sum_n (ikr Kn phi)#(ikz Sum_s d_njs Naps) - (ikz Kn phi)#(ikr Sum_s d_njs Naps) + !! Sapj = Sum_n (ikx Kn phi)#(iky Sum_s d_njs Naps) - (iky Kn phi)#(ikx Sum_s d_njs Naps) !! where # denotes the convolution. USE array, ONLY : dnjs, Sepj, Sipj, kernel_i, kernel_e USE basic @@ -14,18 +14,22 @@ SUBROUTINE compute_Sapj IMPLICIT NONE INCLUDE 'fftw3-mpi.f03' - COMPLEX(dp), DIMENSION(ikrs:ikre,ikzs:ikze) :: Fr_cmpx, Gz_cmpx - COMPLEX(dp), DIMENSION(ikrs:ikre,ikzs:ikze) :: Fz_cmpx, Gr_cmpx, F_conv_G - REAL(dp), DIMENSION(irs:ire,izs:ize) :: fr_real, gz_real - REAL(dp), DIMENSION(irs:ire,izs:ize) :: fz_real, gr_real, f_times_g + COMPLEX(dp), DIMENSION(ikxs:ikxe,ikys:ikye) :: Fx_cmpx, Gy_cmpx + COMPLEX(dp), DIMENSION(ikxs:ikxe,ikys:ikye) :: Fy_cmpx, Gx_cmpx, F_conv_G + REAL(dp), DIMENSION(ixs:ixe,iys:iye) :: fr_real, gz_real + REAL(dp), DIMENSION(ixs:ixe,iys:iye) :: fz_real, gr_real, f_times_g INTEGER :: in, is INTEGER :: nmax, smax ! Upper bound of the sums - REAL(dp):: kr, kz, kerneln + REAL(dp):: kx, ky, kerneln LOGICAL :: COMPUTE_ONLY_EVEN_P = .true. ! Execution time start CALL cpu_time(t0_Sapj) +! If we have a parallel dynamic, odd p are coupled with even ones +IF(Nz .GT. 1) COMPUTE_ONLY_EVEN_P = .false. + +zloop: DO iz = izs,ize !!!!!!!!!!!!!!!!!!!! ELECTRON non linear term computation (Sepj)!!!!!!!!!! ploope: DO ip = ips_e,ipe_e ! Loop over Hermite moments @@ -46,56 +50,56 @@ SUBROUTINE compute_Sapj nloope: DO in = 1,nmax+1 ! Loop over laguerre for the sum - krloope: DO ikr = ikrs,ikre ! Loop over kr - kzloope: DO ikz = ikzs,ikze ! Loop over kz - kr = krarray(ikr) - kz = kzarray(ikz) - kerneln = kernel_e(in, ikr, ikz) + kxloope: DO ikx = ikxs,ikxe ! Loop over kx + kyloope: DO iky = ikys,ikye ! Loop over ky + kx = kxarray(ikx) + ky = kyarray(iky) + kerneln = kernel_e(in, ikx, iky) ! First convolution terms - Fr_cmpx(ikr,ikz) = imagu*kr* phi(ikr,ikz) * kerneln - Fz_cmpx(ikr,ikz) = imagu*kz* phi(ikr,ikz) * kerneln + Fx_cmpx(ikx,iky) = imagu*kx* phi(ikx,iky,iz) * kerneln + Fy_cmpx(ikx,iky) = imagu*ky* phi(ikx,iky,iz) * kerneln ! Second convolution terms - Gz_cmpx(ikr,ikz) = 0._dp ! initialization of the sum - Gr_cmpx(ikr,ikz) = 0._dp ! initialization of the sum + Gy_cmpx(ikx,iky) = 0._dp ! initialization of the sum + Gx_cmpx(ikx,iky) = 0._dp ! initialization of the sum smax = MIN( (in-1)+(ij-1), jmaxe ); DO is = 1, smax+1 ! sum truncation on number of moments - Gz_cmpx(ikr,ikz) = Gz_cmpx(ikr,ikz) + & - dnjs(in,ij,is) * moments_e(ip,is,ikr,ikz,updatetlevel) - Gr_cmpx(ikr,ikz) = Gr_cmpx(ikr,ikz) + & - dnjs(in,ij,is) * moments_e(ip,is,ikr,ikz,updatetlevel) + Gy_cmpx(ikx,iky) = Gy_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_e(ip,is,ikx,iky,iz,updatetlevel) + Gx_cmpx(ikx,iky) = Gx_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_e(ip,is,ikx,iky,iz,updatetlevel) ENDDO - Gz_cmpx(ikr,ikz) = imagu*kz*Gz_cmpx(ikr,ikz) - Gr_cmpx(ikr,ikz) = imagu*kr*Gr_cmpx(ikr,ikz) - ENDDO kzloope - ENDDO krloope + Gy_cmpx(ikx,iky) = imagu*ky*Gy_cmpx(ikx,iky) + Gx_cmpx(ikx,iky) = imagu*kx*Gx_cmpx(ikx,iky) + ENDDO kyloope + ENDDO kxloope ! First term drphi x dzf - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - cmpx_data_f(ikz,ikr-local_nkr_offset) = Fr_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) !Anti aliasing filter - cmpx_data_g(ikz,ikr-local_nkr_offset) = Gz_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) !Anti aliasing filter + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + cmpx_data_f(iky,ikx-local_nkx_offset) = Fx_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter + cmpx_data_g(iky,ikx-local_nkx_offset) = Gy_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter ENDDO ENDDO call fftw_mpi_execute_dft_c2r(planb, cmpx_data_f, real_data_f) call fftw_mpi_execute_dft_c2r(planb, cmpx_data_g, real_data_g) - real_data_c = real_data_c + real_data_f/Nz/Nr * real_data_g/Nz/Nr + real_data_c = real_data_c + real_data_f/Ny/Nx * real_data_g/Ny/Nx ! Second term -dzphi x drf - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - cmpx_data_f(ikz,ikr-local_nkr_offset) = Fz_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) !Anti aliasing filter - cmpx_data_g(ikz,ikr-local_nkr_offset) = Gr_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) !Anti aliasing filter + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + cmpx_data_f(iky,ikx-local_nkx_offset) = Fy_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter + cmpx_data_g(iky,ikx-local_nkx_offset) = Gx_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter ENDDO ENDDO call fftw_mpi_execute_dft_c2r(planb, cmpx_data_f, real_data_f) call fftw_mpi_execute_dft_c2r(planb, cmpx_data_g, real_data_g) - real_data_c = real_data_c - real_data_f/Nz/Nr * real_data_g/Nz/Nr + real_data_c = real_data_c - real_data_f/Ny/Nx * real_data_g/Ny/Nx ENDDO nloope @@ -103,16 +107,16 @@ SUBROUTINE compute_Sapj call fftw_mpi_execute_dft_r2c(planf, real_data_c, cmpx_data_c) ! Retrieve convolution in input format - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - Sepj(ip,ij,ikr,ikz) = cmpx_data_c(ikz,ikr-local_nkr_offset)*AA_r(ikr)*AA_z(ikz) !Anti aliasing filter + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + Sepj(ip,ij,ikx,iky,iz) = cmpx_data_c(iky,ikx-local_nkx_offset)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter ENDDO ENDDO ENDDO jloope ELSE ! Cancel the non lin term if we are dealing with odd Hermite degree - Sepj(ip,:,:,:) = 0._dp + Sepj(ip,:,:,:,iz) = 0._dp ENDIF ENDDO ploope !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -137,56 +141,56 @@ SUBROUTINE compute_Sapj nloopi: DO in = 1,nmax+1 ! Loop over laguerre for the sum - krloopi: DO ikr = ikrs,ikre ! Loop over kr - kzloopi: DO ikz = ikzs,ikze ! Loop over kz - kr = krarray(ikr) - kz = kzarray(ikz) - kerneln = kernel_i(in, ikr, ikz) + kxloopi: DO ikx = ikxs,ikxe ! Loop over kx + kyloopi: DO iky = ikys,ikye ! Loop over ky + kx = kxarray(ikx) + ky = kyarray(iky) + kerneln = kernel_i(in, ikx, iky) ! First convolution terms - Fr_cmpx(ikr,ikz) = imagu*kr* phi(ikr,ikz) * kerneln - Fz_cmpx(ikr,ikz) = imagu*kz* phi(ikr,ikz) * kerneln + Fx_cmpx(ikx,iky) = imagu*kx* phi(ikx,iky,iz) * kerneln + Fy_cmpx(ikx,iky) = imagu*ky* phi(ikx,iky,iz) * kerneln ! Second convolution terms - Gz_cmpx(ikr,ikz) = 0._dp ! initialization of the sum - Gr_cmpx(ikr,ikz) = 0._dp ! initialization of the sum + Gy_cmpx(ikx,iky) = 0._dp ! initialization of the sum + Gx_cmpx(ikx,iky) = 0._dp ! initialization of the sum smax = MIN( (in-1)+(ij-1), jmaxi ); DO is = 1, smax+1 ! sum truncation on number of moments - Gz_cmpx(ikr,ikz) = Gz_cmpx(ikr,ikz) + & - dnjs(in,ij,is) * moments_i(ip,is,ikr,ikz,updatetlevel) - Gr_cmpx(ikr,ikz) = Gr_cmpx(ikr,ikz) + & - dnjs(in,ij,is) * moments_i(ip,is,ikr,ikz,updatetlevel) + Gy_cmpx(ikx,iky) = Gy_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_i(ip,is,ikx,iky,iz,updatetlevel) + Gx_cmpx(ikx,iky) = Gx_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_i(ip,is,ikx,iky,iz,updatetlevel) ENDDO - Gz_cmpx(ikr,ikz) = imagu*kz*Gz_cmpx(ikr,ikz) - Gr_cmpx(ikr,ikz) = imagu*kr*Gr_cmpx(ikr,ikz) - ENDDO kzloopi - ENDDO krloopi + Gy_cmpx(ikx,iky) = imagu*ky*Gy_cmpx(ikx,iky) + Gx_cmpx(ikx,iky) = imagu*kx*Gx_cmpx(ikx,iky) + ENDDO kyloopi + ENDDO kxloopi ! First term drphi x dzf - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - cmpx_data_f(ikz,ikr-local_nkr_offset) = Fr_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) - cmpx_data_g(ikz,ikr-local_nkr_offset) = Gz_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + cmpx_data_f(iky,ikx-local_nkx_offset) = Fx_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) + cmpx_data_g(iky,ikx-local_nkx_offset) = Gy_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) ENDDO ENDDO call fftw_mpi_execute_dft_c2r(planb, cmpx_data_f, real_data_f) call fftw_mpi_execute_dft_c2r(planb, cmpx_data_g, real_data_g) - real_data_c = real_data_c + real_data_f/Nz/Nr * real_data_g/Nz/Nr + real_data_c = real_data_c + real_data_f/Ny/Nx * real_data_g/Ny/Nx ! Second term -dzphi x drf - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - cmpx_data_f(ikz,ikr-local_nkr_offset) = Fz_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) - cmpx_data_g(ikz,ikr-local_nkr_offset) = Gr_cmpx(ikr,ikz)*AA_r(ikr)*AA_z(ikz) + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + cmpx_data_f(iky,ikx-local_nkx_offset) = Fy_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) + cmpx_data_g(iky,ikx-local_nkx_offset) = Gx_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) ENDDO ENDDO call fftw_mpi_execute_dft_c2r(planb, cmpx_data_f, real_data_f) call fftw_mpi_execute_dft_c2r(planb, cmpx_data_g, real_data_g) - real_data_c = real_data_c - real_data_f/Nz/Nr * real_data_g/Nz/Nr + real_data_c = real_data_c - real_data_f/Ny/Nx * real_data_g/Ny/Nx ENDDO nloopi @@ -194,16 +198,16 @@ SUBROUTINE compute_Sapj call fftw_mpi_execute_dft_r2c(planf, real_data_c, cmpx_data_c) ! Retrieve convolution in input format - DO ikr = ikrs, ikre - DO ikz = ikzs, ikze - Sipj(ip,ij,ikr,ikz) = cmpx_data_c(ikz,ikr-local_nkr_offset)*AA_r(ikr)*AA_z(ikz) + DO ikx = ikxs, ikxe + DO iky = ikys, ikye + Sipj(ip,ij,ikx,iky,iz) = cmpx_data_c(iky,ikx-local_nkx_offset)*AA_x(ikx)*AA_y(iky) ENDDO ENDDO ENDDO jloopi ELSE ! Cancel the non lin term if we are dealing with odd Hermite degree - Sipj(ip,:,:,:) = 0._dp + Sipj(ip,:,:,:,iz) = 0._dp ENDIF ENDDO ploopi !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! @@ -212,4 +216,5 @@ SUBROUTINE compute_Sapj CALL cpu_time(t1_Sapj) tc_Sapj = tc_Sapj + (t1_Sapj - t0_Sapj) +ENDDO zloop END SUBROUTINE compute_Sapj diff --git a/src/diagnose.F90 b/src/diagnose.F90 index d4ecfcce2d8ac52dbb6fbea53bd914dc48f99bbe..e66ea02ed6d9b007bacd539ffdf4fe6f35c0e17f 100644 --- a/src/diagnose.F90 +++ b/src/diagnose.F90 @@ -25,7 +25,7 @@ SUBROUTINE diagnose(kstep) ! so we need to gather non 5D data on one proc to output it INTEGER :: parray_e_full(1:pmaxe+1), parray_i_full(1:pmaxi+1) INTEGER :: jarray_e_full(1:jmaxe+1), jarray_i_full(1:jmaxi+1) - REAL(dp) :: krarray_full(1:nkr), kzarray_full(1:nkz) + REAL(dp) :: kxarray_full(1:Nkx), kyarray_full(1:Nky), zarray_full(1:Nz) CALL cpu_time(t0_diag) ! Measuring time !_____________________________________________________________________________ @@ -72,25 +72,34 @@ SUBROUTINE diagnose(kstep) ! J DO ij = 1,jmaxe+1; jarray_e_full(ij) = (ij-1); END DO DO ij = 1,jmaxi+1; jarray_i_full(ij) = (ij-1); END DO - ! Kr - DO ikr = 1,Nkr - krarray_full(ikr) = REAL(ikr-1,dp) * deltakr + ! kx + DO ikx = 1,Nkx + kxarray_full(ikx) = REAL(ikx-1,dp) * deltakx END DO - ! Kz - IF (Nkz .GT. 1) THEN - DO ikz = 1,Nkz - kzarray_full(ikz) = deltakz*(MODULO(ikz-1,Nkz/2)-Nkz/2*FLOOR(2.*real(ikz-1)/real(Nkz))) - if (ikz .EQ. Nz/2+1) kzarray(ikz) = -kzarray(ikz) + ! ky + IF (Nky .GT. 1) THEN + DO iky = 1,Nky + kyarray_full(iky) = deltaky*(MODULO(iky-1,Nky/2)-Nky/2*FLOOR(2.*real(iky-1)/real(Nky))) + if (iky .EQ. Ny/2+1) kyarray(iky) = -kyarray(iky) END DO + ELSE + kyarray_full(1) = 0 + endif + ! z + IF (Nz .GT. 1) THEN + DO iz = 1,Nz + zarray_full(iz) = deltaz*(iz-1) + END DO ELSE - kzarray_full(1) = 0 + zarray_full(1) = 0 endif ENDIF ! Grid info CALL creatg(fidres, "/data/grid", "Grid data") - CALL putarr(fidres, "/data/grid/coordkr", krarray_full(1:nkr),"kr*rho_s0", ionode=0) - CALL putarr(fidres, "/data/grid/coordkz", kzarray_full(1:nkz),"kz*rho_s0", ionode=0) + CALL putarr(fidres, "/data/grid/coordkx", kxarray_full(1:Nkx),"kx*rho_s0", ionode=0) + CALL putarr(fidres, "/data/grid/coordky", kyarray_full(1:Nky),"ky*rho_s0", ionode=0) + CALL putarr(fidres, "/data/grid/coordz", zarray_full(1:Nz) ,"z/R", ionode=0) CALL putarr(fidres, "/data/grid/coordp_e" , parray_e_full(1:pmaxe+1), "p_e", ionode=0) CALL putarr(fidres, "/data/grid/coordj_e" , jarray_e_full(1:jmaxe+1), "j_e", ionode=0) CALL putarr(fidres, "/data/grid/coordp_i" , parray_i_full(1:pmaxi+1), "p_i", ionode=0) @@ -113,33 +122,44 @@ SUBROUTINE diagnose(kstep) END IF - ! var2d group (electro. pot., Ni00 moment) + ! var2d group (??) IF (nsave_2d .GT. 0) THEN CALL creatg(fidres, "/data/var2d", "2d profiles") CALL creatd(fidres, rank, dims, "/data/var2d/time", "Time t*c_s/R") CALL creatd(fidres, rank, dims, "/data/var2d/cstep", "iteration number") + IF (cstep==0) THEN + iframe2d=0 + ENDIF + CALL attach(fidres,"/data/var2d/" , "frames", iframe2d) + END IF - IF (write_phi) CALL creatg(fidres, "/data/var2d/phi", "phi") + ! var3d group (electro. pot., Ni00 moment) + IF (nsave_3d .GT. 0) THEN + CALL creatg(fidres, "/data/var3d", "3d profiles") + CALL creatd(fidres, rank, dims, "/data/var3d/time", "Time t*c_s/R") + CALL creatd(fidres, rank, dims, "/data/var3d/cstep", "iteration number") + + IF (write_phi) CALL creatg(fidres, "/data/var3d/phi", "phi") IF (write_Na00) THEN - CALL creatg(fidres, "/data/var2d/Ne00", "Ne00") - CALL creatg(fidres, "/data/var2d/Ni00", "Ni00") + CALL creatg(fidres, "/data/var3d/Ne00", "Ne00") + CALL creatg(fidres, "/data/var3d/Ni00", "Ni00") ENDIF IF (write_dens) THEN - CALL creatg(fidres, "/data/var2d/dens_e", "dens_e") - CALL creatg(fidres, "/data/var2d/dens_i", "dens_i") + CALL creatg(fidres, "/data/var3d/dens_e", "dens_e") + CALL creatg(fidres, "/data/var3d/dens_i", "dens_i") ENDIF IF (write_temp) THEN - CALL creatg(fidres, "/data/var2d/temp_e", "temp_e") - CALL creatg(fidres, "/data/var2d/temp_i", "temp_i") + CALL creatg(fidres, "/data/var3d/temp_e", "temp_e") + CALL creatg(fidres, "/data/var3d/temp_i", "temp_i") ENDIF IF (cstep==0) THEN - iframe2d=0 + iframe3d=0 ENDIF - CALL attach(fidres,"/data/var2d/" , "frames", iframe2d) + CALL attach(fidres,"/data/var3d/" , "frames", iframe3d) END IF ! var5d group (moments) @@ -181,6 +201,7 @@ SUBROUTINE diagnose(kstep) CALL attach(fidres, TRIM(str), "start_cstep", cstep-1) CALL attach(fidres, TRIM(str), "start_iframe0d", iframe0d) CALL attach(fidres, TRIM(str), "start_iframe2d", iframe2d) + CALL attach(fidres, TRIM(str), "start_iframe3d", iframe3d) CALL attach(fidres, TRIM(str), "start_iframe5d", iframe5d) CALL attach(fidres, TRIM(str), "dt", dt) CALL attach(fidres, TRIM(str), "tmax", tmax) @@ -188,7 +209,7 @@ SUBROUTINE diagnose(kstep) CALL attach(fidres, TRIM(str), "cpu_time", -1) CALL attach(fidres, TRIM(str), "Nproc", num_procs) CALL attach(fidres, TRIM(str), "Np_p" , num_procs_p) - CALL attach(fidres, TRIM(str), "Np_kr",num_procs_kr) + CALL attach(fidres, TRIM(str), "Np_kx",num_procs_kx) CALL attach(fidres, TRIM(str), "write_gamma",write_gamma) CALL attach(fidres, TRIM(str), "write_phi",write_phi) CALL attach(fidres, TRIM(str), "write_Na00",write_Na00) @@ -253,9 +274,13 @@ SUBROUTINE diagnose(kstep) ! empty in our case ! 2.3 2d profiles - IF (nsave_2d .GT. 0) THEN - IF (MOD(cstep, nsave_2d) == 0) THEN - CALL diagnose_2d + ! empty in our case + + + ! 2.3 2d profiles + IF (nsave_3d .GT. 0) THEN + IF (MOD(cstep, nsave_3d) == 0) THEN + CALL diagnose_3d END IF END IF @@ -334,7 +359,7 @@ SUBROUTINE diagnose_2d USE futils, ONLY: append, getatt, attach, putarrnd USE fields USE array, ONLY: Ne00, Ni00, dens_e, dens_i, temp_e, temp_i - USE grid, ONLY: ikrs,ikre, ikzs,ikze, nkr, nkz, local_nkr, ikr, ikz, ips_e, ips_i + USE grid, ONLY: ikxs,ikxe, ikys,ikye, Nkx, Nky, local_nkx, ikx, iky, ips_e, ips_i USE time_integration USE diagnostics_par USE prec_const @@ -342,7 +367,7 @@ SUBROUTINE diagnose_2d IMPLICIT NONE - COMPLEX(dp) :: buffer(ikrs:ikre,ikzs:ikze) + COMPLEX(dp) :: buffer(ikxs:ikxe,ikys:ikye) INTEGER :: i_, root, world_rank, world_size CALL append(fidres, "/data/var2d/time", time,ionode=0) @@ -351,63 +376,110 @@ SUBROUTINE diagnose_2d iframe2d=iframe2d+1 CALL attach(fidres,"/data/var2d/" , "frames", iframe2d) - IF (write_phi) CALL write_field2d(phi (:,:), 'phi') +CONTAINS + + SUBROUTINE write_field2d(field, text) + USE futils, ONLY: attach, putarr + USE grid, ONLY: ikxs,ikxe, ikys,ikye, Nkx, Nky, local_nkx + USE prec_const + USE basic, ONLY : comm_kx, num_procs_p, rank_p + IMPLICIT NONE + + COMPLEX(dp), DIMENSION(ikxs:ikxe, ikys:ikye), INTENT(IN) :: field + CHARACTER(*), INTENT(IN) :: text + COMPLEX(dp) :: buffer_dist(ikxs:ikxe,ikys:ikye) + COMPLEX(dp) :: buffer_full(1:Nkx,1:Nky) + INTEGER :: scount, rcount + CHARACTER(LEN=50) :: dset_name + + scount = (ikxe-ikxs+1) * (ikye-ikys+1) + rcount = scount + + WRITE(dset_name, "(A, '/', A, '/', i6.6)") "/data/var2d", TRIM(text), iframe2d + IF (num_procs .EQ. 1) THEN ! no data distribution + CALL putarr(fidres, dset_name, field(ikxs:ikxe, ikys:ikye), ionode=0) + ELSE + CALL putarrnd(fidres, dset_name, field(ikxs:ikxe, ikys:ikye), (/1, 1/)) + ENDIF + CALL attach(fidres, dset_name, "time", time) + + END SUBROUTINE write_field2d + +END SUBROUTINE diagnose_2d + +SUBROUTINE diagnose_3d + + USE basic + USE futils, ONLY: append, getatt, attach, putarrnd + USE fields + USE array, ONLY: Ne00, Ni00, dens_e, dens_i, temp_e, temp_i + USE grid, ONLY: ikxs,ikxe, ikys,ikye, Nkx, Nky, local_nkx, ikx, iky, ips_e, ips_i + USE time_integration + USE diagnostics_par + USE prec_const + USE processing + + IMPLICIT NONE + + INTEGER :: i_, root, world_rank, world_size + + CALL append(fidres, "/data/var3d/time", time,ionode=0) + CALL append(fidres, "/data/var3d/cstep", real(cstep,dp),ionode=0) + CALL getatt(fidres, "/data/var3d/", "frames",iframe3d) + iframe3d=iframe3d+1 + CALL attach(fidres,"/data/var3d/" , "frames", iframe3d) + + IF (write_phi) CALL write_field3d(phi (:,:,:), 'phi') IF (write_Na00) THEN IF ( (ips_e .EQ. 1) .AND. (ips_i .EQ. 1) ) THEN - Ne00(ikrs:ikre,ikzs:ikze) = moments_e(ips_e,1,ikrs:ikre,ikzs:ikze,updatetlevel) - Ni00(ikrs:ikre,ikzs:ikze) = moments_i(ips_e,1,ikrs:ikre,ikzs:ikze,updatetlevel) + Ne00(ikxs:ikxe,ikys:ikye,izs:ize) = moments_e(ips_e,1,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel) + Ni00(ikxs:ikxe,ikys:ikye,izs:ize) = moments_i(ips_e,1,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel) ENDIF - CALL manual_2D_bcast(Ne00(ikrs:ikre,ikzs:ikze)) - CALL write_field2d(Ne00(ikrs:ikre,ikzs:ikze), 'Ne00') + CALL manual_3D_bcast(Ne00(ikxs:ikxe,ikys:ikye,izs:ize)) + CALL write_field3d(Ne00(ikxs:ikxe,ikys:ikye,izs:ize), 'Ne00') - CALL manual_2D_bcast(Ni00(ikrs:ikre,ikzs:ikze)) - CALL write_field2d(Ni00(ikrs:ikre,ikzs:ikze), 'Ni00') + CALL manual_3D_bcast(Ni00(ikxs:ikxe,ikys:ikye,izs:ize)) + CALL write_field3d(Ni00(ikxs:ikxe,ikys:ikye,izs:ize), 'Ni00') ENDIF IF (write_dens) THEN CALL compute_density - CALL write_field2d(dens_e(ikrs:ikre,ikzs:ikze), 'dens_e') - CALL write_field2d(dens_i(ikrs:ikre,ikzs:ikze), 'dens_i') + CALL write_field3d(dens_e(ikxs:ikxe,ikys:ikye,izs:ize), 'dens_e') + CALL write_field3d(dens_i(ikxs:ikxe,ikys:ikye,izs:ize), 'dens_i') ENDIF IF (write_temp) THEN CALL compute_temperature - CALL write_field2d(temp_e(ikrs:ikre,ikzs:ikze), 'temp_e') - CALL write_field2d(temp_i(ikrs:ikre,ikzs:ikze), 'temp_i') + CALL write_field3d(temp_e(ikxs:ikxe,ikys:ikye,izs:ize), 'temp_e') + CALL write_field3d(temp_i(ikxs:ikxe,ikys:ikye,izs:ize), 'temp_i') ENDIF CONTAINS - SUBROUTINE write_field2d(field, text) + SUBROUTINE write_field3d(field, text) USE futils, ONLY: attach, putarr - USE grid, ONLY: ikrs,ikre, ikzs,ikze, nkr, nkz, local_nkr + USE grid, ONLY: ikxs,ikxe, ikys,ikye, Nkx, Nky, local_nkx USE prec_const - USE basic, ONLY : comm_kr, num_procs_p, rank_p + USE basic, ONLY : comm_kx, num_procs_p, rank_p IMPLICIT NONE - COMPLEX(dp), DIMENSION(ikrs:ikre, ikzs:ikze), INTENT(IN) :: field + COMPLEX(dp), DIMENSION(ikxs:ikxe, ikys:ikye, izs:ize), INTENT(IN) :: field CHARACTER(*), INTENT(IN) :: text - COMPLEX(dp) :: buffer_dist(ikrs:ikre,ikzs:ikze) - COMPLEX(dp) :: buffer_full(1:nkr,1:nkz) - INTEGER :: scount, rcount CHARACTER(LEN=50) :: dset_name - scount = (ikre-ikrs+1) * (ikze-ikzs+1) - rcount = scount - - WRITE(dset_name, "(A, '/', A, '/', i6.6)") "/data/var2d", TRIM(text), iframe2d + WRITE(dset_name, "(A, '/', A, '/', i6.6)") "/data/var3d", TRIM(text), iframe3d IF (num_procs .EQ. 1) THEN ! no data distribution - CALL putarr(fidres, dset_name, field(ikrs:ikre, ikzs:ikze), ionode=0) + CALL putarr(fidres, dset_name, field(ikxs:ikxe, ikys:ikye, izs:ize), ionode=0) ELSE - CALL putarrnd(fidres, dset_name, field(ikrs:ikre, ikzs:ikze), (/1, 1/)) + CALL putarrnd(fidres, dset_name, field(ikxs:ikxe, ikys:ikye, izs:ize), (/1, 1/)) ENDIF CALL attach(fidres, dset_name, "time", time) - END SUBROUTINE write_field2d + END SUBROUTINE write_field3d -END SUBROUTINE diagnose_2d +END SUBROUTINE diagnose_3d SUBROUTINE diagnose_5d @@ -429,33 +501,33 @@ SUBROUTINE diagnose_5d CALL attach(fidres,"/data/var5d/" , "frames", iframe5d) IF (write_Napj) THEN - CALL write_field5d_e(moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,updatetlevel), 'moments_e') - CALL write_field5d_i(moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,updatetlevel), 'moments_i') + CALL write_field5d_e(moments_e(ips_e:ipe_e,ijs_e:ije_e,:,:,:,updatetlevel), 'moments_e') + CALL write_field5d_i(moments_i(ips_i:ipe_i,ijs_i:ije_i,:,:,:,updatetlevel), 'moments_i') ENDIF IF (write_Sapj) THEN - CALL write_field5d_e(Sepj(ips_e:ipe_e,ijs_e:ije_e,:,:), 'Sepj') - CALL write_field5d_i(Sipj(ips_i:ipe_i,ijs_i:ije_i,:,:), 'Sipj') + CALL write_field5d_e(Sepj(ips_e:ipe_e,ijs_e:ije_e,:,:,:), 'Sepj') + CALL write_field5d_i(Sipj(ips_i:ipe_i,ijs_i:ije_i,:,:,:), 'Sipj') ENDIF CONTAINS SUBROUTINE write_field5d_e(field, text) USE futils, ONLY: attach, putarr, putarrnd - USE grid, ONLY: ips_e,ipe_e, ijs_e,ije_e, ikrs,ikre, ikzs,ikze + USE grid, ONLY: ips_e,ipe_e, ijs_e,ije_e, ikxs,ikxe, ikys,ikye, izs,ize USE prec_const IMPLICIT NONE - COMPLEX(dp), DIMENSION(ips_e:ipe_e,ijs_e:ije_e,ikrs:ikre,ikzs:ikze), INTENT(IN) :: field + COMPLEX(dp), DIMENSION(ips_e:ipe_e,ijs_e:ije_e,ikxs:ikxe,ikys:ikye,izs:ize), INTENT(IN) :: field CHARACTER(*), INTENT(IN) :: text CHARACTER(LEN=50) :: dset_name WRITE(dset_name, "(A, '/', A, '/', i6.6)") "/data/var5d", TRIM(text), iframe5d IF (num_procs .EQ. 1) THEN - CALL putarr(fidres, dset_name, field(ips_e:ipe_e,ijs_e:ije_e,ikrs:ikre,ikzs:ikze), ionode=0) + CALL putarr(fidres, dset_name, field(ips_e:ipe_e,ijs_e:ije_e,ikxs:ikxe,ikys:ikye,izs:ize), ionode=0) ELSE - CALL putarrnd(fidres, dset_name, field(ips_e:ipe_e,ijs_e:ije_e,ikrs:ikre,ikzs:ikze), (/1,3/)) + CALL putarrnd(fidres, dset_name, field(ips_e:ipe_e,ijs_e:ije_e,ikxs:ikxe,ikys:ikye,izs:ize), (/1,3/)) ENDIF CALL attach(fidres, dset_name, 'cstep', cstep) CALL attach(fidres, dset_name, 'time', time) @@ -468,20 +540,20 @@ SUBROUTINE diagnose_5d SUBROUTINE write_field5d_i(field, text) USE futils, ONLY: attach, putarr, putarrnd - USE grid, ONLY: ips_i,ipe_i, ijs_i,ije_i, ikrs,ikre, ikzs,ikze + USE grid, ONLY: ips_i,ipe_i, ijs_i,ije_i, ikxs,ikxe, ikys,ikye, izs,ize USE prec_const IMPLICIT NONE - COMPLEX(dp), DIMENSION(ips_i:ipe_i,ijs_i:ije_i,ikrs:ikre,ikzs:ikze), INTENT(IN) :: field + COMPLEX(dp), DIMENSION(ips_i:ipe_i,ijs_i:ije_i,ikxs:ikxe,ikys:ikye,izs:ize), INTENT(IN) :: field CHARACTER(*), INTENT(IN) :: text CHARACTER(LEN=50) :: dset_name WRITE(dset_name, "(A, '/', A, '/', i6.6)") "/data/var5d", TRIM(text), iframe5d IF (num_procs .EQ. 1) THEN - CALL putarr(fidres, dset_name, field(ips_i:ipe_i,ijs_i:ije_i,ikrs:ikre,ikzs:ikze), ionode=0) + CALL putarr(fidres, dset_name, field(ips_i:ipe_i,ijs_i:ije_i,ikxs:ikxe,ikys:ikye,izs:ize), ionode=0) ELSE - CALL putarrnd(fidres, dset_name, field(ips_i:ipe_i,ijs_i:ije_i,ikrs:ikre,ikzs:ikze), (/1,3/)) + CALL putarrnd(fidres, dset_name, field(ips_i:ipe_i,ijs_i:ije_i,ikxs:ikxe,ikys:ikye,izs:ize), (/1,3/)) ENDIF CALL attach(fidres, dset_name, 'cstep', cstep) CALL attach(fidres, dset_name, 'time', time) diff --git a/src/diagnostics_par_mod.F90 b/src/diagnostics_par_mod.F90 index 011e09edcc81ffa7b6a7765d5adf5f6cf352693b..3e48810e8331c9479c932772cf5246b641cdca86 100644 --- a/src/diagnostics_par_mod.F90 +++ b/src/diagnostics_par_mod.F90 @@ -11,7 +11,7 @@ MODULE diagnostics_par LOGICAL, PUBLIC, PROTECTED :: write_Napj, write_Sapj LOGICAL, PUBLIC, PROTECTED :: write_dens, write_temp - INTEGER, PUBLIC, PROTECTED :: nsave_0d , nsave_1d , nsave_2d , nsave_5d, nsave_cp + INTEGER, PUBLIC, PROTECTED :: nsave_0d, nsave_1d, nsave_2d, nsave_3d, nsave_5d, nsave_cp ! HDF5 file CHARACTER(len=256), PUBLIC :: resfile0 = "results" ! Head of main result file name @@ -34,7 +34,7 @@ CONTAINS USE prec_const IMPLICIT NONE - NAMELIST /OUTPUT_PAR/ nsave_0d , nsave_1d , nsave_2d , nsave_5d, nsave_cp + NAMELIST /OUTPUT_PAR/ nsave_0d, nsave_1d, nsave_2d, nsave_3d, nsave_5d, nsave_cp NAMELIST /OUTPUT_PAR/ write_doubleprecision, write_gamma, write_phi NAMELIST /OUTPUT_PAR/ write_Na00, write_Napj, write_Sapj NAMELIST /OUTPUT_PAR/ write_dens, write_temp diff --git a/src/fields_mod.F90 b/src/fields_mod.F90 index 58075c2d5d5f26cb2a5de97e40e8ac45cf3a5792..eac8c04f227a1e86df6cb05b938339c0a7dafc17 100644 --- a/src/fields_mod.F90 +++ b/src/fields_mod.F90 @@ -3,13 +3,13 @@ MODULE fields use prec_const implicit none !------------------MOMENTS Napj------------------ - ! Hermite-Moments: N_a^pj ! dimensions correspond to: p, j, kr, kz, updatetlevel. - COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_e - COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_i + ! Hermite-Moments: N_a^pj ! dimensions correspond to: p, j, kx, ky, z, updatetlevel. + COMPLEX(dp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: moments_e + COMPLEX(dp), DIMENSION(:,:,:,:,:,:), ALLOCATABLE :: moments_i !------------------ELECTROSTATIC POTENTIAL------------------ - ! Normalized electric potential: \hat{\phi} ! (kr,kz) - COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: phi + ! Normalized electric potential: \hat{\phi} ! (kx,ky,z) + COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: phi END MODULE fields diff --git a/src/fourier_mod.F90 b/src/fourier_mod.F90 index 195b0493058a85db1f277674037e531b9475786f..3c5a232b171c707201e0e4b7be6221ed717fd24e 100644 --- a/src/fourier_mod.F90 +++ b/src/fourier_mod.F90 @@ -29,39 +29,39 @@ MODULE fourier CONTAINS - SUBROUTINE init_grid_distr_and_plans(Nr,Nz) + SUBROUTINE init_grid_distr_and_plans(Nx,Ny) IMPLICIT NONE - INTEGER, INTENT(IN) :: Nr,Nz - NR_ = Nr; NZ_ = Nz + INTEGER, INTENT(IN) :: Nx,Ny + NR_ = Nx; NZ_ = Ny NR_halved = NR_/2 + 1 ! communicator = MPI_COMM_WORLD - communicator = comm_kr + communicator = comm_kx !! Complex arrays F, G ! Compute the room to allocate - alloc_local_1 = fftw_mpi_local_size_2d(NR_halved, NZ_, communicator, local_nkr, local_nkr_offset) + alloc_local_1 = fftw_mpi_local_size_2d(NR_halved, NZ_, communicator, local_nkx, local_nkx_offset) ! Initalize pointers to this room cdatac_f = fftw_alloc_complex(alloc_local_1) cdatac_g = fftw_alloc_complex(alloc_local_1) cdatac_c = fftw_alloc_complex(alloc_local_1) ! Initalize the arrays with the rooms pointed - call c_f_pointer(cdatac_f, cmpx_data_f, [NZ_ ,local_nkr]) - call c_f_pointer(cdatac_g, cmpx_data_g, [NZ_ ,local_nkr]) - call c_f_pointer(cdatac_c, cmpx_data_c, [NZ_ ,local_nkr]) + call c_f_pointer(cdatac_f, cmpx_data_f, [NZ_ ,local_nkx]) + call c_f_pointer(cdatac_g, cmpx_data_g, [NZ_ ,local_nkx]) + call c_f_pointer(cdatac_c, cmpx_data_c, [NZ_ ,local_nkx]) !! Real arrays iFFT(F), iFFT(G) ! Compute the room to allocate - alloc_local_2 = fftw_mpi_local_size_2d(NZ_, NR_halved, communicator, local_nz, local_nz_offset) + alloc_local_2 = fftw_mpi_local_size_2d(NZ_, NR_halved, communicator, local_nky, local_nky_offset) ! Initalize pointers to this room cdatar_f = fftw_alloc_real(2*alloc_local_2) cdatar_g = fftw_alloc_real(2*alloc_local_2) cdatar_c = fftw_alloc_real(2*alloc_local_2) ! Initalize the arrays with the rooms pointed - call c_f_pointer(cdatar_f, real_data_f, [2*(NR_/2 + 1),local_nz]) - call c_f_pointer(cdatar_g, real_data_g, [2*(NR_/2 + 1),local_nz]) - call c_f_pointer(cdatar_c, real_data_c, [2*(NR_/2 + 1),local_nz]) + call c_f_pointer(cdatar_f, real_data_f, [2*(NR_/2 + 1),local_nky]) + call c_f_pointer(cdatar_g, real_data_g, [2*(NR_/2 + 1),local_nky]) + call c_f_pointer(cdatar_c, real_data_c, [2*(NR_/2 + 1),local_nky]) ! Plan Creation (out-of-place forward and backward FFT) planf = fftw_mpi_plan_dft_r2c_2d(NZ_, NR_, real_data_f, cmpx_data_f, communicator, ior(FFTW_MEASURE, FFTW_MPI_TRANSPOSED_OUT)) @@ -80,13 +80,13 @@ MODULE fourier SUBROUTINE convolve_2D_F2F( F_2D, G_2D, C_2D ) IMPLICIT NONE - COMPLEX(C_DOUBLE_COMPLEX), DIMENSION(ikrs:ikre,ikzs:ikze), INTENT(IN) :: F_2D, G_2D ! input fields - COMPLEX(C_DOUBLE_COMPLEX), DIMENSION(ikrs:ikre,ikzs:ikze), INTENT(OUT) :: C_2D ! output convolutioned field + COMPLEX(C_DOUBLE_COMPLEX), DIMENSION(ikxs:ikxe,ikys:ikye), INTENT(IN) :: F_2D, G_2D ! input fields + COMPLEX(C_DOUBLE_COMPLEX), DIMENSION(ikxs:ikxe,ikys:ikye), INTENT(OUT) :: C_2D ! output convolutioned field - do ikr = ikrs, ikre - do ikz = ikzs, ikze - cmpx_data_f(ikz,ikr-local_nkr_offset) = F_2D(ikr,ikz)*AA_r(ikr)*AA_z(ikz) - cmpx_data_g(ikz,ikr-local_nkr_offset) = G_2D(ikr,ikz)*AA_r(ikr)*AA_z(ikz) + do ikx = ikxs, ikxe + do iky = ikys, ikye + cmpx_data_f(iky,ikx-local_nkx_offset) = F_2D(ikx,iky)*AA_x(ikx)*AA_y(iky) + cmpx_data_g(iky,ikx-local_nkx_offset) = G_2D(ikx,iky)*AA_x(ikx)*AA_y(iky) end do end do @@ -99,9 +99,9 @@ MODULE fourier call fftw_mpi_execute_dft_r2c(planf, real_data_c, cmpx_data_c) ! Retrieve convolution in input format - do ikr = ikrs, ikre - do ikz = ikzs, ikze - C_2D(ikr,ikz) = cmpx_data_c(ikz,ikr-local_nkr_offset)*AA_r(ikr)*AA_z(ikz) + do ikx = ikxs, ikxe + do iky = ikys, ikye + C_2D(ikx,iky) = cmpx_data_c(iky,ikx-local_nkx_offset)*AA_x(ikx)*AA_y(iky) end do end do diff --git a/src/ghosts_mod.F90 b/src/ghosts_mod.F90 index 416b7a3cb0e8aac761450d43943f9beeecec5178..1e42882206ac8b128c44a3a9f850cacb9fabd728 100644 --- a/src/ghosts_mod.F90 +++ b/src/ghosts_mod.F90 @@ -32,22 +32,22 @@ END SUBROUTINE update_ghosts SUBROUTINE update_ghosts_p_e IMPLICIT NONE - count = (ijeg_e-ijsg_e+1)*(ikre-ikrs+1)*(ikze-ikzs+1) + count = (ijeg_e-ijsg_e+1)*(ikxe-ikxs+1)*(ikye-ikys+1)*(ize-izs+1) !!!!!!!!!!! Send ghost to right neighbour !!!!!!!!!!!!!!!!!!!!!! - CALL mpi_sendrecv(moments_e(ipe_e ,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 10, & - moments_e(ips_e-1,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 10, & + CALL mpi_sendrecv(moments_e(ipe_e ,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 10, & + moments_e(ips_e-1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 10, & comm0, status, ierr) - CALL mpi_sendrecv(moments_e(ipe_e-1,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 11, & - moments_e(ips_e-2,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 11, & + CALL mpi_sendrecv(moments_e(ipe_e-1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 11, & + moments_e(ips_e-2,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 11, & comm0, status, ierr) !!!!!!!!!!! Send ghost to left neighbour !!!!!!!!!!!!!!!!!!!!!! - CALL mpi_sendrecv(moments_e(ips_e ,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 12, & - moments_e(ipe_e+1,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 12, & + CALL mpi_sendrecv(moments_e(ips_e ,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 12, & + moments_e(ipe_e+1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 12, & comm0, status, ierr) - CALL mpi_sendrecv(moments_e(ips_e+1,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 13, & - moments_e(ipe_e+2,ijsg_e:ijeg_e,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 13, & + CALL mpi_sendrecv(moments_e(ips_e+1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 13, & + moments_e(ipe_e+2,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 13, & comm0, status, ierr) END SUBROUTINE update_ghosts_p_e @@ -57,23 +57,23 @@ SUBROUTINE update_ghosts_p_i IMPLICIT NONE - count = (ijeg_i-ijsg_i+1)*(ikre-ikrs+1)*(ikze-ikzs+1) ! Number of elements sent + count = (ijeg_i-ijsg_i+1)*(ikxe-ikxs+1)*(ikye-ikys+1)*(ize-izs+1) ! Number of elements sent !!!!!!!!!!! Send ghost to right neighbour !!!!!!!!!!!!!!!!!!!!!! - CALL mpi_sendrecv(moments_i(ipe_i ,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 14, & - moments_i(ips_i-1,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 14, & + CALL mpi_sendrecv(moments_i(ipe_i ,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 14, & + moments_i(ips_i-1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 14, & comm0, status, ierr) - CALL mpi_sendrecv(moments_i(ipe_i-1,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 15, & - moments_i(ips_i-2,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 15, & + CALL mpi_sendrecv(moments_i(ipe_i-1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 15, & + moments_i(ips_i-2,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 15, & comm0, status, ierr) !!!!!!!!!!! Send ghost to left neighbour !!!!!!!!!!!!!!!!!!!!!! CALL mpi_cart_shift(comm0, 0, -1, source , dest , ierr) - CALL mpi_sendrecv(moments_i(ips_i ,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 16, & - moments_i(ipe_i+1,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 16, & + CALL mpi_sendrecv(moments_i(ips_i ,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 16, & + moments_i(ipe_i+1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 16, & comm0, status, ierr) - CALL mpi_sendrecv(moments_i(ips_i+1,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 17, & - moments_i(ipe_i+2,ijsg_i:ijeg_i,ikrs:ikre,ikzs:ikze,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 17, & + CALL mpi_sendrecv(moments_i(ips_i+1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 17, & + moments_i(ipe_i+2,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,izs:ize,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 17, & comm0, status, ierr) END SUBROUTINE update_ghosts_p_i diff --git a/src/grid_mod.F90 b/src/grid_mod.F90 index 46d2ee3029508f0d77f7371d7a4726b111f63224..eb57a25598f65be9c1e10c069fadd671decf862c 100644 --- a/src/grid_mod.F90 +++ b/src/grid_mod.F90 @@ -12,32 +12,35 @@ MODULE grid INTEGER, PUBLIC, PROTECTED :: pmaxi = 1 ! The maximal ion Hermite-moment computed INTEGER, PUBLIC, PROTECTED :: jmaxi = 1 ! The maximal ion Laguerre-moment computed INTEGER, PUBLIC, PROTECTED :: maxj = 1 ! The maximal ion Laguerre-moment computed - INTEGER, PUBLIC, PROTECTED :: Nr = 16 ! Number of total internal grid points in r - REAL(dp), PUBLIC, PROTECTED :: Lr = 1._dp ! horizontal length of the spatial box - INTEGER, PUBLIC, PROTECTED :: Nz = 16 ! Number of total internal grid points in z - REAL(dp), PUBLIC, PROTECTED :: Lz = 1._dp ! vertical length of the spatial box - INTEGER, PUBLIC, PROTECTED :: Nkr = 8 ! Number of total internal grid points in kr - REAL(dp), PUBLIC, PROTECTED :: Lkr = 1._dp ! horizontal length of the fourier box - INTEGER, PUBLIC, PROTECTED :: Nkz = 16 ! Number of total internal grid points in kz - REAL(dp), PUBLIC, PROTECTED :: Lkz = 1._dp ! vertical length of the fourier box + INTEGER, PUBLIC, PROTECTED :: Nx = 16 ! Number of total internal grid points in x + REAL(dp), PUBLIC, PROTECTED :: Lx = 1._dp ! horizontal length of the spatial box + INTEGER, PUBLIC, PROTECTED :: Ny = 16 ! Number of total internal grid points in y + REAL(dp), PUBLIC, PROTECTED :: Ly = 1._dp ! vertical length of the spatial box + INTEGER, PUBLIC, PROTECTED :: Nz = 1 ! Number of total perpendicular planes + REAL(dp), PUBLIC, PROTECTED :: q0 = 1._dp ! q factor + INTEGER, PUBLIC, PROTECTED :: Nkx = 8 ! Number of total internal grid points in kx + REAL(dp), PUBLIC, PROTECTED :: Lkx = 1._dp ! horizontal length of the fourier box + INTEGER, PUBLIC, PROTECTED :: Nky = 16 ! Number of total internal grid points in ky + REAL(dp), PUBLIC, PROTECTED :: Lky = 1._dp ! vertical length of the fourier box REAL(dp), PUBLIC, PROTECTED :: kpar = 0_dp ! parallel wave vector component ! For Orszag filter - REAL(dp), PUBLIC, PROTECTED :: two_third_krmax - REAL(dp), PUBLIC, PROTECTED :: two_third_kzmax + REAL(dp), PUBLIC, PROTECTED :: two_third_kxmax + REAL(dp), PUBLIC, PROTECTED :: two_third_kymax REAL(dp), PUBLIC, PROTECTED :: two_third_kpmax ! 1D Antialiasing arrays (2/3 rule) - REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: AA_r - REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: AA_z + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: AA_x + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: AA_y ! Grids containing position in physical space - REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: rarray + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: xarray + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: yarray REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: zarray - REAL(dp), PUBLIC, PROTECTED :: deltar, deltaz - INTEGER, PUBLIC, PROTECTED :: irs, ire, izs, ize + REAL(dp), PUBLIC, PROTECTED :: deltax, deltay, deltaz + INTEGER, PUBLIC, PROTECTED :: ixs, ixe, iys, iye, izs, ize INTEGER, PUBLIC :: ir,iz ! counters - integer(C_INTPTR_T), PUBLIC :: local_nkr, local_nz - integer(C_INTPTR_T), PUBLIC :: local_nkr_offset, local_nz_offset + integer(C_INTPTR_T), PUBLIC :: local_nkx, local_nky + integer(C_INTPTR_T), PUBLIC :: local_nkx_offset, local_nky_offset INTEGER, PUBLIC :: local_nkp INTEGER, PUBLIC :: local_np_e, local_np_i integer(C_INTPTR_T), PUBLIC :: local_np_e_offset, local_np_i_offset @@ -45,15 +48,15 @@ MODULE grid INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: displs_np_e, displs_np_i ! Grids containing position in fourier space - REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: krarray - REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: kzarray + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: kxarray + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: kyarray REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: kparray ! kperp array - REAL(dp), PUBLIC, PROTECTED :: deltakr, deltakz, kr_max, kz_max, kp_max - INTEGER, PUBLIC, PROTECTED :: ikrs, ikre, ikzs, ikze, ikps, ikpe - INTEGER, PUBLIC, PROTECTED :: ikr_0, ikz_0, ikr_max, ikz_max ! Indices of k-grid origin and max - INTEGER, PUBLIC :: ikr, ikz, ip, ij, ikp ! counters - LOGICAL, PUBLIC, PROTECTED :: contains_kr0 = .false. ! rank of the proc containing kr=0 indices - LOGICAL, PUBLIC, PROTECTED :: contains_krmax = .false. ! rank of the proc containing kr=max indices + REAL(dp), PUBLIC, PROTECTED :: deltakx, deltaky, kx_max, ky_max, kp_max + INTEGER, PUBLIC, PROTECTED :: ikxs, ikxe, ikys, ikye, ikps, ikpe + INTEGER, PUBLIC, PROTECTED :: ikx_0, iky_0, ikx_max, iky_max ! Indices of k-grid origin and max + INTEGER, PUBLIC :: ikx, iky, ip, ij, ikp ! counters + LOGICAL, PUBLIC, PROTECTED :: contains_kx0 = .false. ! rank of the proc containing kx=0 indices + LOGICAL, PUBLIC, PROTECTED :: contains_kxmax = .false. ! rank of the proc containing kx=max indices ! Grid containing the polynomials degrees INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: parray_e @@ -68,7 +71,7 @@ MODULE grid ! Public Functions PUBLIC :: init_1Dgrid_distr PUBLIC :: set_pgrid, set_jgrid - PUBLIC :: set_krgrid, set_kzgrid, set_kpgrid + PUBLIC :: set_kxgrid, set_kygrid, set_kpgrid, set_zgrid PUBLIC :: grid_readinputs, grid_outputinputs PUBLIC :: bare, bari @@ -79,12 +82,12 @@ CONTAINS SUBROUTINE init_1Dgrid_distr - ! write(*,*) Nr - local_nkr = (Nr/2+1)/num_procs_kr - ! write(*,*) local_nkr - local_nkr_offset = rank_kr*local_nkr + ! write(*,*) Nx + local_nkx = (Nx/2+1)/num_procs_kx + ! write(*,*) local_nkx + local_nkx_offset = rank_kx*local_nkx - if (rank_kr .EQ. num_procs_kr-1) local_nkr = (Nr/2+1)-local_nkr_offset + if (rank_kx .EQ. num_procs_kx-1) local_nkx = (Nx/2+1)-local_nkx_offset END SUBROUTINE init_1Dgrid_distr @@ -153,116 +156,136 @@ CONTAINS END SUBROUTINE set_jgrid - SUBROUTINE set_krgrid + SUBROUTINE set_kxgrid USE prec_const IMPLICIT NONE INTEGER :: i_ - Nkr = Nr/2+1 ! Defined only on positive kr since fields are real + Nkx = Nx/2+1 ! Defined only on positive kx since fields are real ! Start and END indices of grid - ikrs = local_nkr_offset + 1 - ikre = ikrs + local_nkr - 1 - ALLOCATE(krarray(ikrs:ikre)) + ikxs = local_nkx_offset + 1 + ikxe = ikxs + local_nkx - 1 + ALLOCATE(kxarray(ikxs:ikxe)) ! Grid spacings - IF (Lr .EQ. 0) THEN - deltakr = 1._dp - kr_max = 0._dp + IF (Lx .EQ. 0) THEN + deltakx = 1._dp + kx_max = 0._dp ELSE - deltakr = 2._dp*PI/Lr - kr_max = (Nr/2+1)*deltakr + deltakx = 2._dp*PI/Lx + kx_max = (Nx/2+1)*deltakx ENDIF ! Creating a grid ordered as dk*(0 1 2 3) - DO ikr = ikrs,ikre - krarray(ikr) = REAL(ikr-1,dp) * deltakr - ! Finding kr=0 - IF (krarray(ikr) .EQ. 0) THEN - ikr_0 = ikr - contains_kr0 = .true. + DO ikx = ikxs,ikxe + kxarray(ikx) = REAL(ikx-1,dp) * deltakx + ! Finding kx=0 + IF (kxarray(ikx) .EQ. 0) THEN + ikx_0 = ikx + contains_kx0 = .true. ENDIF - ! Finding krmax idx - IF (krarray(ikr) .EQ. kr_max) THEN - ikr_max = ikr - contains_krmax = .true. + ! Finding kxmax idx + IF (kxarray(ikx) .EQ. kx_max) THEN + ikx_max = ikx + contains_kxmax = .true. ENDIF END DO ! Orszag 2/3 filter - two_third_krmax = 2._dp/3._dp*deltakr*Nkr - ALLOCATE(AA_r(ikrs:ikre)) - DO ikr = ikrs,ikre - IF ( (krarray(ikr) .LT. two_third_krmax) ) THEN - AA_r(ikr) = 1._dp; + two_third_kxmax = 2._dp/3._dp*deltakx*Nkx + ALLOCATE(AA_x(ikxs:ikxe)) + DO ikx = ikxs,ikxe + IF ( (kxarray(ikx) .LT. two_third_kxmax) ) THEN + AA_x(ikx) = 1._dp; ELSE - AA_r(ikr) = 0._dp; + AA_x(ikx) = 0._dp; ENDIF END DO - END SUBROUTINE set_krgrid + END SUBROUTINE set_kxgrid - SUBROUTINE set_kzgrid + SUBROUTINE set_kygrid USE prec_const IMPLICIT NONE INTEGER :: i_, counter - Nkz = Nz; + Nky = Ny; ! Start and END indices of grid - ikzs = 1 - ikze = Nkz - ALLOCATE(kzarray(ikzs:ikze)) - - IF (Lz .EQ. 0) THEN ! 1D linear case - deltakz = 1._dp - kzarray(1) = 0 - ikz_0 = 1 - ikz_max = 1 + ikys = 1 + ikye = Nky + ALLOCATE(kyarray(ikys:ikye)) + + IF (Ly .EQ. 0) THEN ! 1D linear case + deltaky = 1._dp + kyarray(1) = 0 + iky_0 = 1 + iky_max = 1 ELSE - deltakz = 2._dp*PI/Lz - kz_max = (Nz/2)*deltakr + deltaky = 2._dp*PI/Ly + ky_max = (Ny/2)*deltakx ! Creating a grid ordered as dk*(0 1 2 3 -2 -1) - DO ikz = ikzs,ikze - kzarray(ikz) = deltakz*(MODULO(ikz-1,Nkz/2)-Nkz/2*FLOOR(2.*real(ikz-1)/real(Nkz))) - if (ikz .EQ. Nz/2+1) kzarray(ikz) = -kzarray(ikz) - ! Finding kz=0 - IF (kzarray(ikz) .EQ. 0) ikz_0 = ikz - ! Finding kzmax - IF (kzarray(ikr) .EQ. kz_max) ikr_max = ikr + DO iky = ikys,ikye + kyarray(iky) = deltaky*(MODULO(iky-1,Nky/2)-Nky/2*FLOOR(2.*real(iky-1)/real(Nky))) + if (iky .EQ. Ny/2+1) kyarray(iky) = -kyarray(iky) + ! Finding ky=0 + IF (kyarray(iky) .EQ. 0) iky_0 = iky + ! Finding kymax + IF (kyarray(ikx) .EQ. ky_max) ikx_max = ikx END DO ENDIF ! Orszag 2/3 filter - two_third_kzmax = 2._dp/3._dp*deltakz*(Nkz/2); - ALLOCATE(AA_z(ikzs:ikze)) - DO ikz = ikzs,ikze - IF ( (kzarray(ikz) .GT. -two_third_kzmax) .AND. (kzarray(ikz) .LT. two_third_kzmax) ) THEN - AA_z(ikz) = 1._dp; + two_third_kymax = 2._dp/3._dp*deltaky*(Nky/2); + ALLOCATE(AA_y(ikys:ikye)) + DO iky = ikys,ikye + IF ( (kyarray(iky) .GT. -two_third_kymax) .AND. (kyarray(iky) .LT. two_third_kymax) ) THEN + AA_y(iky) = 1._dp; ELSE - AA_z(ikz) = 0._dp; + AA_y(iky) = 0._dp; ENDIF END DO - END SUBROUTINE set_kzgrid + END SUBROUTINE set_kygrid SUBROUTINE set_kpgrid !Precompute the grid of kperp IMPLICIT NONE - INTEGER :: ikz_sym, tmp_, counter + INTEGER :: iky_sym, tmp_, counter REAL(dp):: local_kp_min, local_kp_max ! Find the min and max kperp to load subsequent GK matrices - local_kp_min = krarray(ikrs) !smallest local kperp is on the kr axis - local_kp_max = SQRT(krarray(ikre)**2 + kzarray(Nkz/2+1)**2) - ikps = ikrs - ikpe = INT(CEILING(local_kp_max/deltakr))+2 + local_kp_min = kxarray(ikxs) !smallest local kperp is on the kx axis + local_kp_max = SQRT(kxarray(ikxe)**2 + kyarray(Nky/2+1)**2) + ikps = ikxs + ikpe = INT(CEILING(local_kp_max/deltakx))+2 ! local number of different kperp local_nkp = ikpe - ikps + 1 ! Allocate 1D array of kperp values and indices ALLOCATE(kparray(ikps:ikpe)) DO ikp = ikps,ikpe - kparray(ikp) = REAL(ikp-1,dp) * deltakr + kparray(ikp) = REAL(ikp-1,dp) * deltakx ENDDO - write(*,*) rank_kr, ': ikps = ', ikps, 'ikpe = ',ikpe - two_third_kpmax = SQRT(two_third_krmax**2+two_third_kzmax**2) + write(*,*) rank_kx, ': ikps = ', ikps, 'ikpe = ',ikpe + two_third_kpmax = SQRT(two_third_kxmax**2+two_third_kymax**2) kp_max = 3._dp/2._dp * two_third_kpmax END SUBROUTINE + SUBROUTINE set_zgrid + USE prec_const + IMPLICIT NONE + INTEGER :: i_ + ! Start and END indices of grid + izs = 1 + ize = Nz + ALLOCATE(zarray(izs:ize)) + IF (Nz .EQ. 1) THEN ! full perp case + deltaz = 1._dp + zarray(1) = 0 + ELSE + deltaz = q0*2._dp*PI/REAL(Nz+1,dp) + DO iz = izs,ize + zarray(iz) = REAL((iz-1),dp)*deltaz + ENDDO + ENDIF + if(my_id.EQ.0) write(*,*) '#parallel planes = ', Nz + END SUBROUTINE set_zgrid + SUBROUTINE grid_readinputs ! Read the input parameters USE prec_const @@ -270,7 +293,7 @@ CONTAINS INTEGER :: lu_in = 90 ! File duplicated from STDIN NAMELIST /GRID/ pmaxe, jmaxe, pmaxi, jmaxi, & - Nr, Lr, Nz, Lz, kpar + Nx, Lx, Ny, Ly, Nz, q0 READ(lu_in,grid) END SUBROUTINE grid_readinputs @@ -290,14 +313,16 @@ CONTAINS CALL attach(fidres, TRIM(str), "jmaxe", jmaxe) CALL attach(fidres, TRIM(str), "pmaxi", pmaxi) CALL attach(fidres, TRIM(str), "jmaxi", jmaxi) - CALL attach(fidres, TRIM(str), "nr", nr) - CALL attach(fidres, TRIM(str), "Lr", Lr) - CALL attach(fidres, TRIM(str), "nz", nz) - CALL attach(fidres, TRIM(str), "Lz", Lz) - CALL attach(fidres, TRIM(str), "nkr", nkr) - CALL attach(fidres, TRIM(str), "Lkr", Lkr) - CALL attach(fidres, TRIM(str), "nkz", nkz) - CALL attach(fidres, TRIM(str), "Lkz", Lkz) + CALL attach(fidres, TRIM(str), "Nx", Nx) + CALL attach(fidres, TRIM(str), "Lx", Lx) + CALL attach(fidres, TRIM(str), "Ny", Ny) + CALL attach(fidres, TRIM(str), "Ly", Ly) + CALL attach(fidres, TRIM(str), "Nz", Nz) + CALL attach(fidres, TRIM(str), "q0", q0) + CALL attach(fidres, TRIM(str), "Nkx", Nkx) + CALL attach(fidres, TRIM(str), "Lkx", Lkx) + CALL attach(fidres, TRIM(str), "Nky", Nky) + CALL attach(fidres, TRIM(str), "Lky", Lky) END SUBROUTINE grid_outputinputs FUNCTION bare(p_,j_) diff --git a/src/inital.F90 b/src/inital.F90 index dcb31a690bb45555a547adb2f090070cacb3bbb3..2dfd084e44a606a3e5d898bc79ccb6229d5c277f 100644 --- a/src/inital.F90 +++ b/src/inital.F90 @@ -7,43 +7,45 @@ SUBROUTINE inital USE model, ONLY : CO, NON_LIN USE initial_par USE prec_const - USE coeff USE time_integration USE array, ONLY : Sepj,Sipj USE collision USE closure USE ghosts USE restarts - - implicit none + IMPLICIT NONE CALL set_updatetlevel(1) - IF (my_id .EQ. 0) WRITE(*,*) 'Evaluate kernels' - CALL evaluate_kernels - !!!!!! Set the moments arrays Nepj, Nipj and phi!!!!!! + ! through loading a previou state IF ( RESTART ) THEN IF (my_id .EQ. 0) WRITE(*,*) 'Load moments' CALL load_moments ! get N_0 - - IF (my_id .EQ. 0) WRITE(*,*) 'Init phi with Poisson' CALL poisson ! compute phi_0=phi(N_0) - + ! through initialization ELSE + ! set phi with noise and set moments to 0 IF (INIT_NOISY_PHI) THEN - IF (my_id .EQ. 0) WRITE(*,*) 'Init noisy phi' - CALL init_phi ! init noisy phi_0, N_0 = 0 - ELSEIF (INIT_ZF .GT. 0) THEN - IF (my_id .EQ. 0) WRITE(*,*) 'Init ZF phi' - CALL init_phi ! init ZF + CALL init_phi + + ! set moments_00 (GC density) with noise and compute phi afterwards ELSE - IF (my_id .EQ. 0) WRITE(*,*) 'Init noisy moments and ghosts' + IF (my_id .EQ. 0) WRITE(*,*) 'Init noisy moments' CALL init_moments ! init noisy N_0 - IF (my_id .EQ. 0) WRITE(*,*) 'Init phi with Poisson' CALL poisson ! get phi_0 = phi(N_0) ENDIF + ENDIF + ! Option for wiping the turbulence and check growth of secondary inst. + IF ( WIPE_TURB ) THEN + IF (my_id .EQ. 0) WRITE(*,*) '-Wiping turbulence' + CALL wipe_turbulence + ENDIF + ! Option for initializing a gaussian blob on the zonal profile + IF ( INIT_BLOB ) THEN + IF (my_id .EQ. 0) WRITE(*,*) '--init a blob' + CALL put_blob ENDIF IF (my_id .EQ. 0) WRITE(*,*) 'Apply closure' @@ -54,9 +56,6 @@ SUBROUTINE inital !!!!!! Set Sepj, Sipj and dnjs coeff table !!!!!! IF ( NON_LIN ) THEN; - IF (my_id .EQ. 0) WRITE(*,*) 'Building Dnjs table' - CALL build_dnjs_table - IF (my_id .EQ. 0) WRITE(*,*) 'Init Sapj' CALL compute_Sapj ! compute S_0 = S(phi_0,N_0) ENDIF @@ -67,7 +66,6 @@ SUBROUTINE inital ! Compute collision CALL compute_TColl ! compute C_0 = C(N_0) ENDIF - END SUBROUTINE inital !******************************************************************************! @@ -85,7 +83,7 @@ SUBROUTINE init_moments IMPLICIT NONE REAL(dp) :: noise - REAL(dp) :: kr, kz, sigma, gain, kz_shift + REAL(dp) :: kx, ky, sigma, gain, ky_shift INTEGER, DIMENSION(12) :: iseedarr ! Seed random number generator @@ -96,16 +94,18 @@ SUBROUTINE init_moments DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - CALL RANDOM_NUMBER(noise) - moments_e( ip,ij, ikr,ikz, :) = (init_background + init_noiselvl*(noise-0.5_dp)) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + CALL RANDOM_NUMBER(noise) + moments_e(ip,ij,ikx,iky,iz,:) = (init_background + init_noiselvl*(noise-0.5_dp)) + END DO END DO END DO - IF ( contains_kr0 ) THEN - DO ikz=2,Nkz/2 !symmetry at kr = 0 - moments_e( ip,ij,ikr_0,ikz, :) = moments_e( ip,ij,ikr_0,Nkz+2-ikz, :) + IF ( contains_kx0 ) THEN + DO iky=2,Nky/2 !symmetry at kx = 0 for all z + moments_e(ip,ij,ikx_0,iky,:,:) = moments_e( ip,ij,ikx_0,Nky+2-iky,:, :) END DO ENDIF @@ -115,16 +115,18 @@ SUBROUTINE init_moments DO ip=ips_i,ipe_i DO ij=ijs_i,ije_i - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - CALL RANDOM_NUMBER(noise) - moments_i( ip,ij, ikr,ikz, :) = (init_background + init_noiselvl*(noise-0.5_dp)) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + CALL RANDOM_NUMBER(noise) + moments_i(ip,ij,ikx,iky,iz,:) = (init_background + init_noiselvl*(noise-0.5_dp)) + END DO END DO END DO - IF ( contains_kr0 ) THEN - DO ikz=2,Nkz/2 !symmetry at kr = 0 - moments_i( ip,ij,ikr_0,ikz, :) = moments_i( ip,ij,ikr_0,Nkz+2-ikz, :) + IF ( contains_kx0 ) THEN + DO iky=2,Nky/2 !symmetry at kx = 0 for all z + moments_i( ip,ij,ikx_0,iky,:,:) = moments_i( ip,ij,ikx_0,Nky+2-iky,:,:) END DO ENDIF @@ -133,21 +135,19 @@ SUBROUTINE init_moments ! Putting to zero modes that are not in the 2/3 Orszag rule IF (NON_LIN) THEN - DO ip=ips_e,ipe_e - DO ij=ijs_e,ije_e - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_e( ip,ij,ikr,ikz, :) = moments_e( ip,ij,ikr,ikz, :)*AA_r(ikr)*AA_z(ikz) - ENDDO - ENDDO - ENDDO - ENDDO - DO ip=ips_i,ipe_i - DO ij=ijs_i,ije_i - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_i( ip,ij,ikr,ikz, :) = moments_i( ip,ij,ikr,ikz, :)*AA_r(ikr)*AA_z(ikz) - ENDDO + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + DO ip=ips_e,ipe_e + DO ij=ijs_e,ije_e + moments_e( ip,ij,ikx,iky,iz, :) = moments_e( ip,ij,ikx,iky,iz, :)*AA_x(ikx)*AA_y(iky) + ENDDO + ENDDO + DO ip=ips_i,ipe_i + DO ij=ijs_i,ije_i + moments_i( ip,ij,ikx,iky,iz, :) = moments_i( ip,ij,ikx,iky,iz, :)*AA_x(ikx)*AA_y(iky) + ENDDO + ENDDO ENDDO ENDDO ENDDO @@ -168,47 +168,50 @@ SUBROUTINE init_phi IMPLICIT NONE REAL(dp) :: noise - REAL(dp) :: kr, kz, sigma, gain, kz_shift + REAL(dp) :: kx, ky, sigma, gain, ky_shift INTEGER, DIMENSION(12) :: iseedarr IF (INIT_NOISY_PHI) THEN - + IF (my_id .EQ. 0) WRITE(*,*) 'Init noisy phi' ! Seed random number generator iseedarr(:)=iseed CALL RANDOM_SEED(PUT=iseedarr+my_id) !**** noise initialization ******************************************* - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - CALL RANDOM_NUMBER(noise) - phi(ikr,ikz) = (init_background + init_noiselvl*(noise-0.5_dp))*AA_r(ikr)*AA_z(ikz) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + CALL RANDOM_NUMBER(noise) + phi(ikx,iky,iz) = (init_background + init_noiselvl*(noise-0.5_dp))*AA_x(ikx)*AA_y(iky) + ENDDO END DO END DO - !symmetry at kr = 0 to keep real inverse transform - IF ( contains_kr0 ) THEN - DO ikz=2,Nkz/2 - phi(ikr_0,ikz) = phi(ikr_0,Nkz+2-ikz) + !symmetry at kx = 0 to keep real inverse transform + IF ( contains_kx0 ) THEN + DO iky=2,Nky/2 + phi(ikx_0,iky,:) = phi(ikx_0,Nky+2-iky,:) END DO - phi(ikr_0,Nz/2) = REAL(phi(ikr_0,Nz/2)) !origin must be real + phi(ikx_0,Ny/2,:) = REAL(phi(ikx_0,Ny/2,:)) !origin must be real ENDIF - !**** Cancel previous moments initialization + !**** ensure no previous moments initialization moments_e = 0._dp; moments_i = 0._dp + !**** Zonal Flow initialization ******************************************* + ! put a mode at ikx = mode number + 1, symmetry is already included since kx>=0 IF(INIT_ZF .GT. 0) THEN - - !**** Zonal Flow initialization ******************************************* - ! put a mode at ikr = mode number + 1, symmetry is already included since kr>=0 - IF( (INIT_ZF+1 .GT. ikrs) .AND. (INIT_ZF+1 .LT. ikre) ) THEN - phi(INIT_ZF+1,ikz_0) = ZF_AMP*(2._dp*PI)**2/deltakr/deltakz/2._dp - moments_i(1,1,INIT_ZF+1,ikz_0,:) = krarray(INIT_ZF+1)**2*phi(INIT_ZF+1,ikz_0) - moments_e(1,1,INIT_ZF+1,ikz_0,:) = 0._dp + IF (my_id .EQ. 0) WRITE(*,*) 'Init ZF phi' + IF( (INIT_ZF+1 .GT. ikxs) .AND. (INIT_ZF+1 .LT. ikxe) ) THEN + DO iz = izs,ize + phi(INIT_ZF+1,iky_0,iz) = ZF_AMP*(2._dp*PI)**2/deltakx/deltaky/2._dp * COS((iz-1)/Nz*2._dp*PI) + moments_i(1,1,INIT_ZF+1,iky_0,iz,:) = kxarray(INIT_ZF+1)**2*phi(INIT_ZF+1,iky_0,iz)* COS((iz-1)/Nz*2._dp*PI) + moments_e(1,1,INIT_ZF+1,iky_0,iz,:) = 0._dp + ENDDO ENDIF ENDIF ELSE ! we compute phi from noisy moments and poisson - CALL poisson ENDIF @@ -216,224 +219,67 @@ END SUBROUTINE init_phi !******************************************************************************! !******************************************************************************! -!!!!!!! Build the Laguerre-Laguerre coupling coefficient table for nonlin +!!!!!!! Remove all ky!=0 modes to conserve only zonal modes in a restart !******************************************************************************! -SUBROUTINE build_dnjs_table - USE basic - USE array, Only : dnjs - USE grid, Only : jmaxe, jmaxi - USE coeff +SUBROUTINE wipe_turbulence + USE fields + USE grid IMPLICIT NONE - - INTEGER :: in, ij, is, J - INTEGER :: n_, j_, s_ - - J = max(jmaxe,jmaxi) - - DO in = 1,J+1 ! Nested dependent loops to make benefit from dnjs symmetry - n_ = in - 1 - DO ij = in,J+1 - j_ = ij - 1 - DO is = ij,J+1 - s_ = is - 1 - - dnjs(in,ij,is) = TO_DP(ALL2L(n_,j_,s_,0)) - ! By symmetry - dnjs(in,is,ij) = dnjs(in,ij,is) - dnjs(ij,in,is) = dnjs(in,ij,is) - dnjs(ij,is,in) = dnjs(in,ij,is) - dnjs(is,ij,in) = dnjs(in,ij,is) - dnjs(is,in,ij) = dnjs(in,ij,is) - ENDDO + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + DO ip=ips_e,ipe_e + DO ij=ijs_e,ije_e + IF( iky .NE. iky_0) THEN + moments_e( ip,ij,ikx,iky,iz, :) = 0e-3_dp*moments_e( ip,ij,ikx,iky,iz, :) + ELSE + moments_e( ip,ij,ikx,iky,iz, :) = 1e+0_dp*moments_e( ip,ij,ikx,iky,iz, :) + ENDIF ENDDO + ENDDO + DO ip=ips_i,ipe_i + DO ij=ijs_i,ije_i + IF( iky .NE. iky_0) THEN + moments_i( ip,ij,ikx,iky,iz, :) = 0e-3_dp*moments_i( ip,ij,ikx,iky,iz, :) + ELSE + moments_i( ip,ij,ikx,iky,iz, :) = 1e+0_dp*moments_i( ip,ij,ikx,iky,iz, :) + ENDIF + ENDDO + ENDDO + ENDDO ENDDO -END SUBROUTINE build_dnjs_table + ENDDO +END SUBROUTINE !******************************************************************************! !******************************************************************************! -!!!!!!! Evaluate the kernels once for all +!!!!!!! Initialize an ionic Gaussian blob on top of the preexisting modes !******************************************************************************! -SUBROUTINE evaluate_kernels - USE basic - USE array, Only : kernel_e, kernel_i +SUBROUTINE put_blob + USE fields USE grid - use model, ONLY : tau_e, tau_i, sigma_e, sigma_i, q_e, q_i, lambdaD, CLOS, sigmae2_taue_o2, sigmai2_taui_o2 + USE model, ONLY: sigmai2_taui_o2 IMPLICIT NONE - - REAL(dp) :: factj, j_dp, j_int - REAL(dp) :: be_2, bi_2, alphaD - REAL(dp) :: kr, kz, kperp2 - - !!!!! Electron kernels !!!!! - !Precompute species dependant factors - factj = 1.0 ! Start of the recursive factorial - DO ij = 1, jmaxe+1 - j_int = jarray_e(ij) - j_dp = REAL(j_int,dp) ! REAL of degree - - ! Recursive factorial - IF (j_dp .GT. 0) THEN - factj = factj * j_dp - ELSE - factj = 1._dp - ENDIF - - DO ikr = ikrs,ikre - kr = krarray(ikr) - DO ikz = ikzs,ikze - kz = kzarray(ikz) - - be_2 = (kr**2 + kz**2) * sigmae2_taue_o2 - - kernel_e(ij, ikr, ikz) = be_2**j_int * exp(-be_2)/factj - - ENDDO - ENDDO - ENDDO - ! Kernels closure - DO ikr = ikrs,ikre - kr = krarray(ikr) - DO ikz = ikzs,ikze - kz = kzarray(ikz) - be_2 = (kr**2 + kz**2) * sigmae2_taue_o2 - ! Kernel ghost + 1 with Kj+1 = y/(j+1) Kj (/!\ ij = j+1) - kernel_e(ijeg_e,ikr,ikz) = be_2/(real(ijeg_e-1,dp))*kernel_e(ije_e,ikr,ikz) - ! Kernel ghost - 1 with Kj-1 = j/y Kj(careful about the kperp=0) - IF ( be_2 .NE. 0 ) THEN - kernel_e(ijsg_e,ikr,ikz) = (real(ijsg_e,dp))/be_2*kernel_e(ijs_e,ikr,ikz) - ELSE - kernel_e(ijsg_e,ikr,ikz) = 0._dp + REAL(dp) ::kx, ky, sigma, gain + sigma = 0.5_dp + gain = 5e2_dp + + DO ikx=ikxs,ikxe + kx = kxarray(ikx) + DO iky=ikys,ikye + ky = kyarray(iky) + DO iz=izs,ize + DO ip=ips_i,ipe_i + DO ij=ijs_i,ije_i + IF( (iky .NE. iky_0) .AND. (ip .EQ. 1) .AND. (ij .EQ. 1)) THEN + moments_i( ip,ij,ikx,iky,iz, :) = moments_i( ip,ij,ikx,iky,iz, :) & + + gain*sigma/SQRT2 * exp(-(kx**2+ky**2)*sigma**2/4._dp) & + * AA_x(ikx)*AA_y(iky)!& + ! * exp(sigmai2_taui_o2*(kx**2+ky**2)) ENDIF ENDDO - ENDDO - - !!!!! Ion kernels !!!!! - factj = 1.0 ! Start of the recursive factorial - DO ij = 1, jmaxi+1 - j_int = jarray_e(ij) - j_dp = REAL(j_int,dp) ! REAL of degree - - ! Recursive factorial - IF (j_dp .GT. 0) THEN - factj = factj * j_dp - ELSE - factj = 1._dp - ENDIF - - DO ikr = ikrs,ikre - kr = krarray(ikr) - DO ikz = ikzs,ikze - kz = kzarray(ikz) - bi_2 = (kr**2 + kz**2) * sigmai2_taui_o2 - kernel_i(ij, ikr, ikz) = bi_2**j_int * exp(-bi_2)/factj - - ENDDO ENDDO ENDDO - ! Kernels closure - DO ikr = ikrs,ikre - kr = krarray(ikr) - DO ikz = ikzs,ikze - kz = kzarray(ikz) - bi_2 = (kr**2 + kz**2) * sigmai2_taui_o2 - ! Kernel ghost + 1 with Kj+1 = y/(j+1) Kj - kernel_i(ijeg_i,ikr,ikz) = bi_2/(real(ijeg_i-1,dp))*kernel_i(ije_i,ikr,ikz) - ! Kernel ghost - 1 with Kj-1 = j/y Kj(careful about the kperp=0) - IF ( bi_2 .NE. 0 ) THEN - kernel_i(ijsg_i,ikr,ikz) = (real(ijsg_i,dp))/bi_2*kernel_i(ijs_i,ikr,ikz) - ELSE - kernel_i(ijsg_i,ikr,ikz) = 0._dp - ENDIF - ENDDO ENDDO -END SUBROUTINE evaluate_kernels -! !******************************************************************************! -! !!!!!!! Evaluate the kernels once for all -! !******************************************************************************! -! SUBROUTINE evaluate_kernels -! USE basic -! USE array, Only : kernel_e, kernel_i -! USE grid -! use model, ONLY : tau_e, tau_i, sigma_e, sigma_i, q_e, q_i, lambdaD, CLOS -! IMPLICIT NONE -! -! REAL(dp) :: factj, j_dp, j_int -! REAL(dp) :: sigmae2_taue_o2, sigmai2_taui_o2 -! REAL(dp) :: be_2, bi_2, alphaD -! REAL(dp) :: kr, kz, kperp2 -! -! !!!!! Electron kernels !!!!! -! !Precompute species dependant factors -! sigmae2_taue_o2 = sigma_e**2 * tau_e/2._dp ! factor of the Kernel argument -! -! factj = 1.0 ! Start of the recursive factorial -! DO ij = 1, jmaxe+1 -! j_int = jarray_e(ij) -! j_dp = REAL(j_int,dp) ! REAL of degree -! -! ! Recursive factorial -! IF (j_dp .GT. 0) THEN -! factj = factj * j_dp -! ELSE -! factj = 1._dp -! ENDIF -! -! DO ikr = ikrs,ikre -! kr = krarray(ikr) -! DO ikz = ikzs,ikze -! kz = kzarray(ikz) -! -! be_2 = (kr**2 + kz**2) * sigmae2_taue_o2 -! -! kernel_e(ij, ikr, ikz) = be_2**j_int * exp(-be_2)/factj -! -! ENDDO -! ENDDO -! ENDDO -! ! Kernels closure -! DO ikr = ikrs,ikre -! kr = krarray(ikr) -! DO ikz = ikzs,ikze -! kz = kzarray(ikz) -! be_2 = (kr**2 + kz**2) * sigmae2_taue_o2 -! kernel_e(ijeg_e,ikr,ikz) = be_2/(real(ijeg_e,dp))*kernel_e(ije_e,ikr,ikz) -! ENDDO -! ENDDO -! -! !!!!! Ion kernels !!!!! -! sigmai2_taui_o2 = sigma_i**2 * tau_i/2._dp ! (b_a/2)^2 = (kperp sqrt(2 tau_a) sigma_a/2)^2 -! -! factj = 1.0 ! Start of the recursive factorial -! DO ij = 1, jmaxi+1 -! j_int = jarray_e(ij) -! j_dp = REAL(j_int,dp) ! REAL of degree -! -! ! Recursive factorial -! IF (j_dp .GT. 0) THEN -! factj = factj * j_dp -! ELSE -! factj = 1._dp -! ENDIF -! -! DO ikr = ikrs,ikre -! kr = krarray(ikr) -! DO ikz = ikzs,ikze -! kz = kzarray(ikz) -! -! bi_2 = (kr**2 + kz**2) * sigmai2_taui_o2 -! -! kernel_i(ij, ikr, ikz) = bi_2**j_int * exp(-bi_2)/factj -! -! ENDDO -! ENDDO -! ENDDO -! ! Kernels closure -! DO ikr = ikrs,ikre -! kr = krarray(ikr) -! DO ikz = ikzs,ikze -! kz = kzarray(ikz) -! bi_2 = (kr**2 + kz**2) * sigmai2_taui_o2 -! kernel_i(ijeg_i,ikr,ikz) = bi_2/(real(ijeg_i,dp))*kernel_e(ije_i,ikr,ikz) -! ENDDO -! ENDDO -! END SUBROUTINE evaluate_kernels + ENDDO +END SUBROUTINE put_blob !******************************************************************************! diff --git a/src/initial_par_mod.F90 b/src/initial_par_mod.F90 index 1c619aa81ab10c1e414b85a5b053ebe4755603b9..f0b3a7a1f8195a33357fcddd5d3c85e8e5f8fc76 100644 --- a/src/initial_par_mod.F90 +++ b/src/initial_par_mod.F90 @@ -10,6 +10,10 @@ MODULE initial_par ! Initialization through a zonal flow phi INTEGER, PUBLIC, PROTECTED :: INIT_ZF = 0 REAL(DP), PUBLIC, PROTECTED :: ZF_AMP = 1E+3_dp + ! Wipe turbulence in the restart + LOGICAL, PUBLIC, PROTECTED :: WIPE_TURB = .false. + ! Init a Gaussian blob density in the middle + LOGICAL, PUBLIC, PROTECTED :: INIT_BLOB = .false. ! Initial background level REAL(dp), PUBLIC, PROTECTED :: init_background=0._dp ! Initial noise amplitude @@ -39,6 +43,8 @@ CONTAINS NAMELIST /INITIAL_CON/ INIT_NOISY_PHI NAMELIST /INITIAL_CON/ INIT_ZF + NAMELIST /INITIAL_CON/ WIPE_TURB + NAMELIST /INITIAL_CON/ INIT_BLOB NAMELIST /INITIAL_CON/ init_background NAMELIST /INITIAL_CON/ init_noiselvl NAMELIST /INITIAL_CON/ iseed diff --git a/src/lin_coeff_and_geometry.F90 b/src/lin_coeff_and_geometry.F90 index 110208ab1f73e02633379bc8625e112c21ead61a..f2736623f03389363fe70c93f897242bba01a66d 100644 --- a/src/lin_coeff_and_geometry.F90 +++ b/src/lin_coeff_and_geometry.F90 @@ -5,7 +5,7 @@ SUBROUTINE lin_coeff_and_geometry USE model, ONLY: taue_qe, taui_qi, sqrtTaue_qe, sqrtTaui_qi, eta_T, eta_n USE prec_const USE grid, ONLY: parray_e, parray_i, jarray_e, jarray_i, & - ip,ij, ips_e,ip_e, ips_i,ipe_i, ijs_e,ije_e, ijs_i,ije_i,& + ip,ij, ips_e,ipe_e, ips_i,ipe_i, ijs_e,ije_e, ijs_i,ije_i,& kxarray, kyarray, zarray, & ikx,iky,iz, ikxs,ikxe, ikys,ikye, izs,ize IMPLICIT NONE @@ -34,8 +34,8 @@ SUBROUTINE lin_coeff_and_geometry DO ij = ijs_e, ije_e j_int= jarray_e(ij) ! Laguerre degree j_dp = REAL(j_int,dp) ! REAL of Laguerre degree - xnepjp1(ij) = -taui_qi * (j_dp + 1._dp) - xnepjm1(ij) = -taui_qi * j_dp + xnepjp1(ij) = -taue_qe * (j_dp + 1._dp) + xnepjm1(ij) = -taue_qe * j_dp ENDDO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! Ions linear coefficients for moment RHS !!!!!!!!!! @@ -72,10 +72,10 @@ SUBROUTINE lin_coeff_and_geometry !! Electrostatic potential pj terms IF (p_int .EQ. 0) THEN ! kronecker p0 xphij(ip,ij) = eta_n + 2.*j_dp*eta_T - xphijp1(ip,ij) = eta_T*(j_dp+1._dp) - xphijm1(ip,ij) = eta_T* j_dp + xphijp1(ip,ij) =-eta_T*(j_dp+1._dp) + xphijm1(ip,ij) =-eta_T* j_dp ELSE IF (p_int .EQ. 2) THEN ! kronecker p2 - xphij(ip,ij) =-eta_T/SQRT2 + xphij(ip,ij) = eta_T/SQRT2 xphijp1(ip,ij) = 0._dp; xphijm1(ip,ij) = 0._dp; ELSE xphij(ip,ij) = 0._dp; xphijp1(ip,ij) = 0._dp diff --git a/src/memory.F90 b/src/memory.F90 index 4458499ae84c035cc5dda387d77f93683fda2c7f..6c5f3fe1051209ef813f9b4d082a02426fa2d4dc 100644 --- a/src/memory.F90 +++ b/src/memory.F90 @@ -12,43 +12,68 @@ SUBROUTINE memory IMPLICIT NONE !___________________ 2D ARRAYS __________________________ ! Electrostatic potential - CALL allocate_array(phi, ikrs,ikre, ikzs,ikze) + CALL allocate_array(phi, ikxs,ikxe, ikys,ikye, izs,ize) !! Diagnostics arrays ! Gyrocenter density *for 2D output* - CALL allocate_array(Ne00, ikrs,ikre, ikzs,ikze) - CALL allocate_array(Ni00, ikrs,ikre, ikzs,ikze) + CALL allocate_array(Ne00, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array(Ni00, ikxs,ikxe, ikys,ikye, izs,ize) ! particle density *for 2D output* - CALL allocate_array(dens_e, ikrs,ikre, ikzs,ikze) - CALL allocate_array(dens_i, ikrs,ikre, ikzs,ikze) + CALL allocate_array(dens_e, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array(dens_i, ikxs,ikxe, ikys,ikye, izs,ize) ! particle temperature *for 2D output* - CALL allocate_array(temp_e, ikrs,ikre, ikzs,ikze) - CALL allocate_array(temp_i, ikrs,ikre, ikzs,ikze) + CALL allocate_array(temp_e, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array(temp_i, ikxs,ikxe, ikys,ikye, izs,ize) !___________________ 3D ARRAYS __________________________ !! FLR kernels functions ! Kernel evaluation from j= -1 to jmax+1 for truncation - CALL allocate_array(Kernel_e, ijsg_e,ijeg_e, ikrs,ikre, ikzs,ikze) - CALL allocate_array(Kernel_i, ijsg_i,ijeg_i, ikrs,ikre, ikzs,ikze) + CALL allocate_array(Kernel_e, ijsg_e,ijeg_e, ikxs,ikxe, ikys,ikye) + CALL allocate_array(Kernel_i, ijsg_i,ijeg_i, ikxs,ikxe, ikys,ikye) !___________________ 5D ARRAYS __________________________ ! Moments with ghost degrees for p+2 p-2, j+1, j-1 truncations - CALL allocate_array( moments_e, ipsg_e,ipeg_e, ijsg_e,ijeg_e, ikrs,ikre, ikzs,ikze, 1,ntimelevel ) - CALL allocate_array( moments_i, ipsg_i,ipeg_i, ijsg_i,ijeg_i, ikrs,ikre, ikzs,ikze, 1,ntimelevel ) + CALL allocate_array( moments_e, ipsg_e,ipeg_e, ijsg_e,ijeg_e, ikxs,ikxe, ikys,ikye, izs,ize, 1,ntimelevel ) + CALL allocate_array( moments_i, ipsg_i,ipeg_i, ijsg_i,ijeg_i, ikxs,ikxe, ikys,ikye, izs,ize, 1,ntimelevel ) ! Moments right-hand-side (contains linear part of hierarchy) - CALL allocate_array( moments_rhs_e, ips_e,ipe_e, ijs_e,ije_e, ikrs,ikre, ikzs,ikze, 1,ntimelevel ) - CALL allocate_array( moments_rhs_i, ips_i,ipe_i, ijs_i,ije_i, ikrs,ikre, ikzs,ikze, 1,ntimelevel ) + CALL allocate_array( moments_rhs_e, ips_e,ipe_e, ijs_e,ije_e, ikxs,ikxe, ikys,ikye, izs,ize, 1,ntimelevel ) + CALL allocate_array( moments_rhs_i, ips_i,ipe_i, ijs_i,ije_i, ikxs,ikxe, ikys,ikye, izs,ize, 1,ntimelevel ) ! Collision term - CALL allocate_array( TColl_e, ips_e,ipe_e, ijs_e,ije_e , ikrs,ikre, ikzs,ikze) - CALL allocate_array( TColl_i, ips_i,ipe_i, ijs_i,ije_i , ikrs,ikre, ikzs,ikze) + CALL allocate_array( TColl_e, ips_e,ipe_e, ijs_e,ije_e , ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array( TColl_i, ips_i,ipe_i, ijs_i,ije_i , ikxs,ikxe, ikys,ikye, izs,ize) ! Non linear terms and dnjs table - CALL allocate_array( Sepj, ips_e,ipe_e, ijs_e,ije_e, ikrs,ikre, ikzs,ikze ) - CALL allocate_array( Sipj, ips_i,ipe_i, ijs_i,ije_i, ikrs,ikre, ikzs,ikze ) + CALL allocate_array( Sepj, ips_e,ipe_e, ijs_e,ije_e, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array( Sipj, ips_i,ipe_i, ijs_i,ije_i, ikxs,ikxe, ikys,ikye, izs,ize) CALL allocate_array( dnjs, 1,maxj+1, 1,maxj+1, 1,maxj+1) + ! Linear coeff for moments rhs + ! electrons + CALL allocate_array( xnepj, ips_e,ipe_e, ijs_e,ije_e) + CALL allocate_array( xnepp2j, ips_e,ipe_e) + CALL allocate_array( xnepp1j, ips_e,ipe_e) + CALL allocate_array( xnepm1j, ips_e,ipe_e) + CALL allocate_array( xnepm2j, ips_e,ipe_e) + CALL allocate_array( xnepjp1, ijs_e,ije_e) + CALL allocate_array( xnepjm1, ijs_e,ije_e) + ! ions + CALL allocate_array( xnipj, ips_i,ipe_i, ijs_i,ije_i) + CALL allocate_array( xnipp2j, ips_i,ipe_i) + CALL allocate_array( xnipp1j, ips_i,ipe_i) + CALL allocate_array( xnipm1j, ips_i,ipe_i) + CALL allocate_array( xnipm2j, ips_i,ipe_i) + CALL allocate_array( xnipjp1, ijs_i,ije_i) + CALL allocate_array( xnipjm1, ijs_i,ije_i) + ! elect. pot. + CALL allocate_array( xphij, ips_i,ipe_i, ijs_i,ije_i) + CALL allocate_array( xphijp1, ips_i,ipe_i, ijs_i,ije_i) + CALL allocate_array( xphijm1, ips_i,ipe_i, ijs_i,ije_i) + + ! Curvature and geometry + CALL allocate_array( Ckxky, ikxs,ikxe, ikys,ikye, izs,ize) + !___________________ 2x5D ARRAYS __________________________ !! Collision matrices IF (CO .LT. -1) THEN !DK collision matrix (same for every k) @@ -59,12 +84,12 @@ SUBROUTINE memory CALL allocate_array( CiepjT, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), 1,1, 1,1) CALL allocate_array( CiepjF, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxe+1)*(jmaxe+1), 1,1, 1,1) ELSEIF (CO .GT. 1) THEN !GK collision matrices (one for each kperp) - CALL allocate_array( Ceepj, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikrs,ikre, ikzs,ikze) - CALL allocate_array( CeipjT, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikrs,ikre, ikzs,ikze) - CALL allocate_array( CeipjF, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxi+1)*(jmaxi+1), ikrs,ikre, ikzs,ikze) - CALL allocate_array( Ciipj, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), ikrs,ikre, ikzs,ikze) - CALL allocate_array( CiepjT, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), ikrs,ikre, ikzs,ikze) - CALL allocate_array( CiepjF, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxe+1)*(jmaxe+1), ikrs,ikre, ikzs,ikze) + CALL allocate_array( Ceepj, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikxs,ikxe, ikys,ikye) + CALL allocate_array( CeipjT, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikxs,ikxe, ikys,ikye) + CALL allocate_array( CeipjF, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxi+1)*(jmaxi+1), ikxs,ikxe, ikys,ikye) + CALL allocate_array( Ciipj, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), ikxs,ikxe, ikys,ikye) + CALL allocate_array( CiepjT, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), ikxs,ikxe, ikys,ikye) + CALL allocate_array( CiepjF, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxe+1)*(jmaxe+1), ikxs,ikxe, ikys,ikye) ENDIF END SUBROUTINE memory diff --git a/src/model_mod.F90 b/src/model_mod.F90 index f06cf81828b15d97eb1d8079c2920dfc22786776..7ea6600d649955c35a3886e1075cc9a61381fe33 100644 --- a/src/model_mod.F90 +++ b/src/model_mod.F90 @@ -25,8 +25,10 @@ MODULE model REAL(dp), PUBLIC, PROTECTED :: eta_B = 1._dp ! Magnetic gradient REAL(dp), PUBLIC, PROTECTED :: lambdaD = 1._dp ! Debye length - REAL(dp), PUBLIC, PROTECTED :: taue_qe_etaB ! factor of the magnetic moment coupling - REAL(dp), PUBLIC, PROTECTED :: taui_qi_etaB ! + REAL(dp), PUBLIC, PROTECTED :: taue_qe ! factor of the magnetic moment coupling + REAL(dp), PUBLIC, PROTECTED :: taui_qi ! + REAL(dp), PUBLIC, PROTECTED :: qi_taui ! + REAL(dp), PUBLIC, PROTECTED :: qe_taue ! REAL(dp), PUBLIC, PROTECTED :: sqrtTaue_qe ! factor of parallel moment term REAL(dp), PUBLIC, PROTECTED :: sqrtTaui_qi ! REAL(dp), PUBLIC, PROTECTED :: qe_sigmae_sqrtTaue ! factor of parallel phi term @@ -54,16 +56,11 @@ CONTAINS READ(lu_in,model_par) - !Precompute species dependant factors - IF( q_e .NE. 0._dp ) THEN - taue_qe_etaB = tau_e/q_e * eta_B ! factor of the magnetic moment coupling - sqrtTaue_qe = sqrt(tau_e)/q_e ! factor of parallel moment term - ELSE - taue_qe_etaB = 0._dp - sqrtTaue_qe = 0._dp - ENDIF - - taui_qi_etaB = tau_i/q_i * eta_B ! factor of the magnetic moment coupling + taue_qe = tau_e/q_e ! factor of the magnetic moment coupling + taui_qi = tau_i/q_i ! factor of the magnetic moment coupling + qe_taue = q_e/tau_e + qi_taui = q_i/tau_i + sqrtTaue_qe = sqrt(tau_e)/q_e ! factor of parallel moment term sqrtTaui_qi = sqrt(tau_i)/q_i ! factor of parallel moment term qe_sigmae_sqrtTaue = q_e/sigma_e/SQRT(tau_e) ! factor of parallel phi term qi_sigmai_sqrtTaui = q_i/sigma_i/SQRT(tau_i) @@ -79,7 +76,6 @@ CONTAINS nu_ee = nu_e ! e-e coll. frequ. nu_ie = nu_i ! i-e coll. frequ. - ! Old normalization (MOLI Jorge/Frei) ! nu_e = 0.532_dp*nu ! electron-ion collision frequency (where already multiplied by 0.532) ! nu_i = 0.532_dp*nu*sigma_e*tau_e**(-3._dp/2._dp)/SQRT2 ! ion-ion collision frequ. diff --git a/src/moments_eq_rhs.F90 b/src/moments_eq_rhs.F90 index d56a0bfeff849ff9878843f018c8d7fbb38a195c..9d41db7373690bcc17888794fbb476e986321cf7 100644 --- a/src/moments_eq_rhs.F90 +++ b/src/moments_eq_rhs.F90 @@ -13,168 +13,104 @@ SUBROUTINE moments_eq_rhs_e USE grid USE model USE prec_const - USE utility, ONLY : is_nan USE collision IMPLICIT NONE - INTEGER :: ip2, ij2, il, p_int, j_int, p2_int, j2_int ! loops indices and polynom. degrees - REAL(dp) :: p_dp, j_dp, l_dp - REAL(dp) :: kr, kz, kperp2 - REAL(dp) :: kernelj, kerneljp1, kerneljm1 ! Kernel functions and variable - REAL(dp) :: xNapj, xNapp1j, xNapm1j, xNapp2j, xNapm2j, xNapjp1, xNapjm1 ! Mom. factors depending on the pj loop - REAL(dp) :: xphij, xphijp1, xphijm1, xphijpar ! ESpot. factors depending on the pj loop - REAL(dp) :: xCapj, xCa20, xCa01, xCa10 ! Coll. factors depending on the pj loop - COMPLEX(dp) :: TNapj, TNapp1j, TNapm1j, TNapp2j, TNapm2j, TNapjp1, TNapjm1, Tphi - COMPLEX(dp) :: TColl, TColl20, TColl01, TColl10 ! terms of the rhs - COMPLEX(dp) :: i_kz, Hyper_diff_p, Hyper_diff_j + INTEGER :: p_int, j_int ! loops indices and polynom. degrees + REAL(dp) :: kx, ky, kperp2 + COMPLEX(dp) :: Tnepj, Tnepp2j, Tnepm2j, Tnepjp1, Tnepjm1, Tpare, Tphi + COMPLEX(dp) :: TColl ! terms of the rhs + COMPLEX(dp) :: i_ky + REAL(dp) :: delta_p0, delta_p1, delta_p2 + INTEGER :: izprev,iznext ! indices of previous and next z slice - ! Measuring execution time + ! Measuring execution time CALL cpu_time(t0_rhs) ploope : DO ip = ips_e, ipe_e ! loop over Hermite degree indices p_int= parray_e(ip) ! Hermite polynom. degree - p_dp = REAL(p_int,dp) ! REAL of the Hermite degree - - ! N_e^{p+1,j} coeff - xNapp1j = sqrtTaue_qe * SQRT(p_dp + 1) - ! N_e^{p-1,j} coeff - xNapm1j = sqrtTaue_qe * SQRT(p_dp) - ! N_e^{p+2,j} coeff - xNapp2j = taue_qe_etaB * SQRT((p_dp + 1._dp) * (p_dp + 2._dp)) - ! N_e^{p-2,j} coeff - xNapm2j = taue_qe_etaB * SQRT(p_dp * (p_dp - 1._dp)) + delta_p0 = 0._dp; delta_p1 = 0._dp; delta_p2 = 0._dp + IF(p_int .EQ. 0) delta_p0 = 1._dp + IF(p_int .EQ. 1) delta_p1 = 1._dp + IF(p_int .EQ. 2) delta_p2 = 1._dp jloope : DO ij = ijs_e, ije_e ! loop over Laguerre degree indices - j_int= jarray_e(ij) ! Laguerre polynom. degree - j_dp = REAL(j_int,dp) ! REAL of degree - - ! N_e^{p,j+1} coeff - xNapjp1 = -taue_qe_etaB * (j_dp + 1._dp) - ! N_e^{p,j-1} coeff - xNapjm1 = -taue_qe_etaB * j_dp - ! N_e^{pj} coeff - xNapj = taue_qe_etaB * 2._dp*(p_dp + j_dp + 1._dp) - - !! Collision operator pj terms - xCapj = -nu_ee*(p_dp + 2._dp*j_dp) !DK Lenard-Bernstein basis - ! Dougherty part - IF ( CO .EQ. -2) THEN - IF ((p_int .EQ. 2) .AND. (j_int .EQ. 0)) THEN ! kronecker pj20 - xCa20 = nu_ee * 2._dp/3._dp - xCa01 = -SQRT2 * xCa20 - xCa10 = 0._dp - ELSEIF ((p_int .EQ. 0) .AND. (j_int .EQ. 1)) THEN ! kronecker pj01 - xCa20 = -nu_ee * SQRT2 * 2._dp/3._dp - xCa01 = -SQRT2 * xCa20 - xCa10 = 0._dp - ELSEIF ((p_int .EQ. 1) .AND. (j_int .EQ. 0)) THEN ! kronecker pj10 - xCa20 = 0._dp - xCa01 = 0._dp - xCa10 = nu_ee - ELSE - xCa20 = 0._dp; xCa01 = 0._dp; xCa10 = 0._dp - ENDIF - ENDIF - - !! Electrostatic potential pj terms - IF (p_int .EQ. 0) THEN ! kronecker p0 - xphij = (eta_n + 2.*j_dp*eta_T - 2._dp*eta_B*(j_dp+1._dp) ) - xphijp1 = -(eta_T - eta_B)*(j_dp+1._dp) - xphijm1 = -(eta_T - eta_B)* j_dp - xphijpar= 0._dp - ELSE IF (p_int .EQ. 1) THEN ! kronecker p1 - xphijpar = qe_sigmae_sqrtTaue - xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp - ELSE IF (p_int .EQ. 2) THEN ! kronecker p2 - xphij = (eta_T/SQRT2 - SQRT2*eta_B) - xphijp1 = 0._dp; xphijm1 = 0._dp; xphijpar= 0._dp - ELSE - xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp; xphijpar= 0._dp - ENDIF - ! Loop on kspace - krloope : DO ikr = ikrs,ikre - kzloope : DO ikz = ikzs,ikze - kr = krarray(ikr) ! Poloidal wavevector - kz = kzarray(ikz) ! Toroidal wavevector - i_kz = imagu * kz ! Ddz derivative - IF (Nkz .EQ. 1) i_kz = imagu * krarray(ikr) ! If 1D simulation we put kr as kz - kperp2 = kr**2 + kz**2 ! perpendicular wavevector + zloope : DO iz = izs,ize + ! Periodic BC for first order derivative + iznext = iz+1; izprev = iz-1; + IF(iz .EQ. 1) izprev = Nz + IF(iz .EQ. Nz) iznext = 1 + + kxloope : DO ikx = ikxs,ikxe + kx = kxarray(ikx) ! radial wavevector + kyloope : DO iky = ikys,ikye + ky = kyarray(iky) ! toroidal wavevector + i_ky = imagu * ky ! toroidal derivative + IF (Nky .EQ. 1) i_ky = imagu * kxarray(ikx) ! If 1D simulation we put kx as ky + kperp2 = kx**2 + ky**2 ! perpendicular wavevector !! Compute moments mixing terms - ! term propto N_e^{p,j} - TNapj = xNapj * moments_e(ip,ij,ikr,ikz,updatetlevel) - ! term propto N_e^{p+2,j} - TNapp2j = xNapp2j * moments_e(ip+2,ij,ikr,ikz,updatetlevel) - ! term propto N_e^{p-2,j} - TNapm2j = xNapm2j * moments_e(ip-2,ij,ikr,ikz,updatetlevel) - ! term propto N_e^{p,j+1} - TNapjp1 = xNapjp1 * moments_e(ip,ij+1,ikr,ikz,updatetlevel) - ! term propto N_e^{p,j-1} - TNapjm1 = xNapjm1 * moments_e(ip,ij-1,ikr,ikz,updatetlevel) - - !! Collision - IF (CO .EQ. 0) THEN ! Lenard Bernstein - TColl = xCapj * moments_e(ip,ij,ikr,ikz,updatetlevel) - - ELSEIF (CO .EQ. -1) THEN ! DK Dougherty - TColl20 = 0._dp; TColl01 = 0._dp; TColl10 = 0._dp - IF ( (pmaxe .GE. 2) ) TColl20 = xCa20 * moments_e(3,1,ikr,ikz,updatetlevel) - IF ( (jmaxe .GE. 1) ) TColl01 = xCa01 * moments_e(1,2,ikr,ikz,updatetlevel) - IF ( (pmaxe .GE. 1) ) TColl10 = xCa10 * moments_e(2,1,ikr,ikz,updatetlevel) - ! Total collisional term - TColl = xCapj* moments_e(ip,ij,ikr,ikz,updatetlevel)& - + TColl20 + TColl01 + TColl10 - - ELSEIF (CO .EQ. 1) THEN ! GK Dougherty - CALL DoughertyGK_e(ip,ij,ikr,ikz,TColl) - ! CALL DoughertyGK(ip,ij,ikr,ikz,TColl,'e') - - ELSE ! COSOLver matrix - TColl = TColl_e(ip,ij,ikr,ikz) - ENDIF + ! Perpendicular dynamic + ! term propto n_e^{p,j} + Tnepj = xnepj(ip,ij) * (moments_e(ip,ij,ikx,iky,iz,updatetlevel) & + +kernel_e(ij,ikx,iky)*qe_taue*phi(ikx,iky,iz)*delta_p0) + ! term propto n_e^{p+2,j} + Tnepp2j = xnepp2j(ip) * moments_e(ip+2,ij,ikx,iky,iz,updatetlevel) + ! term propto n_e^{p-2,j} + Tnepm2j = xnepm2j(ip) * (moments_e(ip-2,ij,ikx,iky,iz,updatetlevel) & + +kernel_e(ij,ikx,iky)*qe_taue*phi(ikx,iky,iz)*delta_p2) + ! term propto n_e^{p,j+1} + Tnepjp1 = xnepjp1(ij) * (moments_e(ip,ij+1,ikx,iky,iz,updatetlevel) & + +kernel_e(ij+1,ikx,iky)*qe_taue*phi(ikx,iky,iz)*delta_p0) + ! term propto n_e^{p,j-1} + Tnepjm1 = xnepjm1(ij) * (moments_e(ip,ij-1,ikx,iky,iz,updatetlevel) & + +kernel_e(ij-1,ikx,iky)*qe_taue*phi(ikx,iky,iz)*delta_p0) + ! Parallel dynamic + ! term propto n_i^{p+1,j}, centered FDF + Tpare = xnepp1j(ip) * & + (moments_e(ip+1,ij,ikx,iky,iznext,updatetlevel)& + -moments_e(ip+1,ij,ikx,iky,izprev,updatetlevel)) & + +xnepm1j(ip) * & + (moments_e(ip-1,ij,ikx,iky,iznext,updatetlevel)+kernel_e(ij,ikx,iky)*qe_taue*phi(ikx,iky,iznext)*delta_p1& + -moments_e(ip-1,ij,ikx,iky,izprev,updatetlevel)-kernel_e(ij,ikx,iky)*qe_taue*phi(ikx,iky,izprev)*delta_p1) !! Electrical potential term IF ( p_int .LE. 2 ) THEN ! kronecker p0 p1 p2 - Tphi = phi(ikr,ikz) * (xphij*kernel_e(ij, ikr, ikz) & - + xphijp1*kernel_e(ij+1, ikr, ikz) & - + xphijm1*kernel_e(ij-1, ikr, ikz) ) + Tphi = phi(ikx,iky,iz) * (xphij(ip,ij)*kernel_e(ij, ikx, iky) & + + xphijp1(ip,ij)*kernel_e(ij+1, ikx, iky) & + + xphijm1(ip,ij)*kernel_e(ij-1, ikx, iky) ) ELSE Tphi = 0._dp ENDIF - !! Parallel kinetic hyperdiffusion (projection of d/dv^4 f on Hermite basis) - Hyper_diff_p = 0._dp - IF ( p_int .GE. 4 ) THEN - Hyper_diff_p = 4._dp*SQRT(p_dp*(p_dp-1._dp)*(p_dp-2._dp)*(p_dp-3._dp)*(p_dp-4._dp))& - *moments_e(ip-4,ij,ikr,ikz,updatetlevel) - ENDIF - - !! Perpendicular kinetic hyperdiffusion (projection of d/dv^4 f on Laguerre basis) - Hyper_diff_j = 0._dp - IF ( j_int .GE. 4 ) THEN - DO il = 1,(ij-4) - l_dp = real(il-1,dp) - Hyper_diff_j = Hyper_diff_j + (j_dp-(l_dp+1_dp))*moments_e(ip,il,ikr,ikz,updatetlevel) - ENDDO + !! Collision + IF (CO .EQ. 0) THEN ! Lenhard Bernstein + TColl = -nu_ee*(ip+2*ij-3)*moments_e(ip,ij,ikx,iky,iz,updatetlevel) + ELSEIF (CO .EQ. 1) THEN ! GK Dougherty + CALL DoughertyGK_e(ip,ij,ikx,iky,iz,TColl) + ELSE ! COSOLver matrix + TColl = TColl_e(ip,ij,ikx,iky,iz) ENDIF - !! Sum of all linear terms - moments_rhs_e(ip,ij,ikr,ikz,updatetlevel) = & - - INV_LIN_SYS * i_kz * (TNapj + TNapp2j + TNapm2j + TNapjp1 + TNapjm1 - Tphi)& - - mu*kperp2**2 * moments_e(ip,ij,ikr,ikz,updatetlevel) & - + mu_p * Hyper_diff_p + mu_j * Hyper_diff_j & - + INV_LIN_SYS * TColl + !! Sum of all linear terms (the sign is inverted to match RHS) + moments_rhs_e(ip,ij,ikx,iky,iz,updatetlevel) = & + - Ckxky(ikx,iky,iz) * (Tnepj + Tnepp2j + Tnepm2j + Tnepjp1 + Tnepjm1)& + - Tpare/2._dp/deltaz/q0 & + + i_ky * Tphi & + - mu*kperp2**2 * moments_e(ip,ij,ikx,iky,iz,updatetlevel) & + + TColl !! Adding non linearity IF ( NON_LIN ) THEN - moments_rhs_e(ip,ij,ikr,ikz,updatetlevel) = & - moments_rhs_e(ip,ij,ikr,ikz,updatetlevel) + Sepj(ip,ij,ikr,ikz) + moments_rhs_e(ip,ij,ikx,iky,iz,updatetlevel) = & + moments_rhs_e(ip,ij,ikx,iky,iz,updatetlevel) + Sepj(ip,ij,ikx,iky,iz) ENDIF - END DO kzloope - END DO krloope + END DO kyloope + END DO kxloope + END DO zloope END DO jloope END DO ploope @@ -199,167 +135,104 @@ SUBROUTINE moments_eq_rhs_i USE grid USE model USE prec_const - USE utility, ONLY : is_nan USE collision IMPLICIT NONE - INTEGER :: ip2, ij2, il, p_int, j_int, p2_int, j2_int ! loops indices and polynom. degrees - REAL(dp) :: p_dp, j_dp, l_dp - REAL(dp) :: kr, kz, kperp2 - REAL(dp) :: kernelj, kerneljp1, kerneljm1 ! Kernel functions and variable - REAL(dp) :: xNapj, xNapp1j, xNapm1j, xNapp2j, xNapm2j, xNapjp1, xNapjm1 ! Mom. factors depending on the pj loop - REAL(dp) :: xphij, xphijp1, xphijm1, xphijpar ! ESpot. factors depending on the pj loop - REAL(dp) :: xCapj, xCa20, xCa01, xCa10 ! Coll. factors depending on the pj loop - COMPLEX(dp) :: TNapj, TNapp1j, TNapm1j, TNapp2j, TNapm2j, TNapjp1, TNapjm1, Tphi - COMPLEX(dp) :: TColl, TColl20, TColl01, TColl10 ! terms of the rhs - COMPLEX(dp) :: i_kz, Hyper_diff_p, Hyper_diff_j - - LOGICAL :: COPY_CLOS = .false. ! To test closures - ! LOGICAL :: COPY_CLOS = .true. ! To test closures + INTEGER :: p_int, j_int ! loops indices and polynom. degrees + REAL(dp) :: kx, ky, kperp2 + COMPLEX(dp) :: Tnipj, Tnipp2j, Tnipm2j, Tnipjp1, Tnipjm1, Tpari, Tphi + COMPLEX(dp) :: TColl ! terms of the rhs + COMPLEX(dp) :: i_ky + REAL(dp) :: delta_p0, delta_p1, delta_p2 + INTEGER :: izprev,iznext ! indices of previous and next z slice ! Measuring execution time CALL cpu_time(t0_rhs) ploopi : DO ip = ips_i, ipe_i ! Hermite loop p_int= parray_i(ip) ! Hermite degree - p_dp = REAL(p_int,dp) ! REAL of Hermite degree - ! N_i^{p+1,j} coeff - xNapp1j = sqrtTaui_qi * SQRT(p_dp + 1) - ! N_i^{p-1,j} coeff - xNapm1j = sqrtTaui_qi * SQRT(p_dp) - ! x N_i^{p+2,j} coeff - xNapp2j = taui_qi_etaB * SQRT((p_dp + 1._dp) * (p_dp + 2._dp)) - ! x N_i^{p-2,j} coeff - xNapm2j = taui_qi_etaB * SQRT(p_dp * (p_dp - 1._dp)) + delta_p0 = 0._dp; delta_p1 = 0._dp; delta_p2 = 0._dp + IF(p_int .EQ. 0) delta_p0 = 1._dp + IF(p_int .EQ. 1) delta_p1 = 1._dp + IF(p_int .EQ. 2) delta_p2 = 1._dp jloopi : DO ij = ijs_i, ije_i ! This loop is from 1 to jmaxi+1 - j_int= jarray_i(ij) ! REALof Laguerre degree - j_dp = REAL(j_int,dp) ! REALof Laguerre degree - - ! x N_i^{p,j+1} coeff - xNapjp1 = -taui_qi_etaB * (j_dp + 1._dp) - ! x N_i^{p,j-1} coeff - xNapjm1 = -taui_qi_etaB * j_dp - ! x N_i^{pj} coeff - xNapj = taui_qi_etaB * 2._dp*(p_dp + j_dp + 1._dp) - - !! Collision operator pj terms - xCapj = -nu_i*(p_dp + 2._dp*j_dp) !DK Lenard-Bernstein basis - ! Dougherty part - IF ( CO .EQ. -2) THEN - IF ((p_int .EQ. 2) .AND. (j_int .EQ. 0)) THEN ! kronecker pj20 - xCa20 = nu_i * 2._dp/3._dp - xCa01 = -SQRT2 * xCa20 - xCa10 = 0._dp - ELSEIF ((p_int .EQ. 0) .AND. (j_int .EQ. 1)) THEN ! kronecker pj01 - xCa20 = -nu_i * SQRT2 * 2._dp/3._dp - xCa01 = -SQRT2 * xCa20 - xCa10 = 0._dp - ELSEIF ((p_int .EQ. 1) .AND. (j_int .EQ. 0)) THEN ! kronecker pj10 - xCa20 = 0._dp - xCa01 = 0._dp - xCa10 = nu_i - ELSE - xCa20 = 0._dp; xCa01 = 0._dp; xCa10 = 0._dp - ENDIF - ENDIF - - !! Electrostatic potential pj terms - IF (p_int .EQ. 0) THEN ! krokecker p0 - xphij = (eta_n + 2._dp*j_dp*eta_T - 2._dp*eta_B*(j_dp+1._dp)) - xphijp1 = -(eta_T - eta_B)*(j_dp+1._dp) - xphijm1 = -(eta_T - eta_B)* j_dp - xphijpar = 0._dp - ELSE IF (p_int .EQ. 1) THEN ! kronecker p1 - xphijpar = qi_sigmai_sqrtTaui - xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp - ELSE IF (p_int .EQ. 2) THEN !krokecker p2 - xphij = (eta_T/SQRT2 - SQRT2*eta_B) - xphijp1 = 0._dp; xphijm1 = 0._dp; xphijpar = 0._dp - ELSE - xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp; xphijpar = 0._dp - ENDIF - ! Loop on kspace - krloopi : DO ikr = ikrs,ikre - kzloopi : DO ikz = ikzs,ikze - kr = krarray(ikr) ! Poloidal wavevector - kz = kzarray(ikz) ! Toroidal wavevector - i_kz = imagu * kz ! Ddz derivative - IF (Nkz .EQ. 1) i_kz = imagu * krarray(ikr) ! If 1D simulation we put kr as kz - kperp2 = kr**2 + kz**2 ! perpendicular wavevector + zloopi : DO iz = izs,ize + ! Periodic BC for first order derivative + iznext = iz+1; izprev = iz-1; + IF(iz .EQ. 1) izprev = Nz + IF(iz .EQ. Nz) iznext = 1 + + kxloopi : DO ikx = ikxs,ikxe + kx = kxarray(ikx) ! radial wavevector + kyloopi : DO iky = ikys,ikye + ky = kyarray(iky) ! toroidal wavevector + i_ky = imagu * ky ! toroidal derivative + IF (Nky .EQ. 1) i_ky = imagu * kxarray(ikx) ! If 1D simulation we put kx as ky + kperp2 = kx**2 + ky**2 ! perpendicular wavevector !! Compute moments mixing terms - ! term propto N_i^{p,j} - TNapj = xNapj * moments_i(ip,ij,ikr,ikz,updatetlevel) - ! term propto N_i^{p+2,j} - TNapp2j = xNapp2j * moments_i(ip+2,ij,ikr,ikz,updatetlevel) - ! term propto N_i^{p-2,j} - TNapm2j = xNapm2j * moments_i(ip-2,ij,ikr,ikz,updatetlevel) - ! term propto N_i^{p,j+1} - TNapjp1 = xNapjp1 * moments_i(ip,ij+1,ikr,ikz,updatetlevel) - ! term propto N_i^{p,j-1} - TNapjm1 = xNapjm1 * moments_i(ip,ij-1,ikr,ikz,updatetlevel) - - !! Collision - IF (CO .EQ. 0) THEN ! Lenard Bernstein - TColl = xCapj * moments_i(ip,ij,ikr,ikz,updatetlevel) - - ELSEIF (CO .EQ. -1) THEN ! DK Dougherty - TColl20 = 0._dp; TColl01 = 0._dp; TColl10 = 0._dp - IF ( (pmaxi .GE. 2) ) TColl20 = xCa20 * moments_i(3,1,ikr,ikz,updatetlevel) - IF ( (jmaxi .GE. 1) ) TColl01 = xCa01 * moments_i(1,2,ikr,ikz,updatetlevel) - IF ( (pmaxi .GE. 1) ) TColl10 = xCa10 * moments_i(2,1,ikr,ikz,updatetlevel) - ! Total collisional term - TColl = xCapj* moments_i(ip,ij,ikr,ikz,updatetlevel)& - + TColl20 + TColl01 + TColl10 - - ELSEIF (CO .EQ. 1) THEN ! GK Dougherty - CALL DoughertyGK_i(ip,ij,ikr,ikz,TColl) - ! CALL DoughertyGK(ip,ij,ikr,ikz,TColl,'i') - ELSE! COSOLver matrix (Sugama, Coulomb) - TColl = TColl_i(ip,ij,ikr,ikz) - ENDIF + ! Perpendicular dynamic + ! term propto n_i^{p,j} + Tnipj = xnipj(ip,ij) * (moments_i(ip,ij,ikx,iky,iz,updatetlevel) & + +kernel_i(ij,ikx,iky)*qi_taui*phi(ikx,iky,iz)*delta_p0) + ! term propto n_i^{p+2,j} + Tnipp2j = xnipp2j(ip) * moments_i(ip+2,ij,ikx,iky,iz,updatetlevel) + ! term propto n_i^{p-2,j} + Tnipm2j = xnipm2j(ip) * (moments_i(ip-2,ij,ikx,iky,iz,updatetlevel) & + +kernel_i(ij,ikx,iky)*qi_taui*phi(ikx,iky,iz)*delta_p2) + ! term propto n_e^{p,j+1} + Tnipjp1 = xnipjp1(ij) * (moments_i(ip,ij+1,ikx,iky,iz,updatetlevel) & + +kernel_i(ij+1,ikx,iky)*qi_taui*phi(ikx,iky,iz)*delta_p0) + ! term propto n_e^{p,j-1} + Tnipjm1 = xnipjm1(ij) * (moments_i(ip,ij-1,ikx,iky,iz,updatetlevel) & + +kernel_i(ij-1,ikx,iky)*qi_taui*phi(ikx,iky,iz)*delta_p0) + ! Parallel dynamic + ! term propto N_i^{p,j+1}, centered FDF + Tpari = xnipp1j(ip) * & + (moments_i(ip+1,ij,ikx,iky,iznext,updatetlevel)& + -moments_i(ip+1,ij,ikx,iky,izprev,updatetlevel)) & + +xnipm1j(ip) * & + (moments_i(ip-1,ij,ikx,iky,iznext,updatetlevel)+qi_taui*kernel_i(ij,ikx,iky)*phi(ikx,iky,iznext)*delta_p1& + -moments_i(ip-1,ij,ikx,iky,izprev,updatetlevel)-qi_taui*kernel_i(ij,ikx,iky)*phi(ikx,iky,izprev)*delta_p1) !! Electrical potential term IF ( p_int .LE. 2 ) THEN ! kronecker p0 p1 p2 - Tphi = phi(ikr,ikz) * (xphij*kernel_i(ij, ikr, ikz) & - + xphijp1*kernel_i(ij+1, ikr, ikz) & - + xphijm1*kernel_i(ij-1, ikr, ikz) ) + Tphi = phi(ikx,iky,iz) * (xphij(ip,ij)*kernel_i(ij, ikx, iky) & + + xphijp1(ip,ij)*kernel_i(ij+1, ikx, iky) & + + xphijm1(ip,ij)*kernel_i(ij-1, ikx, iky) ) ELSE Tphi = 0._dp ENDIF - !! Kinetic hyperdiffusion - Hyper_diff_p = 0._dp - IF ( p_int .GE. 4 ) THEN - Hyper_diff_p = (2._dp*p_dp)**2 *moments_i(ip-4,ij,ikr,ikz,updatetlevel) - ENDIF - - Hyper_diff_j = 0._dp - IF ( j_int .GE. 2 ) THEN - DO il = 1,(ij-2) - l_dp = real(il-1,dp) - Hyper_diff_j = Hyper_diff_j + (j_dp-(l_dp+1_dp))*moments_i(ip,il,ikr,ikz,updatetlevel) - ENDDO + !! Collision + IF (CO .EQ. 0) THEN ! Lenhard Bernstein + TColl = -nu_i*(ip+2._dp*ij-3)*moments_i(ip,ij,ikx,iky,iz,updatetlevel) + ELSEIF (CO .EQ. 1) THEN ! GK Dougherty + CALL DoughertyGK_i(ip,ij,ikx,iky,iz,TColl) + ELSE! COSOLver matrix (Sugama, Coulomb) + TColl = TColl_i(ip,ij,ikx,iky,iz) ENDIF !! Sum of linear terms - moments_rhs_i(ip,ij,ikr,ikz,updatetlevel) = & - -INV_LIN_SYS * i_kz * (TNapj + TNapp2j + TNapm2j + TNapjp1 + TNapjm1 - Tphi)& - - mu*kperp2**2 * moments_i(ip,ij,ikr,ikz,updatetlevel) & - + mu_p * Hyper_diff_p + mu_j * Hyper_diff_j & - +INV_LIN_SYS * TColl + moments_rhs_i(ip,ij,ikx,iky,iz,updatetlevel) = & + - Ckxky(ikx,iky,iz) * (Tnipj + Tnipp2j + Tnipm2j + Tnipjp1 + Tnipjm1)& + - Tpari/2._dp/deltaz/q0 & + + i_ky * Tphi & + - mu*kperp2**2 * moments_i(ip,ij,ikx,iky,iz,updatetlevel) & + + TColl !! Adding non linearity IF ( NON_LIN ) THEN - moments_rhs_i(ip,ij,ikr,ikz,updatetlevel) = & - moments_rhs_i(ip,ij,ikr,ikz,updatetlevel) + Sipj(ip,ij,ikr,ikz) + moments_rhs_i(ip,ij,ikx,iky,iz,updatetlevel) = & + moments_rhs_i(ip,ij,ikx,iky,iz,updatetlevel) + Sipj(ip,ij,ikx,iky,iz) ENDIF - END DO kzloopi - END DO krloopi + END DO kyloopi + END DO kxloopi + END DO zloopi END DO jloopi END DO ploopi diff --git a/src/numerics.F90 b/src/numerics.F90 new file mode 100644 index 0000000000000000000000000000000000000000..b7870565722df3157fb0148d9c086924dff076ac --- /dev/null +++ b/src/numerics.F90 @@ -0,0 +1,150 @@ +MODULE numerics + USE basic + USE prec_const + USE grid + USE utility + USE coeff + implicit none + + PUBLIC :: compute_derivatives, build_dnjs_table, evaluate_kernels + +CONTAINS + +! Compute the 2D particle temperature for electron and ions (sum over Laguerre) +SUBROUTINE compute_derivatives + +END SUBROUTINE compute_derivatives + +!******************************************************************************! +!!!!!!! Build the Laguerre-Laguerre coupling coefficient table for nonlin +!******************************************************************************! +SUBROUTINE build_dnjs_table + USE array, Only : dnjs + USE coeff + IMPLICIT NONE + + INTEGER :: in, ij, is, J + INTEGER :: n_, j_, s_ + + J = max(jmaxe,jmaxi) + + DO in = 1,J+1 ! Nested dependent loops to make benefit from dnjs symmetry + n_ = in - 1 + DO ij = in,J+1 + j_ = ij - 1 + DO is = ij,J+1 + s_ = is - 1 + + dnjs(in,ij,is) = TO_DP(ALL2L(n_,j_,s_,0)) + ! By symmetry + dnjs(in,is,ij) = dnjs(in,ij,is) + dnjs(ij,in,is) = dnjs(in,ij,is) + dnjs(ij,is,in) = dnjs(in,ij,is) + dnjs(is,ij,in) = dnjs(in,ij,is) + dnjs(is,in,ij) = dnjs(in,ij,is) + ENDDO + ENDDO + ENDDO +END SUBROUTINE build_dnjs_table +!******************************************************************************! + +!******************************************************************************! +!!!!!!! Evaluate the kernels once for all +!******************************************************************************! +SUBROUTINE evaluate_kernels + USE basic + USE array, Only : kernel_e, kernel_i + USE grid + use model, ONLY : tau_e, tau_i, sigma_e, sigma_i, q_e, q_i, lambdaD, CLOS, sigmae2_taue_o2, sigmai2_taui_o2 + IMPLICIT NONE + + REAL(dp) :: factj, j_dp, j_int + REAL(dp) :: be_2, bi_2, alphaD + REAL(dp) :: kx, ky, kperp2 + + !!!!! Electron kernels !!!!! + !Precompute species dependant factors + factj = 1.0 ! Start of the recursive factorial + DO ij = 1, jmaxe+1 + j_int = jarray_e(ij) + j_dp = REAL(j_int,dp) ! REAL of degree + + ! Recursive factorial + IF (j_dp .GT. 0) THEN + factj = factj * j_dp + ELSE + factj = 1._dp + ENDIF + + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) + + be_2 = (kx**2 + ky**2) * sigmae2_taue_o2 + + kernel_e(ij, ikx, iky) = be_2**j_int * exp(-be_2)/factj + + ENDDO + ENDDO + ENDDO + ! Kernels closure + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) + be_2 = (kx**2 + ky**2) * sigmae2_taue_o2 + ! Kernel ghost + 1 with Kj+1 = y/(j+1) Kj (/!\ ij = j+1) + kernel_e(ijeg_e,ikx,iky) = be_2/(real(ijeg_e-1,dp))*kernel_e(ije_e,ikx,iky) + ! Kernel ghost - 1 with Kj-1 = j/y Kj(careful about the kperp=0) + IF ( be_2 .NE. 0 ) THEN + kernel_e(ijsg_e,ikx,iky) = (real(ijsg_e,dp))/be_2*kernel_e(ijs_e,ikx,iky) + ELSE + kernel_e(ijsg_e,ikx,iky) = 0._dp + ENDIF + ENDDO + ENDDO + + !!!!! Ion kernels !!!!! + factj = 1.0 ! Start of the recursive factorial + DO ij = 1, jmaxi+1 + j_int = jarray_e(ij) + j_dp = REAL(j_int,dp) ! REAL of degree + + ! Recursive factorial + IF (j_dp .GT. 0) THEN + factj = factj * j_dp + ELSE + factj = 1._dp + ENDIF + + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) + bi_2 = (kx**2 + ky**2) * sigmai2_taui_o2 + kernel_i(ij, ikx, iky) = bi_2**j_int * exp(-bi_2)/factj + + ENDDO + ENDDO + ENDDO + ! Kernels closure + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) + bi_2 = (kx**2 + ky**2) * sigmai2_taui_o2 + ! Kernel ghost + 1 with Kj+1 = y/(j+1) Kj + kernel_i(ijeg_i,ikx,iky) = bi_2/(real(ijeg_i-1,dp))*kernel_i(ije_i,ikx,iky) + ! Kernel ghost - 1 with Kj-1 = j/y Kj(careful about the kperp=0) + IF ( bi_2 .NE. 0 ) THEN + kernel_i(ijsg_i,ikx,iky) = (real(ijsg_i,dp))/bi_2*kernel_i(ijs_i,ikx,iky) + ELSE + kernel_i(ijsg_i,ikx,iky) = 0._dp + ENDIF + ENDDO + ENDDO +END SUBROUTINE evaluate_kernels +!******************************************************************************! + +END MODULE numerics diff --git a/src/poisson.F90 b/src/poisson.F90 index b4d3918069252c5ea8047d1bf443a82e9391e5ae..6ec3a2fd38ee42899ade6480f7c1365f1a69f15f 100644 --- a/src/poisson.F90 +++ b/src/poisson.F90 @@ -20,7 +20,7 @@ SUBROUTINE poisson REAL(dp) :: gammaD COMPLEX(dp) :: gammaD_phi INTEGER :: count !! mpi integer to broadcast the electric potential at the end - COMPLEX(dp) :: buffer(ikrs:ikre,ikzs:ikze) + COMPLEX(dp) :: buffer(ikxs:ikxe,ikys:ikye) !! Poisson can be solved only for process containing ip=1 IF ( (ips_e .EQ. 1) .AND. (ips_i .EQ. 1) ) THEN @@ -28,48 +28,50 @@ SUBROUTINE poisson ! Execution time start CALL cpu_time(t0_poisson) - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - - !!!!!!!!!!!!! Electrons sum(Kernel * Ne0n) (skm) and sum(Kernel**2) (sk2) - sum_kernel_mom_e = 0._dp - sum_kernel2_e = 0._dp - ! loop over n only if the max polynomial degree - DO ine=1,jmaxe+1 ! ine = n+1 - Kne = kernel_e(ine, ikr, ikz) - sum_kernel_mom_e = sum_kernel_mom_e + Kne * moments_e(1, ine, ikr, ikz, updatetlevel) - sum_kernel2_e = sum_kernel2_e + Kne**2 ! ... sum recursively ... - END DO - - !!!!!!!!!!!!!!!!! Ions sum(Kernel * Ni0n) (skm) and sum(Kernel**2) (sk2) - sum_kernel_mom_i = 0 - sum_kernel2_i = 0 + kxloop: DO ikx = ikxs,ikxe + kyloop: DO iky = ikys,ikye + zloop: DO iz = izs,ize + + !!!!!!!!!!!!! Electrons sum(Kernel * Ne0n) (skm) and sum(Kernel**2) (sk2) + sum_kernel_mom_e = 0._dp + sum_kernel2_e = 0._dp ! loop over n only if the max polynomial degree - DO ini=1,jmaxi+1 - Kni = kernel_i(ini, ikr, ikz) - sum_kernel_mom_i = sum_kernel_mom_i + Kni * moments_i(1, ini, ikr, ikz, updatetlevel) - sum_kernel2_i = sum_kernel2_i + Kni**2 ! ... sum recursively ... + DO ine=1,jmaxe+1 ! ine = n+1 + Kne = kernel_e(ine, ikx, iky) + sum_kernel_mom_e = sum_kernel_mom_e + Kne * moments_e(1, ine, ikx, iky, iz, updatetlevel) + sum_kernel2_e = sum_kernel2_e + Kne**2 ! ... sum recursively ... END DO - !!!!!!!!!!!!!!! Assembling the poisson equation !!!!!!!!!!!!!!!!!!!!!!!!!! - alphaD = (krarray(ikr)**2 + kzarray(ikz)**2) * lambdaD**2 - gammaD = alphaD + qe2_taue * (1._dp - sum_kernel2_e) & ! Called Poisson_ in MOLI - + qi2_taui * (1._dp - sum_kernel2_i) + !!!!!!!!!!!!!!!!! Ions sum(Kernel * Ni0n) (skm) and sum(Kernel**2) (sk2) + sum_kernel_mom_i = 0._dp + sum_kernel2_i = 0._dp + ! loop over n only if the max polynomial degree + DO ini=1,jmaxi+1 + Kni = kernel_i(ini, ikx, iky) + sum_kernel_mom_i = sum_kernel_mom_i + Kni * moments_i(1, ini, ikx, iky, iz, updatetlevel) + sum_kernel2_i = sum_kernel2_i + Kni**2 ! ... sum recursively ... + END DO + + !!!!!!!!!!!!!!! Assembling the poisson equation !!!!!!!!!!!!!!!!!!!!!!!!!! + alphaD = (kxarray(ikx)**2 + kyarray(iky)**2) * lambdaD**2 + gammaD = alphaD + qe2_taue * (1._dp - sum_kernel2_e) & ! Called Poisson_ in MOLI + + qi2_taui * (1._dp - sum_kernel2_i) - gammaD_phi = q_e * sum_kernel_mom_e + q_i * sum_kernel_mom_i + gammaD_phi = q_e * sum_kernel_mom_e + q_i * sum_kernel_mom_i - phi(ikr, ikz) = gammaD_phi/gammaD + phi(ikx, iky, iz) = gammaD_phi/gammaD - END DO - END DO + END DO zloop + END DO kyloop + END DO kxloop ! Cancel origin singularity - IF ((ikr_0 .GE. ikrs) .AND. (ikr_0 .LE. ikre)) phi(ikr_0,ikz_0) = 0 + IF ((ikx_0 .GE. ikxs) .AND. (ikx_0 .LE. ikxe)) phi(ikx_0,iky_0,izs:ize) = 0._dp ENDIF ! Transfer phi to all the others process along p - CALL manual_2D_bcast(phi(ikrs:ikre,ikzs:ikze)) + CALL manual_3D_bcast(phi(ikxs:ikxe,ikys:ikye,izs:ize)) ! Execution time end CALL cpu_time(t1_poisson) diff --git a/src/ppinit.F90 b/src/ppinit.F90 index 1364ea92167e8f432cc54eaa7f5bc8be7317b27f..9b8382b6d135919e48d8cb61f175b6b977b57eff 100644 --- a/src/ppinit.F90 +++ b/src/ppinit.F90 @@ -7,7 +7,7 @@ SUBROUTINE ppinit INTEGER :: version_prov=-1 ! Variables for cartesian domain decomposition - INTEGER, PARAMETER :: ndims=2 ! p and kr + INTEGER, PARAMETER :: ndims=2 ! p and kx INTEGER, DIMENSION(ndims) :: dims=0, coords=0, coords_L=0, coords_R=0 LOGICAL :: periods(ndims) = .FALSE., reorder=.FALSE. CHARACTER(len=32) :: str @@ -40,12 +40,12 @@ SUBROUTINE ppinit END IF num_procs_p = dims(1) ! Number of processes along p - num_procs_kr = dims(2) ! Number of processes along kr + num_procs_kx = dims(2) ! Number of processes along kx ! !periodicity in p periods(1)=.FALSE. - !periodicity in kr + !periodicity in kx periods(2)=.FALSE. CALL MPI_CART_CREATE(MPI_COMM_WORLD, ndims, dims, periods, reorder, comm0, ierr) @@ -58,10 +58,10 @@ SUBROUTINE ppinit ! Partitions 2-dim cartesian topology of comm0 into 1-dim cartesian subgrids ! CALL MPI_CART_SUB (comm0, (/.TRUE.,.FALSE./), comm_p, ierr) - CALL MPI_CART_SUB (comm0, (/.FALSE.,.TRUE./), comm_kr, ierr) + CALL MPI_CART_SUB (comm0, (/.FALSE.,.TRUE./), comm_kx, ierr) ! Find id inside the sub communicators CALL MPI_COMM_RANK(comm_p, rank_p, ierr) - CALL MPI_COMM_RANK(comm_kr, rank_kr, ierr) + CALL MPI_COMM_RANK(comm_kx, rank_kx, ierr) ! Find neighbours CALL MPI_CART_SHIFT(comm0, 0, 1, nbr_L, nbr_R, ierr) CALL MPI_CART_SHIFT(comm0, 1, 1, nbr_B, nbr_T, ierr) diff --git a/src/processing_mod.F90 b/src/processing_mod.F90 index 0cf497c729ae6d2b0b99fb3c69d183556a65f184..129a4c1755ac8cf5aed20d95305d4f8a4ffcc00e 100644 --- a/src/processing_mod.F90 +++ b/src/processing_mod.F90 @@ -19,41 +19,44 @@ SUBROUTINE compute_radial_ion_transport USE time_integration, ONLY : updatetlevel IMPLICIT NONE COMPLEX(dp) :: pflux_local, gflux_local - REAL(dp) :: kz_, buffer(1:2) + REAL(dp) :: ky_, buffer(1:2) INTEGER :: i_, world_rank, world_size, root pflux_local = 0._dp ! particle flux gflux_local = 0._dp ! gyrocenter flux IF(ips_i .EQ. 1) THEN - ! Loop to compute gamma_kr = sum_kz sum_j -i k_z Kernel_j Ni00 * phi - DO ikz = ikzs,ikze - kz_ = kzarray(ikz) - DO ikr = ikrs,ikre - gflux_local = gflux_local - & - imagu * kz_ * moments_i(1,1,ikr,ikz,updatetlevel) * CONJG(phi(ikr,ikz)) - DO ij = ijs_i, ije_i - pflux_local = pflux_local - & - imagu * kz_ * kernel_i(ij,ikr,ikz) * moments_i(1,ij,ikr,ikz,updatetlevel) * CONJG(phi(ikr,ikz)) - ENDDO - ENDDO + ! Loop to compute gamma_kx = sum_ky sum_j -i k_z Kernel_j Ni00 * phi + DO iz = izs,ize + DO iky = ikys,ikye + ky_ = kyarray(iky) + DO ikx = ikxs,ikxe + gflux_local = gflux_local - & + imagu * ky_ * moments_i(1,1,ikx,iky,iz,updatetlevel) * CONJG(phi(ikx,iky,iz)) + DO ij = ijs_i, ije_i + pflux_local = pflux_local - & + imagu * ky_ * kernel_i(ij,ikx,iky) * moments_i(1,ij,ikx,iky,iz,updatetlevel) * CONJG(phi(ikx,iky,iz)) + ENDDO + ENDDO + ENDDO ENDDO + gflux_local = gflux_local/Nz ! Average over parallel planes + pflux_local = pflux_local/Nz buffer(1) = REAL(gflux_local) buffer(2) = REAL(pflux_local) - root = 0 !Gather manually among the rank_p=0 processes and perform the sum gflux_ri = 0 pflux_ri = 0 - IF (num_procs_kr .GT. 1) THEN + IF (num_procs_kx .GT. 1) THEN !! Everyone sends its local_sum to root = 0 - IF (rank_kr .NE. root) THEN - CALL MPI_SEND(buffer, 2 , MPI_DOUBLE_PRECISION, root, 1234, comm_kr, ierr) + IF (rank_kx .NE. root) THEN + CALL MPI_SEND(buffer, 2 , MPI_DOUBLE_PRECISION, root, 1234, comm_kx, ierr) ELSE ! Recieve from all the other processes - DO i_ = 0,num_procs_kr-1 - IF (i_ .NE. rank_kr) & - CALL MPI_RECV(buffer, 2 , MPI_DOUBLE_PRECISION, i_, 1234, comm_kr, MPI_STATUS_IGNORE, ierr) + DO i_ = 0,num_procs_kx-1 + IF (i_ .NE. rank_kx) & + CALL MPI_RECV(buffer, 2 , MPI_DOUBLE_PRECISION, i_, 1234, comm_kx, MPI_STATUS_IGNORE, ierr) gflux_ri = gflux_ri + buffer(1) pflux_ri = pflux_ri + buffer(2) ENDDO @@ -72,25 +75,27 @@ SUBROUTINE compute_density IF( (ips_i .EQ. 1) .AND. (ips_e .EQ. 1) ) THEN ! Loop to compute dens_i = sum_j kernel_j Ni0j at each k - DO ikz = ikzs,ikze - DO ikr = ikrs,ikre - ! electron density - dens_e(ikr,ikz) = 0._dp - DO ij = ijs_e, ije_e - dens_e(ikr,ikz) = dens_e(ikr,ikz) + kernel_e(ij,ikr,ikz) * & - (moments_e(1,ij,ikr,ikz,updatetlevel)+q_e/tau_e*kernel_e(ij,ikr,ikz)*phi(ikr,ikz)) - ENDDO - ! ion density - dens_i(ikr,ikz) = 0._dp - DO ij = ijs_i, ije_i - dens_i(ikr,ikz) = dens_i(ikr,ikz) + kernel_i(ij,ikr,ikz) * & - (moments_i(1,ij,ikr,ikz,updatetlevel)+q_i/tau_i*kernel_i(ij,ikr,ikz)*phi(ikr,ikz)) + DO iky = ikys,ikye + DO ikx = ikxs,ikxe + DO iz = izs,ize + ! electron density + dens_e(ikx,iky,iz) = 0._dp + DO ij = ijs_e, ije_e + dens_e(ikx,iky,iz) = dens_e(ikx,iky,iz) + kernel_e(ij,ikx,iky) * & + (moments_e(1,ij,ikx,iky,iz,updatetlevel)+q_e/tau_e*kernel_e(ij,ikx,iky)*phi(ikx,iky,iz)) + ENDDO + ! ion density + dens_i(ikx,iky,iz) = 0._dp + DO ij = ijs_i, ije_i + dens_i(ikx,iky,iz) = dens_i(ikx,iky,iz) + kernel_i(ij,ikx,iky) * & + (moments_i(1,ij,ikx,iky,iz,updatetlevel)+q_i/tau_i*kernel_i(ij,ikx,iky)*phi(ikx,iky,iz)) + ENDDO ENDDO ENDDO ENDDO ENDIF - CALL manual_2D_bcast(dens_e(ikrs:ikre,ikzs:ikze)) - CALL manual_2D_bcast(dens_i(ikrs:ikre,ikzs:ikze)) + CALL manual_3D_bcast(dens_e(ikxs:ikxe,ikys:ikye,izs:ize)) + CALL manual_3D_bcast(dens_i(ikxs:ikxe,ikys:ikye,izs:ize)) END SUBROUTINE compute_density ! Compute the 2D particle temperature for electron and ions (sum over Laguerre) @@ -105,32 +110,34 @@ SUBROUTINE compute_temperature IF( ((ips_i .EQ. 1) .AND. (ips_e .EQ. 1)) ) THEN ! Loop to compute T = 1/3*(Tpar + 2Tperp) - DO ikz = ikzs,ikze - DO ikr = ikrs,ikre - ! electron temperature - temp_e(ikr,ikz) = 0._dp - DO ij = ijs_e, ije_e - j_dp = REAL(ij-1,dp) - temp_e(ikr,ikz) = temp_e(ikr,ikz) + & - 2._dp/3._dp * (2._dp*j_dp*kernel_e(ij,ikr,ikz) - (j_dp+1)*kernel_e(ij+1,ikr,ikz) - j_dp*kernel_e(ij-1,ikr,ikz))& - * (moments_e(1,ij,ikr,ikz,updatetlevel)+q_e/tau_e*kernel_e(ij,ikr,ikz)*phi(ikr,ikz)) + & - SQRT2/3._dp * kernel_e(ij,ikr,ikz) * moments_e(3,ij,ikr,ikz,updatetlevel) - ENDDO + DO iky = ikys,ikye + DO ikx = ikxs,ikxe + DO iz = izs,ize + ! electron temperature + temp_e(ikx,iky,iz) = 0._dp + DO ij = ijs_e, ije_e + j_dp = REAL(ij-1,dp) + temp_e(ikx,iky,iz) = temp_e(ikx,iky,iz) + & + 2._dp/3._dp * (2._dp*j_dp*kernel_e(ij,ikx,iky) - (j_dp+1)*kernel_e(ij+1,ikx,iky) - j_dp*kernel_e(ij-1,ikx,iky))& + * (moments_e(1,ij,ikx,iky,iz,updatetlevel)+q_e/tau_e*kernel_e(ij,ikx,iky)*phi(ikx,iky,iz)) + & + SQRT2/3._dp * kernel_e(ij,ikx,iky) * moments_e(3,ij,ikx,iky,iz,updatetlevel) + ENDDO - ! ion temperature - temp_i(ikr,ikz) = 0._dp - DO ij = ijs_i, ije_i - j_dp = REAL(ij-1,dp) - temp_i(ikr,ikz) = temp_i(ikr,ikz) + & - 2._dp/3._dp * (2._dp*j_dp*kernel_i(ij,ikr,ikz) - (j_dp+1)*kernel_i(ij+1,ikr,ikz) - j_dp*kernel_i(ij-1,ikr,ikz))& - * (moments_i(1,ij,ikr,ikz,updatetlevel)+q_i/tau_i*kernel_i(ij,ikr,ikz)*phi(ikr,ikz)) + & - SQRT2/3._dp * kernel_i(ij,ikr,ikz) * moments_i(3,ij,ikr,ikz,updatetlevel) + ! ion temperature + temp_i(ikx,iky,iz) = 0._dp + DO ij = ijs_i, ije_i + j_dp = REAL(ij-1,dp) + temp_i(ikx,iky,iz) = temp_i(ikx,iky,iz) + & + 2._dp/3._dp * (2._dp*j_dp*kernel_i(ij,ikx,iky) - (j_dp+1)*kernel_i(ij+1,ikx,iky) - j_dp*kernel_i(ij-1,ikx,iky))& + * (moments_i(1,ij,ikx,iky,iz,updatetlevel)+q_i/tau_i*kernel_i(ij,ikx,iky)*phi(ikx,iky,iz)) + & + SQRT2/3._dp * kernel_i(ij,ikx,iky) * moments_i(3,ij,ikx,iky,iz,updatetlevel) + ENDDO ENDDO ENDDO ENDDO ENDIF - CALL manual_2D_bcast(temp_e(ikrs:ikre,ikzs:ikze)) - CALL manual_2D_bcast(temp_i(ikrs:ikre,ikzs:ikze)) + CALL manual_3D_bcast(temp_e(ikxs:ikxe,ikys:ikye,izs:ize)) + CALL manual_3D_bcast(temp_i(ikxs:ikxe,ikys:ikye,izs:ize)) END SUBROUTINE compute_temperature END MODULE processing diff --git a/src/restarts_mod.F90 b/src/restarts_mod.F90 index f3f14e9db1d32ca0c709f99f863ee64c8030726d..f1c3e29343a55e06e4ae2b92e9f738739a0b30fe 100644 --- a/src/restarts_mod.F90 +++ b/src/restarts_mod.F90 @@ -12,8 +12,8 @@ INTEGER :: rank, sz_, n_ INTEGER :: dims(1) = (/0/) CHARACTER(LEN=50) :: dset_name INTEGER :: pmaxe_cp, jmaxe_cp, pmaxi_cp, jmaxi_cp, n0 -COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: moments_e_cp -COMPLEX(dp), DIMENSION(:,:,:,:), ALLOCATABLE :: moments_i_cp +COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_e_cp +COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_i_cp PUBLIC :: load_moments @@ -68,9 +68,9 @@ CONTAINS ! Read state of system from checkpoint file WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ - CALL getarrnd(fidrst, dset_name, moments_e(ips_e:ipe_e, ijs_e:ije_e, ikrs:ikre, ikzs:ikze, 1),(/1,3/)) + CALL getarrnd(fidrst, dset_name, moments_e(ips_e:ipe_e, ijs_e:ije_e, ikxs:ikxe, ikys:ikye, izs:ize, 1),(/1,3/)) WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_i", n_ - CALL getarrnd(fidrst, dset_name, moments_i(ips_i:ipe_i, ijs_i:ije_i, ikrs:ikre, ikzs:ikze, 1),(/1,3/)) + CALL getarrnd(fidrst, dset_name, moments_i(ips_i:ipe_i, ijs_i:ije_i, ikxs:ikxe, ikys:ikye, izs:ize, 1),(/1,3/)) CALL closef(fidrst) @@ -103,8 +103,8 @@ CONTAINS CALL getatt(fidrst,"/data/input/" , "start_iframe5d", n0) ! Allocate the required size to load checkpoints moments - CALL allocate_array(moments_e_cp, 1,pmaxe_cp+1, 1,jmaxe_cp+1, ikrs,ikre, ikzs,ikze) - CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikrs,ikre, ikzs,ikze) + CALL allocate_array(moments_e_cp, 1,pmaxe_cp+1, 1,jmaxe_cp+1, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikxs,ikxe, ikys,ikye, izs,ize) ! Find the last results of the checkpoint file by iteration n_ = n0+1 WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ ! start with moments_e/000001 @@ -116,18 +116,20 @@ CONTAINS ! Read state of system from checkpoint file and load every moment to change the distribution WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ - CALL getarrnd(fidrst, dset_name, moments_e_cp(1:pmaxe_cp+1, 1:jmaxe_cp+1, ikrs:ikre, ikzs:ikze),(/1,3/)) + CALL getarrnd(fidrst, dset_name, moments_e_cp(1:pmaxe_cp+1, 1:jmaxe_cp+1, ikxs:ikxe, ikys:ikye, izs:ize),(/1,3/)) WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_i", n_ - CALL getarrnd(fidrst, dset_name, moments_i_cp(1:pmaxi_cp+1, 1:jmaxi_cp+1, ikrs:ikre, ikzs:ikze),(/1,3/)) + CALL getarrnd(fidrst, dset_name, moments_i_cp(1:pmaxi_cp+1, 1:jmaxi_cp+1, ikxs:ikxe, ikys:ikye, izs:ize),(/1,3/)) ! Initialize simulation moments array with checkpoints ones ! (they may have a larger number of polynomials, set to 0 at the begining) moments_e = 0._dp; moments_i = 0._dp DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_e(ip,ij,ikr,ikz,:) = moments_e_cp(ip,ij,ikr,ikz) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz = izs,ize + moments_e(ip,ij,ikx,iky,iz,:) = moments_e_cp(ip,ij,ikx,iky,iz) + ENDDO ENDDO ENDDO ENDDO @@ -135,9 +137,11 @@ CONTAINS DO ip=1,pmaxi_cp+1 DO ij=1,jmaxi_cp+1 - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_i(ip,ij,ikr,ikz,:) = moments_i_cp(ip,ij,ikr,ikz) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz = izs,ize + moments_i(ip,ij,ikx,iky,iz,:) = moments_i_cp(ip,ij,ikx,iky,iz) + ENDDO ENDDO ENDDO ENDDO @@ -183,8 +187,8 @@ CONTAINS IF (my_id .EQ. 0) WRITE(*,*) "Je_cp = ", jmaxe_cp ! Allocate the required size to load checkpoints moments - CALL allocate_array(moments_e_cp, 1,pmaxe_cp+1, 1,jmaxe_cp+1, ikrs,ikre, ikzs,ikze) - CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikrs,ikre, ikzs,ikze) + CALL allocate_array(moments_e_cp, 1,pmaxe_cp+1, 1,jmaxe_cp+1, ikxs,ikxe, ikys,ikye, izs,ize) + CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikxs,ikxe, ikys,ikye, izs,ize) ! Find the last results of the checkpoint file by iteration n_ = 0 WRITE(dset_name, "(A, '/', i6.6)") "/Basic/moments_e", n_ ! start with moments_e/000000 @@ -196,20 +200,22 @@ CONTAINS ! Read state of system from checkpoint file WRITE(dset_name, "(A, '/', i6.6)") "/Basic/moments_e", n_ - CALL getarr(fidrst, dset_name, moments_e_cp(1:pmaxe_cp+1, 1:jmaxe_cp+1, ikrs:ikre, ikzs:ikze),pardim=3) + CALL getarr(fidrst, dset_name, moments_e_cp(1:pmaxe_cp+1, 1:jmaxe_cp+1, ikxs:ikxe, ikys:ikye, izs:ize),pardim=3) WRITE(dset_name, "(A, '/', i6.6)") "/Basic/moments_i", n_ - CALL getarr(fidrst, dset_name, moments_i_cp(1:pmaxi_cp+1, 1:jmaxi_cp+1, ikrs:ikre, ikzs:ikze),pardim=3) + CALL getarr(fidrst, dset_name, moments_i_cp(1:pmaxi_cp+1, 1:jmaxi_cp+1, ikxs:ikxe, ikys:ikye, izs:ize),pardim=3) WRITE(dset_name, "(A, '/', i6.6)") "/Basic/phi", n_ - CALL getarr(fidrst, dset_name, phi(ikrs:ikre,ikzs:ikze),pardim=1) + CALL getarr(fidrst, dset_name, phi(ikxs:ikxe,ikys:ikye,izs:ize),pardim=1) ! Initialize simulation moments array with checkpoints ones ! (they may have a larger number of polynomials, set to 0 at the begining) moments_e = 0._dp; moments_i = 0._dp DO ip=1,pmaxe_cp+1 DO ij=1,jmaxe_cp+1 - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_e(ip,ij,ikr,ikz,:) = moments_e_cp(ip,ij,ikr,ikz) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz = izs,ize + moments_e(ip,ij,ikx,iky,iz,:) = moments_e_cp(ip,ij,ikx,iky,iz) + ENDDO ENDDO ENDDO ENDDO @@ -217,9 +223,11 @@ CONTAINS DO ip=1,pmaxi_cp+1 DO ij=1,jmaxi_cp+1 - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_i(ip,ij,ikr,ikz,:) = moments_i_cp(ip,ij,ikr,ikz) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz = izs,ize + moments_i(ip,ij,ikx,iky,iz,:) = moments_i_cp(ip,ij,ikx,iky,iz) + ENDDO ENDDO ENDDO ENDDO diff --git a/src/stepon.F90 b/src/stepon.F90 index 2ef08caac067ff9b48fb3f7bf1cbb53f272de6d5..2f2d8a7e432c73f309e247caffbcd35f3dc37597 100644 --- a/src/stepon.F90 +++ b/src/stepon.F90 @@ -56,19 +56,19 @@ SUBROUTINE stepon ! Execution time start CALL cpu_time(t0_checkfield) - IF ( (ikrs .EQ. 1) .AND. (NON_LIN) ) CALL enforce_symetry() ! Enforcing symmetry on kr = 0 + IF ( (ikxs .EQ. 1) .AND. (NON_LIN) ) CALL enforce_symetry() ! Enforcing symmetry on kx = 0 mlend=.FALSE. IF(.NOT.nlend) THEN mlend=mlend .or. checkfield(phi,' phi') DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - mlend=mlend .or. checkfield(moments_e(ip,ij,:,:,updatetlevel),' moments_e') + mlend=mlend .or. checkfield(moments_e(ip,ij,:,:,:,updatetlevel),' moments_e') ENDDO ENDDO DO ip=ips_i,ipe_i DO ij=ijs_i,ije_i - mlend=mlend .or. checkfield(moments_i(ip,ij,:,:,updatetlevel),' moments_i') + mlend=mlend .or. checkfield(moments_i(ip,ij,:,:,:,updatetlevel),' moments_i') ENDDO ENDDO CALL MPI_ALLREDUCE(mlend, nlend, 1, MPI_LOGICAL, MPI_LOR, MPI_COMM_WORLD, ierr) @@ -82,18 +82,22 @@ SUBROUTINE stepon SUBROUTINE anti_aliasing DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_e( ip,ij,ikr,ikz,:) = AA_r(ikr)* AA_z(ikz) * moments_e( ip,ij,ikr,ikz,:) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + moments_e( ip,ij,ikx,iky,iz,:) = AA_x(ikx)* AA_y(iky) * moments_e( ip,ij,ikx,iky,iz,:) + END DO END DO END DO END DO END DO DO ip=ips_i,ipe_i DO ij=ijs_i,ije_i - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze - moments_i( ip,ij,ikr,ikz,:) = AA_r(ikr)* AA_z(ikz) * moments_i( ip,ij,ikr,ikz,:) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + DO iz=izs,ize + moments_i( ip,ij,ikx,iky,iz,:) = AA_x(ikx)* AA_y(iky) * moments_i( ip,ij,ikx,iky,iz,:) + END DO END DO END DO END DO @@ -101,33 +105,37 @@ SUBROUTINE stepon END SUBROUTINE anti_aliasing SUBROUTINE enforce_symetry ! Force X(k) = X(N-k)* complex conjugate symmetry - IF ( contains_kr0 ) THEN + IF ( contains_kx0 ) THEN ! Electron moments DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - DO ikz=2,Nkz/2 !symmetry at kr = 0 - moments_e( ip,ij,ikr_0,ikz, :) = CONJG(moments_e( ip,ij,ikr_0,Nkz+2-ikz, :)) + DO iz=izs,ize + DO iky=2,Nky/2 !symmetry at kx = 0 + moments_e( ip,ij,ikx_0,iky,iz, :) = CONJG(moments_e( ip,ij,ikx_0,Nky+2-iky,iz, :)) + END DO + ! must be real at origin + moments_e(ip,ij, ikx_0,iky_0,iz, :) = REAL(moments_e(ip,ij, ikx_0,iky_0,iz, :)) END DO - ! must be real at origin - moments_e(ip,ij, ikr_0,ikz_0, :) = REAL(moments_e(ip,ij, ikr_0,ikz_0, :)) END DO END DO ! Ion moments DO ip=ips_i,ipe_i DO ij=ijs_i,ije_i - DO ikz=2,Nkz/2 !symmetry at kr = 0 - moments_i( ip,ij,ikr_0,ikz, :) = CONJG(moments_i( ip,ij,ikr_0,Nkz+2-ikz, :)) + DO iz=izs,ize + DO iky=2,Nky/2 !symmetry at kx = 0 + moments_i( ip,ij,ikx_0,iky,iz, :) = CONJG(moments_i( ip,ij,ikx_0,Nky+2-iky,iz, :)) + END DO + ! must be real at origin and top right + moments_i(ip,ij, ikx_0,iky_0,iz, :) = REAL(moments_i(ip,ij, ikx_0,iky_0,iz, :)) END DO - ! must be real at origin and top right - moments_i(ip,ij, ikr_0,ikz_0, :) = REAL(moments_i(ip,ij, ikr_0,ikz_0, :)) END DO END DO ! Phi - DO ikz=2,Nkz/2 !symmetry at kr = 0 - phi(ikr_0,ikz) = phi(ikr_0,Nkz+2-ikz) + DO iky=2,Nky/2 !symmetry at kx = 0 + phi(ikx_0,iky,:) = phi(ikx_0,Nky+2-iky,:) END DO ! must be real at origin - phi(ikr_0,ikz_0) = REAL(phi(ikr_0,ikz_0)) + phi(ikx_0,iky_0,:) = REAL(phi(ikx_0,iky_0,:)) ENDIF END SUBROUTINE enforce_symetry diff --git a/src/utility_mod.F90 b/src/utility_mod.F90 index b044ce6d368741e72186a61d28ce7b1e87b400c7..a295575e5464fdf0efdf415e2f9f08f84fd7dc0c 100644 --- a/src/utility_mod.F90 +++ b/src/utility_mod.F90 @@ -4,7 +4,7 @@ MODULE utility use prec_const IMPLICIT NONE - PUBLIC :: manual_2D_bcast + PUBLIC :: manual_2D_bcast, manual_3D_bcast CONTAINS @@ -59,7 +59,7 @@ CONTAINS use prec_const IMPLICIT NONE - COMPLEX(dp), DIMENSION(ikrs:ikre,ikzs:ikze), INTENT(IN) :: field + COMPLEX(dp), DIMENSION(ikxs:ikxe,ikys:ikye), INTENT(IN) :: field CHARACTER(LEN=*), INTENT(IN) :: str LOGICAL :: mlend COMPLEX(dp) :: sumfield @@ -75,8 +75,8 @@ CONTAINS SUBROUTINE manual_2D_bcast(field_) USE grid IMPLICIT NONE - COMPLEX(dp), INTENT(INOUT) :: field_(ikrs:ikre,ikzs:ikze) - COMPLEX(dp) :: buffer(ikrs:ikre,ikzs:ikze) + COMPLEX(dp), INTENT(INOUT) :: field_(ikxs:ikxe,ikys:ikye) + COMPLEX(dp) :: buffer(ikxs:ikxe,ikys:ikye) INTEGER :: i_, root, world_rank, world_size root = 0; CALL MPI_COMM_RANK(comm_p,world_rank,ierr) @@ -85,27 +85,68 @@ CONTAINS !! Broadcast phi to the other processes on the same k range (communicator along p) IF (world_rank .EQ. root) THEN ! Fill the buffer - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - buffer(ikr,ikz) = field_(ikr,ikz) + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + buffer(ikx,iky) = field_(ikx,iky) ENDDO ENDDO ! Send it to all the other processes DO i_ = 0,num_procs_p-1 IF (i_ .NE. world_rank) & - CALL MPI_SEND(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, i_, 0, comm_p, ierr) + CALL MPI_SEND(buffer, local_nkx * Nky , MPI_DOUBLE_COMPLEX, i_, 0, comm_p, ierr) ENDDO ELSE ! Recieve buffer from root - CALL MPI_RECV(buffer, local_nkr * nkz , MPI_DOUBLE_COMPLEX, root, 0, comm_p, MPI_STATUS_IGNORE, ierr) + CALL MPI_RECV(buffer, local_nkx * Nky , MPI_DOUBLE_COMPLEX, root, 0, comm_p, MPI_STATUS_IGNORE, ierr) ! Write it in phi - DO ikr = ikrs,ikre - DO ikz = ikzs,ikze - field_(ikr,ikz) = buffer(ikr,ikz) + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + field_(ikx,iky) = buffer(ikx,iky) ENDDO ENDDO ENDIF ENDIF END SUBROUTINE manual_2D_bcast + !!!!! This is a manual way to do MPI_BCAST !!!!!!!!!!! +SUBROUTINE manual_3D_bcast(field_) + USE grid + IMPLICIT NONE + COMPLEX(dp), INTENT(INOUT) :: field_(ikxs:ikxe,ikys:ikye,izs:ize) + COMPLEX(dp) :: buffer(ikxs:ikxe,ikys:ikye,izs:ize) + INTEGER :: i_, root, world_rank, world_size + root = 0; + CALL MPI_COMM_RANK(comm_p,world_rank,ierr) + CALL MPI_COMM_SIZE(comm_p,world_size,ierr) + IF (world_size .GT. 1) THEN + !! Broadcast phi to the other processes on the same k range (communicator along p) + IF (world_rank .EQ. root) THEN + ! Fill the buffer + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + DO iz = izs,ize + buffer(ikx,iky,iz) = field_(ikx,iky,iz) + ENDDO + ENDDO + ENDDO + ! Send it to all the other processes + DO i_ = 0,num_procs_p-1 + IF (i_ .NE. world_rank) & + CALL MPI_SEND(buffer, local_nkx * Nky * Nz, MPI_DOUBLE_COMPLEX, i_, 0, comm_p, ierr) + ENDDO + ELSE + ! Recieve buffer from root + CALL MPI_RECV(buffer, local_nkx * Nky * Nz, MPI_DOUBLE_COMPLEX, root, 0, comm_p, MPI_STATUS_IGNORE, ierr) + ! Write it in phi + DO ikx = ikxs,ikxe + DO iky = ikys,ikye + DO iz = izs,ize + field_(ikx,iky,iz) = buffer(ikx,iky,iz) + ENDDO + ENDDO + ENDDO + ENDIF + ENDIF +END SUBROUTINE manual_3D_bcast + END MODULE utility diff --git a/wk/HD_study.m b/wk/HD_study.m deleted file mode 100644 index 14951e8d5d4f5e060ba5599e6179a56a307e3c29..0000000000000000000000000000000000000000 --- a/wk/HD_study.m +++ /dev/null @@ -1,88 +0,0 @@ -% bursts simulations -b_=[... - 5e-1, 5e+0;... - 1e-1, 1e-1;... - 1e-1, 3e-2;... - 1e-1, 2e-2;... - 1e-1, 1e-2;... - 5e-2, 3e-3;... - 5e-2, 2e-3;... - 1e-2, 3e-3;... - 1e-3, 2e-2;... - ]; -% converged plateau simulations -cp_=[... - 1e+0, 1e-2;... - 1e+0, 3e-3;... - 1e+0, 2e-3;... - 1e-1, 2e-3;... - 1e-1, 1e-3;... - ]; -% moving plateau -dp_=[... - 1e+0, 5e+0;... - 1e+0, 2e+0;... - 1e+0, 1e+0;... - 1e-3, 2e-2;... - 1e-3, 1e-2;... - 1e-3, 5e-3;... - 1e-3, 2.5e-3,... - ]; -% not sure -rp_=[... - 5e-2, 1e-3;... - 1e-2, 1e-3;... - 1e-2, 1e-4;... - ]; -figure; set(gcf, 'Position', [100, 100, 900, 400]) -grid on; xlim([5e-4,5e0]); ylim([5e-5,5e+0]); -set(gca, 'XScale', 'log'); set(gca, 'YScale', 'log'); -xlabel('$\nu_{DGGK}$'); ylabel('$\mu_{HD}$'); hold on; - -% Trajectory of simulations - -% HD_study/200x100_L_200_P_2_J_1_eta_0.6_nu_1e+00_DGGK_CLOS_0_mu_1e-02/ -mu_ = [0 1 2 5 5]; -nu_ = [1 1 1 1 0.5]; -plot(nu_,mu_,'x--','DisplayName','N=200, L=050, P,J=2,1'); - -% HD_study/300x150_L_200_P_2_J_1_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_1e-02/ -mu_ = [1e-2 1e-3]; -nu_ = [1e-1 1e-1]; -plot(nu_,mu_,'x--','DisplayName','N=300, L=100, P,J=2,1'); - -% Trajectory of simulations -% HD_study/100x50_L_50_P_2_J_1_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_1e-02/ -mu_ = [1e-2 5e-3 2e-3]; -nu_ = [1e-1 1e-1 1e-1]; -plot(nu_,mu_,'x-','DisplayName','N=100, L=050, P,J=2,1'); - -% HD_study/150x75_L_100_P_2_J_1_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_3e-02/ -mu_ = [3e-2 1e-3 0]; -nu_ = [1e-1 1e-1 1e-1]; -plot(nu_,mu_,'x--','DisplayName','N=150, L=100, P,J=2,1'); - -% HD_study/150x75_L_100_P_2_J_1_eta_0.6_nu_1e-02_DGGK_CLOS_0_mu_3e-02/ -mu_ = [3e-3 1e-3 1e-4]; -nu_ = [1e-2 1e-2 1e-2]; -plot(nu_,mu_,'x--','DisplayName','N=150, L=100, P,J=2,1'); - -% HD_study/150x75_L_100_P_2_J_1_eta_0.6_nu_5e-02_DGGK_CLOS_0_mu_3e-02/ -mu_ = [3e-3 1e-3]; -nu_ = [5e-2 5e-2]; -plot(nu_,mu_,'x--','DisplayName','N=150, L=100, P,J=2,1'); - -scatter( b_(:,1), b_(:,2),'o',... - 'MarkerFaceColor',[0.6350 0.0780 0.1840],'MarkerEdgeColor',[0 0 0],'SizeData',50,... - 'DisplayName','Bursts'); -scatter(cp_(:,1),cp_(:,2),'s',... - 'MarkerFaceColor',[0.4660 0.6740 0.1880],'MarkerEdgeColor',[0 0 0],'SizeData',50,... - 'DisplayName','Converged Plateau'); -scatter(dp_(:,1),dp_(:,2),'v',... - 'MarkerFaceColor',[0.4660 0.6740 0.1880],'MarkerEdgeColor',[0 0 0],'SizeData',50,... - 'DisplayName','Moving Plateau'); -scatter(rp_(:,1),rp_(:,2),'h',... - 'MarkerFaceColor',[0.9290 0.6940 0.1250],'MarkerEdgeColor',[0 0 0],'SizeData',50,... - 'DisplayName','not sure'); -% plot([1 1],[5e-5 5e-1],'--','Color',[0.4660 0.6740 0.1880]); -legend('show','Location','Eastoutside') \ No newline at end of file diff --git a/wk/ZF_fourier_analysis.m b/wk/ZF_fourier_analysis.m index d5833371109766a745b0e8fcaf81f413b0ff8c35..da4cf8784b24e2d2ba8f53eeede27485f1d04bee 100644 --- a/wk/ZF_fourier_analysis.m +++ b/wk/ZF_fourier_analysis.m @@ -9,7 +9,7 @@ set(gcf, 'Position', [100, 100, 800, 400]) % Time series analysis (burst period and time frequencies spectrum) subplot(121) samplerate = Ts0D(2)-Ts0D(1); - Y = log(PGAMMA_RI(its0D:ite0D)*(2*pi/Nr/Nz)^2); + Y = log(PGAMMA_RI(its0D:ite0D)*(2*pi/Nx/Ny)^2); [n,~] = size(Y); Yy= fft(Y); Pot = Yy .* conj(Yy) / n; @@ -35,13 +35,20 @@ set(gcf, 'Position', [100, 100, 800, 400]) [amax, ikZF] = max(mean(Pot,2)); % pclr = pcolor(NN(1:nmax,:),TT(1:nmax,:),Pot(1:nmax,:)); set(pclr, 'edgecolor','none'); hold on; plot(0:nmax,mean(Pot(1:nmax+1,:),2)/amax,'DisplayName','$\langle\partial_r\phi\rangle_z (k_r)$'); hold on; - plot([ikZF-1,ikZF-1],[0,1],'--k', 'DisplayName',['$L_z=',num2str(2*pi/kr(ikZF)),'\rho_s$']); + plot([ikZF-1,ikZF-1],[0,1],'--k', 'DisplayName',['$L_z=',num2str(2*pi/kx(ikZF)),'\rho_s$']); grid on; box on; title('ZF spatial spectrum') xlabel('radial mode number'); yticks([]); legend('show') save_figure %% Pred-Pray phase space (A Zonal Flow review, Diamond 2005, Fig 15, Kobayashi 2015) + +E_turb = zeros(1,Ns2D); % Time evol. of the turbulence energy (Pred in Kobayashi 2015) +E_ZF = zeros(1,Ns2D); % Time evol. of the ZF energy (Pray in Kobayashi 2015) +for it = 1:numel(Ts2D) + E_turb(it) = sum(sum((1+kx.^2+ky.^2).*abs(PHI(:,:,it)).^2))- sum((1+kx.^2).*abs(PHI(:,1,it)).^2); + E_ZF(it) = kx(ikZF)^2*abs(PHI(ikZF,1,it)).^2; +end fig = figure; FIGNAME = ['phi_shear_phase_space_',PARAMS]; set(gcf, 'Position', [100, 100, 700, 500]) scatter(E_ZF*SCALE,E_turb*SCALE,35,Ts2D,'.',... @@ -75,10 +82,10 @@ end PHI_NZ = PHI; PHI_NZ(ikZF-1:ikZF+1,:,:) = 0; -phi_nz = zeros(Nr,Nz,Ns2D); +phi_nz = zeros(Nx,Ny,Ns2D); for it = 1:numel(Ts2D) PH_ = PHI_NZ(:,:,it); - phi_nz (:,:,it) = real(fftshift(ifft2((PH_),Nr,Nz))); + phi_nz (:,:,it) = real(fftshift(ifft2((PH_),Nx,Ny))); end %% t0 = 1000; @@ -91,6 +98,6 @@ if 0 %% Phi non zonal real space GIFNAME = ['phi_nz',sprintf('_%.2d',JOBNUM),'_',PARAMS];INTERP = 0; FIELD = real(phi_nz); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; -FIELDNAME = '$\phi_{NZ}$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; +FIELDNAME = '$\phi_{Ny}$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif end \ No newline at end of file diff --git a/wk/analysis_1D.m b/wk/analysis_1D.m index 9076e8565eaacbc69116971b7f28bf3825f0267b..bcfffa5749e7677f70cfb5ea251b861a6b38f6fe 100644 --- a/wk/analysis_1D.m +++ b/wk/analysis_1D.m @@ -9,30 +9,30 @@ Ts2D = Ts2D'; Ns = numel(Ts2D); dt_samp = mean(diff(Ts2D)); % Build grids -Nkr = numel(kr); Nkz = numel(kz); -[KZ,KR] = meshgrid(kz,kr); -Lkr = max(kr)-min(kr); Lkz = max(kz)-min(kz); -dkr = Lkr/(Nkr-1); dkz = Lkz/(Nkz-1); -Lk = max(Lkr,Lkz); +Nkx = numel(kx); Nky = numel(ky); +[ky,kx] = meshgrid(ky,kx); +Lkx = max(kx)-min(kx); Lky = max(ky)-min(ky); +dkx = Lkx/(Nkx-1); dky = Lky/(Nky-1); +Lk = max(Lkx,Lky); dr = 2*pi/Lk; dz = 2*pi/Lk; -Nr = max(Nkr,Nkz) * (Nkr > 1) + (Nkr == 1); Nz = Nkz; -r = dr*(-Nr/2:(Nr/2-1)); Lr = max(r)-min(r); -z = dz*(-Nz/2:(Nz/2-1)); Lz = max(z)-min(z); +Nx = max(Nkx,Nky) * (Nkx > 1) + (Nkx == 1); Ny = Nky; +r = dr*(-Nx/2:(Nx/2-1)); Lx = max(r)-min(r); +z = dz*(-Ny/2:(Ny/2-1)); Ly = max(z)-min(z); [YY,XX] = meshgrid(z,r); % Analysis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % IFFT -ne00 = zeros(Nz, Ns); -ni00 = zeros(Nz, Ns); -phi = zeros(Nz, Ns); +ne00 = zeros(Ny, Ns); +ni00 = zeros(Ny, Ns); +phi = zeros(Ny, Ns); for it = 1:numel(Ts2D) NE_ = Ne00(:,it); NN_ = Ni00(:,it); PH_ = PHI(:,it); - F_ = (ifft((NE_),Nz)); + F_ = (ifft((NE_),Ny)); ne00(:,it)= real(fftshift(F_)); - F_ = (ifft((NN_),Nz)); + F_ = (ifft((NN_),Ny)); ni00(:,it) = real(fftshift(F_)); - F_ = (ifft((PH_),Nz)); + F_ = (ifft((PH_),Ny)); phi(:,it) = real(fftshift(F_)); end @@ -44,9 +44,9 @@ E_pot = zeros(1,Ns); % Potential energy n^2 E_kin = zeros(1,Ns); % Kinetic energy grad(phi)^2 ExB = zeros(1,Ns); % ExB drift intensity \propto |\grad \phi| CFL = zeros(1,Ns); % CFL time step -Ddz = 1i*kz; +Ddz = 1i*ky; [~,iz0] = min(abs(z)); % index of z==0 -[~,ikz1] = min(abs(kz-round(1/dkz)*dkz)); % index of kz==1 +[~,iky1] = min(abs(ky-round(1/dky)*dky)); % index of ky==1 for it = 1:numel(Ts2D) NE_ = squeeze(Ne00(:,it)); NN_ = squeeze(Ni00(:,it)); PH_ = squeeze(PHI(:,it)); @@ -56,23 +56,23 @@ for it = 1:numel(Ts2D) phi_00(it) = phi(iz0,it); - E_pot(it) = pi/Lz*sum(abs(NN_).^2)/Nkz; % integrate through Parseval id - E_kin(it) = pi/Lz*sum(abs(Ddz.*PH_).^2)/Nkz; + E_pot(it) = pi/Ly*sum(abs(NN_).^2)/Nky; % integrate through Parseval id + E_kin(it) = pi/Ly*sum(abs(Ddz.*PH_).^2)/Nky; ExB(it) = max(abs(phi(3:end,it)-phi(1:end-2,it))'/(2*dz)); end -E_kin_KZ = abs(Ddz.*PHI(:,it)).^2; +E_kin_KY = abs(Ddz.*PHI(:,it)).^2; dEdt = diff(E_pot+E_kin)./diff(Ts2D); %% Compute growth rate -gamma_Ne = zeros(1,Nkz); -gamma_Ni = zeros(1,Nkz); -gamma_PH = zeros(1,Nkz); +gamma_Ne = zeros(1,Nky); +gamma_Ni = zeros(1,Nky); +gamma_PH = zeros(1,Nky); tend = Ts2D(end); tstart = 0.6*tend; plt = @(x) squeeze(abs(x)); -for ikz = 1:Nkz - gamma_Ne(ikz) = LinearFit_s(Ts2D,plt(Ne00(ikz,:)),tstart,tend); - gamma_Ni(ikz) = LinearFit_s(Ts2D,plt(Ni00(ikz,:)),tstart,tend); - gamma_PH(ikz) = LinearFit_s(Ts2D,plt(PHI(ikz,:)),tstart,tend); +for iky = 1:Nky + gamma_Ne(iky) = LinearFit_s(Ts2D,plt(Ne00(iky,:)),tstart,tend); + gamma_Ni(iky) = LinearFit_s(Ts2D,plt(Ni00(iky,:)),tstart,tend); + gamma_PH(iky) = LinearFit_s(Ts2D,plt(PHI(iky,:)),tstart,tend); end gamma_Ne = real(gamma_Ne .* (gamma_Ne>=0.0)); gamma_Ni = real(gamma_Ni .* (gamma_Ni>=0.0)); @@ -98,15 +98,15 @@ end if 1 %% Growth rate fig = figure; FIGNAME = ['growth_rate',sprintf('_%.2d',JOBNUM)]; -plt = @(x) circshift(x,Nkz/2-1); +plt = @(x) circshift(x,Nky/2-1); subplot(221) - plot(plt(kz),plt(gamma_Ne),'-'); hold on; xlim([0.0,max(kz)+dkz]); + plot(plt(ky),plt(gamma_Ne),'-'); hold on; xlim([0.0,max(ky)+dky]); grid on; xlabel('$k_z$'); ylabel('$\gamma(N_e^{00})$'); subplot(222) - plot(plt(kz),plt(gamma_Ni),'-'); hold on; xlim([0.0,max(kz)+dkz]); + plot(plt(ky),plt(gamma_Ni),'-'); hold on; xlim([0.0,max(ky)+dky]); grid on; xlabel('$k_z$'); ylabel('$\gamma(N_i^{00})$'); subplot(223) - plot(plt(kz),plt(gamma_PH),'-'); hold on; xlim([0.0,max(kz)+dkz]); + plot(plt(ky),plt(gamma_PH),'-'); hold on; xlim([0.0,max(ky)+dky]); grid on; xlabel('$k_z$'); ylabel('$\gamma(\tilde\phi)$'); legend('show'); FMT = '.fig'; save_figure end @@ -137,9 +137,9 @@ XMIN = -L/2-2; XMAX = L/2+1; YMIN = -1.1; YMAX = 1.1; create_gif_1D %% Density electron frequency GIFNAME = ['Ni',sprintf('_%.2d',JOBNUM)]; -FIELD = (abs(Ni00)); X = (kz); T = Ts2D; +FIELD = (abs(Ni00)); X = (ky); T = Ts2D; FIELDNAME = '$|N_i^{00}|$'; XNAME = '$k_z$'; -XMIN = min(kz)-0.5; XMAX = max(kz)+.5; YMIN = -0.1; YMAX = 1.1; +XMIN = min(ky)-0.5; XMAX = max(ky)+.5; YMIN = -0.1; YMAX = 1.1; create_gif_1D end @@ -159,28 +159,28 @@ subplot(223)% density xlabel('$z\,(r=0)$'); ylabel('$t$'); title('$\phi$'); FMT = '.fig'; save_figure -%% Space-Time diagrams at kr=0 +%% Space-Time diagrams at kx=0 plt = @(x) abs(x); -fig = figure; FIGNAME = ['kz_space_time_diag',sprintf('_%.2d',JOBNUM)]; - [TY,TX] = meshgrid(Ts2D,kz); +fig = figure; FIGNAME = ['ky_space_time_diag',sprintf('_%.2d',JOBNUM)]; + [TY,TX] = meshgrid(Ts2D,ky); subplot(221)% density pclr = pcolor(TX,TY,(plt(Ne00))); set(pclr, 'edgecolor','none'); colorbar; - xlabel('$kz$'); ylabel('$t$'); title('$\textrm{Re}(N_e^{00})|_{k_r=0}$'); + xlabel('$ky$'); ylabel('$t$'); title('$\textrm{Re}(N_e^{00})|_{k_r=0}$'); subplot(222)% density pclr = pcolor(TX,TY,(plt(Ni00))); set(pclr, 'edgecolor','none'); colorbar; - xlabel('$kz$'); ylabel('$t$'); title('$\textrm{Re}(N_i^{00})|_{k_r=0}$'); + xlabel('$ky$'); ylabel('$t$'); title('$\textrm{Re}(N_i^{00})|_{k_r=0}$'); subplot(223)% density pclr = pcolor(TX,TY,(plt(PH))); set(pclr, 'edgecolor','none'); colorbar; - xlabel('$kz$'); ylabel('$t$'); title('$\textrm{Re}(\tilde\phi)|_{k_r=0}$'); + xlabel('$ky$'); ylabel('$t$'); title('$\textrm{Re}(\tilde\phi)|_{k_r=0}$'); FMT = '.fig'; save_figure end if 0 %% Mode time evolution -[~,ik05] = min(abs(kz-0.50)); -[~,ik10] = min(abs(kz-1.00)); -[~,ik15] = min(abs(kz-1.50)); -[~,ik20] = min(abs(kz-2.00)); +[~,ik05] = min(abs(ky-0.50)); +[~,ik10] = min(abs(ky-1.00)); +[~,ik15] = min(abs(ky-1.50)); +[~,ik20] = min(abs(ky-2.00)); fig = figure; FIGNAME = ['frame',sprintf('_%.2d',JOBNUM)]; subplot(221); plt = @(x) abs(squeeze(x)); @@ -221,13 +221,13 @@ if 0 it = min(70,numel(Ts2D)); fig = figure; FIGNAME = ['frame',sprintf('_%.2d',JOBNUM)]; subplot(221); plt = @(x) (abs(x)); - plot(kz,plt(PH(:,it))) + plot(ky,plt(PH(:,it))) xlabel('$k_r$'); ylabel('$k_z$'); title(sprintf('t=%.3d',Ts2D(it))); legend('$\hat\phi$'); subplot(222); plt = @(x) (abs(x)); - plot(kz,plt(Ni00(:,it))) + plot(ky,plt(Ni00(:,it))) xlabel('$k_r$'); ylabel('$k_z$'); title(sprintf('t=%.3d',Ts2D(it))); legend('$\hat n_i^{00}$'); subplot(223); plt = @(x) (abs(x)); - plot(kz,plt(Ne00(:,it))) + plot(ky,plt(Ne00(:,it))) xlabel('$k_r$'); ylabel('$k_z$'); title(sprintf('t=%.3d',Ts2D(it))); legend('$\hat n_e^{00}$'); FMT = '.fig'; save_figure end \ No newline at end of file diff --git a/wk/analysis_2D.m b/wk/analysis_2D.m index b52f45546674e12da09db1630c95ef356a0d2ce5..50a40384355df85c07257905a776b7e2e718ef42 100644 --- a/wk/analysis_2D.m +++ b/wk/analysis_2D.m @@ -2,23 +2,21 @@ addpath(genpath('../matlab')) % ... add for i_ = 1 % for ETA_ =[0.6:0.1:0.9] %% Load results -if 1% Local results +if 0% Local results outfile =''; outfile =''; outfile =''; outfile =''; -outfile ='HD_study/300x150_L_100_P_2_J_1_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_1e-03'; -% outfile ='test_3D/50x25_L_50_lin_P_2_J_1_eta_0.5_nu_1e-01_LBDK_CLOS_0_mu_0e+00'; +outfile ='v2.8_kobayashi/100x50_L_50_P_6_J_3_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00'; BASIC.RESDIR = ['../results/',outfile,'/']; BASIC.MISCDIR = ['/misc/HeLaZ_outputs/results/',outfile,'/']; CMD = ['cp ', BASIC.RESDIR,'outputs* ',BASIC.MISCDIR]; disp(CMD); system(CMD); -else% Marconi results -outfile =''; -outfile =''; +end +if 1% Marconi results outfile =''; outfile =''; -outfile ='/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/300x150_L_100_P_10_J_5_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt'; +outfile ='/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-02_SGGK_CLOS_0_mu_1e-02/out.txt'; % outfile = outcl{i_}; % load_marconi(outfile); BASIC.RESDIR = ['../',outfile(46:end-8),'/']; @@ -39,69 +37,63 @@ Ts5D = Ts5D'; Ts2D = Ts2D'; %% Build grids -Nkr = numel(kr); Nkz = numel(kz); -[KZ,KR] = meshgrid(kz,kr); -Lkr = max(kr)-min(kr); Lkz = max(kz)-min(kz); -dkr = Lkr/(Nkr-1); dkz = Lkz/(Nkz-1); -KPERP2 = KZ.^2+KR.^2; -[~,ikr0] = min(abs(kr)); [~,ikz0] = min(abs(kz)); +Nkx = numel(kx); Nky = numel(ky); +[ky,kx] = meshgrid(ky,kx); +Lkx = max(kx)-min(kx); Lky = max(ky)-min(ky); +dkx = Lkx/(Nkx-1); dky = Lky/(Nky-1); +KPERP2 = ky.^2+kx.^2; +[~,ikx0] = min(abs(kx)); [~,iky0] = min(abs(ky)); -Lk = max(Lkr,Lkz); +Lk = max(Lkx,Lky); dr = 2*pi/Lk; dz = 2*pi/Lk; -Nr = max(Nkr,Nkz); Nz = Nr; -r = dr*(-Nr/2:(Nr/2-1)); Lr = max(r)-min(r); -z = dz*(-Nz/2:(Nz/2-1)); Lz = max(z)-min(z); +Nx = max(Nkx,Nky); Ny = Nx; +r = dr*(-Nx/2:(Nx/2-1)); Lx = max(r)-min(r); +z = dz*(-Ny/2:(Ny/2-1)); Ly = max(z)-min(z); [ZZ,RR] = meshgrid(z,r); %% Analysis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp('Analysis :') disp('- iFFT') % IFFT (Lower case = real space, upper case = frequency space) -ne00 = zeros(Nr,Nz,Ns2D); % Gyrocenter density -ni00 = zeros(Nr,Nz,Ns2D); -dzTe = zeros(Nr,Nz,Ns2D); -dzTi = zeros(Nr,Nz,Ns2D); -dzni = zeros(Nr,Nz,Ns2D); -np_i = zeros(Nr,Nz,Ns5D); % Ion particle density -si00 = zeros(Nr,Nz,Ns5D); -phi = zeros(Nr,Nz,Ns2D); -dens_e = zeros(Nr,Nz,Ns2D); -dens_i = zeros(Nr,Nz,Ns2D); -temp_e = zeros(Nr,Nz,Ns2D); -temp_i = zeros(Nr,Nz,Ns2D); -drphi = zeros(Nr,Nz,Ns2D); -dzphi = zeros(Nr,Nz,Ns2D); -dr2phi = zeros(Nr,Nz,Ns2D); -E_turb = zeros(1,Ns2D); % Time evol. of the turbulence energy (Pred in Kobayashi 2015) -E_ZF = zeros(1,Ns2D); % Time evol. of the ZF energy (Pray in Kobayashi 2015) -for it = 1:numel(Ts2D) +ne00 = zeros(Nx,Ny,Ns2D); % Gyrocenter density +ni00 = zeros(Nx,Ny,Ns2D); +dzTe = zeros(Nx,Ny,Ns2D); +dzTi = zeros(Nx,Ny,Ns2D); +dzni = zeros(Nx,Ny,Ns2D); +np_i = zeros(Nx,Ny,Ns5D); % Ion particle density +si00 = zeros(Nx,Ny,Ns5D); +phi = zeros(Nx,Ny,Ns2D); +dens_e = zeros(Nx,Ny,Ns2D); +dens_i = zeros(Nx,Ny,Ns2D); +temp_e = zeros(Nx,Ny,Ns2D); +temp_i = zeros(Nx,Ny,Ns2D); +drphi = zeros(Nx,Ny,Ns2D); +dzphi = zeros(Nx,Ny,Ns2D); +dr2phi = zeros(Nx,Ny,Ns2D); -end for it = 1:numel(Ts2D) NE_ = Ne00(:,:,it); NI_ = Ni00(:,:,it); PH_ = PHI(:,:,it); - ne00(:,:,it) = real(fftshift(ifft2((NE_),Nr,Nz))); - ni00(:,:,it) = real(fftshift(ifft2((NI_),Nr,Nz))); - phi (:,:,it) = real(fftshift(ifft2((PH_),Nr,Nz))); - drphi(:,:,it) = real(fftshift(ifft2(1i*KR.*(PH_),Nr,Nz))); - dr2phi(:,:,it)= real(fftshift(ifft2(-KR.^2.*(PH_),Nr,Nz))); - dzphi(:,:,it) = real(fftshift(ifft2(1i*KZ.*(PH_),Nr,Nz))); - E_turb(it) = sum(sum((1+KR.^2+KZ.^2).*abs(PHI(:,:,it)).^2))- sum((1+kr.^2).*abs(PHI(:,1,it)).^2); - E_ZF(it) = sum(kr.^2.*abs(PHI(:,1,it)).^2); + ne00(:,:,it) = real(fftshift(ifft2((NE_),Nx,Ny))); + ni00(:,:,it) = real(fftshift(ifft2((NI_),Nx,Ny))); + phi (:,:,it) = real(fftshift(ifft2((PH_),Nx,Ny))); + drphi(:,:,it) = real(fftshift(ifft2(1i*kx.*(PH_),Nx,Ny))); + dr2phi(:,:,it)= real(fftshift(ifft2(-kx.^2.*(PH_),Nx,Ny))); + dzphi(:,:,it) = real(fftshift(ifft2(1i*ky.*(PH_),Nx,Ny))); if(W_DENS && W_TEMP) DENS_E_ = DENS_E(:,:,it); DENS_I_ = DENS_I(:,:,it); TEMP_E_ = TEMP_E(:,:,it); TEMP_I_ = TEMP_I(:,:,it); - dzni(:,:,it) = real(fftshift(ifft2(1i*KZ.*(DENS_I_),Nr,Nz))); - dzTe(:,:,it) = real(fftshift(ifft2(1i*KZ.*(TEMP_E_),Nr,Nz))); - dzTi(:,:,it) = real(fftshift(ifft2(1i*KZ.*(TEMP_I_),Nr,Nz))); - dens_e (:,:,it) = real(fftshift(ifft2((DENS_E_),Nr,Nz))); - dens_i (:,:,it) = real(fftshift(ifft2((DENS_I_),Nr,Nz))); - temp_e (:,:,it) = real(fftshift(ifft2((TEMP_E_),Nr,Nz))); - temp_i (:,:,it) = real(fftshift(ifft2((TEMP_I_),Nr,Nz))); + dzni(:,:,it) = real(fftshift(ifft2(1i*ky.*(DENS_I_),Nx,Ny))); + dzTe(:,:,it) = real(fftshift(ifft2(1i*ky.*(TEMP_E_),Nx,Ny))); + dzTi(:,:,it) = real(fftshift(ifft2(1i*ky.*(TEMP_I_),Nx,Ny))); + dens_e (:,:,it) = real(fftshift(ifft2((DENS_E_),Nx,Ny))); + dens_i (:,:,it) = real(fftshift(ifft2((DENS_I_),Nx,Ny))); + temp_e (:,:,it) = real(fftshift(ifft2((TEMP_E_),Nx,Ny))); + temp_i (:,:,it) = real(fftshift(ifft2((TEMP_I_),Nx,Ny))); end end % Building a version of phi only 5D sampling times -PHI_Ts5D = zeros(Nkr,Nkz,Ns5D); +PHI_Ts5D = zeros(Nkx,Nky,Ns5D); err = 0; for it = 1:numel(Ts5D) % Loop over 5D arrays [shift, it2D] = min(abs(Ts2D-Ts5D(it))); @@ -110,7 +102,7 @@ for it = 1:numel(Ts5D) % Loop over 5D arrays end if err > 0; disp('WARNING Ts2D and Ts5D are shifted'); end; -Np_i = zeros(Nkr,Nkz,Ns5D); % Ion particle density in Fourier space +Np_i = zeros(Nkx,Nky,Ns5D); % Ion particle density in Fourier space for it = 1:numel(Ts5D) [~, it2D] = min(abs(Ts2D-Ts5D(it))); @@ -120,7 +112,7 @@ for it = 1:numel(Ts5D) Np_i(:,:,it) = Np_i(:,:,it) + Kn.*squeeze(Nipj(1,ij,:,:,it)); end - np_i(:,:,it) = real(fftshift(ifft2(squeeze(Np_i(:,:,it)),Nr,Nz))); + np_i(:,:,it) = real(fftshift(ifft2(squeeze(Np_i(:,:,it)),Nx,Ny))); end % Post processing @@ -132,8 +124,8 @@ GFlux_re = zeros(1,Ns2D); % Gyrocenter flux Gamma = <ne drphi> GFlux_ze = zeros(1,Ns2D); % Gyrocenter flux Gamma = <ne dzphi> PFlux_ri = zeros(1,Ns5D); % Particle flux % gyrocenter and particle flux from fourier coefficients -GFLUX_RI = real(squeeze(sum(sum(-1i*KZ.*Ni00.*conj(PHI),1),2)))*(2*pi/Nr/Nz)^2; -PFLUX_RI = real(squeeze(sum(sum(-1i*KZ.*Np_i.*conj(PHI_Ts5D),1),2)))*(2*pi/Nr/Nz)^2; +GFLUX_RI = real(squeeze(sum(sum(-1i*ky.*Ni00.*conj(PHI),1),2)))*(2*pi/Nx/Ny)^2; +PFLUX_RI = real(squeeze(sum(sum(-1i*ky.*Np_i.*conj(PHI_Ts5D),1),2)))*(2*pi/Nx/Ny)^2; % Heat flux Q_RI = -squeeze(mean(mean(dzphi.*temp_i,1),2))'; % Hermite energy spectrum @@ -153,17 +145,17 @@ shear_avgr_avgz = zeros(1,Ns2D); % Time evol. of the norm of shear Ne_norm = zeros(Pe_max,Je_max,Ns5D); % Time evol. of the norm of Napj Ni_norm = zeros(Pi_max,Ji_max,Ns5D); % . -Ddr = 1i*KR; Ddz = 1i*KZ; lapl = Ddr.^2 + Ddz.^2; +Ddr = 1i*kx; Ddz = 1i*ky; lapl = Ddr.^2 + Ddz.^2; % Kperp spectrum interpolation %full kperp points -kperp = reshape(sqrt(KR.^2+KZ.^2),[numel(KR),1]); +kperp = reshape(sqrt(kx.^2+ky.^2),[numel(kx),1]); % interpolated kperps -nk_noAA = floor(2/3*numel(kr)); -kp_ip = kr; +nk_noAA = floor(2/3*numel(kx)); +kp_ip = kx; [thg, rg] = meshgrid(linspace(0,pi,2*nk_noAA),kp_ip); [xn,yn] = pol2cart(thg,rg); -[kz_s, sortIdx] = sort(kz); -[xc,yc] = meshgrid(kz_s,kr); +[ky_s, sortIdx] = sort(ky); +[xc,yc] = meshgrid(ky_s,kx); phi_kp_t = zeros(numel(kp_ip),Ns2D); % for it = 1:numel(Ts2D) % Loop over 2D arrays @@ -178,10 +170,10 @@ for it = 1:numel(Ts2D) % Loop over 2D arrays shear_maxr_avgz(it) = mean( max(squeeze(-(dr2phi(:,:,it))))); shear_avgr_avgz(it) = mean(mean(squeeze(-(dr2phi(:,:,it))))); - GFlux_ri(it) = sum(sum(ni00(:,:,it).*dzphi(:,:,it)))*dr*dz/Lr/Lz; - GFlux_zi(it) = sum(sum(-ni00(:,:,it).*drphi(:,:,it)))*dr*dz/Lr/Lz; - GFlux_re(it) = sum(sum(ne00(:,:,it).*dzphi(:,:,it)))*dr*dz/Lr/Lz; - GFlux_ze(it) = sum(sum(-ne00(:,:,it).*drphi(:,:,it)))*dr*dz/Lr/Lz; + GFlux_ri(it) = sum(sum(ni00(:,:,it).*dzphi(:,:,it)))*dr*dz/Lx/Ly; + GFlux_zi(it) = sum(sum(-ni00(:,:,it).*drphi(:,:,it)))*dr*dz/Lx/Ly; + GFlux_re(it) = sum(sum(ne00(:,:,it).*dzphi(:,:,it)))*dr*dz/Lx/Ly; + GFlux_ze(it) = sum(sum(-ne00(:,:,it).*drphi(:,:,it)))*dr*dz/Lx/Ly; Z_rth = interp2(xc,yc,squeeze(mean((abs(PHI(:,sortIdx,it))).^2,3)),xn,yn); phi_kp_t(:,it) = mean(Z_rth,2); @@ -189,50 +181,50 @@ end % for it = 1:numel(Ts5D) % Loop over 5D arrays [~, it2D] = min(abs(Ts2D-Ts5D(it))); - Ne_norm(:,:,it)= sum(sum(abs(Nepj(:,:,:,:,it)),3),4)/Nkr/Nkz; - Ni_norm(:,:,it)= sum(sum(abs(Nipj(:,:,:,:,it)),3),4)/Nkr/Nkz; + Ne_norm(:,:,it)= sum(sum(abs(Nepj(:,:,:,:,it)),3),4)/Nkx/Nky; + Ni_norm(:,:,it)= sum(sum(abs(Nipj(:,:,:,:,it)),3),4)/Nkx/Nky; epsilon_e_pj(:,:,it) = sqrt(pi)/2*sum(sum(abs(Nepj(:,:,:,:,it)).^2,3),4); epsilon_i_pj(:,:,it) = sqrt(pi)/2*sum(sum(abs(Nipj(:,:,:,:,it)).^2,3),4); % Particle flux - PFlux_ri(it) = sum(sum(np_i(:,:,it).*dzphi(:,:,it2D)))*dr*dz/Lr/Lz; + PFlux_ri(it) = sum(sum(np_i(:,:,it).*dzphi(:,:,it2D)))*dr*dz/Lx/Ly; end %% Compute primary instability growth rate disp('- growth rate') % Find max value of transport (end of linear mode) -[tmp,tmax] = max(GGAMMA_RI*(2*pi/Nr/Nz)^2); +[tmp,tmax] = max(GGAMMA_RI*(2*pi/Nx/Ny)^2); [~,itmax] = min(abs(Ts2D-tmax)); tstart = 0.1 * Ts2D(itmax); tend = 0.5 * Ts2D(itmax); [~,its2D_lin] = min(abs(Ts2D-tstart)); [~,ite2D_lin] = min(abs(Ts2D-tend)); -g_I = zeros(Nkr,Nkz); -for ikr = 1:Nkr - for ikz = 1:Nkz - [g_I(ikr,ikz), ~] = LinearFit_s(Ts2D(its2D_lin:ite2D_lin),squeeze(abs(Ni00(ikr,ikz,its2D_lin:ite2D_lin)))); +g_I = zeros(Nkx,Nky); +for ikx = 1:Nkx + for iky = 1:Nky + [g_I(ikx,iky), ~] = LinearFit_s(Ts2D(its2D_lin:ite2D_lin),squeeze(abs(Ni00(ikx,iky,its2D_lin:ite2D_lin)))); end end [gmax_I,ikmax_I] = max(g_I(1,:)); -kmax_I = abs(kz(ikmax_I)); +kmax_I = abs(ky(ikmax_I)); Bohm_transport = ETAB/ETAN*gmax_I/kmax_I^2; %% Compute secondary instability growth rate disp('- growth rate') % Find max value of transport (end of linear mode) -% [tmp,tmax] = max(GGAMMA_RI*(2*pi/Nr/Nz)^2); +% [tmp,tmax] = max(GGAMMA_RI*(2*pi/Nx/Ny)^2); % [~,itmax] = min(abs(Ts2D-tmax)); % tstart = Ts2D(itmax); tend = 1.5*Ts2D(itmax); [~,its2D_lin] = min(abs(Ts2D-tstart)); [~,ite2D_lin] = min(abs(Ts2D-tend)); -g_II = zeros(Nkr,Nkz); -for ikr = 1:Nkr - for ikz = 1 - [g_II(ikr,ikz), ~] = LinearFit_s(Ts2D(its2D_lin:ite2D_lin),squeeze(abs(Ni00(ikr,ikz,its2D_lin:ite2D_lin)))); +g_II = zeros(Nkx,Nky); +for ikx = 1:Nkx + for iky = 1 + [g_II(ikx,iky), ~] = LinearFit_s(Ts2D(its2D_lin:ite2D_lin),squeeze(abs(Ni00(ikx,iky,its2D_lin:ite2D_lin)))); end end [gmax_II,ikmax_II] = max(g_II(1,:)); -kmax_II = abs(kr(ikmax_II)); +kmax_II = abs(kx(ikmax_II)); %% PLOTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% default_plots_options @@ -244,8 +236,8 @@ if 1 fig = figure; FIGNAME = ['t_evolutions',sprintf('_%.2d',JOBNUM),'_',PARAMS]; set(gcf, 'Position', [100, 100, 900, 800]) subplot(111); - suptitle(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... - ', $L=',num2str(L),'$, $N=',num2str(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... + suptitle(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... ' $\mu_{hd}=$',num2str(MU)]); subplot(421); for ip = 1:Pe_max @@ -272,20 +264,20 @@ subplot(111); end grid on; ylabel('$\sum_{k_r,k_z}|N_i^{pj}|$'); xlabel('$t c_s/R$') subplot(222) - plot(Ts0D,GGAMMA_RI*(2*pi/Nr/Nz)^2); hold on; + plot(Ts0D,GGAMMA_RI*(2*pi/Nx/Ny)^2); hold on; % plot(Ts2D,GFLUX_RI) - plot(Ts0D,PGAMMA_RI*(2*pi/Nr/Nz)^2); + plot(Ts0D,PGAMMA_RI*(2*pi/Nx/Ny)^2); % plot(Ts5D,PFLUX_RI,'--'); legend(['Gyro. flux';'Part. flux']); grid on; xlabel('$t c_s/R$'); ylabel('$\Gamma_{r,i}$') % ylim([0,2.0]); - if(0) + if(1) subplot(223) - plot(kz,g_I(1,:),'-','DisplayName','Primar. instability'); hold on; - plot(kr,g_II(:,1),'x-','DisplayName','Second. instability'); hold on; - plot([max(kz)*2/3,max(kz)*2/3],[0,10],'--k', 'DisplayName','2/3 Orszag AA'); + plot(ky,g_I(1,:),'-','DisplayName','Primar. instability'); hold on; + plot(kx,g_II(:,1),'x-','DisplayName','Second. instability'); hold on; + plot([max(ky)*2/3,max(ky)*2/3],[0,10],'--k', 'DisplayName','2/3 Orszag AA'); grid on; xlabel('$k\rho_s$'); ylabel('$\gamma R/c_s$'); legend('show'); - ylim([0,max(g_I(1,:))]); xlim([0,max(kz)]); + ylim([0,max(g_I(1,:))]); xlim([0,max(ky)]); shearplot = 426; phiplot = 428; else shearplot = 223; phiplot = 224; @@ -311,12 +303,12 @@ end if 1 %% Space time diagramm (fig 11 Ivanov 2020) -TAVG = 1000; % Averaging time duration +TAVG = 5000; % Averaging time duration %Compute steady radial transport tend = Ts0D(end); tstart = tend - TAVG; [~,its0D] = min(abs(Ts0D-tstart)); [~,ite0D] = min(abs(Ts0D-tend)); -SCALE = (2*pi/Nr/Nz)^2; +SCALE = (2*pi/Nx/Ny)^2; gamma_infty_avg = mean(PGAMMA_RI(its0D:ite0D))*SCALE; gamma_infty_std = std (PGAMMA_RI(its0D:ite0D))*SCALE; % Compute steady shearing rate @@ -330,28 +322,33 @@ Q_infty_std = std(Q_RI(its2D:ite2D))*SCALE; % plots fig = figure; FIGNAME = ['ZF_transport_drphi','_',PARAMS];set(gcf, 'Position', [100, 100, 1200, 600]) subplot(311) - yyaxis left +% yyaxis left plot(Ts0D,PGAMMA_RI*SCALE,'DisplayName','$\langle n_i d\phi/dz \rangle_z$'); hold on; plot(Ts0D(its0D:ite0D),ones(ite0D-its0D+1,1)*gamma_infty_avg, '-k',... 'DisplayName',['$\Gamma^{\infty} = $',num2str(gamma_infty_avg),'$\pm$',num2str(gamma_infty_std)]); grid on; set(gca,'xticklabel',[]); ylabel('$\Gamma_r$') ylim([0,5*abs(gamma_infty_avg)]); xlim([0,Ts0D(end)]); - title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... - ', $L=',num2str(L),'$, $N=',num2str(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... + title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... ' $\mu_{hd}=$',num2str(MU)]); - yyaxis right +% yyaxis right +% plot(Ts2D,Q_RI*SCALE,'.','DisplayName','$\langle T_i d\phi/dz \rangle_z$'); hold on; +% ylim([0,5*Q_infty_avg]); xlim([0,Ts0D(end)]); ylabel('$Q_r$') +% plot(Ts0D(its0D:ite0D),ones(ite0D-its0D+1,1)*Q_infty_avg, '--k',... +% 'DisplayName',['$Q^{\infty} = $',num2str(Q_infty_avg),'$\pm$',num2str(Q_infty_std)]); +% legend('show','Location','west') + % + subplot(312) + clr = line_colors(1,:); + lstyle = line_styles(1); + plot(Ts2D,shear_maxr_maxz,'DisplayName','$\max_{r,z}(s_\phi)$'); hold on; plot(Ts2D,shear_maxr_avgz,'DisplayName','$\max_{r}\langle s_\phi\rangle_z$'); hold on; + plot(Ts2D,shear_avgr_maxz,'DisplayName','$\max_{z}\langle s_\phi\rangle_r$'); hold on; + plot(Ts2D,shear_avgr_avgz,'DisplayName','$\langle s_\phi\rangle_{r,z}$'); hold on; plot(Ts2D(its2D:ite2D),ones(ite2D-its2D+1,1)*shear_infty_avg, '-k',... 'DisplayName',['$s^{\infty} = $',num2str(shear_infty_avg),'$\pm$',num2str(shear_infty_std)]); ylim([0,shear_infty_avg*5.0]); xlim([0,Ts0D(end)]); grid on; ylabel('Shear amp.');set(gca,'xticklabel',[]);% legend('show'); - subplot(312) - yyaxis left - plot(Ts2D,SCALE*E_ZF);xlim([0,Ts0D(end)]); - ylabel('ZF energy'); ylim([0;1.2*max(SCALE*E_ZF(floor(0.5*numel(Ts2D)):end))]); - yyaxis right - plot(Ts2D,SCALE*E_turb);xlim([0,Ts0D(end)]); - ylabel('Turb. energy'); ylim([0;1.2*max(SCALE*E_turb(floor(0.5*numel(Ts2D)):end))]); subplot(313) [TY,TX] = meshgrid(r,Ts2D); % pclr = pcolor(TX,TY,squeeze(mean(drphi(:,:,:),2))'); set(pclr, 'edgecolor','none'); legend('$\langle \partial_r\phi\rangle_z$') %colorbar; @@ -360,7 +357,7 @@ fig = figure; FIGNAME = ['ZF_transport_drphi','_',PARAMS];set(gcf, 'Position', save_figure end -if 0 +if 1 %% Space time diagramms tstart = 0; tend = Ts2D(end); [~,itstart] = min(abs(Ts2D-tstart)); @@ -369,20 +366,32 @@ trange = itstart:itend; [TY,TX] = meshgrid(r,Ts2D(trange)); fig = figure; FIGNAME = ['space_time','_',PARAMS];set(gcf, 'Position', [100, 100, 1200, 600]) subplot(211) +% pclr = pcolor(TX,TY,squeeze(mean(dens_i(:,:,trange).*dzphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; pclr = pcolor(TX,TY,squeeze(mean(ni00(:,:,trange).*dzphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; shading interp colormap hot; caxis([0.0,0.05*max(max(mean(ni00(:,:,its2D:ite2D).*dzphi(:,:,its2D:ite2D),2)))]); - caxis([0.0,0.05]); c = colorbar; c.Label.String ='\langle n_i\partial_z\phi\rangle_z'; + caxis([0.0,0.01]); c = colorbar; c.Label.String ='\langle n_i\partial_z\phi\rangle_z'; xticks([]); ylabel('$r/\rho_s$') - title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... - ', $L=',num2str(L),'$, $N=',num2str(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... +% legend('Radial part. transport $\langle n_i\partial_z\phi\rangle_z$') + title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... ' $\mu_{hd}=$',num2str(MU)]); +% subplot(312) +% pclr = pcolor(TX,TY,squeeze(mean(temp_i(:,:,trange).*dzphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; +% shading interp +% % colormap(bluewhitered(256)); +% xticks([]); ylabel('$r/\rho_s$') +% legend('Radial part. transport $\langle T_i\partial_z\phi\rangle_z$') +% title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... +% ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... +% ' $\mu_{hd}=$',num2str(MU)]); subplot(212) pclr = pcolor(TX,TY,squeeze(mean(drphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; fieldmax = max(max(mean(abs(drphi(:,:,its2D:ite2D)),2))); caxis([-fieldmax,fieldmax]); c = colorbar; c.Label.String ='\langle \partial_r\phi\rangle_z'; xlabel('$t c_s/R$'), ylabel('$r/\rho_s$') +% legend('Zonal flow $\langle \partial_r\phi\rangle_z$') save_figure end @@ -403,20 +412,20 @@ end if 1 %% |phi_k|^2 spectra (Kobayashi 2015 fig 3) -tstart = 3000; tend = 5000; +tstart = 0.8*Ts2D(end); tend = Ts2D(end); [~,itstart] = min(abs(Ts2D-tstart)); [~,itend] = min(abs(Ts2D-tend)); trange = itstart:itend; %full kperp points -phi_k_2 = reshape(mean((abs(PHI(:,:,trange))).^2,3),[numel(KR),1]); -kperp = reshape(sqrt(KR.^2+KZ.^2),[numel(KR),1]); +phi_k_2 = reshape(mean((abs(PHI(:,:,trange))).^2,3),[numel(kx),1]); +kperp = reshape(sqrt(kx.^2+ky.^2),[numel(kx),1]); % interpolated kperps -nk_noAA = floor(2/3*numel(kr)); -kp_ip = kr; +nk_noAA = floor(2/3*numel(kx)); +kp_ip = kx; [thg, rg] = meshgrid(linspace(0,pi,2*nk_noAA),kp_ip); [xn,yn] = pol2cart(thg,rg); -[kz_s, sortIdx] = sort(kz); -[xc,yc] = meshgrid(kz_s,kr); +[ky_s, sortIdx] = sort(ky); +[xc,yc] = meshgrid(ky_s,kx); Z_rth = interp2(xc,yc,squeeze(mean((abs(PHI(:,sortIdx,trange))).^2,3)),xn,yn); phi_kp = mean(Z_rth,2); Z_rth = interp2(xc,yc,squeeze(mean((abs(Ni00(:,sortIdx,trange))).^2,3)),xn,yn); @@ -426,7 +435,7 @@ ne00_kp = mean(Z_rth,2); %for theorical trends a1 = phi_kp(2)*kp_ip(2).^(13/3); a2 = phi_kp(2)*kp_ip(2).^(3)./(1+kp_ip(2).^2).^(-2); -fig = figure; FIGNAME = ['cascade_',num2str(tstart),'to',num2str(tend),PARAMS];set(gcf, 'Position', [100, 100, 500, 500]) +fig = figure; FIGNAME = ['cascade','_',PARAMS];set(gcf, 'Position', [100, 100, 500, 500]) % scatter(kperp,phi_k_2,'.k','MarkerEdgeAlpha',0.4,'DisplayName','$|\phi_k|^2$'); hold on; grid on; plot(kp_ip,phi_kp,'^','DisplayName','$\langle|\phi_k|^2\rangle_{k_\perp}$'); hold on; plot(kp_ip,ni00_kp, '^','DisplayName','$\langle|N_{i,k}^{00}|^2\rangle_{k_\perp}$'); hold on; @@ -435,19 +444,19 @@ plot(kp_ip,a1*kp_ip.^(-13/3),'-','DisplayName','$k^{-13/3}$'); plot(kp_ip,a2/100*kp_ip.^(-3)./(1+kp_ip.^2).^2,'-','DisplayName','$k^{-3}/(1+k^2)^2$'); set(gca, 'XScale', 'log');set(gca, 'YScale', 'log'); grid on xlabel('$k_\perp \rho_s$'); legend('show','Location','southwest') -title({['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... -', $L=',num2str(L),'$, $N=',num2str(Nr),'$'];[' $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... -' $\mu_{hd}=$',num2str(MU),', $',num2str(tstart),'<t<',num2str(tend),'$']}); +title({['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... +', $L=',num2str(L),'$, $N=',num2str(Nx),'$'];[' $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... +' $\mu_{hd}=$',num2str(MU)]}); xlim([0.1,10]); save_figure clear Z_rth phi_kp ni_kp Ti_kp end %% -t0 =000; +t0 =00; [~, it02D] = min(abs(Ts2D-t0)); [~, it05D] = min(abs(Ts5D-t0)); -skip_ = 5; +skip_ = 4; DELAY = 1e-3*skip_; FRAMES_2D = it02D:skip_:numel(Ts2D); FRAMES_5D = it05D:skip_:numel(Ts5D); @@ -543,48 +552,48 @@ if 0 %% phi kperp spectrum GIFNAME = ['phi2_kp',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; SCALING = 0; FIELD =log10(phi_kp_t); linestyle = '-'; FRAMES = FRAMES_2D; -X = kp_ip; T = Ts2D; YMIN = -20; YMAX = 10; XMIN = min(kr); XMAX = max(kr); +X = kp_ip; T = Ts2D; YMIN = -20; YMAX = 10; XMIN = min(kx); XMAX = max(kx); FIELDNAME = '$\log_{10}|\tilde\phi_k|^2$'; XNAME = '$k_r\rho_s$'; create_gif_1D end if 0 %% Density ion frequency GIFNAME = ['Ni00',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FRAMES = FRAMES_2D; -FIELD =ifftshift((abs(Ni00)),2); X = fftshift(KR,2); Y = fftshift(KZ,2); T = Ts2D; +FIELD =ifftshift((abs(Ni00)),2); X = fftshift(kx,2); Y = fftshift(ky,2); T = Ts2D; FIELDNAME = '$N_i^{00}$'; XNAME = '$k_r\rho_s$'; YNAME = '$k_z\rho_s$'; create_gif end if 0 %% Density electron frequency GIFNAME = ['Ne00',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FRAMES = FRAMES_2D; -FIELD =ifftshift((abs(Ne00)),2); X = fftshift(KR,2); Y = fftshift(KZ,2); T = Ts2D; +FIELD =ifftshift((abs(Ne00)),2); X = fftshift(kx,2); Y = fftshift(ky,2); T = Ts2D; FIELDNAME = '$N_e^{00}$'; XNAME = '$k_r\rho_s$'; YNAME = '$k_z\rho_s$'; create_gif end if 0 -%% kr vs P Si -GIFNAME = ['Sip0_kr',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; +%% kx vs P Si +GIFNAME = ['Sip0_kx',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; plt = @(x) squeeze(max((abs(x)),[],4)); -FIELD =plt(Sipj(:,1,:,:,:)); X = kr'; Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; +FIELD =plt(Sipj(:,1,:,:,:)); X = kx'; Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; FIELDNAME = '$N_i^{p0}$'; XNAME = '$k_{max}\rho_s$'; YNAME = '$P$, $\sum_z$'; create_gif_imagesc end if 0 -%% maxkz, kr vs p, for all Nipj over time -GIFNAME = ['Nipj_kr',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; +%% maxky, kx vs p, for all Nipj over time +GIFNAME = ['Nipj_kx',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; plt = @(x) squeeze(sum((abs(x)),4)); -FIELD = plt(Nipj); X = kr'; Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; +FIELD = plt(Nipj); X = kx'; Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; FIELDNAME = 'N_i'; XNAME = '$k_r\rho_s$'; YNAME = '$P$'; create_gif_5D end if 0 -%% maxkr, kz vs p, for all Nipj over time -GIFNAME = ['Nipj_kz',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; +%% maxkx, ky vs p, for all Nipj over time +GIFNAME = ['Nipj_ky',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; plt = @(x) fftshift(squeeze(sum((abs(x)),3)),3); -FIELD = plt(Nipj); X = sort(kz'); Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; +FIELD = plt(Nipj); X = sort(ky'); Y = Pi'; T = Ts5D; FRAMES = FRAMES_5D; FIELDNAME = 'N_i'; XNAME = '$k_z\rho_s$'; YNAME = '$P$, $\sum_r$'; create_gif_5D end %% -% ZF_fourier_analysis +ZF_fourier_analysis end \ No newline at end of file diff --git a/wk/analysis_3D.m b/wk/analysis_3D.m new file mode 100644 index 0000000000000000000000000000000000000000..6fc1d6678289c0e10f510e1d5a2039c9ed520d94 --- /dev/null +++ b/wk/analysis_3D.m @@ -0,0 +1,510 @@ +addpath(genpath('../matlab')) % ... add +for i_ = 1 +% for ETA_ =[0.6:0.1:0.9] +%% Load results +if 1% Local results +outfile =''; +outfile ='Blob_diffusion/100x50_L_60_P_2_J_1_eta_Inf_nu_1e-01_DGGK_mu_0e+00'; +% outfile ='test_3D/100x50x10_L_60_q0_1_P_2_J_1_eta_0.6_nu_1e-01_DGGK_mu_2e-03'; +% outfile ='test_3D/100x50_L_60_P_2_J_1_eta_0.6_nu_1e-01_DGGK_mu_0e+00'; + BASIC.RESDIR = ['../results/',outfile,'/']; + BASIC.MISCDIR = ['/misc/HeLaZ_outputs/results/',outfile,'/']; + CMD = ['cp ', BASIC.RESDIR,'outputs* ',BASIC.MISCDIR]; disp(CMD); + system(CMD); +end +if 0% Marconi results +outfile =''; +outfile =''; +outfile =''; +outfile =''; +outfile =''; +outfile =''; +BASIC.RESDIR = ['../',outfile(46:end-8),'/']; +BASIC.MISCDIR = ['/misc/HeLaZ_outputs/',outfile(46:end-8),'/']; +end + +%% +JOBNUMMIN = 00; JOBNUMMAX = 20; +compile_results_3D %Compile the results from first output found to JOBNUMMAX if existing + +%% Retrieving max polynomial degree and sampling info +Npe = numel(Pe); Nje = numel(Je); [JE,PE] = meshgrid(Je,Pe); +Npi = numel(Pi); Nji = numel(Ji); [JI,PI] = meshgrid(Ji,Pi); +Ns5D = numel(Ts5D); +Ns3D = numel(Ts3D); +% renaming and reshaping quantity of interest +Ts5D = Ts5D'; +Ts3D = Ts3D'; + +%% Build grids +Nkx = numel(kx); Nky = numel(ky); +[KY,KX] = meshgrid(ky,kx); +Lkx = max(kx)-min(kx); Lky = max(ky)-min(ky); +dkx = Lkx/(Nkx-1); dky = Lky/(Nky-1); +KPERP2 = KY.^2+KX.^2; +[~,ikx0] = min(abs(kx)); [~,iky0] = min(abs(ky)); + +Lk = max(Lkx,Lky); +Nx = max(Nkx,Nky); Ny = Nx; Nz = numel(z); +dx = 2*pi/Lk; dy = 2*pi/Lk; dz = q0*2*pi/Nz; +x = dx*(-Nx/2:(Nx/2-1)); Lx = max(x)-min(x); +y = dy*(-Ny/2:(Ny/2-1)); Ly = max(y)-min(y); +z = dz * (1:Nz); +[Y_XY,X_XY] = meshgrid(y,x); +[Z_XZ,X_XZ] = meshgrid(z,x); +[Z_YZ,Y_YZ] = meshgrid(z,y); + +%% Analysis %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +disp('Analysis :') +disp('- iFFT') +% IFFT (Lower case = real space, upper case = frequency space) +ne00 = zeros(Nx,Ny,Nz,Ns3D); % Gyrocenter density +ni00 = zeros(Nx,Ny,Nz,Ns3D); +dzTe = zeros(Nx,Ny,Nz,Ns3D); +dzTi = zeros(Nx,Ny,Nz,Ns3D); +dzni = zeros(Nx,Ny,Nz,Ns3D); +np_i = zeros(Nx,Ny,Nz,Ns5D); % Ion particle density +si00 = zeros(Nx,Ny,Nz,Ns5D); +phi = zeros(Nx,Ny,Nz,Ns3D); +dens_e = zeros(Nx,Ny,Nz,Ns3D); +dens_i = zeros(Nx,Ny,Nz,Ns3D); +temp_e = zeros(Nx,Ny,Nz,Ns3D); +temp_i = zeros(Nx,Ny,Nz,Ns3D); +drphi = zeros(Nx,Ny,Nz,Ns3D); +dzphi = zeros(Nx,Ny,Nz,Ns3D); +dr2phi = zeros(Nx,Ny,Nz,Ns3D); + +for it = 1:numel(Ts3D) + for iz = 1:numel(z) + NE_ = Ne00(:,:,iz,it); NI_ = Ni00(:,:,iz,it); PH_ = PHI(:,:,iz,it); + ne00(:,:,iz,it) = real(fftshift(ifft2((NE_),Nx,Ny))); + ni00(:,:,iz,it) = real(fftshift(ifft2((NI_),Nx,Ny))); + phi (:,:,iz,it) = real(fftshift(ifft2((PH_),Nx,Ny))); + drphi(:,:,iz,it) = real(fftshift(ifft2(1i*KX.*(PH_),Nx,Ny))); + dr2phi(:,:,iz,it)= real(fftshift(ifft2(-KX.^2.*(PH_),Nx,Ny))); + dzphi(:,:,iz,it) = real(fftshift(ifft2(1i*KY.*(PH_),Nx,Ny))); + if(W_DENS && W_TEMP) + DENS_E_ = DENS_E(:,:,iz,it); DENS_I_ = DENS_I(:,:,iz,it); + TEMP_E_ = TEMP_E(:,:,iz,it); TEMP_I_ = TEMP_I(:,:,iz,it); + dzni(:,:,iz,it) = real(fftshift(ifft2(1i*KY.*(DENS_I_),Nx,Ny))); + dzTe(:,:,iz,it) = real(fftshift(ifft2(1i*KY.*(TEMP_E_),Nx,Ny))); + dzTi(:,:,iz,it) = real(fftshift(ifft2(1i*KY.*(TEMP_I_),Nx,Ny))); + dens_e (:,:,iz,it) = real(fftshift(ifft2((DENS_E_),Nx,Ny))); + dens_i (:,:,iz,it) = real(fftshift(ifft2((DENS_I_),Nx,Ny))); + temp_e (:,:,iz,it) = real(fftshift(ifft2((TEMP_E_),Nx,Ny))); + temp_i (:,:,iz,it) = real(fftshift(ifft2((TEMP_I_),Nx,Ny))); + end + end +end + +Np_i = zeros(Nkx,Nky,Ns5D); % Ion particle density in Fourier space + +for it = 1:numel(Ts5D) + [~, it2D] = min(abs(Ts3D-Ts5D(it))); + Np_i(:,:,it) = 0; + for ij = 1:Nji + Kn = (KPERP2/2.).^(ij-1) .* exp(-KPERP2/2)/(factorial(ij-1)); + Np_i(:,:,it) = Np_i(:,:,it) + Kn.*squeeze(Nipj(1,ij,:,:,it)); + end + + np_i(:,:,it) = real(fftshift(ifft2(squeeze(Np_i(:,:,it)),Nx,Ny))); +end + +% Post processing +disp('- post processing') +% gyrocenter and particle flux from real space +GFlux_xi = zeros(1,Ns3D); % Gyrocenter flux Gamma = <ni drphi> +GFlux_yi = zeros(1,Ns3D); % Gyrocenter flux Gamma = <ni dzphi> +GFlux_xe = zeros(1,Ns3D); % Gyrocenter flux Gamma = <ne drphi> +GFlux_ye = zeros(1,Ns3D); % Gyrocenter flux Gamma = <ne dzphi> +% Hermite energy spectrum +epsilon_e_pj = zeros(Pe_max,Je_max,Ns5D); +epsilon_i_pj = zeros(Pi_max,Ji_max,Ns5D); + +phi_maxx_maxy = zeros(Nz,Ns3D); % Time evol. of the norm of phi +phi_avgx_maxy = zeros(Nz,Ns3D); % Time evol. of the norm of phi +phi_maxx_avg = zeros(Nz,Ns3D); % Time evol. of the norm of phi +phi_avgx_avgy = zeros(Nz,Ns3D); % Time evol. of the norm of phi + +shear_maxx_maxy = zeros(Nz,Ns3D); % Time evol. of the norm of shear +shear_avgx_maxy = zeros(Nz,Ns3D); % Time evol. of the norm of shear +shear_maxx_avgy = zeros(Nz,Ns3D); % Time evol. of the norm of shear +shear_avgx_avgy = zeros(Nz,Ns3D); % Time evol. of the norm of shear + +Ne_norm = zeros(Pe_max,Je_max,Ns5D); % Time evol. of the norm of Napj +Ni_norm = zeros(Pi_max,Ji_max,Ns5D); % . + +% Kperp spectrum interpolation +%full kperp points +kperp = reshape(sqrt(KX.^2+KY.^2),[numel(KX),1]); +% interpolated kperps +nk_noAA = floor(2/3*numel(kx)); +kp_ip = kx; +[thg, rg] = meshgrid(linspace(0,pi,2*nk_noAA),kp_ip); +[xn,yn] = pol2cart(thg,rg); +[ky_s, sortIdx] = sort(ky); +[xc,yc] = meshgrid(ky_s,kx); +phi_kp_t = zeros(numel(kp_ip),Nz,Ns3D); +% +for it = 1:numel(Ts3D) % Loop over 2D aX_XYays + for iz = 1:numel(z) + NE_ = Ne00(:,:,iz,it); NI_ = Ni00(:,:,iz,it); PH_ = PHI(:,:,iz,it); + phi_maxx_maxy(iz,it) = max( max(squeeze(phi(:,:,iz,it)))); + phi_avgx_maxy(iz,it) = max(mean(squeeze(phi(:,:,iz,it)))); + phi_maxx_avgy(iz,it) = mean( max(squeeze(phi(:,:,iz,it)))); + phi_avgx_avgy(iz,it) = mean(mean(squeeze(phi(:,:,iz,it)))); + + shear_maxx_maxy(iz,it) = max( max(squeeze(-(dr2phi(:,:,iz,it))))); + shear_avgx_maxy(iz,it) = max(mean(squeeze(-(dr2phi(:,:,iz,it))))); + shear_maxx_avgy(iz,it) = mean( max(squeeze(-(dr2phi(:,:,iz,it))))); + shear_avgx_avgy(iz,it) = mean(mean(squeeze(-(dr2phi(:,:,iz,it))))); + + GFlux_xi(iz,it) = sum(sum(ni00(:,:,iz,it).*dzphi(:,:,iz,it)))*dx*dy/Lx/Ly; + GFlux_yi(iz,it) = sum(sum(-ni00(:,:,iz,it).*drphi(:,:,iz,it)))*dx*dy/Lx/Ly; + GFlux_xe(iz,it) = sum(sum(ne00(:,:,iz,it).*dzphi(:,:,iz,it)))*dx*dy/Lx/Ly; + GFlux_ye(iz,it) = sum(sum(-ne00(:,:,iz,it).*drphi(:,:,iz,it)))*dx*dy/Lx/Ly; + + Z_rth = interp2(xc,yc,squeeze(mean((abs(PHI(:,sortIdx,iz,it))).^2,3)),xn,yn); + phi_kp_t(:,iz,it) = mean(Z_rth,2); + end +end +% +for it = 1:numel(Ts5D) % Loop over 5D aX_XYays + [~, it2D] = min(abs(Ts3D-Ts5D(it))); + Ne_norm(:,:,it)= sum(sum(abs(Nepj(:,:,:,:,it)),3),4)/Nkx/Nky; + Ni_norm(:,:,it)= sum(sum(abs(Nipj(:,:,:,:,it)),3),4)/Nkx/Nky; + epsilon_e_pj(:,:,it) = sqrt(pi)/2*sum(sum(abs(Nepj(:,:,:,:,it)).^2,3),4); + epsilon_i_pj(:,:,it) = sqrt(pi)/2*sum(sum(abs(Nipj(:,:,:,:,it)).^2,3),4); +end + +%% Compute primary instability growth rate +disp('- growth rate') +% Find max value of transport (end of linear mode) +[tmp,tmax] = max(GGAMMA_RI*(2*pi/Nx/Ny)^2); +[~,itmax] = min(abs(Ts3D-tmax)); +tstart = 0.1 * Ts3D(itmax); tend = 0.5 * Ts3D(itmax); +[~,its3D_lin] = min(abs(Ts3D-tstart)); +[~,ite3D_lin] = min(abs(Ts3D-tend)); + +g_I = zeros(Nkx,Nky,Nz); +for ikx = 1:Nkx + for iky = 1:Nky + for iz = 1:Nz + [g_I(ikx,iky,iz), ~] = LinearFit_s(Ts3D(its3D_lin:ite3D_lin),squeeze(abs(Ni00(ikx,iky,iz,its3D_lin:ite3D_lin)))); + end + end +end +[gmax_I,ikmax_I] = max(max(g_I(1,:,:),[],2),[],3); +kmax_I = abs(ky(ikmax_I)); +Bohm_transport = ETAB/ETAN*gmax_I/kmax_I^2; + +%% Compute secondary instability growth rate +disp('- growth rate') +% Find max value of transport (end of linear mode) +% [tmp,tmax] = max(GGAMMA_RI*(2*pi/Nx/Ny)^2); +% [~,itmax] = min(abs(Ts2D-tmax)); +% tstart = Ts2D(itmax); tend = 1.5*Ts2D(itmax); +[~,its3D_lin] = min(abs(Ts3D-tstart)); +[~,ite3D_lin] = min(abs(Ts3D-tend)); + +g_II = zeros(Nkx,Nky); +for ikx = 1:Nkx + for iky = 1 + for iz = 1:Nz + [g_II(ikx,iky,iz), ~] = LinearFit_s(Ts3D(its3D_lin:ite3D_lin),squeeze(abs(Ni00(ikx,iky,iz,its3D_lin:ite3D_lin)))); + end + end +end +[gmax_II,ikmax_II] = max(max(g_II(1,:,:),[],2),[],3); +kmax_II = abs(kx(ikmax_II)); + +%% PLOTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +default_plots_options +disp('Plots') +FMT = '.fig'; + +if 1 +%% Time evolutions and growth rate +fig = figure; FIGNAME = ['t_evolutions',sprintf('_%.2d',JOBNUM),'_',PARAMS]; +set(gcf, 'Position', [100, 100, 900, 800]) +subplot(111); + suptitle(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... + ' $\mu_{hd}=$',num2str(MU)]); + subplot(421); + for ip = 1:Pe_max + for ij = 1:Je_max + plt = @(x) squeeze(x(ip,ij,:)); + plotname = ['$N_e^{',num2str(ip-1),num2str(ij-1),'}$']; + clr = line_colors(min(ip,numel(line_colors(:,1))),:); + lstyle = line_styles(min(ij,numel(line_styles))); + semilogy(Ts5D,plt(Ne_norm),'DisplayName',plotname,... + 'Color',clr,'LineStyle',lstyle{1}); hold on; + end + end + grid on; ylabel('$\sum_{k_r,k_z}|N_e^{pj}|$'); + subplot(423) + for ip = 1:Pi_max + for ij = 1:Ji_max + plt = @(x) squeeze(x(ip,ij,:)); + plotname = ['$N_i^{',num2str(ip-1),num2str(ij-1),'}$']; + clr = line_colors(min(ip,numel(line_colors(:,1))),:); + lstyle = line_styles(min(ij,numel(line_styles))); + semilogy(Ts5D,plt(Ni_norm),'DisplayName',plotname,... + 'Color',clr,'LineStyle',lstyle{1}); hold on; + end + end + grid on; ylabel('$\sum_{k_r,k_z}|N_i^{pj}|$'); xlabel('$t c_s/R$') + subplot(222) + plot(Ts0D,GGAMMA_RI*(2*pi/Nx/Ny)^2); hold on; + plot(Ts0D,PGAMMA_RI*(2*pi/Nx/Ny)^2); + legend(['Gyro. flux';'Part. flux']); + grid on; xlabel('$t c_s/R$'); ylabel('$\Gamma_{r,i}$') + if(~isnan(max(max(g_I(1,:,:))))) + subplot(223) + plot(ky,max(g_I(1,:,:),[],3),'-','DisplayName','Primar. instability'); hold on; + plot(kx,max(g_II(:,1,:),[],3),'x-','DisplayName','Second. instability'); hold on; + plot([max(ky)*2/3,max(ky)*2/3],[0,10],'--k', 'DisplayName','2/3 Orszag AA'); + grid on; xlabel('$k\rho_s$'); ylabel('$\gamma R/c_s$'); legend('show'); + ylim([0,max(max(g_I(1,:,:)))]); xlim([0,max(ky)]); + shearplot = 426; phiplot = 428; + else + shearplot = 223; phiplot = 224; + end + subplot(shearplot) + plt = @(x) mean(x,1); + clr = line_colors(min(ip,numel(line_colors(:,1))),:); + lstyle = line_styles(min(ij,numel(line_styles))); + plot(Ts3D,plt(shear_maxx_maxy),'DisplayName','$\max_{r,z}(s)$'); hold on; + plot(Ts3D,plt(shear_maxx_avgy),'DisplayName','$\max_{r}\langle s \rangle_z$'); hold on; + plot(Ts3D,plt(shear_avgx_maxy),'DisplayName','$\max_{z}\langle s \rangle_r$'); hold on; + plot(Ts3D,plt(shear_avgx_avgy),'DisplayName','$\langle s \rangle_{r,z}$'); hold on; + grid on; xlabel('$t c_s/R$'); ylabel('$shear$'); + subplot(phiplot) + clr = line_colors(min(ip,numel(line_colors(:,1))),:); + lstyle = line_styles(min(ij,numel(line_styles))); + plot(Ts3D,plt(phi_maxx_maxy),'DisplayName','$\max_{r,z}(\phi)$'); hold on; + plot(Ts3D,plt(phi_maxx_avg),'DisplayName','$\max_{r}\langle\phi\rangle_z$'); hold on; + plot(Ts3D,plt(phi_avgx_maxy),'DisplayName','$\max_{z}\langle\phi\rangle_r$'); hold on; + plot(Ts3D,plt(phi_avgx_avgy),'DisplayName','$\langle\phi\rangle_{r,z}$'); hold on; + grid on; xlabel('$t c_s/R$'); ylabel('$E.S. pot$'); +save_figure +end + +if 1 +%% Space time diagramm (fig 11 Ivanov 2020) +TAVG = 5000; % Averaging time duration +%Compute steady radial transport +tend = Ts0D(end); tstart = tend - TAVG; +[~,its0D] = min(abs(Ts0D-tstart)); +[~,ite0D] = min(abs(Ts0D-tend)); +SCALE = (2*pi/Nx/Ny)^2; +gamma_infty_avg = mean(PGAMMA_RI(its0D:ite0D))*SCALE; +gamma_infty_std = std (PGAMMA_RI(its0D:ite0D))*SCALE; +% Compute steady shearing rate +tend = Ts3D(end); tstart = tend - TAVG; +[~,its2D] = min(abs(Ts3D-tstart)); +[~,ite2D] = min(abs(Ts3D-tend)); +shear_infty_avg = mean(mean(shear_maxx_avgy(:,its2D:ite2D),1)); +shear_infty_std = std (mean(shear_maxx_avgy(:,its2D:ite2D),1)); +% plots +fig = figure; FIGNAME = ['ZF_transport_drphi','_',PARAMS];set(gcf, 'Position', [100, 100, 1200, 600]) + subplot(311) +% yyaxis left + plot(Ts0D,PGAMMA_RI*SCALE,'DisplayName','$\langle n_i d\phi/dz \rangle_z$'); hold on; + plot(Ts0D(its0D:ite0D),ones(ite0D-its0D+1,1)*gamma_infty_avg, '-k',... + 'DisplayName',['$\Gamma^{\infty} = $',num2str(gamma_infty_avg),'$\pm$',num2str(gamma_infty_std)]); + grid on; set(gca,'xticklabel',[]); ylabel('$\Gamma_r$') + ylim([0,5*abs(gamma_infty_avg)]); xlim([Ts0D(1),Ts0D(end)]); + title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... + ' $\mu_{hd}=$',num2str(MU)]); + % + subplot(312) + clr = line_colors(1,:); + lstyle = line_styles(1); +% plt = @(x_) mean(x_,1); + plt = @(x_) x_(1,:); + plot(Ts3D,plt(shear_maxx_maxy),'DisplayName','$\max_{r,z}(s_\phi)$'); hold on; + plot(Ts3D,plt(shear_maxx_avgy),'DisplayName','$\max_{r}\langle s_\phi\rangle_z$'); hold on; + plot(Ts3D,plt(shear_avgx_maxy),'DisplayName','$\max_{z}\langle s_\phi\rangle_r$'); hold on; + plot(Ts3D,plt(shear_avgx_avgy),'DisplayName','$\langle s_\phi\rangle_{r,z}$'); hold on; + plot(Ts3D(its2D:ite2D),ones(ite2D-its2D+1,1)*shear_infty_avg, '-k',... + 'DisplayName',['$s^{\infty} = $',num2str(shear_infty_avg),'$\pm$',num2str(shear_infty_std)]); + ylim([0,shear_infty_avg*5.0]); xlim([Ts0D(1),Ts0D(end)]); + grid on; ylabel('Shear amp.');set(gca,'xticklabel',[]);% legend('show'); + subplot(313) + [TY,TX] = meshgrid(x,Ts3D); + pclr = pcolor(TX,TY,squeeze((mean(dr2phi(:,:,1,:),2)))'); set(pclr, 'edgecolor','none'); legend('Shear ($\langle \partial_r^2\phi\rangle_z$)') %colorbar; + caxis(1*shear_infty_avg*[-1 1]); xlabel('$t c_s/R$'), ylabel('$x/\rho_s$'); colormap(bluewhitered(256)) +save_figure +end + +if 0 +%% Space time diagramms +tstart = 0; tend = Ts3D(end); +[~,itstart] = min(abs(Ts3D-tstart)); +[~,itend] = min(abs(Ts3D-tend)); +trange = itstart:itend; +[TY,TX] = meshgrid(x,Ts3D(trange)); +fig = figure; FIGNAME = ['space_time','_',PARAMS];set(gcf, 'Position', [100, 100, 1200, 600]) + subplot(211) +% pclr = pcolor(TX,TY,squeeze(mean(dens_i(:,:,trange).*dzphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; + pclr = pcolor(TX,TY,squeeze(mean(ni00(:,:,trange).*dzphi(:,:,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; + shading interp + colormap hot; + caxis([0.0,0.05*max(max(mean(ni00(:,:,its2D:ite2D).*dzphi(:,:,its2D:ite2D),2)))]); + caxis([0.0,0.01]); c = colorbar; c.Label.String ='\langle n_i\partial_z\phi\rangle_z'; + xticks([]); ylabel('$x/\rho_s$') +% legend('Radial part. transport $\langle n_i\partial_z\phi\rangle_z$') + title(['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... + ' $\mu_{hd}=$',num2str(MU)]); + subplot(212) + pclr = pcolor(TX,TY,squeeze(mean(drphi(:,:,1,trange),2))'); set(pclr, 'edgecolor','none'); colorbar; + fieldmax = max(max(mean(abs(drphi(:,:,1,its2D:ite2D)),2))); + caxis([-fieldmax,fieldmax]); c = colorbar; c.Label.String ='\langle \partial_r\phi\rangle_z'; + xlabel('$t c_s/R$'), ylabel('$x/\rho_s$') +% legend('Zonal flow $\langle \partial_r\phi\rangle_z$') +save_figure +end + +if 0 +%% Averaged shear and Reynold stress profiles +trange = its2D:ite2D; +% trange = 100:200; +figure; +plt = @(x) squeeze(mean(mean(real(x(:,:,trange)),2),3))/max(abs(squeeze(mean(mean(real(x(:,:,trange)),2),3)))); +plot(r,plt(-dr2phi),'-k','DisplayName','Zonal shear'); hold on; +plot(r,plt(-drphi.*dzphi),'-','DisplayName','$\Pi_\phi$'); hold on; +% plot(r,plt(-drphi.*dzTe),'-','DisplayName','$\Pi_{Te}$'); hold on; +plot(r,plt(-drphi.*dzTi),'-','DisplayName','$\Pi_{Ti}$'); hold on; +plot(r,plt(-drphi.*dzphi-drphi.*dzTi),'-','DisplayName','$\Pi_\phi+\Pi_{Ti}$'); hold on; +% plot(r,plt(-drphi.*dzphi-drphi.*dzTi-drphi.*dzTe),'-','DisplayName','$\Pi_\phi+\Pi_{Te}+\Pi_{Ti}$'); hold on; +xlim([-L/2,L/2]); xlabel('$x/\rho_s$'); grid on; legend('show') +end + +if 0 +%% |phi_k|^2 spectra (Kobayashi 2015 fig 3) +tstart = 0.8*Ts3D(end); tend = Ts3D(end); +[~,itstart] = min(abs(Ts3D-tstart)); +[~,itend] = min(abs(Ts3D-tend)); +trange = itstart:itend; +%full kperp points +phi_k_2 = reshape(mean(mean(abs(PHI(:,:,:,trange)),3),4).^2,[numel(KX),1]); +kperp = reshape(sqrt(KX.^2+KY.^2),[numel(KX),1]); +% interpolated kperps +nk_noAA = floor(2/3*numel(kx)); +kp_ip = kx; +[thg, rg] = meshgrid(linspace(0,pi,2*nk_noAA),kp_ip); +[xn,yn] = pol2cart(thg,rg); +[ky_s, sortIdx] = sort(ky); +[xc,yc] = meshgrid(ky_s,kx); +Z_rth = interp2(xc,yc,squeeze(mean((abs(PHI(:,sortIdx,trange))).^2,3)),xn,yn); +phi_kp = mean(Z_rth,2); +Z_rth = interp2(xc,yc,squeeze(mean((abs(Ni00(:,sortIdx,trange))).^2,3)),xn,yn); +ni00_kp = mean(Z_rth,2); +Z_rth = interp2(xc,yc,squeeze(mean((abs(Ne00(:,sortIdx,trange))).^2,3)),xn,yn); +ne00_kp = mean(Z_rth,2); +%for theorical trends +a1 = phi_kp(2)*kp_ip(2).^(13/3); +a2 = phi_kp(2)*kp_ip(2).^(3)./(1+kp_ip(2).^2).^(-2); +fig = figure; FIGNAME = ['cascade','_',PARAMS];set(gcf, 'Position', [100, 100, 500, 500]) +% scatter(kperp,phi_k_2,'.k','MarkerEdgeAlpha',0.4,'DisplayName','$|\phi_k|^2$'); hold on; grid on; +plot(kp_ip,phi_kp,'^','DisplayName','$\langle|\phi_k|^2\rangle_{k_\perp}$'); hold on; +plot(kp_ip,ni00_kp, '^','DisplayName','$\langle|N_{i,k}^{00}|^2\rangle_{k_\perp}$'); hold on; +plot(kp_ip,ne00_kp, '^','DisplayName','$\langle|N_{e,k}^{00}|^2\rangle_{k_\perp}$'); hold on; +plot(kp_ip,a1*kp_ip.^(-13/3),'-','DisplayName','$k^{-13/3}$'); +plot(kp_ip,a2/100*kp_ip.^(-3)./(1+kp_ip.^2).^2,'-','DisplayName','$k^{-3}/(1+k^2)^2$'); +set(gca, 'XScale', 'log');set(gca, 'YScale', 'log'); grid on +xlabel('$k_\perp \rho_s$'); legend('show','Location','southwest') +title({['$\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... +', $L=',num2str(L),'$, $N=',num2str(Nx),'$'];[' $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... +' $\mu_{hd}=$',num2str(MU)]}); +xlim([0.1,10]); +save_figure +clear Z_rth phi_kp ni_kp Ti_kp +end + +if 0 +%% MOVIES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Options +t0 =00; iz = 1; ix = 1; iy = 1; +skip_ = 1; DELAY = 1e-2*skip_; +[~, it03D] = min(abs(Ts3D-t0)); FRAMES_3D = it03D:skip_:numel(Ts3D); +[~, it05D] = min(abs(Ts5D-t0)); FRAMES_5D = it05D:skip_:numel(Ts5D); +INTERP = 0; T = Ts3D; FRAMES = FRAMES_3D; +% Field to plot +FIELD = dens_e; NAME = 'ne'; FIELDNAME = 'n_e'; +% FIELD = dens_i; NAME = 'ni'; FIELDNAME = 'n_i'; +% FIELD = temp_e; NAME = 'Te'; FIELDNAME = 'n_i'; +% FIELD = temp_i; NAME = 'Ti'; FIELDNAME = 'n_i'; +% FIELD = ne00; NAME = 'ne00'; FIELDNAME = 'n_e^{00}'; +% FIELD = ni00; NAME = 'ni00'; FIELDNAME = 'n_i^{00}'; +% Slice +% plt = @(x) real(x(ix, :, :,:)); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; +% plt = @(x) real(x( :,iy, :,:)); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; +plt = @(x) real(x( :, :,iz,:)); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; + +% Averaged +% plt = @(x) mean(x,1); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; +% plt = @(x) mean(x,2); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; +% plt = @(x) mean(x,3); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; + +FIELD = squeeze(plt(FIELD)); + +% Naming +GIFNAME = [NAME,sprintf('_%.2d',JOBNUM),'_',PARAMS]; + +% Create movie (gif or mp4) +create_gif +% create_mov +end + +if 0 +%% Photomaton : real space + +% Chose the field to plot +% FIELD = ni00; FNAME = 'ni00'; FIELDLTX = 'n_i^{00}'; +% FIELD = ne00; FNAME = 'ne00'; FIELDLTX = 'n_e^{00}' +% FIELD = dens_i; FNAME = 'ni'; FIELDLTX = 'n_i'; +% FIELD = dens_e; FNAME = 'ne'; FIELDLTX = 'n_e'; +% FIELD = temp_i; FNAME = 'Ti'; FIELDLTX = 'T_i'; +% FIELD = temp_e; FNAME = 'Te'; FIELDLTX = 'T_e'; +FIELD = phi; FNAME = 'phi'; FIELDLTX = '\phi'; + +% Chose when to plot it +tf = [0 1 2 3]; + +% Slice +ix = 1; iy = 1; iz = 1; +% plt = @(x,it) real(x(ix, :, :,it)); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; FIELDLTX = [FIELDLTX,'(x=',num2str(round(x(ix))),')'] +% plt = @(x,it) real(x( :,iy, :,it)); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; FIELDLTX = [FIELDLTX,'(y=',num2str(round(y(iy))),')'] +% plt = @(x,it) real(x( :, :,iz,it)); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; FIELDLTX = [FIELDLTX,'(x=',num2str(round(z(iz))),')'] + +% Averaged +% plt = @(x,it) mean(x(:,:,:,it),1); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_x'] +% plt = @(x,it) mean(x(:,:,:,it),2); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_y'] +plt = @(x,it) mean(x(:,:,:,it),3); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_z'] + + +% +TNAME = []; +fig = figure; FIGNAME = [FNAME,TNAME,'_snaps','_',PARAMS]; set(gcf, 'Position', [100, 100, 1500, 350]) +plt_2 = @(x) x./max(max(x)); + for i_ = 1:numel(tf) + [~,it] = min(abs(Ts3D-tf(i_))); TNAME = [TNAME,'_',num2str(Ts3D(it))]; + subplot(1,numel(tf),i_) + DATA = plt_2(squeeze(plt(FIELD,it))); + pclr = pcolor((X),(Y),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) + colormap(bluewhitered); caxis([-1,1]); + xlabel(latexize(XNAME)); ylabel(latexize(YNAME));set(gca,'ytick',[]); + title(sprintf('$t c_s/R=%.0f$',Ts3D(it))); + end + legend(latexize(FIELDLTX)); +save_figure +end + +%% +% ZF_fourier_analysis +end \ No newline at end of file diff --git a/wk/compile_cosolver_mat.m b/wk/compile_cosolver_mat.m index 983d661850673082c72d87ad101db4867481438c..7b2310dd0556e38a05b6b6a1f155383d9735d95c 100644 --- a/wk/compile_cosolver_mat.m +++ b/wk/compile_cosolver_mat.m @@ -1,14 +1,14 @@ addpath(genpath('../matlab')) % ... add %% Grid configuration -N = 200; % Frequency gridpoints (Nkr = N/2) +N = 200; % Frequency gridpoints (Nkx = N/2) L = 120; % Size of the squared frequency domain dk = 2.*pi/L; kmax = N/2*dk; -kr = dk*(0:N/2); -kz = dk*(0:N/2); -[KZ, KR]= meshgrid(kz,kr); -KPERP = sqrt(KR.^2 + KZ.^2); -kperp = reshape(KPERP,[1,numel(kr)^2]); +kx = dk*(0:N/2); +ky = dk*(0:N/2); +[ky, kx]= meshgrid(ky,kx); +KPERP = sqrt(kx.^2 + ky.^2); +kperp = reshape(KPERP,[1,numel(kx)^2]); kperp = uniquetol(kperp,1e-14); Nperp = numel(kperp); %% Model diff --git a/wk/compute_collision_mat.m b/wk/compute_collision_mat.m index a429236ee9d6dd6d6816c4e33a446120b7778bd4..ac5214c15838a5ea489ab1a71fb08f016696d6b5 100644 --- a/wk/compute_collision_mat.m +++ b/wk/compute_collision_mat.m @@ -1,14 +1,14 @@ addpath(genpath('../matlab')) % ... add %% Grid configuration -N = 200; % Frequency gridpoints (Nkr = N/2) +N = 200; % Frequency gridpoints (Nkx = N/2) L = 120; % Size of the squared frequency domain dk = 2.*pi/L; kmax = N/2*dk; -kr = dk*(0:N/2); -kz = dk*(0:N/2); -[KZ, KR]= meshgrid(kz,kr); -KPERP = sqrt(KR.^2 + KZ.^2); -kperp = reshape(KPERP,[1,numel(kr)^2]); +kx = dk*(0:N/2); +ky = dk*(0:N/2); +[ky, kx]= meshgrid(ky,kx); +KPERP = sqrt(kx.^2 + ky.^2); +kperp = reshape(KPERP,[1,numel(kx)^2]); kperp = uniquetol(kperp,1e-14); Nperp = numel(kperp); %% Model diff --git a/wk/continue_multiple_runs_marconi.m b/wk/continue_multiple_runs_marconi.m index 0e701e36ee5c8c0123b432a56cf4c076e6e44a29..47f91c36798a46e241c443e08f13445d10f49ffe 100644 --- a/wk/continue_multiple_runs_marconi.m +++ b/wk/continue_multiple_runs_marconi.m @@ -1,5 +1,5 @@ %% Paste the list of continue_run calls -continue_run('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/300x150_L_100_P_10_J_5_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt') +continue_run('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-02_SGGK_CLOS_0_mu_1e-02/out.txt') %% Functions to modify preexisting fort.90 input file and launch on marconi function [] = continue_run(outfilename) @@ -10,8 +10,8 @@ function [] = continue_run(outfilename) if(strcmp(CLUSTER.PART,'dbg')); CLUSTER.TIME = '00:30:00'; end; CLUSTER.MEM = '64GB'; % Memory CLUSTER.JNAME = 'HeLaZ';% Job name - NP_P = 3; % MPI processes along p - NP_KX = 32; % MPI processes along kx + NP_P = 2; % MPI processes along p + NP_KX = 24; % MPI processes along kx % Compute processes distribution Ntot = NP_P * NP_KX; Nnodes = ceil(Ntot/48); @@ -44,36 +44,33 @@ function [] = continue_run(outfilename) line = A{35}; line = line(end-2:end); if(line(1) == '='); line = line(end); end; - J2L = str2num(line)+1; + J2L = str2num(line) + 1; end % Change job 2 load in fort.90 A{35} = [' job2load = ',num2str(J2L)]; disp(A{35}) % Change time step - line_= A{3}; dt_old = str2num(line_(12:end)); - A{3} = [' dt = ',num2str(1.5*dt_old)]; + A{3} = [' dt = 0.005']; % Increase endtime - A{4} = [' tmax = 20000']; + A{4} = [' tmax = 10000']; % Put non linear term back - line_= A{41}; NL_old = str2num(line_(13:end)); - A{41} = [' NL_CLOS = ',num2str(NL_old)]; -% A{41} = [' NL_CLOS = -1']; + A{41} = [' NL_CLOS = -1']; % change HD - line_= A{43}; mu_old = str2num(line_(13:end)); - A{43} = [' mu = ',num2str(0*mu_old)]; - % change N - line_= A{13}; N_old = str2num(line_(8:end)); - A{13} = [' Nr = ',num2str(N_old)]; - A{15} = [' Nz = ',num2str(N_old)]; + line_= A{43}; + mu_old = str2num(line_(13:end)); + A{43} = [' mu = ',num2str(mu_old*2)]; % change L - line_= A{14}; L_old = str2num(line_(8:end)); - A{14} = [' Lr = ',num2str(L_old)]; - A{16} = [' Lz = ',num2str(L_old)]; + line_= A{14}; + L_old = str2num(line_(8:end)); + A{14} = [' Lx = ',num2str(L_old)]; + A{16} = [' Ly = ',num2str(L_old)]; % change eta N - line_= A{53}; etan_old = str2num(line_(13:end)); + line_= A{53}; + etan_old = str2num(line_(13:end)); A{53} = [' eta_n = ',num2str(etan_old)]; % change eta B - line_= A{55}; etab_old = str2num(line_(13:end)); + line_= A{55}; + etab_old = str2num(line_(13:end)); A{55} = [' eta_B = ',num2str(etab_old)]; % Rewrite fort.90 fid = fopen('fort.90', 'w'); diff --git a/wk/daint_run.m b/wk/daint_run.m index e7f53ac38e507fb62cab04859b3b75aed3b983cc..95806c96bdeb2983e39b1a04085193192006852e 100644 --- a/wk/daint_run.m +++ b/wk/daint_run.m @@ -6,7 +6,7 @@ addpath(genpath('../matlab')) % ... add %% CLUSTER PARAMETERS CLUSTER.TIME = '24:00:00'; % allocation time hh:mm:ss NP_P = 2; % MPI processes along p -NP_KR = 18; % MPI processes along kr +NP_KX = 18; % MPI processes along kx CLUSTER.PART = 'normal'; % debug or normal if(strcmp(CLUSTER.PART,'debug')); CLUSTER.TIME = '00:30:00'; end; CLUSTER.MEM = '12GB'; % Memory @@ -18,7 +18,7 @@ NU = 0.1; % Collision frequency ETAB = 0.6; % Magnetic gradient NU_HYP = 1.0; % Hyperdiffusivity coefficient %% GRID PARAMETERS -N = 200; % Frequency gridpoints (Nkr = N/2) +N = 200; % Frequency gridpoints (Nkx = N/2) L = 120; % Size of the squared frequency domain P = 12; % Electron and Ion highest Hermite polynomial degree J = 06; % Electron and Ion highest Laguerre polynomial degree @@ -38,7 +38,7 @@ SIMID = ['HeLaZ_v2.5_eta_',num2str(ETAB),'_nu_%0.0e']; % Name of the simulati % SIMID = 'test_marconi_sugama'; % Name of the simulation SIMID = sprintf(SIMID,NU); PREFIX =[]; -% PREFIX = sprintf('%d_%d_',NP_P, NP_KR); +% PREFIX = sprintf('%d_%d_',NP_P, NP_KX); % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Full Couloumb ; +/- for GK/DK) CO = 1; CLOS = 0; % Closure model (0: =0 truncation, 1: semi coll, 2: Copy closure J+1 = J, P+2 = P) @@ -55,11 +55,11 @@ W_SAPJ = 0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% fixed parameters (for current study) -KR0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. -KREQ0 = 0; % put kr = 0 +KX0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. +KXEQ0 = 0; % put kx = 0 KPAR = 0.0; % Parellel wave vector component LAMBDAD = 0.0; -NON_LIN = 1 *(1-KREQ0); % activate non-linearity (is cancelled if KREQ0 = 1) +NON_LIN = 1 *(1-KXEQ0); % activate non-linearity (is cancelled if KXEQ0 = 1) PMAXE = P; % Highest electron Hermite polynomial degree JMAXE = J; % Highest '' Laguerre '' PMAXI = P; % Highest ion Hermite polynomial degree @@ -72,11 +72,11 @@ ETAT = 0.0; % Temperature gradient ETAN = 1.0; % Density gradient TAU = 1.0; % e/i temperature ratio % Compute processes distribution -Ntot = NP_P * NP_KR; +Ntot = NP_P * NP_KX; Nnodes = ceil(Ntot/36); Nppn = Ntot/Nnodes; CLUSTER.NODES = num2str(Nnodes); % MPI process along p -CLUSTER.NTPN = num2str(Nppn); % MPI process along kr +CLUSTER.NTPN = num2str(Nppn); % MPI process along kx CLUSTER.CPUPT = '1'; % CPU per task CLUSTER.NTPC = '1'; % N tasks per core (openmp threads) %% Run file management scripts @@ -84,6 +84,6 @@ setup write_sbash_daint system('rm fort.90 setup_and_run.sh batch_script.sh'); disp('done'); -if(mod(NP_P*NP_KR,36)~= 0) +if(mod(NP_P*NP_KX,36)~= 0) disp('WARNING : unused cores (ntot cores must be a 36 multiple)'); end \ No newline at end of file diff --git a/wk/fig_post_processing.m b/wk/fig_post_processing.m index 1479162b8055556e8227399b363e4da794d4fb12..e51be5273ac9e66874f84050ffbb6185da7d4ea1 100644 --- a/wk/fig_post_processing.m +++ b/wk/fig_post_processing.m @@ -37,7 +37,7 @@ Results_150x75.P = [2, 4, 6, 2, 4, 6 Results_150x75.J = [1, 2, 3 1 2 3 4 1, 2, 3 1, 2, 3 4 1, 2 5]; Results_150x75.etaB = [0.49, 0.49 0.49 0.59 0.59 0.59 0.59 0.50, 0.50 0.50 0.60, 0.60 0.60 0.60 0.51 0.51 0.51]; Results_150x75.nu = [1.0, 1.0 1.0 1.0 1.0 1.0 1.0 0.5, 0.5 0.5 0.5, 0.5 0.5 0.5 0.1 0.1 0.1]; -Results_150x75.mrkr = [ '*', '*', '*', '*', '*', '*', '*', 'o', 'o', 'o', 'o', 'o', 'o', 'o' 's' 's' 's']; +Results_150x75.mrkx = [ '*', '*', '*', '*', '*', '*', '*', 'o', 'o', 'o', 'o', 'o', 'o', 'o' 's' 's' 's']; Results_150x75.iclr = [ 1, 2, 3, 1 2 3 4 1, 2, 3 1, 2, 3 4 1 2 5]; % Ricci_Rogers.Gamma = [2 1e-1]; @@ -61,7 +61,7 @@ plot(10,10,'sk','MarkerSize',10, 'LineWidth',1.0); res = Results_150x75; for i = 1:numel(res.Gamma) errorbar(res.etaB(i),res.Gamma(i)*SCALING,res.error(i)*SCALING,... - res.mrkr(i),'DisplayName','256x128', 'color', line_colors(res.iclr(i),:),... + res.mrkx(i),'DisplayName','256x128', 'color', line_colors(res.iclr(i),:),... 'MarkerSize',12, 'LineWidth',2.0); hold on; end diff --git a/wk/flux_results.m b/wk/flux_results.m index 22f77dcb088df5e0a6bbef7afa4cb7a2132a2906..594b3b62b5a69226a163cfca70774bd147354d6c 100644 --- a/wk/flux_results.m +++ b/wk/flux_results.m @@ -17,7 +17,7 @@ Results_256x128.L = [ 66, 66, 66, 50, 66, 66, 66, 66, 66, Results_256x128.P = [ 2, 3, 4, 5, 2, 3, 4, 2, 3, 4]; Results_256x128.J = [ 1, 2, 2, 3, 1, 2, 2, 1, 2, 2]; Results_256x128.etaB = [ 0.5, 0.5, 0.5, 0.5, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6]; -Results_256x128.mrkr = [ 'v', '>', '^', 'o', 'v', '>', '^', 'v', '>', '^']; +Results_256x128.mrkx = [ 'v', '>', '^', 'o', 'v', '>', '^', 'v', '>', '^']; Results_256x128.clr = [ 'k', 'k', 'k', 'r', 'r', 'r', 'r', 'k', 'k', 'k']; % Low definition results (128x64) % Results_128x64.Gamma = [0.29, 0.05, 7e-4, 0.31, 3.7, 2e-3]; @@ -26,7 +26,7 @@ Results_256x128.clr = [ 'k', 'k', 'k', 'r', 'r', 'r', 'r', 'k', 'k', % Results_128x64.J = [ 1, 1, 1, 1, 1, 1]; % Results_128x64.NU = [0.01, 0.1, 0.01, 0.01, 0.01, 0.01]; % Results_128x64.etaB = [ 0.5, 0.5, 0.67, 0.5 0.4, 0.6]; -% Results_128x64.mrkr = [ 's', 's', 's', 's', 's', 's']; +% Results_128x64.mrkx = [ 's', 's', 's', 's', 's', 's']; % Results_128x64.clr = [ 'b', 'b', 'b', 'r', 'r', 'r']; % Ricci_Rogers.Gamma = [2.5 1 1e-2]; @@ -41,14 +41,14 @@ hold on; res = Results_256x128; for i = 1:numel(res.Gamma) semilogy(res.etaB(i),res.Gamma(i)*SCALING,... - res.mrkr(i),'DisplayName','256x128', 'color', res.clr(i)); + res.mrkx(i),'DisplayName','256x128', 'color', res.clr(i)); hold on; end % res = Results_128x64; % for i = 1:numel(res.Gamma) % if res.NU(i) == 0.01 % semilogy(res.etaB(i),res.Gamma(i),... -% res.mrkr(i),'DisplayName','128x64', 'color', res.clr(i)); +% res.mrkx(i),'DisplayName','128x64', 'color', res.clr(i)); % end % hold on; % end @@ -67,7 +67,7 @@ Results_256x128.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, Results_256x128.P = [ 2, 3, 4, 2, 3, 4, 2, 3, 4, 4]; Results_256x128.J = [ 1, 2, 2, 1, 2, 2, 1, 2, 2, 2]; Results_256x128.etaB = [ 0.5, 0.5, 0.5, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.7]; -Results_256x128.mrkr = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; +Results_256x128.mrkx = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; Results_256x128.clr = [ 'k', 'k', 'k', 'b', 'b', 'b', 'r', 'b', 'r', 'r']; % Ricci_Rogers.Gamma = [2 1e-1]; @@ -84,7 +84,7 @@ hold on; res = Results_256x128; for i = 1:numel(res.Gamma) semilogy(res.etaB(i),res.Gamma(i)*SCALING,... - res.mrkr(i),'DisplayName','256x128', 'color', res.clr(i)); + res.mrkx(i),'DisplayName','256x128', 'color', res.clr(i)); hold on; end @@ -104,7 +104,7 @@ Results_256x128.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, Results_256x128.P = [ 2, 3, 4, 2, 3, 4, 2, 3, 4, 4]; Results_256x128.J = [ 1, 2, 2, 1, 2, 2, 1, 2, 2, 2]; Results_256x128.etaB = [ 0.5, 0.5, 0.5, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.7]; -Results_256x128.mrkr = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; +Results_256x128.mrkx = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; Results_256x128.clr = [ 'k', 'k', 'k', 'b', 'b', 'b', 'r', 'b', 'r', 'r']; % Ricci_Rogers.Gamma = [2 1e-1]; @@ -121,7 +121,7 @@ hold on; res = Results_256x128; for i = 1:numel(res.Gamma) semilogy(res.etaB(i),res.Gamma(i)*SCALING,... - res.mrkr(i),'DisplayName','256x128', 'color', res.clr(i)); + res.mrkx(i),'DisplayName','256x128', 'color', res.clr(i)); hold on; end @@ -140,7 +140,7 @@ Results_150x75.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, Results_150x75.P = [ 2, 3, 4, 2, 3, 4, 2, 3, 4, 4]; Results_150x75.J = [ 1, 2, 2, 1, 2, 2, 1, 2, 2, 2]; Results_150x75.etaB = [ 0.5, 0.5, 0.5, 0.4, 0.4, 0.4, 0.6, 0.6, 0.6, 0.7]; -Results_150x75.mrkr = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; +Results_150x75.mrkx = [ 'v', '>', '^', 'v', '>', '^', 'v', '>', '^', '^']; Results_150x75.clr = [ 'k', 'k', 'k', 'b', 'b', 'b', 'r', 'b', 'r', 'r']; % Ricci_Rogers.Gamma = [2 1e-1]; @@ -157,7 +157,7 @@ hold on; res = Results_150x75; for i = 1:numel(res.Gamma) semilogy(res.etaB(i),res.Gamma(i)*SCALING,... - res.mrkr(i),'DisplayName','256x128', 'color', res.clr(i)); + res.mrkx(i),'DisplayName','256x128', 'color', res.clr(i)); hold on; end diff --git a/wk/izar_run.m b/wk/izar_run.m index 168f69119533870ef2d1969292e55d081c83b8e9..035adff386eabe7702c1f1d0c5c6ba7f28c4ebdf 100644 --- a/wk/izar_run.m +++ b/wk/izar_run.m @@ -9,14 +9,14 @@ CLUSTER.PART = 'gpu'; % debug/gpu CLUSTER.MEM = '4G'; % Memory CLUSTER.JNAME = 'gamma_inf';% Job name NP_P = 1; % MPI processes along p (nodes) -NP_KR = 20; % MPI processes along kr (cpu) +NP_KX = 20; % MPI processes along kx (cpu) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS NU = 0.1; % Collision frequency ETAB = 0.6; % Magnetic gradient NU_HYP = 1.0; % Hyperdiffusivity coefficient %% GRID PARAMETERS -N = 50; % Frequency gridpoints (Nkr = N/2) +N = 50; % Frequency gridpoints (Nkx = N/2) L = 10; % Size of the squared frequency domain P = 04; % Electron and Ion highest Hermite polynomial degree J = 04; % Electron and Ion highest Laguerre polynomial degree @@ -36,7 +36,7 @@ JOB2LOAD= 0; % SIMID = sprintf(SIMID,NU); SIMID = 'izar_setup'; % Name of the simulation PREFIX =[]; -% PREFIX = sprintf('%d_%d_',NP_P, NP_KR); +% PREFIX = sprintf('%d_%d_',NP_P, NP_KX); % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Full Couloumb ; +/- for GK/DK) CO = 1; CLOS = 0; % Closure model (0: =0 truncation, 1: semi coll, 2: Copy closure J+1 = J, P+2 = P) @@ -53,11 +53,11 @@ W_SAPJ = 0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% fixed parameters (for current study) -KR0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. -KREQ0 = 0; % put kr = 0 +KX0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. +KXEQ0 = 0; % put kx = 0 KPAR = 0.0; % Parellel wave vector component LAMBDAD = 0.0; -NON_LIN = 1 *(1-KREQ0); % activate non-linearity (is cancelled if KREQ0 = 1) +NON_LIN = 1 *(1-KXEQ0); % activate non-linearity (is cancelled if KXEQ0 = 1) PMAXE = P; % Highest electron Hermite polynomial degree JMAXE = J; % Highest '' Laguerre '' PMAXI = P; % Highest ion Hermite polynomial degree @@ -70,17 +70,17 @@ ETAT = 0.0; % Temperature gradient ETAN = 1.0; % Density gradient TAU = 1.0; % e/i temperature ratio % Compute processes distribution -Ntot = NP_P * NP_KR; +Ntot = NP_P * NP_KX; Nnodes = ceil(Ntot/48); Nppn = Ntot/Nnodes; CLUSTER.NODES = num2str(Nnodes); % MPI process along p -CLUSTER.NTPN = num2str(Nppn); % MPI process along kr +CLUSTER.NTPN = num2str(Nppn); % MPI process along kx CLUSTER.CPUPT = '1'; % CPU per task %% Run file management scripts setup write_sbash_izar system('rm fort.90 setup_and_run.sh batch_script.sh'); disp('done'); -if(mod(NP_P*NP_KR,20)~= 0) +if(mod(NP_P*NP_KX,20)~= 0) disp('WARNING : unused cores (ntot cores must be a 20 multiple)'); end \ No newline at end of file diff --git a/wk/linear_study.m b/wk/linear_study.m index 5838766da09c7996132387840cd9695fc4f6b566..223568a489b73a0e297071d4abaeeb37c6693a64 100644 --- a/wk/linear_study.m +++ b/wk/linear_study.m @@ -1,5 +1,5 @@ -for NU = [0.14] -for ETAB = [1/1.4] +for NU = [0.01] +for ETAN = [2.0] for CO = [3] %clear all; addpath(genpath('../matlab')) % ... add @@ -11,24 +11,24 @@ CLUSTER.TIME = '99:00:00'; % allocation time hh:mm:ss %% PHYSICAL PARAMETERS % NU = 1.0; % Collision frequency TAU = 1.0; % e/i temperature ratio -% ETAB = 0.5; -ETAN = 1.0; % Density gradient +ETAB = 1.0; +% ETAN = ETAN; % Density gradient ETAT = 0.0; % Temperature gradient NU_HYP = 0.0; % Hyperdiffusivity coefficient LAMBDAD = 0.0; NOISE0 = 1.0e-5; %% GRID PARAMETERS -N = 50; % Frequency gridpoints (Nkr = N/2) +N = 50; % Frequency gridpoints (Nkx = N/2) L = 100; % Size of the squared frequency domain -KREQ0 = 1; % put kr = 0 +KXEQ0 = 1; % put kx = 0 MU_P = 0.0; % Hermite hyperdiffusivity -mu_p*(d/dvpar)^4 f MU_J = 0.0; % Laguerre hyperdiffusivity -mu_j*(d/dvperp)^4 f %% TIME PARMETERS -TMAX = 100; % Maximal time unit +TMAX = 200; % Maximal time unit DT = 1e-2; % Time step SPS0D = 1; % Sampling per time unit for 2D arrays SPS2D = 1; % Sampling per time unit for 2D arrays -SPS5D = 1/200; % Sampling per time unit for 5D arrays +SPS5D = 1/50; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints RESTART = 0; % To restart from last checkpoint JOB2LOAD= 00; @@ -36,7 +36,7 @@ JOB2LOAD= 00; % SIMID = 'v2.7_lin_analysis'; % Name of the simulation SIMID = 'kobayashi_2015_fig2'; % Name of the simulation % SIMID = 'v2.6_lin_analysis'; % Name of the simulation -NON_LIN = 0 *(1-KREQ0); % activate non-linearity (is cancelled if KREQ0 = 1) +NON_LIN = 0 *(1-KXEQ0); % activate non-linearity (is cancelled if KXEQ0 = 1) % Collision operator % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Full Couloumb ; +/- for GK/DK) % CO = 2; @@ -68,11 +68,11 @@ MU = NU_HYP/(HD_CO*kmax)^4 % Hyperdiffusivity coefficient %% PARAMETER SCANS if 1 %% Parameter scan over PJ -PA = [2, 6, 10]; -JA = [1, 3, 5]; -% PA = [2 4]; -% JA = [1 2]; -DTA= DT./sqrt(JA)/4; +% PA = [2 4 6 10]; +% JA = [1 2 3 5]; +PA = [2]; +JA = [1]; +DTA= DT*ones(size(JA));%./sqrt(JA); % DTA= DT; mup_ = MU_P; muj_ = MU_J; @@ -101,20 +101,20 @@ for i = 1:Nparam tend = Ts2D(end); tstart = 0.4*tend; [~,itstart] = min(abs(Ts2D-tstart)); [~,itend] = min(abs(Ts2D-tend)); - for ikr = 1:N/2+1 - gamma_Ni00(i,ikr) = (LinearFit_s(Ts2D(itstart:itend)',(squeeze(abs(Ni00(ikr,1,itstart:itend)))))); - Ni00_ST(i,ikr,1:numel(Ts2D)) = squeeze((Ni00(ikr,1,:))); + for ikx = 1:N/2+1 + gamma_Ni00(i,ikx) = (LinearFit_s(Ts2D(itstart:itend)',(squeeze(abs(Ni00(ikx,1,itstart:itend)))))); + Ni00_ST(i,ikx,1:numel(Ts2D)) = squeeze((Ni00(ikx,1,:))); end tend = Ts5D(end); tstart = 0.4*tend; [~,itstart] = min(abs(Ts5D-tstart)); [~,itend] = min(abs(Ts5D-tend)); - for ikr = 1:N/2+1 - gamma_Nipj(i,ikr) = LinearFit_s(Ts5D(itstart:itend)',squeeze(max(max(abs(Nipj(:,:,ikr,1,itstart:itend)),[],1),[],2))); + for ikx = 1:N/2+1 + gamma_Nipj(i,ikx) = LinearFit_s(Ts5D(itstart:itend)',squeeze(max(max(abs(Nipj(:,:,ikx,1,itstart:itend)),[],1),[],2))); end gamma_Ni00(i,:) = real(gamma_Ni00(i,:) .* (gamma_Ni00(i,:)>=0.0)); gamma_Nipj(i,:) = real(gamma_Nipj(i,:) .* (gamma_Nipj(i,:)>=0.0)); -% kzmax = abs(kr(ikzmax)); -% Bohm_transport(i) = ETAB/ETAN*gmax/kzmax^2; +% kymax = abs(kx(ikymax)); +% Bohm_transport(i) = ETAB/ETAN*gmax/kymax^2; % Clean output system(['rm -r ',BASIC.RESDIR]); end @@ -128,14 +128,14 @@ plt = @(x) x; for i = 1:Nparam clr = line_colors(mod(i-1,numel(line_colors(:,1)))+1,:); linestyle = line_styles(floor((i-1)/numel(line_colors(:,1)))+1); - semilogx(plt(SCALE*kr(2:numel(kr))),plt(gamma_Ni00(i,2:end)),... + semilogx(plt(SCALE*kx(2:numel(kx))),plt(gamma_Ni00(i,2:end)),... 'Color',clr,... 'LineStyle',linestyle{1},'Marker','^',... - 'DisplayName',['$\eta_B=',num2str(ETAB),'$, $\nu_{',CONAME,'}=',num2str(NU),'$, $P=',num2str(PA(i)),'$, $J=',num2str(JA(i)),'$']); + 'DisplayName',['$\eta=',num2str(ETAB/ETAN),'$, $\nu_{',CONAME,'}=',num2str(NU),'$, $P=',num2str(PA(i)),'$, $J=',num2str(JA(i)),'$']); hold on; end - grid on; xlabel('$k_z\rho_s^{R}$'); ylabel('$\gamma(N_i^{00})L_\perp/c_s$'); xlim([0.0,max(kr)]); - title(['$\eta_B=',num2str(ETAB),'$, $\nu_{',CONAME,'}=',num2str(NU),'$']) + grid on; xlabel('$k_z\rho_s^{R}$'); ylabel('$\gamma(N_i^{00})L_\perp/c_s$'); xlim([0.0,max(kx)]); + title(['$\eta=',num2str(ETAB/ETAN),'$, $\nu_{',CONAME,'}=',num2str(NU),'$']) legend('show'); xlim([0.01,10]) saveas(fig,[SIMDIR,'gamma_Ni_vs_',param_name,'_',PARAMS,'.fig']); saveas(fig,[SIMDIR,'gamma_Ni_vs_',param_name,'_',PARAMS,'.png']); @@ -168,14 +168,14 @@ for i = 1:Nparam % Load and process results load_results tend = Ts2D(end); tstart = 0.4*tend; - for ikr = 1:N/2+1 - gamma_Ni(i,ikr) = LinearFit_s(Ts2D,squeeze(abs(Ni00(ikr,1,:))),tstart,tend); - Ni00_ST(i,ikr,1:numel(Ts2D)) = squeeze((Ni00(ikr,1,:))); + for ikx = 1:N/2+1 + gamma_Ni(i,ikx) = LinearFit_s(Ts2D,squeeze(abs(Ni00(ikx,1,:))),tstart,tend); + Ni00_ST(i,ikx,1:numel(Ts2D)) = squeeze((Ni00(ikx,1,:))); end gamma_Ni(i,:) = real(gamma_Ni(i,:) .* (gamma_Ni(i,:)>=0.0)); - [gmax,ikzmax] = max(gamma_Ni(i,:)); - kzmax = abs(kr(ikzmax)); - Bohm_transport(i) = ETAB/ETAN*gmax/kzmax^2; + [gmax,ikymax] = max(gamma_Ni(i,:)); + kymax = abs(kx(ikymax)); + Bohm_transport(i) = ETAB/ETAN*gmax/kymax^2; % Clean output system(['rm -r ',BASIC.RESDIR]) end @@ -187,13 +187,13 @@ plt = @(x) circshift(x,N/2-1); for i = 1:Nparam clr = line_colors(mod(i-1,numel(line_colors(:,1)))+1,:); linestyle = line_styles(floor((i-1)/numel(line_colors(:,1)))+1); - plot(plt(kz),plt(gamma_Ni(i,:)),... + plot(plt(ky),plt(gamma_Ni(i,:)),... 'Color',clr,... 'LineStyle',linestyle{1},... 'DisplayName',['$\eta_B=$',num2str(eta_B(i))]); hold on; end -grid on; xlabel('$k_z\rho_s$'); ylabel('$\gamma(N_i^{00})\rho_2/c_s$'); xlim([0.0,max(kz)]); +grid on; xlabel('$k_z\rho_s$'); ylabel('$\gamma(N_i^{00})\rho_2/c_s$'); xlim([0.0,max(ky)]); title(['$P_e=',num2str(PMAXE),'$',', $J_e=',num2str(JMAXE),'$',... ', $P_i=',num2str(PMAXE),'$',', $J_i=',num2str(JMAXI),'$']) legend('show') diff --git a/wk/load_multiple_outputs_marconi.m b/wk/load_multiple_outputs_marconi.m index f647156162f0e6611d726924d46cec265d2d4fb5..a1bb19572a4029a2c5792038ba9dd6732b4744f8 100644 --- a/wk/load_multiple_outputs_marconi.m +++ b/wk/load_multiple_outputs_marconi.m @@ -1,5 +1,11 @@ addpath(genpath('../matlab')) % ... add %% Paste the list of simulation results to load load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/100x50_L_50_P_6_J_3_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt') -load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/300x150_L_100_P_10_J_5_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt') load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.8_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-03_SGGK_CLOS_0_mu_2e-02/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-02_DGGK_CLOS_0_mu_1e-02/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/300x150_L_100_P_6_J_3_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/kobayashi/300x150_L_100_P_10_J_5_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_6_J_3/200x100_L_120_P_6_J_3_eta_0.6_nu_1e-02_DGGK_CLOS_0_mu_1e-02/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_6_J_3/200x100_L_120_P_6_J_3_eta_0.6_nu_1e-02_SGGK_CLOS_0_mu_1e-02/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_6_J_3/200x100_L_120_P_6_J_3_eta_0.6_nu_1e+00_SGGK_CLOS_0_mu_1e-02/out.txt') +load_marconi('/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-02_SGGK_CLOS_0_mu_1e-02/out.txt') diff --git a/wk/local_run.m b/wk/local_run.m index 77030a96b600d37218b0d1df06702366526f9219..c3a7bb8e444ba2d109b1a414902050dcdbdefdeb 100644 --- a/wk/local_run.m +++ b/wk/local_run.m @@ -5,21 +5,23 @@ CLUSTER.TIME = '99:00:00'; % allocation time hh:mm:ss %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS NU = 0.1; % Collision frequency -ETAB = 1.0; % Magnetic gradient -ETAN = 2.0; % Density gradient +ETAN = 0/0.6; % Density gradient drive (R/Ln) NU_HYP = 0.0; %% GRID PARAMETERS -N = 50; % Frequency gridpoints (Nkr = N/2) -L = 50; % Size of the squared frequency domain +N = 100; % Frequency gridpoints (Nkx = N/2) +L = 60; % Size of the squared frequency domain +Nz = 1; % number of perpendicular planes (parallel grid) +q0 = 1.0; % q factor () P = 2; J = 1; MU_P = 0.0; % Hermite hyperdiffusivity -mu_p*(d/dvpar)^4 f MU_J = 0.0; % Laguerre hyperdiffusivity -mu_j*(d/dvperp)^4 f %% TIME PARAMETERS -TMAX = 100; % Maximal time unit +TMAX = 10; % Maximal time unit DT = 1e-2; % Time step SPS0D = 1; % Sampling per time unit for profiler SPS2D = 1; % Sampling per time unit for 2D arrays +SPS3D = 2; % Sampling per time unit for 3D arrays SPS5D = 1; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints/10 RESTART = 0; % To restart from last checkpoint @@ -27,15 +29,17 @@ JOB2LOAD= 0; %% OPTIONS AND NAMING % Collision operator % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Pitch angle ; +/- for GK/DK) -CO = 0; +CO = 1; CLOS = 0; % Closure model (0: =0 truncation) NL_CLOS = -1; % nonlinear closure model (-2: nmax = jmax, -1: nmax = jmax-j, >=0 : nmax = NL_CLOS) +% SIMID = 'test_3D'; % Name of the simulation % SIMID = 'HD_study'; % Name of the simulation -SIMID = 'test_3D'; % Name of the simulation -% SIMID = 'kobayashi'; % Name of the simulation -% SIMID = ['v2.7_P_',num2str(P),'_J_',num2str(J)]; % Name of the simulation -NON_LIN = 0; % activate non-linearity (is cancelled if KREQ0 = 1) +SIMID = 'Blob_diffusion'; % Name of the simulation +% SIMID = ['v3.0_P_',num2str(P),'_J_',num2str(J)]; % Name of the simulation +NON_LIN = 1; % activate non-linearity (is cancelled if KXEQ0 = 1) +% INIT options INIT_ZF = 0; ZF_AMP = 0.0; +INIT_BLOB = 1; WIPE_TURB = 1; %% OUTPUTS W_DOUBLE = 0; W_GAMMA = 1; @@ -53,8 +57,8 @@ JMAXE = J; % Highest '' Laguerre '' PMAXI = P; % Highest ion Hermite polynomial degree JMAXI = J; % Highest '' Laguerre '' KERN = 0; % Kernel model (0 : GK) -KR0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. -KREQ0 = 0; % put kr = 0 +KX0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. +KXEQ0 = 0; % put kx = 0 KPAR = 0.0; % Parellel wave vector component LAMBDAD = 0.0; kmax = N*pi/L;% Highest fourier mode @@ -64,9 +68,10 @@ MU = NU_HYP/(HD_CO*kmax)^4 % Hyperdiffusivity coefficient NOISE0 = 1.0e-5; TAU = 1.0; % e/i temperature ratio ETAT = 0.0; % Temperature gradient +ETAB = 1.0; % Magnetic gradient (1.0 to set R=LB) INIT_PHI= 1; % Start simulation with a noisy phi and moments %% Setup and file management setup system('rm fort.90'); outfile = [BASIC.RESDIR,'out.txt']; -disp(outfile); \ No newline at end of file +disp(outfile); diff --git a/wk/marconi_scaling.m b/wk/marconi_scaling.m index 8c5cd7ee85d7c7b040335ba640fa26a9407e12e4..b33ec6ed6ae25774ca04eafee3cffb093e6007cd 100644 --- a/wk/marconi_scaling.m +++ b/wk/marconi_scaling.m @@ -1,13 +1,13 @@ %% Load results np = 24 np_p_24 = [1 2 3 4]; -np_kr_24= [24 12 8 6]; +np_kx_24= [24 12 8 6]; el_ti_np_24= zeros(numel(np_p_24),1); for i_ = 1:numel(np_p_24) - npp_ = np_p_24(i_); npkr = np_kr_24(i_); + npp_ = np_p_24(i_); npkx = np_kx_24(i_); %% Load from Marconi outfile =['/marconi_scratch/userexternal/ahoffman/HeLaZ/results/Marconi_parallel_scaling_2D/',... - sprintf('%d_%d',npp_,npkr),... + sprintf('%d_%d',npp_,npkx),... '_200x100_L_120_P_12_J_5_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_2e-03/out.txt']; BASIC.RESDIR = load_marconi(outfile); compile_results @@ -16,14 +16,14 @@ for i_ = 1:numel(np_p_24) end %% Load results np = 48 np_p_48 = [1 2 3 4 6]; -np_kr_48= [48 24 16 12 8]; +np_kx_48= [48 24 16 12 8]; el_ti_np_48= zeros(numel(np_p_48),1); for i_ = 1:numel(np_p_48) - npp_ = np_p_48(i_); npkr = np_kr_48(i_); + npp_ = np_p_48(i_); npkx = np_kx_48(i_); %% Load from Marconi outfile =['/marconi_scratch/userexternal/ahoffman/HeLaZ/results/Marconi_parallel_scaling_2D/',... - sprintf('%d_%d',npp_,npkr),... + sprintf('%d_%d',npp_,npkx),... '_200x100_L_120_P_12_J_5_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_2e-03/out.txt']; BASIC.RESDIR = load_marconi(outfile); compile_results @@ -33,14 +33,14 @@ end %% Load results np = 72 np_p_72 = [ 2 3]; -np_kr_72= [36 24]; +np_kx_72= [36 24]; el_ti_np_72= zeros(numel(np_p_72),1); for i_ = 1:numel(np_p_72) - npp_ = np_p_72(i_); npkr = np_kr_72(i_); + npp_ = np_p_72(i_); npkx = np_kx_72(i_); %% Load from Marconi outfile =['/marconi_scratch/userexternal/ahoffman/HeLaZ/results/Marconi_parallel_scaling_2D/',... - sprintf('%d_%d',npp_,npkr),... + sprintf('%d_%d',npp_,npkx),... '_200x100_L_120_P_12_J_5_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_2e-03/out.txt']; BASIC.RESDIR = load_marconi(outfile); compile_results diff --git a/wk/open_figure_script.m b/wk/open_figure_script.m index b7ef07f7b0cea979d7d145e7d18608318c12a6d1..cc22dcf67c5e13a585e601d6ca543fed581c7b17 100644 --- a/wk/open_figure_script.m +++ b/wk/open_figure_script.m @@ -3,7 +3,10 @@ fname_=''; %% Marconi output file fname_=''; fname_=''; -fname_='/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_10_J_5/200x100_L_120_P_10_J_5_eta_0.6_nu_1e-01_DGGK_CLOS_0_mu_2e-02/out.txt'; +fname_=''; +fname_=''; +fname_=''; +fname_='/marconi_scratch/userexternal/ahoffman/HeLaZ/results/v2.7_P_6_J_3/200x100_L_60_P_6_J_3_eta_0.6_nu_1e-03_SGGK_CLOS_0_mu_1e-03/out.txt'; simname_ = fname_(54:end-8); %% @@ -12,8 +15,8 @@ simname_ = fname_(54:end-8); % simname_ = ''; % simname_ = ''; % simname_ = ''; -% simname_ = 'v2.7_P_2_J_1/100x50_L_200_P_2_J_1_eta_0.6_nu_1e+00_SGGK_CLOS_0_mu_0e+00'; -simname_ = 'v2.7_P_2_J_1/100x50_L_100_P_2_J_1_eta_0.6_nu_1e+00_DGGK_CLOS_0_mu_0e+00'; +% simname_ = ''; + diff --git a/wk/photomaton.m b/wk/photomaton.m index 34474be94a4e862e00794ed437a7b046579aada2..39f6813d34e4eb080db5c52849ee0582635f26c3 100644 --- a/wk/photomaton.m +++ b/wk/photomaton.m @@ -1,48 +1,44 @@ if 0 %% Photomaton : real space -% FIELD = ni00; FNAME = 'ni00'; FIELDLTX = '$n_i^{00}$'; XX = RR; YY = ZZ; -FIELD = ne00; FNAME = 'ne00'; FIELDLTX = '$n_e^{00}$'; XX = RR; YY = ZZ; -% FIELD = dens_i; FNAME = 'ni'; FIELDLTX = '$n_i$'; XX = RR; YY = ZZ; -% FIELD = dens_e; FNAME = 'ne'; FIELDLTX = '$n_e$'; XX = RR; YY = ZZ; -% FIELD = temp_i; FNAME = 'Ti'; FIELDLTX = '$T_i$'; XX = RR; YY = ZZ; -% FIELD = temp_e; FNAME = 'Te'; FIELDLTX = '$T_e$'; XX = RR; YY = ZZ; -% FIELD = phi; FNAME = 'phi'; FIELDLTX = '$\phi$'; XX = RR; YY = ZZ; -% FIELD = drphi; FNAME = 'ZF'; FIELDLTX = '$u^{ZF}_z$'; XX = RR; YY = ZZ; -% FIELD = -dr2phi; FNAME = 'shear'; FIELDLTX = '$s$'; XX = RR; YY = ZZ; - plt = @(x) x./max(max(x)); + +% Chose the field to plot +% FIELD = ni00; FNAME = 'ni00'; FIELDLTX = 'n_i^{00}'; +% FIELD = ne00; FNAME = 'ne00'; FIELDLTX = 'n_e^{00}' +% FIELD = dens_i; FNAME = 'ni'; FIELDLTX = 'n_i'; +% FIELD = dens_e; FNAME = 'ne'; FIELDLTX = 'n_e'; +% FIELD = temp_i; FNAME = 'Ti'; FIELDLTX = 'T_i'; +% FIELD = temp_e; FNAME = 'Te'; FIELDLTX = 'T_e'; +FIELD = phi; FNAME = 'phi'; FIELDLTX = '\phi'; + +% Chose when to plot it +tf = [0 10 50 100]; + +% Slice +ix = 1; iy = 1; iz = 1; +% plt = @(x,it) real(x(ix, :, :,it)); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; FIELDLTX = [FIELDLTX,'(x=',num2str(round(x(ix))),')'] +% plt = @(x,it) real(x( :,iy, :,it)); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; FIELDLTX = [FIELDLTX,'(y=',num2str(round(y(iy))),')'] +% plt = @(x,it) real(x( :, :,iz,it)); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; FIELDLTX = [FIELDLTX,'(x=',num2str(round(z(iz))),')'] + +% Averaged +% plt = @(x,it) mean(x(:,:,:,it),1); X = Y_YZ; Y = Z_YZ; XNAME = 'y'; YNAME = 'z'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_x'] +% plt = @(x,it) mean(x(:,:,:,it),2); X = X_XZ; Y = Z_XZ; XNAME = 'x'; YNAME = 'z'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_y'] +plt = @(x,it) mean(x(:,:,:,it),3); X = X_XY; Y = Y_XY; XNAME = 'x'; YNAME = 'y'; FIELDLTX = ['\langle',FIELDLTX,'\rangle_z'] + + +% TNAME = []; -tf = 500; [~,it1] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1000; [~,it2] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1250; [~,it3] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1750; [~,it4] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; fig = figure; FIGNAME = [FNAME,TNAME,'_snaps','_',PARAMS]; set(gcf, 'Position', [100, 100, 1500, 350]) - subplot(141) - DATA = plt(FIELD(:,:,it1)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); caxis([-1,1]); - xlabel('$r/\rho_s$'); ylabel('$z/\rho_s$');set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it1))); - subplot(142) - DATA = plt(FIELD(:,:,it2)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); caxis([-1,1]); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$'); set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it2))); - subplot(143) - DATA = plt(FIELD(:,:,it3)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); caxis([-1,1]); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$');set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it3))); - subplot(144) - DATA = plt(FIELD(:,:,it4)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) +plt_2 = @(x) x./max(max(x)); + for i_ = 1:numel(tf) + [~,it] = min(abs(Ts3D-tf(i_))); TNAME = [TNAME,'_',num2str(Ts3D(it))]; + subplot(1,numel(tf),i_) + DATA = plt_2(squeeze(plt(FIELD,it))); + pclr = pcolor((X),(Y),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) colormap(bluewhitered); caxis([-1,1]); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$'); set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it4))); - suptitle([FIELDLTX,', $\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... - ', $L=',num2str(L),'$, $N=',num2str(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... - ' $\mu_{hd}=$',num2str(MU)]); + xlabel(latexize(XNAME)); ylabel(latexize(YNAME));set(gca,'ytick',[]); + title(sprintf('$t c_s/R=%.0f$',Ts3D(it))); + end + legend(latexize(FIELDLTX)); save_figure end @@ -51,58 +47,13 @@ if 0 figure skip = 2; plt = @(x) x./max(max(x)); -FNAME = 'ZF'; FIELDLTX = '$\bm{u}^{ZF}$'; XX = RR; YY = ZZ; +FNAME = 'ZF'; FIELDLTX = '$\bm{u}^{ZF}$'; X_XY = RR; Y_XY = ZZ; tf = 1200; [~,it1] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; UY = plt(drphi(1:skip:end,1:skip:end,it1)); UX = plt(-dzphi(1:skip:end,1:skip:end,it1)); -pclr = pcolor(XX,YY,plt(ni00(:,:,it1))); set(pclr, 'edgecolor','none'); +pclr = pcolor(X_XY,Y_XY,plt(ni00(:,:,it1))); set(pclr, 'edgecolor','none'); hold on -quiver((XX(1:skip:end,1:skip:end)),(YY(1:skip:end,1:skip:end)),UX,UY,'r'); xlim(L/2*[-1 1]); ylim(L/2*[-1 1]); +quiver((X_XY(1:skip:end,1:skip:end)),(Y_XY(1:skip:end,1:skip:end)),UX,UY,'r'); xlim(L/2*[-1 1]); ylim(L/2*[-1 1]); pbaspect([1 1 1]) xlabel('$r/\rho_s$');ylabel('$z/\rho_s$');set(gca,'ytick',[]); title(sprintf('$t c_s/R=%.0f$',Ts2D(it1))); -end - - -%% -if 0 -%% Photomaton : k space -% FIELD = Ni00; FNAME = 'Ni00'; FIELDLTX = '$N_i^{00}$'; XX = KR; YY = KZ; -FIELD = Ne00; FNAME = 'Ne00'; FIELDLTX = '$N_e^{00}$'; XX = KR; YY = KZ; -FIELD = PHI; FNAME = 'PHI'; FIELDLTX = '$\tilde\phi$'; XX = KR; YY = KZ; -FIELD = ifftshift((abs(FIELD)),2); XX = fftshift(XX,2); YY = fftshift(YY,2); -plt = @(x) x./max(max(x)); -TNAME = []; -tf = 500; [~,it1] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1000; [~,it2] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1250; [~,it3] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1750; [~,it4] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -fig = figure; FIGNAME = [FNAME,TNAME,'_snaps','_',PARAMS]; set(gcf, 'Position', [100, 100, 1500, 350]) - subplot(141) - DATA = plt(FIELD(:,:,it1)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap gray; - xlabel('$r/\rho_s$'); ylabel('$z/\rho_s$');set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it1))); - subplot(142) - DATA = plt(FIELD(:,:,it2)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$'); set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it2))); - subplot(143) - DATA = plt(FIELD(:,:,it3)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$');set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it3))); - subplot(144) - DATA = plt(FIELD(:,:,it4)); - pclr = pcolor((XX),(YY),DATA); set(pclr, 'edgecolor','none');pbaspect([1 1 1]) - colormap(bluewhitered); - xlabel('$r/\rho_s$');ylabel('$z/\rho_s$'); set(gca,'ytick',[]); - title(sprintf('$t c_s/R=%.0f$',Ts2D(it4))); - suptitle([FIELDLTX,', $\nu_{',CONAME,'}=$', num2str(NU), ', $\eta_B=$',num2str(ETAB),... - ', $L=',num2str(L),'$, $N=',num2str(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... - ' $\mu_{hd}=$',num2str(MU)]); -save_figure end \ No newline at end of file diff --git a/wk/plot_cosol_mat.m b/wk/plot_cosol_mat.m new file mode 100644 index 0000000000000000000000000000000000000000..876a233af31d659bc239328252f78affc9965724 --- /dev/null +++ b/wk/plot_cosol_mat.m @@ -0,0 +1,63 @@ +MAT = results.iCa; +figure +suptitle('DGGK,P=6,J=3'); +subplot(221) + imagesc(log(abs(MAT))); + title('log abs') +subplot(222) + imagesc(imag(MAT)); colormap(bluewhitered) + title('imag'); colorbar +subplot(223) + imagesc(imag(MAT)>0); + title('imag$>$0'); +subplot(224) + imagesc(imag(MAT)<0); + title('imag$<$0'); + + + %% SGGK +P_ = 20; J_ = 10; +mat_file_name = '/home/ahoffman/HeLaZ/iCa/gk_sugama_P_20_J_10_N_150_kpm_8.0.h5'; +SGGK_self = h5read(mat_file_name,'/00149/Caapj/Ciipj'); +SGGK_ei = h5read(mat_file_name,'/00000/Ceipj/CeipjF')+h5read(mat_file_name,'/00000/Ceipj/CeipjT'); +SGGK_ie = h5read(mat_file_name,'/00000/Ciepj/CiepjF')+h5read(mat_file_name,'/00000/Ciepj/CiepjT'); + +figure +MAT = 1i*SGGK_self; suptitle('SGGK ii,P=20,J=10, k=8'); +% MAT = 1i*SGGK_ei; suptitle('SGGK ei,P=20,J=10'); +% MAT = 1i*SGGK_ie; suptitle('SGGK ie,P=20,J=10'); +subplot(221) + imagesc(abs(MAT)); + title('log abs') +subplot(222) + imagesc(imag(MAT)); colormap(bluewhitered) + title('imag'); colorbar +subplot(223) + imagesc(imag(MAT)>0); + title('imag$>$0'); +subplot(224) + imagesc(imag(MAT)<0); + title('imag$<$0'); + + %% PAGK +P_ = 20; J_ = 10; +mat_file_name = '/home/ahoffman/HeLaZ/iCa/gk_pitchangle_8_P_20_J_10_N_150_kpm_8.0.h5'; +PAGK_self = h5read(mat_file_name,'/00149/Caapj/Ceepj'); +% PAGK_ei = h5read(mat_file_name,'/00000/Ceipj/CeipjF')+h5read(mat_file_name,'/00000/Ceipj/CeipjT'); +% PAGK_ie = h5read(mat_file_name,'/00000/Ciepj/CiepjF')+h5read(mat_file_name,'/00000/Ciepj/CiepjT'); + +figure +MAT = 1i*PAGK_self; suptitle('PAGK ii,P=20,J=10, k=8'); + +subplot(221) + imagesc(abs(MAT)); + title('log abs') +subplot(222) + imagesc(imag(MAT)); colormap(bluewhitered) + title('imag'); colorbar +subplot(223) + imagesc(imag(MAT)>0); + title('imag$>$0'); +subplot(224) + imagesc(imag(MAT)<0); + title('imag$<$0'); diff --git a/wk/ppb110_run.m b/wk/ppb110_run.m index a241120dd7a5d29aeb07e9669e1987c46d5fec1d..2eddbcd16dbc25e17408aea3333b339b61913a95 100644 --- a/wk/ppb110_run.m +++ b/wk/ppb110_run.m @@ -17,7 +17,7 @@ NU = 1.0; % Collision frequency ETAB = 0.5; % Magnetic gradient NU_HYP = 0.1; % Hyperdiffusivity coefficient %% GRID PARAMETERS -N = 150; % Frequency gridpoints (Nkr = N/2) +N = 150; % Frequency gridpoints (Nkx = N/2) L = 70; % Size of the squared frequency domain P = 2; % Electron and Ion highest Hermite polynomial degree J = 1; % Electron and Ion highest Laguerre polynomial degree @@ -41,11 +41,11 @@ KERN = 0; % Kernel model (0 : GK) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% fixed parameters (for current study) -KR0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. (not implemented) -KREQ0 = 0; % put kr = 0 +KX0KH = 0; A0KH = 0; % Background phi mode to drive Ray-Tay inst. (not implemented) +KXEQ0 = 0; % put kx = 0 KPAR = 0.0; % Parellel wave vector component LAMBDAD = 0.0; -NON_LIN = 1 *(1-KREQ0); % activate non-linearity (is cancelled if KREQ0 = 1) +NON_LIN = 1 *(1-KXEQ0); % activate non-linearity (is cancelled if KXEQ0 = 1) PMAXE = P; % Highest electron Hermite polynomial degree JMAXE = J; % Highest '' Laguerre '' PMAXI = P; % Highest ion Hermite polynomial degree diff --git a/wk/spectral_analysis.m b/wk/spectral_analysis.m index afb9f7177289308e71a7e05ae775449d7cd4d4ea..8830f118d3566211c8096cf531fa8a33cdae2819 100644 --- a/wk/spectral_analysis.m +++ b/wk/spectral_analysis.m @@ -19,7 +19,7 @@ for ij = 1:Nji end grid on; ylim([1e0,1e10]); xlabel('$p$'); - TITLE = ['$\sum_{kr,kz} |N_i^{p',num2str(Ji(ij)),'}|^2$']; title(TITLE); + TITLE = ['$\sum_{kx,ky} |N_i^{p',num2str(Ji(ij)),'}|^2$']; title(TITLE); end save_figure end @@ -42,26 +42,26 @@ for ip = 1:2:Npi 'DisplayName',['t=',num2str(Ts5D(it5))]); hold on; grid on; xlabel('$j$'); ylim([1e-20,1e10]); - TITLE = ['$\sum_{kr,kz} |N_i^{',num2str(Pi(ip)),'j}|^2$']; title(TITLE); + TITLE = ['$\sum_{kx,ky} |N_i^{',num2str(Pi(ip)),'j}|^2$']; title(TITLE); end end save_figure end %% -no_AA = (2:floor(2*Nkr/3)); +no_AA = (2:floor(2*Nkx/3)); tKHI = 100; [~,itKHI] = min(abs(Ts2D-tKHI)); after_KHI = (itKHI:Ns2D); if 0 -%% Phi frequency space time diagram at kz=kz(ikz) -kz_ = 0.0; -[~,ikz] = min(abs(kz-kz_)); +%% Phi frequency space time diagram at ky=ky(iky) +ky_ = 0.0; +[~,iky] = min(abs(ky-ky_)); fig = figure; FIGNAME = ['phi_freq_diag_',PARAMS];set(gcf, 'Position', [100, 100, 500, 400]); - [TY,TX] = meshgrid(Ts2D(after_KHI),kr(no_AA)); - pclr = pcolor(TX,TY,(squeeze(abs(PHI(no_AA,ikz,(after_KHI)))))); set(pclr, 'edgecolor','none'); colorbar; + [TY,TX] = meshgrid(Ts2D(after_KHI),kx(no_AA)); + pclr = pcolor(TX,TY,(squeeze(abs(PHI(no_AA,iky,(after_KHI)))))); set(pclr, 'edgecolor','none'); colorbar; caxis([0,10000]); colormap hot ylabel('$t c_s/R$'), xlabel('$0<k_r<2/3 k_r^{\max}$') - legend(['$|\tilde\phi(k_z=',num2str(kz_),')|$']) + legend(['$|\tilde\phi(k_z=',num2str(ky_),')|$']) title('Spectrogram of $\phi$') end \ No newline at end of file