PB3D [2.47]
Ideal linear high-n MHD stability in 3-D
Loading...
Searching...
No Matches
eq_vars.f90
Go to the documentation of this file.
1!------------------------------------------------------------------------------!
2!> Variables that have to do with equilibrium quantities and the grid used in
3!! the calculations:
4!! - The equilibrium variables are comprised of the variables that result from
5!! the equilibrium calculation, such as pressure, rotational transform, etc.
6!! - The flux variables are tabulated on a 1D grid.
7!! - The metric variables are tabulated on a 3D grid
8!! + In the normal coordinate, they are tabulated in the equilibrium grid.
9!! + In the angular coordinates, they are tabulated in the solution grid
10!! (VMEC), or in the equilibrium grid followed by an adaptation to the
11!! solution grid (HELENA).
12!! - However, this is not necessarily always the case, as it depends on the
13!! grid angles being aligned with the grid (e.g. Providing theta and zeta in
14!! the equilibrium grid so that the magnetic field lines are followed.
15!!
16!! \note In general in PB3D, there are two kinds of variables, differing from
17!! one another in the way in which they are tabulated:
18!! - variables tabulated on the full output grid of the equilibrium code
19!! - variables tabulated in an internal grid of this code
20!! \note In many places in the code a range in the normal coordinate is selected
21!! for each of the variables on different processes. This selection has to be
22!! done correctly and things can get a little bit complicated if trimmed grids
23!! are used (grids that have no overlap between processes).
24!!
25!! \see grid_ops()
26!------------------------------------------------------------------------------!
27module eq_vars
28#include <PB3D_macros.h>
30 use messages
32 use grid_vars, only: grid_type
33
34 implicit none
35 private
37#if ldebug
39#endif
40
41 ! global variables
42 real(dp) :: r_0 !< independent normalization constant for nondimensionalization
43 real(dp) :: pres_0 !< independent normalization constant for nondimensionalization
44 real(dp) :: rho_0 !< independent normalization constant for nondimensionalization
45 real(dp) :: b_0 !< derived normalization constant for nondimensionalization
46 real(dp) :: psi_0 !< derived normalization constant for nondimensionalization
47 real(dp) :: t_0 !< derived normalization constant for nondimensionalization
48 real(dp) :: vac_perm = mu_0_original !< either usual mu_0 (default) or normalized
49 real(dp) :: max_flux_e !< max. flux in Equilibrium coordinates, set in calc_norm_range_PB3D_in
50 real(dp) :: max_flux_f !< max. flux in Flux coordinates, set in calc_norm_range_PB3D_in
51#if ldebug
52 !> \ldebug
53 integer :: n_alloc_eq_1s !< nr. of allocated \c eq_1 variables
54 !> \ldebug
55 integer :: n_alloc_eq_2s !< nr. of allocated \c eq_2 variables
56#endif
57
58 !> flux equilibrium type
59 !!
60 !! The arrays here are of the form
61 !! - <tt>(r)</tt> for variables without derivs.
62 !! - <tt>(r,Dr)</tt> for variables with derivs.
63 type, public :: eq_1_type
64 real(dp), allocatable :: pres_e(:,:) !< pressure, and norm. deriv.
65 real(dp), allocatable :: q_saf_e(:,:) !< safety factor
66 real(dp), allocatable :: rot_t_e(:,:) !< rot. transform
67 real(dp), allocatable :: flux_p_e(:,:) !< poloidal flux and norm. deriv.
68 real(dp), allocatable :: flux_t_e(:,:) !< toroidal flux and norm. deriv.
69 real(dp), allocatable :: pres_fd(:,:) !< pressure, and norm. deriv.
70 real(dp), allocatable :: q_saf_fd(:,:) !< safety factor
71 real(dp), allocatable :: rot_t_fd(:,:) !< rot. transform
72 real(dp), allocatable :: flux_p_fd(:,:) !< poloidal flux and norm. deriv.
73 real(dp), allocatable :: flux_t_fd(:,:) !< toroidal flux and norm. deriv.
74 real(dp), allocatable :: rho(:) !< density
75#if ldebug
76 real(dp) :: estim_mem_usage(2) !< expected memory usage \ldebug
77#endif
78 contains
79 !> initialize
80 procedure :: init => init_eq_1
81 !> copy
82 procedure :: copy => copy_eq_1
83 !> deallocate
84 procedure :: dealloc => dealloc_eq_1
85 end type
86
87 !> metric equilibrium type
88 !!
89 !! The arrays here are of the form
90 !! - <tt>(angle_1,angle_2,r)</tt> for scalars without derivs.
91 !! - <tt>(angle_1,angle_2,r,D123)</tt> for scalars with derivs.
92 !! - <tt>(angle_1,angle_2,r,6/9,D1,D2,D3)</tt> for tensors with derivs.
93 !! \n where it is refered to the discussion of the grid type for an
94 !! explanation of the angles \c angle_1 and \c angle_2.
95 !!
96 !! The last index refers to the derivatives in coordinate 1, 2 and 3, which
97 !! refer to the coordinates described in \cite Weyens3D.
98 !! - For E(quilibrium) coordinates, they are
99 !! \f$\left(r,\theta,\zeta\right)_\text{E}\f$.
100 !! - For F(lux) coordinates, they are
101 !! \f$\left(\alpha,\psi,\gamma\right)_\text{F}\f$, where
102 !! + \f$\alpha = \zeta - q \theta\f$ and \f$\gamma = \theta\f$
103 !! for pol. flux,
104 !! + \f$\alpha = -\theta + \iota \zeta\f$ and \f$\gamma = \zeta\f$
105 !! Nfor tor. flux.
106 !!
107 !! The fourth index for tensorial variables correspond to the 9 or 6
108 !! (symmetric) different values:
109 !! \f[ \left( \begin{array}{ccc}1&4&7\\2&5&8\\3&6&9\end{array} \right) \
110 !! \text{or} \quad
111 !! \left( \begin{array}{ccc}1& & \\2&4& \\3&5&6\end{array} \right) \f]
112 !!
113 !! \note Fortran only allows for 7 dimensions in arrays.
114 type, public :: eq_2_type
115 ! coordinate variables R, Z and L (VMEC)
116 real(dp), allocatable :: r_e(:,:,:,:,:,:) !< R in E(quilibrium) coord
117 real(dp), allocatable :: z_e(:,:,:,:,:,:) !< Z in E(quilibrium) coords.
118 real(dp), allocatable :: l_e(:,:,:,:,:,:) !< L(ambda) in E(quilibrium) coords.
119 ! upper (h) and lower (g) metric factors
120 real(dp), allocatable :: g_c(:,:,:,:,:,:,:) !< in the C(ylindrical) coord. system
121 real(dp), allocatable :: g_e(:,:,:,:,:,:,:) !< in the E(quilibrium) coord. system
122 real(dp), allocatable :: h_e(:,:,:,:,:,:,:) !< in the E(quilibrium) coord. system
123 real(dp), allocatable :: g_f(:,:,:,:,:,:,:) !< in the F(lux) coord. system with derivs. in V(MEC) system
124 real(dp), allocatable :: h_f(:,:,:,:,:,:,:) !< in the F(lux) coord. system with derivs. in V(MEC) system
125 real(dp), allocatable :: g_fd(:,:,:,:,:,:,:) !< in the F(lux) coord. system with derivs in F(lux) system
126 real(dp), allocatable :: h_fd(:,:,:,:,:,:,:) !< in the F(lux) coord. system with derivs in F(lux) system
127 ! transformation matrices
128 real(dp), allocatable :: t_vc(:,:,:,:,:,:,:) !< C(ylindrical) to V(MEC)
129 real(dp), allocatable :: t_ef(:,:,:,:,:,:,:) !< E(quilibrium) to F(lux)
130 real(dp), allocatable :: t_fe(:,:,:,:,:,:,:) !< F(lux) to E(quilibrium)
131 ! determinants of transformation matrices
132 real(dp), allocatable :: det_t_ef(:,:,:,:,:,:) !< determinant of T_EF
133 real(dp), allocatable :: det_t_fe(:,:,:,:,:,:) !< determinant of T_FE
134 ! Jacobians
135 real(dp), allocatable :: jac_e(:,:,:,:,:,:) !< jacobian of E(quilibrium) coord. system
136 real(dp), allocatable :: jac_f(:,:,:,:,:,:) !< jacobian of F(lux) coord. system with derivs. in V(MEC) system
137 real(dp), allocatable :: jac_fd(:,:,:,:,:,:) !< jacobian of F(lux) coord. system with derivs. in F(lux) system
138 ! derived variables
139 real(dp), allocatable :: s(:,:,:) !< magnetic shear
140 real(dp), allocatable :: kappa_n(:,:,:) !< normal curvature
141 real(dp), allocatable :: kappa_g(:,:,:) !< geodesic curvature
142 real(dp), allocatable :: sigma(:,:,:) !< parallel current
143#if ldebug
144 real(dp) :: estim_mem_usage(2) !< expected memory usage \ldebug
145#endif
146 contains
147 !> initialize
148 procedure :: init => init_eq_2
149 !> copy
150 procedure :: copy => copy_eq_2
151 !> deallocate
152 procedure :: dealloc => dealloc_eq_2
153 end type
154
155contains
156 !> \public Initializes new flux equilibrium.
157 !!
158 !! The normal and angular grid can be in any coord. system, as only the grid
159 !! sizes are used, not the coordinate values.
160 !!
161 !! Optionally, it can be chosen individually whether the E or F(D)
162 !! quantities are allocated. D means that the derivatives are in F as well.
163 !! The rationale behind this is that the E quantities are only used in the
164 !! pre-perturbation phase.
165 !! \note
166 !! -# The E quantities are not written in eq_ops.print_output_eq().
167 !! -# The quantities that do not have a derivative are considered F
168 !! quantities. Alternatively, all quantities that have only one version,
169 !! are considered F quantities, such as \c rho, \c kappa_n, ...
170 !! -# The maximum derivative degree for flux quantities is one higher than
171 !! \c max_deriv, because the derivative of some of them appear in the
172 !! transformation matrices.
173 subroutine init_eq_1(eq,grid,setup_E,setup_F)
174 use num_vars, only: max_deriv
175#if ldebug
176 use num_vars, only: print_mem_usage, rank
177#endif
178
179 ! input / output
180 class(eq_1_type), intent(inout) :: eq !< equilibrium to be initialized
181 type(grid_type), intent(in) :: grid !< equilibrium grid
182 logical, intent(in), optional :: setup_E !< whether to set up E
183 logical, intent(in), optional :: setup_F !< whether to set up F
184
185 ! local variables
186 integer :: loc_n_r, n ! local and total nr. of normal points
187 logical :: setup_E_loc, setup_F_loc ! local versions of setup_E and setup_F
188#if ldebug
189 ! initialize memory usage
190 if (print_mem_usage) eq%estim_mem_usage = 0._dp
191#endif
192
193 ! setup local setup_E and setup_F
194 setup_e_loc = .true.
195 if (present(setup_e)) setup_e_loc = setup_e
196 setup_f_loc = .true.
197 if (present(setup_f)) setup_f_loc = setup_f
198
199 ! set local variables
200 loc_n_r = grid%loc_n_r
201 n = grid%n(3)
202
203 if (setup_e_loc) then
204 ! pres_E
205 allocate(eq%pres_E(loc_n_r,0:max_deriv+1))
206
207 ! q_saf_E
208 allocate(eq%q_saf_E(loc_n_r,0:max_deriv+1))
209
210 ! rot_t_E
211 allocate(eq%rot_t_E(loc_n_r,0:max_deriv+1))
212
213 ! flux_p_E
214 allocate(eq%flux_p_E(loc_n_r,0:max_deriv+1))
215
216 ! flux_t_E
217 allocate(eq%flux_t_E(loc_n_r,0:max_deriv+1))
218
219#if ldebug
220 ! set estimated memory usage
221 if (print_mem_usage) eq%estim_mem_usage(1) = &
222 &eq%estim_mem_usage(1) + loc_n_r*(max_deriv+2)*5
223#endif
224 end if
225
226 if (setup_f_loc) then
227 ! pres_FD
228 allocate(eq%pres_FD(loc_n_r,0:max_deriv+1))
229
230 ! flux_p_FD
231 allocate(eq%flux_p_FD(loc_n_r,0:max_deriv+1))
232
233 ! flux_t_FD
234 allocate(eq%flux_t_FD(loc_n_r,0:max_deriv+1))
235
236 ! q_saf_FD
237 allocate(eq%q_saf_FD(loc_n_r,0:max_deriv+1))
238
239 ! rot_t_FD
240 allocate(eq%rot_t_FD(loc_n_r,0:max_deriv+1))
241
242 ! rho
243 allocate(eq%rho(grid%loc_n_r))
244
245#if ldebug
246 ! set estimated memory usage
247 if (print_mem_usage) eq%estim_mem_usage(2) = &
248 &eq%estim_mem_usage(2) + loc_n_r*((max_deriv+2)*5+1)
249#endif
250 end if
251
252#if ldebug
253 ! increment n_alloc_eq_1s
255
256 ! print memory usage
257 if (print_mem_usage) call writo('[rank '//trim(i2str(rank))//&
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]',&
261 &alert=.true.)
262#endif
263 end subroutine init_eq_1
264
265 !> \public Initializes new metric equilibrium.
266 !!
267 !! \see For explanation see init_eq_1().
268 !!
269 !! \note The maximum derivative degree for R, Z and lambda is one higher
270 !! than \c max_deriv, because their first derivative already appears in g_C
271 !! and h_C.
272 subroutine init_eq_2(eq,grid,setup_E,setup_F) ! metric version
273 use num_vars, only: max_deriv, eq_style
274#if ldebug
275 use num_vars, only: print_mem_usage, rank
276#endif
277
278 ! input / output
279 class(eq_2_type), intent(inout) :: eq !< equilibrium to be initialized
280 type(grid_type), intent(in) :: grid !< equilibrium grid
281 logical, intent(in), optional :: setup_E !< whether to set up E
282 logical, intent(in), optional :: setup_F !< whether to set up F
283
284 ! local variables
285 logical :: setup_E_loc, setup_F_loc ! local versions of setup_E and setup_F
286 integer :: dims(3) ! dimensions
287
288 ! set up local variables
289 dims = [grid%n(1),grid%n(2),grid%loc_n_r]
290
291#if ldebug
292 ! initialize memory usage
293 if (print_mem_usage) eq%estim_mem_usage = 0._dp
294#endif
295
296 ! setup local setup_E and setup_F
297 setup_e_loc = .true.
298 if (present(setup_e)) setup_e_loc = setup_e
299 setup_f_loc = .true.
300 if (present(setup_f)) setup_f_loc = setup_f
301
302 if (setup_e_loc) then
303 ! initialize variables that are used for all equilibrium styles
304 ! g_E
305 allocate(eq%g_E(dims(1),dims(2),dims(3),6,&
307
308 ! h_E
309 allocate(eq%h_E(dims(1),dims(2),dims(3),6,&
311
312 ! g_F
313 allocate(eq%g_F(dims(1),dims(2),dims(3),6,&
315
316 ! h_F
317 allocate(eq%h_F(dims(1),dims(2),dims(3),6,&
319
320 ! jac_E
321 allocate(eq%jac_E(dims(1),dims(2),dims(3),&
323
324 ! jac_F
325 allocate(eq%jac_F(dims(1),dims(2),dims(3),&
327
328 ! T_EF
329 allocate(eq%T_EF(dims(1),dims(2),dims(3),9,&
331
332 ! T_FE
333 allocate(eq%T_FE(dims(1),dims(2),dims(3),9,&
335
336 ! det_T_EF
337 allocate(eq%det_T_EF(dims(1),dims(2),dims(3),&
339
340 ! det_T_FE
341 allocate(eq%det_T_FE(dims(1),dims(2),dims(3),&
343
344#if ldebug
345 ! set estimated memory usage
346 if (print_mem_usage) eq%estim_mem_usage(1) = &
347 &eq%estim_mem_usage(1) + product(dims)*&
348 &((max_deriv+1)**3*(4*6+2*9+4))
349#endif
350
351 ! initialize variables that are specificic to which equilibrium
352 ! style is being used:
353 ! 1: VMEC
354 ! 2: HELENA
355 select case (eq_style)
356 case (1) ! VMEC
357 ! g_C
358 allocate(eq%g_C(dims(1),dims(2),dims(3),6,&
360
361 ! T_VC
362 allocate(eq%T_VC(dims(1),dims(2),dims(3),9,&
364
365 ! R
366 allocate(eq%R_E(dims(1),dims(2),dims(3),&
367 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+1))
368
369 ! Z
370 allocate(eq%Z_E(dims(1),dims(2),dims(3),&
371 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+1))
372
373 ! lambda
374 allocate(eq%L_E(dims(1),dims(2),dims(3),&
375 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+1))
376
377#if ldebug
378 ! set estimated memory usage
379 if (print_mem_usage) eq%estim_mem_usage(1) = &
380 &eq%estim_mem_usage(1) + product(dims)*(&
381 &(max_deriv+1)**3*(1*6+1*9+2) + &
382 &(max_deriv+2)**3*(3))
383#endif
384 case (2) ! HELENA
385 ! do nothing
386 end select
387 end if
388
389 if (setup_f_loc) then
390 ! initialize variables that are used for all equilibrium styles
391 ! g_FD
392 allocate(eq%g_FD(dims(1),dims(2),dims(3),6,&
394
395 ! h_FD
396 allocate(eq%h_FD(dims(1),dims(2),dims(3),6,&
398
399 ! jac_FD
400 allocate(eq%jac_FD(dims(1),dims(2),dims(3),&
402
403 ! magnetic shear
404 allocate(eq%S(dims(1),dims(2),dims(3)))
405
406 ! normal curvature
407 allocate(eq%kappa_n(dims(1),dims(2),dims(3)))
408
409 ! geodesic curvature
410 allocate(eq%kappa_g(dims(1),dims(2),dims(3)))
411
412 ! parallel current
413 allocate(eq%sigma(dims(1),dims(2),dims(3)))
414
415#if ldebug
416 ! set estimated memory usage
417 if (print_mem_usage) eq%estim_mem_usage(2) = &
418 &eq%estim_mem_usage(2) + product(dims)*(&
419 &(max_deriv+1)**3*(2*6+1) + &
420 &4)
421#endif
422 end if
423
424#if ldebug
425 ! increment n_alloc_eq_2s
427
428 ! print memory usage
429 if (print_mem_usage) call writo('[rank '//trim(i2str(rank))//&
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]',&
433 &alert=.true.)
434#endif
435 end subroutine init_eq_2
436
437 !> \public Deep copy of flux equilibrium variables.
438 subroutine copy_eq_1(eq_i,grid_i,eq_o)
439 use grid_vars, only: grid_type
440
441 ! input / output
442 class(eq_1_type), intent(in) :: eq_i !< eq_1 to be copied
443 type(grid_type), intent(in) :: grid_i !< grid of eq_i
444 type(eq_1_type), intent(inout) :: eq_o !< copied eq_1
445
446 ! local variables
447 logical :: setup_E
448 logical :: setup_F
449
450 setup_e = allocated(eq_i%pres_E)
451 setup_f = allocated(eq_i%pres_FD)
452
453 call eq_o%init(grid_i,setup_e=setup_e,setup_f=setup_f)
454
455 if (setup_e) then
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
461 end if
462
463 if (setup_f) then
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
470 end if
471 end subroutine copy_eq_1
472
473 !> \public Deep copy of metric equilibrium variables.
474 !!
475 !! \return ierr
476 subroutine copy_eq_2(eq_i,grid_i,eq_o)
477 use num_vars, only: eq_style
478 use grid_vars, only: grid_type
479
480 ! input / output
481 class(eq_2_type), intent(in) :: eq_i !< eq_2 to be copied
482 type(grid_type), intent(in) :: grid_i !< grid of eq_i
483 type(eq_2_type), intent(inout) :: eq_o !< copied eq_1
484
485 ! local variables
486 logical :: setup_E
487 logical :: setup_F
488
489 setup_e = allocated(eq_i%jac_E)
490 setup_f = allocated(eq_i%jac_FD)
491
492 call eq_o%init(grid_i,setup_e=setup_e,setup_f=setup_f)
493
494 if (setup_e) then
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
505
506 select case (eq_style)
507 case (1) ! VMEC
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
513 case (2) ! HELENA
514 ! do nothing
515 end select
516 end if
517
518 if (setup_f) then
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
526 end if
527 end subroutine copy_eq_2
528
529 !> \public Deallocates flux equilibrium quantities.
530 subroutine dealloc_eq_1(eq)
531#if ldebug
532 use num_vars, only: rank, print_mem_usage
533#endif
534
535 ! input / output
536 class(eq_1_type), intent(inout) :: eq !< equilibrium to be deallocated
537
538#if ldebug
539 ! local variables
540 integer :: mem_diff ! difference in memory
541 real(dp) :: estim_mem_usage ! estimated memory usage
542
543 ! memory usage before deallocation
544 if (print_mem_usage) then
545 mem_diff = get_mem_usage()
546 estim_mem_usage = sum(eq%estim_mem_usage)
547 end if
548#endif
549
550 ! deallocate allocatable variables
551 call dealloc_eq_1_final(eq)
552
553#if ldebug
554 ! decrement n_alloc_eq_1s
556
557 ! memory usage difference after deallocation
558 if (print_mem_usage) then
559 mem_diff = mem_diff - get_mem_usage()
560 call writo('[Rank '//trim(i2str(rank))//' - liberated '//&
561 &trim(i2str(mem_diff))//'kB deallocating eq_1 ('//&
562 &trim(i2str(nint(100*mem_diff/&
563 &(estim_mem_usage*weight_dp))))//&
564 &'% of estimated)]',alert=.true.)
565 end if
566#endif
567 contains
568 ! Note: intent(out) automatically deallocates the variable
569 !> \private
570 subroutine dealloc_eq_1_final(eq)
571 ! input / output
572 type(eq_1_type), intent(out) :: eq ! equilibrium to be deallocated
573 end subroutine dealloc_eq_1_final
574 end subroutine dealloc_eq_1
575
576 !> \public Deallocates metric equilibrium quantities.
577 subroutine dealloc_eq_2(eq)
578#if ldebug
579 use num_vars, only: rank, print_mem_usage
580#endif
581 ! input / output
582 class(eq_2_type), intent(inout) :: eq !< equilibrium to be deallocated
583
584#if ldebug
585 ! local variables
586 integer :: mem_diff ! difference in memory
587 real(dp) :: estim_mem_usage ! estimated memory usage
588
589 ! memory usage before deallocation
590 if (print_mem_usage) then
591 mem_diff = get_mem_usage()
592 estim_mem_usage = sum(eq%estim_mem_usage)
593 end if
594#endif
595
596 ! deallocate allocatable variables
597 call dealloc_eq_2_final(eq)
598
599#if ldebug
600 ! decrement n_alloc_eq_2s
602
603 ! memory usage difference after deallocation
604 if (print_mem_usage) then
605 mem_diff = mem_diff - get_mem_usage()
606 call writo('[Rank '//trim(i2str(rank))//' - liberated '//&
607 &trim(i2str(mem_diff))//'kB deallocating eq_2 ('//&
608 &trim(i2str(nint(100*mem_diff/&
609 &(estim_mem_usage*weight_dp))))//&
610 &'% of estimated)]',alert=.true.)
611 end if
612#endif
613 contains
614 ! Note: intent(out) automatically deallocates the variable
615 !> \private
616 subroutine dealloc_eq_2_final(eq)
617 ! input / output
618 type(eq_2_type), intent(out) :: eq ! equilibrium to be deallocated
619 end subroutine dealloc_eq_2_final
620 end subroutine dealloc_eq_2
621end module eq_vars
Variables that have to do with equilibrium quantities and the grid used in the calculations:
Definition eq_vars.f90:27
real(dp), public r_0
independent normalization constant for nondimensionalization
Definition eq_vars.f90:42
subroutine init_eq_1(eq, grid, setup_e, setup_f)
Initializes new flux equilibrium.
Definition eq_vars.f90:174
subroutine dealloc_eq_2(eq)
Deallocates metric equilibrium quantities.
Definition eq_vars.f90:578
real(dp), public psi_0
derived normalization constant for nondimensionalization
Definition eq_vars.f90:46
real(dp), public max_flux_f
max. flux in Flux coordinates, set in calc_norm_range_PB3D_in
Definition eq_vars.f90:50
subroutine copy_eq_2(eq_i, grid_i, eq_o)
Deep copy of metric equilibrium variables.
Definition eq_vars.f90:477
real(dp), public t_0
derived normalization constant for nondimensionalization
Definition eq_vars.f90:47
real(dp), public max_flux_e
max. flux in Equilibrium coordinates, set in calc_norm_range_PB3D_in
Definition eq_vars.f90:49
real(dp), public rho_0
independent normalization constant for nondimensionalization
Definition eq_vars.f90:44
subroutine copy_eq_1(eq_i, grid_i, eq_o)
Deep copy of flux equilibrium variables.
Definition eq_vars.f90:439
subroutine dealloc_eq_1(eq)
Deallocates flux equilibrium quantities.
Definition eq_vars.f90:531
real(dp), public pres_0
independent normalization constant for nondimensionalization
Definition eq_vars.f90:43
real(dp), public vac_perm
either usual mu_0 (default) or normalized
Definition eq_vars.f90:48
real(dp), public b_0
derived normalization constant for nondimensionalization
Definition eq_vars.f90:45
subroutine init_eq_2(eq, grid, setup_e, setup_f)
Initializes new metric equilibrium.
Definition eq_vars.f90:273
integer, public n_alloc_eq_1s
nr. of allocated eq_1 variables
Definition eq_vars.f90:53
integer, public n_alloc_eq_2s
nr. of allocated eq_2 variables
Definition eq_vars.f90:55
Variables pertaining to the different grids used.
Definition grid_vars.f90:4
Numerical utilities related to giving output.
Definition messages.f90:4
integer function, public get_mem_usage()
Returns the memory usage in kilobytes.
Definition messages.f90:554
subroutine, public writo(input_str, persistent, error, warning, alert)
Write output to file identified by output_i.
Definition messages.f90:275
Numerical variables used by most other modules.
Definition num_vars.f90:4
integer, parameter, public dp
double precision
Definition num_vars.f90:46
real(dp), parameter, public pi
Definition num_vars.f90:83
logical, public print_mem_usage
print memory usage is printed
Definition num_vars.f90:149
integer, parameter, public max_str_ln
maximum length of strings
Definition num_vars.f90:50
real(dp), parameter, public mu_0_original
permeability of free space
Definition num_vars.f90:84
integer, parameter, public max_deriv
highest derivatives for metric factors in Flux coords.
Definition num_vars.f90:52
integer, public eq_style
either 1 (VMEC) or 2 (HELENA)
Definition num_vars.f90:89
integer, public rank
MPI rank.
Definition num_vars.f90:68
real(dp), parameter, public weight_dp
size of double precision in kB
Definition num_vars.f90:49
Operations on strings.
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.
flux equilibrium type
Definition eq_vars.f90:63
metric equilibrium type
Definition eq_vars.f90:114
Type for grids.
Definition grid_vars.f90:59