Octopus
cube_function.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2011 M. Marques, A. Castro, A. Rubio, G. Bertsch, M. Oliveira
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use accel_oct_m
23 use cube_oct_m
24 use debug_oct_m
25 use fft_oct_m
26 use global_oct_m
28 use math_oct_m
29 use mesh_oct_m
33 use mpi_oct_m
40 use types_oct_m
41
42 implicit none
43 private
44 public :: &
72
74 ! Components are public by default
75 integer :: batch_capacity = 1
76 integer :: batch_size = 1
78 real(real64), pointer, contiguous :: dRS(:, :, :, :) => null()
79 complex(real64), pointer, contiguous :: zRS(:, :, :, :) => null()
80 complex(real64), pointer, contiguous :: FS(:, :, :, :) => null()
81 logical :: forced_alloc = .false.
82 logical :: in_device_memory = .false.
83 type(accel_mem_t) :: real_space_buffer
84 type(accel_mem_t) :: fourier_space_buffer
85 end type cube_function_t
86
87 interface dmesh_to_cube
88 module procedure dmesh_to_cube_1, dmesh_to_cube_2
89 end interface dmesh_to_cube
90
91 interface zmesh_to_cube
92 module procedure zmesh_to_cube_1, zmesh_to_cube_2
93 end interface zmesh_to_cube
94
95 interface dcube_to_mesh
96 module procedure dcube_to_mesh_1, dcube_to_mesh_2
97 end interface dcube_to_mesh
98
99 interface zcube_to_mesh
100 module procedure zcube_to_mesh_1, zcube_to_mesh_2
101 end interface zcube_to_mesh
102
103contains
104
109 subroutine cube_function_alloc_fs(cube, cf, force_alloc)
110 type(cube_t), target, intent(in) :: cube
111 type(cube_function_t), intent(inout) :: cf
112 logical, optional, intent(in) :: force_alloc
113
114 integer :: n1, n2, n3
115 logical :: is_allocated
117 push_sub(cube_function_alloc_fs)
118
119 assert(.not. associated(cf%fs))
120 assert(allocated(cube%fft))
121
122 cf%forced_alloc = optional_default(force_alloc, .false.)
123 ! cf has no init, so assign here; preserve cf%batch_size (active count) set by the caller
124 cf%batch_capacity = cube%batch_capacity
125
126 n1 = max(1, cube%fs_n(1))
127 n2 = max(1, cube%fs_n(2))
128 n3 = max(1, cube%fs_n(3))
129
130 is_allocated = .false.
131
132 select case (cube%fft%library)
133 case (fftlib_pfft)
134 if (.not. cf%forced_alloc) then
135 is_allocated = .true.
136 if (any(cube%fs_n(1:3) == 0)) then
137 cf%fs => cube%fft%fs_data(1:1,1:1,1:1,1:cf%batch_capacity)
138 else
139 cf%fs => cube%fft%fs_data(1:n3,1:n1,1:n2,1:cf%batch_capacity)
140 end if
141 else ! force allocate transposed with PFFT
142 is_allocated = .true.
143 safe_allocate(cf%fs(1:n3, 1:n1, 1:n2, 1:cf%batch_capacity))
144 end if
145 case (fftlib_accel)
146 if (cf%in_device_memory) then
147 is_allocated = .true.
148 call accel_create_buffer(cf%fourier_space_buffer, accel_mem_read_write, type_cmplx, &
149 int(cf%batch_capacity, int64) * product(int(cube%fs_n(1:3), int64)))
150 end if
151
152 case (fftlib_fftw)
153 if (.not. cf%forced_alloc) then
154 is_allocated = .true.
155 cf%fs => cube%fft%fs_data(1:cube%fs_n(1), 1:cube%fs_n(2), 1:cube%fs_n(3), 1:cf%batch_capacity)
156 end if
157 end select
158
159 if (.not. is_allocated) then
160 safe_allocate(cf%fs(1:cube%fs_n(1), 1:cube%fs_n(2), 1:cube%fs_n(3), 1:cf%batch_capacity))
161 end if
162
164 end subroutine cube_function_alloc_fs
165
166
168 subroutine cube_function_free_fs(cube, cf)
169 type(cube_t), intent(in) :: cube
170 type(cube_function_t), intent(inout) :: cf
172 logical :: deallocated
176 assert(allocated(cube%fft))
178 deallocated = .false.
180 select case (cube%fft%library)
181 case (fftlib_pfft)
182 if (.not. cf%forced_alloc) then
183 deallocated = .true.
184 nullify(cf%fs)
185 end if
187 if (cf%in_device_memory) then
188 deallocated = .true.
189 call accel_free_buffer(cf%fourier_space_buffer)
190 end if
191 case (fftlib_fftw)
192 if (.not. cf%forced_alloc) then
193 deallocated = .true.
194 nullify(cf%fs)
195 end if
196 end select
197
198 if (.not. deallocated) then
199 assert(associated(cf%fs))
200 safe_deallocate_p(cf%fs)
201 end if
202
203 pop_sub(cube_function_free_fs)
205
206
207 ! ---------------------------------------------------------
213 pure logical function cube_map_is_trivial(cube) result(trivial)
214 type(cube_t), intent(in) :: cube
215 trivial = cube%cube_map_present .and. allocated(cube%cube_map%map)
216 if (.not. trivial) return
217 ! is_trivial captures the mesh-side property; the additional checks
218 ! verify the cube dimensions match the mesh and the cube origin aligns
219 ! so that mesh point 1 lands at cube cell (1, 1, 1).
220 trivial = cube%cube_map%is_trivial .and. &
221 cube%cube_map%nmap == cube%rs_n(2) * cube%rs_n(3) .and. &
222 cube%cube_map%map(mcm_count, 1) == cube%rs_n(1) .and. &
223 cube%cube_map%map(1, 1) + cube%center(1) == 1 .and. &
224 cube%cube_map%map(2, 1) + cube%center(2) == 1 .and. &
225 cube%cube_map%map(3, 1) + cube%center(3) == 1
226 end function cube_map_is_trivial
227
228#include "undef.F90"
229#include "real.F90"
230#include "cube_function_inc.F90"
231
232#include "undef.F90"
233#include "complex.F90"
234#include "cube_function_inc.F90"
235
236end module cube_function_oct_m
237
238
239!! Local Variables:
240!! mode: f90
241!! coding: utf-8
242!! End:
subroutine, public accel_free_buffer(this, async)
Definition: accel.F90:941
integer, parameter, public accel_mem_read_write
Definition: accel.F90:185
real(real64) function, public dcube_function_surface_average(cube, cf)
This function calculates the surface average of any function.
complex(real64) function, public zcube_function_surface_average(cube, cf)
This function calculates the surface average of any function.
subroutine dcube_to_mesh_1(cube, cf, mesh, mf)
Convert a single function from the cube to the mesh.
subroutine, public dcube_function_rs2fs(cube, cf)
Fourier transform a cube function from real space to Fourier space.
subroutine zcube_to_mesh_2(cube, cf, mesh, mf, mf_buffer)
Convert a set of functions from the cube to the mesh.
subroutine, public dcube_to_submesh(cube, cf, sm, mf)
subroutine, public cube_function_free_fs(cube, cf)
Deallocates the Fourier space buffer of the cube function.
subroutine dmesh_to_cube_2(mesh, mf, cube, cf, mf_buffer)
Convert a set of functions from the mesh to the cube.
subroutine, public dcube_function_allgather(cube, cf, cf_local, order, gatherfs)
subroutine, public zcube_to_mesh_parallel(cube, cf, mesh, mf, map)
subroutine, public dcube_function_alloc_rs(cube, cf, in_device, force_alloc)
Allocates locally the real space grid, if PFFT library is not used. Otherwise, it assigns the PFFT re...
subroutine zmesh_to_cube_1(mesh, mf, cube, cf)
Convert a single function from the mesh to the cube.
subroutine, public zcube_to_submesh(cube, cf, sm, mf)
subroutine, public zmesh_to_cube_parallel(mesh, mf, cube, cf, map)
The next two subroutines convert a function between the normal mesh and the cube in parallel.
subroutine, public dcube_function_free_rs(cube, cf)
Deallocates the real space grid.
subroutine dmesh_to_cube_1(mesh, mf, cube, cf)
Convert a single function from the mesh to the cube.
subroutine, public dsubmesh_to_cube(sm, mf, cube, cf)
The next two subroutines convert a function between a submesh and the cube.
subroutine zmesh_to_cube_2(mesh, mf, cube, cf, mf_buffer)
Convert a set of functions from the mesh to the cube.
subroutine, public cube_function_alloc_fs(cube, cf, force_alloc)
Allocates the local part of the Fourier space grid on the cube function.
subroutine, public zsubmesh_to_cube(sm, mf, cube, cf)
The next two subroutines convert a function between a submesh and the cube.
subroutine, public zcube_function_allgather(cube, cf, cf_local, order, gatherfs)
subroutine, public dmesh_to_cube_parallel(mesh, mf, cube, cf, map)
The next two subroutines convert a function between the normal mesh and the cube in parallel.
subroutine, public zcube_function_fs2rs(cube, cf)
Fourier transform a cube function from Fourier space to real space.
subroutine, public dcube_function_fs2rs(cube, cf)
Fourier transform a cube function from Fourier space to real space.
subroutine dcube_to_mesh_2(cube, cf, mesh, mf, mf_buffer)
Convert a set of functions from the cube to the mesh.
subroutine, public zcube_function_free_rs(cube, cf)
Deallocates the real space grid.
pure logical function cube_map_is_trivial(cube)
True when the cube_map describes a trivial mesh->cube identity: the mesh is X-fastest with one full-X...
subroutine, public dcube_to_mesh_parallel(cube, cf, mesh, mf, map)
subroutine, public zcube_function_rs2fs(cube, cf)
Fourier transform a cube function from real space to Fourier space.
subroutine, public zcube_function_alloc_rs(cube, cf, in_device, force_alloc)
Allocates locally the real space grid, if PFFT library is not used. Otherwise, it assigns the PFFT re...
subroutine zcube_to_mesh_1(cube, cf, mesh, mf)
Convert a single function from the cube to the mesh.
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
Definition: fft.F90:120
integer, parameter, public fftlib_accel
Definition: fft.F90:179
integer, parameter, public fftlib_pfft
Definition: fft.F90:179
integer, parameter, public fftlib_fftw
Definition: fft.F90:179
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:117
integer, parameter, public mcm_count
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
Some general things and nomenclature:
Definition: par_vec.F90:173
This module is an helper to perform ring-pattern communications among all states.
type(type_t), parameter, public type_cmplx
Definition: types.F90:136
int true(void)