5 #include <PB3D_macros.h>
65 real(
dp),
pointer :: r_e(:) => null()
66 real(
dp),
pointer :: r_f(:) => null()
67 real(
dp),
pointer :: loc_r_e(:) => null()
68 real(
dp),
pointer :: loc_r_f(:) => null()
69 real(
dp),
pointer :: theta_e(:,:,:) => null()
70 real(
dp),
pointer :: theta_f(:,:,:) => null()
71 real(
dp),
pointer :: zeta_e(:,:,:) => null()
72 real(
dp),
pointer :: zeta_f(:,:,:) => null()
73 real(
dp),
allocatable :: trigon_factors(:,:,:,:,:)
75 real(
dp) :: estim_mem_usage
101 integer function init_grid(grid,n,i_lim,divided)
result(ierr)
105 character(*),
parameter :: rout_name =
'init_grid'
109 integer,
intent(in) :: n(3)
110 integer,
intent(in),
optional :: i_lim(2)
111 logical,
intent(in),
optional :: divided
114 character(len=max_str_ln) :: err_msg
115 logical :: divided_loc
121 if (
present(i_lim))
then
122 if (i_lim(2)-i_lim(1)+1.gt.n(3))
then
124 err_msg =
'The local nr. of normal points cannot be higher &
125 &than the total nr. of normal points'
136 divided_loc = .false.
137 if (
present(i_lim))
then
138 if (i_lim(2).lt.i_lim(1))
then
140 write(*,*)
'i_lim = ', i_lim
141 err_msg =
'faulty i_lim'
144 grid%i_min = i_lim(1)
145 grid%i_max = i_lim(2)
146 grid%loc_n_r = i_lim(2)-i_lim(1)+1
147 if (i_lim(2)-i_lim(1)+1.lt.n(3)) divided_loc = .true.
153 if (
present(divided)) divided_loc = divided
155 grid%divided = divided_loc
159 allocate(grid%r_E(n(3)))
160 allocate(grid%r_F(n(3)))
161 if (divided_loc)
then
162 allocate(grid%loc_r_E(grid%loc_n_r))
163 allocate(grid%loc_r_F(grid%loc_n_r))
165 grid%loc_r_E => grid%r_E
166 grid%loc_r_F => grid%r_F
176 if (n(1).ne.0 .and. n(2).ne.0)
then
177 allocate(grid%theta_E(n(1),n(2),grid%loc_n_r))
178 allocate(grid%zeta_E(n(1),n(2),grid%loc_n_r))
179 allocate(grid%theta_F(n(1),n(2),grid%loc_n_r))
180 allocate(grid%zeta_F(n(1),n(2),grid%loc_n_r))
185 &grid%loc_n_r*n(1)*n(2)*4
195 &
' - Expected memory usage of grid: '//&
196 &trim(
r2strt(grid%estim_mem_usage*weight_dp))//
' kB]',&
212 real(dp) :: estim_mem_usage
217 estim_mem_usage = grid%estim_mem_usage
222 deallocate(grid%r_E,grid%r_F)
223 if (grid%n(1).ne.0 .and. grid%n(2).ne.0)
then
224 deallocate(grid%theta_E,grid%zeta_E)
225 deallocate(grid%theta_F,grid%zeta_F)
227 if (grid%divided)
deallocate(grid%loc_r_E,grid%loc_r_F)
230 nullify(grid%r_E,grid%r_F)
231 nullify(grid%theta_E,grid%zeta_E)
232 nullify(grid%theta_F,grid%zeta_F)
233 nullify(grid%loc_r_E,grid%loc_r_F)
236 call dealloc_grid_final(grid)
246 &trim(
i2str(mem_diff))//
'kB deallocating grid ('//&
247 &trim(
i2str(nint(100*mem_diff/&
248 &(estim_mem_usage*weight_dp))))//&
249 &
'% of estimated)]',alert=.true.)
255 subroutine dealloc_grid_final(grid)
258 end subroutine dealloc_grid_final
266 integer function copy_grid(grid_i,grid_o)
result(ierr)
267 character(*),
parameter :: rout_name =
'copy_grid'
276 ierr =
init_grid(grid_o,grid_i%n,i_lim=[grid_i%i_min,grid_i%i_max],&
277 ÷d=grid_i%divided)
279 grid_o%r_E = grid_i%r_E
280 grid_o%r_F = grid_i%r_F
281 grid_o%loc_r_E = grid_i%loc_r_E
282 grid_o%loc_r_F = grid_i%loc_r_F
283 if (
associated(grid_i%theta_E)) grid_o%theta_E = grid_i%theta_E
284 if (
associated(grid_i%theta_F)) grid_o%theta_F = grid_i%theta_F
285 if (
associated(grid_i%zeta_E)) grid_o%zeta_E = grid_i%zeta_E
286 if (
associated(grid_i%zeta_F)) grid_o%zeta_F = grid_i%zeta_F
287 if (
allocated(grid_i%trigon_factors))
then
288 allocate(grid_o%trigon_factors(
size(grid_i%trigon_factors,1),&
289 &
size(grid_i%trigon_factors,2),
size(grid_i%trigon_factors,3),&
290 &
size(grid_i%trigon_factors,4),
size(grid_i%trigon_factors,5)))
291 grid_o%trigon_factors = grid_i%trigon_factors