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)
173 subroutine init_eq_1(eq,grid,setup_E,setup_F)
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]',&
272 subroutine init_eq_2(eq,grid,setup_E,setup_F)
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,&
306 &0:max_deriv,0:max_deriv,0:max_deriv))
309 allocate(eq%h_E(dims(1),dims(2),dims(3),6,&
310 &0:max_deriv,0:max_deriv,0:max_deriv))
313 allocate(eq%g_F(dims(1),dims(2),dims(3),6,&
314 &0:max_deriv,0:max_deriv,0:max_deriv))
317 allocate(eq%h_F(dims(1),dims(2),dims(3),6,&
318 &0:max_deriv,0:max_deriv,0:max_deriv))
321 allocate(eq%jac_E(dims(1),dims(2),dims(3),&
322 &0:max_deriv,0:max_deriv,0:max_deriv))
325 allocate(eq%jac_F(dims(1),dims(2),dims(3),&
326 &0:max_deriv,0:max_deriv,0:max_deriv))
329 allocate(eq%T_EF(dims(1),dims(2),dims(3),9,&
330 &0:max_deriv,0:max_deriv,0:max_deriv))
333 allocate(eq%T_FE(dims(1),dims(2),dims(3),9,&
334 &0:max_deriv,0:max_deriv,0:max_deriv))
337 allocate(eq%det_T_EF(dims(1),dims(2),dims(3),&
338 &0:max_deriv,0:max_deriv,0:max_deriv))
341 allocate(eq%det_T_FE(dims(1),dims(2),dims(3),&
342 &0:max_deriv,0:max_deriv,0:max_deriv))
347 &eq%estim_mem_usage(1) + product(dims)*&
348 &((max_deriv+1)**3*(4*6+2*9+4))
355 select case (eq_style)
358 allocate(eq%g_C(dims(1),dims(2),dims(3),6,&
359 &0:max_deriv,0:max_deriv,0:max_deriv))
362 allocate(eq%T_VC(dims(1),dims(2),dims(3),9,&
363 &0:max_deriv,0:max_deriv,0:max_deriv))
366 allocate(eq%R_E(dims(1),dims(2),dims(3),&
367 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+1))
370 allocate(eq%Z_E(dims(1),dims(2),dims(3),&
371 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+1))
374 allocate(eq%L_E(dims(1),dims(2),dims(3),&
375 &0:max_deriv+1,0:max_deriv+1,0:max_deriv+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))
389 if (setup_f_loc)
then
392 allocate(eq%g_FD(dims(1),dims(2),dims(3),6,&
393 &0:max_deriv,0:max_deriv,0:max_deriv))
396 allocate(eq%h_FD(dims(1),dims(2),dims(3),6,&
397 &0:max_deriv,0:max_deriv,0:max_deriv))
400 allocate(eq%jac_FD(dims(1),dims(2),dims(3),&
401 &0:max_deriv,0:max_deriv,0:max_deriv))
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)*(&
419 &(max_deriv+1)**3*(2*6+1) + &
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/&
563 &(estim_mem_usage*weight_dp))))//&
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/&
609 &(estim_mem_usage*weight_dp))))//&
610 &
'% of estimated)]',alert=.true.)
616 subroutine dealloc_eq_2_final(eq)
619 end subroutine dealloc_eq_2_final