diff --git a/README.md b/README.md index c0b0278..b929970 100644 --- a/README.md +++ b/README.md @@ -1,78 +1,78 @@ # HeLaZ (Hermite-Laguerre Z-pinch solver, 2021) To compile it check INSTALLATION.txt How to run it 1. Be sure to have correct paths in local/dirs.inc for the different libraries 2. Compile from HeLaZ/ using make 3. To run the code, use HeLaZ/wk/local_run.m and run it to set up the parameters and the results folder -4. Then go to the results folder and launch HeLaZ using mpirun -np num_procs ./../../../bin/helaz num_p num_kr +4. Then go to the results folder and launch HeLaZ using mpirun -np num_procs ./../../../bin/helaz num_p num_kx 5. You can obtain various plots and gifs using HeLaZ/wk/analysis_2D.m once the simulation is done. To select the correct output file, run parameters*.m with the corresponding simulation parameters and then run analysis_2D.m (everything with matlab from wk/) // Comment : For some collision operators (Sugama and Full Coulomb) you have to run COSOlver from B.J.Frei first in order to generate the required matrices in HeLaZ/iCa folder. # Changelog 2. MPI parallel version 2.7 Versatile interpolation of kperp for the cosolver matrices and corrections done on DGGK 2.6 Change of collisionality normalisation (from nu_ei to nu_ii), implementation of FCGK 2.5 GK cosolver collision implementation - 2.4 2D cartesian parallel (along p and kr) + 2.4 2D cartesian parallel (along p and kx) 2.3 GK Dougherty operator 2.2 Allow restart with different P,J values (results are not concluents) - 2.1 First compilable parallel version (1D parallel along kr) + 2.1 First compilable parallel version (1D parallel along kx) 1. Implementation of the non linear Poisson brackets term 1.4 Quantitative study with stationary average particle flux \Gamma_\infty 1.3 Linear analysis showed that a certain amount of PJ are recquired to trigger mode 1.2 Zonal flows are observed in a similar way to Ricci Rogers 2006 with GS2 1.1 Qualitative test : find similar turbulences as Hasegawa Wakatani system with few moments 1.1 Methods in fourier_mod.f90 have been validated by tests on Hasegawa Wakatani system 1.1 Methods in fourier_mod.f90 have been validated by tests on Hasegawa Wakatani system 1.0 FFTW3 has been used to treat the convolution as a product and discrete fourier transform 0. Write MOLI matlab solver in Fortran using Monli1D as starting point 0.6 Benchmarks now include Dougherty, Lenard-Bernstein and Full Coulomb collision operators 0.5 Load COSOlver matrices - 0.4 Benchmark with MOLI matlab results for Z-pinch (cf. kz_linear script) + 0.4 Benchmark with MOLI matlab results for Z-pinch (cf. ky_linear script) 0.3 RK4 time solver 0.2 implement moment hierarchy linear terms 0.1 implement linear Poisson equation in fourier space 0.0 go from 1D space to 2D fourier and from Hermite basis to Hermite-Laguerre basis # Roadmap 2. MPI parallel version 2.6 GK Full Coulomb collision operator 2.7 GPU? -3. GK 3D version, kr,kz,kpar for linear device +3. GK 3D version, kx,ky,kpar for linear device -4. DK 3D version, kr,kz,kpar for linear device +4. DK 3D version, kx,ky,kpar for linear device -5. DK+GK 3D version, kr,kz,kpar for linear device +5. DK+GK 3D version, kx,ky,kpar for linear device 6. 3D version with curvature diff --git a/matlab/COSOlver_matrices_analysis.m b/matlab/COSOlver_matrices_analysis.m index 1514d48..083eb5e 100644 --- a/matlab/COSOlver_matrices_analysis.m +++ b/matlab/COSOlver_matrices_analysis.m @@ -1,72 +1,72 @@ addpath(genpath('../matlab')) % ... add %% Grid configuration -N = 10; % Frequency gridpoints (Nkr = N/2) +N = 10; % 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); COSOlver_path = '../../Documents/MoliSolver/COSOlver/'; COSOLVER.pmaxe = 10; COSOLVER.jmaxe = 5; COSOLVER.pmaxi = 10; COSOLVER.jmaxi = 5; COSOLVER.neFLR = max(5,ceil(COSOLVER.kperp^2)); % rule of thumb for sum truncation COSOLVER.niFLR = max(5,ceil(COSOLVER.kperp^2)); COSOLVER.neFLRs = 0; % ... only for GK abel COSOLVER.npeFLR = 0; % ... only for GK abel COSOLVER.niFLRs = 0; % ... only for GK abel COSOLVER.npiFLR = 0; % ... only for GK abel COSOLVER.gk = 1; COSOLVER.co = 3; if 0 %% plot the kperp distribution figure plot(kperp) end %% Load the matrices C_self_i = zeros((COSOLVER.pmaxi+1)*(COSOLVER.jmaxi+1),(COSOLVER.pmaxi+1)*(COSOLVER.jmaxi+1),Nperp); for n_ = 1:Nperp COSOLVER.kperp = kperp(n_); k_string = sprintf('%0.4f',kperp(n_)); mat_file_name = ['../iCa/self_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ESELF_',num2str(COSOLVER.co),'_ISELF_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12',... '_NFLR_',num2str(COSOLVER.neFLR),... '_kperp_',k_string,'.h5']; tmp = h5read(mat_file_name,'/Caapj/Ceepj'); C_self_i(:,:,n_) = tmp; end %% Post processing dC_self_i = diff(C_self_i,1,3); gvar_dC = squeeze(sum(sum(abs(dC_self_i),2),1)); %% Plots %% all coeffs evolution figure for ip_ = 1:COSOLVER.pmaxi+1 for ij_ = 1:COSOLVER.jmaxi+1 plot(kperp,squeeze(C_self_i(ip_,ij_,:)),'o'); hold on; end end %% global matrix variation figure; kperpmid = 0.5*(kperp(2:end)+kperp(1:end-1)); plot(kperpmid,gvar_dC./diff(kperp)'); diff --git a/matlab/MOLI_kperp_scan.m b/matlab/MOLI_kperp_scan.m index 9920550..f87b507 100644 --- a/matlab/MOLI_kperp_scan.m +++ b/matlab/MOLI_kperp_scan.m @@ -1,166 +1,166 @@ %% Run MOLI for a scan in kperp %% Move to MOLI workspace cd ../../MoliSolver/MOLI/workspace/ %% Add paths my_paths %% Directories ROOT = '/home/ahoffman/Documents/MoliSolver'; options.dirs.COSOlverdir = fullfile(ROOT,'COSOlver'); options.dirs.MOLIdir = fullfile(ROOT,'MOLI'); %% MOLI Physical and Main Parameters % Solve DK AND/OR GK Linear Moment Hierarchy. options.DKI = 0; % First-order DK options.DKII = 0; % Second-order DK options.GK = 1; % Gyrokinetic GK options.EM = 0; % Include Electromagnetic effects (only for GK=1) options.GD = 0; % Gyro-Drift options.GDI = 0; % First/second order % Solve MOLI options.MOLI = 1; % 1 -> Solve MOLI, 0 -> off % MOLI Solver options.solver.solver = 3; % MOLI Linear Fit Solver options.LinFitSolver = 2; %% Main parameter scan % Closure by truncation params.Pmaxi = GRID.pmaxi; % parallel ion Hermite moments params.Jmaxi = GRID.jmaxi; % perpendicular ion Laguerre moments params.Pmaxe = GRID.pmaxe; % parallel electron Hermite moments params.Jmaxe = GRID.jmaxe; % perpendicular electron Laguerre moments % w/wo ions options.ions = 1; % if ions are present -> 1, 0 otherwise % Adiabatic electrons options.electrons = 1; % 0 -> adiabatic electrons, 1 no adiabatic electrons % w/wo soundwaves options.sw = 1; % 1 -> sound waves on, 0 -> put ion parallel velocity row/column to 0 %% Collision Operator Models and COSOlver Input Parameters options.collI = MODEL.CO; % collI=-2 -> Dougherty, -1 -> COSOlver, 0 -> Lenard-Bernstein, other -> hyperviscosity exponent options.collGK = 0; % collDKGK =1 -> GK collision operator, else DK collision operator options.COSOlver.GKE = 0; options.COSOlver.GKI = 0; % COSOlver Input Parameters (if collI = -1 only) options.COSOlver.eecolls = 1; % 1 -> electron-electron collisions, 0 -> off options.COSOlver.iicolls = 1; % 1 -> ion-ion collisions, 0 -> off options.COSOlver.eicolls = 1; % 1 -> electron-ion collisions (e-i) on, 0 -> off options.COSOlver.iecolls = 1; % 1 -> ion-electron collisions (i-e) on, 0 -> off % Collisional Coulomb sum bounds (only if collI = -1, i.e. Coulomb) options.COSOlver.lmaxx = 10; % upper bound collision operator first sum first species options.COSOlver.kmaxx = 10; % upper bound collision operator second sum first species options.COSOlver.nmaxx = options.COSOlver.lmaxx; % upper bound collision operator first sum second species options.COSOlver.qmaxx = options.COSOlver.kmaxx; % upper bound collision operator second sum second species % Collsion FLR sum bounds options.COSOlver.nemaxxFLR = 0; % upper bound FLR electron collision options.COSOlver.nimaxxFLR = 0; % upper bound FLR ion collision % Collision Operator Model % Set electron/ion test and back-reaction model operator % % 0 => Coulomb Collisions options.COSOlver.ETEST = 1; % 0 --> Buffer Operator, 1 --> Coulomb, 2 --> Lorentz options.COSOlver.EBACK = 1; options.COSOlver.ITEST = 1; options.COSOlver.IBACK = 1; options.COSOlver.ESELF = 1; options.COSOlver.ISELF = 1; options.COSOlver.OVERWRITE = 0; % overwrite collisional matrices even if exists options.COSOlver.cmd = 'mpirun -np 6 ./bin/CO 2 2 2'; %% Physical Parameters % Toroidal effects options.magnetic = 1; % 1-> Add toroidal magnetic gradient drift resonance effects % Physical Parameters params.tau = MODEL.tau_i; % Ti/Te params.nu = MODEL.nu; % electron/ion collision frequency ... only for nu/ omega_pe < nuoveromegapemax (electron plasma frequency) [See Banks et al. (2017)] params.nuoveromegapemax = inf; % Maximum ratio between electron/ion collision frequency and electron plasma frequency [See Banks et al. (2017)]. Set to inf if not desired !!! params.mu = MODEL.sigma_e; % sqrt(m_e/m_i) params.kpar = 0.0; % normalized parallel wave number to the major radius -params.kperp = GRID.kzmin; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b -params.kr = GRID.krmin; % Radial component of perpendicular vector +params.kperp = GRID.kymin; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b +params.kx = GRID.kxmin; % Radial component of perpendicular vector params.alphaD = 0.0; % (k*Debye length)^2 params.Rn = MODEL.eta_n; % Major Radius / Background density gradient length params.RTe = MODEL.eta_T; % Major Radius * normalized kperp / Background electron temperature gradient length params.RTi = MODEL.eta_T; % Major Radius * normalized kperp / Background ion temperature gradient length params.Rphi = 0.0; % Major Radius * normalized kperp / Background potentiel gradient length [presence of shear] - only for GK params.betae = 1e-6; % Electron Beta plasma. params.rhostar = 1e-5; % sound Larmor Radius/Major Radius ~ sqrt(Te)/(R_0*B). params.n0 = INITIAL.init_background; % initial density perturbation params.gradB = MODEL.eta_B; % Magnetic field gradient params.curvB = MODEL.eta_B; % Curvature of B params.trappB = 0.0; % Trapping term %% MOLI Options % Save data in results dir options.save = 0; options.verbose = 0; options.dbg = 0; options.DR = 0; % 1 -> Solve kinetic dispersion relation, options.KineticDR = 0; % Solve kinetic dispersion relation (Landau integral) for the given theory % Compute the kinetic susceptibility for EPW only options.SPTBLTY = 0; options.nharm = 1; % Number of harmonics in disp. rel. 1 and 4 wlim = 5.0; options.DRsolver.wr_min = -wlim; % Minimum of real part. options.DRsolver.wr_max = wlim; % Maximum of real part. options.DRsolver.wi_min = -wlim; % Minimum of imag part. options.DRsolver.wi_max = wlim; % Maximum of imag part. options.DRsolver.nw = 300; % Grid resolution % Disp. Rel. Options options.FLRmodel = 0; % 1 -> Truncated Laguerre, 0 -> Exact representation options.FluidLandau = 0; % 1 -> Add Landau Fluid Closure to Fluid Dispersion Relation, 0 -> off options.deltaLandau = 0; % 1 -> Hammet-Perkins closure on, 0 -> off % Fluid dispersion relation options.FluidDR = 0; % Solve annamaria's fluid equations options.Fluid.sITGmm = 0; % Define scan parameters options.fscan = 1; % 1 -> peform scan over scan.list, 0-> off options.scan.list = {'kperp'};% List of scan parameters. If empty, solve MOLI with params -options.scan.kperp.array = linspace(GRID.kzmin, GRID.kzmax, GRID.nkz); +options.scan.kperp.array = linspace(GRID.kymin, GRID.kymax, GRID.Nky); % Time-Evolution Problem [Solver==3] ... options.solver.TimeSolver.dt = BASIC.dt; % timestep of time evolution (R/c_s or 1/(k v/the) units) options.solver.TimeSolver.tmax = BASIC.tmax; options.solver.TimeSolver.Trun = BASIC.tmax; % total time to run time evolution options.solver.TimeSolver.t_fit_min = 0.05; % Phase-Mixing fit Lower time limit options.solver.TimeSolver.t_fit_max = 8; % Phase-Mixing fit Upper time limit options.solver.TimeSolver.en_fit_min = 0.15; % Entropy Mode fit Lower time limit options.solver.TimeSolver.en_fit_max = 0.3; % Entropy Mode fit Upper time limit options.solver.TimeSolver.movie = 0; % Display movie if 1, last frame otherwise options.solver.TimeSolver.save = 0; % 1 --> save during fscan, Warning: memory storage %% Run MOLI % Solve the MOLI [results,params,options] = MOLI_Control(params,options); %% Return to HeLaZ workspace cd ../../../HeLaZ/wk diff --git a/matlab/MOLI_time_solver.m b/matlab/MOLI_time_solver.m index c6c6ed3..659f69d 100644 --- a/matlab/MOLI_time_solver.m +++ b/matlab/MOLI_time_solver.m @@ -1,164 +1,164 @@ %% Run MOLI for a time evolution of the moments at a given kperp %% Move to MOLI workspace cd ../../MoliSolver/MOLI/workspace/ %% Add paths my_paths %% Directories ROOT = '/home/ahoffman/Documents/MoliSolver'; options.dirs.COSOlverdir = fullfile(ROOT,'COSOlver'); options.dirs.MOLIdir = fullfile(ROOT,'MOLI'); %% MOLI Physical and Main Parameters % Solve DK AND/OR GK Linear Moment Hierarchy. options.DKI = 0; % First-order DK options.DKII = 0; % Second-order DK options.GK = 1; % Gyrokinetic GK options.EM = 0; % Include Electromagnetic effects (only for GK=1) options.GD = 0; % Gyro-Drift options.GDI = 0; % First/second order % Solve MOLI options.MOLI = 1; % 1 -> Solve MOLI, 0 -> off % MOLI Solver options.solver.solver = 3; % MOLI Linear Fit Solver options.LinFitSolver = 0; %% Main parameter scan % Closure by truncation params.Pmaxi = GRID.pmaxi; % parallel ion Hermite moments params.Jmaxi = GRID.jmaxi; % perpendicular ion Laguerre moments params.Pmaxe = GRID.pmaxe; % parallel electron Hermite moments params.Jmaxe = GRID.jmaxe; % perpendicular electron Laguerre moments % w/wo ions options.ions = 1; % if ions are present -> 1, 0 otherwise % Adiabatic electrons options.electrons = 1; % 0 -> adiabatic electrons, 1 no adiabatic electrons % w/wo soundwaves options.sw = 1; % 1 -> sound waves on, 0 -> put ion parallel velocity row/column to 0 %% Collision Operator Models and COSOlver Input Parameters options.collI = MODEL.CO; % collI=-2 -> Dougherty, -1 -> COSOlver, 0 -> Lenard-Bernstein, other -> hyperviscosity exponent options.collGK = 0; % collDKGK =1 -> GK collision operator, else DK collision operator options.COSOlver.GKE = 0; options.COSOlver.GKI = 0; % COSOlver Input Parameters (if collI = -1 only) options.COSOlver.eecolls = 1; % 1 -> electron-electron collisions, 0 -> off options.COSOlver.iicolls = 1; % 1 -> ion-ion collisions, 0 -> off options.COSOlver.eicolls = 1; % 1 -> electron-ion collisions (e-i) on, 0 -> off options.COSOlver.iecolls = 1; % 1 -> ion-electron collisions (i-e) on, 0 -> off % Collisional Coulomb sum bounds (only if collI = -1, i.e. Coulomb) options.COSOlver.lmaxx = 10; % upper bound collision operator first sum first species options.COSOlver.kmaxx = 10; % upper bound collision operator second sum first species options.COSOlver.nmaxx = options.COSOlver.lmaxx; % upper bound collision operator first sum second species options.COSOlver.qmaxx = options.COSOlver.kmaxx; % upper bound collision operator second sum second species % Collsion FLR sum bounds options.COSOlver.nemaxxFLR = 0; % upper bound FLR electron collision options.COSOlver.nimaxxFLR = 0; % upper bound FLR ion collision % Collision Operator Model % Set electron/ion test and back-reaction model operator % % 0 => Coulomb Collisions options.COSOlver.ETEST = 1; % 0 --> Buffer Operator, 1 --> Coulomb, 2 --> Lorentz options.COSOlver.EBACK = 1; options.COSOlver.ITEST = 1; options.COSOlver.IBACK = 1; options.COSOlver.ESELF = 1; options.COSOlver.ISELF = 1; options.COSOlver.OVERWRITE = 0; % overwrite collisional matrices even if exists options.COSOlver.cmd = 'mpirun -np 6 ./bin/CO 2 2 2'; %% Physical Parameters % Toroidal effects options.magnetic = 1; % 1-> Add toroidal magnetic gradient drift resonance effects % Physical Parameters params.tau = MODEL.tau_i; % Ti/Te params.nu = MODEL.nu; % electron/ion collision frequency ... only for nu/ omega_pe < nuoveromegapemax (electron plasma frequency) [See Banks et al. (2017)] params.nuoveromegapemax = inf; % Maximum ratio between electron/ion collision frequency and electron plasma frequency [See Banks et al. (2017)]. Set to inf if not desired !!! params.mu = MODEL.sigma_e; % sqrt(m_e/m_i) params.kpar = 0.0; % normalized parallel wave number to the major radius -params.kperp = kz_MOLI; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b -params.kr = kr_MOLI; % Radial component of perpendicular vector +params.kperp = ky_MOLI; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b +params.kx = kx_MOLI; % Radial component of perpendicular vector params.alphaD = 0.0; % (k*Debye length)^2 params.Rn = MODEL.eta_n; % Major Radius / Background density gradient length params.RTe = MODEL.eta_T; % Major Radius * normalized kperp / Background electron temperature gradient length params.RTi = MODEL.eta_T; % Major Radius * normalized kperp / Background ion temperature gradient length params.Rphi = 0.0; % Major Radius * normalized kperp / Background potentiel gradient length [presence of shear] - only for GK params.betae = 1e-6; % Electron Beta plasma. params.rhostar = 1e-5; % sound Larmor Radius/Major Radius ~ sqrt(Te)/(R_0*B). params.n0 = INITIAL.init_background; % initial density perturbation params.gradB = MODEL.eta_B; % Magnetic field gradient params.curvB = MODEL.eta_B; % Curvature of B params.trappB = 0.0; % Trapping term %% MOLI Options % Save data in results dir options.save = 0; options.verbose = 0; options.dbg = 0; options.DR = 0; % 1 -> Solve kinetic dispersion relation, options.KineticDR = 0; % Solve kinetic dispersion relation (Landau integral) for the given theory % Compute the kinetic susceptibility for EPW only options.SPTBLTY = 0; options.nharm = 1; % Number of harmonics in disp. rel. 1 and 4 wlim = 5.0; options.DRsolver.wr_min = -wlim; % Minimum of real part. options.DRsolver.wr_max = wlim; % Maximum of real part. options.DRsolver.wi_min = -wlim; % Minimum of imag part. options.DRsolver.wi_max = wlim; % Maximum of imag part. options.DRsolver.nw = 300; % Grid resolution % Disp. Rel. Options options.FLRmodel = 0; % 1 -> Truncated Laguerre, 0 -> Exact representation options.FluidLandau = 0; % 1 -> Add Landau Fluid Closure to Fluid Dispersion Relation, 0 -> off options.deltaLandau = 0; % 1 -> Hammet-Perkins closure on, 0 -> off % Fluid dispersion relation options.FluidDR = 0; % Solve annamaria's fluid equations options.Fluid.sITGmm = 0; % Define scan parameters options.fscan = 0; % 1 -> peform scan over scan.list, 0-> off options.scan.list = {};% List of scan parameters. If empty, solve MOLI with params % Time-Evolution Problem [Solver==3] ... options.solver.TimeSolver.dt = BASIC.dt; % timestep of time evolution (R/c_s or 1/(k v/the) units) options.solver.TimeSolver.tmax = BASIC.tmax; options.solver.TimeSolver.Trun = BASIC.tmax; % total time to run time evolution options.solver.TimeSolver.t_fit_min = 0.05; % Phase-Mixing fit Lower time limit options.solver.TimeSolver.t_fit_max = 8; % Phase-Mixing fit Upper time limit options.solver.TimeSolver.en_fit_min = 0.15; % Entropy Mode fit Lower time limit options.solver.TimeSolver.en_fit_max = 0.3; % Entropy Mode fit Upper time limit options.solver.TimeSolver.movie = 0; % Display movie if 1, last frame otherwise options.solver.TimeSolver.save = 0; % 1 --> save during fscan, Warning: memory storage %% Run MOLI % Solve the MOLI [results,params,options] = MOLI_Control(params,options); %% Return to HeLaZ workspace cd ../../../HeLaZ/wk diff --git a/matlab/MOLI_time_solver_2D.m b/matlab/MOLI_time_solver_2D.m index a356c5e..a838179 100644 --- a/matlab/MOLI_time_solver_2D.m +++ b/matlab/MOLI_time_solver_2D.m @@ -1,164 +1,164 @@ %% Run MOLI for a time evolution of the moments at a given kperp %% Move to MOLI workspace cd ../../MoliSolver/MOLI/workspace/ %% Add paths my_paths %% Directories ROOT = '/home/ahoffman/Documents/MoliSolver'; options.dirs.COSOlverdir = fullfile(ROOT,'COSOlver'); options.dirs.MOLIdir = fullfile(ROOT,'MOLI'); %% MOLI Physical and Main Parameters % Solve DK AND/OR GK Linear Moment Hierarchy. options.DKI = 0; % First-order DK options.DKII = 0; % Second-order DK options.GK = 1; % Gyrokinetic GK options.EM = 0; % Include Electromagnetic effects (only for GK=1) options.GD = 0; % Gyro-Drift options.GDI = 0; % First/second order % Solve MOLI options.MOLI = 1; % 1 -> Solve MOLI, 0 -> off % MOLI Solver options.solver.solver = 3; % MOLI Linear Fit Solver options.LinFitSolver = 0; %% Main parameter scan % Closure by truncation params.Pmaxi = GRID.pmaxi; % parallel ion Hermite moments params.Jmaxi = GRID.jmaxi; % perpendicular ion Laguerre moments params.Pmaxe = GRID.pmaxe; % parallel electron Hermite moments params.Jmaxe = GRID.jmaxe; % perpendicular electron Laguerre moments % w/wo ions options.ions = 1; % if ions are present -> 1, 0 otherwise % Adiabatic electrons options.electrons = 1; % 0 -> adiabatic electrons, 1 no adiabatic electrons % w/wo soundwaves options.sw = 1; % 1 -> sound waves on, 0 -> put ion parallel velocity row/column to 0 %% Collision Operator Models and COSOlver Input Parameters options.collI = MODEL.CO; % collI=-2 -> Dougherty, -1 -> COSOlver, 0 -> Lenard-Bernstein, other -> hyperviscosity exponent options.collGK = 0; % collDKGK =1 -> GK collision operator, else DK collision operator options.COSOlver.GKE = 0; options.COSOlver.GKI = 0; % COSOlver Input Parameters (if collI = -1 only) options.COSOlver.eecolls = 1; % 1 -> electron-electron collisions, 0 -> off options.COSOlver.iicolls = 1; % 1 -> ion-ion collisions, 0 -> off options.COSOlver.eicolls = 1; % 1 -> electron-ion collisions (e-i) on, 0 -> off options.COSOlver.iecolls = 1; % 1 -> ion-electron collisions (i-e) on, 0 -> off % Collisional Coulomb sum bounds (only if collI = -1, i.e. Coulomb) options.COSOlver.lmaxx = 10; % upper bound collision operator first sum first species options.COSOlver.kmaxx = 10; % upper bound collision operator second sum first species options.COSOlver.nmaxx = options.COSOlver.lmaxx; % upper bound collision operator first sum second species options.COSOlver.qmaxx = options.COSOlver.kmaxx; % upper bound collision operator second sum second species % Collsion FLR sum bounds options.COSOlver.nemaxxFLR = 0; % upper bound FLR electron collision options.COSOlver.nimaxxFLR = 0; % upper bound FLR ion collision % Collision Operator Model % Set electron/ion test and back-reaction model operator % % 0 => Coulomb Collisions options.COSOlver.ETEST = 1; % 0 --> Buffer Operator, 1 --> Coulomb, 2 --> Lorentz options.COSOlver.EBACK = 1; options.COSOlver.ITEST = 1; options.COSOlver.IBACK = 1; options.COSOlver.ESELF = 1; options.COSOlver.ISELF = 1; options.COSOlver.OVERWRITE = 0; % overwrite collisional matrices even if exists options.COSOlver.cmd = 'mpirun -np 6 ./bin/CO 2 2 2'; %% Physical Parameters % Toroidal effects options.magnetic = 1; % 1-> Add toroidal magnetic gradient drift resonance effects % Physical Parameters params.tau = MODEL.tau_i; % Ti/Te params.nu = MODEL.nu; % electron/ion collision frequency ... only for nu/ omega_pe < nuoveromegapemax (electron plasma frequency) [See Banks et al. (2017)] params.nuoveromegapemax = inf; % Maximum ratio between electron/ion collision frequency and electron plasma frequency [See Banks et al. (2017)]. Set to inf if not desired !!! params.mu = MODEL.sigma_e; % sqrt(m_e/m_i) params.kpar = 0.0; % normalized parallel wave number to the major radius -params.kperp = kz; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b -params.kr = kr; % Radial component of perpendicular vector +params.kperp = ky; % normalized perpendicular toroidal wave number to the soundLarmor radius. Note: If ions ==0 (e.g. EPW), kperp --> b +params.kx = kx; % Radial component of perpendicular vector params.alphaD = 0.0; % (k*Debye length)^2 params.Rn = MODEL.eta_n; % Major Radius / Background density gradient length params.RTe = MODEL.eta_T; % Major Radius * normalized kperp / Background electron temperature gradient length params.RTi = MODEL.eta_T; % Major Radius * normalized kperp / Background ion temperature gradient length params.Rphi = 0.0; % Major Radius * normalized kperp / Background potentiel gradient length [presence of shear] - only for GK params.betae = 1e-6; % Electron Beta plasma. params.rhostar = 1e-5; % sound Larmor Radius/Major Radius ~ sqrt(Te)/(R_0*B). params.n0 = INITIAL.init_background; % initial density perturbation params.gradB = MODEL.eta_B; % Magnetic field gradient params.curvB = MODEL.eta_B; % Curvature of B params.trappB = 0.0; % Trapping term %% MOLI Options % Save data in results dir options.save = 0; options.verbose = 0; options.dbg = 0; options.DR = 0; % 1 -> Solve kinetic dispersion relation, options.KineticDR = 0; % Solve kinetic dispersion relation (Landau integral) for the given theory % Compute the kinetic susceptibility for EPW only options.SPTBLTY = 0; options.nharm = 1; % Number of harmonics in disp. rel. 1 and 4 wlim = 5.0; options.DRsolver.wr_min = -wlim; % Minimum of real part. options.DRsolver.wr_max = wlim; % Maximum of real part. options.DRsolver.wi_min = -wlim; % Minimum of imag part. options.DRsolver.wi_max = wlim; % Maximum of imag part. options.DRsolver.nw = 300; % Grid resolution % Disp. Rel. Options options.FLRmodel = 0; % 1 -> Truncated Laguerre, 0 -> Exact representation options.FluidLandau = 0; % 1 -> Add Landau Fluid Closure to Fluid Dispersion Relation, 0 -> off options.deltaLandau = 0; % 1 -> Hammet-Perkins closure on, 0 -> off % Fluid dispersion relation options.FluidDR = 0; % Solve annamaria's fluid equations options.Fluid.sITGmm = 0; % Define scan parameters options.fscan = 0; % 1 -> peform scan over scan.list, 0-> off options.scan.list = {};% List of scan parameters. If empty, solve MOLI with params % Time-Evolution Problem [Solver==3] ... options.solver.TimeSolver.dt = BASIC.dt; % timestep of time evolution (R/c_s or 1/(k v/the) units) options.solver.TimeSolver.tmax = BASIC.tmax; options.solver.TimeSolver.Trun = BASIC.tmax; % total time to run time evolution options.solver.TimeSolver.t_fit_min = 0.05; % Phase-Mixing fit Lower time limit options.solver.TimeSolver.t_fit_max = 8; % Phase-Mixing fit Upper time limit options.solver.TimeSolver.en_fit_min = 0.15; % Entropy Mode fit Lower time limit options.solver.TimeSolver.en_fit_max = 0.3; % Entropy Mode fit Upper time limit options.solver.TimeSolver.movie = 0; % Display movie if 1, last frame otherwise options.solver.TimeSolver.save = 0; % 1 --> save during fscan, Warning: memory storage %% Run MOLI % Solve the MOLI [results,params,options] = MOLI_Control(params,options); %% Return to HeLaZ workspace cd ../../../HeLaZ/wk diff --git a/matlab/check_checkpoint.m b/matlab/check_checkpoint.m index 8265cf4..021138d 100644 --- a/matlab/check_checkpoint.m +++ b/matlab/check_checkpoint.m @@ -1,19 +1,19 @@ function [] = check_checkpoint(cp_ID, OUTPUTS) cp_fname = OUTPUTS.rstfile0; cp_fname = [cp_fname(2:end-1),'_%.2d.h5']; cp_fname = sprintf(cp_fname,cp_ID) tmp = h5read(cp_fname,'/Basic/moments_i'); Nipj_cp = tmp.real + 1i * tmp.imaginary; t_cp = h5readatt(cp_fname,'/Basic','time'); -[~,~,Nr,Nz] = size(Nipj_cp); +[~,~,Nx,Ny] = size(Nipj_cp); % ni00_cp = fftshift(ifft2(half_2_full_cc_2D(squeeze(Nipj_cp(1,1,:,:))),'symmetric')); -ni00_cp = real(fftshift(ifft2(squeeze(Nipj_cp(1,1,:,:)),Nz,Nz))); +ni00_cp = real(fftshift(ifft2(squeeze(Nipj_cp(1,1,:,:)),Ny,Ny))); fig = figure; pclr=pcolor(transpose(ni00_cp(:,:)));set(pclr, 'edgecolor','none'); colorbar; title(['$n_i^{00}$',', $t \approx$', sprintf('%.3d',ceil(t_cp))]); xlabel('$i_r$'); ylabel('$i_z$'); end \ No newline at end of file diff --git a/matlab/compute_Sapj.m b/matlab/compute_Sapj.m index 0a708aa..3e4f873 100644 --- a/matlab/compute_Sapj.m +++ b/matlab/compute_Sapj.m @@ -1,37 +1,37 @@ -function [ Sapj ] = compute_Sapj(p, j, Kr, Kz, Napj, specie, phi, MODEL, GRID) +function [ Sapj ] = compute_Sapj(p, j, kx, ky, Napj, specie, phi, MODEL, GRID) %COMPUT_SAPJ compute the non linear term for moment pj specie a % perform a convolution by product of inverse fourier transform and then % put the results back into k space with an FFT Jmax = GRID.jmaxe * (specie=='e')... + GRID.jmaxi * (specie=='i'); %padding Pad = 2.0; - Sapj = zeros(numel(Kr), numel(Kz)); - F = zeros(numel(Kr), numel(Kz)); - G = zeros(numel(Kr), numel(Kz)); + Sapj = zeros(numel(kx), numel(ky)); + F = zeros(numel(kx), numel(ky)); + G = zeros(numel(kx), numel(ky)); for n = 0:Jmax % Sum over Laguerre - for ikr = 1:numel(Kr) - for ikz = 1:numel(Kz) - kr = Kr(ikr); kz = Kz(ikz); - BA = sqrt(kr^2+kz^2)*... + for ikx = 1:numel(kx) + for iky = 1:numel(ky) + kx = kx(ikx); ky = ky(iky); + BA = sqrt(kx^2+ky^2)*... (MODEL.sigma_e*sqrt(2) * (specie=='e')... + sqrt(2*MODEL.tau_i) * (specie=='i')); %First conv term - F(ikr,ikz) = (kz-kr).*phi(ikr,ikz).*kernel(n,BA); + F(ikx,iky) = (ky-kx).*phi(ikx,iky).*kernel(n,BA); %Second conv term - G(ikr,ikz) = 0.0; + G(ikx,iky) = 0.0; for s = 0:min(n+j,Jmax) - G(ikr,ikz) = ... - G(ikr,ikz) + dnjs(n,j,s) .* squeeze(Napj(p+1,s+1,ikr,ikz)); + G(ikx,iky) = ... + G(ikx,iky) + dnjs(n,j,s) .* squeeze(Napj(p+1,s+1,ikx,iky)); end - G(ikr,ikz) = (kz-kr) .* G(ikr,ikz); + G(ikx,iky) = (ky-kx) .* G(ikx,iky); end end %Conv theorem Sapj = Sapj + conv_thm_2D(F,G,Pad); end end diff --git a/matlab/conv_thm_2D.m b/matlab/conv_thm_2D.m index 6f2b445..31e274f 100644 --- a/matlab/conv_thm_2D.m +++ b/matlab/conv_thm_2D.m @@ -1,14 +1,14 @@ function [ conv ] = conv_thm_2D( F, G, Pad ) %conv_thm_2D computes the convolution between F and G with a zero pading Pad % kspace -> real -> product -> kspace -[Nr, Nz] = size(F); +[Nx, Ny] = size(F); -f = ifft2(F,Nr*Pad, Nz*Pad); -g = ifft2(G,Nr*Pad, Nz*Pad); +f = ifft2(F,Nx*Pad, Ny*Pad); +g = ifft2(G,Nx*Pad, Ny*Pad); conv_pad = fft2(f.*g); % convolution becomes product -conv = conv_pad(1:Nr,1:Nz); % remove padding +conv = conv_pad(1:Nx,1:Ny); % remove padding end diff --git a/matlab/half_2_full_cc_2D.m b/matlab/half_2_full_cc_2D.m index 481ee16..eb052ac 100644 --- a/matlab/half_2_full_cc_2D.m +++ b/matlab/half_2_full_cc_2D.m @@ -1,27 +1,27 @@ function [ FF_f ] = half_2_full_cc_2D( FF_h ) %half_2_full_cc_2D Retrieve full domain frequency from half domain % Meant for complex conjugate symmetric fields -[Nkr,Nkz] = size(FF_h); +[Nkx,Nky] = size(FF_h); -if Nkr > Nkz +if Nkx > Nky FF_f = zeros(max(size(FF_h))); - FF_f(1:Nkr,1:Nkz) = FF_h; + FF_f(1:Nkx,1:Nky) = FF_h; - for ikr = 1:Nkr - for ikz = Nkr/2+2:Nkr - FF_f(ikr,ikz) = FF_f(Nkr-ikr+1,Nkr-ikz+1); + for ikx = 1:Nkx + for iky = Nkx/2+2:Nkx + FF_f(ikx,iky) = FF_f(Nkx-ikx+1,Nkx-iky+1); end end else FF_f = zeros(max(size(FF_h))); - FF_f(1:Nkr,1:Nkz) = FF_h; + FF_f(1:Nkx,1:Nky) = FF_h; - for ikz = 1:Nkz - for ikr = Nkz/2+2:Nkz - FF_f(ikr,ikz) = FF_f(Nkz-ikr+1,Nkz-ikz+1); + for iky = 1:Nky + for ikx = Nky/2+2:Nky + FF_f(ikx,iky) = FF_f(Nky-ikx+1,Nky-iky+1); end end end end diff --git a/matlab/helaz_analysis.m b/matlab/helaz_analysis.m index e623ae8..3ac51a0 100644 --- a/matlab/helaz_analysis.m +++ b/matlab/helaz_analysis.m @@ -1,27 +1,27 @@ %% HeLaZ data filename = 'results_00.h5'; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Load the data moment = 'Ni00'; -kr = h5read(filename,['/data/var2d/' moment '/coordkr']); -kz = h5read(filename,['/data/var2d/' moment '/coordkz']); +kx = h5read(filename,['/data/var2d/' moment '/coordkx']); +ky = h5read(filename,['/data/var2d/' moment '/coordky']); timeNi = h5read(filename,'/data/var2d/time'); -Nipj = zeros(numel(timeNi),numel(kr),numel(kz)); +Nipj = zeros(numel(timeNi),numel(kx),numel(ky)); for it = 1:numel(timeNi) tmp = h5read(filename,['/data/var2d/', moment,'/', num2str(it,'%06d')]); Nipj(it,:,:) = tmp.real + 1i * tmp.imaginary; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% Plot growth rate vs kz +%% Plot growth rate vs ky K_RICCI = 1; %% add a sqrt(1+tau) to the kperps -ikr = 1; %% Fix the kr value +ikx = 1; %% Fix the kx value plot_gamma_vs_k; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Plot Ni00 evolution -ikr = 1; %% Fix the kr value +ikx = 1; %% Fix the kx value plot_Ni00_t_evolution; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \ No newline at end of file diff --git a/matlab/load_2D_data.m b/matlab/load_2D_data.m index 47ef91a..b013a63 100644 --- a/matlab/load_2D_data.m +++ b/matlab/load_2D_data.m @@ -1,16 +1,16 @@ function [ data, time, dt ] = load_2D_data( filename, variablename ) %LOAD_2D_DATA load a 2D variable stored in a hdf5 result file from HeLaZ time = h5read(filename,'/data/var2d/time'); - kr = h5read(filename,'/data/grid/coordkr'); - kz = h5read(filename,'/data/grid/coordkz'); + kx = h5read(filename,'/data/grid/coordkx'); + ky = h5read(filename,'/data/grid/coordky'); dt = h5readatt(filename,'/data/input','dt'); cstart= h5readatt(filename,'/data/input','start_iframe2d'); - data = zeros(numel(kr),numel(kz),numel(time)); + data = zeros(numel(kx),numel(ky),numel(time)); for it = 1:numel(time) tmp = h5read(filename,['/data/var2d/',variablename,'/', num2str(cstart+it,'%06d')]); data(:,:,it) = tmp.real + 1i * tmp.imaginary; end end diff --git a/matlab/load_5D_data.m b/matlab/load_5D_data.m index e36d767..d08e943 100644 --- a/matlab/load_5D_data.m +++ b/matlab/load_5D_data.m @@ -1,23 +1,23 @@ function [ data, time, dt ] = load_5D_data( filename, variablename ) %LOAD_5D_DATA load a 5D variable stored in a hdf5 result file from HeLaZ time = h5read(filename,'/data/var5d/time'); if strcmp(variablename,'moments_e') || strcmp(variablename,'Sepj') p = h5read(filename,'/data/grid/coordp_e'); j = h5read(filename,'/data/grid/coordj_e'); else p = h5read(filename,'/data/grid/coordp_i'); j = h5read(filename,'/data/grid/coordj_i'); end - kr = h5read(filename,'/data/grid/coordkr'); - kz = h5read(filename,'/data/grid/coordkz'); + kx = h5read(filename,'/data/grid/coordkx'); + ky = h5read(filename,'/data/grid/coordky'); dt = h5readatt(filename,'/data/input','dt'); cstart= h5readatt(filename,'/data/input','start_iframe5d'); - data = zeros(numel(p),numel(j),numel(kr),numel(kz),numel(time)); + data = zeros(numel(p),numel(j),numel(kx),numel(ky),numel(time)); for it = 1:numel(time) tmp = h5read(filename,['/data/var5d/', variablename,'/', num2str(cstart+it,'%06d')]); data(:,:,:,:,it) = tmp.real + 1i * tmp.imaginary; end end \ No newline at end of file diff --git a/matlab/load_grid_data.m b/matlab/load_grid_data.m index 4318157..f0835ca 100644 --- a/matlab/load_grid_data.m +++ b/matlab/load_grid_data.m @@ -1,9 +1,9 @@ -function [ pe, je, pi, ji, kr, kz ] = load_grid_data( filename ) +function [ pe, je, pi, ji, kx, ky ] = load_grid_data( filename ) %LOAD_GRID_DATA stored in a hdf5 result file from HeLaZ pe = h5read(filename,'/data/grid/coordp_e'); je = h5read(filename,'/data/grid/coordj_e'); pi = h5read(filename,'/data/grid/coordp_i'); ji = h5read(filename,'/data/grid/coordj_i'); - kr = h5read(filename,'/data/grid/coordkr'); - kz = h5read(filename,'/data/grid/coordkz'); + kx = h5read(filename,'/data/grid/coordkx'); + ky = h5read(filename,'/data/grid/coordky'); end \ No newline at end of file diff --git a/matlab/load_params.m b/matlab/load_params.m index c74d7b1..336c305 100644 --- a/matlab/load_params.m +++ b/matlab/load_params.m @@ -1,56 +1,56 @@ CO = h5readatt(filename,'/data/input','CO'); ETAB = h5readatt(filename,'/data/input','eta_B'); ETAN = h5readatt(filename,'/data/input','eta_n'); ETAT = h5readatt(filename,'/data/input','eta_T'); PMAXI = h5readatt(filename,'/data/input','pmaxi'); JMAXI = h5readatt(filename,'/data/input','jmaxi'); PMAXE = h5readatt(filename,'/data/input','pmaxe'); JMAXE = h5readatt(filename,'/data/input','jmaxe'); NON_LIN = h5readatt(filename,'/data/input','NON_LIN'); NU = h5readatt(filename,'/data/input','nu'); -NR = h5readatt(filename,'/data/input','nr'); -NZ = h5readatt(filename,'/data/input','nz'); -L = h5readatt(filename,'/data/input','Lr'); +Nx = h5readatt(filename,'/data/input','Nx'); +Ny = h5readatt(filename,'/data/input','Ny'); +L = h5readatt(filename,'/data/input','Lx'); CLOS = h5readatt(filename,'/data/input','CLOS'); DT_SIM = h5readatt(filename,'/data/input','dt'); -% MU = h5readatt(filename,'/data/input','mu'); -MU = str2num(filename(end-18:end-14)); %bad... +MU = h5readatt(filename,'/data/input','mu'); +% MU = str2num(filename(end-18:end-14)); %bad... W_GAMMA = h5readatt(filename,'/data/input','write_gamma') == 'y'; W_PHI = h5readatt(filename,'/data/input','write_phi') == 'y'; W_NA00 = h5readatt(filename,'/data/input','write_Na00') == 'y'; W_NAPJ = h5readatt(filename,'/data/input','write_Napj') == 'y'; W_SAPJ = h5readatt(filename,'/data/input','write_Sapj') == 'y'; if NON_LIN == 'y' NON_LIN = 1; else NON_LIN = 0; end if (CO == -3); CONAME = 'PADK'; elseif(CO == -2); CONAME = 'SGDK'; elseif(CO == -1); CONAME = 'DGDK'; elseif(CO == 0); CONAME = 'LB'; elseif(CO == 1); CONAME = 'DGGK'; elseif(CO == 2); CONAME = 'SGGK'; elseif(CO == 3); CONAME = 'PAGK'; end if (CLOS == 0); CLOSNAME = 'Trunc.'; elseif(CLOS == 1); CLOSNAME = 'Clos. 1'; elseif(CLOS == 2); CLOSNAME = 'Clos. 2'; end if (PMAXE == PMAXI) && (JMAXE == JMAXI) degngrad = ['P_',num2str(PMAXE),'_J_',num2str(JMAXE)]; else degngrad = ['Pe_',num2str(PMAXE),'_Je_',num2str(JMAXE),... '_Pi_',num2str(PMAXI),'_Ji_',num2str(JMAXI)]; end -degngrad = [degngrad,'_eta_',num2str(ETAB/ETAN),'_nu_%0.0e_',... +degngrad = [degngrad,'_eta_%1.1f_nu_%0.0e_',... CONAME,'_CLOS_',num2str(CLOS),'_mu_%0.0e']; -degngrad = sprintf(degngrad,[NU,MU]); +degngrad = sprintf(degngrad,[ETAB/ETAN,NU,MU]); if ~NON_LIN; degngrad = ['lin_',degngrad]; end -resolution = [num2str(NR),'x',num2str(NZ/2),'_']; +resolution = [num2str(Nx),'x',num2str(Ny/2),'_']; gridname = ['L_',num2str(L),'_']; PARAMS = [resolution,gridname,degngrad]; % BASIC.RESDIR = [SIMDIR,PARAMS,'/']; diff --git a/matlab/load_results.m b/matlab/load_results.m index 412b92a..f947eda 100644 --- a/matlab/load_results.m +++ b/matlab/load_results.m @@ -1,51 +1,51 @@ %% load results %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% disp(['Loading ',filename]) % Loading from output file CPUTIME = h5readatt(filename,'/data/input','cpu_time'); DT_SIM = h5readatt(filename,'/data/input','dt'); -[Pe, Je, Pi, Ji, kr, kz] = load_grid_data(filename); +[Pe, Je, Pi, Ji, kx, ky] = load_grid_data(filename); W_GAMMA = strcmp(h5readatt(filename,'/data/input','write_gamma'),'y'); W_PHI = strcmp(h5readatt(filename,'/data/input','write_phi') ,'y'); W_NA00 = strcmp(h5readatt(filename,'/data/input','write_Na00') ,'y'); W_NAPJ = strcmp(h5readatt(filename,'/data/input','write_Napj') ,'y'); W_SAPJ = strcmp(h5readatt(filename,'/data/input','write_Sapj') ,'y'); W_DENS = strcmp(h5readatt(filename,'/data/input','write_dens') ,'y'); W_TEMP = strcmp(h5readatt(filename,'/data/input','write_temp') ,'y'); if W_GAMMA [ GGAMMA_RI, Ts0D, dt0D] = load_0D_data(filename, 'gflux_ri'); PGAMMA_RI = load_0D_data(filename, 'pflux_ri'); end if W_PHI [ PHI, Ts2D, dt2D] = load_2D_data(filename, 'phi'); end if W_NA00 [Ni00, Ts2D, dt2D] = load_2D_data(filename, 'Ni00'); Ne00 = load_2D_data(filename, 'Ne00'); end if W_NAPJ [Nipj, Ts5D, dt5D] = load_5D_data(filename, 'moments_i'); [Nepj ] = load_5D_data(filename, 'moments_e'); end if W_SAPJ [Sipj, Ts5D, dt5D] = load_5D_data(filename, 'Sipj'); Sepj = load_5D_data(filename, 'Sepj'); end if W_DENS [DENS_E, Ts2D, dt2D] = load_2D_data(filename, 'dens_e'); [DENS_I, Ts2D, dt2D] = load_2D_data(filename, 'dens_i'); end if W_TEMP [TEMP_E, Ts2D, dt2D] = load_2D_data(filename, 'temp_e'); [TEMP_I, Ts2D, dt2D] = load_2D_data(filename, 'temp_i'); end \ No newline at end of file diff --git a/matlab/plot_Ni00_t_evolution.m b/matlab/plot_Ni00_t_evolution.m index d5aa35d..711eec6 100644 --- a/matlab/plot_Ni00_t_evolution.m +++ b/matlab/plot_Ni00_t_evolution.m @@ -1,44 +1,44 @@ %% Plot the time evolution of the firt ion moment default_plots_options % Script to set up default plot variables fig = figure; LEGEND = []; x1 = timeNi; -for ikz = 1:2:numel(kz) +for iky = 1:2:numel(ky) - linename = ['$k_r = ',num2str(kr(ikr)),'$, ','$k_z = ',num2str(kz(ikz)),'$']; - y1 = abs(Nipj(:,ikr,ikz)); + linename = ['$k_r = ',num2str(kx(ikx)),'$, ','$k_z = ',num2str(ky(iky)),'$']; + y1 = abs(Nipj(:,ikx,iky)); semilogy(x1,y1,'DisplayName',linename) LEGEND = [LEGEND, linename]; hold on end -for ikz = 1:2:numel(kz) +for iky = 1:2:numel(ky) semilogy(x1(itmin:end),... - exp(gammas(ikr,ikz)*x1(itmin:end) + shifts(ikr,ikz)),... + exp(gammas(ikx,iky)*x1(itmin:end) + shifts(ikx,iky)),... 'Color', 'k', 'LineStyle', '--','HandleVisibility','off') end LEGEND = [LEGEND, 'fits']; TITLE = []; TITLE = [TITLE,'$\eta_n=',num2str(MODEL.eta_n),'$, ']; TITLE = [TITLE,'$\eta_B=',num2str(MODEL.eta_B),'$, ']; TITLE = [TITLE, '$\nu=',num2str(MODEL.nu),'$, ']; TITLE = [TITLE, '$(P,J)=(',num2str(GRID.pmaxe),',',num2str(GRID.jmaxe),')$']; title(TITLE); grid on xlabel('$t$') ylabel(['$|',moment,'|$']) %% Saving fig FIGNAME = 'Ni00_t'; if SAVEFIG save_figure; end \ No newline at end of file diff --git a/matlab/plot_gamma_vs_k.m b/matlab/plot_gamma_vs_k.m index 250b4a1..1707ff1 100644 --- a/matlab/plot_gamma_vs_k.m +++ b/matlab/plot_gamma_vs_k.m @@ -1,45 +1,45 @@ -%Plot growth rate vs kz +%Plot growth rate vs ky default_plots_options % Script to set up default plot variables % with a linear fit of the log evolution -gammas = zeros(numel(kr),numel(kz)); -shifts = zeros(numel(kr),numel(kz)); +gammas = zeros(numel(kx),numel(ky)); +shifts = zeros(numel(kx),numel(ky)); if K_RICCI factor = sqrt(1+MODEL.tau_i); fchar = '\times(1+\tau)^{1/2}$'; else factor = 1; fchar = '$'; end % Linear fit of log(Napj) x1 = timeNi; itmin = ceil(0.9 * numel(timeNi)); %Take a subset of the time evolution -for ikz = 1:numel(kz) - fit = polyfit(x1(itmin:end),log(abs(Nipj(itmin:end,ikr,ikz))),1); - gammas(ikr,ikz) = fit(1); - shifts(ikr,ikz) = fit(2); +for iky = 1:numel(ky) + fit = polyfit(x1(itmin:end),log(abs(Nipj(itmin:end,ikx,iky))),1); + gammas(ikx,iky) = fit(1); + shifts(ikx,iky) = fit(2); end fig = figure; linename = ['$(P,J)=(',num2str(GRID.pmaxe),',',num2str(GRID.jmaxe),')$']; -plot(factor*kz,gammas(ikr,:),'DisplayName',linename); +plot(factor*ky,gammas(ikx,:),'DisplayName',linename); TITLE = []; TITLE = [TITLE,'$\eta_n=',num2str(1.0/MODEL.eta_n),'$, ']; TITLE = [TITLE,'$\eta_B=',num2str(MODEL.eta_B),'$, ']; TITLE = [TITLE, '$\nu=',num2str(MODEL.nu),'$, ']; -%TITLE = [TITLE, '$k_z=',num2str(GRID.kz),'$']; +%TITLE = [TITLE, '$k_z=',num2str(GRID.ky),'$']; title(TITLE); grid on legend('show') xlabel(['$k_z',fchar]) ylabel('$\gamma L_\perp/c_{s} $') %% Saving fig if SAVEFIG FIGNAME = 'gamma_k'; save_figure; end diff --git a/matlab/plot_kernels.m b/matlab/plot_kernels.m index f772984..f7eede8 100644 --- a/matlab/plot_kernels.m +++ b/matlab/plot_kernels.m @@ -1,46 +1,46 @@ %% Kernels kmax=7; nmax=6; -kr_ = linspace(0,kmax,100); +kx_ = linspace(0,kmax,100); figure for n_ = 0:nmax - plot(kr_,kernel(n_,kr_),'DisplayName',['$\mathcal{K}_{',num2str(n_),'}$']);hold on; + plot(kx_,kernel(n_,kx_),'DisplayName',['$\mathcal{K}_{',num2str(n_),'}$']);hold on; end ylim_ = ylim; -plot(kr_(end)*[2/3 2/3],ylim_,'--k','DisplayName','AA'); -plot(kr_,J0,'-r','DisplayName','$J_0$'); +plot(kx_(end)*[2/3 2/3],ylim_,'--k','DisplayName','AA'); +plot(kx_,J0,'-r','DisplayName','$J_0$'); legend('show') %% Bessels and approx vperp = linspace(0,1.5,4); nmax1=5; nmax2=10; kmax=7; figure for i = 1:4 subplot(2,2,i) v_ = vperp(i); - kr_ = linspace(0,kmax,100); + kx_ = linspace(0,kmax,100); - J0 = besselj(0,kr_*v_); - A1 = 1 - kr_.^2*v_^2/4; - K1 = zeros(size(kr_)); - K2 = zeros(size(kr_)); + J0 = besselj(0,kx_*v_); + A1 = 1 - kx_.^2*v_^2/4; + K1 = zeros(size(kx_)); + K2 = zeros(size(kx_)); for n_ = 0:nmax1 - K1 = K1 + kernel(n_,kr_).*polyval(LaguerrePoly(n_),v_^2); + K1 = K1 + kernel(n_,kx_).*polyval(LaguerrePoly(n_),v_^2); end for n_ = 0:nmax2 - K2 = K2 + kernel(n_,kr_).*polyval(LaguerrePoly(n_),v_^2); + K2 = K2 + kernel(n_,kx_).*polyval(LaguerrePoly(n_),v_^2); end - plot(kr_,J0,'-k','DisplayName','$J_0(kv)$'); hold on; - plot(kr_,A1,'-r','DisplayName','$1 - k^2 v^2/4$'); - plot(kr_,K1,'--b','DisplayName',['$\sum_{n=0}^{',num2str(nmax1),'}\mathcal K_n(k) L^n(v)$']); - plot(kr_,K2,'-b','DisplayName',['$\sum_{n=0}^{',num2str(nmax2),'}\mathcal K_n(k) L^n(v)$']); + plot(kx_,J0,'-k','DisplayName','$J_0(kv)$'); hold on; + plot(kx_,A1,'-r','DisplayName','$1 - k^2 v^2/4$'); + plot(kx_,K1,'--b','DisplayName',['$\sum_{n=0}^{',num2str(nmax1),'}\mathcal K_n(k) L^n(v)$']); + plot(kx_,K2,'-b','DisplayName',['$\sum_{n=0}^{',num2str(nmax2),'}\mathcal K_n(k) L^n(v)$']); ylim_ = [-0.5, 1.0]; - plot(kr_(end)*[2/3 2/3],ylim_,'--k','DisplayName','AA'); + plot(kx_(end)*[2/3 2/3],ylim_,'--k','DisplayName','AA'); ylim(ylim_); xlabel('$k$') legend('show'); grid on; title(['$v = ',num2str(v_),'$']) end %% \ No newline at end of file diff --git a/matlab/setup.m b/matlab/setup.m index bf6f7c2..432b7b1 100644 --- a/matlab/setup.m +++ b/matlab/setup.m @@ -1,135 +1,135 @@ %% ________________________________________________________________________ SIMDIR = ['../results/',SIMID,'/']; % Grid parameters GRID.pmaxe = PMAXE; % Electron Hermite moments GRID.jmaxe = JMAXE; % Electron Laguerre moments GRID.pmaxi = PMAXI; % Ion Hermite moments GRID.jmaxi = JMAXI; % Ion Laguerre moments -GRID.Nr = N; % r grid resolution -GRID.Lr = L; % r length -GRID.Nz = N * (1-KREQ0) + KREQ0; % z '' -GRID.Lz = L * (1-KREQ0); % z '' +GRID.Nx = N; % r grid resolution +GRID.Lx = L; % r length +GRID.Ny = N * (1-KXEQ0) + KXEQ0; % z '' +GRID.Ly = L * (1-KXEQ0); % z '' GRID.kpar = KPAR; % Model parameters MODEL.CO = CO; % Collision operator (0 : L.Bernstein, -1 : Full Coulomb, -2 : Dougherty) MODEL.CLOS = CLOS; MODEL.NL_CLOS = NL_CLOS; if NON_LIN; MODEL.NON_LIN = '.true.'; else; MODEL.NON_LIN = '.false.';end; MODEL.mu = MU; MODEL.mu_p = MU_P; MODEL.mu_j = MU_J; MODEL.nu = NU; % hyper diffusive coefficient nu for HW % temperature ratio T_a/T_e MODEL.tau_e = TAU; MODEL.tau_i = TAU; % mass ratio sqrt(m_a/m_i) MODEL.sigma_e = 0.0233380; MODEL.sigma_i = 1.0; % charge q_a/e MODEL.q_e =-1.0; MODEL.q_i = 1.0; if MODEL.q_e == 0; SIMID = [SIMID,'_i']; end; % gradients L_perp/L_x MODEL.eta_n = ETAN; % source term kappa for HW MODEL.eta_T = ETAT; % Temperature MODEL.eta_B = ETAB; % Magnetic MODEL.lambdaD = LAMBDAD; -% if A0KH ~= 0; SIMID = [SIMID,'_Nz_',num2str(L/2/pi*KR0KH),'_A_',num2str(A0KH)]; end; +% if A0KH ~= 0; SIMID = [SIMID,'_Nz_',num2str(L/2/pi*KX0KH),'_A_',num2str(A0KH)]; end; % Time integration and intialization parameters TIME_INTEGRATION.numerical_scheme = '''RK4'''; if (INIT_PHI); INITIAL.init_noisy_phi = '.true.'; else; INITIAL.init_noisy_phi = '.false.';end; INITIAL.INIT_ZF = INIT_ZF; INITIAL.init_background = (INIT_ZF>0)*ZF_AMP; INITIAL.init_noiselvl = NOISE0; INITIAL.iseed = 42; INITIAL.mat_file = '''null'''; if (abs(CO) == 2) %Sugama operator - INITIAL.mat_file = ['''../../../iCa/gk_sugama_P_20_J_10_N_150_kpm_8.h5''']; + INITIAL.mat_file = ['''../../../iCa/gk_sugama_P_20_J_10_N_150_kpm_8.0.h5''']; elseif (abs(CO) == 3) %pitch angle operator INITIAL.mat_file = ['''../../../iCa/gk_pitchangle_8_P_20_J_10_N_150_kpm_8.0.h5''']; elseif (CO == 4) % Full Coulomb GK disp('Warning, FCGK not implemented yet') elseif (CO == -1) % DGDK disp('Warning, DGDK not debugged') end % Naming and creating input file if (CO == -3); CONAME = 'PADK'; elseif(CO == -2); CONAME = 'SGDK'; elseif(CO == -1); CONAME = 'DGDK'; elseif(CO == 0); CONAME = 'LB'; elseif(CO == 1); CONAME = 'DGGK'; elseif(CO == 2); CONAME = 'SGGK'; elseif(CO == 3); CONAME = 'PAGK'; end if (CLOS == 0); CLOSNAME = 'Trunc.'; elseif(CLOS == 1); CLOSNAME = 'Clos. 1'; elseif(CLOS == 2); CLOSNAME = 'Clos. 2'; end if (PMAXE == PMAXI) && (JMAXE == JMAXI) degngrad = ['P_',num2str(PMAXE),'_J_',num2str(JMAXE)]; else degngrad = ['Pe_',num2str(PMAXE),'_Je_',num2str(JMAXE),... '_Pi_',num2str(PMAXI),'_Ji_',num2str(JMAXI)]; end degngrad = [degngrad,'_eta_',num2str(ETAB/ETAN),'_nu_%0.0e_',... CONAME,'_CLOS_',num2str(CLOS),'_mu_%0.0e']; degngrad = sprintf(degngrad,[NU,MU]); if ~NON_LIN; degngrad = ['lin_',degngrad]; end -resolution = [num2str(GRID.Nr),'x',num2str(GRID.Nz/2),'_']; +resolution = [num2str(GRID.Nx),'x',num2str(GRID.Ny/2),'_']; gridname = ['L_',num2str(L),'_']; if (exist('PREFIX','var') == 0); PREFIX = []; end; if (exist('SUFFIX','var') == 0); SUFFIX = []; end; PARAMS = [PREFIX,resolution,gridname,degngrad,SUFFIX]; BASIC.RESDIR = [SIMDIR,PARAMS,'/']; BASIC.MISCDIR = ['/misc/HeLaZ_outputs/',SIMDIR(4:end),PARAMS,'/']; BASIC.PARAMS = PARAMS; BASIC.SIMID = SIMID; BASIC.nrun = 1e8; BASIC.dt = DT; BASIC.tmax = TMAX; %time normalized to 1/omega_pe BASIC.maxruntime = str2num(CLUSTER.TIME(1:2))*3600 ... + str2num(CLUSTER.TIME(4:5))*60 ... + str2num(CLUSTER.TIME(7:8)); % Outputs parameters if RESTART; BASIC.RESTART = '.true.'; else; BASIC.RESTART = '.false.';end; OUTPUTS.nsave_0d = floor(1.0/SPS0D/DT); OUTPUTS.nsave_1d = -1; OUTPUTS.nsave_2d = floor(1.0/SPS2D/DT); OUTPUTS.nsave_5d = floor(1.0/SPS5D/DT); OUTPUTS.nsave_cp = floor(1.0/SPSCP/DT); if W_DOUBLE; OUTPUTS.write_doubleprecision = '.true.'; else; OUTPUTS.write_doubleprecision = '.false.';end; if W_GAMMA; OUTPUTS.write_gamma = '.true.'; else; OUTPUTS.write_gamma = '.false.';end; if W_PHI; OUTPUTS.write_phi = '.true.'; else; OUTPUTS.write_phi = '.false.';end; if W_NA00; OUTPUTS.write_Na00 = '.true.'; else; OUTPUTS.write_Na00 = '.false.';end; if W_NAPJ; OUTPUTS.write_Napj = '.true.'; else; OUTPUTS.write_Napj = '.false.';end; if W_SAPJ; OUTPUTS.write_Sapj = '.true.'; else; OUTPUTS.write_Sapj = '.false.';end; if W_DENS; OUTPUTS.write_dens = '.true.'; else; OUTPUTS.write_dens = '.false.';end; if W_TEMP; OUTPUTS.write_temp = '.true.'; else; OUTPUTS.write_temp = '.false.';end; OUTPUTS.resfile0 = '''outputs'''; OUTPUTS.rstfile0 = '''checkpoint'''; OUTPUTS.job2load = JOB2LOAD; %% Create directories if ~exist(SIMDIR, 'dir') mkdir(SIMDIR) end if ~exist(BASIC.RESDIR, 'dir') mkdir(BASIC.RESDIR) end if ~exist(BASIC.MISCDIR, 'dir') mkdir(BASIC.MISCDIR) end %% Compile and WRITE input file INPUT = write_fort90(OUTPUTS,GRID,MODEL,INITIAL,TIME_INTEGRATION,BASIC); nproc = 1; MAKE = 'cd ..; make; cd wk'; system(MAKE); %% disp(['Set up ',SIMID]); disp([resolution,gridname,degngrad]); if RESTART disp(['- restarting from JOBNUM = ',num2str(JOB2LOAD)]); else disp(['- starting from T = 0']); end diff --git a/matlab/write_fort90.m b/matlab/write_fort90.m index 19ccdf5..b2a7c25 100644 --- a/matlab/write_fort90.m +++ b/matlab/write_fort90.m @@ -1,82 +1,82 @@ function [INPUT] = write_fort90(OUTPUTS,GRID,MODEL,INITIAL,TIME_INTEGRATION,BASIC) % Write the input script "fort.90" with desired parameters INPUT = 'fort.90'; fid = fopen(INPUT,'wt'); fprintf(fid,'&BASIC\n'); fprintf(fid,[' nrun = ', num2str(BASIC.nrun),'\n']); fprintf(fid,[' dt = ', num2str(BASIC.dt),'\n']); fprintf(fid,[' tmax = ', num2str(BASIC.tmax),'\n']); fprintf(fid,[' RESTART = ', BASIC.RESTART,'\n']); fprintf(fid,[' maxruntime = ', num2str(BASIC.maxruntime),'\n']); fprintf(fid,'/\n'); fprintf(fid,'&GRID\n'); fprintf(fid,[' pmaxe =', num2str(GRID.pmaxe),'\n']); fprintf(fid,[' jmaxe = ', num2str(GRID.jmaxe),'\n']); fprintf(fid,[' pmaxi = ', num2str(GRID.pmaxi),'\n']); fprintf(fid,[' jmaxi = ', num2str(GRID.jmaxi),'\n']); -fprintf(fid,[' Nr = ', num2str(GRID.Nr),'\n']); -fprintf(fid,[' Lr = ', num2str(GRID.Lr),'\n']); -fprintf(fid,[' Nz = ', num2str(GRID.Nz),'\n']); -fprintf(fid,[' Lz = ', num2str(GRID.Lz),'\n']); +fprintf(fid,[' Nx = ', num2str(GRID.Nx),'\n']); +fprintf(fid,[' Lx = ', num2str(GRID.Lx),'\n']); +fprintf(fid,[' Ny = ', num2str(GRID.Ny),'\n']); +fprintf(fid,[' Ly = ', num2str(GRID.Ly),'\n']); fprintf(fid,[' kpar = ', num2str(GRID.kpar),'\n']); fprintf(fid,'/\n'); fprintf(fid,'&OUTPUT_PAR\n'); fprintf(fid,[' nsave_0d = ', num2str(OUTPUTS.nsave_0d),'\n']); fprintf(fid,[' nsave_1d = ', num2str(OUTPUTS.nsave_1d),'\n']); fprintf(fid,[' nsave_2d = ', num2str(OUTPUTS.nsave_2d),'\n']); fprintf(fid,[' nsave_5d = ', num2str(OUTPUTS.nsave_5d),'\n']); fprintf(fid,[' nsave_cp = ', num2str(OUTPUTS.nsave_cp),'\n']); fprintf(fid,[' write_doubleprecision = ', OUTPUTS.write_doubleprecision,'\n']); fprintf(fid,[' write_gamma = ', OUTPUTS.write_gamma,'\n']); fprintf(fid,[' write_phi = ', OUTPUTS.write_phi,'\n']); fprintf(fid,[' write_Na00 = ', OUTPUTS.write_Na00,'\n']); fprintf(fid,[' write_Napj = ', OUTPUTS.write_Napj,'\n']); fprintf(fid,[' write_Sapj = ', OUTPUTS.write_Sapj,'\n']); fprintf(fid,[' write_dens = ', OUTPUTS.write_dens,'\n']); fprintf(fid,[' write_temp = ', OUTPUTS.write_temp,'\n']); fprintf(fid,[' resfile0 = ', OUTPUTS.resfile0,'\n']); fprintf(fid,[' rstfile0 = ', OUTPUTS.rstfile0,'\n']); fprintf(fid,[' job2load = ', num2str(OUTPUTS.job2load),'\n']); fprintf(fid,'/\n'); fprintf(fid,'&MODEL_PAR\n'); fprintf(fid,' ! Collisionality\n'); fprintf(fid,[' CO = ', num2str(MODEL.CO),'\n']); fprintf(fid,[' CLOS = ', num2str(MODEL.CLOS),'\n']); fprintf(fid,[' NL_CLOS = ', num2str(MODEL.NL_CLOS),'\n']); fprintf(fid,[' NON_LIN = ', MODEL.NON_LIN,'\n']); fprintf(fid,[' mu = ', num2str(MODEL.mu),'\n']); fprintf(fid,[' mu_p = ', num2str(MODEL.mu_p),'\n']); fprintf(fid,[' mu_j = ', num2str(MODEL.mu_j),'\n']); fprintf(fid,[' nu = ', num2str(MODEL.nu),'\n']); fprintf(fid,[' tau_e = ', num2str(MODEL.tau_e),'\n']); fprintf(fid,[' tau_i = ', num2str(MODEL.tau_i),'\n']); fprintf(fid,[' sigma_e = ', num2str(MODEL.sigma_e),'\n']); fprintf(fid,[' sigma_i = ', num2str(MODEL.sigma_i),'\n']); fprintf(fid,[' q_e = ', num2str(MODEL.q_e),'\n']); fprintf(fid,[' q_i = ', num2str(MODEL.q_i),'\n']); fprintf(fid,[' eta_n = ', num2str(MODEL.eta_n),'\n']); fprintf(fid,[' eta_T = ', num2str(MODEL.eta_T),'\n']); fprintf(fid,[' eta_B = ', num2str(MODEL.eta_B),'\n']); fprintf(fid,[' lambdaD = ', num2str(MODEL.lambdaD),'\n']); fprintf(fid,'/\n'); fprintf(fid,'&INITIAL_CON\n'); fprintf(fid,[' INIT_NOISY_PHI =', INITIAL.init_noisy_phi,'\n']); fprintf(fid,[' INIT_ZF =', num2str(INITIAL.INIT_ZF),'\n']); fprintf(fid,[' init_background =', num2str(INITIAL.init_background),'\n']); fprintf(fid,[' init_noiselvl =', num2str(INITIAL.init_noiselvl),'\n']); fprintf(fid,[' iseed =', num2str(INITIAL.iseed),'\n']); fprintf(fid,[' mat_file =', INITIAL.mat_file,'\n']); fprintf(fid,'/\n'); fprintf(fid,'&TIME_INTEGRATION_PAR\n'); fprintf(fid,[' numerical_scheme=', TIME_INTEGRATION.numerical_scheme,'\n']); fprintf(fid,'/'); fclose(fid); system(['cp fort.90 ',BASIC.RESDIR,'/.']); end diff --git a/matlab/write_sbash_daint.m b/matlab/write_sbash_daint.m index 98c1e35..62a48ac 100644 --- a/matlab/write_sbash_daint.m +++ b/matlab/write_sbash_daint.m @@ -1,57 +1,57 @@ % Write the input script "fort.90" with desired parameters INPUT = 'setup_and_run.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... 'mkdir -p $SCRATCH/HeLaZ/wk\n',... ... 'cd $SCRATCH/HeLaZ/wk/\n',... ... 'mkdir -p ', BASIC.RESDIR,'\n',... 'cd ',BASIC.RESDIR,'\n',... 'cp $HOME/HeLaZ/wk/fort.90 .\n',... 'cp $HOME/HeLaZ/wk/batch_script.sh .\n',... ... 'jid=$(sbatch batch_script.sh)\n',... 'echo $jid\n',... 'echo to check output log :\n',... 'echo tail -f $SCRATCH/HeLaZ/results/',BASIC.SIMID,'/',BASIC.PARAMS,'/out.txt']); fclose(fid); system(['cp setup_and_run.sh ',BASIC.RESDIR,'/.']); % Write the sbatch script INPUT = 'batch_script.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... '#SBATCH --job-name="',CLUSTER.JNAME,'"\n',... '#SBATCH --time=', CLUSTER.TIME,'\n',... '#SBATCH --nodes=', CLUSTER.NODES,'\n',... '#SBATCH --cpus-per-task=', CLUSTER.CPUPT,'\n',... '#SBATCH --ntasks-per-node=', CLUSTER.NTPN,'\n',... '#SBATCH --ntasks-per-core=', CLUSTER.NTPC,'\n',... '#SBATCH --mem=', CLUSTER.MEM,'\n',... '#SBATCH --error=err.txt\n',... '#SBATCH --output=out.txt\n',... '#SBATCH --account="s882"\n',... '#SBATCH --constraint=mc\n',... '#SBATCH --hint=nomultithread\n',... '#SBATCH --partition=',CLUSTER.PART,'\n',... 'export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK\n',... ...% '#SBATCH --job-name=',PARAMS,'\n\n',... 'module purge\n',... 'module load PrgEnv-intel\n',... 'module load cray-hdf5-parallel\n',... 'module load cray-mpich\n',... 'module load craype-x86-skylake\n',... 'module load cray-fftw\n',... -'srun --cpu-bind=cores ./../../../bin/helaz ',num2str(NP_P),' ',num2str(NP_KR)]); +'srun --cpu-bind=cores ./../../../bin/helaz ',num2str(NP_P),' ',num2str(NP_KX)]); %'srun ./../../../bin/helaz']); fclose(fid); system(['cp batch_script.sh ',BASIC.RESDIR,'/.']); system('scp {fort.90,setup_and_run.sh,batch_script.sh} ahoffman@ela.cscs.ch:HeLaZ/wk'); \ No newline at end of file diff --git a/matlab/write_sbash_izar.m b/matlab/write_sbash_izar.m index 01c7334..02224f4 100644 --- a/matlab/write_sbash_izar.m +++ b/matlab/write_sbash_izar.m @@ -1,46 +1,46 @@ % Write the input script "fort.90" with desired parameters INPUT = 'setup_and_run.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... 'mkdir -p $SCRATCH/ahoffman/HeLaZ/wk\n',... ... 'cd $SCRATCH/ahoffman/HeLaZ/wk/\n',... ... 'mkdir -p ', BASIC.RESDIR,'\n',... 'cd ',BASIC.RESDIR,'\n',... 'cp $HOME/HeLaZ/wk/fort.90 .\n',... 'cp $HOME/HeLaZ/wk/batch_script.sh .\n',... ... 'sbatch batch_script.sh\n',... 'echo tail -f $SCRATCH/ahoffman/HeLaZ/results/',BASIC.SIMID,'/',BASIC.PARAMS,'/out.txt']); fclose(fid); system(['cp setup_and_run.sh ',BASIC.RESDIR,'/.']); % Write the sbatch script INPUT = 'batch_script.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... '#SBATCH --chdir $SCRATCH/ahoffman/HeLaZ/results/',BASIC.SIMID,'/',BASIC.PARAMS,'\n',... '#SBATCH --job-name ',CLUSTER.JNAME,'\n',... '#SBATCH --time ', CLUSTER.TIME,'\n',... '#SBATCH --nodes ', CLUSTER.NODES,'\n',... '#SBATCH --cpus-per-task ', CLUSTER.CPUPT,'\n',... '#SBATCH --ntasks-per-node ', CLUSTER.NTPN,'\n',... '#SBATCH --mem ', CLUSTER.MEM,'\n',... '#SBATCH --partition ',CLUSTER.PART,'\n',... 'module purge\n',... 'module load intel/19.0.5\n',... 'module load intel-mpi/2019.5.281\n',... 'module load fftw/3.3.8-mpi-openmp\n',... 'module load hdf5/1.10.6-mpi\n',... -'srun --cpu-bind=cores ./../../../bin/helaz ',num2str(NP_P),' ',num2str(NP_KR)]); +'srun --cpu-bind=cores ./../../../bin/helaz ',num2str(NP_P),' ',num2str(NP_KX)]); fclose(fid); system(['cp batch_script.sh ',BASIC.RESDIR,'/.']); system('scp {fort.90,setup_and_run.sh,batch_script.sh} ahoffman@izar.epfl.ch:/home/ahoffman/HeLaZ/wk'); \ No newline at end of file diff --git a/matlab/write_sbash_marconi.m b/matlab/write_sbash_marconi.m index 8caf105..d4fde78 100644 --- a/matlab/write_sbash_marconi.m +++ b/matlab/write_sbash_marconi.m @@ -1,45 +1,45 @@ % Write the input script "fort.90" with desired parameters INPUT = 'setup_and_run.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... 'mkdir -p $CINECA_SCRATCH/HeLaZ/wk\n',... ... 'cd $CINECA_SCRATCH/HeLaZ/wk/\n',... ... 'mkdir -p ', BASIC.RESDIR,'\n',... 'cd ',BASIC.RESDIR,'\n',... 'cp $HOME/HeLaZ/wk/fort.90 .\n',... 'cp $HOME/HeLaZ/wk/batch_script.sh .\n',... ... 'sbatch batch_script.sh\n',... 'echo tail -f $CINECA_SCRATCH/HeLaZ',BASIC.RESDIR(3:end),'out.txt']); fclose(fid); system(['cp setup_and_run.sh ',BASIC.RESDIR,'/.']); % Write the sbatch script INPUT = 'batch_script.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... '#SBATCH --job-name=',CLUSTER.JNAME,'\n',... '#SBATCH --time=', CLUSTER.TIME,'\n',... '#SBATCH --nodes=', CLUSTER.NODES,'\n',... '#SBATCH --cpus-per-task=', CLUSTER.CPUPT,'\n',... '#SBATCH --ntasks-per-node=', CLUSTER.NTPN,'\n',... '#SBATCH --mem=', CLUSTER.MEM,'\n',... '#SBATCH --error=err.txt\n',... '#SBATCH --output=out.txt\n',... '#SBATCH --account=FUA35_TSVVT421\n',... '#SBATCH --partition=skl_fua_',CLUSTER.PART,'\n',... 'module load autoload hdf5 fftw\n',... -'srun --cpu-bind=cores ./../../../bin/',EXECNAME,' ',num2str(NP_P),' ',num2str(NP_KR)]); +'srun --cpu-bind=cores ./../../../bin/',EXECNAME,' ',num2str(NP_P),' ',num2str(NP_KX)]); fclose(fid); system(['cp batch_script.sh ',BASIC.RESDIR,'/.']); system('scp {fort.90,setup_and_run.sh,batch_script.sh} ahoffman@login.marconi.cineca.it:/marconi/home/userexternal/ahoffman/HeLaZ/wk > trash.txt'); system('rm trash.txt'); \ No newline at end of file diff --git a/src/advance_field.F90 b/src/advance_field.F90 index b542906..9227ccc 100644 --- a/src/advance_field.F90 +++ b/src/advance_field.F90 @@ -1,97 +1,97 @@ MODULE advance_field_routine USE prec_const implicit none CONTAINS SUBROUTINE advance_time_level USE basic USE time_integration use prec_const IMPLICIT NONE CALL set_updatetlevel(mod(updatetlevel,ntimelevel)+1) END SUBROUTINE advance_time_level SUBROUTINE advance_moments USE basic USE time_integration USE grid use prec_const use fields, ONLY: moments_e, moments_i use array, ONLY: moments_rhs_e, moments_rhs_i IMPLICIT NONE INTEGER :: istage ! Execution time start CALL cpu_time(t0_adv_field) 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) 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) 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); 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) 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); 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) END DO END SELECT ! Execution time end CALL cpu_time(t1_adv_field) tc_adv_field = tc_adv_field + (t1_adv_field - t0_adv_field) END SUBROUTINE advance_moments SUBROUTINE advance_field( f, f_rhs ) USE basic USE time_integration USE array USE grid 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 INTEGER :: istage SELECT CASE (updatetlevel) CASE(1) - DO ikz=ikzs,ikze - DO ikr=ikrs,ikre + DO iky=ikys,ikye + DO ikx=ikxs,ikxe 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 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 END SELECT END SUBROUTINE advance_field END MODULE advance_field_routine diff --git a/src/advance_field_adapt.F90 b/src/advance_field_adapt.F90 index 2380904..aed2a7e 100644 --- a/src/advance_field_adapt.F90 +++ b/src/advance_field_adapt.F90 @@ -1,80 +1,80 @@ MODULE advance_field_routine USE prec_const implicit none CONTAINS SUBROUTINE advance_time_level USE basic USE time_integration use prec_const IMPLICIT NONE CALL set_updatetlevel(mod(updatetlevel,ntimelevel)+1) END SUBROUTINE advance_time_level SUBROUTINE advance_field( f, f_rhs ) USE basic USE time_integration USE array USE grid 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 SELECT CASE (updatetlevel) CASE(1) SELECT CASE (numerical_scheme) 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 END SELECT END SUBROUTINE advance_field END MODULE advance_field_routine diff --git a/src/array_mod.F90 b/src/array_mod.F90 index 85560f4..120e38d 100644 --- a/src/array_mod.F90 +++ b/src/array_mod.F90 @@ -1,43 +1,43 @@ 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) + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_rhs_e ! (ip,ij,ikx,iky,updatetlevel) + COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_rhs_i ! (ip,ij,ikx,iky,updatetlevel) ! To load collision matrix 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 ! dnjs coefficient storage (in, ij, is) COMPLEX(dp), DIMENSION(:,:,:), ALLOCATABLE :: dnjs ! Kernel function evaluation REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: kernel_e REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: kernel_i - ! Non linear term array (ip,ij,ikr,ikz) + ! Non linear term array (ip,ij,ikx,iky) 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 ! particle density for electron and ions (meant for 2D output) 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 END MODULE array diff --git a/src/auxval.F90 b/src/auxval.F90 index ff50aba..64cc462 100644 --- a/src/auxval.F90 +++ b/src/auxval.F90 @@ -1,59 +1,59 @@ subroutine auxval ! Set auxiliary values, at beginning of simulation USE basic USE grid USE array USE model USE fourier, ONLY: init_grid_distr_and_plans, alloc_local_1, alloc_local_2 use prec_const 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 CALL set_pgrid CALL set_jgrid - CALL set_krgrid ! MPI Distributed dimension - CALL set_kzgrid + CALL set_kxgrid ! MPI Distributed dimension + CALL set_kygrid CALL set_kpgrid CALL memory ! Allocate memory for global arrays !! 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 + 'my_id = ', my_id, ', rank_p = ', rank_p, ', rank_kx = ', rank_kx WRITE(*,'(A22,I3,A10,I3)')& - ' ips_e = ', ips_e, ', ikrs = ', ikrs + ' ips_e = ', ips_e, ', ikxs = ', ikxs WRITE(*,'(A22,I3,A10,I3)')& - ' ipe_e = ', ipe_e, ', ikre = ', ikre + ' ipe_e = ', ipe_e, ', ikxe = ', ikxe WRITE(*,'(A22,I3,A10,I3)')& - ' ips_i = ', ips_i, ', ikzs = ', ikzs + ' ips_i = ', ips_i, ', ikys = ', ikys WRITE(*,'(A22,I3,A10,I3)')& - ' ipe_i = ', ipe_i, ', ikze = ', ikze + ' ipe_i = ', ipe_i, ', ikye = ', ikye ! 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 + ! ' ikxs = ', ikxs, ', ikxe = ', ikxe, ', ikys = ', ikys, ', ikye = ', ikye IF (my_id .NE. num_procs-1) WRITE (*,*) '' IF (my_id .EQ. num_procs-1) WRITE(*,*) '------------------------------------------' ENDIF ENDDO CALL mpi_barrier(MPI_COMM_WORLD, ierr) END SUBROUTINE auxval diff --git a/src/basic_mod.F90 b/src/basic_mod.F90 index 4516673..c6f007a 100644 --- a/src/basic_mod.F90 +++ b/src/basic_mod.F90 @@ -1,297 +1,297 @@ MODULE basic ! Basic module for time dependent problems use, intrinsic :: iso_c_binding use prec_const IMPLICIT none ! INCLUDE 'fftw3-mpi.f03' INTEGER :: nrun = 1 ! Number of time steps to run real(dp) :: tmax = 100000.0 ! Maximum simulation time real(dp) :: dt = 1.0 ! Time step 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 INTEGER :: cstep = 0 ! Current step number (Init from restart file) LOGICAL :: RESTART = .FALSE. ! Signal end of run LOGICAL :: nlend = .FALSE. ! Signal end of run LOGICAL :: crashed = .FALSE. ! Signal end of crashed run INTEGER :: ierr ! flag for MPI error 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) INTEGER :: iframe2d ! counting the number of times 2d datasets are outputed (for diagnose) INTEGER :: iframe3d ! counting the number of times 3d datasets are outputed (for diagnose) INTEGER :: iframe5d ! counting the number of times 5d datasets are outputed (for diagnose) ! List of logical file units INTEGER :: lu_in = 90 ! File duplicated from STDIN INTEGER :: lu_job = 91 ! myjob file ! To measure computation time real :: start, finish real(dp) :: t0_rhs, t0_adv_field, t0_poisson, t0_Sapj, t0_diag, t0_checkfield,& t0_step, t0_clos, t0_ghost, t0_coll real(dp) :: t1_rhs, t1_adv_field, t1_poisson, t1_Sapj, t1_diag, t1_checkfield,& t1_step, t1_clos, t1_ghost, t1_coll real(dp) :: tc_rhs, tc_adv_field, tc_poisson, tc_Sapj, tc_diag, tc_checkfield,& tc_step, tc_clos, tc_ghost, tc_coll 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_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 CONTAINS !================================================================================ SUBROUTINE basic_data ! Read basic data for input file use prec_const IMPLICIT NONE NAMELIST /BASIC/ nrun, dt, tmax, RESTART, maxruntime READ(lu_in,basic) !Init cumulative timers tc_rhs = 0.;tc_adv_field = 0.; tc_poisson = 0. tc_Sapj = 0.; tc_diag = 0.; tc_checkfield = 0. END SUBROUTINE basic_data !================================================================================ SUBROUTINE daytim(str) ! Print date and time use prec_const IMPLICIT NONE CHARACTER(len=*) , INTENT(in) :: str CHARACTER(len=16) :: d, t, dat, time !________________________________________________________________________________ ! CALL DATE_AND_TIME(d,t) dat=d(7:8) // '/' // d(5:6) // '/' // d(1:4) time=t(1:2) // ':' // t(3:4) // ':' // t(5:10) WRITE(*,'(a,1x,a,1x,a)') str, dat(1:10), time(1:12) ! END SUBROUTINE daytim !================================================================================ SUBROUTINE display_h_min_s(time) real :: time integer :: days, hours, mins, secs days = FLOOR(time/24./3600.); hours= FLOOR(time/3600.); mins = FLOOR(time/60.); secs = FLOOR(time); IF ( days .GT. 0 ) THEN !display day h min s hours = (time/3600./24. - days) * 24 mins = (time/3600. - days*24. - hours) * 60 secs = (time/60. - days*24.*60 - hours*60 - mins) * 60 WRITE(*,*) 'CPU Time = ', days, '[day]', hours, '[h]', mins, '[min]', secs, '[s]' WRITE(*,*) '(',time,'[s])' ELSEIF ( hours .GT. 0 ) THEN !display h min s mins = (time/3600. - hours) * 60 secs = (time/60. - hours*60 - mins) * 60 WRITE(*,*) 'CPU Time = ', hours, '[h]', mins, '[min]', secs, '[s]' WRITE(*,*) '(',time,'[s])' ELSEIF ( mins .GT. 0 ) THEN !display min s secs = (time/60. - mins) * 60 WRITE(*,*) 'CPU Time = ', mins, '[min]', secs, '[s]' WRITE(*,*) '(',time,'[s])' ELSE ! display s WRITE(*,*) 'CPU Time = ', FLOOR(time), '[s]' ENDIF END SUBROUTINE display_h_min_s !================================================================================ ! To allocate arrays of doubles, integers, etc. at run time SUBROUTINE allocate_array_dp1(a,is1,ie1) IMPLICIT NONE real(dp), DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1 ALLOCATE(a(is1:ie1)) a=0.0_dp END SUBROUTINE allocate_array_dp1 SUBROUTINE allocate_array_dp2(a,is1,ie1,is2,ie2) IMPLICIT NONE real(dp), DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2 ALLOCATE(a(is1:ie1,is2:ie2)) a=0.0_dp END SUBROUTINE allocate_array_dp2 SUBROUTINE allocate_array_dp3(a,is1,ie1,is2,ie2,is3,ie3) IMPLICIT NONE real(dp), DIMENSION(:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3)) a=0.0_dp END SUBROUTINE allocate_array_dp3 SUBROUTINE allocate_array_dp4(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4) IMPLICIT NONE real(dp), DIMENSION(:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4)) a=0.0_dp END SUBROUTINE allocate_array_dp4 SUBROUTINE allocate_array_dp5(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5) IMPLICIT NONE real(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5)) a=0.0_dp END SUBROUTINE allocate_array_dp5 !======================================== SUBROUTINE allocate_array_dc1(a,is1,ie1) IMPLICIT NONE DOUBLE COMPLEX, DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1 ALLOCATE(a(is1:ie1)) a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc1 SUBROUTINE allocate_array_dc2(a,is1,ie1,is2,ie2) IMPLICIT NONE DOUBLE COMPLEX, DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2 ALLOCATE(a(is1:ie1,is2:ie2)) a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc2 SUBROUTINE allocate_array_dc3(a,is1,ie1,is2,ie2,is3,ie3) IMPLICIT NONE DOUBLE COMPLEX, DIMENSION(:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3)) a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc3 SUBROUTINE allocate_array_dc4(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4) IMPLICIT NONE DOUBLE COMPLEX, DIMENSION(:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4)) a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc4 SUBROUTINE allocate_array_dc5(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5) IMPLICIT NONE DOUBLE COMPLEX, DIMENSION(:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5)) a=CMPLX(0.0_dp,0.0_dp) END SUBROUTINE allocate_array_dc5 !======================================== SUBROUTINE allocate_array_i1(a,is1,ie1) IMPLICIT NONE INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1 ALLOCATE(a(is1:ie1)) a=0 END SUBROUTINE allocate_array_i1 SUBROUTINE allocate_array_i2(a,is1,ie1,is2,ie2) IMPLICIT NONE INTEGER, DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2 ALLOCATE(a(is1:ie1,is2:ie2)) a=0 END SUBROUTINE allocate_array_i2 SUBROUTINE allocate_array_i3(a,is1,ie1,is2,ie2,is3,ie3) IMPLICIT NONE INTEGER, DIMENSION(:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3)) a=0 END SUBROUTINE allocate_array_i3 SUBROUTINE allocate_array_i4(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4) IMPLICIT NONE INTEGER, DIMENSION(:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4)) a=0 END SUBROUTINE allocate_array_i4 SUBROUTINE allocate_array_i5(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5) IMPLICIT NONE real(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5)) a=0 END SUBROUTINE allocate_array_i5 !======================================== SUBROUTINE allocate_array_l1(a,is1,ie1) IMPLICIT NONE LOGICAL, DIMENSION(:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1 ALLOCATE(a(is1:ie1)) a=.false. END SUBROUTINE allocate_array_l1 SUBROUTINE allocate_array_l2(a,is1,ie1,is2,ie2) IMPLICIT NONE LOGICAL, DIMENSION(:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2 ALLOCATE(a(is1:ie1,is2:ie2)) a=.false. END SUBROUTINE allocate_array_l2 SUBROUTINE allocate_array_l3(a,is1,ie1,is2,ie2,is3,ie3) IMPLICIT NONE LOGICAL, DIMENSION(:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3)) a=.false. END SUBROUTINE allocate_array_l3 SUBROUTINE allocate_array_l4(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4) IMPLICIT NONE LOGICAL, DIMENSION(:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4)) a=.false. END SUBROUTINE allocate_array_l4 SUBROUTINE allocate_array_l5(a,is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5) IMPLICIT NONE LOGICAL, DIMENSION(:,:,:,:,:), ALLOCATABLE, INTENT(INOUT) :: a INTEGER, INTENT(IN) :: is1,ie1,is2,ie2,is3,ie3,is4,ie4,is5,ie5 ALLOCATE(a(is1:ie1,is2:ie2,is3:ie3,is4:ie4,is5:ie5)) a=.false. END SUBROUTINE allocate_array_l5 END MODULE basic diff --git a/src/closure_mod.F90 b/src/closure_mod.F90 index f8846d4..06ef792 100644 --- a/src/closure_mod.F90 +++ b/src/closure_mod.F90 @@ -1,107 +1,107 @@ module closure ! Contains the routines to define closures USE basic USE model, ONLY: CLOS, tau_e, tau_i, q_e, q_i, eta_B, nu USE grid USE array, ONLY: kernel_e, kernel_i USE fields, ONLY: moments_e, moments_i USE time_integration, ONLY: updatetlevel IMPLICIT NONE PUBLIC :: apply_closure_model CONTAINS ! Positive Oob indices are approximated with a model SUBROUTINE apply_closure_model IMPLICIT NONE - complex(dp) :: i_kz + complex(dp) :: i_ky 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 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 + moments_e(ip,ijsg_e,ikx,iky,updatetlevel) = 0._dp + moments_e(ip,ijeg_e,ikx,iky,updatetlevel) = 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 + moments_e(ipsg_e+1,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipsg_e ,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipeg_e-1,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipeg_e ,ij,ikx,iky,updatetlevel) = 0._dp ENDDO - kernel_e(ijsg_e,ikr,ikz) = 0._dp - kernel_e(ijeg_e,ikr,ikz) = 0._dp + kernel_e(ijsg_e,ikx,iky) = 0._dp + kernel_e(ijeg_e,ikx,iky) = 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 + moments_i(ip,ijsg_i,ikx,iky,updatetlevel) = 0._dp + moments_i(ip,ijeg_i,ikx,iky,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 + moments_i(ipsg_i+1,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipsg_i ,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipeg_i-1,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipeg_i ,ij,ikx,iky,updatetlevel) = 0._dp ENDDO - kernel_i(ijsg_i,ikr,ikz) = 0._dp - kernel_i(ijeg_i,ikr,ikz) = 0._dp + kernel_i(ijsg_i,ikx,iky) = 0._dp + kernel_i(ijeg_i,ikx,iky) = 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 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 + moments_e(ip,ijsg_e,ikx,iky,updatetlevel) = 0._dp + moments_e(ip,ijeg_e,ikx,iky,updatetlevel) = 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 + moments_e(ipsg_e+1,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipsg_e ,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipeg_e-1,ij,ikx,iky,updatetlevel) = 0._dp + moments_e(ipeg_e ,ij,ikx,iky,updatetlevel) = 0._dp ENDDO - kernel_e(ijsg_e,ikr,ikz) = 0._dp - kernel_e(ijeg_e,ikr,ikz) = 0._dp + kernel_e(ijsg_e,ikx,iky) = 0._dp + kernel_e(ijeg_e,ikx,iky) = 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 + moments_i(ip,ijsg_i,ikx,iky,updatetlevel) = 0._dp + moments_i(ip,ijeg_i,ikx,iky,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 + moments_i(ipsg_i+1,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipsg_i ,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipeg_i-1,ij,ikx,iky,updatetlevel) = 0._dp + moments_i(ipeg_i ,ij,ikx,iky,updatetlevel) = 0._dp ENDDO - kernel_i(ijsg_i,ikr,ikz) = 0._dp - kernel_i(ijeg_i,ikr,ikz) = 0._dp + kernel_i(ijsg_i,ikx,iky) = 0._dp + kernel_i(ijeg_i,ikx,iky) = 0._dp ENDDO ENDDO ELSE if(my_id .EQ. 0) write(*,*) '! Closure scheme not found !' ENDIF CALL cpu_time(t1_clos) tc_clos = tc_clos + (t1_clos - t0_clos) END SUBROUTINE apply_closure_model END module closure diff --git a/src/collision_mod.F90 b/src/collision_mod.F90 index d6f267f..f04936b 100644 --- a/src/collision_mod.F90 +++ b/src/collision_mod.F90 @@ -1,651 +1,651 @@ 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 PUBLIC :: DoughertyGK_e, DoughertyGK_i!, DoughertyGK PUBLIC :: load_COSOlver_mat PUBLIC :: apply_COSOlver_mat_e, apply_COSOlver_mat_i CONTAINS !******************************************************************************! !! Doughtery gyrokinetic collision operator for electrons !******************************************************************************! - SUBROUTINE DoughertyGK_e(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE DoughertyGK_e(ip_,ij_,ikx_,iky_,TColl_) IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_,ij_,ikr_,ikz_ + INTEGER, INTENT(IN) :: ip_,ij_,ikx_,iky_ COMPLEX(dp), INTENT(INOUT) :: TColl_ COMPLEX(dp) :: n_,upar_,uperp_,Tpar_, Tperp_ COMPLEX(dp) :: Dpj, Ppj, T_, be_ COMPLEX(dp) :: nadiab_moment_0j REAL(dp) :: Knp0, Knp1, Knm1 INTEGER :: in_ REAL(dp) :: n_dp, j_dp, p_dp, be_2, q_e_tau_e !** 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 + be_2 = (kxarray(ikx_)**2 + kyarray(iky_)**2) * sigmae2_taue_o2 ! this is (be/2)^2 ! ibe_ = imagu*2._dp*SQRT(be_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_,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) * q_e_tau_e * Kernel_e(ij_,ikx_,iky_)*phi(ikx_,iky_) !** build required fluid moments ** n_ = 0._dp upar_ = 0._dp; uperp_ = 0._dp Tpar_ = 0._dp; Tperp_ = 0._dp 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_,updatetlevel) + q_e_tau_e * Knp0 *phi(ikx_,iky_) ! 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_,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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - 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,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_,updatetlevel) ENDDO - TColl_ = TColl_ + upar_*Kernel_e(ij_,ikr_,ikz_) + TColl_ = TColl_ + upar_*Kernel_e(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 Tpar_ = 0._dp; Tperp_ = 0._dp 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_,updatetlevel) + q_e_tau_e*Knp0*phi(ikx_,iky_) ! 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_,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 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 ! Multiply by electron-electron collision coefficient TColl_ = nu_ee * TColl_ END SUBROUTINE DoughertyGK_e !******************************************************************************! !! Doughtery gyrokinetic collision operator for ions !******************************************************************************! - SUBROUTINE DoughertyGK_i(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE DoughertyGK_i(ip_,ij_,ikx_,iky_,TColl_) IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_,ij_,ikr_,ikz_ + INTEGER, INTENT(IN) :: ip_,ij_,ikx_,iky_ COMPLEX(dp), INTENT(INOUT) :: TColl_ COMPLEX(dp) :: n_,upar_,uperp_,Tpar_, Tperp_ COMPLEX(dp) :: Dpj, Ppj, T_, bi_ COMPLEX(dp) :: nadiab_moment_0j REAL(dp) :: Knp0, Knp1, Knm1 INTEGER :: in_ REAL(dp) :: n_dp, j_dp, p_dp, bi_2, q_i_tau_i !** 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_,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) * q_i_tau_i * Kernel_i(ij_,ikx_,iky_)*phi(ikx_,iky_) !** build required fluid moments ** n_ = 0._dp upar_ = 0._dp; uperp_ = 0._dp Tpar_ = 0._dp; Tperp_ = 0._dp 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 * Kernel_i(in_ ,ikr_,ikz_)*phi(ikr_,ikz_) + nadiab_moment_0j = moments_i(1,in_ ,ikx_,iky_,updatetlevel) + q_i_tau_i * Kernel_i(in_ ,ikx_,iky_)*phi(ikx_,iky_) ! 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_ + ibi_*0.5_dp*Kernel_i(in_,ikx_,iky_) * (nadiab_moment_0j - nadiab_moment_0jp1) + ! uperp_ = uperp_ + b_i*0.5_dp*Kernel_i(in_,ikx_,iky_) * (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_,updatetlevel) + nadiab_moment_0j) ! Perpendicular temperature - ! Tperp_ = Tperp_ + Kernel_i(in_,ikr_,ikz_) * ((2._dp*n_dp+1._dp)* nadiab_moment_0j & + ! Tperp_ = Tperp_ + Kernel_i(in_,ikx_,iky_) * ((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 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_,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 Tpar_ = 0._dp; Tperp_ = 0._dp 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 * Kernel_i(in_ ,ikr_,ikz_)*phi(ikr_,ikz_) + nadiab_moment_0j = moments_i(1,in_ ,ikx_,iky_,updatetlevel) + q_i_tau_i * Kernel_i(in_ ,ikx_,iky_)*phi(ikx_,iky_) ! 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_,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 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 ! Multiply by ion-ion collision coefficient TColl_ = nu_i * TColl_ 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 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 + DO ikx = ikxs,ikxe + DO iky = ikys,ikye ! 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) + CALL apply_COSOlver_mat_e(ip,ij,ikx,iky,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,ikr,ikz) = TColl_distr_e(ip) + TColl_e(ip,ij,ikx,iky) = 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) + CALL apply_COSOlver_mat_i(ip,ij,ikx,iky,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) + TColl_i(ip,ij,ikx,iky) = TColl_distr_i(ip) ENDDO ENDDO ENDDO ENDDO ENDIF ! Execution time end CALL cpu_time(t1_coll) tc_coll = tc_coll + (t1_coll - t0_coll) END SUBROUTINE compute_TColl !******************************************************************************! !!!!!!! Compute ion collision term !******************************************************************************! - SUBROUTINE apply_COSOlver_mat_e(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE apply_COSOlver_mat_e(ip_,ij_,ikx_,iky_,TColl_) IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_, ij_ ,ikr_, ikz_ + INTEGER, INTENT(IN) :: ip_, ij_ ,ikx_, iky_ 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 ! sum the electron-self and electron-ion test terms ploopee: DO ip2 = ips_e,ipe_e 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_,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 ! sum the electron-ion field terms ploopei: DO ip2 = ips_i,ipe_i 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_,updatetlevel) & + *(nu_e * CeipjF(bare(p_int,j_int), bari(p2_int,j2_int),ikx_C, iky_C)) END DO jloopei ENDDO ploopei END SUBROUTINE apply_COSOlver_mat_e !******************************************************************************! !!!!!!! Compute ion collision term !******************************************************************************! - SUBROUTINE apply_COSOlver_mat_i(ip_,ij_,ikr_,ikz_,TColl_) + SUBROUTINE apply_COSOlver_mat_i(ip_,ij_,ikx_,iky_,TColl_) IMPLICIT NONE - INTEGER, INTENT(IN) :: ip_, ij_ ,ikr_, ikz_ + INTEGER, INTENT(IN) :: ip_, ij_ ,ikx_, iky_ 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 ! sum the ion-self and ion-electron test terms ploopii: DO ip2 = ips_i,ipe_i 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_,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 ploopie: DO ip2 = ips_e,ipe_e ! sum the ion-electron field terms 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_,updatetlevel) & + *(nu_ie * CiepjF(bari(p_int,j_int), bare(p2_int,j2_int), ikx_C, iky_C)) ENDDO jloopie ENDDO ploopie END SUBROUTINE apply_COSOlver_mat_i !******************************************************************************! !!!!!!! Load the collision matrix coefficient table from COSOlver results !******************************************************************************! SUBROUTINE load_COSOlver_mat ! Load a sub matrix from iCa files (works for pmaxa,jmaxa<=P_full,J_full) use futils use initial_par IMPLICIT NONE ! Indices for row and columns of the COSOlver matrix (4D compressed 2D matrices) INTEGER :: irow_sub, irow_full, icol_sub, icol_full INTEGER :: fid ! file indexation INTEGER :: ip_e, ij_e, il_e, ik_e, ikps_C, ikpe_C ! indices for electrons loops REAL(dp), DIMENSION(2) :: dims_e INTEGER :: pdime, jdime ! dimensions of the COSOlver matrices REAL(dp), DIMENSION(:,:), ALLOCATABLE :: Ceepj_full, CeipjT_full ! To load the entire matrix REAL(dp), DIMENSION(:,:), ALLOCATABLE :: CeipjF_full ! '' REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: Ceepj__kp, CeipjT_kp ! To store the coeff that will be used along kperp REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: CeipjF_kp ! '' INTEGER :: ip_i, ij_i, il_i, ik_i ! same for ions INTEGER, DIMENSION(2) :: dims_i INTEGER :: pdimi, jdimi ! dimensions of the COSOlver matrices REAL(dp), DIMENSION(:,:), ALLOCATABLE :: Ciipj_full, CiepjT_full ! . REAL(dp), DIMENSION(:,:), ALLOCATABLE :: CiepjF_full ! . REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: Ciipj__kp, CiepjT_kp ! . REAL(dp), DIMENSION(:,:,:), ALLOCATABLE :: CiepjF_kp ! . INTEGER :: NFLR REAL(dp), DIMENSION(:), ALLOCATABLE :: kp_grid_mat ! kperp grid of the matrices INTEGER :: ikp_next, ikp_prev, nkp_mat, ikp_mat REAL(dp) :: kp_next, kp_prev, kperp_sim, kperp_mat, zerotoone CHARACTER(len=128) :: var_name, kperp_string, ikp_string LOGICAL :: CO_AA_ONLY = .false. ! Flag to remove ei ie collision !! Some terminal info IF (CO .EQ. 2) THEN IF (my_id .EQ. 0) WRITE(*,*) '=== Load GK Sugama matrix ===' ELSEIF(CO .EQ. 3) THEN IF (my_id .EQ. 0) WRITE(*,*) '=== Load GK pitch angle matrix ===' ELSEIF(CO .EQ. -2) THEN IF (my_id .EQ. 0) WRITE(*,*) '=== Load DK Sugama matrix ===' ELSEIF(CO .EQ. -3) THEN IF (my_id .EQ. 0) WRITE(*,*) '=== Load DK pitch angle matrix ===' ENDIF ! Opening the compiled cosolver matrices results if(my_id.EQ.0)write(*,*) mat_file CALL openf(mat_file,fid, 'r', 'D', mpicomm=comm_p); ! Get matrices dimensions (polynomials degrees and kperp grid) CALL getarr(fid, '/dims_e', dims_e) ! Get the electron polynomial degrees pdime = dims_e(1); jdime = dims_e(2); CALL getarr(fid, '/dims_i', dims_i) ! Get the ion polynomial degrees pdimi = dims_i(1); jdimi = dims_i(2); IF ( ((pdime .LT. pmaxe) .OR. (jdime .LT. jmaxe)) .AND. (my_id .EQ. 0)) WRITE(*,*) '!! Pe,Je Matrix too small !!' IF ( ((pdimi .LT. pmaxi) .OR. (jdimi .LT. jmaxi)) .AND. (my_id .EQ. 0)) WRITE(*,*) '!! Pi,Ji Matrix too small !!' CALL getsize(fid, '/coordkperp', nkp_mat) ! Get the dimension kperp grid of the matrices CALL allocate_array(kp_grid_mat, 1,nkp_mat) CALL getarr(fid, '/coordkperp', kp_grid_mat) IF (NON_LIN) THEN ! check that we have enough kperps mat IF ( (kp_grid_mat(nkp_mat) .LT. two_third_kpmax) .AND. (my_id .EQ. 0)) WRITE(*,*) '!! Matrix kperp grid too small !!' ELSE IF ( (kp_grid_mat(nkp_mat) .LT. kp_max) .AND. (my_id .EQ. 0)) WRITE(*,*) '!! Matrix kperp grid too small !!' ENDIF IF (CO .GT. 0) THEN ! GK operator (k-dependant) ikps_C = 1; ikpe_C = nkp_mat ELSEIF (CO .LT. 0) THEN ! DK operator (only one mat for all k) ikps_C = 1; ikpe_C = 1 ENDIF CALL allocate_array( Ceepj__kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) CALL allocate_array( CeipjT_kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) CALL allocate_array( CeipjF_kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) CALL allocate_array( Ciipj__kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) CALL allocate_array( CiepjT_kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) CALL allocate_array( CiepjF_kp, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), ikps_C,ikpe_C) DO ikp = ikps_C,ikpe_C ! Loop over everz kperp values ! we put zeros if kp>2/3kpmax because thoses frequenvies are filtered through AA IF(kp_grid_mat(ikp) .GT. two_third_kpmax .AND. NON_LIN) THEN CiepjT_kp(:,:,ikp) = 0._dp CiepjF_kp(:,:,ikp) = 0._dp CeipjT_kp(:,:,ikp) = 0._dp CeipjF_kp(:,:,ikp) = 0._dp Ceepj__kp(:,:,ikp) = 0._dp Ciipj__kp(:,:,ikp) = 0._dp ELSE ! Kperp value in string format IF (CO .GT. 0) THEN write(ikp_string,'(i5.5)') ikp-1 ELSE write(ikp_string,'(i5.5)') 0 ENDIF !!!!!!!!!!!! E-E matrices !!!!!!!!!!!! ! get the self electron colision matrix ! Allocate space for storing full collision matrix CALL allocate_array( Ceepj_full, 1,(pdime+1)*(jdime+1), 1,(pdime+1)*(jdime+1)) ! Naming of the array to load (kperp dependant) WRITE(var_name,'(a,a)') TRIM(ADJUSTL(ikp_string)),'/Caapj/Ceepj' CALL getarr(fid, var_name, Ceepj_full) ! get array (moli format) ! Fill sub array with the usefull polynmial degrees only DO ip_e = 0,pmaxe ! Loop over rows DO ij_e = 0,jmaxe irow_sub = (jmaxe +1)*ip_e + ij_e +1 irow_full = (jdime +1)*ip_e + ij_e +1 DO il_e = 0,pmaxe ! Loop over columns DO ik_e = 0,jmaxe icol_sub = (jmaxe +1)*il_e + ik_e +1 icol_full = (jdime +1)*il_e + ik_e +1 Ceepj__kp (irow_sub,icol_sub,ikp) = Ceepj_full (irow_full,icol_full) ENDDO ENDDO ENDDO ENDDO DEALLOCATE(Ceepj_full) !!!!!!!!!!!!!!! I-I matrices !!!!!!!!!!!!!! ! get the self electron colision matrix CALL allocate_array( Ciipj_full, 1,(pdimi+1)*(jdimi+1), 1,(pdimi+1)*(jdimi+1)) WRITE(var_name,'(a,a,a)') TRIM(ADJUSTL(ikp_string)),'/Caapj/Ciipj' CALL getarr(fid, var_name, Ciipj_full) ! get array (moli format) ! Fill sub array with only usefull polynmials degree DO ip_i = 0,Pmaxi ! Loop over rows DO ij_i = 0,Jmaxi irow_sub = (Jmaxi +1)*ip_i + ij_i +1 irow_full = (jdimi +1)*ip_i + ij_i +1 DO il_i = 0,Pmaxi ! Loop over columns DO ik_i = 0,Jmaxi icol_sub = (Jmaxi +1)*il_i + ik_i +1 icol_full = (jdimi +1)*il_i + ik_i +1 Ciipj__kp (irow_sub,icol_sub,ikp) = Ciipj_full (irow_full,icol_full) ENDDO ENDDO ENDDO ENDDO DEALLOCATE(Ciipj_full) IF(abs(CO) .NE. 3) THEN ! Pitch angle is only applied on like-species !!!!!!!!!!!!!!! E-I matrices !!!!!!!!!!!!!! ! Get test and field e-i collision matrices CALL allocate_array( CeipjT_full, 1,(pdime+1)*(jdime+1), 1,(pdime+1)*(jdime+1)) CALL allocate_array( CeipjF_full, 1,(pdime+1)*(jdime+1), 1,(pdimi+1)*(jdimi+1)) WRITE(var_name,'(a,a)') TRIM(ADJUSTL(ikp_string)),'/Ceipj/CeipjT' CALL getarr(fid, var_name, CeipjT_full) WRITE(var_name,'(a,a)') TRIM(ADJUSTL(ikp_string)),'/Ceipj/CeipjF' CALL getarr(fid, var_name, CeipjF_full) ! Fill sub array with only usefull polynmials degree DO ip_e = 0,pmaxe ! Loop over rows DO ij_e = 0,jmaxe irow_sub = (jmaxe +1)*ip_e + ij_e +1 irow_full = (jdime +1)*ip_e + ij_e +1 DO il_e = 0,pmaxe ! Loop over columns DO ik_e = 0,jmaxe icol_sub = (jmaxe +1)*il_e + ik_e +1 icol_full = (jdime +1)*il_e + ik_e +1 CeipjT_kp(irow_sub,icol_sub,ikp) = CeipjT_full(irow_full,icol_full) ENDDO ENDDO DO il_i = 0,pmaxi ! Loop over columns DO ik_i = 0,jmaxi icol_sub = (Jmaxi +1)*il_i + ik_i +1 icol_full = (jdimi +1)*il_i + ik_i +1 CeipjF_kp(irow_sub,icol_sub,ikp) = CeipjF_full(irow_full,icol_full) ENDDO ENDDO ENDDO ENDDO DEALLOCATE(CeipjF_full) DEALLOCATE(CeipjT_full) !!!!!!!!!!!!!!! I-E matrices !!!!!!!!!!!!!! ! get the Test and Back field electron ion collision matrix CALL allocate_array( CiepjT_full, 1,(pdimi+1)*(jdimi+1), 1,(pdimi+1)*(jdimi+1)) CALL allocate_array( CiepjF_full, 1,(pdimi+1)*(jdimi+1), 1,(pdime+1)*(jdime+1)) WRITE(var_name,'(a,a,a)') TRIM(ADJUSTL(ikp_string)),'/Ciepj/CiepjT' CALL getarr(fid, var_name, CiepjT_full) WRITE(var_name,'(a,a,a)') TRIM(ADJUSTL(ikp_string)),'/Ciepj/CiepjF' CALL getarr(fid, var_name, CiepjF_full) ! Fill sub array with only usefull polynmials degree DO ip_i = 0,Pmaxi ! Loop over rows DO ij_i = 0,Jmaxi irow_sub = (Jmaxi +1)*ip_i + ij_i +1 irow_full = (jdimi +1)*ip_i + ij_i +1 DO il_i = 0,Pmaxi ! Loop over columns DO ik_i = 0,Jmaxi icol_sub = (Jmaxi +1)*il_i + ik_i +1 icol_full = (jdimi +1)*il_i + ik_i +1 CiepjT_kp(irow_sub,icol_sub,ikp) = CiepjT_full(irow_full,icol_full) ENDDO ENDDO DO il_e = 0,pmaxe ! Loop over columns DO ik_e = 0,jmaxe icol_sub = (jmaxe +1)*il_e + ik_e +1 icol_full = (jdime +1)*il_e + ik_e +1 CiepjF_kp(irow_sub,icol_sub,ikp) = CiepjF_full(irow_full,icol_full) ENDDO ENDDO ENDDO ENDDO DEALLOCATE(CiepjF_full) DEALLOCATE(CiepjT_full) ELSE CeipjT_kp = 0._dp; CeipjF_kp = 0._dp; CiepjT_kp = 0._dp; CiepjF_kp = 0._dp; ENDIF ENDIF 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 ! larger than the current kperp_sim (brute force...) DO ikp=1,nkp_mat ikp_mat = ikp ! the first indice of the interval (k0) kperp_mat = kp_grid_mat(ikp) IF(kperp_mat .GT. kperp_sim) EXIT ENDDO ! interval boundaries ikp_prev = ikp_mat - 1 !index of k0 ikp_next = ikp_mat !index of k1 ! write(*,*) kp_grid_mat(ikp_prev), '<', kperp_sim, '<', kp_grid_mat(ikp_next) ! 0->1 variable for linear interp, i.e. zero2one = (k-k0)/(k1-k0) 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 Ceepj (:,:,1,1) = Ceepj__kp (:,:,1) CeipjT(:,:,1,1) = CeipjT_kp(:,:,1) CeipjF(:,:,1,1) = CeipjF_kp(:,:,1) Ciipj (:,:,1,1) = Ciipj__kp (:,:,1) CiepjT(:,:,1,1) = CiepjT_kp(:,:,1) CiepjF(:,:,1,1) = CiepjF_kp(:,:,1) ENDIF ! Deallocate auxiliary variables DEALLOCATE (Ceepj__kp ); DEALLOCATE (CeipjT_kp); DEALLOCATE (CeipjF_kp) DEALLOCATE (Ciipj__kp ); DEALLOCATE (CiepjT_kp); DEALLOCATE (CiepjF_kp) IF( CO_AA_ONLY ) THEN CeipjF = 0._dp; CeipjT = 0._dp; CiepjF = 0._dp; CiepjT = 0._dp; ENDIF IF (my_id .EQ. 0) WRITE(*,*) '============DONE===========' END SUBROUTINE load_COSOlver_mat !******************************************************************************! end module collision diff --git a/src/compute_Sapj.F90 b/src/compute_Sapj.F90 index 4ef4f87..a6dcb0d 100644 --- a/src/compute_Sapj.F90 +++ b/src/compute_Sapj.F90 @@ -1,215 +1,215 @@ 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 USE fourier USE fields!, ONLY : phi, moments_e, moments_i USE grid USE model USE prec_const USE time_integration!, ONLY : updatetlevel 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) :: Fr_cmpx, Gz_cmpx + COMPLEX(dp), DIMENSION(ikxs:ikxe,ikys:ikye) :: Fz_cmpx, Gr_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) !!!!!!!!!!!!!!!!!!!! ELECTRON non linear term computation (Sepj)!!!!!!!!!! ploope: DO ip = ips_e,ipe_e ! Loop over Hermite moments ! we check if poly degree is even (eq to index is odd) to spare computation IF ((MODULO(ip,2) .EQ. 1) .OR. (.NOT. COMPUTE_ONLY_EVEN_P)) THEN jloope: DO ij = ijs_e, ije_e ! Loop over Laguerre moments real_data_c = 0._dp ! initialize sum over real nonlinear term ! Set non linear sum truncation IF (NL_CLOS .EQ. -2) THEN nmax = Jmaxe ELSEIF (NL_CLOS .EQ. -1) THEN nmax = Jmaxe-(ij-1) ELSE nmax = NL_CLOS ENDIF 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 + Fr_cmpx(ikx,iky) = imagu*kx* phi(ikx,iky) * kerneln + Fz_cmpx(ikx,iky) = imagu*ky* phi(ikx,iky) * kerneln ! Second convolution terms - Gz_cmpx(ikr,ikz) = 0._dp ! initialization of the sum - Gr_cmpx(ikr,ikz) = 0._dp ! initialization of the sum + Gz_cmpx(ikx,iky) = 0._dp ! initialization of the sum + Gr_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) + Gz_cmpx(ikx,iky) = Gz_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_e(ip,is,ikx,iky,updatetlevel) + Gr_cmpx(ikx,iky) = Gr_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_e(ip,is,ikx,iky,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 + Gz_cmpx(ikx,iky) = imagu*ky*Gz_cmpx(ikx,iky) + Gr_cmpx(ikx,iky) = imagu*kx*Gr_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) = Fr_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter + cmpx_data_g(iky,ikx-local_nkx_offset) = Gz_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) = Fz_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) !Anti aliasing filter + cmpx_data_g(iky,ikx-local_nkx_offset) = Gr_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 ! Put the real nonlinear product into k-space 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) = 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 ENDIF ENDDO ploope !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!! ION non linear term computation (Sipj)!!!!!!!!!! ploopi: DO ip = ips_i,ipe_i ! Loop over Hermite moments ! we check if poly degree is even (eq to index is odd) to spare computation IF (MODULO(ip,2) .EQ. 1 .OR. (.NOT. COMPUTE_ONLY_EVEN_P)) THEN jloopi: DO ij = ijs_i, ije_i ! Loop over Laguerre moments real_data_c = 0._dp ! initialize sum over real nonlinear term ! Set non linear sum truncation IF (NL_CLOS .EQ. -2) THEN nmax = Jmaxi ELSEIF (NL_CLOS .EQ. -1) THEN nmax = Jmaxi-(ij-1) ELSE nmax = NL_CLOS ENDIF 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 + Fr_cmpx(ikx,iky) = imagu*kx* phi(ikx,iky) * kerneln + Fz_cmpx(ikx,iky) = imagu*ky* phi(ikx,iky) * kerneln ! Second convolution terms - Gz_cmpx(ikr,ikz) = 0._dp ! initialization of the sum - Gr_cmpx(ikr,ikz) = 0._dp ! initialization of the sum + Gz_cmpx(ikx,iky) = 0._dp ! initialization of the sum + Gr_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) + Gz_cmpx(ikx,iky) = Gz_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_i(ip,is,ikx,iky,updatetlevel) + Gr_cmpx(ikx,iky) = Gr_cmpx(ikx,iky) + & + dnjs(in,ij,is) * moments_i(ip,is,ikx,iky,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 + Gz_cmpx(ikx,iky) = imagu*ky*Gz_cmpx(ikx,iky) + Gr_cmpx(ikx,iky) = imagu*kx*Gr_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) = Fr_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) + cmpx_data_g(iky,ikx-local_nkx_offset) = Gz_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) = Fz_cmpx(ikx,iky)*AA_x(ikx)*AA_y(iky) + cmpx_data_g(iky,ikx-local_nkx_offset) = Gr_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 ! Put the real nonlinear product into k-space 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) = 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 ENDIF ENDDO ploopi !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! Execution time END CALL cpu_time(t1_Sapj) tc_Sapj = tc_Sapj + (t1_Sapj - t0_Sapj) END SUBROUTINE compute_Sapj diff --git a/src/diagnose.F90 b/src/diagnose.F90 index d4ecfcc..e9ea571 100644 --- a/src/diagnose.F90 +++ b/src/diagnose.F90 @@ -1,495 +1,495 @@ SUBROUTINE diagnose(kstep) ! Diagnostics, writing simulation state to disk USE basic USE grid USE diagnostics_par USE futils, ONLY: creatf, creatg, creatd, closef, putarr, putfile, attach, openf, putarrnd USE model USE initial_par USE fields USE time_integration USE utility USE prec_const IMPLICIT NONE INCLUDE 'srcinfo.h' INTEGER, INTENT(in) :: kstep INTEGER, parameter :: BUFSIZE = 2 INTEGER :: rank = 0 INTEGER :: dims(1) = (/0/) INTEGER :: cp_counter = 0 CHARACTER(len=256) :: str, fname,test_ ! putarr(...,pardim=1) does not work for 2D domain decomposition ! 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) CALL cpu_time(t0_diag) ! Measuring time !_____________________________________________________________________________ ! 1. Initial diagnostics IF ((kstep .EQ. 0)) THEN ! Writing output filename WRITE(resfile,'(a,a1,i2.2,a3)') TRIM(resfile0),'_',jobnum,'.h5' ! 1.1 Initial run ! Main output file creation IF (write_doubleprecision) THEN CALL creatf(resfile, fidres, real_prec='d', mpicomm=comm0) ELSE CALL creatf(resfile, fidres, mpicomm=comm0) END IF IF (my_id .EQ. 0) WRITE(*,'(3x,a,a)') TRIM(resfile), ' created' ! Data group CALL creatg(fidres, "/data", "data") ! File group CALL creatg(fidres, "/files", "files") CALL attach(fidres, "/files", "jobnum", jobnum) ! Profiler time measurement CALL creatg(fidres, "/profiler", "performance analysis") CALL creatd(fidres, 0, dims, "/profiler/Tc_rhs", "cumulative rhs computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_adv_field", "cumulative adv. fields computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_clos", "cumulative closure computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_ghost", "cumulative communication time") CALL creatd(fidres, 0, dims, "/profiler/Tc_coll", "cumulative collision computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_poisson", "cumulative poisson computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_Sapj", "cumulative Sapj computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_checkfield", "cumulative checkfield computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_diag", "cumulative sym computation time") CALL creatd(fidres, 0, dims, "/profiler/Tc_step", "cumulative total step computation time") CALL creatd(fidres, 0, dims, "/profiler/time", "current simulation time") ! Build the full grids on process 0 to diagnose it without comm IF (my_id .EQ. 0) THEN ! P DO ip = 1,pmaxe+1; parray_e_full(ip) = (ip-1); END DO DO ip = 1,pmaxi+1; parray_i_full(ip) = (ip-1); END DO ! 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 - kzarray_full(1) = 0 + kyarray_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/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) CALL putarr(fidres, "/data/grid/coordj_i" , jarray_i_full(1:jmaxi+1), "j_i", ionode=0) ! var0d group (gyro transport) IF (nsave_0d .GT. 0) THEN CALL creatg(fidres, "/data/var0d", "0d profiles") CALL creatd(fidres, rank, dims, "/data/var0d/time", "Time t*c_s/R") CALL creatd(fidres, rank, dims, "/data/var0d/cstep", "iteration number") IF (write_gamma) THEN CALL creatd(fidres, rank, dims, "/data/var0d/gflux_ri", "Radial gyro ion transport") CALL creatd(fidres, rank, dims, "/data/var0d/pflux_ri", "Radial part ion transport") ENDIF IF (cstep==0) THEN iframe0d=0 ENDIF CALL attach(fidres,"/data/var0d/" , "frames", iframe0d) END IF ! var2d group (electro. pot., Ni00 moment) 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 (write_phi) CALL creatg(fidres, "/data/var2d/phi", "phi") IF (write_Na00) THEN CALL creatg(fidres, "/data/var2d/Ne00", "Ne00") CALL creatg(fidres, "/data/var2d/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") ENDIF IF (write_temp) THEN CALL creatg(fidres, "/data/var2d/temp_e", "temp_e") CALL creatg(fidres, "/data/var2d/temp_i", "temp_i") ENDIF IF (cstep==0) THEN iframe2d=0 ENDIF CALL attach(fidres,"/data/var2d/" , "frames", iframe2d) END IF ! var5d group (moments) IF (nsave_5d .GT. 0) THEN CALL creatg(fidres, "/data/var5d", "5d profiles") CALL creatd(fidres, rank, dims, "/data/var5d/time", "Time t*c_s/R") CALL creatd(fidres, rank, dims, "/data/var5d/cstep", "iteration number") IF (write_Napj) THEN CALL creatg(fidres, "/data/var5d/moments_e", "moments_e") CALL creatg(fidres, "/data/var5d/moments_i", "moments_i") ENDIF IF (write_Sapj) THEN CALL creatg(fidres, "/data/var5d/moments_e", "Sipj") CALL creatg(fidres, "/data/var5d/moments_i", "Sepj") ENDIF IF (cstep==0) THEN iframe5d=0 END IF CALL attach(fidres,"/data/var5d/" , "frames", iframe5d) END IF ! Add input namelist variables as attributes of /data/input, defined in srcinfo.h IF (my_id .EQ. 0) WRITE(*,*) 'VERSION=', VERSION IF (my_id .EQ. 0) WRITE(*,*) 'BRANCH=', BRANCH IF (my_id .EQ. 0) WRITE(*,*) 'AUTHOR=', AUTHOR IF (my_id .EQ. 0) WRITE(*,*) 'HOST=', HOST WRITE(str,'(a,i2.2)') "/data/input" CALL creatd(fidres, rank,dims,TRIM(str),'Input parameters') CALL attach(fidres, TRIM(str), "version", VERSION) !defined in srcinfo.h CALL attach(fidres, TRIM(str), "branch", BRANCH) !defined in srcinfo.h CALL attach(fidres, TRIM(str), "author", AUTHOR) !defined in srcinfo.h CALL attach(fidres, TRIM(str), "execdate", EXECDATE) !defined in srcinfo.h CALL attach(fidres, TRIM(str), "host", HOST) !defined in srcinfo.h CALL attach(fidres, TRIM(str), "start_time", time) 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_iframe5d", iframe5d) CALL attach(fidres, TRIM(str), "dt", dt) CALL attach(fidres, TRIM(str), "tmax", tmax) CALL attach(fidres, TRIM(str), "nrun", nrun) 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) CALL attach(fidres, TRIM(str), "write_Napj",write_Napj) CALL attach(fidres, TRIM(str), "write_Sapj",write_Sapj) CALL attach(fidres, TRIM(str), "write_dens",write_dens) CALL attach(fidres, TRIM(str), "write_temp",write_temp) CALL grid_outputinputs(fidres, str) CALL output_par_outputinputs(fidres, str) CALL model_outputinputs(fidres, str) CALL initial_outputinputs(fidres, str) CALL time_integration_outputinputs(fidres, str) ! Save STDIN (input file) of this run IF(jobnum .LE. 99) THEN WRITE(str,'(a,i2.2)') "/files/STDIN.",jobnum ELSE WRITE(str,'(a,i3.2)') "/files/STDIN.",jobnum END IF INQUIRE(unit=lu_in, name=fname) CLOSE(lu_in) CALL putfile(fidres, TRIM(str), TRIM(fname),ionode=0) ELSEIF((kstep .EQ. 0)) THEN IF(jobnum .LE. 99) THEN WRITE(resfile,'(a,a1,i2.2,a3)') TRIM(resfile0),'_',jobnum,'.h5' ELSE WRITE(resfile,'(a,a1,i3.2,a3)') TRIM(resfile0),'_',jobnum,'.h5' END IF CALL openf(resfile,fidres, 'D'); ENDIF !_____________________________________________________________________________ ! 2. Periodic diagnostics ! IF (kstep .GE. 0) THEN ! Terminal info IF (MOD(cstep, INT(1.0/dt)) == 0 .AND. (my_id .EQ. 0)) THEN WRITE(*,"(F6.0,A,F6.0)") time,"/",tmax ENDIF ! 2.1 0d history arrays IF (nsave_0d .GT. 0) THEN IF ( MOD(cstep, nsave_0d) == 0 ) THEN CALL diagnose_0d END IF END IF ! 2.2 1d profiles ! empty in our case ! 2.3 2d profiles IF (nsave_2d .GT. 0) THEN IF (MOD(cstep, nsave_2d) == 0) THEN CALL diagnose_2d END IF END IF ! 2.4 3d profiles IF (nsave_5d .GT. 0 .AND. cstep .GT. 0) THEN IF (MOD(cstep, nsave_5d) == 0) THEN CALL diagnose_5d END IF END IF !_____________________________________________________________________________ ! 3. Final diagnostics ELSEIF (kstep .EQ. -1) THEN CALL cpu_time(finish) CALL attach(fidres, "/data/input","cpu_time",finish-start) ! make a checkpoint at last timestep if not crashed IF(.NOT. crashed) THEN IF(my_id .EQ. 0) write(*,*) 'Saving last state' CALL diagnose_5d ENDIF ! Display computational time cost IF (my_id .EQ. 0) CALL display_h_min_s(finish-start) ! Close all diagnostic files CALL closef(fidres) END IF CALL cpu_time(t1_diag); tc_diag = tc_diag + (t1_diag - t0_diag) END SUBROUTINE diagnose SUBROUTINE diagnose_0d USE basic USE futils, ONLY: append, attach, getatt USE diagnostics_par USE prec_const USE processing IMPLICIT NONE ! Time measurement data CALL append(fidres, "/profiler/Tc_rhs", tc_rhs,ionode=0) CALL append(fidres, "/profiler/Tc_adv_field", tc_adv_field,ionode=0) CALL append(fidres, "/profiler/Tc_clos", tc_clos,ionode=0) CALL append(fidres, "/profiler/Tc_ghost", tc_ghost,ionode=0) CALL append(fidres, "/profiler/Tc_coll", tc_coll,ionode=0) CALL append(fidres, "/profiler/Tc_poisson", tc_poisson,ionode=0) CALL append(fidres, "/profiler/Tc_Sapj", tc_Sapj,ionode=0) CALL append(fidres, "/profiler/Tc_checkfield",tc_checkfield,ionode=0) CALL append(fidres, "/profiler/Tc_diag", tc_diag,ionode=0) CALL append(fidres, "/profiler/Tc_step", tc_step,ionode=0) CALL append(fidres, "/profiler/time", time,ionode=0) ! Processing data CALL append(fidres, "/data/var0d/time", time,ionode=0) CALL append(fidres, "/data/var0d/cstep", real(cstep,dp),ionode=0) CALL getatt(fidres, "/data/var0d/", "frames",iframe2d) iframe0d=iframe0d+1 CALL attach(fidres,"/data/var0d/" , "frames", iframe0d) ! Ion transport data IF (write_gamma) THEN CALL compute_radial_ion_transport CALL append(fidres, "/data/var0d/gflux_ri",gflux_ri,ionode=0) CALL append(fidres, "/data/var0d/pflux_ri",pflux_ri,ionode=0) ENDIF END SUBROUTINE diagnose_0d SUBROUTINE diagnose_2d 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: 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 USE processing 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) CALL append(fidres, "/data/var2d/cstep", real(cstep,dp),ionode=0) CALL getatt(fidres, "/data/var2d/", "frames",iframe2d) iframe2d=iframe2d+1 CALL attach(fidres,"/data/var2d/" , "frames", iframe2d) IF (write_phi) CALL write_field2d(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) = moments_e(ips_e,1,ikxs:ikxe,ikys:ikye,updatetlevel) + Ni00(ikxs:ikxe,ikys:ikye) = moments_i(ips_e,1,ikxs:ikxe,ikys:ikye,updatetlevel) ENDIF - CALL manual_2D_bcast(Ne00(ikrs:ikre,ikzs:ikze)) - CALL write_field2d(Ne00(ikrs:ikre,ikzs:ikze), 'Ne00') + CALL manual_2D_bcast(Ne00(ikxs:ikxe,ikys:ikye)) + CALL write_field2d(Ne00(ikxs:ikxe,ikys:ikye), 'Ne00') - CALL manual_2D_bcast(Ni00(ikrs:ikre,ikzs:ikze)) - CALL write_field2d(Ni00(ikrs:ikre,ikzs:ikze), 'Ni00') + CALL manual_2D_bcast(Ni00(ikxs:ikxe,ikys:ikye)) + CALL write_field2d(Ni00(ikxs:ikxe,ikys:ikye), '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_field2d(dens_e(ikxs:ikxe,ikys:ikye), 'dens_e') + CALL write_field2d(dens_i(ikxs:ikxe,ikys:ikye), '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_field2d(temp_e(ikxs:ikxe,ikys:ikye), 'temp_e') + CALL write_field2d(temp_i(ikxs:ikxe,ikys:ikye), 'temp_i') ENDIF CONTAINS SUBROUTINE write_field2d(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), INTENT(IN) :: field CHARACTER(*), INTENT(IN) :: text - COMPLEX(dp) :: buffer_dist(ikrs:ikre,ikzs:ikze) - COMPLEX(dp) :: buffer_full(1:nkr,1:nkz) + 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 = (ikre-ikrs+1) * (ikze-ikzs+1) + 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(ikrs:ikre, ikzs:ikze), ionode=0) + CALL putarr(fidres, dset_name, field(ikxs:ikxe, ikys:ikye), 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), (/1, 1/)) ENDIF CALL attach(fidres, dset_name, "time", time) END SUBROUTINE write_field2d END SUBROUTINE diagnose_2d SUBROUTINE diagnose_5d USE basic USE futils, ONLY: append, getatt, attach, putarrnd USE fields USE array!, ONLY: Sepj, Sipj USE grid, ONLY: ips_e,ipe_e, ips_i, ipe_i, & ijs_e,ije_e, ijs_i, ije_i USE time_integration USE diagnostics_par USE prec_const IMPLICIT NONE CALL append(fidres, "/data/var5d/time", time,ionode=0) CALL append(fidres, "/data/var5d/cstep", real(cstep,dp),ionode=0) CALL getatt(fidres, "/data/var5d/", "frames",iframe5d) iframe5d=iframe5d+1 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') 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') 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 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), 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), 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), (/1,3/)) ENDIF CALL attach(fidres, dset_name, 'cstep', cstep) CALL attach(fidres, dset_name, 'time', time) CALL attach(fidres, dset_name, 'jobnum', jobnum) CALL attach(fidres, dset_name, 'dt', dt) CALL attach(fidres, dset_name, 'iframe2d', iframe2d) CALL attach(fidres, dset_name, 'iframe5d', iframe5d) END SUBROUTINE write_field5d_e 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 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), 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), 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), (/1,3/)) ENDIF CALL attach(fidres, dset_name, 'cstep', cstep) CALL attach(fidres, dset_name, 'time', time) CALL attach(fidres, dset_name, 'jobnum', jobnum) CALL attach(fidres, dset_name, 'dt', dt) CALL attach(fidres, dset_name, 'iframe2d', iframe2d) CALL attach(fidres, dset_name, 'iframe5d', iframe5d) END SUBROUTINE write_field5d_i END SUBROUTINE diagnose_5d diff --git a/src/fields_mod.F90 b/src/fields_mod.F90 index 58075c2..b6fb94a 100644 --- a/src/fields_mod.F90 +++ b/src/fields_mod.F90 @@ -1,15 +1,15 @@ MODULE fields use prec_const implicit none !------------------MOMENTS Napj------------------ - ! Hermite-Moments: N_a^pj ! dimensions correspond to: p, j, kr, kz, updatetlevel. + ! Hermite-Moments: N_a^pj ! dimensions correspond to: p, j, kx, ky, updatetlevel. COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_e COMPLEX(dp), DIMENSION(:,:,:,:,:), ALLOCATABLE :: moments_i !------------------ELECTROSTATIC POTENTIAL------------------ - ! Normalized electric potential: \hat{\phi} ! (kr,kz) + ! Normalized electric potential: \hat{\phi} ! (kx,ky) COMPLEX(dp), DIMENSION(:,:), ALLOCATABLE :: phi END MODULE fields diff --git a/src/fourier_mod.F90 b/src/fourier_mod.F90 index 195b049..3c5a232 100644 --- a/src/fourier_mod.F90 +++ b/src/fourier_mod.F90 @@ -1,125 +1,125 @@ MODULE fourier USE prec_const USE grid USE basic use, intrinsic :: iso_c_binding implicit none ! INCLUDE 'fftw3.f03' INCLUDE 'fftw3-mpi.f03' PRIVATE PUBLIC :: init_grid_distr_and_plans, convolve_2D_F2F, finalize_plans real(C_DOUBLE), pointer, PUBLIC :: real_data_f(:,:), real_data_g(:,:), real_data_c(:,:) complex(C_DOUBLE_complex), pointer, PUBLIC :: cmpx_data_f(:,:), cmpx_data_g(:,:), cmpx_data_c(:,:) type(C_PTR) :: cdatar_f, cdatar_g, cdatar_c type(C_PTR) :: cdatac_f, cdatac_g, cdatac_c type(C_PTR) , PUBLIC :: planf, planb integer(C_INTPTR_T) :: i, ix, iy integer(C_INTPTR_T), PUBLIC :: alloc_local_1, alloc_local_2 integer(C_INTPTR_T) :: NR_, NZ_, NR_halved integer :: communicator ! many plan data variables integer(C_INTPTR_T) :: howmany=9 ! numer of eleemnt of the tensor integer :: rank=3 ! rank of the transform integer(C_INTPTR_T), dimension(2) :: fft_dims ! array containing data extent 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)) planb = fftw_mpi_plan_dft_c2r_2d(NZ_, NR_, cmpx_data_f, real_data_f, communicator, ior(FFTW_MEASURE, FFTW_MPI_TRANSPOSED_IN)) if ((.not. c_associated(planf)) .OR. (.not. c_associated(planb))) then write(*,*) "plan creation error!!" stop end if END SUBROUTINE init_grid_distr_and_plans !!! Convolution 2D Fourier to Fourier ! - Compute the convolution using the convolution theorem and MKL 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 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_f/NZ_/NR_ * real_data_g/NZ_/NR_ 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 END SUBROUTINE convolve_2D_F2F SUBROUTINE finalize_plans IMPLICIT NONE IF (my_id .EQ. 0) write(*,*) '..plan Destruction.' call fftw_destroy_plan(planb) call fftw_destroy_plan(planf) call fftw_mpi_cleanup() call fftw_free(cdatar_f) call fftw_free(cdatar_g) call fftw_free(cdatar_c) call fftw_free(cdatac_f) call fftw_free(cdatac_g) call fftw_free(cdatac_c) END SUBROUTINE finalize_plans END MODULE fourier diff --git a/src/ghosts_mod.F90 b/src/ghosts_mod.F90 index 416b7a3..20e71f6 100644 --- a/src/ghosts_mod.F90 +++ b/src/ghosts_mod.F90 @@ -1,81 +1,81 @@ module ghosts USE basic USE fields, ONLY : moments_e, moments_i USE grid USE time_integration IMPLICIT NONE INTEGER :: status(MPI_STATUS_SIZE), source, dest, count, ipg PUBLIC :: update_ghosts CONTAINS SUBROUTINE update_ghosts CALL cpu_time(t0_ghost) IF (num_procs_p .GT. 1) THEN ! Do it only if we share the p CALL MPI_BARRIER(MPI_COMM_WORLD,ierr) CALL update_ghosts_p_e CALL MPI_BARRIER(MPI_COMM_WORLD,ierr) CALL update_ghosts_p_i ENDIF CALL cpu_time(t1_ghost) tc_ghost = tc_ghost + (t1_ghost - t0_ghost) END SUBROUTINE update_ghosts !Communicate p+1, p+2 moments to left neighboor and p-1, p-2 moments to right one 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) !!!!!!!!!!! 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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 10, & + moments_e(ips_e-1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 11, & + moments_e(ips_e-2,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 12, & + moments_e(ipe_e+1,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 13, & + moments_e(ipe_e+2,ijsg_e:ijeg_e,ikxs:ikxe,ikys:ikye,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 13, & comm0, status, ierr) END SUBROUTINE update_ghosts_p_e !Communicate p+1, p+2 moments to left neighboor and p-1, p-2 moments to right one 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) ! 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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 14, & + moments_i(ips_i-1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 15, & + moments_i(ips_i-2,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 16, & + moments_i(ipe_i+1,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,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,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_L, 17, & + moments_i(ipe_i+2,ijsg_i:ijeg_i,ikxs:ikxe,ikys:ikye,updatetlevel), count, MPI_DOUBLE_COMPLEX, nbr_R, 17, & comm0, status, ierr) END SUBROUTINE update_ghosts_p_i END MODULE ghosts diff --git a/src/grid_mod.F90 b/src/grid_mod.F90 index 46d2ee3..90360fa 100644 --- a/src/grid_mod.F90 +++ b/src/grid_mod.F90 @@ -1,329 +1,330 @@ MODULE grid ! Grid module for spatial discretization USE prec_const USE basic IMPLICIT NONE PRIVATE ! GRID Namelist INTEGER, PUBLIC, PROTECTED :: pmaxe = 1 ! The maximal electron Hermite-moment computed INTEGER, PUBLIC, PROTECTED :: jmaxe = 1 ! The maximal electron Laguerre-moment computed 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 r + 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 z + REAL(dp), PUBLIC, PROTECTED :: Ly = 1._dp ! vertical length of the spatial box + 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 :: zarray - REAL(dp), PUBLIC, PROTECTED :: deltar, deltaz - INTEGER, PUBLIC, PROTECTED :: irs, ire, izs, ize + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: xarray + REAL(dp), DIMENSION(:), ALLOCATABLE, PUBLIC :: yarray + REAL(dp), PUBLIC, PROTECTED :: deltax, deltay + INTEGER, PUBLIC, PROTECTED :: ixs, ixe, iys, iye 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 INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: counts_np_e, counts_np_i 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 INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: parray_i INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: jarray_e INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: jarray_i INTEGER, PUBLIC, PROTECTED :: ips_e,ipe_e, ijs_e,ije_e ! Start and end indices for pol. deg. INTEGER, PUBLIC, PROTECTED :: ips_i,ipe_i, ijs_i,ije_i INTEGER, PUBLIC, PROTECTED :: ipsg_e,ipeg_e, ijsg_e,ijeg_e ! Ghosts start and end indices INTEGER, PUBLIC, PROTECTED :: ipsg_i,ipeg_i, ijsg_i,ijeg_i ! 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 PUBLIC :: grid_readinputs, grid_outputinputs PUBLIC :: bare, bari ! Precomputations real(dp), PUBLIC, PROTECTED :: pmaxe_dp, pmaxi_dp, jmaxe_dp,jmaxi_dp 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 SUBROUTINE set_pgrid USE prec_const IMPLICIT NONE INTEGER :: ip, istart, iend, in ! Local data distribution CALL decomp1D(pmaxe+1, num_procs_p, rank_p, ips_e, ipe_e) CALL decomp1D(pmaxi+1, num_procs_p, rank_p, ips_i, ipe_i) local_np_e = ipe_e - ips_e + 1 local_np_i = ipe_i - ips_i + 1 ! List of shift and local numbers between the different processes (used in scatterv and gatherv) ALLOCATE(counts_np_e (1:num_procs_p)) ALLOCATE(counts_np_i (1:num_procs_p)) ALLOCATE(displs_np_e (1:num_procs_p)) ALLOCATE(displs_np_i (1:num_procs_p)) DO in = 0,num_procs_p-1 CALL decomp1D(pmaxe+1, num_procs_p, in, istart, iend) counts_np_e(in+1) = iend-istart+1 displs_np_e(in+1) = istart-1 CALL decomp1D(pmaxi+1, num_procs_p, in, istart, iend) counts_np_i(in+1) = iend-istart+1 displs_np_i(in+1) = istart-1 !DGGK operator uses moments at index p=2 (ip=3) for the p=0 term so the ! process that contains ip=1 MUST contain ip=3 as well for both e and i. IF(((ips_e .EQ. 1) .OR. (ips_i .EQ. 1)) .AND. ((ipe_e .LT. 3) .OR. (ipe_i .LT. 3)))& WRITE(*,*) "Warning : distribution along p may not work with DGGK" ENDDO ! local grid computation ALLOCATE(parray_e(ips_e:ipe_e)) ALLOCATE(parray_i(ips_i:ipe_i)) DO ip = ips_e,ipe_e; parray_e(ip) = (ip-1); END DO DO ip = ips_i,ipe_i; parray_i(ip) = (ip-1); END DO ! Ghosts boundaries ipsg_e = ips_e - 2; ipeg_e = ipe_e + 2; ipsg_i = ips_i - 2; ipeg_i = ipe_i + 2; ! Precomputations pmaxe_dp = real(pmaxe,dp) pmaxi_dp = real(pmaxi,dp) END SUBROUTINE set_pgrid SUBROUTINE set_jgrid USE prec_const IMPLICIT NONE INTEGER :: ij ijs_e = 1; ije_e = jmaxe + 1 ijs_i = 1; ije_i = jmaxi + 1 ALLOCATE(jarray_e(ijs_e:ije_e)) ALLOCATE(jarray_i(ijs_i:ije_i)) DO ij = ijs_e,ije_e; jarray_e(ij) = ij-1; END DO DO ij = ijs_i,ije_i; jarray_i(ij) = ij-1; END DO maxj = MAX(jmaxi, jmaxe) ! Ghosts boundaries ijsg_e = ijs_e - 1; ijeg_e = ije_e + 1; ijsg_i = ijs_i - 1; ijeg_i = ije_i + 1; ! Precomputations jmaxe_dp = real(jmaxe,dp) jmaxi_dp = real(jmaxi,dp) 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 grid_readinputs ! Read the input parameters USE prec_const IMPLICIT NONE INTEGER :: lu_in = 90 ! File duplicated from STDIN NAMELIST /GRID/ pmaxe, jmaxe, pmaxi, jmaxi, & - Nr, Lr, Nz, Lz, kpar + Nx, Lx, Ny, Ly, kpar READ(lu_in,grid) END SUBROUTINE grid_readinputs SUBROUTINE grid_outputinputs(fidres, str) ! Write the input parameters to the results_xx.h5 file USE futils, ONLY: attach USE prec_const IMPLICIT NONE INTEGER, INTENT(in) :: fidres CHARACTER(len=256), INTENT(in) :: str CALL attach(fidres, TRIM(str), "pmaxe", pmaxe) 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), "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_) IMPLICIT NONE INTEGER :: bare, p_, j_ bare = (jmaxe+1)*p_ + j_ + 1 END FUNCTION FUNCTION bari(p_,j_) IMPLICIT NONE INTEGER :: bari, p_, j_ bari = (jmaxi+1)*p_ + j_ + 1 END FUNCTION SUBROUTINE decomp1D( n, numprocs, myid, s, e ) INTEGER :: n, numprocs, myid, s, e INTEGER :: nlocal INTEGER :: deficit nlocal = n / numprocs s = myid * nlocal + 1 deficit = MOD(n,numprocs) s = s + MIN(myid,deficit) IF (myid .LT. deficit) nlocal = nlocal + 1 e = s + nlocal - 1 IF (e .GT. n .OR. myid .EQ. numprocs-1) e = n END SUBROUTINE decomp1D END MODULE grid diff --git a/src/inital.F90 b/src/inital.F90 index 91f05c8..746d961 100644 --- a/src/inital.F90 +++ b/src/inital.F90 @@ -1,343 +1,343 @@ !******************************************************************************! !!!!!! initialize the moments and load/build coeff tables !******************************************************************************! SUBROUTINE inital USE basic 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 CALL set_updatetlevel(1) IF (my_id .EQ. 0) WRITE(*,*) 'Evaluate kernels' CALL evaluate_kernels !!!!!! Set the moments arrays Nepj, Nipj and phi!!!!!! 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) ELSE 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 ELSE IF (my_id .EQ. 0) WRITE(*,*) 'Init noisy moments and ghosts' 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 IF (my_id .EQ. 0) WRITE(*,*) 'Apply closure' CALL apply_closure_model IF (my_id .EQ. 0) WRITE(*,*) 'Ghosts communication' CALL update_ghosts !!!!!! 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 !!!!!! Load the COSOlver collision operator coefficients !!!!!! IF (ABS(CO) .GT. 1) THEN CALL load_COSOlver_mat ! Compute collision CALL compute_TColl ! compute C_0 = C(N_0) ENDIF END SUBROUTINE inital !******************************************************************************! !******************************************************************************! !!!!!!! Initialize the moments randomly !******************************************************************************! SUBROUTINE init_moments USE basic USE grid USE fields USE prec_const USE utility, ONLY: checkfield USE initial_par USE model, ONLY : NON_LIN 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 iseedarr(:)=iseed CALL RANDOM_SEED(PUT=iseedarr+my_id) !**** Broad noise initialization ******************************************* DO ip=ips_e,ipe_e DO ij=ijs_e,ije_e - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze + DO ikx=ikxs,ikxe + DO iky=ikys,ikye CALL RANDOM_NUMBER(noise) - moments_e( ip,ij, ikr,ikz, :) = (init_background + init_noiselvl*(noise-0.5_dp)) + moments_e( ip,ij, ikx,iky, :) = (init_background + init_noiselvl*(noise-0.5_dp)) 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 + moments_e( ip,ij,ikx_0,iky, :) = moments_e( ip,ij,ikx_0,Nky+2-iky, :) END DO ENDIF END DO END DO DO ip=ips_i,ipe_i DO ij=ijs_i,ije_i - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze + DO ikx=ikxs,ikxe + DO iky=ikys,ikye CALL RANDOM_NUMBER(noise) - moments_i( ip,ij, ikr,ikz, :) = (init_background + init_noiselvl*(noise-0.5_dp)) + moments_i( ip,ij, ikx,iky, :) = (init_background + init_noiselvl*(noise-0.5_dp)) 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 + moments_i( ip,ij,ikx_0,iky, :) = moments_i( ip,ij,ikx_0,Nky+2-iky, :) END DO ENDIF END DO END DO ! 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) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + moments_e( ip,ij,ikx,iky, :) = moments_e( ip,ij,ikx,iky, :)*AA_x(ikx)*AA_y(iky) 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) + DO ikx=ikxs,ikxe + DO iky=ikys,ikye + moments_i( ip,ij,ikx,iky, :) = moments_i( ip,ij,ikx,iky, :)*AA_x(ikx)*AA_y(iky) ENDDO ENDDO ENDDO ENDDO ENDIF END SUBROUTINE init_moments !******************************************************************************! !******************************************************************************! !!!!!!! Initialize a noisy ES potential and cancel the moments !******************************************************************************! SUBROUTINE init_phi USE basic USE grid USE fields USE prec_const USE initial_par 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 ! Seed random number generator iseedarr(:)=iseed CALL RANDOM_SEED(PUT=iseedarr+my_id) !**** noise initialization ******************************************* - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze + DO ikx=ikxs,ikxe + DO iky=ikys,ikye CALL RANDOM_NUMBER(noise) - phi(ikr,ikz) = (init_background + init_noiselvl*(noise-0.5_dp))*AA_r(ikr)*AA_z(ikz) + phi(ikx,iky) = (init_background + init_noiselvl*(noise-0.5_dp))*AA_x(ikx)*AA_y(iky) 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 moments_e = 0._dp; moments_i = 0._dp 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 + ! put a mode at ikx = mode number + 1, symmetry is already included since kx>=0 + IF( (INIT_ZF+1 .GT. ikxs) .AND. (INIT_ZF+1 .LT. ikxe) ) THEN + phi(INIT_ZF+1,iky_0) = ZF_AMP*(2._dp*PI)**2/deltakx/deltaky/2._dp + moments_i(1,1,INIT_ZF+1,iky_0,:) = kxarray(INIT_ZF+1)**2*phi(INIT_ZF+1,iky_0) + moments_e(1,1,INIT_ZF+1,iky_0,:) = 0._dp ENDIF ENDIF ELSE ! we compute phi from noisy moments and poisson CALL poisson ENDIF END SUBROUTINE init_phi !******************************************************************************! !******************************************************************************! !!!!!!! Build the Laguerre-Laguerre coupling coefficient table for nonlin !******************************************************************************! SUBROUTINE build_dnjs_table USE basic USE array, Only : dnjs USE grid, Only : jmaxe, jmaxi 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 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 + REAL(dp) :: kx, ky, 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) + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) - be_2 = (kr**2 + kz**2) * sigmae2_taue_o2 + be_2 = (kx**2 + ky**2) * sigmae2_taue_o2 - kernel_e(ij, ikr, ikz) = be_2**j_int * exp(-be_2)/factj + kernel_e(ij, ikx, iky) = 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) + 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(ijeg_e,ikx,iky) = be_2/(real(ijeg_e,dp))*kernel_e(ije_e,ikx,iky) 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) + DO ikx = ikxs,ikxe + kx = kxarray(ikx) + DO iky = ikys,ikye + ky = kyarray(iky) - bi_2 = (kr**2 + kz**2) * sigmai2_taui_o2 + bi_2 = (kx**2 + ky**2) * sigmai2_taui_o2 - kernel_i(ij, ikr, ikz) = bi_2**j_int * exp(-bi_2)/factj + kernel_i(ij, ikx, iky) = 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) + 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(ijeg_i,ikx,iky) = bi_2/(real(ijeg_i,dp))*kernel_e(ije_i,ikx,iky) ENDDO ENDDO END SUBROUTINE evaluate_kernels !******************************************************************************! diff --git a/src/memory.F90 b/src/memory.F90 index 4458499..2d1ca5c 100644 --- a/src/memory.F90 +++ b/src/memory.F90 @@ -1,70 +1,70 @@ SUBROUTINE memory ! Allocate arrays (done dynamically otherwise size is unknown) USE array USE basic USE fields USE grid USE time_integration USE model, ONLY: CO, NON_LIN USE prec_const IMPLICIT NONE !___________________ 2D ARRAYS __________________________ ! Electrostatic potential - CALL allocate_array(phi, ikrs,ikre, ikzs,ikze) + CALL allocate_array(phi, ikxs,ikxe, ikys,ikye) !! 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) + CALL allocate_array(Ni00, ikxs,ikxe, ikys,ikye) ! 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) + CALL allocate_array(dens_i, ikxs,ikxe, ikys,ikye) ! 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) + CALL allocate_array(temp_i, ikxs,ikxe, ikys,ikye) !___________________ 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, 1,ntimelevel ) + CALL allocate_array( moments_i, ipsg_i,ipeg_i, ijsg_i,ijeg_i, ikxs,ikxe, ikys,ikye, 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, 1,ntimelevel ) + CALL allocate_array( moments_rhs_i, ips_i,ipe_i, ijs_i,ije_i, ikxs,ikxe, ikys,ikye, 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) + CALL allocate_array( TColl_i, ips_i,ipe_i, ijs_i,ije_i , ikxs,ikxe, ikys,ikye) ! 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 ) + CALL allocate_array( Sipj, ips_i,ipe_i, ijs_i,ije_i, ikxs,ikxe, ikys,ikye ) CALL allocate_array( dnjs, 1,maxj+1, 1,maxj+1, 1,maxj+1) !___________________ 2x5D ARRAYS __________________________ !! Collision matrices IF (CO .LT. -1) THEN !DK collision matrix (same for every k) CALL allocate_array( Ceepj, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), 1,1, 1,1) CALL allocate_array( CeipjT, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxe+1)*(jmaxe+1), 1,1, 1,1) CALL allocate_array( CeipjF, 1,(pmaxe+1)*(jmaxe+1), 1,(pmaxi+1)*(jmaxi+1), 1,1, 1,1) CALL allocate_array( Ciipj, 1,(pmaxi+1)*(jmaxi+1), 1,(pmaxi+1)*(jmaxi+1), 1,1, 1,1) 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/moments_eq_rhs.F90 b/src/moments_eq_rhs.F90 index d56a0bf..3a65bfe 100644 --- a/src/moments_eq_rhs.F90 +++ b/src/moments_eq_rhs.F90 @@ -1,371 +1,371 @@ !_____________________________________________________________________________! !_____________________________________________________________________________! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!! Electrons moments RHS !!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !_____________________________________________________________________________! SUBROUTINE moments_eq_rhs_e USE basic USE time_integration USE array USE fields 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) :: kx, ky, 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 + COMPLEX(dp) :: i_ky, Hyper_diff_p, Hyper_diff_j ! 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)) 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 + IF ((p_int .EQ. 2) .AND. (j_int .EQ. 0)) THEN ! kxonecker 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 + ELSEIF ((p_int .EQ. 0) .AND. (j_int .EQ. 1)) THEN ! kxonecker 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 + ELSEIF ((p_int .EQ. 1) .AND. (j_int .EQ. 0)) THEN ! kxonecker 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 + IF (p_int .EQ. 0) THEN ! kxonecker 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 + ELSE IF (p_int .EQ. 1) THEN ! kxonecker p1 xphijpar = qe_sigmae_sqrtTaue xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp - ELSE IF (p_int .EQ. 2) THEN ! kronecker p2 + ELSE IF (p_int .EQ. 2) THEN ! kxonecker 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 + kxloope : DO ikx = ikxs,ikxe + kyloope : DO iky = ikys,ikye + kx = kxarray(ikx) ! Poloidal wavevector + ky = kyarray(iky) ! Toroidal wavevector + i_ky = imagu * ky ! Ddz 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) + TNapj = xNapj * moments_e(ip,ij,ikx,iky,updatetlevel) ! term propto N_e^{p+2,j} - TNapp2j = xNapp2j * moments_e(ip+2,ij,ikr,ikz,updatetlevel) + TNapp2j = xNapp2j * moments_e(ip+2,ij,ikx,iky,updatetlevel) ! term propto N_e^{p-2,j} - TNapm2j = xNapm2j * moments_e(ip-2,ij,ikr,ikz,updatetlevel) + TNapm2j = xNapm2j * moments_e(ip-2,ij,ikx,iky,updatetlevel) ! term propto N_e^{p,j+1} - TNapjp1 = xNapjp1 * moments_e(ip,ij+1,ikr,ikz,updatetlevel) + TNapjp1 = xNapjp1 * moments_e(ip,ij+1,ikx,iky,updatetlevel) ! term propto N_e^{p,j-1} - TNapjm1 = xNapjm1 * moments_e(ip,ij-1,ikr,ikz,updatetlevel) + TNapjm1 = xNapjm1 * moments_e(ip,ij-1,ikx,iky,updatetlevel) !! Collision IF (CO .EQ. 0) THEN ! Lenard Bernstein - TColl = xCapj * moments_e(ip,ij,ikr,ikz,updatetlevel) + TColl = xCapj * moments_e(ip,ij,ikx,iky,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) + IF ( (pmaxe .GE. 2) ) TColl20 = xCa20 * moments_e(3,1,ikx,iky,updatetlevel) + IF ( (jmaxe .GE. 1) ) TColl01 = xCa01 * moments_e(1,2,ikx,iky,updatetlevel) + IF ( (pmaxe .GE. 1) ) TColl10 = xCa10 * moments_e(2,1,ikx,iky,updatetlevel) ! Total collisional term - TColl = xCapj* moments_e(ip,ij,ikr,ikz,updatetlevel)& + TColl = xCapj* moments_e(ip,ij,ikx,iky,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') + CALL DoughertyGK_e(ip,ij,ikx,iky,TColl) + ! CALL DoughertyGK(ip,ij,ikx,iky,TColl,'e') ELSE ! COSOLver matrix - TColl = TColl_e(ip,ij,ikr,ikz) + TColl = TColl_e(ip,ij,ikx,iky) ENDIF !! 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) ) + IF ( p_int .LE. 2 ) THEN ! kxonecker p0 p1 p2 + Tphi = phi(ikx,iky) * (xphij*kernel_e(ij, ikx, iky) & + + xphijp1*kernel_e(ij+1, ikx, iky) & + + xphijm1*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) + *moments_e(ip-4,ij,ikx,iky,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) + Hyper_diff_j = Hyper_diff_j + (j_dp-(l_dp+1_dp))*moments_e(ip,il,ikx,iky,updatetlevel) ENDDO 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) & + moments_rhs_e(ip,ij,ikx,iky,updatetlevel) = & + - INV_LIN_SYS * i_ky * (TNapj + TNapp2j + TNapm2j + TNapjp1 + TNapjm1 - Tphi)& + - mu*kperp2**2 * moments_e(ip,ij,ikx,iky,updatetlevel) & + mu_p * Hyper_diff_p + mu_j * Hyper_diff_j & + INV_LIN_SYS * 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,updatetlevel) = & + moments_rhs_e(ip,ij,ikx,iky,updatetlevel) + Sepj(ip,ij,ikx,iky) ENDIF - END DO kzloope - END DO krloope + END DO kyloope + END DO kxloope END DO jloope END DO ploope ! Execution time end CALL cpu_time(t1_rhs) tc_rhs = tc_rhs + (t1_rhs-t0_rhs) END SUBROUTINE moments_eq_rhs_e !_____________________________________________________________________________! !_____________________________________________________________________________! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!! Ions moments RHS !!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !_____________________________________________________________________________! SUBROUTINE moments_eq_rhs_i USE basic USE time_integration, ONLY: updatetlevel USE array USE fields 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) :: kx, ky, 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 + COMPLEX(dp) :: i_ky, Hyper_diff_p, Hyper_diff_j LOGICAL :: COPY_CLOS = .false. ! To test closures ! LOGICAL :: COPY_CLOS = .true. ! To test closures ! 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)) 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 + IF ((p_int .EQ. 2) .AND. (j_int .EQ. 0)) THEN ! kxonecker 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 + ELSEIF ((p_int .EQ. 0) .AND. (j_int .EQ. 1)) THEN ! kxonecker 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 + ELSEIF ((p_int .EQ. 1) .AND. (j_int .EQ. 0)) THEN ! kxonecker 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 + IF (p_int .EQ. 0) THEN ! kxokecker 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 + ELSE IF (p_int .EQ. 1) THEN ! kxonecker p1 xphijpar = qi_sigmai_sqrtTaui xphij = 0._dp; xphijp1 = 0._dp; xphijm1 = 0._dp - ELSE IF (p_int .EQ. 2) THEN !krokecker p2 + ELSE IF (p_int .EQ. 2) THEN !kxokecker 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 + kxloopi : DO ikx = ikxs,ikxe + kyloopi : DO iky = ikys,ikye + kx = kxarray(ikx) ! Poloidal wavevector + ky = kyarray(iky) ! Toroidal wavevector + i_ky = imagu * ky ! Ddz 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) + TNapj = xNapj * moments_i(ip,ij,ikx,iky,updatetlevel) ! term propto N_i^{p+2,j} - TNapp2j = xNapp2j * moments_i(ip+2,ij,ikr,ikz,updatetlevel) + TNapp2j = xNapp2j * moments_i(ip+2,ij,ikx,iky,updatetlevel) ! term propto N_i^{p-2,j} - TNapm2j = xNapm2j * moments_i(ip-2,ij,ikr,ikz,updatetlevel) + TNapm2j = xNapm2j * moments_i(ip-2,ij,ikx,iky,updatetlevel) ! term propto N_i^{p,j+1} - TNapjp1 = xNapjp1 * moments_i(ip,ij+1,ikr,ikz,updatetlevel) + TNapjp1 = xNapjp1 * moments_i(ip,ij+1,ikx,iky,updatetlevel) ! term propto N_i^{p,j-1} - TNapjm1 = xNapjm1 * moments_i(ip,ij-1,ikr,ikz,updatetlevel) + TNapjm1 = xNapjm1 * moments_i(ip,ij-1,ikx,iky,updatetlevel) !! Collision IF (CO .EQ. 0) THEN ! Lenard Bernstein - TColl = xCapj * moments_i(ip,ij,ikr,ikz,updatetlevel) + TColl = xCapj * moments_i(ip,ij,ikx,iky,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) + IF ( (pmaxi .GE. 2) ) TColl20 = xCa20 * moments_i(3,1,ikx,iky,updatetlevel) + IF ( (jmaxi .GE. 1) ) TColl01 = xCa01 * moments_i(1,2,ikx,iky,updatetlevel) + IF ( (pmaxi .GE. 1) ) TColl10 = xCa10 * moments_i(2,1,ikx,iky,updatetlevel) ! Total collisional term - TColl = xCapj* moments_i(ip,ij,ikr,ikz,updatetlevel)& + TColl = xCapj* moments_i(ip,ij,ikx,iky,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') + CALL DoughertyGK_i(ip,ij,ikx,iky,TColl) + ! CALL DoughertyGK(ip,ij,ikx,iky,TColl,'i') ELSE! COSOLver matrix (Sugama, Coulomb) - TColl = TColl_i(ip,ij,ikr,ikz) + TColl = TColl_i(ip,ij,ikx,iky) ENDIF !! 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) ) + IF ( p_int .LE. 2 ) THEN ! kxonecker p0 p1 p2 + Tphi = phi(ikx,iky) * (xphij*kernel_i(ij, ikx, iky) & + + xphijp1*kernel_i(ij+1, ikx, iky) & + + xphijm1*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) + Hyper_diff_p = (2._dp*p_dp)**2 *moments_i(ip-4,ij,ikx,iky,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) + Hyper_diff_j = Hyper_diff_j + (j_dp-(l_dp+1_dp))*moments_i(ip,il,ikx,iky,updatetlevel) ENDDO 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) & + moments_rhs_i(ip,ij,ikx,iky,updatetlevel) = & + -INV_LIN_SYS * i_ky * (TNapj + TNapp2j + TNapm2j + TNapjp1 + TNapjm1 - Tphi)& + - mu*kperp2**2 * moments_i(ip,ij,ikx,iky,updatetlevel) & + mu_p * Hyper_diff_p + mu_j * Hyper_diff_j & +INV_LIN_SYS * 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,updatetlevel) = & + moments_rhs_i(ip,ij,ikx,iky,updatetlevel) + Sipj(ip,ij,ikx,iky) ENDIF - END DO kzloopi - END DO krloopi + END DO kyloopi + END DO kxloopi END DO jloopi END DO ploopi ! Execution time end CALL cpu_time(t1_rhs) tc_rhs = tc_rhs + (t1_rhs-t0_rhs) END SUBROUTINE moments_eq_rhs_i diff --git a/src/poisson.F90 b/src/poisson.F90 index b4d3918..7ed1a50 100644 --- a/src/poisson.F90 +++ b/src/poisson.F90 @@ -1,78 +1,78 @@ SUBROUTINE poisson ! Solve poisson equation to get phi USE basic USE time_integration, ONLY: updatetlevel USE array USE fields USE grid USE utility use model, ONLY : qe2_taue, qi2_taui, q_e, q_i, lambdaD USE prec_const IMPLICIT NONE INTEGER :: ini,ine, i_, root_bcast REAL(dp) :: Kne, Kni ! sub kernel factor for recursive build REAL(dp) :: alphaD REAL(dp) :: sum_kernel2_e, sum_kernel2_i ! Store sum Kn^2 COMPLEX(dp) :: sum_kernel_mom_e, sum_kernel_mom_i ! Store sum Kn*Napn 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 ! Execution time start CALL cpu_time(t0_poisson) - DO ikr=ikrs,ikre - DO ikz=ikzs,ikze + DO ikx=ikxs,ikxe + DO iky=ikys,ikye !!!!!!!!!!!!! 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) + Kne = kernel_e(ine, ikx, iky) + sum_kernel_mom_e = sum_kernel_mom_e + Kne * moments_e(1, ine, ikx, iky, 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 ! 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) + Kni = kernel_i(ini, ikx, iky) + sum_kernel_mom_i = sum_kernel_mom_i + Kni * moments_i(1, ini, ikx, iky, updatetlevel) sum_kernel2_i = sum_kernel2_i + Kni**2 ! ... sum recursively ... END DO !!!!!!!!!!!!!!! Assembling the poisson equation !!!!!!!!!!!!!!!!!!!!!!!!!! - alphaD = (krarray(ikr)**2 + kzarray(ikz)**2) * lambdaD**2 + 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 - phi(ikr, ikz) = gammaD_phi/gammaD + phi(ikx, iky) = gammaD_phi/gammaD END DO END DO ! 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) = 0 ENDIF ! Transfer phi to all the others process along p - CALL manual_2D_bcast(phi(ikrs:ikre,ikzs:ikze)) + CALL manual_2D_bcast(phi(ikxs:ikxe,ikys:ikye)) ! Execution time end CALL cpu_time(t1_poisson) tc_poisson = tc_poisson + (t1_poisson - t0_poisson) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! END SUBROUTINE poisson diff --git a/src/ppinit.F90 b/src/ppinit.F90 index 1364ea9..9b8382b 100644 --- a/src/ppinit.F90 +++ b/src/ppinit.F90 @@ -1,69 +1,69 @@ SUBROUTINE ppinit ! Parallel environment USE basic use prec_const IMPLICIT NONE 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 INTEGER :: nargs, i, l CALL MPI_INIT(ierr) CALL MPI_COMM_RANK (MPI_COMM_WORLD, my_id, ierr) CALL MPI_COMM_SIZE (MPI_COMM_WORLD, num_procs, ierr) nargs = COMMAND_ARGUMENT_COUNT() IF( nargs .NE. 0 .AND. nargs .NE. ndims ) THEN IF(my_id .EQ. 0) WRITE(*, '(a,i4,a)') 'Number of arguments not equal to NDIMS =', ndims, '!' CALL MPI_ABORT(MPI_COMM_WORLD, -1, ierr) END IF ! IF( nargs .NE. 0 ) THEN DO i=1,nargs CALL GET_COMMAND_ARGUMENT(i, str, l, ierr) READ(str(1:l),'(i3)') dims(i) END DO IF( PRODUCT(dims) .NE. num_procs ) THEN IF(my_id .EQ. 0) WRITE(*, '(a,i4,a,i4)') 'Product of dims: ', PRODUCT(dims), " is not consistent WITH NPROCS=",num_procs CALL MPI_ABORT(MPI_COMM_WORLD, -2, ierr) END IF ELSE ! CALL MPI_DIMS_CREATE(num_procs, ndims, dims, ierr) dims(1) = 1 dims(2) = num_procs 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) CALL MPI_COMM_RANK(comm0, rank_0, ierr) CALL MPI_CART_COORDS(comm0,rank_0,ndims,coords,ierr) ! ! 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) END SUBROUTINE ppinit diff --git a/src/processing_mod.F90 b/src/processing_mod.F90 index 0cf497c..8ed9fe0 100644 --- a/src/processing_mod.F90 +++ b/src/processing_mod.F90 @@ -1,136 +1,136 @@ MODULE processing ! contains the Hermite-Laguerre collision operators. Solved using COSOlver. USE basic USE prec_const USE grid USE utility implicit none REAL(dp), PUBLIC, PROTECTED :: pflux_ri, gflux_ri PUBLIC :: compute_radial_ion_transport, compute_density, compute_temperature CONTAINS ! 1D diagnostic to compute the average radial particle transport _r SUBROUTINE compute_radial_ion_transport USE fields, ONLY : moments_i, phi USE array, ONLY : kernel_i 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 + ! Loop to compute gamma_kx = sum_ky sum_j -i k_z Kernel_j Ni00 * phi + DO iky = ikys,ikye + ky_ = kyarray(iky) + DO ikx = ikxs,ikxe gflux_local = gflux_local - & - imagu * kz_ * moments_i(1,1,ikr,ikz,updatetlevel) * CONJG(phi(ikr,ikz)) + imagu * ky_ * moments_i(1,1,ikx,iky,updatetlevel) * CONJG(phi(ikx,iky)) 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)) + imagu * ky_ * kernel_i(ij,ikx,iky) * moments_i(1,ij,ikx,iky,updatetlevel) * CONJG(phi(ikx,iky)) ENDDO ENDDO ENDDO 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 ENDIF ENDIF ENDIF END SUBROUTINE compute_radial_ion_transport ! Compute the 2D particle density for electron and ions (sum over Laguerre) SUBROUTINE compute_density USE fields, ONLY : moments_i, moments_e, phi USE array, ONLY : dens_e, dens_i, kernel_e, kernel_i USE time_integration, ONLY : updatetlevel USE model, ONLY : q_e, q_i, tau_e, tau_i IMPLICIT NONE 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 + DO iky = ikys,ikye + DO ikx = ikxs,ikxe ! electron density - dens_e(ikr,ikz) = 0._dp + dens_e(ikx,iky) = 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)) + dens_e(ikx,iky) = dens_e(ikx,iky) + kernel_e(ij,ikx,iky) * & + (moments_e(1,ij,ikx,iky,updatetlevel)+q_e/tau_e*kernel_e(ij,ikx,iky)*phi(ikx,iky)) ENDDO ! ion density - dens_i(ikr,ikz) = 0._dp + dens_i(ikx,iky) = 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)) + dens_i(ikx,iky) = dens_i(ikx,iky) + kernel_i(ij,ikx,iky) * & + (moments_i(1,ij,ikx,iky,updatetlevel)+q_i/tau_i*kernel_i(ij,ikx,iky)*phi(ikx,iky)) 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_2D_bcast(dens_e(ikxs:ikxe,ikys:ikye)) + CALL manual_2D_bcast(dens_i(ikxs:ikxe,ikys:ikye)) END SUBROUTINE compute_density ! Compute the 2D particle temperature for electron and ions (sum over Laguerre) SUBROUTINE compute_temperature USE fields, ONLY : moments_i, moments_e, phi USE array, ONLY : temp_e, temp_i, kernel_e, kernel_i USE time_integration, ONLY : updatetlevel USE model, ONLY : q_e, q_i, tau_e, tau_i IMPLICIT NONE REAL(dp) :: j_dp COMPLEX(dp) :: Tperp, Tpar 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 + DO iky = ikys,ikye + DO ikx = ikxs,ikxe ! electron temperature - temp_e(ikr,ikz) = 0._dp + temp_e(ikx,iky) = 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) + temp_e(ikx,iky) = temp_e(ikx,iky) + & + 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,updatetlevel)+q_e/tau_e*kernel_e(ij,ikx,iky)*phi(ikx,iky)) + & + SQRT2/3._dp * kernel_e(ij,ikx,iky) * moments_e(3,ij,ikx,iky,updatetlevel) ENDDO ! ion temperature - temp_i(ikr,ikz) = 0._dp + temp_i(ikx,iky) = 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) + temp_i(ikx,iky) = temp_i(ikx,iky) + & + 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,updatetlevel)+q_i/tau_i*kernel_i(ij,ikx,iky)*phi(ikx,iky)) + & + SQRT2/3._dp * kernel_i(ij,ikx,iky) * moments_i(3,ij,ikx,iky,updatetlevel) 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_2D_bcast(temp_e(ikxs:ikxe,ikys:ikye)) + CALL manual_2D_bcast(temp_i(ikxs:ikxe,ikys:ikye)) END SUBROUTINE compute_temperature END MODULE processing diff --git a/src/restarts_mod.F90 b/src/restarts_mod.F90 index f3f14e9..e8abdef 100644 --- a/src/restarts_mod.F90 +++ b/src/restarts_mod.F90 @@ -1,247 +1,247 @@ MODULE restarts USE basic USE futils, ONLY: openf, closef, getarr, getatt, isgroup, isdataset,getarrnd USE grid USE fields USE diagnostics_par USE time_integration IMPLICIT NONE 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 PUBLIC :: load_moments CONTAINS !******************************************************************************! !!!!!!! Load moments from a previous output file !******************************************************************************! SUBROUTINE load_moments IMPLICIT NONE ! Checkpoint filename WRITE(rstfile,'(a,a1,i2.2,a3)') TRIM(resfile0),'_',job2load,'.h5' IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Resume from ", rstfile ! Open file CALL openf(rstfile, fidrst,mpicomm=comm0) ! Get the checkpoint moments degrees to allocate memory CALL getatt(fidrst,"/data/input/" , "pmaxe", pmaxe_cp) CALL getatt(fidrst,"/data/input/" , "jmaxe", jmaxe_cp) CALL getatt(fidrst,"/data/input/" , "pmaxi", pmaxi_cp) CALL getatt(fidrst,"/data/input/" , "jmaxi", jmaxi_cp) IF (my_id .EQ. 0) WRITE(*,*) "Pe_cp = ", pmaxe_cp IF (my_id .EQ. 0) WRITE(*,*) "Je_cp = ", jmaxe_cp CALL getatt(fidrst,"/data/input/" , "start_iframe5d", n0) IF ((pmaxe_cp .NE. pmaxe) .OR. (jmaxe_cp .NE. jmaxe) .OR.& (pmaxi_cp .NE. pmaxi) .OR. (jmaxi_cp .NE. jmaxi)) THEN IF(my_id.EQ.0)WRITE(*,*) '! Extending the polynomials basis !' CALL load_output_adapt_pj ELSE ! 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 DO WHILE (isdataset(fidrst, dset_name)) ! If n_ is not a file we stop the loop n_ = n_ + 1 WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ ! updtate file number ENDDO n_ = n_ - 1 ! n_ is not a file so take the previous one n_-1 ! Read time dependent attributes to continue simulation WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ CALL getatt(fidrst, dset_name, 'cstep', cstep) CALL getatt(fidrst, dset_name, 'time', time) CALL getatt(fidrst, dset_name, 'jobnum', jobnum) jobnum = jobnum+1 CALL getatt(fidrst, dset_name, 'iframe2d',iframe2d) CALL getatt(fidrst, dset_name, 'iframe5d',iframe5d) iframe2d = iframe2d-1; iframe5d = iframe5d-1 IF(my_id.EQ.0) WRITE(*,*) '.. restart from t = ', time ! 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, 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, 1),(/1,3/)) CALL closef(fidrst) IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Reading from restart file "//TRIM(rstfile)//" completed!" ENDIF END SUBROUTINE load_moments !******************************************************************************! !******************************************************************************! !!!!!!! Load moments from a previous output file with possible different PJ !******************************************************************************! SUBROUTINE load_output_adapt_pj IMPLICIT NONE ! Checkpoint filename WRITE(rstfile,'(a,a1,i2.2,a3)') TRIM(resfile0),'_',job2load,'.h5' IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Resume from ", rstfile ! Open file CALL openf(rstfile, fidrst,mpicomm=comm0) ! Get the checkpoint moments degrees to allocate memory CALL getatt(fidrst,"/data/input/" , "pmaxe", pmaxe_cp) CALL getatt(fidrst,"/data/input/" , "jmaxe", jmaxe_cp) CALL getatt(fidrst,"/data/input/" , "pmaxi", pmaxi_cp) CALL getatt(fidrst,"/data/input/" , "jmaxi", jmaxi_cp) IF (my_id .EQ. 0) WRITE(*,*) "Pe_cp = ", pmaxe_cp IF (my_id .EQ. 0) WRITE(*,*) "Je_cp = ", jmaxe_cp 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) + CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikxs,ikxe, ikys,ikye) ! 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 DO WHILE (isdataset(fidrst, dset_name)) ! If n_ is not a file we stop the loop n_ = n_ + 1 WRITE(dset_name, "(A, '/', i6.6)") "/data/var5d/moments_e", n_ ! updtate file number ENDDO n_ = n_ - 1 ! n_ is not a file so take the previous one n_-1 ! 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),(/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),(/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 + moments_e(ip,ij,ikx,iky,:) = moments_e_cp(ip,ij,ikx,iky) ENDDO ENDDO ENDDO ENDDO 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 + moments_i(ip,ij,ikx,iky,:) = moments_i_cp(ip,ij,ikx,iky) ENDDO ENDDO ENDDO ENDDO ! Deallocate checkpoint arrays DEALLOCATE(moments_e_cp) DEALLOCATE(moments_i_cp) ! Read time dependent attributes to continue simulation CALL getatt(fidrst, dset_name, 'cstep', cstep) CALL getatt(fidrst, dset_name, 'time', time) CALL getatt(fidrst, dset_name, 'jobnum', jobnum) jobnum = jobnum+1 CALL getatt(fidrst, dset_name, 'iframe2d',iframe2d) CALL getatt(fidrst, dset_name, 'iframe5d',iframe5d) iframe2d = iframe2d-1; iframe5d = iframe5d-1 CALL closef(fidrst) IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Reading from restart file "//TRIM(rstfile)//" completed!" END SUBROUTINE load_output_adapt_pj !******************************************************************************! !******************************************************************************! !!!!!!! Load moments from a previous save !******************************************************************************! SUBROUTINE load_cp IMPLICIT NONE ! Checkpoint filename WRITE(rstfile,'(a,a1,i2.2,a3)') TRIM(rstfile0),'_',job2load,'.h5' IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Resume from previous run" ! Open file CALL openf(rstfile, fidrst,mpicomm=MPI_COMM_WORLD) ! Get the checkpoint moments degrees to allocate memory CALL getatt(fidrst,"/Basic/moments_e/" , "pmaxe", pmaxe_cp) CALL getatt(fidrst,"/Basic/moments_e/" , "jmaxe", jmaxe_cp) CALL getatt(fidrst,"/Basic/moments_i/" , "pmaxi", pmaxi_cp) CALL getatt(fidrst,"/Basic/moments_i/" , "jmaxi", jmaxi_cp) IF (my_id .EQ. 0) WRITE(*,*) "Pe_cp = ", pmaxe_cp 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) + CALL allocate_array(moments_i_cp, 1,pmaxi_cp+1, 1,jmaxi_cp+1, ikxs,ikxe, ikys,ikye) ! 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 DO WHILE (isdataset(fidrst, dset_name)) ! If n_ is not a file we stop the loop n_ = n_ + 1 WRITE(dset_name, "(A, '/', i6.6)") "/Basic/moments_e", n_ ! updtate file number ENDDO n_ = n_ - 1 ! n_ is not a file so take the previous one n_-1 ! 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),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),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),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 + moments_e(ip,ij,ikx,iky,:) = moments_e_cp(ip,ij,ikx,iky) ENDDO ENDDO ENDDO ENDDO 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 + moments_i(ip,ij,ikx,iky,:) = moments_i_cp(ip,ij,ikx,iky) ENDDO ENDDO ENDDO ENDDO ! Deallocate checkpoint arrays DEALLOCATE(moments_e_cp) DEALLOCATE(moments_i_cp) ! Read time dependent attributes to continue simulation CALL getatt(fidrst, dset_name, 'cstep', cstep) CALL getatt(fidrst, dset_name, 'time', time) CALL getatt(fidrst, dset_name, 'jobnum', jobnum) jobnum = jobnum+1 CALL getatt(fidrst, dset_name, 'iframe2d',iframe2d) CALL getatt(fidrst, dset_name, 'iframe5d',iframe5d) iframe2d = iframe2d-1; iframe5d = iframe5d-1 CALL closef(fidrst) IF (my_id .EQ. 0) WRITE(*,'(3x,a)') "Reading from restart file "//TRIM(rstfile)//" completed!" END SUBROUTINE load_cp !******************************************************************************! END MODULE restarts diff --git a/src/stepon.F90 b/src/stepon.F90 index 2ef08ca..c11ca76 100644 --- a/src/stepon.F90 +++ b/src/stepon.F90 @@ -1,134 +1,134 @@ SUBROUTINE stepon ! Advance one time step, (num_step=4 for Runge Kutta 4 scheme) USE advance_field_routine, ONLY: advance_time_level, advance_field, advance_moments USE array , ONLY: moments_rhs_e, moments_rhs_i, Sepj, Sipj USE basic USE closure USE collision, ONLY : compute_TColl USE fields, ONLY: moments_e, moments_i, phi USE ghosts USE grid USE model use prec_const USE time_integration USE utility, ONLY: checkfield IMPLICIT NONE INTEGER :: num_step LOGICAL :: mlend DO num_step=1,ntimelevel ! eg RK4 compute successively k1, k2, k3, k4 !----- BEFORE: All fields are updated for step = n ! Compute right hand side from current fields ! N_rhs(N_n,phi_n, S_n, Tcoll_n) CALL moments_eq_rhs_e CALL moments_eq_rhs_i ! ---- step n -> n+1 transition ! Advance from updatetlevel to updatetlevel+1 (according to num. scheme) CALL advance_time_level ! Update moments with the hierarchy RHS (step by step) ! N_n+1 = N_n + N_rhs(n) CALL advance_moments ! Closure enforcement of N_n+1 CALL apply_closure_model ! Exchanges the ghosts values of N_n+1 CALL update_ghosts ! Update collision C_n+1 = C(N_n+1) CALL compute_TColl ! Update electrostatic potential phi_n = phi(N_n+1) CALL poisson ! Update nonlinear term S_n -> S_n+1(phi_n+1,N_n+1) IF ( NON_LIN ) THEN CALL compute_Sapj ENDIF !- Check before next step CALL checkfield_all() IF( nlend ) EXIT ! exit do loop CALL MPI_BARRIER(MPI_COMM_WORLD,ierr) !----- AFTER: All fields are updated for step = n+1 END DO CONTAINS SUBROUTINE checkfield_all ! Check all the fields for inf or nan ! 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') 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') ENDDO ENDDO CALL MPI_ALLREDUCE(mlend, nlend, 1, MPI_LOGICAL, MPI_LOR, MPI_COMM_WORLD, ierr) ENDIF ! Execution time end CALL cpu_time(t1_checkfield) tc_checkfield = tc_checkfield + (t1_checkfield - t0_checkfield) END SUBROUTINE checkfield_all 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 + moments_e( ip,ij,ikx,iky,:) = AA_x(ikx)* AA_y(iky) * moments_e( ip,ij,ikx,iky,:) 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 + moments_i( ip,ij,ikx,iky,:) = AA_x(ikx)* AA_y(iky) * moments_i( ip,ij,ikx,iky,:) END DO END DO END DO END DO 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 iky=2,Nky/2 !symmetry at kx = 0 + moments_e( ip,ij,ikx_0,iky, :) = CONJG(moments_e( ip,ij,ikx_0,Nky+2-iky, :)) END DO ! must be real at origin - moments_e(ip,ij, ikr_0,ikz_0, :) = REAL(moments_e(ip,ij, ikr_0,ikz_0, :)) + moments_e(ip,ij, ikx_0,iky_0, :) = REAL(moments_e(ip,ij, ikx_0,iky_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 iky=2,Nky/2 !symmetry at kx = 0 + moments_i( ip,ij,ikx_0,iky, :) = CONJG(moments_i( ip,ij,ikx_0,Nky+2-iky, :)) 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, :)) + moments_i(ip,ij, ikx_0,iky_0, :) = REAL(moments_i(ip,ij, ikx_0,iky_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 END SUBROUTINE stepon diff --git a/src/utility_mod.F90 b/src/utility_mod.F90 index b044ce6..3a95deb 100644 --- a/src/utility_mod.F90 +++ b/src/utility_mod.F90 @@ -1,111 +1,111 @@ MODULE utility USE basic use prec_const IMPLICIT NONE PUBLIC :: manual_2D_bcast CONTAINS FUNCTION is_nan(x,str) RESULT(isn) USE time_integration use prec_const IMPLICIT NONE real(dp), INTENT(IN) :: x CHARACTER(LEN=*), INTENT(IN) :: str LOGICAL :: isn isn=.FALSE. IF(x .NE. x) THEN isn=.TRUE. END IF IF((isn).AND.(str.NE.'')) THEN WRITE(*,'(a20,a25,i6.6,a20,i1)') str,' = NaN at timestep',cstep, ' and substep',updatetlevel CALL FLUSH(stdout) END IF END FUNCTION is_nan FUNCTION is_inf(x,str) RESULT(isi) USE time_integration use prec_const IMPLICIT NONE real(dp), INTENT(IN) :: x CHARACTER(LEN=*), INTENT(IN) :: str LOGICAL :: isi isi=.FALSE. IF(x+1.0== x) THEN isi=.TRUE. END IF IF((isi).AND.(str.NE.'')) THEN !WRITE(*,'(a20,a25,i6.6,a20,i1)') str,' = Inf at timestep',cstep, ' and substep',updatetlevel CALL FLUSH(stdout) END IF END FUNCTION is_inf FUNCTION checkfield(field,str) RESULT(mlend) USE grid 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 sumfield=SUM(field) mlend= is_nan( REAL(sumfield),str).OR.is_inf( REAL(sumfield),str) & .OR. is_nan(AIMAG(sumfield),str).OR.is_inf(AIMAG(sumfield),str) END FUNCTION checkfield !!!!! This is a manual way to do MPI_BCAST !!!!!!!!!!! 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) 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 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 END MODULE utility diff --git a/wk/ZF_fourier_analysis.m b/wk/ZF_fourier_analysis.m index 7c37eca..da4cf87 100644 --- a/wk/ZF_fourier_analysis.m +++ b/wk/ZF_fourier_analysis.m @@ -1,103 +1,103 @@ %% Zonal flow spectral analysis fig = figure; FIGNAME = ['zonal_flow_spectral_analysis_',PARAMS]; tend = Ts0D(end); tstart = tend-TAVG ; [~,its0D] = min(abs(Ts0D-tstart)); [~,ite0D] = min(abs(Ts0D-tend)); [~,its2D] = min(abs(Ts2D-tstart)); [~,ite2D] = min(abs(Ts2D-tend)); 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; Freq = (samplerate / n * (1:n))'; Pot(1) = 0; nmax = min(20,round(n/2)); [amax, itmax] = max(Pot); plot((0:nmax-1) , Pot(1:nmax)/amax,'DisplayName','$\Gamma_r(\omega)$');hold on; plot([itmax-1,itmax-1],[0,1],'--k', 'DisplayName',['$T_{per}\approx',num2str(round(1/Freq(itmax))),'L_\perp/c_s$']); legend('show'); grid on; box on; xlabel('Period number'); yticks([]); title('$\Gamma_r$ temporal spectrum') % Space analysis (spatial period of ZF) subplot(122) nmax = 20; n = numel(r); [TT,NN] = meshgrid(Ts2D(its2D:ite2D),0:n-1); Pot = NN; for it = 1:ite2D-its2D+1 Y = mean(real(drphi(:,:,it)),2); Yy = fft(Y); [n,~] = size(Yy); Pot(:,it) = Yy .* conj(Yy) / n; end [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+KR.^2+KZ.^2).*abs(PHI(:,:,it)).^2))- sum((1+kr.^2).*abs(PHI(:,1,it)).^2); - E_ZF(it) = kr(ikZF)^2*abs(PHI(ikZF,1,it)).^2; + 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,'.',... 'DisplayName',PARAMS); cbar = colorbar;ylabel(cbar,'$t c_s/\rho_s$','Interpreter','LaTeX') hold on % xlabel('$\langle \phi \rangle_z^r$'); ylabel('$\langle dV_E/dr \rangle_z^r$') xlabel('$E_v$'); ylabel('$N$') grid on; title('ES pot. vs Shear phase space') % plot(phi_avgr_maxz(its2D:ite2D),shear_avgr_maxz(its2D:ite2D),'-') % plot(phi_maxr_maxz(its2D:ite2D),shear_maxr_maxz(its2D:ite2D),'-') % plot(phi_avgr_avgz(its2D:ite2D),shear_avgr_avgz(its2D:ite2D),'-') save_figure clear x_ y_ if 0 %% density and phi phase space fig = figure; FIGNAME = ['phi_ni_phase_space_',PARAMS]; set(gcf, 'Position', [100, 100, 700, 500]) t1 = Ts2D(end); t0 = 0; [~,its2D] = min(abs(Ts2D-t0)); [~,ite2D] = min(abs(Ts2D-t1)); scatter3(max(mean(ni00(:,:,its2D:ite2D),2),[],1),phi_maxr_avgz(its2D:ite2D),shear_maxr_avgz(its2D:ite2D),35,Ts2D(its2D:ite2D),'.',... 'DisplayName',PARAMS); cbar = colorbar;ylabel(cbar,'$t c_s/\rho_s$','Interpreter','LaTeX') hold on xlabel('$\langle n_i^{00} \rangle_z^r$'); ylabel('$\langle \phi \rangle_z^r$'); zlabel('$\langle dV_E/dr \rangle_z^r$') grid on; title('ES pot. vs Shear phase space') % plot(phi_avgr_maxz(its2D:ite2D),shear_avgr_maxz(its2D:ite2D),'-') % plot(phi_maxr_maxz(its2D:ite2D),shear_maxr_maxz(its2D:ite2D),'-') % plot(phi_avgr_avgz(its2D:ite2D),shear_avgr_avgz(its2D:ite2D),'-') % save_figure end %% Non zonal quantities 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; [~, it02D] = min(abs(Ts2D-t0)); [~, it05D] = min(abs(Ts5D-t0)); skip_ = 10; DELAY = 0.005*skip_; FRAMES_2D = it02D:skip_:numel(Ts2D); 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 9076e85..bcfffa5 100644 --- a/wk/analysis_1D.m +++ b/wk/analysis_1D.m @@ -1,233 +1,233 @@ default_plots_options %% load resulTs2D JOBNUM = 00; load_results Ni00 = squeeze(Ni00); Ne00 = squeeze(Ne00); PHI = squeeze(PHI); 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 % Post processing ne_00 = zeros(1,Ns); % Time evolution of ne(r,z) at origin ni_00 = zeros(1,Ns); % . phi_00 = zeros(1,Ns); % . 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)); ne_00(it) = ne00(iz0,it); ni_00(it) = ni00(iz0,it); 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)); gamma_PH = real(gamma_PH .* (gamma_PH>=0.0)); %% PLOTs2D if 0 %% Time evolutions fig = figure; FIGNAME = ['t_evolutions',sprintf('_%.2d',JOBNUM)]; subplot(221) semilogy(Ts2D,abs(ne_00),'-','DisplayName','$n_e^{00}$'); hold on; semilogy(Ts2D,abs(ni_00),'-','DisplayName','$n_i^{00}$'); grid on; xlabel('$t$'); ylabel('$|n_a(x=0,y=0)|$'); subplot(222) semilogy(Ts2D,abs(Ni_gm),'-','DisplayName','$\phi$') grid on; xlabel('$t$'); ylabel('$|\tilde n(k_r\approx 1,k_z\approx 1)|$'); subplot(223) semilogy(Ts2D,E_kin+E_pot,'-','DisplayName','$\sum|ik\tilde\phi_i|^2+\sum|\tilde n_i|^2$') hold on; grid on; xlabel('$t$'); ylabel('$E$'); legend('show'); FMT = '.fig'; save_figure 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 %% GIFS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t0 = 0; skip_ = 1; DELAY = 0.01*skip_; FRAMES = floor(t0/dt_samp)+1:skip_:numel(Ts2D); linestyle = 'o-.'; if 0 %% Density electron GIFNAME = ['ne',sprintf('_%.2d',JOBNUM)]; FIELD = real(ne00); X = z; T = Ts2D; FIELDNAME = '$n_e^{00}/\max(n_e^{00})$'; XNAME = '$z$'; XMIN = -L/2-2; XMAX = L/2+1; YMIN = -1.1; YMAX = 1.1; create_gif_1D %% Density ion GIFNAME = ['ni',sprintf('_%.2d',JOBNUM)]; FIELD = real(ni00); X = z; T = Ts2D; FIELDNAME = '$n_i^{00}/\max(n_i^{00})$'; XNAME = '$z$'; XMIN = -L/2-2; XMAX = L/2+1; YMIN = -1.1; YMAX = 1.1; create_gif_1D %% Phi GIFNAME = ['phi',sprintf('_%.2d',JOBNUM)]; FIELD = real(phi); X = z; T = Ts2D; FIELDNAME = '$\phi/\max(\phi)$'; XNAME = '$z$'; 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 if 0 %% Space-Time diagrams at r = 0 plt = @(x) real(x); fig = figure; FIGNAME = ['z_space_time_diag',sprintf('_%.2d',JOBNUM)]; [TY,TX] = meshgrid(Ts2D,z); subplot(221)% density pclr = pcolor(TX,TY,(plt(ne00))); set(pclr, 'edgecolor','none'); colorbar; xlabel('$z\,(r=0)$'); ylabel('$t$'); title('$n_e^{00}$'); subplot(222)% density pclr = pcolor(TX,TY,(plt(ni00))); set(pclr, 'edgecolor','none'); colorbar; xlabel('$z\,(r=0)$'); ylabel('$t$'); title('$n_i^{00}$'); subplot(223)% density pclr = pcolor(TX,TY,(plt(phi))); set(pclr, 'edgecolor','none'); colorbar; 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)); semilogy(Ts2D,plt(PHI(ik05,:)),'DisplayName', '$k_z = 0.5$'); hold on semilogy(Ts2D,plt(PHI(ik10,:)),'DisplayName', '$k_z = 1.0$') semilogy(Ts2D,plt(PHI(ik15,:)),'DisplayName', '$k_z = 1.5$') semilogy(Ts2D,plt(PHI(ik20,:)),'DisplayName', '$k_z = 2.0$') xlabel('$t$'); ylabel('$|\tilde\phi|$'); legend('show'); semilogy(Ts2D,plt(PHI(ik05,end)).*exp(gamma_PH(ik05).*(Ts2D-Ts2D(end))),'--k') semilogy(Ts2D,plt(PHI(ik10,end)).*exp(gamma_PH(ik10).*(Ts2D-Ts2D(end))),'--k') plot(tstart*[1 1],ylim,'k-','LineWidth',0.5); plot(tend*[1 1],ylim,'k-','LineWidth',0.5); subplot(222); plt = @(x) squeeze(abs(x)); semilogy(Ts2D,plt(Ni00(ik05,:)),'DisplayName', '$k_z = 0.5$'); hold on semilogy(Ts2D,plt(Ni00(ik10,:)),'DisplayName', '$k_z = 1.0$') semilogy(Ts2D,plt(Ni00(ik15,:)),'DisplayName', '$k_z = 1.5$') semilogy(Ts2D,plt(Ni00(ik20,:)),'DisplayName', '$k_z = 2.0$') xlabel('$t$'); ylabel('$|N_i^{00}|$'); legend('show'); semilogy(Ts2D,plt(Ni00(ik05,end)).*exp(gamma_Ni(ik05).*(Ts2D-Ts2D(end))),'--k') semilogy(Ts2D,plt(Ni00(ik10,end)).*exp(gamma_Ni(ik10).*(Ts2D-Ts2D(end))),'--k') plot(tstart*[1 1],ylim,'k-','LineWidth',0.5); plot(tend*[1 1],ylim,'k-','LineWidth',0.5); subplot(223); plt = @(x) squeeze(abs(x)); semilogy(Ts2D,plt(Ne00(ik05,:)),'DisplayName', '$k_z = 0.5$'); hold on semilogy(Ts2D,plt(Ne00(ik10,:)),'DisplayName', '$k_z = 1.0$') semilogy(Ts2D,plt(Ne00(ik15,:)),'DisplayName', '$k_z = 1.5$') semilogy(Ts2D,plt(Ne00(ik20,:)),'DisplayName', '$k_z = 2.0$') xlabel('$t$'); ylabel('$|N_e^{00}|$'); legend('show'); semilogy(Ts2D,plt(Ne00(ik05,end)).*exp(gamma_Ne(ik05).*(Ts2D-Ts2D(end))),'--k') semilogy(Ts2D,plt(Ne00(ik10,end)).*exp(gamma_Ne(ik10).*(Ts2D-Ts2D(end))),'--k') plot(tstart*[1 1],ylim,'k-','LineWidth',0.5); plot(tend*[1 1],ylim,'k-','LineWidth',0.5); FMT = '.fig'; save_figure end if 0 %% Show frame 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 e1896cb..50a4038 100644 --- a/wk/analysis_2D.m +++ b/wk/analysis_2D.m @@ -1,604 +1,599 @@ addpath(genpath('../matlab')) % ... add for i_ = 1 % for ETA_ =[0.6:0.1:0.9] %% Load results if 0% Local results outfile =''; outfile =''; outfile =''; outfile =''; -outfile ='kobayashi/100x50_L_50_P_2_J_1_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00'; -% outfile ='kobayashi/100x50_L_50_P_2_J_1_eta_0.71429_nu_1e-02_PAGK_CLOS_0_mu_0e+00'; -% outfile ='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'; +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); end if 1% Marconi results outfile =''; outfile =''; -outfile =''; -outfile =''; -outfile =''; -outfile ='/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'; +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),'/']; BASIC.MISCDIR = ['/misc/HeLaZ_outputs/',outfile(46:end-8),'/']; end %% % JOBNUM = 1; load_results; JOBNUMMAX = 20; compile_results %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); Ns2D = numel(Ts2D); % renaming and reshaping quantity of interest 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); +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); 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))); + 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))); if shift > err; err = shift; end; PHI_Ts5D(:,:,it) = PHI(:,:,it2D); 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))); 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)),Nr,Nz))); + 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_ri = zeros(1,Ns2D); % Gyrocenter flux Gamma = GFlux_zi = zeros(1,Ns2D); % Gyrocenter flux Gamma = GFlux_re = zeros(1,Ns2D); % Gyrocenter flux Gamma = GFlux_ze = zeros(1,Ns2D); % Gyrocenter flux Gamma = 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 epsilon_e_pj = zeros(Pe_max,Je_max,Ns5D); epsilon_i_pj = zeros(Pi_max,Ji_max,Ns5D); phi_maxr_maxz = zeros(1,Ns2D); % Time evol. of the norm of phi phi_avgr_maxz = zeros(1,Ns2D); % Time evol. of the norm of phi phi_maxr_avgz = zeros(1,Ns2D); % Time evol. of the norm of phi phi_avgr_avgz = zeros(1,Ns2D); % Time evol. of the norm of phi shear_maxr_maxz = zeros(1,Ns2D); % Time evol. of the norm of shear shear_avgr_maxz = zeros(1,Ns2D); % Time evol. of the norm of shear shear_maxr_avgz = zeros(1,Ns2D); % Time evol. of the norm of shear 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 NE_ = Ne00(:,:,it); NI_ = Ni00(:,:,it); PH_ = PHI(:,:,it); phi_maxr_maxz(it) = max( max(squeeze(phi(:,:,it)))); phi_avgr_maxz(it) = max(mean(squeeze(phi(:,:,it)))); phi_maxr_avgz(it) = mean( max(squeeze(phi(:,:,it)))); phi_avgr_avgz(it) = mean(mean(squeeze(phi(:,:,it)))); shear_maxr_maxz(it) = max( max(squeeze(-(dr2phi(:,:,it))))); shear_avgr_maxz(it) = max(mean(squeeze(-(dr2phi(:,:,it))))); 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); 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 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_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 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/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; end subplot(shearplot) clr = line_colors(min(ip,numel(line_colors(:,1))),:); lstyle = line_styles(min(ij,numel(line_styles))); plot(Ts2D,shear_maxr_maxz,'DisplayName','$\max_{r,z}(s)$'); hold on; plot(Ts2D,shear_maxr_avgz,'DisplayName','$\max_{r}\langle s \rangle_z$'); hold on; plot(Ts2D,shear_avgr_maxz,'DisplayName','$\max_{z}\langle s \rangle_r$'); hold on; plot(Ts2D,shear_avgr_avgz,'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(Ts2D,phi_maxr_maxz,'DisplayName','$\max_{r,z}(\phi)$'); hold on; plot(Ts2D,phi_maxr_avgz,'DisplayName','$\max_{r}\langle\phi\rangle_z$'); hold on; plot(Ts2D,phi_avgr_maxz,'DisplayName','$\max_{z}\langle\phi\rangle_r$'); hold on; plot(Ts2D,phi_avgr_avgz,'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 = 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 tend = Ts2D(end); tstart = tend - TAVG; [~,its2D] = min(abs(Ts2D-tstart)); [~,ite2D] = min(abs(Ts2D-tend)); shear_infty_avg = mean(shear_maxr_avgz(its2D:ite2D)); shear_infty_std = std (shear_maxr_avgz(its2D:ite2D)); Q_infty_avg = mean(Q_RI(its2D:ite2D))*SCALE; 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 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 % 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(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; pclr = pcolor(TX,TY,squeeze(mean(dr2phi(:,:,:),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('$r/\rho_s$'); colormap(bluewhitered(256)) save_figure end if 1 %% Space time diagramms tstart = 0; tend = Ts2D(end); [~,itstart] = min(abs(Ts2D-tstart)); [~,itend] = min(abs(Ts2D-tend)); 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$') % legend('Radial part. transport $\langle n_i\partial_z\phi\rangle_z$') - 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)]); % 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(Nr),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... +% ', $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 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('$r/\rho_s$'); grid on; legend('show') end if 1 %% |phi_k|^2 spectra (Kobayashi 2015 fig 3) -tstart = 4000; tend = 4000; +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); 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_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)]}); 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_ = 1; +skip_ = 4; DELAY = 1e-3*skip_; FRAMES_2D = it02D:skip_:numel(Ts2D); FRAMES_5D = it05D:skip_:numel(Ts5D); %% GIFS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if 0 %% part density electron GIFNAME = ['ne',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(dens_e); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$n_e$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif % create_mov end if 0 %% part temperature electron GIFNAME = ['Te',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(temp_e); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$T_e$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif % create_mov end if 0 %% part density ion GIFNAME = ['ni',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(dens_i); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$n_i$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif % create_mov end if 0 %% part temperature ion GIFNAME = ['Ti',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(temp_i); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$T_i$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif % create_mov end if 0 %% GC Density ion GIFNAME = ['ni00',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(ni00); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$n_i^{00}$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; -% create_gif -create_mov +create_gif +% create_mov end if 0 %% GC Density electrons GIFNAME = ['ne00',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; FIELD = real(ne00); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$n_e^{00}$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; % create_gif create_mov end if 0 %% Phi real space GIFNAME = ['phi',sprintf('_%.2d',JOBNUM),'_',PARAMS];INTERP = 0; FIELD = real(phi); X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$\phi$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif % create_mov end if 0 %% shear GIFNAME = ['shear_r',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 1; FIELD = -dr2phi; X = RR; Y = ZZ; T = Ts2D; FRAMES = FRAMES_2D; FIELDNAME = '$s$'; XNAME = '$r/\rho_s$'; YNAME = '$z/\rho_s$'; create_gif end if 0 %% phi averaged on z GIFNAME = ['phi_z0',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; SCALING=1; FIELD =(squeeze(mean(real(phi),2))); linestyle = '-.k'; FRAMES = FRAMES_2D; X = (r); T = Ts2D; YMIN = -1.1; YMAX = 1.1; XMIN = min(r); XMAX = max(r); FIELDNAME = '$\langle\phi\rangle_{z}$'; XNAME = '$r/\rho_s$'; create_gif_1D_phi end if 0 %% flow averaged on z GIFNAME = ['zf_z0',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; SCALING=1; FIELD =(squeeze(mean(real(drphi),2))); linestyle = '-.k'; FRAMES = FRAMES_2D; X = (r); T = Ts2D; YMIN = -1.1; YMAX = 1.1; XMIN = min(r); XMAX = max(r); FIELDNAME = '$\langle\phi\rangle_{z}$'; XNAME = '$r/\rho_s$'; create_gif_1D_phi end if 0 %% shear averaged on z GIFNAME = ['shear_z0',sprintf('_%.2d',JOBNUM),'_',PARAMS]; INTERP = 0; SCALING=1; FIELD =(squeeze(mean(real(dr2phi),2))); linestyle = '-.k'; FRAMES = FRAMES_2D; X = (r); T = Ts2D; YMIN = -1.1; YMAX = 1.1; XMIN = min(r); XMAX = max(r); FIELDNAME = '$\langle\phi\rangle_{z}$'; XNAME = '$r/\rho_s$'; create_gif_1D_phi end 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 end \ No newline at end of file diff --git a/wk/compile_cosolver_mat.m b/wk/compile_cosolver_mat.m index 983d661..7b2310d 100644 --- a/wk/compile_cosolver_mat.m +++ b/wk/compile_cosolver_mat.m @@ -1,137 +1,137 @@ 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 % ! 0 = nothing % ! 1 = coulomb % ! 2 = pitch-angle (with constant coll.freq.) % ! 3 = sugama % ! 4 = pitch-angle with veloty dependent coll. freq. % ! 5 = improved sugama % ! 6 = Hirschman-Sigmar Clarke % ! 7 = Abel (only for like species) % ! 8 = conserving momentun pitch-angle operator (with veloty dependent coll. freq.) % ! 9 = GK coulomb polarization term CO = 3; GK = 1; P = 10; J = 5; M_FLR= 0; %to increase the NFLR if 0 %% plot the kperp distribution figure plot(kperp) end % %% Check if the differences btw kperp is larger than naming precision %% %% We compute only on a kperp grid with dk space from 0 to kperpmax kperpmax = sqrt(2) * kmax; kperp = unique([0:dk:kperpmax,kperpmax]); %% Naming if CO == 1; CONAME = 'FC'; end; if CO == 2; CONAME = 'PA'; end; if CO == 3; CONAME = 'SG'; end; % matfilename = ['../iCa/',CONAME,'_P_',num2str(P),'_J_',num2str(J),... % '_N_',num2str(N),'_dk_',num2str(dk),'_MFLR_',num2str(M_FLR),'.h5']; matfilename = '../iCa/gk_sugama_P_10_J_5.h5'; n_ = 0; for k_ = kperp disp(['-Writing matrices for kperp = ',num2str(k_)]) %% Script to run COSOlver in order to create needed collision matrices COSOlver_path = '../../Documents/MoliSolver/COSOlver/'; COSOLVER.pmaxe = P; COSOLVER.jmaxe = J; COSOLVER.pmaxi = P; COSOLVER.jmaxi = J; COSOLVER.kperp = k_; COSOLVER.neFLR = min(ceil((2/3*kperpmax)^2),max(5,ceil(COSOLVER.kperp^2)))+M_FLR; % rule of thumb for sum truncation COSOLVER.niFLR = min(ceil((2/3*kperpmax)^2),max(5,ceil(COSOLVER.kperp^2)))+M_FLR; COSOLVER.idxT4max = 40; COSOLVER.neFLRs = 0; % ... only for GK abel COSOLVER.npeFLR = 0; % ... only for GK abel COSOLVER.niFLRs = 0; % ... only for GK abel COSOLVER.npiFLR = 0; % ... only for GK abel COSOLVER.gk = GK; COSOLVER.co = CO; k_string = sprintf('%0.4f',k_); n_string = sprintf('%0.5d',n_); self_mat_file_name = ['../iCa/self_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ESELF_',num2str(COSOLVER.co),'_ISELF_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12',... '_NFLR_',num2str(COSOLVER.neFLR),... '_kperp_',k_string,'.h5']; ei_mat_file_name = ['../iCa/ei_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ETEST_',num2str(COSOLVER.co),'_EBACK_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12_tau_1.0000_mu_0.0233',... '_NFLRe_',num2str(COSOLVER.neFLR),'_NFLRi_',num2str(COSOLVER.neFLR)... '_kperp_',k_string,'.h5']; ie_mat_file_name = ['../iCa/ie_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ITEST_',num2str(COSOLVER.co),'_IBACK_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12_tau_1.0000_mu_0.0233',... '_NFLRe_',num2str(COSOLVER.neFLR),'_NFLRi_',num2str(COSOLVER.neFLR)... '_kperp_',k_string,'.h5']; %% Load self matrix C_self = h5read(self_mat_file_name,'/Caapj/Ceepj'); sz_ = size(C_self); % Write it in the compiled file h5create(matfilename,['/',n_string,'/Caapj/Ceepj'],sz_) h5write (matfilename,['/',n_string,'/Caapj/Ceepj'],C_self) h5create(matfilename,['/',n_string,'/Caapj/Ciipj'],sz_) h5write (matfilename,['/',n_string,'/Caapj/Ciipj'],C_self) %% Load ei matrices % Field C_eiF = h5read(ei_mat_file_name,'/Ceipj/CeipjF'); sz_ = size(C_eiF); h5create(matfilename,['/',n_string,'/Ceipj/CeipjF'],sz_) h5write (matfilename,['/',n_string,'/Ceipj/CeipjF'],C_eiF) % Test C_eiT = h5read(ei_mat_file_name,'/Ceipj/CeipjT'); sz_ = size(C_eiT); h5create(matfilename,['/',n_string,'/Ceipj/CeipjT'],sz_) h5write (matfilename,['/',n_string,'/Ceipj/CeipjT'],C_eiT) %% Load ie matrices % Field C_ieF = h5read(ie_mat_file_name,'/Ciepj/CiepjF'); sz_ = size(C_ieF); h5create(matfilename,['/',n_string,'/Ciepj/CiepjF'],sz_) h5write (matfilename,['/',n_string,'/Ciepj/CiepjF'],C_ieF) % Test C_ieT = h5read(ie_mat_file_name,'/Ciepj/CiepjT'); sz_ = size(C_eiT); h5create(matfilename,['/',n_string,'/Ciepj/CiepjT'],sz_) h5write (matfilename,['/',n_string,'/Ciepj/CiepjT'],C_ieT) %% Copy fort.90 input file and put grid params if(k_ == 0) h5create(matfilename,'/coordkperp',numel(kperp)); h5write (matfilename,'/coordkperp',kperp); h5create(matfilename,'/dims_e',2); h5write (matfilename,'/dims_e',[P,J]); h5create(matfilename,'/dims_i',2); h5write (matfilename,'/dims_i',[P,J]); end n_ = n_ + 1; end disp(['File saved @ :',matfilename]) \ No newline at end of file diff --git a/wk/compute_collision_mat.m b/wk/compute_collision_mat.m index a429236..ac5214c 100644 --- a/wk/compute_collision_mat.m +++ b/wk/compute_collision_mat.m @@ -1,99 +1,99 @@ 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 % ! 0 = nothing % ! 1 = coulomb % ! 2 = pitch-angle (with constant coll.freq.) % ! 3 = sugama % ! 4 = pitch-angle with veloty dependent coll. freq. % ! 5 = improved sugama % ! 6 = Hirschman-Sigmar Clarke % ! 7 = Abel (only for like species) % ! 8 = conserving momentun pitch-angle operator (with veloty dependent coll. freq.) % ! 9 = GK coulomb polarization term CO = 3; GK = 1; %% %% We compute only on a kperp grid with dk space from 0 to kperpmax kperpmax = sqrt(2) * kmax; kperp = unique([0:dk:kperpmax,kperpmax]); %% %% If DK collision, compute only kperp = 0 if (GK == 0); kperp = 0; end; %% Kperp scan n_ = 1; for k_ = kperp disp(['----------Computing matrix ',num2str(n_),'/',num2str(numel(kperp)),'----------']) %% Script to run COSOlver in order to create needed collision matrices COSOlver_path = '../../Documents/MoliSolver/COSOlver/'; COSOLVER.pmaxe = 10; COSOLVER.jmaxe = 05; COSOLVER.pmaxi = 10; COSOLVER.jmaxi = 05; COSOLVER.kperp = k_; COSOLVER.neFLR = min(ceil((2/3*kperpmax)^2),max(5,ceil(COSOLVER.kperp^2))); % rule of thumb for sum truncation COSOLVER.niFLR = min(ceil((2/3*kperpmax)^2),max(5,ceil(COSOLVER.kperp^2))); COSOLVER.idxT4max = 40; COSOLVER.neFLRs = 0; % ... only for GK abel COSOLVER.npeFLR = 0; % ... only for GK abel COSOLVER.niFLRs = 0; % ... only for GK abel COSOLVER.npiFLR = 0; % ... only for GK abel COSOLVER.gk = GK; COSOLVER.co = CO; write_fort90_COSOlver k_string = sprintf('%0.4f',k_); self_mat_file_name = ['../iCa/self_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ESELF_',num2str(COSOLVER.co),'_ISELF_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12',... '_NFLR_',num2str(COSOLVER.neFLR),... '_kperp_',k_string,'.h5']; ei_mat_file_name = ['../iCa/ei_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ETEST_',num2str(COSOLVER.co),'_EBACK_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12_tau_1.0000_mu_0.0233',... '_NFLRe_',num2str(COSOLVER.neFLR),'_NFLRi_',num2str(COSOLVER.neFLR)... '_kperp_',k_string,'.h5']; ie_mat_file_name = ['../iCa/ie_Coll_GKE_',num2str(COSOLVER.gk),'_GKI_',num2str(COSOLVER.gk),... '_ITEST_',num2str(COSOLVER.co),'_IBACK_',num2str(COSOLVER.co),... '_Pmaxe_',num2str(COSOLVER.pmaxe),'_Jmaxe_',num2str(COSOLVER.jmaxe),... '_Pmaxi_',num2str(COSOLVER.pmaxi),'_Jmaxi_',num2str(COSOLVER.jmaxi),... '_JE_12_tau_1.0000_mu_0.0233',... '_NFLRe_',num2str(COSOLVER.neFLR),'_NFLRi_',num2str(COSOLVER.neFLR)... '_kperp_',k_string,'.h5']; % if (exist(self_mat_file_name,'file')>0 && exist(ei_mat_file_name,'file')>0 && exist(ie_mat_file_name,'file') > 0) if (exist(ei_mat_file_name,'file')>0)%&& exist(ie_mat_file_name,'file') > 0) disp(['Matrix available for kperp = ',k_string]); else cd ../../Documents/MoliSolver/COSOlver/ disp(['Matrix not found for kperp = ',k_string]); disp([num2str(n_),'/',Nperp]) disp('computing...'); CMD = 'mpirun -np 6 bin/CO 2 2 2 > out.txt'; disp(CMD); system(CMD); system(CMD); disp('..done'); cd ../../../HeLaZ/wk end n_ = n_ + 1; end \ No newline at end of file diff --git a/wk/continue_multiple_runs_marconi.m b/wk/continue_multiple_runs_marconi.m index c2b825b..47f91c3 100644 --- a/wk/continue_multiple_runs_marconi.m +++ b/wk/continue_multiple_runs_marconi.m @@ -1,77 +1,89 @@ %% Paste the list of continue_run calls -continue_run('/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') +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) - EXECNAME = 'helaz_2.73'; + EXECNAME = 'helaz_2.8'; %% CLUSTER PARAMETERS CLUSTER.PART = 'prod'; % dbg or prod CLUSTER.TIME = '24:00:00'; % allocation time hh:mm:ss if(strcmp(CLUSTER.PART,'dbg')); CLUSTER.TIME = '00:30:00'; end; CLUSTER.MEM = '64GB'; % Memory CLUSTER.JNAME = 'HeLaZ';% Job name NP_P = 2; % MPI processes along p - NP_KR = 24; % MPI processes along kr + NP_KX = 24; % MPI processes along kx % 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 %% RESDIR = ['../',outfilename(46:end-8),'/']; BASIC.RESDIR = RESDIR; FORT90 = [RESDIR,'fort.90']; % Read txt into cell A fid = fopen(FORT90,'r'); i = 1; tline = fgetl(fid); A{i} = tline; while ischar(tline) i = i+1; tline = fgetl(fid); A{i} = tline; end fclose(fid); % Find previous job2load if( numel(A{5}) == numel(' RESTART = .false.') ) A{5} = sprintf(' RESTART = .true.'); J2L = 0; else line = A{35}; line = line(end-2:end); if(line(1) == '='); line = line(end); end; - J2L = str2num(line); + J2L = str2num(line) + 1; end % Change job 2 load in fort.90 - A{35} = [' job2load = ',num2str(0)]; + A{35} = [' job2load = ',num2str(J2L)]; disp(A{35}) % Change time step - A{3} = [' dt = 0.01']; + A{3} = [' dt = 0.005']; % Increase endtime A{4} = [' tmax = 10000']; % Put non linear term back A{41} = [' NL_CLOS = -1']; % change HD line_= A{43}; mu_old = str2num(line_(13:end)); - A{43} = [' mu = ',num2str(1e-3)]; - + A{43} = [' mu = ',num2str(mu_old*2)]; + % change L + 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)); + A{53} = [' eta_n = ',num2str(etan_old)]; + % change eta B + line_= A{55}; + etab_old = str2num(line_(13:end)); + A{55} = [' eta_B = ',num2str(etab_old)]; % Rewrite fort.90 fid = fopen('fort.90', 'w'); for i = 1:numel(A) if A{i+1} == -1 fprintf(fid,'%s', A{i}); break else fprintf(fid,'%s\n', A{i}); end end % Copy fort.90 into marconi write_sbash_marconi % Launch the job system('ssh ahoffman@login.marconi.cineca.it sh HeLaZ/wk/setup_and_run.sh'); end \ No newline at end of file diff --git a/wk/daint_run.m b/wk/daint_run.m index e7f53ac..95806c9 100644 --- a/wk/daint_run.m +++ b/wk/daint_run.m @@ -1,89 +1,89 @@ %clear all; addpath(genpath('../matlab')) % ... add %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 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 CLUSTER.JNAME = 'gamma_inf';% Job name %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS 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 MU_P = 0; % Hermite hyperdiffusivity -mu_p*(d/dvpar)^4 f MU_J = 0; % Laguerre hyperdiffusivity -mu_j*(d/dvperp)^4 f %% TIME PARAMETERS TMAX = 1000; % 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 SPS5D = 1/40; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints RESTART = 1; % To restart from last checkpoint JOB2LOAD= 2; %% OPTIONS SIMID = ['HeLaZ_v2.5_eta_',num2str(ETAB),'_nu_%0.0e']; % Name of the simulation % 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) NL_CLOS = 1; % nonlinear closure model (0: =0 nmax = jmax, 1: nmax = jmax-j, >1 : nmax = NL_CLOS) KERN = 0; % Kernel model (0 : GK) INIT_PHI= 1; % Start simulation with a noisy phi and moments %% OUTPUTS W_DOUBLE = 1; W_GAMMA = 1; W_PHI = 1; W_NA00 = 1; W_NAPJ = 1; 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 JMAXI = J; % Highest '' Laguerre '' kmax = N*pi/L;% Highest fourier mode HD_CO = 0.5; % Hyper diffusivity cutoff ratio MU = NU_HYP/(HD_CO*kmax)^4 % Hyperdiffusivity coefficient NOISE0 = 1.0e-5; 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 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 1479162..e51be52 100644 --- a/wk/fig_post_processing.m +++ b/wk/fig_post_processing.m @@ -1,78 +1,78 @@ %% Load figure figpath = 'C:\Users\antoi\Desktop\gamma_eta_05_nu_1e-01_trunc'; fig = openfig(figpath); %% Load data axObjs = fig.Children; dataObjs = findobj(fig,'-property','YData'); Nlines = numel(dataObjs); %% Post processing sigma = zeros(Nlines,1); mu = sigma; tmin = 350; for i = 1:Nlines x = dataObjs(i).XData; [~, itmin] = min(abs(tmin-x)); y = dataObjs(i).YData; sigma(i) = std(y(itmin:end)); mu(i) = mean(y(itmin:end)); end mu = flip(mu') sigma = flip(sigma') %% Plot mean with error bar if 0 %% Handwritten results for nu = 1.0, 150x75, L=100, DGGK Results_150x75.Gamma = [0.3794 0.3194 0.3226, 0.0098 0.0221 0.0321 0.0400 0.2897 0.2886 0.2569 0.0104 0.0086 0.0276 0.0320 0.1375 0.1633 0.0848]; Results_150x75.error = [0.1909 0.1207 0.1336, 0.0028 0.0038 0.0058 0.0086 0.0832 0.0624 0.0557 0.0021 0.0023 0.0068 0.0088 0.0821 0.0278 0.0083]; Results_150x75.P = [2, 4, 6, 2, 4, 6 8 2, 4, 6 2, 4, 6 8 2, 4, 10]; 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]; % Ricci_Rogers.etaB = [0.5 1.0]; Ricci_Rogers.Gamma = [10 1e-2]; Ricci_Rogers.etaB = [0.5 1.25]; if 1 % Fig 3 of Ricci Rogers 2006 SCALING = 2*sqrt(2); fig = figure; semilogy(Ricci_Rogers.etaB,Ricci_Rogers.Gamma,'--','color',[0,0,0]+0.6); hold on; plot(10,10,'color',line_colors(1,:)); plot(10,10,'color',line_colors(2,:)); plot(10,10,'color',line_colors(3,:)); plot(10,10,'color',line_colors(4,:)); plot(10,10,'color',line_colors(5,:)); plot(10,10,'*k','MarkerSize',10, 'LineWidth',1.0); plot(10,10,'ok','MarkerSize',10, 'LineWidth',1.0); 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 xlabel('$L_n/L_B$'); ylabel('$2\sqrt(2)\Gamma^\infty_{part}$') end grid on; title('$L=100$, $150\times75$, $\nu_{hyp}=0.1$'); xlim([0,1.75]); ylim([1e-6,100]) legend('Mix. Length, Ricci 2006','$P=2$, $J=1$','$P=4$, $J=2$','$P=6$, $J=3$','$P=8$, $J=4$','$P=10$, $J=5$',... '$\nu_{DGGK}=1.0$', '$\nu_{DGGK}=0.5$','$\nu_{DGGK}=0.1$'); plot([0.3 0.3],[1e-6,1e2],'r') plot([1.6 1.6],[1e-6,1e2],'r') plot([0.5],[0.3965],'--','color',[0,0,0]+0.6) end \ No newline at end of file diff --git a/wk/flux_results.m b/wk/flux_results.m index 22f77dc..594b3b6 100644 --- a/wk/flux_results.m +++ b/wk/flux_results.m @@ -1,171 +1,171 @@ default_plots_options if 1 %% Compute time average and std of the mean flow t0 = 1000; t1 = 3000; [~,it0] = min(abs(t0-Ts2D)); [~,it1] = min(abs(t1-Ts2D)); range = it0:it1; avg = mean(GFlux_ri(range)) stdev = std(GFlux_ri(range))^(.5) figure hist(GFlux_ri(range),20); xlabel('$\Gamma$') end if 0 %% Handwritten results for nu = 0.01 % High definition results (256x128) SCALING = 2*sqrt(2); Results_256x128.Gamma = [0.02, 0.03, 0.20, 0.037, 2.7, 2.25, 4, 5e-4, 2e-3, 0.03]; Results_256x128.L = [ 66, 66, 66, 50, 66, 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]; % Results_128x64.L = [ 25, 25, 25, 33 33, 33]; % Results_128x64.P = [ 2, 2, 2, 2, 2, 2]; % 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]; % Ricci_Rogers.etaB = [0.4 0.5 1.0]; Ricci_Rogers.Gamma = [10 1e-1]; Ricci_Rogers.etaB = [0.5 1.0]; if 1 % Fig 3 of Ricci Rogers 2006 fig = figure; semilogy(Ricci_Rogers.etaB,Ricci_Rogers.Gamma,'--','color',[0,0,0]+0.6); 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 xlabel('$\eta_B$'); ylabel('$\Gamma^\infty_{part}$') end grid on; title('$\nu = 0.01$') legend('Mix. Length, Ricci 2006','$P=2$, $J=1$','$P=3$, $J=2$','$P=4$, $J=2$','$P=5$, $J=3$') FIGNAME = [SIMDIR,'flux_study_nu_1e-2.png']; ylim([1e-4, 10]) saveas(fig,FIGNAME); disp(['Figure saved @ : ',FIGNAME]) end if 0 %% Handwritten results for nu = 0.1 Results_256x128.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, 3e-3]; 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]; % Ricci_Rogers.etaB = [0.5 1.0]; Ricci_Rogers.Gamma = [10 1e-1]; Ricci_Rogers.etaB = [0.5 1.0]; if 1 SCALING = 2*sqrt(2); % Fig 3 of Ricci Rogers 2006 fig = figure; semilogy(Ricci_Rogers.etaB,Ricci_Rogers.Gamma,'--','color',[0,0,0]+0.6); 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 xlabel('$\eta_B$'); ylabel('$\Gamma^\infty_{part}$') end grid on; title('$\nu = 0.1$') legend('Mix. Length, Ricci 2006','$P=2$, $J=1$','$P=3$, $J=2$','$P=4$, $J=2$') FIGNAME = [SIMDIR,'flux_study_nu_1e-1.png']; saveas(fig,FIGNAME); disp(['Figure saved @ : ',FIGNAME]) end if 0 %% Handwritten results for nu = 1.0, eta = 0.5, 200x100, L=100 Results_256x128.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, 3e-3]; 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]; % Ricci_Rogers.etaB = [0.5 1.0]; Ricci_Rogers.Gamma = [10 1e-1]; Ricci_Rogers.etaB = [0.5 1.0]; if 1 % Fig 3 of Ricci Rogers 2006 SCALING = 2*sqrt(2); fig = figure; semilogy(Ricci_Rogers.etaB,Ricci_Rogers.Gamma,'--','color',[0,0,0]+0.6); 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 xlabel('$\eta_B$'); ylabel('$\Gamma^\infty_{part}$') end grid on; title('$\nu = 0.1$') legend('Mix. Length, Ricci 2006','$P=2$, $J=1$','$P=3$, $J=2$','$P=4$, $J=2$') FIGNAME = [SIMDIR,'flux_study_nu_1e-1.png']; saveas(fig,FIGNAME); disp(['Figure saved @ : ',FIGNAME]) end if 0 %% Handwritten results for nu = 1.0, eta = 0.5, 150x75, L=100, DGGK Results_150x75.Gamma = [0.026,0.026, 1e-2, 1, 1, 1, 2e-2, 1, 0.15, 3e-3]; 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]; % Ricci_Rogers.etaB = [0.5 1.0]; Ricci_Rogers.Gamma = [10 1e-1]; Ricci_Rogers.etaB = [0.5 1.0]; if 1 % Fig 3 of Ricci Rogers 2006 SCALING = 2*sqrt(2); fig = figure; semilogy(Ricci_Rogers.etaB,Ricci_Rogers.Gamma,'--','color',[0,0,0]+0.6); 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 xlabel('$\eta_B$'); ylabel('$\Gamma^\infty_{part}$') end grid on; title('$\nu = 0.1$') legend('Mix. Length, Ricci 2006','$P=2$, $J=1$','$P=3$, $J=2$','$P=4$, $J=2$') FIGNAME = [SIMDIR,'flux_study_nu_1e-1.png']; saveas(fig,FIGNAME); disp(['Figure saved @ : ',FIGNAME]) end \ No newline at end of file diff --git a/wk/izar_run.m b/wk/izar_run.m index 168f691..035adff 100644 --- a/wk/izar_run.m +++ b/wk/izar_run.m @@ -1,86 +1,86 @@ %clear all; addpath(genpath('../matlab')) % ... add %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CLUSTER PARAMETERS CLUSTER.TIME = '00:15:00'; % allocation time hh:mm:ss 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 MU_P = 0; % Hermite hyperdiffusivity -mu_p*(d/dvpar)^4 f MU_J = 0; % Laguerre hyperdiffusivity -mu_j*(d/dvperp)^4 f %% TIME PARAMETERS TMAX = 200; % 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 SPS5D = 1/50; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints RESTART = 1; % To restart from last checkpoint JOB2LOAD= 0; %% OPTIONS % SIMID = ['HeLaZ_v2.5_eta_',num2str(ETAB),'_nu_%0.0e']; % Name of the simulation % 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) NL_CLOS = 1; % nonlinear closure model (0: =0 nmax = jmax, 1: nmax = jmax-j, >1 : nmax = NL_CLOS) KERN = 0; % Kernel model (0 : GK) INIT_PHI= 1; % Start simulation with a noisy phi and moments %% OUTPUTS W_DOUBLE = 1; W_GAMMA = 1; W_PHI = 1; W_NA00 = 1; W_NAPJ = 1; 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 JMAXI = J; % Highest '' Laguerre '' kmax = N*pi/L;% Highest fourier mode HD_CO = 0.5; % Hyper diffusivity cutoff ratio MU = NU_HYP/(HD_CO*kmax)^4 % Hyperdiffusivity coefficient NOISE0 = 1.0e-5; 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 5838766..223568a 100644 --- a/wk/linear_study.m +++ b/wk/linear_study.m @@ -1,216 +1,216 @@ -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 default_plots_options %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters 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; %% OPTIONS % 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; INIT_ZF = 0; ZF_AMP = 0.0; CLOS = 0; % Closure model (0: =0 truncation, 1: semi coll, 2: Copy closure J+1 = J, P+2 = P) NL_CLOS = 0; % nonlinear closure model (0: =0 nmax = jmax, 1: nmax = jmax-j, >1 : nmax = NL_CLOS) KERN = 0; % Kernel model (0 : GK) INIT_PHI= 0; % Start simulation with a noisy phi INIT_ZF = 0; % Start simulation with a noisy phi %% OUTPUTS W_DOUBLE = 0; W_GAMMA = 0; W_PHI = 0; W_NA00 = 1; W_NAPJ = 1; W_SAPJ = 0; W_DENS = 0; W_TEMP = 0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % unused % DK = 0; % Drift kinetic model (put every kernel_n to 0 except n=0 to 1) JOBNUM = 00; KPAR = 0.0; % Parellel wave vector component HD_CO = 0.5; % Hyper diffusivity cutoff ratio kmax = N*pi/L;% Highest fourier mode 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; Nparam = numel(PA); param_name = 'PJ'; gamma_Ni00 = zeros(Nparam,floor(N/2)+1); gamma_Nipj = zeros(Nparam,floor(N/2)+1); Bohm_transport = zeros(Nparam,1); Ni00_ST = zeros(Nparam,floor(N/2)+1,floor(SPS2D*TMAX)); for i = 1:Nparam % Change scan parameter PMAXE = PA(i); PMAXI = PA(i); JMAXE = JA(i); JMAXI = JA(i); DT = DTA(i); % MU_P = mup_/PMAXE^2; % MU_J = muj_/JMAXE^3; setup % Run linear simulation % system(['cd ../results/',SIMID,'/',PARAMS,'/; mpirun -np 1 ./../../../bin/helaz 1 1; cd ../../../wk']) system(['cd ../results/',SIMID,'/',PARAMS,'/; mpirun -np 6 ./../../../bin/helaz 1 6; cd ../../../wk']) % system(['cd ../results/',SIMID,'/',PARAMS,'/; mpirun -np 6 ./../../../bin/helaz 2 3; cd ../../../wk']) % Load and process results %% filename = ['../results/',SIMID,'/',PARAMS,'/outputs_00.h5']; load_results 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 if 1 %% Plot SCALE = 1;%sqrt(2); fig = figure; FIGNAME = 'linear_study'; plt = @(x) x; % subplot(211) 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']); end end if 0 %% Parameter scan over eta_B PMAXE = 6; PMAXI = 6; JMAXE = 3; JMAXI = 3; TMAX = 400; DT = 0.001; eta_B = [0.45, 0.5, 0.55, 0.6, 0.65]; Nparam = numel(eta_B); param_name = 'etaB'; CO = -2; % Collision operator (0 : L.Bernstein, -1 : Full Coulomb, -2 : Dougherty) NU = 1e-2; % Collision frequency Bohm_transport = zeros(Nparam,1); gamma_Ni = zeros(Nparam,N); for i = 1:Nparam % Change scan parameter ETAB = eta_B(i); setup % Run linear simulation system(... ['cd ../results/',SIMID,'/',PARAMS,'/; mpirun -np 4 ./../../../bin/helaz; cd ../../../wk']... ) % 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 if 0 %% Plot fig = figure; FIGNAME = 'linear_study'; 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') saveas(fig,[SIMDIR,'gamma_Ni_vs_',param_name,'_',PARAMS,'.fig']); end if 1 %% Plot fig = figure; FIGNAME = 'mixing_length'; plot(eta_B, Bohm_transport) grid on; xlabel('$L_n/L_B$'); ylabel('$\eta\gamma_{max}/k_{max}^2$'); title(['$P_e=',num2str(PMAXE),'$',', $J_e=',num2str(JMAXE),'$',... ', $P_i=',num2str(PMAXE),'$',', $J_i=',num2str(JMAXI),'$']) saveas(fig,[SIMDIR,FIGNAME,'_vs_',param_name,'_',PARAMS,'.fig']); end %% end end end end \ No newline at end of file diff --git a/wk/load_multiple_outputs_marconi.m b/wk/load_multiple_outputs_marconi.m index ee1d402..a1bb195 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/v2.7_P_10_J_5/200x100_L_60_P_10_J_5_eta_0.6_nu_1e-03_SGGK_CLOS_0_mu_1e-03/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_DGGK_CLOS_0_mu_1e-02/out.txt') +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/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 a7a196a..aa5436c 100644 --- a/wk/local_run.m +++ b/wk/local_run.m @@ -1,71 +1,71 @@ addpath(genpath('../matlab')) % ... add %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters CLUSTER.TIME = '99:00:00'; % allocation time hh:mm:ss %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS -NU = 0.0141; % Collision frequency -ETAB = 1/1.4; % Magnetic gradient -ETAN = 1.0; % Density gradient +NU = 1e-2; % Collision frequency +ETAN = 2.0; % Density gradient drive (R/Ln) NU_HYP = 0.0; %% GRID PARAMETERS -N = 100; % Frequency gridpoints (Nkr = N/2) -L = 50; % Size of the squared frequency domain +N = 200; % Frequency gridpoints (Nkx = N/2) +L = 150; % Size of the squared frequency domain 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 = 1000; % Maximal time unit +TMAX = 300; % 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 SPS5D = 1/200; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints/10 RESTART = 0; % To restart from last checkpoint JOB2LOAD= 0; %% OPTIONS AND NAMING % Collision operator % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Pitch angle ; +/- for GK/DK) CO = 3; CLOS = 0; % Closure model (0: =0 truncation) -NL_CLOS = -1; % nonlinear closure model (-2: nmax = jmax, -1: nmax = jmax-j, >=0 : nmax = NL_CLOS) +NL_CLOS = 0; % nonlinear closure model (-2: nmax = jmax, -1: nmax = jmax-j, >=0 : nmax = NL_CLOS) % SIMID = 'test_restart'; % 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 = 1; % activate non-linearity (is cancelled if KREQ0 = 1) +SIMID = 'v2.8_barnes'; % Name of the simulation +% SIMID = ['v2.8_P_',num2str(P),'_J_',num2str(J)]; % Name of the simulation +NON_LIN = 1; % activate non-linearity (is cancelled if KXEQ0 = 1) INIT_ZF = 0; ZF_AMP = 0.0; %% OUTPUTS W_DOUBLE = 0; W_GAMMA = 1; W_PHI = 1; W_NA00 = 1; W_NAPJ = 1; W_SAPJ = 0; W_DENS = 1; W_TEMP = 1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% unused PMAXE = P; % Highest electron Hermite polynomial degree 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 HD_CO = 0.5; % Hyper diffusivity cutoff ratio % kmaxcut = 2.5; 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 diff --git a/wk/marconi_run.m b/wk/marconi_run.m index 1e8aabd..e77e072 100644 --- a/wk/marconi_run.m +++ b/wk/marconi_run.m @@ -1,101 +1,101 @@ clear all; addpath(genpath('../matlab')) % ... add SUBMIT = 1; % To submit the job automatically % EXECNAME = 'helaz_dbg'; - EXECNAME = 'helaz_2.73'; -for ETAB = [0.6] + EXECNAME = 'helaz_2.8'; +for ETAN = [1.4] %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CLUSTER PARAMETERS -% CLUSTER.PART = 'prod'; % dbg or prod -CLUSTER.PART = 'dbg'; +CLUSTER.PART = 'prod'; % dbg or prod +% CLUSTER.PART = 'dbg'; CLUSTER.TIME = '24:00:00'; % allocation time hh:mm:ss if(strcmp(CLUSTER.PART,'dbg')); CLUSTER.TIME = '00:30:00'; end; CLUSTER.MEM = '128GB'; % Memory CLUSTER.JNAME = 'HeLaZ';% Job name NP_P = 2; % MPI processes along p -NP_KR = 24; % MPI processes along kr +NP_KX = 24; % MPI processes along kx %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS -NU = 1e-3; % Collision frequency -% ETAB = 0.7; % Magnetic gradient -NU_HYP = 0.1; % Hyperdiffusivity coefficient +NU = 1e-2; % Collision frequency +NU_HYP = 0.0; % Hyperdiffusivity coefficient +% ETAN = 1.0; % Density gradient % (0 : L.Bernstein, 1 : Dougherty, 2: Sugama, 3 : Pitch angle ; +/- for GK/DK) -CO = 2; +CO = 3; INIT_ZF = 0; ZF_AMP = 0.0; %% GRID PARAMETERS -N = 200; % Frequency gridpoints (Nkr = N/2) -L = 60; % Size of the squared frequency domain -P = 6; % Electron and Ion highest Hermite polynomial degree -J = 3; % Electron and Ion highest Laguerre polynomial degree +N = 300; % Frequency gridpoints (Nkx = N/2) +L = 100; % Size of the squared frequency domain +P = 10; % Electron and Ion highest Hermite polynomial degree +J = 5; % Electron and Ion highest Laguerre polynomial degree 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 = 10000; % Maximal time unit -DT = 1e-2; % Time step +DT = 5e-3; % Time step SPS0D = 1; % Sampling per time unit for profiler SPS2D = 1/4; % Sampling per time unit for 2D arrays SPS5D = 1/300; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints RESTART = 0; % To restart from last checkpoint JOB2LOAD= 0; %% Naming SIMID = 'kobayashi'; % Name of the simulation % SIMID = 'test'; % Name of the simulation -% SIMID = ['v2.7_P_',num2str(P),'_J_',num2str(J)]; % Name of the simulation +% SIMID = ['v2.8_P_',num2str(P),'_J_',num2str(J)]; % Name of the simulation PREFIX =[]; -% PREFIX = sprintf('%d_%d_',NP_P, NP_KR); +% PREFIX = sprintf('%d_%d_',NP_P, NP_KX); %% Options CLOS = 0; % Closure model (0: =0 truncation, 1: semi coll, 2: Copy closure J+1 = J, P+2 = P) -NL_CLOS = -1; % nonlinear closure model (-2: nmax = jmax, -1: nmax = jmax-j, >=0 : nmax = NL_CLOS) +NL_CLOS = 0; % nonlinear closure model (-2: nmax = jmax, -1: nmax = jmax-j, >=0 : nmax = NL_CLOS) KERN = 0; % Kernel model (0 : GK) INIT_PHI= 1; % Start simulation with a noisy phi and moments %% OUTPUTS W_DOUBLE = 1; W_GAMMA = 1; W_PHI = 1; W_NA00 = 1; W_NAPJ = 1; W_SAPJ = 0; W_DENS = 1; W_TEMP = 1; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% fixed parameters (for current study) -KR0KH = 0; A0KH = 0; % Background phi mode -KREQ0 = 0; % put kr = 0 +KX0KH = 0; A0KH = 0; % Background phi mode +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 JMAXI = J; % Highest '' Laguerre '' kmax = N*pi/L;% Highest fourier mode % kmax = 2/3*N*pi/L;% Highest fourier mode with AA HD_CO = 0.5; % Hyper diffusivity cutoff ratio MU = NU_HYP/(HD_CO*kmax)^4; % Hyperdiffusivity coefficient NOISE0 = 1.0e-5; ETAT = 0.0; % Temperature gradient -ETAN = 1.0; % Density gradient +ETAB = 1.0; % Magnetic 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_marconi system('rm fort.90 setup_and_run.sh batch_script.sh'); -if(mod(NP_P*NP_KR,48)~= 0) +if(mod(NP_P*NP_KX,48)~= 0) disp('WARNING : unused cores (ntot cores must be a 48 multiple)'); end if(SUBMIT) system('ssh ahoffman@login.marconi.cineca.it sh HeLaZ/wk/setup_and_run.sh'); end disp('done'); end \ No newline at end of file diff --git a/wk/marconi_scaling.m b/wk/marconi_scaling.m index 8c5cd7e..b33ec6e 100644 --- a/wk/marconi_scaling.m +++ b/wk/marconi_scaling.m @@ -1,60 +1,60 @@ %% 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 load_params el_ti_np_24(i_) = CPUTIME; 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 load_params el_ti_np_48(i_) = CPUTIME; 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 load_params el_ti_np_72(i_) = CPUTIME; end %% Plot figure plt = @(x) (x/el_ti_np_24(1)-1)*100; plot(np_p_24,plt(el_ti_np_24),'o--','DisplayName','Ncpu = 24'); hold on; plot(np_p_48,plt(el_ti_np_48),'o--','DisplayName','Ncpu = 48 ') plot(np_p_72,plt(el_ti_np_72),'o--','DisplayName','Ncpu = 72 ') xlabel('Num. proc. p') ylabel('Variation from 1 24 [$\%$]') title('CPU time change from 1D paralel') legend('show') \ No newline at end of file diff --git a/wk/open_figure_script.m b/wk/open_figure_script.m index b7ef07f..cc22dcf 100644 --- a/wk/open_figure_script.m +++ b/wk/open_figure_script.m @@ -1,32 +1,35 @@ simname_ = ''; 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); %% % simname_ = ''; % simname_ = ''; % 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_ = ''; + %% figname_ = '/fig/ZF_transport_drphi_'; % figname_ = '/fig/space_time_'; % figname_ = '/fig/phi_shear_phase_space_'; path_ = '../results/'; [~,idx] = max(simname_=='x'); params_ = simname_(idx-3:end); openfig([path_,simname_,figname_,params_,'.fig']); \ No newline at end of file diff --git a/wk/photomaton.m b/wk/photomaton.m index 32b5454..428eb69 100644 --- a/wk/photomaton.m +++ b/wk/photomaton.m @@ -1,90 +1,90 @@ 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 = 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 = 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; TNAME = []; -tf = 250; [~,it1] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 450; [~,it2] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1200; [~,it3] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; -tf = 1500; [~,it4] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; +tf = 3000; [~,it1] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; +tf = 4000; [~,it2] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; +tf = 5000; [~,it3] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; +tf = 6000; [~,it4] = min(abs(Ts2D-tf)); TNAME = [TNAME,'_',num2str(tf)]; fig = figure; FIGNAME = [FNAME,TNAME,'_snaps','_',PARAMS]; set(gcf, 'Position', [100, 100, 1500, 350]) plt = @(x) x./max(max(x)); 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]) 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),')$,',... + suptitle([FIELDLTX,', $\nu_{',CONAME,'}=$', num2str(NU), ', $\eta=$',num2str(ETAB/ETAN),... + ', $L=',num2str(L),'$, $N=',num2str(Nx),'$, $(P,J)=(',num2str(PMAXI),',',num2str(JMAXI),')$,',... ' $\mu_{hd}=$',num2str(MU)]); save_figure end if 0 %% Photomaton : quiver ExB velocity figure skip = 2; plt = @(x) x./max(max(x)); FNAME = 'ZF'; FIELDLTX = '$\bm{u}^{ZF}$'; XX = RR; YY = 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'); 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]); 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 %% Show frame in kspace tf = 800; [~,it2] = min(abs(Ts2D-tf)); [~,it5] = min(abs(Ts5D-tf)); -fig = figure; FIGNAME = ['krkz_',sprintf('t=%.0f',Ts2D(it2)),'_',PARAMS];set(gcf, 'Position', [100, 100, 700, 600]) +fig = figure; FIGNAME = ['kxky_',sprintf('t=%.0f',Ts2D(it2)),'_',PARAMS];set(gcf, 'Position', [100, 100, 700, 600]) CLIM = [0,1]; subplot(223); plt = @(x) fftshift((abs(x)),2)/max(max(abs(x))); - pclr = pcolor(fftshift(KR,2),fftshift(KZ,2),plt(PHI(:,:,it2))); set(pclr, 'edgecolor','none'); + pclr = pcolor(fftshift(kx,2),fftshift(ky,2),plt(PHI(:,:,it2))); set(pclr, 'edgecolor','none'); caxis(CLIM); colormap hot xlabel('$k_r$'); ylabel('$k_z$'); title(sprintf('$t c_s/R=%.0f$',Ts2D(it2))); legend('$|\hat\phi|$'); subplot(222); - pclr = pcolor(fftshift(KR,2),fftshift(KZ,2),plt(Ni00(:,:,it2))); set(pclr, 'edgecolor','none'); + pclr = pcolor(fftshift(kx,2),fftshift(ky,2),plt(Ni00(:,:,it2))); set(pclr, 'edgecolor','none'); caxis(CLIM); colormap hot xlabel('$k_r$'); ylabel('$k_z$'); legend('$|\hat n_i^{00}|$'); subplot(221); - pclr = pcolor(fftshift(KR,2),fftshift(KZ,2),plt(Ne00(:,:,it2))); set(pclr, 'edgecolor','none'); + pclr = pcolor(fftshift(kx,2),fftshift(ky,2),plt(Ne00(:,:,it2))); set(pclr, 'edgecolor','none'); caxis(CLIM); colormap hot xlabel('$k_r$'); ylabel('$k_z$'); legend('$|\hat n_e^{00}|$'); subplot(224); colorbar; caxis(CLIM); colormap hot -% pclr = pcolor(fftshift(KR,2),fftshift(KZ,2),plt(Si00(:,:,it5))); set(pclr, 'edgecolor','none'); colorbar; +% pclr = pcolor(fftshift(kx,2),fftshift(ky,2),plt(Si00(:,:,it5))); set(pclr, 'edgecolor','none'); colorbar; % xlabel('$k_r$'); ylabel('$k_z$');legend('$\hat S_i^{00}$'); 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 0000000..876a233 --- /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 a241120..2eddbcd 100644 --- a/wk/ppb110_run.m +++ b/wk/ppb110_run.m @@ -1,106 +1,106 @@ %clear all; addpath(genpath('../matlab')) % ... add %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Set Up parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% CLUSTER PARAMETERS CLUSTER.TIME = '01:00:00'; % allocation time hh:mm:ss CLUSTER.NODES = '1'; % MPI process CLUSTER.CPUPT = '1'; % CPU per task CLUSTER.NTPN = '4'; % N tasks per node CLUSTER.MEM = '2000'; % Memory CLUSTER.JNAME = 'test_HeLaZ'; % Job name USERNAME = 'ahoffman'; % username at ppb110 for folder naming %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% PHYSICAL PARAMETERS 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 MU_P = 0; % Hermite hyperdiffusivity -mu_p*(d/dvpar)^4 f MU_J = 0; % Laguerre hyperdiffusivity -mu_j*(d/dvperp)^4 f %% TIME PARAMETERS TMAX = 150; % Maximal time unit DT = 2e-2; % Time step SPS0D = 1; % Sampling per time unit for profiler SPS2D = 1/10; % Sampling per time unit for 2D arrays SPS5D = 1/10; % Sampling per time unit for 5D arrays SPSCP = 0; % Sampling per time unit for checkpoints RESTART = 0; % To restart from last checkpoint JOB2LOAD= 0; %% OPTIONS SIMID = 'test_low_sampling'; % Name of the simulation SIMID = sprintf(SIMID,NU); CO = -3; % Collision operator (0 : L.Bernstein, -1 : Full Coulomb, -2 : Dougherty, -3 : GK Dougherty) CLOS = 0; % Closure model (0: =0 truncation, 1: semi coll, 2: Copy closure J+1 = J, P+2 = P) 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 JMAXI = J; % Highest '' Laguerre '' kmax = N*pi/L;% Highest fourier mode HD_CO = 0.5; % Hyper diffusivity cutoff ratio MU = NU_HYP/(HD_CO*kmax)^4 % Hyperdiffusivity coefficient NOISE0 = 1.0e-5; ETAT = 0.0; % Temperature gradient ETAN = 1.0; % Density gradient TAU = 1.0; % e/i temperature ratio %% Run file management scripts setup % Write the input script "fort.90" with desired parameters %% Write the sh script to launch the job on slurm for PPB110 INPUT = 'setup_and_run.sh'; fid = fopen(INPUT,'wt'); SCRATCH_SIMDIR = ['/scratch/',USERNAME,'/HeLaZ']; % Path to the simulation directory in the scratch % Writing of the script fprintf(fid,[... '#!/bin/bash\n',... 'mkdir -p ',SCRATCH_SIMDIR,'/wk\n',... ... 'cd ',SCRATCH_SIMDIR,'/wk\n',... ... 'mkdir -p ', BASIC.RESDIR,'\n',... 'cd ',BASIC.RESDIR,'\n',... 'cp $HOME/HeLaZ/wk/fort.90 .\n',... 'cp $HOME/HeLaZ/wk/batch_script.sh .\n',... ... 'sbatch batch_script.sh\n',... 'echo $',SCRATCH_SIMDIR,'/results/',BASIC.SIMID,'/',BASIC.PARAMS,'/out.txt']); fclose(fid); system(['cp setup_and_run.sh ',BASIC.RESDIR,'/.']); %% Write the sbatch script for PPB110 INPUT = 'batch_script.sh'; fid = fopen(INPUT,'wt'); fprintf(fid,[... '#!/bin/bash\n',... '#SBATCH --job-name=',CLUSTER.JNAME,'\n',... '#SBATCH --time=', CLUSTER.TIME,'\n',... '#SBATCH --nodes=', CLUSTER.NODES,'\n',... '#SBATCH --cpus-per-task=', CLUSTER.CPUPT,'\n',... '#SBATCH --ntasks-per-node=', CLUSTER.NTPN,'\n',... '#SBATCH --mem-per-cpu=', CLUSTER.MEM,'\n',... '#SBATCH --error=err.txt\n',... '#SBATCH --output=out.txt\n',... 'module purge\n',... 'module load PrgEnv-intel/17.0\n',... 'srun ./../../../bin/helaz']); fclose(fid); system(['cp batch_script.sh ',BASIC.RESDIR,'/.']); disp('done'); diff --git a/wk/spectral_analysis.m b/wk/spectral_analysis.m index afb9f71..8830f11 100644 --- a/wk/spectral_analysis.m +++ b/wk/spectral_analysis.m @@ -1,67 +1,67 @@ %% if 0 %% Hermite energy spectra % tf = Ts2D(end-3); skip = 1; fig = figure; FIGNAME = ['hermite_spectrum_',PARAMS];set(gcf, 'Position', [100, 100, 1800, 600]); plt = @(x) squeeze(x); N10 = floor(Nji/10); Nrow = (1+N10); Ncol = ceil(Nji/Nrow); for ij = 1:Nji subplot(Nrow,Ncol,ij) for it5 = 1:skip:Ns5D alpha = it5*1.0/Ns5D; loglog(Pi(1:2:end),plt(epsilon_i_pj(1:2:end,ij,it5)),... 'color',(1-alpha)*[0.8500, 0.3250, 0.0980]+alpha*[0, 0.4470, 0.7410],... 'DisplayName',['t=',num2str(Ts5D(it5))]); hold on; 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 %% if 0 %% Laguerre energy spectra % tf = Ts2D(end-3); skip = 1; fig = figure; FIGNAME = ['laguerre_spectrum_',PARAMS];set(gcf, 'Position', [100, 100, 1800, 600]); plt = @(x) squeeze(x); N10 = floor(Npi/10); Nrow = ceil((1+N10)/2); Ncol = ceil(Npi/Nrow/2); for ip = 1:2:Npi subplot(Nrow,Ncol,ip/2+1) for it5 = 1:skip:Ns5D alpha = it5*1.0/Ns5D; loglog(Ji,plt(epsilon_i_pj(ip,:,it5)),... 'color',(1-alpha)*[0.8500, 0.3250, 0.0980]+alpha*[0, 0.4470, 0.7410],... '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