PB3D  [2.45]
Ideal linear high-n MHD stability in 3-D
PB3D_utilities.f90
Go to the documentation of this file.
1 !------------------------------------------------------------------------------!
3 !------------------------------------------------------------------------------!
5 #include <PB3D_macros.h>
6  use str_utilities
7  use messages
8  use num_vars, only: dp, pi, max_str_ln, max_name_ln
9  use hdf5_vars, only: var_1d_type
10 
11  implicit none
12  private
14 
15  ! interfaces
16 
21  interface conv_1d2nd
23  module procedure conv_1d2nd_1d
25  module procedure conv_1d2nd_2d
27  module procedure conv_1d2nd_3d
29  module procedure conv_1d2nd_4d
31  module procedure conv_1d2nd_6d
33  module procedure conv_1d2nd_7d
34  end interface
35 
36 contains
38  subroutine conv_1d2nd_1d(var_in,var_out)
39  ! input / output
40  type(var_1d_type), intent(in) :: var_in
41  real(dp), intent(inout), allocatable :: var_out(:)
42 
43  ! allocate and copy variable
44  if (allocated(var_out)) deallocate(var_out)
45  allocate(var_out(var_in%tot_i_min(1):var_in%tot_i_max(1)))
46  var_out = reshape(var_in%p,shape(var_out))
47  end subroutine conv_1d2nd_1d
49  subroutine conv_1d2nd_2d(var_in,var_out)
50  ! input / output
51  type(var_1d_type), intent(in) :: var_in
52  real(dp), intent(inout), allocatable :: var_out(:,:)
53 
54  ! allocate and copy variable
55  if (allocated(var_out)) deallocate(var_out)
56  allocate(var_out(&
57  &var_in%tot_i_min(1):var_in%tot_i_max(1),&
58  &var_in%tot_i_min(2):var_in%tot_i_max(2)))
59  var_out = reshape(var_in%p,[&
60  &var_in%tot_i_max(1)-var_in%tot_i_min(1)+1,&
61  &var_in%tot_i_max(2)-var_in%tot_i_min(2)+1])
62  end subroutine conv_1d2nd_2d
64  subroutine conv_1d2nd_3d(var_in,var_out)
65  ! input / output
66  type(var_1d_type), intent(in) :: var_in
67  real(dp), intent(inout), allocatable :: var_out(:,:,:)
68 
69  ! allocate and copy variable
70  if (allocated(var_out)) deallocate(var_out)
71  allocate(var_out(&
72  &var_in%tot_i_min(1):var_in%tot_i_max(1),&
73  &var_in%tot_i_min(2):var_in%tot_i_max(2),&
74  &var_in%tot_i_min(3):var_in%tot_i_max(3)))
75  var_out = reshape(var_in%p,shape(var_out))
76  end subroutine conv_1d2nd_3d
78  subroutine conv_1d2nd_4d(var_in,var_out)
79  ! input / output
80  type(var_1d_type), intent(in) :: var_in
81  real(dp), intent(inout), allocatable :: var_out(:,:,:,:)
82 
83  ! allocate and copy variable
84  if (allocated(var_out)) deallocate(var_out)
85  allocate(var_out(&
86  &var_in%tot_i_min(1):var_in%tot_i_max(1),&
87  &var_in%tot_i_min(2):var_in%tot_i_max(2),&
88  &var_in%tot_i_min(3):var_in%tot_i_max(3),&
89  &var_in%tot_i_min(4):var_in%tot_i_max(4)))
90  var_out = reshape(var_in%p,shape(var_out))
91  end subroutine conv_1d2nd_4d
93  subroutine conv_1d2nd_6d(var_in,var_out)
94  ! input / output
95  type(var_1d_type), intent(in) :: var_in
96  real(dp), intent(inout), allocatable :: var_out(:,:,:,:,:,:)
97 
98  ! allocate and copy variable
99  if (allocated(var_out)) deallocate(var_out)
100  allocate(var_out(&
101  &var_in%tot_i_min(1):var_in%tot_i_max(1),&
102  &var_in%tot_i_min(2):var_in%tot_i_max(2),&
103  &var_in%tot_i_min(3):var_in%tot_i_max(3),&
104  &var_in%tot_i_min(4):var_in%tot_i_max(4),&
105  &var_in%tot_i_min(5):var_in%tot_i_max(5),&
106  &var_in%tot_i_min(6):var_in%tot_i_max(6)))
107  var_out = reshape(var_in%p,shape(var_out))
108  end subroutine conv_1d2nd_6d
110  subroutine conv_1d2nd_7d(var_in,var_out)
111  ! input / output
112  type(var_1d_type), intent(in) :: var_in
113  real(dp), intent(inout), allocatable :: var_out(:,:,:,:,:,:,:)
114 
115  ! allocate and copy variable
116  if (allocated(var_out)) deallocate(var_out)
117  allocate(var_out(&
118  &var_in%tot_i_min(1):var_in%tot_i_max(1),&
119  &var_in%tot_i_min(2):var_in%tot_i_max(2),&
120  &var_in%tot_i_min(3):var_in%tot_i_max(3),&
121  &var_in%tot_i_min(4):var_in%tot_i_max(4),&
122  &var_in%tot_i_min(5):var_in%tot_i_max(5),&
123  &var_in%tot_i_min(6):var_in%tot_i_max(6),&
124  &var_in%tot_i_min(7):var_in%tot_i_max(7)))
125  var_out = reshape(var_in%p,shape(var_out))
126  end subroutine conv_1d2nd_7d
127 
179  function setup_par_id(grid,rich_lvl_max,rich_lvl_loc,tot_rich,par_lim,&
180  &par_id_mem) result(par_id)
181  use grid_vars, only: grid_type
182 
183  ! input / output
184  type(grid_type), intent(in) :: grid
185  integer, intent(in) :: rich_lvl_max
186  integer, intent(in) :: rich_lvl_loc
187  logical, intent(in), optional :: tot_rich
188  integer, intent(in), optional :: par_lim(2)
189  integer, intent(inout), optional :: par_id_mem(2)
190  integer :: par_id(3)
191 
192  ! local variables
193  integer :: s ! stride
194  integer :: p ! lower limit in memory
195  integer :: n ! b-a+1
196  logical :: tot_rich_loc ! local tot_rich
197  integer :: par_lim_loc(2) ! local par_lim
198 
199  ! set up local tot_rich and par_lim
200  tot_rich_loc = .false.
201  if (present(tot_rich) .and. rich_lvl_max.gt.1) tot_rich_loc = tot_rich ! only for higher Richardson levels
202  par_lim_loc = [1,grid%n(1)]
203  if (present(par_lim)) par_lim_loc = par_lim
204 
205  ! set up parallel indices
206  n = par_lim_loc(2)-par_lim_loc(1)+1
207  if (tot_rich_loc) then
208  if (rich_lvl_loc.eq.1) then
209  s = 2**(rich_lvl_max-1)
210  p = 1
211  else
212  s = 2**(rich_lvl_max+1-rich_lvl_loc)
213  p = 1 + s/2
214  end if
215  else
216  s = 1
217  p = 1
218  end if
219  par_id(1) = 1 + modulo(p-par_lim_loc(1),s)
220  par_id(2) = n - s + 1 + modulo(p-par_lim_loc(2)-1,s)
221  par_id(3) = s
222 
223  ! set par_id in memory if requested
224  if (present(par_id_mem)) par_id_mem = &
225  &1 + (par_lim_loc(1)-1-p+par_id(1:2))/s
226  end function setup_par_id
227 
233  function setup_rich_id(rich_lvl_max,tot_rich) result(rich_id)
234  ! input / output
235  integer, intent(in) :: rich_lvl_max
236  logical, intent(in), optional :: tot_rich
237  integer :: rich_id(2)
238 
239  ! set up rich_id
240  rich_id = [rich_lvl_max,rich_lvl_max]
241  if (present(tot_rich) .and. rich_lvl_max.gt.1) then ! only for higher Richardson levels
242  if (tot_rich) rich_id = [1,rich_lvl_max]
243  end if
244  end function setup_rich_id
245 end module pb3d_utilities
num_vars::max_name_ln
integer, parameter, public max_name_ln
maximum length of filenames
Definition: num_vars.f90:51
num_vars::dp
integer, parameter, public dp
double precision
Definition: num_vars.f90:46
num_vars
Numerical variables used by most other modules.
Definition: num_vars.f90:4
num_vars::max_str_ln
integer, parameter, public max_str_ln
maximum length of strings
Definition: num_vars.f90:50
hdf5_vars
Variables pertaining to HDF5 and XDMF.
Definition: HDF5_vars.f90:4
str_utilities
Operations on strings.
Definition: str_utilities.f90:4
grid_vars::grid_type
Type for grids.
Definition: grid_vars.f90:59
pb3d_utilities::setup_rich_id
integer function, dimension(2), public setup_rich_id(rich_lvl_max, tot_rich)
Returns richardson id.
Definition: PB3D_utilities.f90:234
pb3d_utilities::setup_par_id
integer function, dimension(3), public setup_par_id(grid, rich_lvl_max, rich_lvl_loc, tot_rich, par_lim, par_id_mem)
Setup parallel id.
Definition: PB3D_utilities.f90:181
hdf5_vars::var_1d_type
1D equivalent of multidimensional variables, used for internal HDF5 storage.
Definition: HDF5_vars.f90:48
messages
Numerical utilities related to giving output.
Definition: messages.f90:4
num_vars::pi
real(dp), parameter, public pi
Definition: num_vars.f90:83
grid_vars
Variables pertaining to the different grids used.
Definition: grid_vars.f90:4
pb3d_utilities::conv_1d2nd
Converts 1-D to n-D variables.
Definition: PB3D_utilities.f90:21
pb3d_utilities
Numerical utilities related to PB3D operations.
Definition: PB3D_utilities.f90:4