1857 &v_mag,base_name,max_transf,v_flux_tor,v_flux_pol,XYZ,compare_tor_pos) &
1870 character(*),
parameter :: rout_name =
'calc_vec_comp'
1877 real(
dp),
intent(inout) :: v_com(:,:,:,:,:)
1878 integer,
intent(in) :: norm_disc_prec
1879 real(
dp),
intent(inout),
optional :: v_mag(:,:,:)
1880 character(len=*),
intent(in),
optional :: base_name
1881 integer,
intent(in),
optional :: max_transf
1882 real(
dp),
intent(inout),
allocatable,
optional :: v_flux_pol(:,:)
1883 real(
dp),
intent(inout),
allocatable,
optional :: v_flux_tor(:,:)
1884 real(
dp),
intent(in),
optional :: xyz(:,:,:,:)
1889 integer :: max_transf_loc
1890 integer :: id, jd, kd, ld
1891 integer :: plot_dim(4)
1892 integer :: plot_offset(4)
1894 integer :: tor_id(2)
1895 integer :: norm_id(2)
1896 logical :: cont_plot
1898 logical :: compare_tor_pos_loc
1899 character(len=max_str_ln) :: description(3)
1900 character(len=max_str_ln) :: file_names(3)
1901 character(len=max_str_ln) :: var_names(3,2)
1902 character(len=5) :: coord_names(3)
1903 character(len=max_str_ln) :: err_msg
1904 real(
dp) :: norm_len
1905 real(
dp),
allocatable :: q_saf(:,:)
1906 real(
dp),
allocatable :: jac(:,:,:)
1907 real(
dp),
allocatable :: xyzr(:,:,:,:)
1908 real(
dp),
allocatable :: theta_geo(:,:,:)
1909 real(
dp),
allocatable :: x(:,:,:,:), y(:,:,:,:), z(:,:,:,:)
1910 real(
dp),
allocatable :: v_temp(:,:,:,:,:)
1911 real(
dp),
allocatable :: v_ser_temp(:)
1912 real(
dp),
allocatable :: v_ser_temp_int(:)
1913 real(
dp),
allocatable :: t_ba(:,:,:,:,:,:,:), t_ab(:,:,:,:,:,:,:)
1914 real(
dp),
allocatable :: d1r(:,:,:), d2r(:,:,:)
1915 real(
dp),
allocatable :: d1z(:,:,:), d2z(:,:,:)
1921 call writo(
'Prepare calculation of vector components')
1926 if (
present(max_transf))
then
1927 if (max_transf.ge.1 .and. max_transf.le.5) &
1928 &max_transf_loc = max_transf
1931 if (
present(base_name))
then
1932 if (trim(base_name).ne.
'') do_plot = .true.
1943 ierr =
trim_grid(grid,grid_trim,norm_id)
1947 allocate(xyzr(grid%n(1),grid%n(2),grid%loc_n_r,4))
1948 ierr =
calc_xyz_grid(grid_eq,grid,xyzr(:,:,:,1),xyzr(:,:,:,2),&
1949 &xyzr(:,:,:,3),r=xyzr(:,:,:,4))
1953 compare_tor_pos_loc = compare_tor_pos_glob
1957 if (compare_tor_pos_loc)
then
1958 allocate(theta_geo(grid%n(1),grid%n(2),grid%loc_n_r))
1959 theta_geo = atan2(xyzr(:,:,:,3)-
rz_0(2),xyzr(:,:,:,4)-
rz_0(1))
1960 where (theta_geo.lt.0) theta_geo = theta_geo + 2*
pi
1966 plot_dim = [grid_trim%n,3]
1967 plot_offset = [0,0,grid_trim%i_min-1,0]
1968 tor_id = [1,
size(v_com,2)]
1969 if (compare_tor_pos_loc)
then
1970 if (plot_dim(2).ne.3)
then
1972 err_msg =
'When comparing toroidal positions, need to &
1973 &have 3 toroidal points (one in the middle)'
1985 if (compare_tor_pos_loc)
then
1987 err_msg =
'When comparing toroidal positions, cannot have &
1988 &multiple equilibrium jobs'
1994 if (
eq_style.eq.1 .and. .not.
allocated(grid%trigon_factors))
then
1996 err_msg =
'trigonometric factors not allocated'
2001 if (compare_tor_pos_loc)
call writo(
'Comparing toroidal positions')
2004 allocate(x(grid_trim%n(1),grid_trim%n(2),grid_trim%loc_n_r,1))
2005 allocate(y(grid_trim%n(1),grid_trim%n(2),grid_trim%loc_n_r,1))
2006 allocate(z(grid_trim%n(1),grid_trim%n(2),grid_trim%loc_n_r,1))
2007 if (
present(xyz))
then
2008 x(:,:,:,1) = xyz(:,:,norm_id(1):norm_id(2),1)
2009 y(:,:,:,1) = xyz(:,:,norm_id(1):norm_id(2),2)
2010 z(:,:,:,1) = xyz(:,:,norm_id(1):norm_id(2),3)
2012 x(:,:,:,1) = xyzr(:,:,norm_id(1):norm_id(2),1)
2013 y(:,:,:,1) = xyzr(:,:,norm_id(1):norm_id(2),2)
2014 z(:,:,:,1) = xyzr(:,:,norm_id(1):norm_id(2),3)
2019 allocate(v_temp(grid%n(1),grid%n(2),grid%loc_n_r,3,2))
2020 allocate(t_ba(grid%n(1),grid%n(2),grid%loc_n_r,9,0:0,0:0,0:0))
2021 allocate(t_ab(grid%n(1),grid%n(2),grid%loc_n_r,9,0:0,0:0,0:0))
2022 allocate(q_saf(grid%loc_n_r,0:1))
2023 if ((
present(v_flux_tor) .or.
present(v_flux_pol)) .and. &
2024 &.not.compare_tor_pos_loc)
then
2025 allocate(jac(grid%n(1),grid%n(2),grid%loc_n_r))
2026 if (
rank.eq.0 .and. .not.cont_plot)
then
2027 if (
present(v_flux_tor))
then
2028 allocate(v_flux_tor(grid_trim%n(3),plot_dim(2)))
2031 if (
present(v_flux_pol))
then
2032 allocate(v_flux_pol(grid_trim%n(3),plot_dim(1)))
2041 call writo(
'Flux coordinates')
2043 if (
present(v_mag))
then
2046 v_mag = v_mag + v_com(:,:,:,id,1)*v_com(:,:,:,id,2)
2055 if (do_plot .and. .not.compare_tor_pos_loc)
then
2056 coord_names(1) =
'alpha'
2057 coord_names(2) =
'psi'
2059 coord_names(3) =
'theta'
2061 coord_names(3) =
'zeta'
2063 var_names = trim(base_name)
2065 var_names(id,1) = trim(var_names(id,1))//
'_sub_'//&
2066 &trim(coord_names(id))
2067 var_names(id,2) = trim(var_names(id,2))//
'_sup_'//&
2068 &trim(coord_names(id))
2070 description(1) =
'covariant components of the magnetic field in &
2072 description(2) =
'contravariant components of the magnetic field &
2073 &in Flux coordinates'
2074 description(3) =
'magnitude of the magnetic field in Flux &
2076 file_names(1) = trim(base_name)//
'_F_sub'
2077 file_names(2) = trim(base_name)//
'_F_sup'
2078 file_names(3) = trim(base_name)//
'_F_mag'
2080 v_com(:,:,:,1,1) = v_com(:,:,:,1,1) *
r_0
2081 v_com(:,:,:,2,1) = v_com(:,:,:,2,1) / (
r_0*
b_0)
2082 v_com(:,:,:,3,1) = v_com(:,:,:,3,1) *
r_0
2083 v_com(:,:,:,1,2) = v_com(:,:,:,1,2) /
r_0
2084 v_com(:,:,:,2,2) = v_com(:,:,:,2,2) * (
r_0*
b_0)
2085 v_com(:,:,:,3,2) = v_com(:,:,:,3,2) /
r_0
2088 call plot_hdf5(var_names(:,id),trim(file_names(id)),&
2089 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,id),&
2090 &tot_dim=plot_dim,loc_offset=plot_offset,&
2091 &x=x(:,tor_id(1):tor_id(2),:,:),&
2092 &y=y(:,tor_id(1):tor_id(2),:,:),&
2093 &z=z(:,tor_id(1):tor_id(2),:,:),&
2094 &cont_plot=cont_plot,descr=description(id))
2096 if (
present(v_mag))
then
2097 call plot_hdf5(trim(base_name),trim(file_names(3)),&
2098 &v_mag(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2)),&
2099 &tot_dim=plot_dim(1:3),loc_offset=plot_offset(1:3),&
2100 &x=x(:,tor_id(1):tor_id(2),:,1),&
2101 &y=y(:,tor_id(1):tor_id(2),:,1),&
2102 &z=z(:,tor_id(1):tor_id(2),:,1),&
2103 &cont_plot=cont_plot,descr=description(3))
2122 call writo(
'magnetic coordinates')
2127 ierr =
spline(grid_eq%loc_r_F,eq_1%q_saf_FD(:,id),grid%loc_r_F,&
2128 &q_saf(:,id),ord=norm_disc_prec)
2131 c_loc =
c([1,1],.false.)
2133 t_ba(:,:,:,c_loc,0,0,0) = -grid%theta_F
2134 do kd = 1,grid%loc_n_r
2135 t_ba(:,:,kd,c_loc,0,0,0) = t_ba(:,:,kd,c_loc,0,0,0)*q_saf(kd,1)
2136 t_ba(:,:,kd,
c([2,1],.false.),0,0,0) = -q_saf(kd,0)
2138 t_ba(:,:,:,
c([3,1],.false.),0,0,0) = 1._dp
2139 t_ba(:,:,:,
c([1,2],.false.),0,0,0) = 1._dp
2140 t_ba(:,:,:,
c([2,3],.false.),0,0,0) = 1._dp
2142 t_ba(:,:,:,c_loc,0,0,0) = -grid%zeta_F
2143 do kd = 1,grid%loc_n_r
2144 t_ba(:,:,kd,c_loc,0,0,0) = &
2145 &t_ba(:,:,kd,c_loc,0,0,0)*q_saf(kd,1)/q_saf(kd,0)
2146 t_ba(:,:,kd,
c([2,1],.false.),0,0,0) = 1._dp/q_saf(kd,0)
2147 t_ba(:,:,kd,
c([1,2],.false.),0,0,0) = q_saf(kd,0)
2149 t_ba(:,:,:,
c([2,1],.false.),0,0,0) = -1._dp
2150 t_ba(:,:,:,
c([3,3],.false.),0,0,0) = 1._dp
2157 v_com(:,:,:,jd,1) = v_com(:,:,:,jd,1) + t_ba(:,:,:,&
2158 &
c([jd,id],.false.),0,0,0) * v_temp(:,:,:,id,1)
2159 v_com(:,:,:,jd,2) = v_com(:,:,:,jd,2) + t_ab(:,:,:,&
2160 &
c([id,jd],.false.),0,0,0) * v_temp(:,:,:,id,2)
2163 if (
present(v_mag))
then
2166 v_mag = v_mag + v_com(:,:,:,id,1)*v_com(:,:,:,id,2)
2173 coord_names(1) =
'psi'
2174 coord_names(2) =
'theta'
2175 coord_names(3) =
'zeta'
2176 var_names = trim(base_name)
2178 var_names(id,1) = trim(var_names(id,1))//
'_sub_'//&
2179 &trim(coord_names(id))
2180 var_names(id,2) = trim(var_names(id,2))//
'_sup_'//&
2181 &trim(coord_names(id))
2183 description(1) =
'covariant components of the magnetic field in &
2184 &Magnetic coordinates'
2185 description(2) =
'contravariant components of the magnetic field &
2186 &in Magnetic coordinates'
2187 description(3) =
'magnitude of the magnetic field in Magnetic &
2189 file_names(1) = trim(base_name)//
'_M_sub'
2190 file_names(2) = trim(base_name)//
'_M_sup'
2191 file_names(3) = trim(base_name)//
'_M_mag'
2192 if (compare_tor_pos_loc)
then
2194 file_names(id) = trim(file_names(id))//
'_COMP'
2198 v_com(:,:,:,1,1) = v_com(:,:,:,1,1) / (
r_0*
b_0)
2199 v_com(:,:,:,2,1) = v_com(:,:,:,2,1) *
r_0
2200 v_com(:,:,:,3,1) = v_com(:,:,:,3,1) *
r_0
2201 v_com(:,:,:,1,2) = v_com(:,:,:,1,2) * (
r_0*
b_0)
2202 v_com(:,:,:,2,2) = v_com(:,:,:,2,2) /
r_0
2203 v_com(:,:,:,3,2) = v_com(:,:,:,3,2) /
r_0
2205 if (compare_tor_pos_loc)
then
2210 call plot_hdf5(var_names(:,id),trim(file_names(id)),&
2211 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,id),&
2212 &tot_dim=plot_dim,loc_offset=plot_offset,&
2213 &x=x(:,tor_id(1):tor_id(2),:,:),&
2214 &y=y(:,tor_id(1):tor_id(2),:,:),&
2215 &z=z(:,tor_id(1):tor_id(2),:,:),&
2216 &cont_plot=cont_plot,descr=description(id))
2218 if (
present(v_mag))
then
2219 if (compare_tor_pos_loc)
then
2223 call plot_hdf5(trim(base_name),trim(file_names(3)),&
2224 &v_mag(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2)),&
2225 &tot_dim=plot_dim(1:3),loc_offset=plot_offset(1:3),&
2226 &x=x(:,tor_id(1):tor_id(2),:,1),&
2227 &y=y(:,tor_id(1):tor_id(2),:,1),&
2228 &z=z(:,tor_id(1):tor_id(2),:,1),&
2229 &cont_plot=cont_plot,descr=description(3))
2233 if ((
present(v_flux_tor) .or.
present(v_flux_pol)) .and. &
2234 &.not.compare_tor_pos_loc)
then
2236 if (maxval(grid%theta_F(grid%n(1),:,:)).lt.&
2237 &minval(grid%theta_F(1,:,:)))
then
2238 call writo(
'theta of the grid monotomically decreases in Flux &
2239 &quantities.',alert=.true.)
2241 call writo(
'This inverts the sign of the toroidal flux.')
2242 call writo(
'Remember that the grid limits are prescribed &
2243 &in Flux quantities.')
2246 if (maxval(grid%zeta_F(:,grid%n(2),:)).lt.&
2247 &minval(grid%zeta_F(:,1,:)))
then
2248 call writo(
'zeta of the grid monotomically decreases in Flux &
2249 &quantities.',alert=.true.)
2251 call writo(
'This inverts the sign of the poloidal flux.')
2252 call writo(
'Remember that the grid limits are prescribed &
2253 &in Flux quantities.')
2254 if (
eq_style.eq.1)
call writo(
'For VMEC, these are inverse.')
2257 if (grid_trim%r_F(grid_trim%n(3)).lt.grid_trim%r_F(1))
then
2258 call writo(
'r of the grid monotomically decreases in Flux &
2259 &quantities.',alert=.true.)
2261 call writo(
'This inverts the sign of the fluxes.')
2262 call writo(
'Remember that the grid limits are prescribed &
2263 &in Flux quantities.')
2266 if (abs(minval(grid_trim%r_F)).gt.
tol_zero)
then
2267 call writo(
'r of the grid does not start at zero.',alert=.true.)
2269 call writo(
'This leaves out part of the fluxes.')
2274 allocate(v_ser_temp_int(grid_trim%n(3)))
2277 var_names(1,2) =
'integrated poloidal flux of '//trim(base_name)
2278 var_names(2,2) =
'integrated toroidal flux of '//trim(base_name)
2279 file_names(1) = trim(base_name)//
'_flux_pol_int'
2280 file_names(2) = trim(base_name)//
'_flux_tor_int'
2285 call writo(
'Instead of calculating fluxes, returning &
2286 &integrals in the angular variables.',alert=.true.)
2288 call writo(
'Useful to check whether Maxwell holds.')
2289 call writo(
'i.e. whether loop integral of J returns &
2291 call writo(
'Note that the J-variables now refer to B and &
2293 call writo(
'Don''t forget the contribution of the toroidal &
2294 &field B_zeta on axis, times 2piR.')
2295 call writo(
'Don''t forget the vacuum permeability!')
2300 do jd = 1,grid_eq%n(2)
2301 do id = 1,grid_eq%n(1)
2302 ierr =
spline(grid_eq%loc_r_F,&
2303 &eq_2%jac_FD(id,jd,:,0,0,0),grid%loc_r_F,&
2304 &jac(id,jd,:),ord=norm_disc_prec)
2309 v_com(:,:,:,2,2) = v_com(:,:,:,2,2)*jac
2310 v_com(:,:,:,3,2) = v_com(:,:,:,3,2)*jac
2317 if (
present(v_flux_tor) .and. grid_trim%n(1).gt.1 .and. &
2318 &.not.compare_tor_pos_loc)
then
2320 do jd = 1,grid_trim%n(2)
2325 do kd = norm_id(1),norm_id(2)
2326 ierr =
calc_int(v_com(:,jd,kd,2,1),&
2327 &grid%theta_F(:,jd,kd),v_com(:,jd,kd,2,2))
2333 &norm_id(1):norm_id(2),2,2),v_ser_temp)
2339 v_flux_tor(:,jd) = v_flux_tor(:,jd) + v_ser_temp
2341 v_flux_tor(:,jd+plot_offset(1)) = v_ser_temp
2347 do kd = norm_id(1),norm_id(2)
2348 ierr =
calc_int(v_com(:,jd,kd,3,2),&
2349 &grid%theta_F(:,jd,kd),v_com(:,jd,kd,3,1))
2355 &norm_id(1):norm_id(2),3,1),v_ser_temp)
2361 &grid_trim%r_F(norm_id(1):),v_ser_temp_int)
2364 &v_ser_temp_int*
psi_0
2366 v_flux_tor(:,jd) = v_flux_tor(:,jd) + &
2369 v_flux_tor(:,jd+plot_offset(1)) = v_ser_temp_int
2378 if (
rank.eq.0 .and. do_plot .and. &
2381 &trim(file_names(2)),v_flux_tor,&
2382 &x=reshape(grid_trim%r_F(norm_id(1):)*2*
pi/
max_flux_f,&
2383 &[grid_trim%n(3),1]),draw=.false.)
2384 call draw_ex([var_names(2,2)],trim(file_names(2)),&
2385 &plot_dim(2),1,.false.)
2390 if (
present(v_flux_pol) .and. grid_trim%n(2).gt.1 .and. &
2391 &.not.compare_tor_pos_loc)
then
2393 do id = 1,grid_trim%n(1)
2398 do kd = norm_id(1),norm_id(2)
2399 ierr =
calc_int(v_com(id,:,kd,3,1),&
2400 &grid%zeta_F(id,:,kd),v_com(id,:,kd,3,2))
2406 &norm_id(1):norm_id(2),3,2),v_ser_temp)
2412 v_flux_pol(:,id+plot_offset(1)) = v_ser_temp
2414 v_flux_pol(:,id) = v_flux_pol(:,id) + v_ser_temp
2420 do kd = norm_id(1),norm_id(2)
2421 ierr =
calc_int(v_com(id,:,kd,2,2),&
2422 &grid%zeta_F(id,:,kd),v_com(id,:,kd,2,1))
2428 &norm_id(1):norm_id(2),2,1),v_ser_temp)
2434 &grid_trim%r_F(norm_id(1):),v_ser_temp_int)
2437 &v_ser_temp_int*
psi_0
2439 v_flux_pol(:,id+plot_offset(1)) = v_ser_temp_int
2441 v_flux_pol(:,id) = v_flux_pol(:,id) + &
2451 if (
rank.eq.0 .and. do_plot .and. &
2454 &trim(file_names(1)),v_flux_pol,&
2455 &x=reshape(grid_trim%r_F(norm_id(1):)*2*
pi/
max_flux_f,&
2456 &[grid_trim%n(3),1]),draw=.false.)
2457 call draw_ex([var_names(1,2)],trim(file_names(1)),&
2458 &plot_dim(1),1,.false.)
2463 deallocate(v_ser_temp)
2464 if (
rank.eq.0)
deallocate(v_ser_temp_int)
2469 if (max_transf_loc.eq.2)
return
2477 call writo(
'Equilibrium coordinates')
2480 do jd = 1,grid_eq%n(2)
2481 do id = 1,grid_eq%n(1)
2482 ierr =
spline(grid_eq%loc_r_F,&
2483 &eq_2%T_FE(id,jd,:,ld,0,0,0),grid%loc_r_F,&
2484 &t_ab(id,jd,:,ld,0,0,0),ord=norm_disc_prec)
2486 ierr =
spline(grid_eq%loc_r_F,&
2487 &eq_2%T_EF(id,jd,:,ld,0,0,0),grid%loc_r_F,&
2488 &t_ba(id,jd,:,ld,0,0,0),ord=norm_disc_prec)
2496 v_com(:,:,:,jd,1) = v_com(:,:,:,jd,1) + &
2497 &t_ba(:,:,:,
c([jd,id],.false.),0,0,0) * &
2499 v_com(:,:,:,jd,2) = v_com(:,:,:,jd,2) + &
2500 &t_ab(:,:,:,
c([id,jd],.false.),0,0,0) * &
2504 if (
present(v_mag))
then
2507 v_mag = v_mag + v_com(:,:,:,id,1)*v_com(:,:,:,id,2)
2519 coord_names(1) =
'r'
2520 coord_names(2) =
'theta'
2521 coord_names(3) =
'phi'
2522 description(1) =
'covariant components of the magnetic &
2523 &field in VMEC coordinates'
2524 description(2) =
'contravariant components of the magnetic &
2525 &field in VMEC coordinates'
2526 description(3) =
'magnitude of the magnetic field in VMEC &
2528 file_names(1) = trim(base_name)//
'_V_sub'
2529 file_names(2) = trim(base_name)//
'_V_sup'
2530 file_names(3) = trim(base_name)//
'_V_mag'
2532 coord_names(1) =
'psi'
2533 coord_names(2) =
'theta'
2534 coord_names(3) =
'phi'
2535 description(1) =
'covariant components of the magnetic &
2536 &field in HELENA coordinates'
2537 description(2) =
'contravariant components of the magnetic &
2538 &field in HELENA coordinates'
2539 description(3) =
'magnitude of the magnetic field in &
2540 &HELENA coordinates'
2541 file_names(1) = trim(base_name)//
'_H_sub'
2542 file_names(2) = trim(base_name)//
'_H_sup'
2543 file_names(3) = trim(base_name)//
'_H_mag'
2545 if (compare_tor_pos_loc)
then
2547 file_names(id) = trim(file_names(id))//
'_COMP'
2550 var_names = trim(base_name)
2552 var_names(id,1) = trim(var_names(id,1))//
'_sub_'//&
2553 &trim(coord_names(id))
2554 var_names(id,2) = trim(var_names(id,2))//
'_sup_'//&
2555 &trim(coord_names(id))
2558 v_com(:,:,:,1,1) = v_com(:,:,:,1,1) *
r_0
2559 v_com(:,:,:,2,1) = v_com(:,:,:,2,1) *
r_0
2560 v_com(:,:,:,3,1) = v_com(:,:,:,3,1) *
r_0
2561 v_com(:,:,:,1,2) = v_com(:,:,:,1,2) /
r_0
2562 v_com(:,:,:,2,2) = v_com(:,:,:,2,2) /
r_0
2563 v_com(:,:,:,3,2) = v_com(:,:,:,3,2) /
r_0
2565 if (compare_tor_pos_loc)
then
2570 call plot_hdf5(var_names(:,id),trim(file_names(id)),&
2571 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,id),&
2572 &tot_dim=plot_dim,loc_offset=plot_offset,&
2573 &x=x(:,tor_id(1):tor_id(2),:,:),&
2574 &y=y(:,tor_id(1):tor_id(2),:,:),&
2575 &z=z(:,tor_id(1):tor_id(2),:,:),&
2576 &cont_plot=cont_plot,descr=description(id))
2578 if (
present(v_mag))
then
2579 if (compare_tor_pos_loc)
then
2583 call plot_hdf5(trim(base_name),trim(file_names(3)),&
2584 &v_mag(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2)),&
2585 &tot_dim=plot_dim(1:3),loc_offset=plot_offset(1:3),&
2586 &x=x(:,tor_id(1):tor_id(2),:,1),&
2587 &y=y(:,tor_id(1):tor_id(2),:,1),&
2588 &z=z(:,tor_id(1):tor_id(2),:,1),&
2589 &cont_plot=cont_plot,descr=description(3))
2595 if (max_transf_loc.eq.3)
return
2608 call writo(
'Cylindrical coordinates')
2615 do jd = 1,grid_eq%n(2)
2616 do id = 1,grid_eq%n(1)
2617 ierr =
spline(grid_eq%loc_r_F,&
2618 &eq_2%T_VC(id,jd,:,ld,0,0,0),grid%loc_r_F,&
2619 &t_ab(id,jd,:,ld,0,0,0),ord=norm_disc_prec)
2627 allocate(d1r(grid%n(1),grid%n(2),grid%loc_n_r))
2628 allocate(d2r(grid%n(1),grid%n(2),grid%loc_n_r))
2629 allocate(d1z(grid%n(1),grid%n(2),grid%loc_n_r))
2630 allocate(d2z(grid%n(1),grid%n(2),grid%loc_n_r))
2633 ierr =
spline(grid%loc_r_E,xyzr(id,jd,:,4)/norm_len,&
2634 &grid%loc_r_E,d1r(id,jd,:),ord=norm_disc_prec,&
2637 ierr =
spline(grid%loc_r_E,xyzr(id,jd,:,3)/norm_len,&
2638 &grid%loc_r_E,d1z(id,jd,:),ord=norm_disc_prec,&
2643 do kd = 1,grid%loc_n_r
2645 ierr =
spline(grid%theta_E(:,jd,kd),&
2646 &xyzr(:,jd,kd,4)/norm_len,grid%theta_E(:,jd,kd),&
2647 &d2r(:,jd,kd),ord=norm_disc_prec,deriv=1)
2649 ierr =
spline(grid%theta_E(:,jd,kd),&
2650 &xyzr(:,jd,kd,3)/norm_len,grid%theta_E(:,jd,kd),&
2651 &d2z(:,jd,kd),ord=norm_disc_prec,deriv=1)
2655 t_ab(:,:,:,
c([1,1],.false.),0,0,0) = d1r
2656 t_ab(:,:,:,
c([1,3],.false.),0,0,0) = d1z
2657 t_ab(:,:,:,
c([2,1],.false.),0,0,0) = d2r
2658 t_ab(:,:,:,
c([2,3],.false.),0,0,0) = d2z
2659 t_ab(:,:,:,
c([3,2],.false.),0,0,0) = -1._dp
2660 deallocate(d1r,d2r,d1z,d2z)
2667 v_com(:,:,:,jd,1) = v_com(:,:,:,jd,1) + t_ba(:,:,:,&
2668 &
c([jd,id],.false.),0,0,0) * v_temp(:,:,:,id,1)
2669 v_com(:,:,:,jd,2) = v_com(:,:,:,jd,2) + t_ab(:,:,:,&
2670 &
c([id,jd],.false.),0,0,0) * v_temp(:,:,:,id,2)
2673 if (
present(v_mag))
then
2676 v_mag = v_mag + v_com(:,:,:,id,1)*v_com(:,:,:,id,2)
2686 description(1) =
'covariant components of the magnetic field in &
2687 &cylindrical coordinates'
2688 description(2) =
'contravariant components of the magnetic field &
2689 &in cylindrical coordinates'
2690 description(3) =
'magnitude of the magnetic field in cylindrical &
2692 file_names(1) = trim(base_name)//
'_C_sub'
2693 file_names(2) = trim(base_name)//
'_C_sup'
2694 file_names(3) = trim(base_name)//
'_C_mag'
2695 if (compare_tor_pos_loc)
then
2697 file_names(id) = trim(file_names(id))//
'_COMP'
2700 coord_names(1) =
'R'
2701 coord_names(2) =
'phi'
2702 coord_names(3) =
'Z'
2703 var_names = trim(base_name)
2705 var_names(id,1) = trim(var_names(id,1))//
'_sub_'//&
2706 &trim(coord_names(id))
2707 var_names(id,2) = trim(var_names(id,2))//
'_sup_'//&
2708 &trim(coord_names(id))
2712 v_com(:,:,:,2,1) = v_com(:,:,:,2,1) *
r_0
2715 v_com(:,:,:,2,2) = v_com(:,:,:,2,2) /
r_0
2718 if (compare_tor_pos_loc)
then
2723 call plot_hdf5(var_names(:,id),trim(file_names(id)),&
2724 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,id),&
2725 &tot_dim=plot_dim,loc_offset=plot_offset,&
2726 &x=x(:,tor_id(1):tor_id(2),:,:),&
2727 &y=y(:,tor_id(1):tor_id(2),:,:),&
2728 &z=z(:,tor_id(1):tor_id(2),:,:),&
2729 &cont_plot=cont_plot,descr=description(id))
2731 if (
present(v_mag))
then
2732 if (compare_tor_pos_loc)
then
2736 call plot_hdf5(trim(base_name),trim(file_names(3)),&
2737 &v_mag(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2)),&
2738 &tot_dim=plot_dim(1:3),loc_offset=plot_offset(1:3),&
2739 &x=x(:,tor_id(1):tor_id(2),:,1),&
2740 &y=y(:,tor_id(1):tor_id(2),:,1),&
2741 &z=z(:,tor_id(1):tor_id(2),:,1),&
2742 &cont_plot=cont_plot,descr=description(3))
2748 if (max_transf_loc.eq.4)
return
2757 call writo(
'Cartesian coordinates')
2761 t_ab(:,:,:,
c([1,1],.false.),0,0,0) = cos(-grid%zeta_F)
2762 t_ab(:,:,:,
c([1,2],.false.),0,0,0) = sin(-grid%zeta_F)
2763 t_ab(:,:,:,
c([2,1],.false.),0,0,0) = -xyzr(:,:,:,4)/norm_len*&
2765 t_ab(:,:,:,
c([2,2],.false.),0,0,0) = xyzr(:,:,:,4)/norm_len*&
2767 t_ab(:,:,:,
c([3,3],.false.),0,0,0) = 1._dp
2773 v_com(:,:,:,jd,1) = v_com(:,:,:,jd,1) + t_ba(:,:,:,&
2774 &
c([jd,id],.false.),0,0,0) * v_temp(:,:,:,id,1)
2775 v_com(:,:,:,jd,2) = v_com(:,:,:,jd,2) + t_ab(:,:,:,&
2776 &
c([id,jd],.false.),0,0,0) * v_temp(:,:,:,id,2)
2779 if (
present(v_mag))
then
2782 v_mag = v_mag + v_com(:,:,:,id,1)*v_com(:,:,:,id,2)
2789 description(1) =
'covariant components of the magnetic field in &
2790 &cartesian coordinates'
2791 description(2) =
'contravariant components of the magnetic field &
2792 &in cartesian coordinates'
2793 description(3) =
'magnitude of the magnetic field in cartesian &
2795 file_names(1) = trim(base_name)//
'_X_sub'
2796 file_names(2) = trim(base_name)//
'_X_sup'
2797 file_names(3) = trim(base_name)//
'_X_mag'
2798 if (compare_tor_pos_loc)
then
2800 file_names(id) = trim(file_names(id))//
'_COMP'
2803 coord_names(1) =
'X'
2804 coord_names(2) =
'Y'
2805 coord_names(3) =
'Z'
2806 var_names = trim(base_name)
2808 var_names(id,1) = trim(var_names(id,1))//
'_sub_'//&
2809 &trim(coord_names(id))
2810 var_names(id,2) = trim(var_names(id,2))//
'_sup_'//&
2811 &trim(coord_names(id))
2813 if (compare_tor_pos_loc)
then
2818 call plot_hdf5(var_names(:,id),trim(file_names(id)),&
2819 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,id),&
2820 &tot_dim=plot_dim,loc_offset=plot_offset,&
2821 &x=x(:,tor_id(1):tor_id(2),:,:),&
2822 &y=y(:,tor_id(1):tor_id(2),:,:),&
2823 &z=z(:,tor_id(1):tor_id(2),:,:),&
2824 &cont_plot=cont_plot,descr=description(id))
2826 if (
present(v_mag))
then
2827 if (compare_tor_pos_loc)
then
2831 call plot_hdf5(trim(base_name),trim(file_names(3)),&
2832 &v_mag(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2)),&
2833 &tot_dim=plot_dim(1:3),loc_offset=plot_offset(1:3),&
2834 &x=x(:,tor_id(1):tor_id(2),:,1),&
2835 &y=y(:,tor_id(1):tor_id(2),:,1),&
2836 &z=z(:,tor_id(1):tor_id(2),:,1),&
2837 &cont_plot=cont_plot,descr=description(3))
2841 call plot_hdf5([trim(base_name)],trim(base_name)//
'_vec',&
2842 &v_com(:,tor_id(1):tor_id(2),norm_id(1):norm_id(2),:,1),&
2843 &tot_dim=plot_dim,loc_offset=plot_offset,&
2844 &x=x(:,tor_id(1):tor_id(2),:,:),y=y(:,tor_id(1):tor_id(2),:,:),&
2845 &z=z(:,tor_id(1):tor_id(2),:,:),col=4,cont_plot=cont_plot,&
2846 &descr=
'magnetic field vector')
2852 call grid_trim%dealloc()