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')
341 call find_stab_ranges(sol,min_id,max_id,last_unstable_id)
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'
561 type(grid_type) :: grids(3)
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:')
586 &trim(
i2str(n_par_tot)))
591 n_ev_out = sum(max_id-min_id+1)
594 ierr = setup_out_grids(grids,xyz_eq,xyz_sol)
603 call writo(
'Calculate variables on output grid')
614 ierr =
calc_eq(grids(1),eq_1,eq_2)
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')
664 allocate(e_pot_int(7,n_ev_out))
665 allocate(e_kin_int(2,n_ev_out))
669 ierr = open_decomp_log()
675 call writo(
'3-D plots initialized')
678 call writo(
'3-D PB3D output plots')
683 call writo(
'Plot the displacement vector')
692 call writo(
'Plot the magnetic field')
702 call writo(
'Plot the current')
712 call writo(
'Plot the curvature')
714 ierr =
kappa_plot(grids(1),eq_1,eq_2,xyz=xyz_eq)
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,&
749 call writo(
'Decompose the energy into its terms')
752 &grids(3),eq_1,eq_2,x,sol,vac,id,&
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
762 ierr = write_decomp_log(id,e_pot_int(:,i_ev_out),&
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
790 call plot_sol_val_comp(sol_val_comp)
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()
840 integer function open_decomp_log()
result(ierr)
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')
916 end function open_decomp_log
921 integer function write_decomp_log(X_id,E_pot_int,E_kin_int)
result(ierr)
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')
1014 end function write_decomp_log
1036 subroutine find_stab_ranges(sol,min_id,max_id,last_unstable_id)
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)
1109 end subroutine find_stab_ranges
1112 subroutine plot_sol_val_comp(sol_val_comp)
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.)
1166 end subroutine plot_sol_val_comp
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(:,:,:,:)
1204 type(grid_type) :: grid_eq
1205 type(grid_type) :: grid_x
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')
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
1264 call writo(
'Extend equilibrium grid')
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
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,:),&
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,:),&
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,:),&
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,:),&
1321 call grid_eq%dealloc()
1322 call grid_x%dealloc()
1325 call writo(
'Set up limits')
1328 lim_loc(2,:,1) = [1,-1]
1329 lim_loc(3,:,1) = [1,-1]
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')
1342 &rich_lvl=rich_lvl,tot_rich=.true.,&
1343 &lim_pos=lim_loc(:,:,1),grid_limits=lims_norm(:,1))
1346 &rich_lvl=rich_lvl,tot_rich=.true.,&
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))
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,&
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)))
1419 call draw_ex([
'r_geo_cos'],
'r_geo_cos',grids_out(1)%n(1),1,.false.,&
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')
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
1549 &modulo(xyz(:,:,:,1:2)+1._dp,2._dp)-1._dp
1554 &
'" for plot_grid_style'
1562 end function calc_xyz_of_output_grid
1563 end function setup_out_grids
Calculate the equilibrium quantities on a grid determined by straight field lines.
Calculate , the transformation matrix between H(ELENA) and F(lux) coordinate systems.
Calculate from and where and , according to weyens3d.
Calculate grid of equidistant points, where optionally the last point can be excluded.
Gather parallel variable in serial version on group master.
Wrapper to the pspline library, making it easier to use for 1-D applications where speed is not the m...
Prints variables vars with names var_names in an HDF5 file with name c file_name and accompanying XDM...
Print 2-D output on a file.
Calculates either vectorial or tensorial perturbation variables.
Main driver of PostProcessing of program Peeling Ballooning in 3D.
integer function, public run_driver_post()
The main driver routine for postprocessing.
subroutine, public stop_post()
Cleans up main driver for postprocessing.
integer function, public init_post()
Initializes the POST driver.
Operations on the equilibrium variables.
integer function, public delta_r_plot(grid_eq, eq_1, eq_2, xyz, rich_lvl)
Plots HALF of the change in the position vectors for 2 different toroidal positions,...
integer function, public kappa_plot(grid_eq, eq_1, eq_2, rich_lvl, xyz)
Plots the curvature.
integer function, public divide_eq_jobs(n_par_x, arr_size, n_div, n_div_max, n_par_x_base, range_name)
Divides the equilibrium jobs.
integer function, public calc_eq_jobs_lims(n_par_x, n_div)
Calculate eq_jobs_lims.
integer function, public j_plot(grid_eq, eq_1, eq_2, rich_lvl, plot_fluxes, xyz)
Plots the current.
integer function, public b_plot(grid_eq, eq_1, eq_2, rich_lvl, plot_fluxes, xyz)
Plots the magnetic fields.
integer function, public flux_q_plot(grid_eq, eq)
Plots the flux quantities in the solution grid.
Numerical utilities related to equilibrium variables.
Variables that have to do with equilibrium quantities and the grid used in the calculations:
real(dp), public max_flux_f
max. flux in Flux coordinates, set in calc_norm_range_PB3D_in
Operations that have to do with the grids and different coordinate systems.
integer function, public calc_norm_range(style, in_limits, eq_limits, x_limits, sol_limits, r_f_eq, r_f_x, r_f_sol, jq)
Calculates normal range for the input grid, the equilibrium grid and/or the solution grid.
integer function, public magn_grid_plot(grid)
Plots the grid in real 3-D space.
Numerical utilities related to the grids and different coordinate systems.
integer function, public extend_grid_f(grid_in, grid_ext, grid_eq, n_theta_plot, n_zeta_plot, lim_theta_plot, lim_zeta_plot)
Extend a grid angularly.
integer function, public calc_xyz_grid(grid_eq, grid_xyz, x, y, z, l, r)
Calculates , and on a grid grid_XYZ, determined through its E(quilibrium) coordinates.
integer function, public nufft(x, f, f_f, plot_name)
calculates the cosine and sine mode numbers of a function defined on a non-regular grid.
Variables pertaining to the different grids used.
real(dp), dimension(:), allocatable, public alpha
field line label alpha
integer, public n_alpha
nr. of field-lines
real(dp), public max_alpha
max. of field-line label [ ] in field-aligned grid
real(dp), public min_alpha
min. of field-line label [ ] in field-aligned grid
integer, public n_r_sol
nr. of normal points in solution grid
Operations on HELENA variables.
integer function, public interp_hel_on_grid(grid_in, grid_out, eq_2, x_1, x_2, eq_2_out, x_1_out, x_2_out, eq_1, grid_name)
Interpolate variables resulting from HELENA equilibria to another grid (angularly).
Variables that have to do with HELENA quantities.
integer, public nchi
nr. of poloidal points
Numerical utilities related to giving output.
subroutine, public lvl_ud(inc)
Increases/decreases lvl of output.
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Numerical utilities related to MPI.
integer function, public wait_mpi()
Wait for all processes, wrapper to MPI barrier.
integer, dimension(:,:), allocatable, public f
1-D array indices of Fourier mode combination indices
subroutine, public calc_aux_utilities(n_mod)
Initialize utilities for fast future reference, depending on program style.
Numerical variables used by most other modules.
integer, parameter, public dp
double precision
logical, public ltest
whether or not to call the testing routines
integer, public post_style
style for POST (1: extended grid, 2: B-aligned grid)
logical, public plot_b
whether to plot the magnetic field in real coordinates
integer, public n_theta_plot
nr. of poloidal points in plot
integer, public plot_grid_style
style for POST plot grid (0: 3-D plots, 1: slab plots, 2: slab plots with folding,...
character(len=3), parameter, public output_name
name of output file
logical, public plot_kappa
whether to plot curvature
real(dp), public max_r_plot
max. of r_plot
real(dp), public min_theta_plot
min. of theta_plot
real(dp), parameter, public pi
real(dp), public max_zeta_plot
max. of zeta_plot
logical, public compare_tor_pos
compare quantities at toroidal positions (only for POST)
logical, public no_output
no output shown
integer, public n_procs
nr. of MPI processes
logical, public plot_flux_q
whether to plot flux quantities in real coordinates
complex(dp), parameter, public iu
complex unit
integer, parameter, public max_str_ln
maximum length of strings
logical, public plot_sol_q
whether to plot magnetic perturbation of solution in POST
logical, public post_output_sol
POST has outputs of solution.
logical, public plot_vac_pot
whether to plot vacuum potential in POST
integer, public n_zeta_plot
nr. of toroidal points in plot
logical, public plot_resonance
whether to plot the q-profile or iota-profile with resonances
integer, dimension(:,:), allocatable, public eq_jobs_lims
data about eq jobs: [ , ] for all jobs
integer, public x_grid_style
style for normal component of X grid (1: eq, 2: sol, 3: enriched)
character(len=4), public prog_name
name of program, used for info
real(dp), public min_zeta_plot
min. of zeta_plot
logical, public post_output_full
POST has output on full grids.
integer, public eq_style
either 1 (VMEC) or 2 (HELENA)
integer, parameter, public decomp_i
file number of output of EV decomposition
integer, dimension(4), public n_sol_plotted
how many solutions to be plot (first unstable, last unstable, first stable, last stable)
logical, public plot_j
whether to plot the current in real coordinates
integer, public ex_plot_style
external plot style (1: GNUPlot, 2: Bokeh for 2D, Mayavi for 3D)
real(dp), public min_r_plot
min. of r_plot
integer, public rank
MPI rank.
logical, public plot_sol_xi
whether to plot plasma perturbation of solution in POST
integer, public norm_disc_prec_x
precision for normal discretization for perturbation
logical, public plot_magn_grid
whether to plot the grid in real coordinates
logical, public swap_angles
swap angles theta and zeta in plots (only for POST)
real(dp), public max_theta_plot
max. of theta_plot
integer, public eq_job_nr
nr. of eq job
logical, public use_pol_flux_f
whether poloidal flux is used in F coords.
logical, public plot_e_rec
whether to plot energy reconstruction in POST
logical, public no_plots
no plots made
Operations concerning giving output, on the screen as well as in output files.
subroutine, public draw_ex(var_names, draw_name, nplt, draw_dim, plot_on_screen, ex_plot_style, data_name, draw_ops, extra_ops, is_animated, ranges, delay, persistent)
Use external program to draw a plot.
Operations on PB3D output.
integer function, public reconstruct_pb3d_vac(vac, data_name, rich_lvl)
Reconstructs the vacuum variables from PB3D HDF5 output.
integer function, public reconstruct_pb3d_eq_1(grid_eq, eq, data_name, lim_pos)
Reconstructs the equilibrium variables from PB3D HDF5 output.
integer function, public reconstruct_pb3d_grid(grid, data_name, rich_lvl, tot_rich, lim_pos, grid_limits)
Reconstructs grid variables from PB3D HDF5 output.
integer function, public get_pb3d_grid_size(n, grid_name, rich_lvl, tot_rich)
get grid size
integer function, public reconstruct_pb3d_x_1(mds, grid_x, x, data_name, rich_lvl, tot_rich, lim_sec_x, lim_pos)
Reconstructs the vectorial perturbation variables from PB3D HDF5 output.
integer function, public reconstruct_pb3d_eq_2(grid_eq, eq, data_name, rich_lvl, tot_rich, lim_pos)
Reconstructs the equilibrium variables from PB3D HDF5 output.
integer function, public reconstruct_pb3d_in(data_name)
Reconstructs the input variables from PB3D HDF5 output.
integer function, public reconstruct_pb3d_sol(mds, grid_sol, sol, data_name, rich_lvl, lim_sec_sol, lim_pos)
Reconstructs the solution variables from PB3D HDF5 output.
Variables concerning Richardson extrapolation.
integer, public rich_lvl
current level of Richardson extrapolation
Operations on the solution vectors such as decompososing the energy, etc...
subroutine, public plot_sol_vals(sol, last_unstable_id)
Plots Eigenvalues.
integer function, public decompose_energy(mds_x, mds_sol, grid_eq, grid_x, grid_sol, eq_1, eq_2, x, sol, vac, x_id, b_aligned, xyz, e_pot_int, e_kin_int)
Decomposes the plasma potential and kinetic energy in its individual terms for an individual Eigenval...
integer function, public plot_sol_vec(mds_x, mds_sol, grid_eq, grid_x, grid_sol, eq_1, eq_2, x, sol, xyz, x_id, plot_var)
Plots Eigenvectors.
integer function, public plot_harmonics(mds, grid_sol, sol, x_id, res_surf)
Plots the harmonics and their maximum in 2-D.
Variables pertaining to the solution quantities.
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
elemental character(len=max_str_ln) function, public c2strt(k)
Convert a complex (double) to string.
elemental character(len=max_str_ln) function, public r2strt(k)
Convert a real (double) to string.
Operations and variables pertaining to the vacuum response.
integer function, public vac_pot_plot(grid_sol, vac, sol, x_id)
Calculate vacuum potential at some positions that are not resonant.
Variables pertaining to the vacuum quantities.
Numerical utilities related to the output of VMEC.
integer function, public calc_trigon_factors(theta, zeta, trigon_factors)
Calculate the trigonometric cosine and sine factors.
Operations considering perturbation quantities.
integer function, public calc_res_surf(mds, grid_eq, eq, res_surf, info, jq)
Calculates resonating flux surfaces for the perturbation modes.
integer function, public setup_modes(mds, grid_eq, grid, plot_name)
Sets up some variables concerning the mode numbers.
integer function, public init_modes(grid_eq, eq)
Initializes some variables concerning the mode numbers.
integer function, public resonance_plot(mds, grid_eq, eq)
plot -profile or -profile in flux coordinates with or indicated if requested.
Variables pertaining to the perturbation quantities.
type(modes_type), public mds_x
modes variables for perturbation grid
type(modes_type), public mds_sol
modes variables for solution grid
vectorial perturbation type