Skip to content

Commit c4844ef

Browse files
committed
make zonal diagnostic for all kx
1 parent 947da07 commit c4844ef

File tree

9 files changed

+94
-61
lines changed

9 files changed

+94
-61
lines changed

COMPILATION/Makefile.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,4 +1395,5 @@ $(OBJ_DIR)/write_diagnostics_to_netcdf.o: \
13951395
$(OBJ_DIR)/mp.o \
13961396
$(OBJ_DIR)/neasyf.o \
13971397
$(OBJ_DIR)/netcdf_utils.o \
1398+
$(OBJ_DIR)/parameters_diagnostics.o \
13981399
$(OBJ_DIR)/parameters_physics.o
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
from stella_plots import movie_2d
3-
from stella_data import gzvs, vpa, zed, ntime, g2nozonal_vs_zvpas, nzed
3+
from stella_data import gzvs, vpa, zed, ntime, g2nozonal_vs_zvpas, nzed, time
44
from stella_data import gzvs_zonal
55
from stella_data import outdir
66

@@ -9,22 +9,17 @@
99
gmax = np.arange(ntime,dtype=float)
1010
gmin = np.arange(ntime,dtype=float)
1111

12-
#print('SHAPE=', gzvs_zonal.shape)
13-
14-
#g_zonal = np.zeros((ntime, nvpa, nzed), dtype=complex)
15-
#g_zonal = np.array(gzvs_zonal[:, 0, :, :, 0, 0] + 1j*gzvs_zonal[:, 0, :, :, 0, 1], dtype=complex) #gzvs - g2nozonal_vs_zvpas
16-
17-
#print('shape zonal', np.shape(g_zonal))
12+
#(t, species, vpa, tube, zed, kx, ri)
13+
g_zonal = np.array(gzvs_zonal[:, 0, :, 0, :, 1, 0] + 1j*gzvs_zonal[:, 0, :, 0, :, 1, 1], dtype=complex)
1814

1915
for i in range(ntime):
20-
gmax[i] = np.absolute(gzvs[i,0,:,:].max())
21-
#gmax[i] = np.abs(g_zonal[i,:,:]).max()
16+
gmax[i] = np.abs(g_zonal[i,:,:]).max()
17+
18+
gmin[:] = -gmax[:]
2219

23-
gmin[:] = - gmax[:]
2420
ylabel = '$v_{\parallel}$'
2521
xlabel = '$z$'
2622
title = '$\int d\mu \int d^2 \mathbf{R} g^2$'
2723
movie_file = outdir + 'gzvs.mp4'
2824

29-
movie_2d(gzvs[:,0,:,:],zed,vpa,gmin,gmax,ntime-1,movie_file,xlabel,ylabel,title,cmp='YlGnBu', abs_flag=False)
30-
#movie_2d(g_zonal,zed,vpa,gmin,gmax,ntime-1,movie_file,xlabel,ylabel,title,cmp='RdBu', abs_flag=False)
25+
movie_2d(g_zonal,zed,vpa,gmin,gmax,ntime-1,movie_file,xlabel,ylabel,title,cmp='RdBu', abs_flag=True)

POST_PROCESSING/post_processing/stella_data.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
# note stella orders kx as (0, dkx, ..., kx_max, -kx_max, -kx_max+dkx, ..., -dkx)
2828
nakx_mid = nakx//2+1
2929
kx = np.concatenate((kx_stella[nakx_mid:],kx_stella[:nakx_mid]))
30-
3130
print('nakx=', nakx)
3231
# get zed grid
3332
zed = np.copy(ncfile.variables['zed'][:])

