28#include <PB3D_macros.h>
64 real(
dp),
allocatable :: pres_e(:,:)
65 real(
dp),
allocatable :: q_saf_e(:,:)
66 real(
dp),
allocatable :: rot_t_e(:,:)
67 real(
dp),
allocatable :: flux_p_e(:,:)
68 real(
dp),
allocatable :: flux_t_e(:,:)
69 real(
dp),
allocatable :: pres_fd(:,:)
70 real(
dp),
allocatable :: q_saf_fd(:,:)
71 real(
dp),
allocatable :: rot_t_fd(:,:)
72 real(
dp),
allocatable :: flux_p_fd(:,:)
73 real(
dp),
allocatable :: flux_t_fd(:,:)
74 real(
dp),
allocatable :: rho(:)
76 real(
dp) :: estim_mem_usage(2)
116 real(
dp),
allocatable :: r_e(:,:,:,:,:,:)
117 real(
dp),
allocatable :: z_e(:,:,:,:,:,:)
118 real(
dp),
allocatable :: l_e(:,:,:,:,:,:)
120 real(
dp),
allocatable :: g_c(:,:,:,:,:,:,:)
121 real(
dp),
allocatable :: g_e(:,:,:,:,:,:,:)
122 real(
dp),
allocatable :: h_e(:,:,:,:,:,:,:)
123 real(
dp),
allocatable :: g_f(:,:,:,:,:,:,:)
124 real(
dp),
allocatable :: h_f(:,:,:,:,:,:,:)
125 real(
dp),
allocatable :: g_fd(:,:,:,:,:,:,:)
126 real(
dp),
allocatable :: h_fd(:,:,:,:,:,:,:)
128 real(
dp),
allocatable :: t_vc(:,:,:,:,:,:,:)
129 real(
dp),
allocatable :: t_ef(:,:,:,:,:,:,:)
130 real(
dp),
allocatable :: t_fe(:,:,:,:,:,:,:)
132 real(
dp),
allocatable :: det_t_ef(:,:,:,:,:,:)
133 real(
dp),
allocatable :: det_t_fe(:,:,:,:,:,:)
135 real(
dp),
allocatable :: jac_e(:,:,:,:,:,:)
136 real(
dp),
allocatable :: jac_f(:,:,:,:,:,:)
137 real(
dp),
allocatable :: jac_fd(:,:,:,:,:,:)
139 real(
dp),
allocatable :: s(:,:,:)
140 real(
dp),
allocatable :: kappa_n(:,:,:)
141 real(
dp),
allocatable :: kappa_g(:,:,:)
142 real(
dp),
allocatable :: sigma(:,:,:)
144 real(
dp) :: estim_mem_usage(2)
182 logical,
intent(in),
optional :: setup_E
183 logical,
intent(in),
optional :: setup_F
186 integer :: loc_n_r, n
187 logical :: setup_E_loc, setup_F_loc
195 if (
present(setup_e)) setup_e_loc = setup_e
197 if (
present(setup_f)) setup_f_loc = setup_f
200 loc_n_r = grid%loc_n_r
203 if (setup_e_loc)
then
205 allocate(eq%pres_E(loc_n_r,0:
max_deriv+1))
208 allocate(eq%q_saf_E(loc_n_r,0:
max_deriv+1))
211 allocate(eq%rot_t_E(loc_n_r,0:
max_deriv+1))
214 allocate(eq%flux_p_E(loc_n_r,0:
max_deriv+1))
217 allocate(eq%flux_t_E(loc_n_r,0:
max_deriv+1))
222 &eq%estim_mem_usage(1) + loc_n_r*(
max_deriv+2)*5
226 if (setup_f_loc)
then
228 allocate(eq%pres_FD(loc_n_r,0:
max_deriv+1))
231 allocate(eq%flux_p_FD(loc_n_r,0:
max_deriv+1))
234 allocate(eq%flux_t_FD(loc_n_r,0:
max_deriv+1))
237 allocate(eq%q_saf_FD(loc_n_r,0:
max_deriv+1))
240 allocate(eq%rot_t_FD(loc_n_r,0:
max_deriv+1))
243 allocate(eq%rho(grid%loc_n_r))
248 &eq%estim_mem_usage(2) + loc_n_r*((
max_deriv+2)*5+1)
258 &
' - Expected memory usage of eq_1: '//&
259 &trim(
r2strt(eq%estim_mem_usage(1)*0.008))//
' kB for E and '//&
260 &trim(
r2strt(eq%estim_mem_usage(2)*0.008))//
' kB for E]',&
281 logical,
intent(in),
optional :: setup_E
282 logical,
intent(in),
optional :: setup_F
285 logical :: setup_E_loc, setup_F_loc
289 dims = [grid%n(1),grid%n(2),grid%loc_n_r]
298 if (
present(setup_e)) setup_e_loc = setup_e
300 if (
present(setup_f)) setup_f_loc = setup_f
302 if (setup_e_loc)
then
305 allocate(eq%g_E(dims(1),dims(2),dims(3),6,&
309 allocate(eq%h_E(dims(1),dims(2),dims(3),6,&
313 allocate(eq%g_F(dims(1),dims(2),dims(3),6,&
317 allocate(eq%h_F(dims(1),dims(2),dims(3),6,&
321 allocate(eq%jac_E(dims(1),dims(2),dims(3),&
325 allocate(eq%jac_F(dims(1),dims(2),dims(3),&
329 allocate(eq%T_EF(dims(1),dims(2),dims(3),9,&
333 allocate(eq%T_FE(dims(1),dims(2),dims(3),9,&
337 allocate(eq%det_T_EF(dims(1),dims(2),dims(3),&
341 allocate(eq%det_T_FE(dims(1),dims(2),dims(3),&
347 &eq%estim_mem_usage(1) + product(dims)*&
358 allocate(eq%g_C(dims(1),dims(2),dims(3),6,&
362 allocate(eq%T_VC(dims(1),dims(2),dims(3),9,&
366 allocate(eq%R_E(dims(1),dims(2),dims(3),&
370 allocate(eq%Z_E(dims(1),dims(2),dims(3),&
374 allocate(eq%L_E(dims(1),dims(2),dims(3),&
380 &eq%estim_mem_usage(1) + product(dims)*(&
389 if (setup_f_loc)
then
392 allocate(eq%g_FD(dims(1),dims(2),dims(3),6,&
396 allocate(eq%h_FD(dims(1),dims(2),dims(3),6,&
400 allocate(eq%jac_FD(dims(1),dims(2),dims(3),&
404 allocate(eq%S(dims(1),dims(2),dims(3)))
407 allocate(eq%kappa_n(dims(1),dims(2),dims(3)))
410 allocate(eq%kappa_g(dims(1),dims(2),dims(3)))
413 allocate(eq%sigma(dims(1),dims(2),dims(3)))
418 &eq%estim_mem_usage(2) + product(dims)*(&
430 &
' - Expected memory usage of eq_2: '//&
431 &trim(
r2strt(eq%estim_mem_usage(1)*0.008))//
' kB for E and '//&
432 &trim(
r2strt(eq%estim_mem_usage(2)*0.008))//
' kB for E]',&
450 setup_e =
allocated(eq_i%pres_E)
451 setup_f =
allocated(eq_i%pres_FD)
453 call eq_o%init(grid_i,setup_e=setup_e,setup_f=setup_f)
456 if (
allocated(eq_i%pres_E)) eq_o%pres_E = eq_i%pres_E
457 if (
allocated(eq_i%q_saf_E)) eq_o%q_saf_E = eq_i%q_saf_E
458 if (
allocated(eq_i%rot_t_E)) eq_o%rot_t_E = eq_i%rot_t_E
459 if (
allocated(eq_i%flux_p_E)) eq_o%flux_p_E = eq_i%flux_p_E
460 if (
allocated(eq_i%flux_t_E)) eq_o%flux_t_E = eq_i%flux_t_E
464 if (
allocated(eq_i%pres_FD)) eq_o%pres_FD = eq_i%pres_FD
465 if (
allocated(eq_i%flux_p_FD)) eq_o%flux_p_FD = eq_i%flux_p_FD
466 if (
allocated(eq_i%flux_t_FD)) eq_o%flux_t_FD = eq_i%flux_t_FD
467 if (
allocated(eq_i%q_saf_FD)) eq_o%q_saf_FD = eq_i%q_saf_FD
468 if (
allocated(eq_i%rot_t_FD)) eq_o%rot_t_FD = eq_i%rot_t_FD
469 if (
allocated(eq_i%rho)) eq_o%rho = eq_i%rho
489 setup_e =
allocated(eq_i%jac_E)
490 setup_f =
allocated(eq_i%jac_FD)
492 call eq_o%init(grid_i,setup_e=setup_e,setup_f=setup_f)
495 if (
allocated(eq_i%g_E)) eq_o%g_E = eq_i%g_E
496 if (
allocated(eq_i%h_E)) eq_o%h_E = eq_i%h_E
497 if (
allocated(eq_i%g_F)) eq_o%g_F = eq_i%g_F
498 if (
allocated(eq_i%h_F)) eq_o%h_F = eq_i%h_F
499 if (
allocated(eq_i%jac_E)) eq_o%jac_E = eq_i%jac_E
500 if (
allocated(eq_i%jac_F)) eq_o%jac_F = eq_i%jac_F
501 if (
allocated(eq_i%T_EF)) eq_o%T_EF = eq_i%T_EF
502 if (
allocated(eq_i%T_FE)) eq_o%T_FE = eq_i%T_FE
503 if (
allocated(eq_i%det_T_EF)) eq_o%det_T_EF = eq_i%det_T_EF
504 if (
allocated(eq_i%det_T_FE)) eq_o%det_T_FE = eq_i%det_T_FE
508 if (
allocated(eq_i%g_C)) eq_o%g_C = eq_i%g_C
509 if (
allocated(eq_i%T_VC)) eq_o%T_VC = eq_i%T_VC
510 if (
allocated(eq_i%R_E)) eq_o%R_E = eq_i%R_E
511 if (
allocated(eq_i%Z_E)) eq_o%Z_E = eq_i%Z_E
512 if (
allocated(eq_i%l_E)) eq_o%l_E = eq_i%l_E
519 if (
allocated(eq_i%g_FD)) eq_o%g_FD = eq_i%g_FD
520 if (
allocated(eq_i%h_FD)) eq_o%h_FD = eq_i%h_FD
521 if (
allocated(eq_i%jac_FD)) eq_o%jac_FD = eq_i%jac_FD
522 if (
allocated(eq_i%S)) eq_o%S = eq_i%S
523 if (
allocated(eq_i%kappa_n)) eq_o%kappa_n = eq_i%kappa_n
524 if (
allocated(eq_i%kappa_g)) eq_o%kappa_g = eq_i%kappa_g
525 if (
allocated(eq_i%sigma)) eq_o%sigma = eq_i%sigma
541 real(dp) :: estim_mem_usage
546 estim_mem_usage = sum(eq%estim_mem_usage)
551 call dealloc_eq_1_final(eq)
561 &trim(
i2str(mem_diff))//
'kB deallocating eq_1 ('//&
562 &trim(
i2str(nint(100*mem_diff/&
564 &
'% of estimated)]',alert=.true.)
570 subroutine dealloc_eq_1_final(eq)
573 end subroutine dealloc_eq_1_final
587 real(dp) :: estim_mem_usage
592 estim_mem_usage = sum(eq%estim_mem_usage)
597 call dealloc_eq_2_final(eq)
607 &trim(
i2str(mem_diff))//
'kB deallocating eq_2 ('//&
608 &trim(
i2str(nint(100*mem_diff/&
610 &
'% of estimated)]',alert=.true.)
616 subroutine dealloc_eq_2_final(eq)
619 end subroutine dealloc_eq_2_final
Variables that have to do with equilibrium quantities and the grid used in the calculations:
real(dp), public r_0
independent normalization constant for nondimensionalization
subroutine init_eq_1(eq, grid, setup_e, setup_f)
Initializes new flux equilibrium.
subroutine dealloc_eq_2(eq)
Deallocates metric equilibrium quantities.
real(dp), public psi_0
derived normalization constant for nondimensionalization
real(dp), public max_flux_f
max. flux in Flux coordinates, set in calc_norm_range_PB3D_in
subroutine copy_eq_2(eq_i, grid_i, eq_o)
Deep copy of metric equilibrium variables.
real(dp), public t_0
derived normalization constant for nondimensionalization
real(dp), public max_flux_e
max. flux in Equilibrium coordinates, set in calc_norm_range_PB3D_in
real(dp), public rho_0
independent normalization constant for nondimensionalization
subroutine copy_eq_1(eq_i, grid_i, eq_o)
Deep copy of flux equilibrium variables.
subroutine dealloc_eq_1(eq)
Deallocates flux equilibrium quantities.
real(dp), public pres_0
independent normalization constant for nondimensionalization
real(dp), public vac_perm
either usual mu_0 (default) or normalized
real(dp), public b_0
derived normalization constant for nondimensionalization
subroutine init_eq_2(eq, grid, setup_e, setup_f)
Initializes new metric equilibrium.
integer, public n_alloc_eq_1s
nr. of allocated eq_1 variables
integer, public n_alloc_eq_2s
nr. of allocated eq_2 variables
Variables pertaining to the different grids used.
Numerical utilities related to giving output.
integer function, public get_mem_usage()
Returns the memory usage in kilobytes.
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Numerical variables used by most other modules.
integer, parameter, public dp
double precision
real(dp), parameter, public pi
logical, public print_mem_usage
print memory usage is printed
integer, parameter, public max_str_ln
maximum length of strings
real(dp), parameter, public mu_0_original
permeability of free space
integer, parameter, public max_deriv
highest derivatives for metric factors in Flux coords.
integer, public eq_style
either 1 (VMEC) or 2 (HELENA)
integer, public rank
MPI rank.
real(dp), parameter, public weight_dp
size of double precision in kB
elemental character(len=max_str_ln) function, public i2str(k)
Convert an integer to string.
elemental character(len=max_str_ln) function, public r2strt(k)
Convert a real (double) to string.