5 #include <PB3D_macros.h>
24 integer :: lims_norm(2,3)
25 integer,
allocatable :: dum_ser(:)
26 integer :: rich_lvl_name
27 integer :: min_id(3), max_id(3)
28 integer :: last_unstable_id
30 character(len=4) :: grid_name(3)
34 type(grid_type) :: grid_eq_XYZ
35 type(grid_type) :: grid_eq_HEL
36 type(grid_type) :: grid_X_HEL
37 type(eq_2_type) :: eq_2_HEL
38 type(X_1_type) :: X_HEL
39 complex(dp),
allocatable :: E_pot_int(:,:)
40 complex(dp),
allocatable :: E_kin_int(:,:)
42 logical :: debug_tor_dep_ripple = .false.
97 character(*),
parameter :: rout_name =
'init_POST'
107 integer :: var_size_without_par(2)
108 integer :: lim_loc(3,2)
110 real(dp),
allocatable :: res_surf(:,:)
111 real(dp),
allocatable :: r_f_x(:)
112 character(len=max_str_ln) :: err_msg
120 call writo(
'The post-processing will be done in an extended &
133 call writo(
'The post-processing will be done in the PB3D grid')
141 call writo(
'Setting up preliminary variables')
170 grid_name(1) =
'eq_B'
178 lim_loc(3,:) = [1,-1]
183 &tot_rich=.true.,lim_pos=lim_loc)
186 &tot_rich=.true.,lim_pos=lim_loc)
206 call writo(
'Preliminary variables set up')
209 call writo(
'Dividing grids over MPI processes')
213 allocate(r_f_x(grid_x%n(3)))
216 &x_limits=lims_norm(:,2),sol_limits=lims_norm(:,3),&
217 &r_f_eq=grid_eq%r_F,r_f_x=r_f_x,r_f_sol=grid_sol%r_F)
220 call writo(
'normal grid limits:')
223 &trim(
i2str(lims_norm(1,1)))//
' .. '//trim(
i2str(lims_norm(2,1))),&
226 &trim(
i2str(lims_norm(1,2)))//
' .. '//trim(
i2str(lims_norm(2,2))),&
229 &trim(
i2str(lims_norm(1,3)))//
' .. '//trim(
i2str(lims_norm(2,3))),&
239 call writo(
'Grids divided over MPI processes')
242 call grid_eq%dealloc()
243 call grid_x%dealloc()
244 call grid_sol%dealloc()
248 call writo(
'Setting up final variables')
253 &tot_rich=.true.,grid_limits=lims_norm(:,1))
256 &tot_rich=.true.,grid_limits=lims_norm(:,2))
267 chckerr(
'Vacuum has not been implemented yet!')
274 call writo(
'Final variables set up')
277 call writo(
'1-D PB3D output plots')
284 call writo(
'Resonance plot not requested')
290 call writo(
'Flux quantities plot not requested')
300 &grid_limits=lims_norm(:,1))
306 call grid_eq_b%dealloc()
307 deallocate(grid_eq_b)
311 call writo(
'Magnetic grid plot not requested')
319 call writo(
'1-D outputs plots done')
322 call writo(
'Prepare 3-D plots')
326 call writo(
'Calculate resonant surfaces')
333 call writo(
'Plot the Eigenvalues')
339 call writo(
'Find stability ranges')
345 call writo(
'Plot the Harmonics')
348 if (min_id(jd).le.max_id(jd))
call &
349 &
writo(
'RANGE '//trim(
i2str(jd))//
': modes '//&
350 &trim(
i2str(min_id(jd)))//
'..'//trim(
i2str(max_id(jd))))
354 do id = min_id(jd),max_id(jd)
357 &trim(
i2str(
size(sol%val)))//
', with eigenvalue '&
358 &//trim(
c2strt(sol%val(id))))
366 &trim(
i2str(
size(sol%val)))//
' finished')
369 write(*,*)
'¡¡¡¡¡ NO VACUUM !!!!!'
373 call writo(
'Start vacuum plot for this solution')
382 call writo(
'Done with vacuum plot')
387 if (min_id(jd).le.max_id(jd))
call &
409 if (n_out(1,1).ne.n_out(1,2) .or. n_out(2,1).ne.n_out(2,2))
then
411 call writo(
'grid sizes for output grids not compatible. This &
412 &is assumed in the calculation of the equilibrium jobs.')
413 call writo(
'If this has changed, adapt and generalize &
414 &"divide_eq_jobs" appropriately.')
415 err_msg =
'Take into account how the ranges transfer from &
422 ierr =
get_ser_var(lims_norm(:,1),dum_ser,scatter=.true.)
424 var_size_without_par(1) = dum_ser(2*
n_procs)-dum_ser(1)+1
425 ierr =
get_ser_var(lims_norm(:,2),dum_ser,scatter=.true.)
427 var_size_without_par(2) = dum_ser(2*
n_procs)-dum_ser(1)+1
430 var_size_without_par(2) = var_size_without_par(2) +
n_r_sol
436 n_div_max = n_out(1,1)-1
442 &var_size_without_par,n_div,n_div_max=n_div_max)
447 &var_size_without_par,n_div,n_div_max=n_div_max,&
466 call writo(
'Reconstructing HELENA output for later interpolation')
470 &grid_limits=lims_norm(:,1))
473 &grid_limits=lims_norm(:,2))
482 call writo(
'HELENA output reconstructed for later interpolation')
489 call writo(
'Reconstructing full eq grid for XYZ reconstruction')
493 &
rich_lvl=rich_lvl_name,tot_rich=.true.,lim_pos=lim_loc)
498 call writo(
'Full eq grid reconstructed for XYZ reconstruction')
503 call writo(
'3-D plots prepared')
506 call grid_eq%dealloc()
507 call grid_x%dealloc()
508 call grid_sol%dealloc()
558 character(*),
parameter :: rout_name =
'run_driver_POST'
568 logical :: no_plots_loc
569 logical :: no_output_loc
570 logical :: last_eq_job
571 real(dp),
allocatable :: xyz_eq(:,:,:,:)
572 real(dp),
allocatable :: xyz_sol(:,:,:,:)
573 complex(dp),
allocatable :: sol_val_comp(:,:,:)
582 call writo(
'Parallel range for this job:')
584 call writo(trim(
i2str(eq_jobs_lims(1,eq_job_nr)))//
'..'//&
585 &trim(
i2str(eq_jobs_lims(2,eq_job_nr)))//
' of '//
'1..'//&
586 &trim(
i2str(n_par_tot)))
590 last_eq_job = eq_job_nr.eq.
size(eq_jobs_lims,2)
591 n_ev_out = sum(max_id-min_id+1)
600 select case (eq_style)
603 call writo(
'Calculate variables on output grid')
607 no_plots_loc = no_plots; no_plots = .true.
608 no_output_loc = no_output; no_output = .true.
614 ierr =
calc_eq(grids(1),eq_1,eq_2)
622 no_plots = no_plots_loc
623 no_output = no_output_loc
630 call writo(
'Variables calculated on output grid')
633 call writo(
'Interpolate variables angularly on output grid')
636 call eq_2%init(grids(1),setup_e=.true.,setup_f=.true.)
637 call x%init(
mds_x,grids(2))
639 &eq_2=eq_2_hel,eq_2_out=eq_2,eq_1=eq_1,&
640 &grid_name=
'output equilibrium grid')
643 &x_1_out=x,grid_name=
'output perturbation grid')
647 ierr =
calc_t_hf(grids(1),eq_1,eq_2,[0,0,0])
654 call writo(
'Variables interpolated angularly on output grid')
658 call writo(
'Initialize 3-D plots')
663 if (plot_e_rec .and. eq_job_nr.eq.1)
then
664 allocate(e_pot_int(7,n_ev_out))
665 allocate(e_kin_int(2,n_ev_out))
675 call writo(
'3-D plots initialized')
678 call writo(
'3-D PB3D output plots')
682 if (compare_tor_pos)
then
683 call writo(
'Plot the displacement vector')
692 call writo(
'Plot the magnetic field')
694 ierr =
b_plot(grids(1),eq_1,eq_2,plot_fluxes=post_style.eq.1,&
702 call writo(
'Plot the current')
704 ierr =
j_plot(grids(1),eq_1,eq_2,plot_fluxes=post_style.eq.1,&
712 call writo(
'Plot the curvature')
714 ierr =
kappa_plot(grids(1),eq_1,eq_2,xyz=xyz_eq)
719 if (post_output_sol)
then
721 call writo(
'Solution plots for different ranges')
726 if (last_eq_job)
allocate(sol_val_comp(2,2,n_ev_out))
728 if (min_id(jd).le.max_id(jd))
call &
729 &
writo(
'RANGE '//trim(
i2str(jd))//
': modes '//&
730 &trim(
i2str(min_id(jd)))//
'..'//trim(
i2str(max_id(jd))))
734 do id = min_id(jd),max_id(jd)
737 &trim(
i2str(
size(sol%val)))//
', with eigenvalue '&
738 &//trim(
c2strt(sol%val(id))))
743 &grids(3),eq_1,eq_2,x,sol,xyz_sol,id,&
744 &[plot_sol_xi,plot_sol_q])
749 call writo(
'Decompose the energy into its terms')
752 &grids(3),eq_1,eq_2,x,sol,vac,id,&
753 &b_aligned=post_style.eq.2,xyz=xyz_sol,&
754 &e_pot_int=e_pot_int(:,i_ev_out),&
755 &e_kin_int=e_kin_int(:,i_ev_out))
761 if (last_eq_job)
then
763 &e_kin_int(:,i_ev_out))
766 sol_val_comp(:,1,i_ev_out) = id*1._dp
767 sol_val_comp(:,2,i_ev_out) = [sol%val(id),&
768 &sum(e_pot_int(:,i_ev_out))/&
769 &sum(e_kin_int(:,i_ev_out))]
773 i_ev_out = i_ev_out + 1
779 &trim(
i2str(
size(sol%val)))//
' finished')
783 if (min_id(jd).le.max_id(jd))
call &
789 if (last_eq_job)
then
795 call writo(
'Solution for different ranges plotted')
800 call writo(
'3-D output plots done')
803 call writo(
'Clean up')
805 call grids(1)%dealloc()
806 call grids(2)%dealloc()
807 call grids(3)%dealloc()
826 call grid_eq_hel%dealloc()
827 call grid_x_hel%dealloc()
828 call eq_2_hel%dealloc()
833 call grid_eq_xyz%dealloc()
845 character(*),
parameter :: rout_name =
'open_decomp_log'
848 character(len=max_str_ln) :: format_head
849 character(len=max_str_ln) :: full_output_name
850 character(len=max_str_ln) :: grid_name
851 character(len=2*max_str_ln) :: temp_output_str
859 grid_name =
'extended'
861 grid_name =
'field-aligned'
864 call writo(
'Open decomposition log file')
868 format_head =
'("# ",7(A23," "))'
872 open(unit=
decomp_i,status=
'replace',file=full_output_name,&
874 chckerr(
'Cannot open EN output file')
875 call writo(
'Log file opened in '//trim(full_output_name))
876 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
877 &
'# Energy decomposition using the solution Eigenvectors'
878 chckerr(
'Failed to write')
879 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
880 &
'# (Output on the '//trim(grid_name)//
' grid)'
881 chckerr(
'Failed to write')
882 write(temp_output_str,format_head) &
883 &
'RE Eigenvalue ',
'RE E_pot/E_kin ', &
884 &
'RE E_pot ',
'RE E_kin '
885 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
886 chckerr(
'Failed to write')
887 write(temp_output_str,format_head) &
888 &
'IM Eigenvalue ',
'IM E_pot/E_kin ', &
889 &
'IM E_pot ',
'IM E_kin '
890 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
891 chckerr(
'Failed to write')
892 write(temp_output_str,format_head) &
893 &
'RE E_kin_n ',
'RE E_kin_g '
894 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
895 chckerr(
'Failed to write')
896 write(temp_output_str,format_head) &
897 &
'IM E_kin_n ',
'IM E_kin_g '
898 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
899 chckerr(
'Failed to write')
900 write(temp_output_str,format_head) &
901 &
'RE E_pot line_bending_n',
'RE E_pot line_bending_g', &
902 &
'RE E_pot ballooning_n ',
'RE E_pot ballooning_g ', &
903 &
'RE E_pot kink_n ',
'RE E_pot kink_g ', &
905 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
906 chckerr(
'Failed to write')
907 write(temp_output_str,format_head) &
908 &
'IM E_pot line_bending_n',
'IM E_pot line_bending_g', &
909 &
'IM E_pot ballooning_n ',
'IM E_pot ballooning_g ', &
910 &
'IM E_pot kink_n ',
'IM E_pot kink_g ', &
912 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) trim(temp_output_str)
913 chckerr(
'Failed to write')
924 character(*),
parameter :: rout_name =
'write_decomp_log'
927 integer,
intent(in) :: x_id
928 complex(dp),
intent(in) :: e_pot_int(7)
929 complex(dp),
intent(in) :: e_kin_int(2)
932 character(len=max_str_ln) :: format_val
933 character(len=2*max_str_ln) :: temp_output_str
939 call writo(
'Write to log file')
951 format_val =
'(" ",7(ES23.16," "))'
954 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
955 &
'# Eigenvalue '//trim(
i2str(x_id))
956 chckerr(
'Failed to write')
959 write(temp_output_str,format_val) &
961 &rp(sum(e_pot_int)/sum(e_kin_int)),&
962 &rp(sum(e_pot_int)),&
964 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
965 &trim(temp_output_str)
966 chckerr(
'Failed to write')
967 write(temp_output_str,format_val) &
969 &ip(sum(e_pot_int)/sum(e_kin_int)), &
970 &ip(sum(e_pot_int)),&
972 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
973 &trim(temp_output_str)
974 chckerr(
'Failed to write')
975 write(temp_output_str,format_val) &
978 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
979 &trim(temp_output_str)
980 chckerr(
'Failed to write')
981 write(temp_output_str,format_val) &
984 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
985 &trim(temp_output_str)
986 chckerr(
'Failed to write')
987 write(temp_output_str,format_val) &
995 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
996 &trim(temp_output_str)
997 chckerr(
'Failed to write')
998 write(temp_output_str,format_val) &
1006 write(unit=
decomp_i,fmt=
'(A)',iostat=ierr) &
1007 &trim(temp_output_str)
1008 chckerr(
'Failed to write')
1041 integer,
intent(inout) :: min_id(3)
1042 integer,
intent(inout) :: max_id(3)
1043 integer,
intent(inout) :: last_unstable_id
1047 integer :: n_sol_found
1050 n_sol_found =
size(sol%val)
1053 last_unstable_id = 0
1054 do id = 1,n_sol_found
1055 if (rp(sol%val(id)).lt.0._dp) last_unstable_id = id
1058 if (last_unstable_id.gt.0)
then
1064 max_id(1) = last_unstable_id
1071 if (last_unstable_id.gt.0)
then
1078 max_id(2) = min(last_unstable_id +
n_sol_plotted(3),n_sol_found)
1080 max_id(2) = n_sol_found
1087 max_id(2) = n_sol_found
1094 min_id(3) = last_unstable_id + 1
1096 max_id(3) = n_sol_found
1098 if (min_id(3).le.max_id(2))
then
1099 max_id(2) = max_id(3)
1104 if (min_id(2).le.max_id(1))
then
1105 max_id(1) = max_id(2)
1116 complex(dp),
intent(inout) :: sol_val_comp(:,:,:)
1119 character(len=max_str_ln) :: plot_title(2)
1120 character(len=max_str_ln) :: plot_name
1122 if (
rank.eq.0 .and.
size(sol_val_comp,3).gt.0)
then
1124 plot_title = [
'RE sol_val',
'E_frac ']
1125 plot_name =
'sol_val_comp_RE'
1127 &rp(sol_val_comp(:,1,:)),&
1128 &x=rp(sol_val_comp(:,2,:)),draw=.false.)
1129 call draw_ex(plot_title,plot_name,
size(sol_val_comp,3),1,.false.)
1130 plot_title(1) =
'rel diff between RE sol_val and E_frac'
1131 plot_name =
'sol_val_comp_RE_rel_diff'
1133 &(sol_val_comp(1,2,:)-sol_val_comp(2,2,:))/&
1134 &sol_val_comp(1,2,:)),x=rp(sol_val_comp(1,1,:)),&
1136 call draw_ex(plot_title(1:1),plot_name,1,1,.false.)
1137 plot_title(1) =
'rel diff between RE sol_val and E_frac [log]'
1138 plot_name =
'sol_val_comp_RE_rel_diff_log'
1139 call print_ex_2d(plot_title(1),plot_name,log10(abs(rp(&
1140 &(sol_val_comp(1,2,:)-sol_val_comp(2,2,:))/&
1141 &sol_val_comp(1,2,:)))),x=rp(sol_val_comp(1,1,:)),&
1143 call draw_ex(plot_title(1:1),plot_name,1,1,.false.)
1146 plot_title = [
'IM sol_val',
'E_frac ']
1147 plot_name =
'sol_val_comp_IM'
1149 &rp(sol_val_comp(:,1,:)),x=ip(sol_val_comp(:,2,:)),draw=.false.)
1150 call draw_ex(plot_title,plot_name,
size(sol_val_comp,3),1,.false.)
1151 plot_title(1) =
'rel diff between IM sol_val and E_frac'
1152 plot_name =
'sol_val_comp_IM_rel_diff'
1154 &(sol_val_comp(1,2,:)-sol_val_comp(2,2,:))/&
1155 &sol_val_comp(1,2,:)),x=rp(sol_val_comp(1,1,:)),&
1157 call draw_ex(plot_title(1:1),plot_name,1,1,.false.)
1158 plot_title(1) =
'rel diff between IM sol_val and E_frac [log]'
1159 plot_name =
'sol_val_comp_IM_rel_diff_log'
1160 call print_ex_2d(plot_title(1),plot_name,log10(abs(ip(&
1161 &(sol_val_comp(1,2,:)-sol_val_comp(2,2,:))/&
1162 &sol_val_comp(1,2,:)))),x=rp(sol_val_comp(1,1,:)),&
1164 call draw_ex(plot_title(1:1),plot_name,1,1,.false.)
1185 integer function setup_out_grids(grids_out,XYZ_eq,XYZ_sol)
result(ierr)
1196 character(*),
parameter :: rout_name =
'setup_out_grids'
1199 type(
grid_type),
intent(inout) :: grids_out(3)
1200 real(dp),
intent(inout),
allocatable :: xyz_eq(:,:,:,:)
1201 real(dp),
intent(inout),
allocatable :: xyz_sol(:,:,:,:)
1207 integer :: id, jd, ld
1208 integer :: lim_loc(3,2,3)
1209 real(dp) :: lim_theta(2)
1210 real(dp),
allocatable :: r_geo(:,:,:)
1211 real(dp),
allocatable :: xy(:,:,:)
1212 real(dp),
allocatable :: f(:,:,:)
1213 real(dp),
allocatable :: f_loc(:,:)
1214 real(dp),
allocatable :: xyz_x(:,:,:,:)
1219 call writo(
'Set up output grid')
1222 select case (post_style)
1225 call writo(
'Set up limits')
1227 lim_loc(1,:,1) = [0,0]
1228 lim_loc(2,:,1) = [0,0]
1229 lim_loc(3,:,1) = [1,-1]
1231 lim_loc(1,:,2) = [0,0]
1232 lim_loc(2,:,2) = [0,0]
1233 lim_loc(3,:,2) = [1,-1]
1235 lim_loc(1,:,3) = [0,0]
1236 lim_loc(2,:,3) = [0,0]
1237 lim_loc(3,:,3) = [1,-1]
1240 call writo(
'Reconstruct PB3D variables')
1242 &
rich_lvl=rich_lvl_name,lim_pos=lim_loc(:,:,1),&
1243 &grid_limits=lims_norm(:,1))
1246 &
rich_lvl=rich_lvl_name,lim_pos=lim_loc(:,:,2),&
1247 &grid_limits=lims_norm(:,2))
1250 &lim_pos=lim_loc(:,:,3),grid_limits=lims_norm(:,3))
1254 if (n_par_tot.gt.1)
then
1255 lim_theta = min_theta_plot + &
1256 &(eq_jobs_lims(:,eq_job_nr)-1._dp)*&
1257 &(max_theta_plot-min_theta_plot)/(n_par_tot-1._dp)
1259 lim_theta = min_theta_plot
1261 n_theta = eq_jobs_lims(2,eq_job_nr)-eq_jobs_lims(1,eq_job_nr)+1
1264 call writo(
'Extend equilibrium grid')
1266 ierr = extend_grid_f(grid_eq,grids_out(1),n_theta_plot=n_theta,&
1267 &lim_theta_plot=lim_theta,grid_eq=grid_eq)
1271 call writo(
'Extend perturbation grid')
1273 ierr = grids_out(2)%init([n_theta,n_out(2:3,2)],&
1274 &i_lim=[grid_x%i_min,grid_x%i_max])
1276 grids_out(2)%r_F = grid_x%r_F
1277 grids_out(2)%r_E = grid_x%r_E
1278 grids_out(2)%loc_r_F = grid_x%loc_r_F
1279 grids_out(2)%loc_r_E = grid_x%loc_r_E
1280 select case (x_grid_style)
1283 grids_out(2)%theta_F = grids_out(1)%theta_F
1284 grids_out(2)%theta_E = grids_out(1)%theta_E
1285 grids_out(2)%zeta_F = grids_out(1)%zeta_F
1286 grids_out(2)%zeta_E = grids_out(1)%zeta_E
1289 do jd = 1,grids_out(1)%n(2)
1290 do id = 1,grids_out(1)%n(1)
1291 ierr =
spline(grids_out(1)%loc_r_F,&
1292 &grids_out(1)%theta_F(id,jd,:),&
1293 &grids_out(2)%loc_r_F,&
1294 &grids_out(2)%theta_F(id,jd,:),&
1295 &ord=norm_disc_prec_x)
1297 ierr =
spline(grids_out(1)%loc_r_F,&
1298 &grids_out(1)%theta_E(id,jd,:),&
1299 &grids_out(2)%loc_r_F,&
1300 &grids_out(2)%theta_E(id,jd,:),&
1301 &ord=norm_disc_prec_x)
1303 ierr =
spline(grids_out(1)%loc_r_F,&
1304 &grids_out(1)%zeta_F(id,jd,:),&
1305 &grids_out(2)%loc_r_F,&
1306 &grids_out(2)%zeta_F(id,jd,:),&
1307 &ord=norm_disc_prec_x)
1309 ierr =
spline(grids_out(1)%loc_r_F,&
1310 &grids_out(1)%zeta_E(id,jd,:),&
1311 &grids_out(2)%loc_r_F,&
1312 &grids_out(2)%zeta_E(id,jd,:),&
1313 &ord=norm_disc_prec_x)
1321 call grid_eq%dealloc()
1322 call grid_x%dealloc()
1325 call writo(
'Set up limits')
1327 lim_loc(1,:,1) = eq_jobs_lims(:,eq_job_nr)
1328 lim_loc(2,:,1) = [1,-1]
1329 lim_loc(3,:,1) = [1,-1]
1331 lim_loc(1,:,2) = eq_jobs_lims(:,eq_job_nr)
1332 lim_loc(2,:,2) = [1,-1]
1333 lim_loc(3,:,2) = [1,-1]
1335 lim_loc(1,:,3) = [0,0]
1336 lim_loc(2,:,3) = [0,0]
1337 lim_loc(3,:,3) = [1,-1]
1340 call writo(
'Reconstruct PB3D variables')
1343 &lim_pos=lim_loc(:,:,1),grid_limits=lims_norm(:,1))
1347 &lim_pos=lim_loc(:,:,2),grid_limits=lims_norm(:,2))
1350 &lim_pos=lim_loc(:,:,3),grid_limits=lims_norm(:,3))
1354 call writo(
'Calculate X, Y and Z of equilibrium grid')
1356 ierr = calc_xyz_of_output_grid(grids_out(1),xyz_eq)
1360 call writo(
'Calculate X, Y and Z of perturbation grid')
1362 ierr = calc_xyz_of_output_grid(grids_out(2),xyz_x)
1366 call writo(
'Calculate X, Y and Z of solution grid')
1368 allocate(xyz_sol(grids_out(2)%n(1),grids_out(2)%n(2),&
1369 &grids_out(3)%loc_n_r,3))
1370 select case (x_grid_style)
1374 do jd = 1,grids_out(2)%n(2)
1375 do id = 1,grids_out(2)%n(1)
1376 ierr =
spline(grids_out(2)%loc_r_F,&
1377 &xyz_x(id,jd,:,ld),grids_out(3)%loc_r_F,&
1378 &xyz_sol(id,jd,:,ld),ord=norm_disc_prec_x)
1391 if (debug_tor_dep_ripple .and.
rank.eq.
n_procs-1)
then
1392 call plot_hdf5([
'X',
'Y',
'Z'],
'XYZ',xyz_eq)
1393 allocate(r_geo(grids_out(1)%n(1),grids_out(1)%n(2),&
1394 &grids_out(1)%loc_n_r))
1395 r_geo = sqrt((xyz_eq(:,:,:,3)-0.56710)**2 + &
1396 &(xyz_eq(:,:,:,1)-6.4297)**2)
1397 call plot_hdf5(
'r_geo',
'r_geo_TEMP',r_geo,x=xyz_eq(:,:,:,1),&
1398 &y=xyz_eq(:,:,:,2),z=xyz_eq(:,:,:,3))
1399 allocate(xy(grids_out(1)%n(2),grids_out(1)%n(1),2))
1400 do id = 1,grids_out(1)%n(1)
1401 xy(:,id,1) = xyz_eq(id,:,grids_out(1)%loc_n_r,2)*18
1402 xy(:,id,2) = r_geo(id,:,grids_out(1)%loc_n_r) &
1403 &* grids_out(1)%n(2) / sum(r_geo(id,:,grids_out(1)%loc_n_r))
1405 call print_ex_2d([
'r_geo'],
'r_geo',xy(:,:,2),x=xy(:,:,1),&
1407 call draw_ex([
'r_geo'],
'r_geo',grids_out(1)%n(1),1,.false.,&
1409 do id = 1,grids_out(1)%n(1)
1410 ierr =
nufft(xy(1:
size(xy,1)-1,id,1),xy(1:
size(xy,1)-1,id,2),&
1414 &
allocate(f(
size(f_loc,1),
size(f_loc,2),grids_out(1)%n(1)))
1417 call print_ex_2d([
'r_geo_cos'],
'r_geo_cos',f(:,1,:),&
1419 call draw_ex([
'r_geo_cos'],
'r_geo_cos',grids_out(1)%n(1),1,.false.,&
1421 call print_ex_2d([
'r_geo_sin'],
'r_geo_sin',f(:,2,:),&
1423 call draw_ex([
'r_geo_sin'],
'r_geo_sin',grids_out(1)%n(1),1,.false.,&
1436 integer function calc_xyz_of_output_grid(grid,XYZ)
result(ierr)
1445 character(*),
parameter :: rout_name =
'calc_XYZ_of_output_grid'
1449 real(dp),
allocatable :: xyz(:,:,:,:)
1452 real(dp),
allocatable :: r(:,:,:)
1453 character(len=max_str_ln) :: err_msg
1462 &grid%trigon_factors)
1467 allocate(xyz(grid%n(1),grid%n(2),grid%loc_n_r,3))
1471 call writo(
'Plots are done in 3-D geometry')
1475 &xyz(:,:,:,1),xyz(:,:,:,2),xyz(:,:,:,3))
1488 call writo(
'Plots are done in an unwrapped torus')
1491 allocate(r(grid%n(1),grid%n(2),grid%loc_n_r))
1493 &xyz(:,:,:,1),xyz(:,:,:,2),xyz(:,:,:,3),r=r)
1496 xyz(:,:,:,2) = grid%zeta_F
1508 call writo(
'Plots are done in slab geometry')
1512 select case (post_style)
1515 xyz(:,:,:,1) = grid%theta_F/pi
1516 xyz(:,:,:,2) = grid%zeta_F/pi
1518 xyz(:,:,:,1) = grid%zeta_F/pi
1519 xyz(:,:,:,2) = grid%theta_F/pi
1523 call writo(
'For plotting, the angular &
1524 &coordinates are swapped: theta <-> zeta')
1526 xyz(:,:,:,1) = grid%zeta_F/pi
1528 xyz(:,:,:,1) = grid%theta_F/pi
1532 xyz(:,:,:,1) = grid%theta_F/pi
1534 xyz(:,:,:,1) = grid%zeta_F/pi
1538 xyz(:,jd,:,2) =
alpha(jd)
1543 do kd = 1,grid%loc_n_r
1544 xyz(:,:,kd,3) = grid%loc_r_F(kd)/
max_flux_f*2*pi
1549 &modulo(xyz(:,:,:,1:2)+1._dp,2._dp)-1._dp
1554 &
'" for plot_grid_style'
1562 end function calc_xyz_of_output_grid