POST_PROCESSING/post_processing/stella_plots.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ def movie_2d(z, xin, yin, zmin, zmax, nframes, outfile,
8383
z_even = np.sign(np.real(z_even_full)) * np.abs(z_even_full)
8484
z_odd = np.sign(np.real(z_odd_full)) * np.abs(z_odd_full)
8585
else:
86-
z_even = np.real(z_even_full)#0.5*(z + np.flip(z, axis=1)))
87-
z_odd = np.real(z_odd_full) #0.5*(z - np.flip(z, axis=1)))
86+
z_even = np.real(z_even_full)
87+
z_odd = np.real(z_odd_full)
8888

8989
# Ensure frames list respects step
9090
frames = list(range(0, nframes, step))

STELLA_CODE/calculations/calculations_velocity_integrals.f90

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module calculations_velocity_integrals
5858
interface integrate_mu
5959
module procedure integrate_mu_local
6060
module procedure integrate_mu_nonlocal
61+
module procedure integrate_mu_nonlocal_complex
6162
end interface
6263

6364
! Integrations over the parallel velocity
@@ -145,6 +146,49 @@ subroutine integrate_mu_nonlocal(iz, g, total)
145146
if (nproc > 1) call sum_reduce(total, 0)
146147

147148
end subroutine integrate_mu_nonlocal
149+
150+
151+
!---------------- Each processor has a number of ivmu points ----------------
152+
subroutine integrate_mu_nonlocal_complex(iz, g, total)
153+
154+
use mp, only: nproc, sum_allreduce
155+
use parallelisation_layouts, only: vmu_lo
156+
use parallelisation_layouts, only: is_idx, imu_idx, iv_idx
157+
158+
implicit none
159+
160+
! Arguments
161+
integer, intent(in) :: iz
162+
complex, dimension(vmu_lo%llim_proc:), intent(in) :: g
163+
complex, dimension(:, :), intent(out) :: total
164+
165+
! Local variables
166+
integer :: is, imu, iv, ivmu, ia
167+
168+
!-------------------------------------------------------------------------
169+
170+
! Initialise sum
171+
total = 0.
172+
! Assume we only have a single flux tube
173+
ia = 1
174+
175+
! Iterate over the i[vpa, mu, s] points
176+
do ivmu = vmu_lo%llim_proc, vmu_lo%ulim_proc
177+
178+
! Obtain the [ivpa, imu, is] indices from [ivmus]
179+
is = is_idx(vmu_lo, ivmu)
180+
imu = imu_idx(vmu_lo, ivmu)
181+
iv = iv_idx(vmu_lo, ivmu)
182+
183+
! Integrate over mu
184+
total(iv, is) = total(iv, is) + wgts_mu(ia, iz, imu) * g(ivmu)
185+
186+
end do
187+
188+
! Each processor has a few [ivmu] points, so sum all calculations
189+
call sum_allreduce(total)
190+
191+
end subroutine integrate_mu_nonlocal_complex
148192

149193
!###############################################################################
150194
!############################## INTEGRALS OVER VPA #############################
@@ -291,7 +335,6 @@ subroutine integrate_vmu_vmulo_complex(g, weights, total)
291335
total(:, :, iz, :, is) = total(:, :, iz, :, is) + &
292336
wgts_mu(ia, iz, imu) * wgts_vpa(iv) * g(:, :, iz, :, ivmu) * weights(is)
293337
end do
294-
295338
end do
296339

297340
! Each processor has a few [ivmu] points, so sum all calculations

STELLA_CODE/diagnostics/diagnostics_distribution.f90

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
128128
! Dimensions
129129
use grids_kxky, only: nakx, naky
130130
use grids_velocity, only: nvpa, nmu
131-
use grids_z, only: nztot, ntubes
131+
use grids_z, only: nztot, ntubes, nzgrid
132132
use grids_species, only: nspec
133133

134134
! Write to netcdf file
@@ -176,7 +176,6 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
176176

177177
use parameters_diagnostics, only: write_g_vs_zvpas_zonal
178178
use parameters_diagnostics, only: write_free_energy
179-
use parameters_diagnostics, only: number_zonals_kxs, zonal_iks
180179

181180
! Calculations
182181
use calculations_tofrom_ghf, only: g_to_f, g_to_h
@@ -193,7 +192,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
193192
real, dimension(:, :, :, :), allocatable :: g2_vs_zvpas, g2_vs_zmus, g2nozonal_vs_zvpas, g2nozonal_vs_zmus
194193

195194
! Zonals
196-
real, dimension(:, :, :, :, :, :), allocatable :: g_vs_zvpas_zonal
195+
complex, dimension(:, :, :, :, :), allocatable :: g_vs_zvpas_zonal
197196
real, dimension(:), allocatable :: free_energy_vs_kx
198197

199198
real, dimension(:, :, :, :, :), allocatable :: g2_vs_zkykxs, g2_vs_zvpamus, g2nozonal_vs_zvpamus
@@ -222,7 +221,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
222221
if (write_g2_vs_kxkyzs) allocate (g2_vs_zkykxs(ntubes, nztot, naky, nakx, nspec))
223222

224223
! Zonal diagnostics
225-
if (write_g_vs_zvpas_zonal) allocate (g_vs_zvpas_zonal(2, number_zonals_kxs, ntubes, nztot, nvpa, nspec))
224+
if (write_g_vs_zvpas_zonal) allocate (g_vs_zvpas_zonal(nakx, -nzgrid:nzgrid, ntubes, nvpa, nspec))
226225
if (write_free_energy) allocate (free_energy_vs_kx(nakx))
227226

228227
! Redistribute the data from <gnew>(ky,kx,z,tube,i[vpa,mu,s]) to <gvmu>(vpa,mu,i[kx,ky,z,s]) for |g|^2(z,kx,ky,s)
@@ -248,9 +247,7 @@ subroutine write_distribution_to_netcdf_file(nout, timer)
248247
if (write_g2_vs_zvpamus .and. proc0) call write_g2nozonal_vs_zvpamus_nc(nout, g2nozonal_vs_zvpamus)
249248

250249
! Zonals
251-
if (write_g_vs_zvpas_zonal .and. proc0) then
252-
call write_g_vs_zvpas_zonal_nc(nout, g_vs_zvpas_zonal)
253-
end if
250+
if (write_g_vs_zvpas_zonal .and. proc0) call write_g_vs_zvpas_zonal_nc(nout, g_vs_zvpas_zonal)
254251

255252
if (write_free_energy) then
256253
call g_to_h(gnew, phi, bpar, fphi)
@@ -380,7 +377,6 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
380377
use parameters_diagnostics, only: write_g2_vs_zvpamus
381378

382379
use parameters_diagnostics, only: write_g_vs_zvpas_zonal
383-
use parameters_diagnostics, only: number_zonals_kxs, zonal_iks
384380

385381
implicit none
386382

@@ -392,14 +388,14 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
392388
real, dimension(:, :, :), intent(out) :: g2_vs_vpamus, g2nozonal_vs_vpamus
393389

394390
! Zonals
395-
real, dimension(:, :, :, :, :, :), intent(out) :: g_vs_zvpas_zonal
391+
complex, dimension(:, -nzgrid:, :, :, :), intent(out) :: g_vs_zvpas_zonal
396392

397393
! Arrays needed to perform calculations
398394
real, dimension(:, :, :), allocatable :: g2_vs_ztubeivmus, g2nozonal_vs_ztubeivmus
399395
real, dimension(:, :), allocatable :: g2_vs_ztube, g2_vs_vpamu
400396

401397
! Zonals
402-
real, dimension(:, :, :, :, :), allocatable :: g_vs_zivmus_zonal
398+
complex, dimension(:, :, :, :), allocatable :: g_vs_zivmus_zonal
403399

404400
integer :: ivmus, ia, iz, it, ikx, iky, izp, is, iv, imu, ikxkyzs
405401
integer :: j, ikx_plot
@@ -414,8 +410,8 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
414410
if (write_g2_vs_kxkyzs) then; allocate (g2_vs_vpamu(nvpa, nmu)); g2_vs_vpamu = 0.; end if
415411
allocate (g2_vs_ztube(-nzgrid:nzgrid, ntubes)); g2_vs_ztube = 0.
416412

417-
if (write_g_vs_zvpas_zonal .and. number_zonals_kxs > 0) then
418-
allocate (g_vs_zivmus_zonal(2, number_zonals_kxs, -nzgrid:nzgrid, ntubes, vmu_lo%llim_proc:vmu_lo%ulim_alloc))
413+
if (write_g_vs_zvpas_zonal) then
414+
allocate (g_vs_zivmus_zonal(nakx, -nzgrid:nzgrid, ntubes, vmu_lo%llim_proc:vmu_lo%ulim_alloc))
419415
g_vs_zivmus_zonal = 0.0
420416
end if
421417

@@ -464,28 +460,19 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
464460

465461
! Zonals
466462
if (write_g_vs_zvpas_zonal) then
467-
if (number_zonals_kxs == 1) then
463+
if (nakx == 1) then
468464
if (abs(akx(1)) < epsilon(0.)) then
469465
ikx_plot = 2
470466
else
471467
ikx_plot = 1
472468
end if
473-
g_vs_zivmus_zonal(1, 1, :, :, ivmus) = real(g_vs_kykxztube(1, ikx_plot, :, :, ivmus))
474-
g_vs_zivmus_zonal(2, 1, :, :, ivmus) = aimag(g_vs_kykxztube(1, ikx_plot, :, :, ivmus))
469+
g_vs_zivmus_zonal(1, :, :, ivmus) = g_vs_kykxztube(1, ikx_plot, :, :, ivmus)
475470

476471
else
477472

478473
ikx_plot = 0
479474

480-
do ikx = 1, nakx
481-
if (any(zonal_iks == ikx)) then
482-
ikx_plot = ikx_plot + 1
483-
484-
g_vs_zivmus_zonal(1, ikx_plot, :, :, ivmus) = real(g_vs_kykxztube(1, ikx, :, :, ivmus))
485-
g_vs_zivmus_zonal(2, ikx_plot, :, :, ivmus) = aimag(g_vs_kykxztube(1, ikx, :, :, ivmus))
486-
487-
end if
488-
end do
475+
g_vs_zivmus_zonal(:, :, :, ivmus) = g_vs_kykxztube(1, :, :, :, ivmus)
489476
end if
490477

491478
end if
@@ -517,25 +504,28 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
517504
! The velocity parallel integration takes |g|^2(ivmus) and returns int dvpa |g|^2(ivmus) = |g|^2(mu,s)
518505
! There is a sum_reduce() inside of the velocity integration, so <g2_vs_tzmus> holds the total sum
519506
if (debug) write (*, *) 'diagnostics::diagnostics_distribution::calculate_distribution::write_g2_vs_zvpas .or. write_g2_vs_zmus'
520-
if (write_g2_vs_zvpas .or. write_g2_vs_zmus .or. write_g_vs_zvpas_zonal) then
507+
if (write_g2_vs_zvpas .or. write_g2_vs_zmus) then
521508
do it = 1, ntubes
522509
do iz = -nzgrid, nzgrid
523510
izp = iz + nzgrid + 1
524511
if (write_g2_vs_zvpas) call integrate_mu(iz, g2_vs_ztubeivmus(iz, it, :), g2_vs_zvpas(it, izp, :, :))
525-
if (write_g_vs_zvpas_zonal) then
526-
do ikx = 1, number_zonals_kxs
527-
do j = 1, 2
528-
call integrate_mu(iz, g_vs_zivmus_zonal(j, ikx, iz, it, :), g_vs_zvpas_zonal(j, ikx, it, izp, :, :))
529-
end do
530-
end do
531-
end if
532512
if (write_g2_vs_zmus) call integrate_vpa(g2_vs_ztubeivmus(iz, it, :), g2_vs_tzmus(it, izp, :, :))
533513
if (write_g2_vs_zvpas) call integrate_mu(iz, g2nozonal_vs_ztubeivmus(iz, it, :), g2nozonal_vs_zvpas(it, izp, :, :))
534514
if (write_g2_vs_zmus) call integrate_vpa(g2nozonal_vs_ztubeivmus(iz, it, :), g2nozonal_vs_tzmus(it, izp, :, :))
535515
end do
536516
end do
537517
end if
538518

519+
if (write_g_vs_zvpas_zonal) then
520+
do it = 1, ntubes
521+
do iz = -nzgrid, nzgrid
522+
do ikx = 1, nakx
523+
call integrate_mu(iz, g_vs_zivmus_zonal(ikx, iz, it, :), g_vs_zvpas_zonal(ikx, iz, it, :, :))
524+
end do
525+
end do
526+
end do
527+
end if
528+
539529
! For the field line average normalise to account for contributions from multiple flux tubes
540530
! in a flux tube train, and sum the values on all processors and to send them to <proc0>
541531
if (debug) write (*, *) 'diagnostics::diagnostics_distribution::calculate_distribution::sum_all_reduce'
@@ -552,6 +542,10 @@ subroutine calculate_distribution(g_vs_kykxztube, g_vs_vpamuikxkyzs, g2_vs_tzmus
552542
if (nproc > 1) call sum_reduce(g2_vs_zkykxs, 0)
553543
end if
554544

545+
if (write_g_vs_zvpas_zonal) then
546+
if (nproc > 1) call sum_reduce(g_vs_zvpas_zonal, 0)
547+
end if
548+
555549
! Deallocate local arrays
556550
if (write_g2_vs_zvpas) deallocate (g2nozonal_vs_ztubeivmus)
557551
if (write_g2_vs_zvpas) deallocate (g2_vs_ztubeivmus)

STELLA_CODE/diagnostics/write_diagnostics_to_netcdf.fpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,6 @@ contains
305305
use grids_z, only: nzgrid, ntubes, zed
306306
use grids_velocity, only: nvpa, vpa, nmu, mu
307307
use grids_species, only: nspec
308-
use parameters_diagnostics, only: number_zonals_kxs, zonal_ks
309308
! Geometry
310309
use parameters_physics, only: rhostar
311310
use geometry, only: geo_surf, dxdpsi, q_as_x
@@ -320,7 +319,6 @@ contains
320319
integer :: ix
321320
real :: nmesh ! Total number of mesh points
322321

323-
324322
!-------------------------------------------------------------------------
325323
! DIMENSIONS
326324
!-------------------------------------------------------------------------
@@ -337,8 +335,6 @@ contains
337335
call neasyf_dim(file_id, "t", unlimited=.true., long_name="Time", units="a_ref/v_ref")
338336
call neasyf_dim(file_id, "ri", dim_size=2, long_name="Complex components", units="(real, imaginary)")
339337

340-
call neasyf_dim(file_id, "zonal_ks", values=zonal_ks)
341-
342338
! Dimensions for various string variables
343339
call neasyf_dim(file_id, "char10", dim_size=10, dimid=char10_dim)
344340
call neasyf_dim(file_id, "char200", dim_size=200)
@@ -958,12 +954,18 @@ contains
958954
end subroutine write_g2_vs_zvpas_nc
959955

960956
subroutine write_g_vs_zvpas_zonal_nc (nout, g_vs_zvpas_zonal)
961-
implicit none
962-
integer, intent(in) :: nout
963-
real, dimension(:, :, :, :, :, :), intent(in) :: g_vs_zvpas_zonal
964-
call neasyf_write(ncid, "g_vs_zvpas_zonal", g_vs_zvpas_zonal, &
965-
dim_names=[character(len=8)::"ri", "zonal_ks", "tube", "zed", "vpa", "species", "t"], start=[1, 1, 1, 1, 1, 1, nout], &
957+
implicit none
958+
integer, intent(in) :: nout
959+
complex, dimension(:, :, :, :, :), intent(in) :: g_vs_zvpas_zonal
960+
#ifdef NETCDF
961+
character(*), dimension(*), parameter :: dims = [character(7)::"ri", "kx", "zed", "tube", "vpa", "species", "t"]
962+
integer, dimension(7) :: start
963+
start = [1, 1, 1, 1, 1, 1, nout]
964+
965+
call netcdf_write_complex(ncid, "g_vs_zvpas_zonal", g_vs_zvpas_zonal, &
966+
dim_names=dims, start=start, &
966967
long_name="Guiding center Zonal distribution function for min kx, ky = 0, averaged over (mu)")
968+
#endif
967969
end subroutine write_g_vs_zvpas_zonal_nc
968970

969971
subroutine write_free_energy_nc(nout, free_energy_vs_kx)

STELLA_CODE/parameters/parameters_diagnostics.f90

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,8 @@ subroutine broadcast_parameters
269269

270270
call broadcast(write_g_vs_zvpas_zonal)
271271
call broadcast(write_free_energy)
272-
call broadcast(number_zonals_kxs)
273-
call broadcast(number_zonals_kxs)
274-
272+
call broadcast(number_zonals_kxs)
273+
275274
call broadcast(write_radial_fluxes)
276275
call broadcast(write_radial_moments)
277276
call broadcast(write_fluxes_kxkyz)

STELLA_CODE/read_namelists_from_input_file/namelist_diagnostics.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ subroutine read_input_file_diagnostics_zonal
737737
implicit none
738738
integer :: ios
739739
integer, parameter :: max_kxs = 100
740-
real(kind=8) :: zonal_kxs(max_kxs)
740+
real :: zonal_kxs(max_kxs)
741741
integer :: j
742742

743743
namelist /diagnostics_zonal/ write_g_vs_zvpas_zonal, write_free_energy, &

0 commit comments

Comments
 (0)