5 #include <PB3D_macros.h>
37 integer,
allocatable :: n(:,:)
38 integer,
allocatable :: m(:,:)
39 integer,
allocatable :: sec(:,:)
53 integer :: lim_sec_x(2)
54 integer,
allocatable :: n(:,:)
55 integer,
allocatable :: m(:,:)
56 complex(dp),
allocatable :: u_0(:,:,:,:)
57 complex(dp),
allocatable :: u_1(:,:,:,:)
58 complex(dp),
allocatable :: du_0(:,:,:,:)
59 complex(dp),
allocatable :: du_1(:,:,:,:)
61 real(
dp) :: estim_mem_usage
83 integer :: lim_sec_x(2,2)
84 integer,
allocatable :: n_1(:,:)
85 integer,
allocatable :: n_2(:,:)
86 integer,
allocatable :: m_1(:,:)
87 integer,
allocatable :: m_2(:,:)
88 complex(dp),
allocatable :: pv_0(:,:,:,:)
89 complex(dp),
allocatable :: pv_1(:,:,:,:)
90 complex(dp),
allocatable :: pv_2(:,:,:,:)
91 complex(dp),
allocatable :: kv_0(:,:,:,:)
92 complex(dp),
allocatable :: kv_1(:,:,:,:)
93 complex(dp),
allocatable :: kv_2(:,:,:,:)
95 real(
dp) :: estim_mem_usage
118 module procedure set_nm_x_1
120 module procedure set_nm_x_2
144 subroutine set_nm_x_1(mds,grid_X,lim_sec_X_o,n_X_loc,m_X_loc,lim_sec_X_i)
149 integer,
intent(inout) :: lim_sec_X_o(2)
150 integer,
intent(inout),
allocatable :: n_X_loc(:,:)
151 integer,
intent(inout),
allocatable :: m_X_loc(:,:)
152 integer,
intent(in),
optional :: lim_sec_X_i(2)
156 if (
present(lim_sec_x_i)) lim_sec_x_o = lim_sec_x_i
159 allocate(n_x_loc(grid_x%loc_n_r,lim_sec_x_o(2)-lim_sec_x_o(1)+1))
160 allocate(m_x_loc(grid_x%loc_n_r,lim_sec_x_o(2)-lim_sec_x_o(1)+1))
161 n_x_loc = mds%n(grid_x%i_min:grid_x%i_max,&
162 &lim_sec_x_o(1):lim_sec_x_o(2))
163 m_x_loc = mds%m(grid_x%i_min:grid_x%i_max,&
164 &lim_sec_x_o(1):lim_sec_x_o(2))
165 end subroutine set_nm_x_1
167 subroutine set_nm_x_2(mds,grid_X,lim_sec_X_o,n_X_1,m_X_1,n_X_2,m_X_2,&
173 integer,
intent(inout) :: lim_sec_X_o(2,2)
174 integer,
intent(inout),
allocatable :: n_X_1(:,:)
175 integer,
intent(inout),
allocatable :: m_X_1(:,:)
176 integer,
intent(inout),
allocatable :: n_X_2(:,:)
177 integer,
intent(inout),
allocatable :: m_X_2(:,:)
178 integer,
intent(in),
optional :: lim_sec_X_i(2,2)
181 if (
present(lim_sec_x_i))
then
182 call set_nm_x(mds,grid_x,lim_sec_x_o(:,1),n_x_1,m_x_1,&
184 call set_nm_x(mds,grid_x,lim_sec_x_o(:,2),n_x_2,m_x_2,&
187 call set_nm_x(mds,grid_x,lim_sec_x_o(:,1),n_x_1,m_x_1)
188 call set_nm_x(mds,grid_x,lim_sec_x_o(:,2),n_x_2,m_x_2)
190 end subroutine set_nm_x_2
203 subroutine init_x_1(X,mds,grid_X,lim_sec_X)
212 integer,
intent(in),
optional :: lim_sec_X(2)
216 integer :: n_par, n_geo
219 loc_n_r = grid_x%loc_n_r
229 call set_nm_x(mds,grid_x,x%lim_sec_X,x%n,x%m,lim_sec_x)
232 x%n_mod =
size(x%n,2)
235 allocate(x%U_0(n_par,n_geo,loc_n_r,x%n_mod))
238 allocate(x%U_1(n_par,n_geo,loc_n_r,x%n_mod))
241 allocate(x%DU_0(n_par,n_geo,loc_n_r,x%n_mod))
244 allocate(x%DU_1(n_par,n_geo,loc_n_r,x%n_mod))
249 &(n_par*n_geo*loc_n_r)*(x%n_mod*4)
256 &
' - Expected memory usage of X_1: '//&
257 &trim(
r2strt(x%estim_mem_usage*weight_dp*2))//
' kB]',alert=.true.)
270 subroutine init_x_2(X,mds,grid_X,lim_sec_X,is_field_averaged)
279 integer,
intent(in),
optional :: lim_sec_X(2,2)
280 logical,
intent(in),
optional :: is_field_averaged
284 integer :: n_par, n_geo
289 if (
present(is_field_averaged))
then
290 if (is_field_averaged) n_par = 1
293 loc_n_r = grid_x%loc_n_r
301 call set_nm_x(mds,grid_x,x%lim_sec_X,x%n_1,x%m_1,x%n_2,x%m_2,lim_sec_x)
304 x%n_mod(1) =
size(x%n_1,2)
305 x%n_mod(2) =
size(x%n_2,2)
311 allocate(x%PV_0(n_par,n_geo,loc_n_r,nn_mod))
312 allocate(x%PV_1(n_par,n_geo,loc_n_r,product(x%n_mod)))
313 allocate(x%PV_2(n_par,n_geo,loc_n_r,nn_mod))
316 allocate(x%KV_0(n_par,n_geo,loc_n_r,nn_mod))
317 allocate(x%KV_1(n_par,n_geo,loc_n_r,product(x%n_mod)))
318 allocate(x%KV_2(n_par,n_geo,loc_n_r,nn_mod))
323 &x%estim_mem_usage + (n_par*n_geo*loc_n_r)*&
324 &(nn_mod*4+product(x%n_mod)*2) + product(x%n_mod)
331 &
' - Expected memory usage of X_2: '//&
332 &trim(
r2strt(x%estim_mem_usage*weight_dp*2))//
' kB]',alert=.true.)
337 subroutine copy_x_1(X_i,mds,grid_i,X_o)
344 type(
x_1_type),
intent(inout) :: X_o
346 call x_o%init(mds,grid_i,lim_sec_x=x_i%lim_sec_X)
358 subroutine copy_x_2(X_i,mds,grid_i,X_o)
365 type(
x_2_type),
intent(inout) :: X_o
367 call x_o%init(mds,grid_i,lim_sec_x=x_i%lim_sec_X,&
368 &is_field_averaged=
size(x_i%PV_0,1).eq.1)
382 integer function set_nn_mod(sym,lim_sec_X)
result(nn_mod)
384 logical,
intent(in) :: sym
385 integer,
intent(in),
optional :: lim_sec_x(2,2)
389 integer :: lim_sec_x_loc(2,2)
392 lim_sec_x_loc(:,1) = [1,
n_mod_x]
393 lim_sec_x_loc(:,2) = [1,
n_mod_x]
394 if (
present(lim_sec_x)) lim_sec_x_loc = lim_sec_x
399 do jd = lim_sec_x_loc(1,2),lim_sec_x_loc(2,2)
400 do id = lim_sec_x_loc(1,1),lim_sec_x_loc(2,1)
401 if (id.ge.jd) nn_mod = nn_mod + 1
406 nn_mod = product(lim_sec_x_loc(2,:)-lim_sec_x_loc(1,:)+1)
416 call dealloc_mds_final(mds)
420 subroutine dealloc_mds_final(mds)
423 end subroutine dealloc_mds_final
438 real(dp) :: estim_mem_usage
443 estim_mem_usage = x%estim_mem_usage
448 call dealloc_x_1_final(x)
458 &trim(
i2str(mem_diff))//
'kB deallocating X_1 ('//&
459 &trim(
i2str(nint(100*mem_diff/&
460 &(estim_mem_usage*weight_dp*2))))//&
461 &
'% of estimated)]',alert=.true.)
467 subroutine dealloc_x_1_final(X)
470 end subroutine dealloc_x_1_final
484 real(dp) :: estim_mem_usage
489 estim_mem_usage = x%estim_mem_usage
494 call dealloc_x_2_final(x)
504 &trim(
i2str(mem_diff))//
'kB deallocating X_2 ('//&
505 &trim(
i2str(nint(100*mem_diff/&
506 &(estim_mem_usage*weight_dp*2))))//&
507 &
'% of estimated)]',alert=.true.)
513 subroutine dealloc_x_2_final(X)
516 end subroutine dealloc_x_2_final