Neko 1.99.1
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
buffer_4d_npar.F90
Go to the documentation of this file.
1! Copyright (c) 2024, Gregor Weiss (HLRS)
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
35 use num_types, only : dp, sp, i8, rp
36 use vector, only : vector_t
37#ifdef HAVE_ADIOS2_FORTRAN
38 use adios2
39#endif
41 implicit none
42
43 integer, private :: nthpar
44 integer, private :: npar
45
46 type, extends(buffer_t) :: buffer_4d_npar_t
47 integer(kind=i8), dimension(5) :: shape_dims, start_dims, count_dims
48 real(kind=dp), private, allocatable :: data_dp(:,:,:,:,:)
49 real(kind=sp), private, allocatable :: data_sp(:,:,:,:,:)
50 contains
51 procedure :: init => buffer_4d_npar_init
52 procedure :: fill => buffer_4d_npar_fill
53#ifdef HAVE_ADIOS2_FORTRAN
54 procedure :: define => buffer_4d_npar_define
55 procedure :: inquire => buffer_4d_npar_inquire
56 procedure :: write => buffer_4d_npar_write
57 procedure :: read => buffer_4d_npar_read
58#endif
59 procedure :: copy => buffer_4d_npar_copy
60 end type buffer_4d_npar_t
61
62contains
63
64 subroutine buffer_4d_npar_init(this, precision, gdim, glb_nelv, offset_el, &
65 nelv, lx, ly, lz)
66 class(buffer_4d_npar_t), intent(inout) :: this
67 logical, intent(in) :: precision
68 integer, intent(in) :: gdim, glb_nelv, offset_el, nelv, lx, ly, lz
69 integer :: lxyz
70
71 nthpar = 0
72 npar = gdim
73 lxyz = lx*ly*lz
74
75 call buffer_set_precision(this, precision)
76
77 if (this%dp_precision) then
78 if (allocated(this%data_dp)) then
79 deallocate(this%data_dp)
80 end if
81 allocate(this%data_dp(nelv, lx, ly, lz, npar))
82 else
83 if (allocated(this%data_sp)) then
84 deallocate(this%data_sp)
85 end if
86 allocate(this%data_sp(nelv, lx, ly, lz, npar))
87 end if
88
89 this%shape_dims = [int(glb_nelv, i8), int(lx, i8), int(ly, i8), &
90 int(lz, i8), int(npar, i8)]
91 this%start_dims = [int(offset_el, i8), int(0, i8), int(0, i8), &
92 int(0, i8), int(0, i8)]
93 this%count_dims = [int(nelv, i8), int(lx, i8), int(ly, i8), &
94 int(lz, i8), int(npar, i8)]
95
96 end subroutine buffer_4d_npar_init
97
98 subroutine buffer_4d_npar_fill(this, x, n)
99 class(buffer_4d_npar_t), intent(inout) :: this
100 integer, intent(inout) :: n
101 real(kind=rp), intent(inout) :: x(n)
102 integer :: i, j, k, l, nelv, lx, ly, lz, index
103
104 nthpar = nthpar + 1
105 if (nthpar .le. npar) then
106
107 nelv = this%count_dims(1)
108 lx = this%count_dims(2)
109 ly = this%count_dims(3)
110 lz = this%count_dims(4)
111
112 if (this%dp_precision) then
113 do i = 1, nelv
114 do j = 1, lz
115 do k = 1, ly
116 do l = 1, lx
117 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) +1
118 this%data_dp(i,l,k,j, nthpar) = real(x(index), dp)
119 end do
120 end do
121 end do
122 end do
123 else
124 do i = 1, nelv
125 do j = 1, lz
126 do k = 1, ly
127 do l = 1, lx
128 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) +1
129 this%data_sp(i,l,k,j, nthpar) = real(x(index), sp)
130 end do
131 end do
132 end do
133 end do
134 end if
135
136 end if
137
138 end subroutine buffer_4d_npar_fill
139
140#ifdef HAVE_ADIOS2_FORTRAN
141
142 subroutine buffer_4d_npar_define(this, variable, io, variable_name, ierr)
143 class(buffer_4d_npar_t), intent(inout) :: this
144 type(adios2_variable), intent(inout) :: variable
145 type(adios2_io), intent(inout) :: io
146 character(len=*), intent(in) :: variable_name
147 integer, intent(inout) :: ierr
148 integer :: adios2_type
149
150 if (this%dp_precision) then
151 adios2_type = adios2_type_dp
152 else
153 adios2_type = adios2_type_real
154 end if
155
156 call adios2_inquire_variable(variable, io, trim(variable_name), ierr)
157 if (.not.variable%valid) then
159 call adios2_define_variable(variable, io, variable_name, adios2_type, &
160 size(this%shape_dims), this%shape_dims, this%start_dims, &
161 this%count_dims, .false., ierr)
162 else
163 call adios2_set_selection(variable, size(this%start_dims), &
164 this%start_dims, this%count_dims, ierr)
165 end if
166
167 end subroutine buffer_4d_npar_define
168
169 subroutine buffer_4d_npar_inquire(this, variable, io, variable_name, ierr)
170 class(buffer_4d_npar_t), intent(inout) :: this
171 type(adios2_variable), intent(inout) :: variable
172 type(adios2_io), intent(inout) :: io
173 character(len=*), intent(in) :: variable_name
174 integer, intent(inout) :: ierr
175
176 call adios2_inquire_variable(variable, io, trim(variable_name), ierr)
177 if (variable%valid) then
178 call adios2_set_selection(variable, size(this%start_dims), &
179 this%start_dims, this%count_dims, ierr)
180 end if
181
182 end subroutine buffer_4d_npar_inquire
183
184 subroutine buffer_4d_npar_write(this, engine, variable, ierr)
185 class(buffer_4d_npar_t), intent(inout) :: this
186 type(adios2_engine), intent(in) :: engine
187 type(adios2_variable), intent(in) :: variable
188 integer, intent(inout) :: ierr
189
190 if (this%dp_precision) then
191 call adios2_put(engine, variable, this%data_dp, adios2_mode_sync, ierr)
192 else
193 call adios2_put(engine, variable, this%data_sp, adios2_mode_sync, ierr)
194 end if
195
196 end subroutine buffer_4d_npar_write
197
198 subroutine buffer_4d_npar_read(this, engine, variable, ierr)
199 class(buffer_4d_npar_t), intent(inout) :: this
200 type(adios2_engine), intent(in) :: engine
201 type(adios2_variable), intent(in) :: variable
202 integer, intent(inout) :: ierr
203
204 if (this%dp_precision) then
205 call adios2_get(engine, variable, this%data_dp, adios2_mode_sync, ierr)
206 else
207 call adios2_get(engine, variable, this%data_sp, adios2_mode_sync, ierr)
208 end if
209
210 end subroutine buffer_4d_npar_read
211
212#endif
213
214 subroutine buffer_4d_npar_copy(this, x)
215 class(buffer_4d_npar_t), intent(inout) :: this
216 type(vector_t), intent(inout) :: x
217 integer :: i, j, k, l, nelv, lx, ly, lz, index
218
219 nthpar = nthpar + 1
220 if (nthpar .le. npar) then
221
222 nelv = this%count_dims(1)
223 lx = this%count_dims(2)
224 ly = this%count_dims(3)
225 lz = this%count_dims(4)
226
227 if (this%dp_precision) then
228 do i = 1, nelv
229 do j = 1, lz
230 do k = 1, ly
231 do l = 1, lx
232 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) +1
233 x%x(index) = this%data_dp(i,l,k,j, nthpar)
234 end do
235 end do
236 end do
237 end do
238 else
239 do i = 1, nelv
240 do j = 1, lz
241 do k = 1, ly
242 do l = 1, lx
243 index = (l-1) + lx*(k-1) + lx*ly*(j-1) + lx*ly*lz*(i-1) +1
244 x%x(index) = this%data_sp(i,l,k,j, nthpar)
245 end do
246 end do
247 end do
248 end do
249 end if
250
251 end if
252
253 end subroutine buffer_4d_npar_copy
254
255end module buffer_4d_npar
double real
Generic buffer that is extended with buffers of varying rank.
integer, private nthpar
integer, private npar
subroutine buffer_4d_npar_init(this, precision, gdim, glb_nelv, offset_el, nelv, lx, ly, lz)
subroutine buffer_4d_npar_fill(this, x, n)
subroutine buffer_4d_npar_copy(this, x)
Generic buffer that is extended with buffers of varying rank.
Definition buffer.F90:34
subroutine buffer_set_precision(this, precision)
Definition buffer.F90:112
integer, parameter, public i8
Definition num_types.f90:7
integer, parameter, public dp
Definition num_types.f90:9
integer, parameter, public sp
Definition num_types.f90:8
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Defines a vector.
Definition vector.f90:34