Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
operators.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2024, The Neko Authors
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!
33!> Operators
37 use num_types, only : rp, i8, dp
38 use opr_cpu, only : opr_cpu_cfl, opr_cpu_curl, opr_cpu_opgrad, &
39 opr_cpu_conv1, opr_cpu_convect_scalar, opr_cpu_cdtp, &
40 opr_cpu_dudxyz, opr_cpu_lambda2, opr_cpu_set_convect_rst, &
42 use opr_sx, only : opr_sx_cfl, opr_sx_curl, opr_sx_opgrad, &
43 opr_sx_conv1, opr_sx_convect_scalar, opr_sx_cdtp, &
44 opr_sx_dudxyz, opr_sx_lambda2, opr_sx_set_convect_rst
52 use space, only : space_t
53 use coefs, only : coef_t
54 use field, only : field_t
55 use field_list, only : field_list_t
56 use field_math, only : field_rzero
58 use math, only : glsum, cmult, add2, add3s2, cadd, copy, col2, invcol2, &
65 use vector, only : vector_t
67 use mpi_f08, only : mpi_allreduce, mpi_in_place, mpi_max, mpi_sum, &
68 mpi_double_precision
69 use, intrinsic :: iso_c_binding, only : c_ptr
70 use logger, only : neko_log
71 implicit none
72 private
73
77
78 !> Compute derivative of a scalar field along a single direction.
79 interface dudxyz
80 module procedure dudxyz_r4
81 module procedure opr_device_dudxyz
82 module procedure dudxyz_f
83 end interface dudxyz
84
85 !> Compute the divergence of a vector field.
86 interface div
87 module procedure div_r4
88 module procedure div_d
89 end interface div
90
91 !> Compute the gradient of a scalar field, multiplied by the mass matrix.
92 interface grad
93 module procedure grad_r4
94 module procedure grad_d
95 end interface grad
96
97 !> Compute CFL condition.
98 interface cfl
99 module procedure cfl_r4
100 module procedure cfl_d
101 module procedure cfl_f
102 end interface cfl
103
104 !> Compute CFL condition for compressible flow.
106 module procedure cfl_compressible_r4
107 module procedure cfl_compressible_d
108 module procedure cfl_compressible_f
109 end interface cfl_compressible
110
111 !> Apply cyclic boundary condition to a vector field.
112 interface rotate_cyc
113 module procedure rotate_cyc_r1
114 module procedure rotate_cyc_r4
115 module procedure rotate_cyc_d
116 module procedure rotate_cyc_f
117 end interface rotate_cyc
118
119 !> Compute the strain rate tensor of a vector field.
120 interface strain_rate
121 module procedure strain_rate_r4
122 module procedure strain_rate_d
123 module procedure strain_rate_f
124 end interface strain_rate
125contains
126
127 !> Compute derivative of a scalar field along a single direction.
128 !! @param du Holds the resulting derivative values.
129 !! @param u The values of the field.
130 !! @param dr The derivative of r with respect to the chosen direction.
131 !! @param ds The derivative of s with respect to the chosen direction.
132 !! @param dt The derivative of t with respect to the chosen direction.
133 !! @param coef The SEM coefficients.
134 subroutine dudxyz_r4(du, u, dr, ds, dt, coef)
135 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: du
136 real(kind=rp), contiguous, dimension(:,:,:,:), intent(in) :: u, dr, ds, dt
137 type(coef_t), intent(in) :: coef
138 type(c_ptr) :: du_d, u_d, dr_d, ds_d, dt_d
139
140 if (neko_bcknd_sx .eq. 1) then
141 call opr_sx_dudxyz(du, u, dr, ds, dt, coef)
142 else if (neko_bcknd_xsmm .eq. 1) then
143 call opr_xsmm_dudxyz(du, u, dr, ds, dt, coef)
144 else if (neko_bcknd_device .eq. 1) then
145 call neko_log%deprecated('Operator: dudxyz, implicit device', &
146 '2.0.0', 'Please call opr_device_dudxyz instead.')
147
148 du_d = device_get_ptr(du)
149 u_d = device_get_ptr(u)
150 dr_d = device_get_ptr(dr)
151 ds_d = device_get_ptr(ds)
152 dt_d = device_get_ptr(dt)
153
154 call opr_device_dudxyz(du_d, u_d, dr_d, ds_d, dt_d, coef)
155 else
156 call opr_cpu_dudxyz(du, u, dr, ds, dt, coef)
157 end if
158
159 end subroutine dudxyz_r4
160
161 !> Compute derivative of a scalar field along a single direction.
162 !! @param du Holds the resulting derivative values.
163 !! @param u The values of the field.
164 !! @param dr The derivative of r with respect to the chosen direction.
165 !! @param ds The derivative of s with respect to the chosen direction.
166 !! @param dt The derivative of t with respect to the chosen direction.
167 !! @param coef The SEM coefficients.
168 subroutine dudxyz_f(du, u, dr, ds, dt, coef)
169 type(field_t), intent(inout) :: du
170 type(field_t), intent(in) :: u, dr, ds, dt
171 type(coef_t), intent(in) :: coef
172
173 if (neko_bcknd_sx .eq. 1) then
174 call opr_sx_dudxyz(du%x, u%x, dr%x, ds%x, dt%x, coef)
175 else if (neko_bcknd_xsmm .eq. 1) then
176 call opr_xsmm_dudxyz(du%x, u%x, dr%x, ds%x, dt%x, coef)
177 else if (neko_bcknd_device .eq. 1) then
178 call opr_device_dudxyz(du%x_d, u%x_d, dr%x_d, ds%x_d, dt%x_d, coef)
179 else
180 call opr_cpu_dudxyz(du%x, u%x, dr%x, ds%x, dt%x, coef)
181 end if
182
183 end subroutine dudxyz_f
184
185 !> Compute the divergence of a vector field.
186 !! @param res Holds the resulting divergence values.
187 !! @param ux The x component of the vector field.
188 !! @param uy The y component of the vector field.
189 !! @param uz The z component of the vector field.
190 !! @param coef The SEM coefficients.
191 subroutine div_r4(res, ux, uy, uz, coef)
192 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: res
193 real(kind=rp), contiguous, dimension(:,:,:,:), intent(in) :: ux, uy, uz
194 type(coef_t), intent(in), target :: coef
195 type(field_t), pointer :: work
196 integer :: ind
197 type(c_ptr) :: res_d
198
199 if (neko_bcknd_device .eq. 1) then
200 call neko_log%deprecated('Operator: div, implicit device', &
201 '2.0.0', 'Please call div_d instead.')
202 res_d = device_get_ptr(res)
203 end if
204
205 call neko_scratch_registry%request_field(work, ind, .false.)
206
207 ! Get dux / dx
208 call dudxyz(res, ux, coef%drdx, coef%dsdx, coef%dtdx, coef)
209
210 ! Get duy / dy
211 call dudxyz(work%x, uy, coef%drdy, coef%dsdy, coef%dtdy, coef)
212 if (neko_bcknd_device .eq. 1) then
213 call device_add2(res_d, work%x_d, work%size())
214 else
215 call add2(res, work%x, work%size())
216 end if
217
218 ! Get dux / dz
219 call dudxyz(work%x, uz, coef%drdz, coef%dsdz, coef%dtdz, coef)
220 if (neko_bcknd_device .eq. 1) then
221 call device_add2(res_d, work%x_d, work%size())
222 else
223 call add2(res, work%x, work%size())
224 end if
225
226 call neko_scratch_registry%relinquish_field(ind)
227
228 end subroutine div_r4
229
230 !> Compute the divergence of a vector field.
231 !! @param res Holds the resulting divergence values.
232 !! @param ux The x component of the vector field.
233 !! @param uy The y component of the vector field.
234 !! @param uz The z component of the vector field.
235 !! @param coef The SEM coefficients.
236 subroutine div_d(res_d, ux_d, uy_d, uz_d, coef)
237 type(c_ptr), intent(inout) :: res_d
238 type(c_ptr), intent(in) :: ux_d, uy_d, uz_d
239 type(coef_t), intent(in), target :: coef
240 type(field_t), pointer :: work
241 integer :: ind
242
243 call neko_scratch_registry%request_field(work, ind, .false.)
244
245 ! Get dux / dx
246 call dudxyz(res_d, ux_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
247
248 ! Get duy / dy
249 call dudxyz(work%x_d, uy_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
250 call device_add2(res_d, work%x_d, work%size())
251
252 ! Get duz / dz
253 call dudxyz(work%x_d, uz_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
254 call device_add2(res_d, work%x_d, work%size())
255
256 call neko_scratch_registry%relinquish_field(ind)
257
258 end subroutine div_d
259
260 !> Compute the gradient of a scalar field.
261 !! @param ux Will store the x component of the gradient.
262 !! @param uy Will store the y component of the gradient.
263 !! @param uz Will store the z component of the gradient.
264 !! @param u The values of the field.
265 !! @param coef The SEM coefficients.
266 subroutine grad_r4(ux, uy, uz, u, coef)
267 type(coef_t), intent(in) :: coef
268 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: ux
269 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: uy
270 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: uz
271 real(kind=rp), contiguous, dimension(:,:,:,:), intent(in) :: u
272
273 call dudxyz(ux, u, coef%drdx, coef%dsdx, coef%dtdx, coef)
274 call dudxyz(uy, u, coef%drdy, coef%dsdy, coef%dtdy, coef)
275 call dudxyz(uz, u, coef%drdz, coef%dsdz, coef%dtdz, coef)
276
277 end subroutine grad_r4
278
279 !> Compute the gradient of a scalar field.
280 !! @param ux Will store the x component of the gradient.
281 !! @param uy Will store the y component of the gradient.
282 !! @param uz Will store the z component of the gradient.
283 !! @param u The values of the field.
284 !! @param coef The SEM coefficients.
285 subroutine grad_d(ux_d, uy_d, uz_d, u_d, coef)
286 type(coef_t), intent(in) :: coef
287 type(c_ptr), intent(inout) :: ux_d, uy_d, uz_d
288 type(c_ptr), intent(in) :: u_d
289
290 call dudxyz(ux_d, u_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
291 call dudxyz(uy_d, u_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
292 call dudxyz(uz_d, u_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
293
294 end subroutine grad_d
295
296 !> Compute the weak gradient of a scalar field, i.e. the gradient multiplied
297 !! by the mass matrix.
298 !! @details By providing `es` and `ee`, it is possible to compute only for a
299 !! range of element indices.
300 !! @param ux Will store the x component of the gradient.
301 !! @param uy Will store the y component of the gradient.
302 !! @param uz Will store the z component of the gradient.
303 !! @param u The values of the field.
304 !! @param coef The SEM coefficients.
305 !! @param es Starting element index, optional, defaults to 1.
306 !! @param ee Ending element index, optional, defaults to `nelv`.
307 !! @note Equals wgradm1 in Nek5000, the weak form of the gradient.
308 subroutine opgrad(ux, uy, uz, u, coef, es, ee)
309 type(coef_t), intent(in) :: coef
310 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(inout) :: ux
311 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(inout) :: uy
312 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(inout) :: uz
313 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(in) :: u
314 integer, optional :: es, ee
315 integer :: eblk_start, eblk_end
316 type(c_ptr) :: ux_d, uy_d, uz_d, u_d
317
318 if (present(es)) then
319 eblk_start = es
320 else
321 eblk_start = 1
322 end if
323
324 if (present(ee)) then
325 eblk_end = ee
326 else
327 eblk_end = coef%msh%nelv
328 end if
329
330 if (neko_bcknd_sx .eq. 1) then
331 call opr_sx_opgrad(ux, uy, uz, u, coef)
332 else if (neko_bcknd_xsmm .eq. 1) then
333 call opr_xsmm_opgrad(ux, uy, uz, u, coef)
334 else if (neko_bcknd_device .eq. 1) then
335 ux_d = device_get_ptr(ux)
336 uy_d = device_get_ptr(uy)
337 uz_d = device_get_ptr(uz)
338 u_d = device_get_ptr(u)
339 call opr_device_opgrad(ux_d, uy_d, uz_d, u_d, coef)
340 else
341 call opr_cpu_opgrad(ux, uy, uz, u, coef, eblk_start, eblk_end)
342 end if
343
344 end subroutine opgrad
345
346 !> Othogonalize with regard to vector (1,1,1,1,1,1...,1)^T.
347 !! @param x The vector to orthogonolize.
348 !! @param glb_n_points The global number of non-unique gll points in the grid.
349 !! @note This is equivalent to subtracting the mean of `x` from each of its elements.
350 subroutine ortho(x, glb_n_points, n)
351 integer, intent(in) :: n
352 integer(kind=i8), intent(in) :: glb_n_points
353 real(kind=rp), dimension(n), intent(inout) :: x
354 real(kind=rp) :: c
355 type(c_ptr) :: x_d
356
357 if (neko_bcknd_device .eq. 1) then
358 call neko_log%deprecated('Operator: ortho, implicit device', &
359 '2.0.0', 'Please call device_ortho instead.')
360
361 x_d = device_get_ptr(x)
362 c = device_glsum(x_d, n) / glb_n_points
363 call device_cadd(x_d, -c, n)
364 else
365 c = glsum(x, n) / glb_n_points
366 call cadd(x, -c, n)
367 end if
368
369 end subroutine ortho
370
371 !> Apply D^T to a scalar field, where D is the derivative matrix.
372 !! @param dtx Will store the result.
373 !! @param x The values of the field.
374 !! @param dr The derivative of r with respect to the chosen direction.
375 !! @param ds The derivative of s with respect to the chosen direction.
376 !! @param dt The derivative of t with respect to the chosen direction.
377 !! @param coef The SEM coefficients.
378 !! @param es Starting element index, optional, defaults to 1.
379 !! @param ee Ending element index, optional, defaults to `nelv`.
380 !> @note This needs to be revised... the loop over n1,n2 is probably
381 !! unnecessary
382 subroutine cdtp(dtx, x, dr, ds, dt, coef, es, ee)
383 type(coef_t), intent(in) :: coef
384 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(inout) :: dtx
385 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(inout) :: x
386 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(in) :: dr
387 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(in) :: ds
388 real(kind=rp), dimension(coef%Xh%lxyz, coef%msh%nelv), intent(in) :: dt
389 integer, optional :: es, ee
390 integer :: eblk_start, eblk_end
391 type(c_ptr) :: dtx_d, x_d, dr_d, ds_d, dt_d
392
393 if (present(es)) then
394 eblk_start = es
395 else
396 eblk_start = 1
397 end if
398
399 if (present(ee)) then
400 eblk_end = ee
401 else
402 eblk_end = coef%msh%nelv
403 end if
404
405 if (neko_bcknd_sx .eq. 1) then
406 call opr_sx_cdtp(dtx, x, dr, ds, dt, coef)
407 else if (neko_bcknd_xsmm .eq. 1) then
408 call opr_xsmm_cdtp(dtx, x, dr, ds, dt, coef)
409 else if (neko_bcknd_device .eq. 1) then
410 dtx_d = device_get_ptr(dtx)
411 x_d = device_get_ptr(x)
412 dr_d = device_get_ptr(dr)
413 ds_d = device_get_ptr(ds)
414 dt_d = device_get_ptr(dt)
415 call opr_device_cdtp(dtx_d, x_d, dr_d, ds_d, dt_d, coef)
416 else
417 call opr_cpu_cdtp(dtx, x, dr, ds, dt, coef, eblk_start, eblk_end)
418 end if
419
420 end subroutine cdtp
421
422 !> Compute the advection term.
423 !! @param du Holds the result.
424 !! @param u The advected field.
425 !! @param vx The x component of the advecting velocity.
426 !! @param vy The y component of the advecting velocity.
427 !! @param vz The z component of the advecting velocity.
428 !! @param Xh The function space for the fields involved.
429 !! @param coef The SEM coefficients.
430 !! @param es Starting element index, defaults to 1.
431 !! @param ee Last element index, defaults to mesh size.
432 subroutine conv1(du, u, vx, vy, vz, Xh, coef, es, ee)
433 type(space_t), intent(in) :: xh
434 type(coef_t), intent(in) :: coef
435 real(kind=rp), intent(inout) :: du(xh%lxyz, coef%msh%nelv)
436 real(kind=rp), intent(in) :: u(xh%lx, xh%ly, xh%lz, coef%msh%nelv)
437 real(kind=rp), intent(in) :: vx(xh%lx, xh%ly, xh%lz, coef%msh%nelv)
438 real(kind=rp), intent(in) :: vy(xh%lx, xh%ly, xh%lz, coef%msh%nelv)
439 real(kind=rp), intent(in) :: vz(xh%lx, xh%ly, xh%lz, coef%msh%nelv)
440 integer, optional :: es, ee
441 integer :: eblk_end, eblk_start
442 type(c_ptr) :: du_d, u_d, vx_d, vy_d, vz_d
443
444 associate(nelv => coef%msh%nelv, gdim => coef%msh%gdim)
445 if (present(es)) then
446 eblk_start = es
447 else
448 eblk_start = 1
449 end if
450
451 if (present(ee)) then
452 eblk_end = ee
453 else
454 eblk_end = coef%msh%nelv
455 end if
456
457 if (neko_bcknd_sx .eq. 1) then
458 call opr_sx_conv1(du, u, vx, vy, vz, xh, coef, nelv)
459 else if (neko_bcknd_xsmm .eq. 1) then
460 call opr_xsmm_conv1(du, u, vx, vy, vz, xh, coef, nelv, gdim)
461 else if (neko_bcknd_device .eq. 1) then
462 du_d = device_get_ptr(du)
463 u_d = device_get_ptr(u)
464 vx_d = device_get_ptr(vx)
465 vy_d = device_get_ptr(vy)
466 vz_d = device_get_ptr(vz)
467 call opr_device_conv1(du_d, u_d, vx_d, vy_d, vz_d, xh, coef, nelv, gdim)
468 else
469 call opr_cpu_conv1(du, u, vx, vy, vz, xh, coef, eblk_start, eblk_end)
470 end if
471 end associate
472
473 end subroutine conv1
474
475 !> Apply the convecting velocity c to the to the scalar field u, used in the OIFS scheme.
476 !! @param du Holds the result
477 !! @param cr The r-component of convecting velocity
478 !! @param cs The s-component of convecting velocity
479 !! @param ct The t-component of convecting velocity
480 !! @param u The convected scalar field
481 !! @param Xh_GLL The GLL space used in simulation
482 !! @param Xh_GL The GL space used for dealiasing
483 !! @param coef The coefficients of the original space in simulation
484 !! @param coef_GL The coefficients of the GL space used for dealiasing
485 !! @param GLL_to_GL the interpolator between the GLL and GL spaces
486 !! @note This subroutine is equal to the convop_fst_3d of the NEK5000.
487 !! @note This subroutine is used specifically in the OIFS scheme, calculateing eq(17)
488 !! in https://publications.anl.gov/anlpubs/2017/12/140626.pdf. The convecting term is
489 !! calculated in the rst format and the GL grid. Then converted back to the GLL grid,
490 !! going through an ADD gatter scatter operation at the element boundaries,
491 !! before being multiplied by inverse of mass matrix.
492 subroutine convect_scalar(du, u, cr, cs, ct, Xh_GLL, Xh_GL, coef_GLL, &
493 coef_GL, GLL_to_GL)
494 type(space_t), intent(in) :: Xh_GL
495 type(space_t), intent(in) :: Xh_GLL
496 type(coef_t), intent(in) :: coef_GLL
497 type(coef_t), intent(in) :: coef_GL
498 type(interpolator_t), intent(inout) :: GLL_to_GL
499 real(kind=rp), intent(inout) :: &
500 du(xh_gll%lx, xh_gll%ly, xh_gll%lz, coef_gl%msh%nelv)
501 real(kind=rp), intent(inout) :: &
502 u(xh_gl%lx, xh_gl%lx, xh_gl%lx, coef_gl%msh%nelv)
503 type(field_t), intent(inout) :: cr, cs, ct
504 type(c_ptr) :: u_d
505
506 if (neko_bcknd_sx .eq. 1) then
507 call opr_sx_convect_scalar(du, u, cr%x, cs%x, ct%x, &
508 xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
509 else if (neko_bcknd_xsmm .eq. 1) then
510 call opr_xsmm_convect_scalar(du, u, cr%x, cs%x, ct%x, &
511 xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
512 else if (neko_bcknd_device .eq. 1) then
513 u_d = device_get_ptr(u)
514 call opr_device_convect_scalar(du, u_d, cr%x_d, cs%x_d, ct%x_d, &
515 xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
516 else
517 call opr_cpu_convect_scalar(du, u, cr%x, cs%x, ct%x, &
518 xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
519 end if
520
521 end subroutine convect_scalar
522
523 !! Compute the curl fo a vector field.
524 !! @param w1 Will store the x component of the curl.
525 !! @param w2 Will store the y component of the curl.
526 !! @param w3 Will store the z component of the curl.
527 !! @param u1 The x component of the vector field.
528 !! @param u2 The y component of the vector field.
529 !! @param u3 The z component of the vector field.
530 !! @param work1 A temporary array for computations.
531 !! @param work2 A temporary array for computations.
532 !! @param coef The SEM coefficients.
533 !! @param event Optional device event. When present, the gather-scatter
534 !! records it instead of syncing the host, so the routine may return
535 !! before the device has finished.
536 subroutine curl(w1, w2, w3, u1, u2, u3, work1, work2, coef, event)
537 type(field_t), intent(inout) :: w1
538 type(field_t), intent(inout) :: w2
539 type(field_t), intent(inout) :: w3
540 type(field_t), intent(in) :: u1
541 type(field_t), intent(in) :: u2
542 type(field_t), intent(in) :: u3
543 type(field_t), intent(inout) :: work1
544 type(field_t), intent(inout) :: work2
545 type(coef_t), intent(in) :: coef
546 type(c_ptr), optional, intent(inout) :: event
547
548 if (neko_bcknd_sx .eq. 1) then
549 call opr_sx_curl(w1%x, w2%x, w3%x, u1%x, u2%x, u3%x, &
550 work1%x, work2%x, coef)
551 else if (neko_bcknd_xsmm .eq. 1) then
552 call opr_xsmm_curl(w1%x, w2%x, w3%x, u1%x, u2%x, u3%x, &
553 work1%x, work2%x, coef)
554 else if (neko_bcknd_device .eq. 1) then
555 call opr_device_curl(w1, w2, w3, u1, u2, u3, &
556 work1, work2, coef, event)
557 else
558 call opr_cpu_curl(w1%x, w2%x, w3%x, u1%x, u2%x, u3%x, &
559 work1%x, work2%x, coef)
560 end if
561
562 end subroutine curl
563
564 !! Compute the CFL number
565 !! @param dt The timestep.
566 !! @param u The x component of velocity.
567 !! @param v The y component of velocity.
568 !! @param w The z component of velocity.
569 !! @param Xh The SEM function space.
570 !! @param coef The SEM coefficients.
571 !! @param nelv The total number of elements.
572 !! @param gdim Number of geometric dimensions.
573 function cfl_r4(dt, u, v, w, Xh, coef, nelv, gdim)
574 real(kind=dp), intent(in) :: dt
575 real(kind=rp), contiguous, dimension(:,:,:,:), intent(in) :: u, v, w
576 type(space_t), intent(in) :: xh
577 type(coef_t), intent(in) :: coef
578 integer, intent(in) :: nelv, gdim
579 real(kind=dp) :: cfl_r4
580 integer :: ierr
581 type(c_ptr) :: u_d, v_d, w_d
582
583 if (neko_bcknd_sx .eq. 1) then
584 cfl_r4 = opr_sx_cfl(dt, u, v, w, xh, coef, nelv)
585 else if (neko_bcknd_device .eq. 1) then
586 call neko_log%deprecated('Operator: cfl_r4, implicit device', &
587 '2.0.0', 'Please call cfl_d instead.')
588
589 u_d = device_get_ptr(u)
590 v_d = device_get_ptr(v)
591 w_d = device_get_ptr(w)
592
593 cfl_r4 = opr_device_cfl(dt, u_d, v_d, w_d, xh, coef, nelv, gdim)
594 else
595 cfl_r4 = opr_cpu_cfl(dt, u, v, w, xh, coef, nelv, gdim)
596 end if
597
598 if (.not. neko_device_mpi) then
599 call mpi_allreduce(mpi_in_place, cfl_r4, 1, &
600 mpi_double_precision, mpi_max, neko_comm, ierr)
601 end if
602
603 end function cfl_r4
604
605 function cfl_d(dt, u_d, v_d, w_d, Xh, coef, nelv, gdim)
606 real(kind=dp), intent(in) :: dt
607 type(c_ptr), intent(in) :: u_d, v_d, w_d
608 type(space_t), intent(in) :: xh
609 type(coef_t), intent(in) :: coef
610 integer, intent(in) :: nelv, gdim
611 real(kind=dp) :: cfl_d
612 integer :: ierr
613
614 cfl_d = opr_device_cfl(dt, u_d, v_d, w_d, xh, coef, nelv, gdim)
615
616 if (.not. neko_device_mpi) then
617 call mpi_allreduce(mpi_in_place, cfl_d, 1, &
618 mpi_double_precision, mpi_max, neko_comm, ierr)
619 end if
620
621 end function cfl_d
622
623 function cfl_f(dt, u, v, w, Xh, coef, nelv, gdim)
624 real(kind=dp), intent(in) :: dt
625 type(field_t), intent(in) :: u, v, w
626 type(space_t), intent(in) :: xh
627 type(coef_t), intent(in) :: coef
628 integer, intent(in) :: nelv, gdim
629 real(kind=dp) :: cfl_f
630 integer :: ierr
631
632 if (neko_bcknd_sx .eq. 1) then
633 cfl_f = opr_sx_cfl(dt, u%x, v%x, w%x, xh, coef, nelv)
634 else if (neko_bcknd_device .eq. 1) then
635 cfl_f = opr_device_cfl(dt, u%x_d, v%x_d, w%x_d, xh, coef, nelv, gdim)
636 else
637 cfl_f = opr_cpu_cfl(dt, u%x, v%x, w%x, xh, coef, nelv, gdim)
638 end if
639
640 if (.not. neko_device_mpi) then
641 call mpi_allreduce(mpi_in_place, cfl_f, 1, &
642 mpi_double_precision, mpi_max, neko_comm, ierr)
643 end if
644
645 end function cfl_f
646
647 !! Compute the CFL number for compressible flows
648 !! @param dt The timestep.
649 !! @param max_wave_speed The precomputed maximum wave speed field.
650 !! @param Xh The SEM function space.
651 !! @param coef The SEM coefficients.
652 !! @param nelv The total number of elements.
653 !! @param gdim Number of geometric dimensions.
654 function cfl_compressible_r4(dt, max_wave_speed, Xh, coef, nelv, gdim)
655 real(kind=dp), intent(in) :: dt
656 real(kind=rp), contiguous, dimension(:,:,:,:), intent(in) :: max_wave_speed
657 type(space_t), intent(in) :: xh
658 type(coef_t), intent(in) :: coef
659 integer, intent(in) :: nelv, gdim
660 real(kind=dp) :: cfl_compressible_r4
661
662 cfl_compressible_r4 = cfl(dt, max_wave_speed, max_wave_speed, &
663 max_wave_speed, xh, coef, nelv, gdim)
664
665 end function cfl_compressible_r4
666
667 !! Compute the CFL number for compressible flows
668 !! @param dt The timestep.
669 !! @param max_wave_speed The precomputed maximum wave speed field.
670 !! @param Xh The SEM function space.
671 !! @param coef The SEM coefficients.
672 !! @param nelv The total number of elements.
673 !! @param gdim Number of geometric dimensions.
674 function cfl_compressible_d(dt, max_wave_speed, Xh, coef, nelv, gdim)
675 real(kind=dp), intent(in) :: dt
676 type(c_ptr), intent(in) :: max_wave_speed
677 type(space_t), intent(in) :: xh
678 type(coef_t), intent(in) :: coef
679 integer, intent(in) :: nelv, gdim
680 real(kind=dp) :: cfl_compressible_d
681
682 cfl_compressible_d = cfl(dt, max_wave_speed, max_wave_speed, &
683 max_wave_speed, xh, coef, nelv, gdim)
684
685 end function cfl_compressible_d
686
687 !! Compute the CFL number for compressible flows
688 !! @param dt The timestep.
689 !! @param max_wave_speed The precomputed maximum wave speed field.
690 !! @param Xh The SEM function space.
691 !! @param coef The SEM coefficients.
692 !! @param nelv The total number of elements.
693 !! @param gdim Number of geometric dimensions.
694 function cfl_compressible_f(dt, max_wave_speed, Xh, coef, nelv, gdim)
695 real(kind=dp), intent(in) :: dt
696 type(field_t), intent(in) :: max_wave_speed
697 type(space_t), intent(in) :: xh
698 type(coef_t), intent(in) :: coef
699 integer, intent(in) :: nelv, gdim
700 real(kind=dp) :: cfl_compressible_f
701
702 cfl_compressible_f = cfl(dt, max_wave_speed, max_wave_speed, &
703 max_wave_speed, xh, coef, nelv, gdim)
704
705 end function cfl_compressible_f
706
707 !> Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i
708 !! @param s11 Will hold the 1,1 component of the strain rate tensor.
709 !! @param s22 Will hold the 2,2 component of the strain rate tensor.
710 !! @param s33 Will hold the 3,3 component of the strain rate tensor.
711 !! @param s12 Will hold the 1,2 component of the strain rate tensor.
712 !! @param s13 Will hold the 1,3 component of the strain rate tensor.
713 !! @param s23 Will hold the 2,3 component of the strain rate tensor.
714 !! @param u The x component of velocity.
715 !! @param v The y component of velocity.
716 !! @param w The z component of velocity.
717 !! @param coef The SEM coefficients.
718 !! @note Similar to comp_sij in Nek5000.
719 subroutine strain_rate_r4(s11, s22, s33, s12, s13, s23, u, v, w, coef)
720 real(kind=rp), contiguous, intent(inout) :: s11(:,:,:,:)
721 real(kind=rp), contiguous, intent(inout) :: s22(:,:,:,:)
722 real(kind=rp), contiguous, intent(inout) :: s33(:,:,:,:)
723 real(kind=rp), contiguous, intent(inout) :: s12(:,:,:,:)
724 real(kind=rp), contiguous, intent(inout) :: s13(:,:,:,:)
725 real(kind=rp), contiguous, intent(inout) :: s23(:,:,:,:)
726 real(kind=rp), contiguous, intent(in) :: u(:,:,:,:), v(:,:,:,:), w(:,:,:,:)
727 type(coef_t), intent(in) :: coef
728
729 type(c_ptr) :: s11_d, s22_d, s33_d, s12_d, s23_d, s13_d, u_d, v_d, w_d
730
731 integer :: nelv, lxyz
732
733 nelv = coef%msh%nelv
734 lxyz = coef%Xh%lxyz
735
736 if (neko_bcknd_device .eq. 1) then
737 call neko_log%deprecated('Operator: strain_rate_r4, implicit device', &
738 '2.0.0', 'Please call strain_rate_d instead.')
739 s11_d = device_get_ptr(s11)
740 s22_d = device_get_ptr(s22)
741 s33_d = device_get_ptr(s33)
742 s12_d = device_get_ptr(s12)
743 s23_d = device_get_ptr(s23)
744 s13_d = device_get_ptr(s13)
745 u_d = device_get_ptr(u)
746 v_d = device_get_ptr(v)
747 w_d = device_get_ptr(w)
748
749 call dudxyz(s12_d, u_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
750 call dudxyz(s11_d, v_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
751 call device_add2(s12_d, s11_d, nelv*lxyz)
752
753 call dudxyz(s13_d, u_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
754 call dudxyz(s11_d, w_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
755 call device_add2(s13_d, s11_d, nelv*lxyz)
756
757 call dudxyz(s23_d, v_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
758 call dudxyz(s11_d, w_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
759 call device_add2(s23_d, s11_d, nelv*lxyz)
760
761 call dudxyz(s11_d, u_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
762 call dudxyz(s22_d, v_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
763 call dudxyz(s33_d, w_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
764 call device_cmult(s12_d, 0.5_rp, nelv*lxyz)
765 call device_cmult(s13_d, 0.5_rp, nelv*lxyz)
766 call device_cmult(s23_d, 0.5_rp, nelv*lxyz)
767 else
768 call dudxyz(s12, u, coef%drdy, coef%dsdy, coef%dtdy, coef)
769 call dudxyz(s11, v, coef%drdx, coef%dsdx, coef%dtdx, coef)
770 call add2(s12, s11, nelv*lxyz)
771
772 call dudxyz(s13, u, coef%drdz, coef%dsdz, coef%dtdz, coef)
773 call dudxyz(s11, w, coef%drdx, coef%dsdx, coef%dtdx, coef)
774 call add2(s13, s11, nelv*lxyz)
775
776 call dudxyz(s23, v, coef%drdz, coef%dsdz, coef%dtdz, coef)
777 call dudxyz(s11, w, coef%drdy, coef%dsdy, coef%dtdy, coef)
778 call add2(s23, s11, nelv*lxyz)
779
780 call dudxyz(s11, u, coef%drdx, coef%dsdx, coef%dtdx, coef)
781 call dudxyz(s22, v, coef%drdy, coef%dsdy, coef%dtdy, coef)
782 call dudxyz(s33, w, coef%drdz, coef%dsdz, coef%dtdz, coef)
783 call cmult(s12, 0.5_rp, nelv*lxyz)
784 call cmult(s13, 0.5_rp, nelv*lxyz)
785 call cmult(s23, 0.5_rp, nelv*lxyz)
786 end if
787
788 end subroutine strain_rate_r4
789
790 !> Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i
791 !! @param s11_d Will hold the 1,1 component of the strain rate tensor.
792 !! @param s22_d Will hold the 2,2 component of the strain rate tensor.
793 !! @param s33_d Will hold the 3,3 component of the strain rate tensor.
794 !! @param s12_d Will hold the 1,2 component of the strain rate tensor.
795 !! @param s13_d Will hold the 1,3 component of the strain rate tensor.
796 !! @param s23_d Will hold the 2,3 component of the strain rate tensor.
797 !! @param u_d The x component of velocity.
798 !! @param v_d The y component of velocity.
799 !! @param w_d The z component of velocity.
800 !! @param coef The SEM coefficients.
801 !! @note Similar to comp_sij in Nek5000.
802 subroutine strain_rate_d(s11_d, s22_d, s33_d, s12_d, s13_d, s23_d, &
803 u_d, v_d, w_d, coef)
804 type(c_ptr), intent(inout) :: s11_d, s22_d, s33_d, s12_d, s13_d, s23_d
805 type(c_ptr), intent(in) :: u_d, v_d, w_d
806 type(coef_t), intent(in) :: coef
807
808 integer :: nelv, lxyz
809
810 nelv = coef%msh%nelv
811 lxyz = coef%Xh%lxyz
812
813 call dudxyz(s12_d, u_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
814 call dudxyz(s11_d, v_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
815 call device_add2(s12_d, s11_d, nelv*lxyz)
816
817 call dudxyz(s13_d, u_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
818 call dudxyz(s11_d, w_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
819 call device_add2(s13_d, s11_d, nelv*lxyz)
820
821 call dudxyz(s23_d, v_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
822 call dudxyz(s11_d, w_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
823 call device_add2(s23_d, s11_d, nelv*lxyz)
824
825 call dudxyz(s11_d, u_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
826 call dudxyz(s22_d, v_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
827 call dudxyz(s33_d, w_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
828 call device_cmult(s12_d, 0.5_rp, nelv*lxyz)
829 call device_cmult(s13_d, 0.5_rp, nelv*lxyz)
830 call device_cmult(s23_d, 0.5_rp, nelv*lxyz)
831
832 end subroutine strain_rate_d
833
834 !> Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i
835 !! @param s11 Will hold the 1,1 component of the strain rate tensor.
836 !! @param s22 Will hold the 2,2 component of the strain rate tensor.
837 !! @param s33 Will hold the 3,3 component of the strain rate tensor.
838 !! @param s12 Will hold the 1,2 component of the strain rate tensor.
839 !! @param s13 Will hold the 1,3 component of the strain rate tensor.
840 !! @param s23 Will hold the 2,3 component of the strain rate tensor.
841 !! @param u The x component of velocity.
842 !! @param v The y component of velocity.
843 !! @param w The z component of velocity.
844 !! @param coef The SEM coefficients.
845 !! @note Similar to comp_sij in Nek5000.
846 subroutine strain_rate_f(s11, s22, s33, s12, s13, s23, u, v, w, coef)
847 type(field_t), intent(inout) :: s11, s22, s33, s12, s13, s23
848 type(field_t), intent(in) :: u, v, w
849 type(coef_t), intent(in) :: coef
850
851 integer :: n
852 n = coef%Xh%lxyz * coef%msh%nelv
853
854 if (neko_bcknd_device .eq. 1) then
855 call dudxyz(s12%x_d, u%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
856 call dudxyz(s11%x_d, v%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
857 call device_add2(s12%x_d, s11%x_d, n)
858
859 call dudxyz(s13%x_d, u%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
860 call dudxyz(s11%x_d, w%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
861 call device_add2(s13%x_d, s11%x_d, n)
862
863 call dudxyz(s23%x_d, v%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
864 call dudxyz(s11%x_d, w%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
865 call device_add2(s23%x_d, s11%x_d, n)
866
867 call dudxyz(s11%x_d, u%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
868 call dudxyz(s22%x_d, v%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
869 call dudxyz(s33%x_d, w%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
870 call device_cmult(s12%x_d, 0.5_rp, n)
871 call device_cmult(s13%x_d, 0.5_rp, n)
872 call device_cmult(s23%x_d, 0.5_rp, n)
873 else
874 call dudxyz(s12%x, u%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
875 call dudxyz(s11%x, v%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
876 call add2(s12%x, s11%x, n)
877
878 call dudxyz(s13%x, u%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
879 call dudxyz(s11%x, w%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
880 call add2(s13%x, s11%x, n)
881
882 call dudxyz(s23%x, v%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
883 call dudxyz(s11%x, w%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
884 call add2(s23%x, s11%x, n)
885
886 call dudxyz(s11%x, u%x, coef%drdx, coef%dsdx, coef%dtdx, coef)
887 call dudxyz(s22%x, v%x, coef%drdy, coef%dsdy, coef%dtdy, coef)
888 call dudxyz(s33%x, w%x, coef%drdz, coef%dsdz, coef%dtdz, coef)
889 call cmult(s12%x, 0.5_rp, n)
890 call cmult(s13%x, 0.5_rp, n)
891 call cmult(s23%x, 0.5_rp, n)
892 end if
893
894 end subroutine strain_rate_f
895
896 !> Compute the Lambda2 field for a given velocity field.
897 !! @param lambda2 Holds the computed Lambda2 field.
898 !! @param u The x-velocity.
899 !! @param v The y-velocity.
900 !! @param w the z-velocity.
901 !! @param coef The SEM coefficients.
902 subroutine lambda2op(lambda2, u, v, w, coef)
903 type(coef_t), intent(in) :: coef
904 type(field_t), intent(inout) :: lambda2
905 type(field_t), intent(in) :: u, v, w
906
907 if (neko_bcknd_sx .eq. 1) then
908 call opr_sx_lambda2(lambda2%x, u%x, v%x, w%x, coef)
909 else if (neko_bcknd_device .eq. 1) then
910 call opr_device_lambda2(lambda2%x_d, u%x_d, v%x_d, w%x_d, coef)
911 else
912 call opr_cpu_lambda2(lambda2%x, u%x, v%x, w%x, coef)
913 end if
914
915 end subroutine lambda2op
916
917 !> Transforms the convecting velocity field to the rst form of the GL space
918 !! @param cr convecting velocity in r-direction
919 !! @param cs convecting velocity in s-direction
920 !! @param ct convecting velocity in t-direction
921 !! @param cx convecting velocity in x-direction
922 !! @param cy convecting velocity in y-direction
923 !! @param cz convecting velocity in z-direction
924 !! @param Xh The GL space used for dealiasing
925 !! @param coef The coeffiecients of the GL space used for dealiasing
926 !! @note This subroutine is equal to the set_convect_new subroutine of NEK5000
927 subroutine set_convect_rst(cr, cs, ct, cx, cy, cz, Xh, coef)
928 type(space_t), intent(inout) :: xh
929 type(coef_t), intent(inout) :: coef
930 type(field_t), intent(inout) :: cr, cs, ct
931 real(kind=rp), dimension(Xh%lxyz, coef%msh%nelv), &
932 intent(in) :: cx, cy, cz
933 type(c_ptr) :: cx_d, cy_d, cz_d
934
935 if (neko_bcknd_sx .eq. 1) then
936 call opr_sx_set_convect_rst(cr%x, cs%x, ct%x, cx, cy, cz, xh, coef)
937 else if (neko_bcknd_xsmm .eq. 1) then
938 call opr_xsmm_set_convect_rst(cr%x, cs%x, ct%x, cx, cy, cz, xh, coef)
939 else if (neko_bcknd_device .eq. 1) then
940 cx_d = device_get_ptr(cx)
941 cy_d = device_get_ptr(cy)
942 cz_d = device_get_ptr(cz)
943 call opr_device_set_convect_rst(cr%x_d, cs%x_d, ct%x_d, &
944 cx_d, cy_d, cz_d, xh, coef)
945 else
946 call opr_cpu_set_convect_rst(cr%x, cs%x, ct%x, cx, cy, cz, xh, coef)
947 end if
948
949 end subroutine set_convect_rst
950
951 !> Compute one step of Runge Kutta time interpolation for OIFS scheme
952 !! @param phi The iterpolated field
953 !! @param conv_k1 The covecting velocity for the first stage
954 !! @param conv_k23 The convecting velocity for the second and third stage
955 !! @param conv_k4 The convecting velocity for the fourth stage
956 !! @param Xh_GLL The GLL space used in simulation
957 !! @param Xh_GL The GL space used for dealiasing
958 !! @param coef The coefficients of the original space in simulation
959 !! @param coef_GL The coefficients of the GL space used for dealiasing
960 !! @param GLL_to_GL the interpolator between the GLL and GL spaces
961 !! @param tau The the starting time
962 !! @param dtau The time step used for the Runge Kutta scheme
963 !! @param n size of phi
964 !! @param nel Total number of elements
965 !! @param n_GL the size in the GL space
966 subroutine runge_kutta(phi, conv_k1, conv_k23, conv_k4, Xh_GLL, Xh_GL, &
967 coef, coef_GL, GLL_to_GL, tau, dtau, n, nel, n_GL)
968 type(space_t), intent(in) :: xh_gll
969 type(space_t), intent(inout) :: xh_gl
970 type(coef_t), intent(in) :: coef
971 type(coef_t), intent(inout) :: coef_gl
972 type(interpolator_t) :: gll_to_gl
973 real(kind=dp), intent(inout) :: tau, dtau
974 integer, intent(in) :: n, nel, n_gl
975 type(field_t), intent(inout) :: phi
976 type(field_list_t) :: conv_k1, conv_k23, conv_k4
977 real(kind=rp) :: c1, c2, c3
978 type(field_t), pointer :: u1, k1, k2, k3, k4
979 type(vector_t), pointer :: u1_gl
980 integer :: ind(6), i, e
981
982 call neko_scratch_registry%request_field(u1, ind(1), .false.)
983 call neko_scratch_registry%request_field(k1, ind(2), .false.)
984 call neko_scratch_registry%request_field(k2, ind(3), .false.)
985 call neko_scratch_registry%request_field(k3, ind(4), .false.)
986 call neko_scratch_registry%request_field(k4, ind(5), .false.)
987 call neko_scratch_registry%request_vector(u1_gl, ind(6), n_gl, .false.)
988
989 c1 = 1.0_rp
990 c2 = -dtau / 2.0_rp
991 c3 = -dtau
992
993 if (neko_bcknd_device .eq. 1) then
994
995 ! Stage 1:
996 call device_invcol3(u1%x_d, phi%x_d, coef%B_d, n)
997 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
998 call convect_scalar(k1%x, u1_gl%x, conv_k1%items(1)%ptr, &
999 conv_k1%items(2)%ptr, conv_k1%items(3)%ptr, &
1000 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1001 call device_col2(k1%x_d, coef%B_d, n)
1002
1003 ! Stage 2:
1004 call device_add3s2(u1%x_d, phi%x_d, k1%x_d, c1, c2, n)
1005 call device_invcol2(u1%x_d, coef%B_d, n)
1006 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1007 call convect_scalar(k2%x, u1_gl%x, conv_k23%items(1)%ptr, &
1008 conv_k23%items(2)%ptr, conv_k23%items(3)%ptr, &
1009 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1010 call device_col2(k2%x_d, coef%B_d, n)
1011
1012 ! Stage 3:
1013 call device_add3s2(u1%x_d, phi%x_d, k2%x_d, c1, c2, n)
1014 call device_invcol2(u1%x_d, coef%B_d, n)
1015 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1016 call convect_scalar(k3%x, u1_gl%x, conv_k23%items(1)%ptr, &
1017 conv_k23%items(2)%ptr, conv_k23%items(3)%ptr, &
1018 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1019 call device_col2(k3%x_d, coef%B_d, n)
1020
1021 ! Stage 4:
1022 call device_add3s2(u1%x_d, phi%x_d, k3%x_d, c1, c3, n)
1023 call device_invcol2(u1%x_d, coef%B_d, n)
1024 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1025 call convect_scalar(k4%x, u1_gl%x, conv_k4%items(1)%ptr, &
1026 conv_k4%items(2)%ptr, conv_k4%items(3)%ptr, &
1027 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1028 call device_col2(k4%x_d, coef%B_d, n)
1029
1030 c1 = -dtau / 6.0_rp
1031 c2 = -dtau / 3.0_rp
1032
1033 call device_add5s4(phi%x_d, k1%x_d, k2%x_d, k3%x_d, k4%x_d, &
1034 c1, c2, c2, c1, n)
1035
1036 else
1037
1038 ! Stage 1:
1039 call invcol3(u1%x, phi%x, coef%B, n)
1040 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1041 call convect_scalar(k1%x, u1_gl%x, conv_k1%items(1)%ptr, &
1042 conv_k1%items(2)%ptr, conv_k1%items(3)%ptr, &
1043 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1044 call col2(k1%x, coef%B, n)
1045
1046 ! Stage 2:
1047 call add3s2(u1%x, phi%x, k1%x, c1, c2, n)
1048 call invcol2(u1%x, coef%B, n)
1049 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1050 call convect_scalar(k2%x, u1_gl%x, conv_k23%items(1)%ptr, &
1051 conv_k23%items(2)%ptr, conv_k23%items(3)%ptr, &
1052 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1053 call col2(k2%x, coef%B, n)
1054
1055 ! Stage 3:
1056 call add3s2(u1%x, phi%x, k2%x, c1, c2, n)
1057 call invcol2(u1%x, coef%B, n)
1058 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1059 call convect_scalar(k3%x, u1_gl%x, conv_k23%items(1)%ptr, &
1060 conv_k23%items(2)%ptr, conv_k23%items(3)%ptr, &
1061 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1062 call col2(k3%x, coef%B, n)
1063
1064 ! Stage 4:
1065 call add3s2(u1%x, phi%x, k3%x, c1, c3, n)
1066 call invcol2(u1%x, coef%B, n)
1067 call gll_to_gl%map(u1_gl%x, u1%x, nel, xh_gl)
1068 call convect_scalar(k4%x, u1_gl%x, conv_k4%items(1)%ptr, &
1069 conv_k4%items(2)%ptr, conv_k4%items(3)%ptr, &
1070 xh_gll, xh_gl, coef, coef_gl, gll_to_gl)
1071 call col2(k4%x, coef%B, n)
1072
1073 c1 = -dtau / 6.0_rp
1074 c2 = -dtau / 3.0_rp
1075 call add5s4(phi%x, k1%x, k2%x, k3%x, k4%x, c1, c2, c2, c1, n)
1076 end if
1077
1078 call neko_scratch_registry%relinquish(ind)
1079
1080 end subroutine runge_kutta
1081
1082 subroutine rotate_cyc_r1(vx, vy, vz, idir, coef)
1083 real(kind=rp), contiguous, dimension(:), intent(inout) :: vx, vy, vz
1084 integer, intent(in) :: idir
1085 type(coef_t), intent(in) :: coef
1086 type(c_ptr) :: vx_d, vy_d, vz_d
1087
1088 if (coef%cyclic .and. coef%cyc_msk(0) .gt. 1) then
1089 if (neko_bcknd_device .eq. 1) then
1090 call neko_log%deprecated('Operator: rotate_cyc_r1, implicit device', &
1091 '2.0.0', 'Please call rotate_cyc_d instead.')
1092
1093 vx_d = device_get_ptr(vx)
1094 vy_d = device_get_ptr(vy)
1095 vz_d = device_get_ptr(vz)
1096 call opr_device_rotate_cyc(vx_d, vy_d, vz_d, idir, coef)
1097 else
1098 call opr_cpu_rotate_cyc_r1(vx, vy, vz, idir, coef)
1099 end if
1100 end if
1101 end subroutine rotate_cyc_r1
1102
1103 subroutine rotate_cyc_r4(vx, vy, vz, idir, coef)
1104 real(kind=rp), contiguous, dimension(:,:,:,:), intent(inout) :: vx, vy, vz
1105 integer, intent(in) :: idir
1106 type(coef_t), intent(in) :: coef
1107 type(c_ptr) :: vx_d, vy_d, vz_d
1108
1109 if (coef%cyclic .and. coef%cyc_msk(0) .gt. 1) then
1110 if (neko_bcknd_device .eq. 1) then
1111 call neko_log%deprecated('Operator: rotate_cyc_r4, implicit device', &
1112 '2.0.0', 'Please call rotate_cyc_d instead.')
1113
1114 vx_d = device_get_ptr(vx)
1115 vy_d = device_get_ptr(vy)
1116 vz_d = device_get_ptr(vz)
1117 call opr_device_rotate_cyc(vx_d, vy_d, vz_d, idir, coef)
1118 else
1119 call opr_cpu_rotate_cyc_r4(vx, vy, vz, idir, coef)
1120 end if
1121 end if
1122 end subroutine rotate_cyc_r4
1123
1124 subroutine rotate_cyc_d(vx_d, vy_d, vz_d, idir, coef)
1125 type(c_ptr), intent(inout) :: vx_d, vy_d, vz_d
1126 integer, intent(in) :: idir
1127 type(coef_t), intent(in) :: coef
1128
1129 if (coef%cyclic .and. coef%cyc_msk(0) .gt. 1) then
1130 call opr_device_rotate_cyc(vx_d, vy_d, vz_d, idir, coef)
1131 end if
1132 end subroutine rotate_cyc_d
1133
1134 subroutine rotate_cyc_f(vx, vy, vz, idir, coef)
1135 type(field_t), intent(inout) :: vx, vy, vz
1136 integer, intent(in) :: idir
1137 type(coef_t), intent(in) :: coef
1138
1139 if (coef%cyclic .and. coef%cyc_msk(0) .gt. 1) then
1140 if (neko_bcknd_device .eq. 1) then
1141 call opr_device_rotate_cyc(vx%x_d, vy%x_d, vz%x_d, idir, coef)
1142 else
1143 call opr_cpu_rotate_cyc_r4(vx%x, vy%x, vz%x, idir, coef)
1144 end if
1145 end if
1146 end subroutine rotate_cyc_f
1147
1148end module operators
Return the device pointer for an associated Fortran array.
Definition device.F90:113
Map a Fortran array to a device (allocate and associate).
Definition device.F90:83
Compute CFL condition for compressible flow.
Compute CFL condition.
Definition operators.f90:98
Compute the divergence of a vector field.
Definition operators.f90:86
Compute derivative of a scalar field along a single direction.
Definition operators.f90:79
Compute the gradient of a scalar field, multiplied by the mass matrix.
Definition operators.f90:92
Apply cyclic boundary condition to a vector field.
Compute the strain rate tensor of a vector field.
Coefficients.
Definition coef.f90:34
Definition comm.F90:1
type(mpi_datatype), public mpi_real_precision
MPI type for working precision of REAL types.
Definition comm.F90:54
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:46
subroutine, public device_add2(a_d, b_d, n, strm)
Vector addition .
real(kind=rp) function, public device_glsum(a_d, n, strm)
Sum a vector of length n.
subroutine, public device_add3s2(a_d, b_d, c_d, c1, c2, n, strm)
Returns .
subroutine, public device_cmult(a_d, c, n, strm)
Multiplication by constant c .
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_invcol3(a_d, b_d, c_d, n, strm)
Vector division .
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
subroutine, public device_add5s4(a_d, b_d, c_d, d_d, e_d, c1, c2, c3, c4, n, strm)
Returns .
subroutine, public device_invcol2(a_d, b_d, n, strm)
Vector division .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
subroutine, public device_free(x_d)
Deallocate memory on the device.
Definition device.F90:281
subroutine, public field_rzero(a, n)
Zero a real vector.
Defines a field.
Definition field.f90:34
Routines to interpolate between different spaces.
A simulation component that computes lambda2 The values are stored in the field registry under the na...
Definition lambda2.f90:37
Logging routines.
Definition log.f90:34
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
Definition math.F90:60
subroutine, public cmult(a, c, n)
Multiplication by constant c .
Definition math.F90:518
subroutine, public invcol2(a, b, n)
Vector division .
Definition math.F90:1079
subroutine, public cadd(a, s, n)
Add a scalar to vector .
Definition math.F90:580
real(kind=rp) function, public glsum(a, n)
Sum a vector of length n.
Definition math.F90:643
subroutine, public add2(a, b, n)
Vector addition .
Definition math.F90:949
subroutine, public invcol3(a, b, c, n)
Invert a vector .
Definition math.F90:834
subroutine, public add3s2(a, b, c, c1, c2, n)
Returns .
Definition math.F90:1142
subroutine, public col2(a, b, n)
Vector multiplication .
Definition math.F90:1095
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
subroutine, public add5s4(a, b, c, d, e, c1, c2, c3, c4, n)
Returns .
Definition math.F90:1177
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.F90:249
Build configurations.
integer, parameter neko_bcknd_sx
integer, parameter neko_bcknd_device
logical, parameter neko_device_mpi
integer, parameter neko_bcknd_xsmm
integer, parameter, public i8
Definition num_types.f90:7
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
real(kind=dp) function cfl_compressible_r4(dt, max_wave_speed, xh, coef, nelv, gdim)
subroutine, public set_convect_rst(cr, cs, ct, cx, cy, cz, xh, coef)
Transforms the convecting velocity field to the rst form of the GL space.
subroutine, public ortho(x, glb_n_points, n)
Othogonalize with regard to vector (1,1,1,1,1,1...,1)^T.
subroutine strain_rate_d(s11_d, s22_d, s33_d, s12_d, s13_d, s23_d, u_d, v_d, w_d, coef)
Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i.
subroutine dudxyz_r4(du, u, dr, ds, dt, coef)
Compute derivative of a scalar field along a single direction.
subroutine, public opgrad(ux, uy, uz, u, coef, es, ee)
Compute the weak gradient of a scalar field, i.e. the gradient multiplied by the mass matrix.
subroutine div_r4(res, ux, uy, uz, coef)
Compute the divergence of a vector field.
subroutine rotate_cyc_r1(vx, vy, vz, idir, coef)
subroutine grad_r4(ux, uy, uz, u, coef)
Compute the gradient of a scalar field.
subroutine strain_rate_r4(s11, s22, s33, s12, s13, s23, u, v, w, coef)
Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i.
real(kind=dp) function cfl_f(dt, u, v, w, xh, coef, nelv, gdim)
subroutine convect_scalar(du, u, cr, cs, ct, xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
Apply the convecting velocity c to the to the scalar field u, used in the OIFS scheme.
real(kind=dp) function cfl_r4(dt, u, v, w, xh, coef, nelv, gdim)
subroutine rotate_cyc_r4(vx, vy, vz, idir, coef)
subroutine grad_d(ux_d, uy_d, uz_d, u_d, coef)
Compute the gradient of a scalar field.
subroutine, public conv1(du, u, vx, vy, vz, xh, coef, es, ee)
Compute the advection term.
subroutine div_d(res_d, ux_d, uy_d, uz_d, coef)
Compute the divergence of a vector field.
subroutine, public curl(w1, w2, w3, u1, u2, u3, work1, work2, coef, event)
subroutine strain_rate_f(s11, s22, s33, s12, s13, s23, u, v, w, coef)
Compute the strain rate tensor, i.e 0.5 * du_i/dx_j + du_j/dx_i.
real(kind=dp) function cfl_compressible_f(dt, max_wave_speed, xh, coef, nelv, gdim)
subroutine, public lambda2op(lambda2, u, v, w, coef)
Compute the Lambda2 field for a given velocity field.
subroutine rotate_cyc_d(vx_d, vy_d, vz_d, idir, coef)
subroutine dudxyz_f(du, u, dr, ds, dt, coef)
Compute derivative of a scalar field along a single direction.
real(kind=dp) function cfl_d(dt, u_d, v_d, w_d, xh, coef, nelv, gdim)
real(kind=dp) function cfl_compressible_d(dt, max_wave_speed, xh, coef, nelv, gdim)
subroutine, public cdtp(dtx, x, dr, ds, dt, coef, es, ee)
Apply D^T to a scalar field, where D is the derivative matrix.
subroutine rotate_cyc_f(vx, vy, vz, idir, coef)
subroutine, public runge_kutta(phi, conv_k1, conv_k23, conv_k4, xh_gll, xh_gl, coef, coef_gl, gll_to_gl, tau, dtau, n, nel, n_gl)
Compute one step of Runge Kutta time interpolation for OIFS scheme.
Operators CPU backend.
Definition opr_cpu.f90:34
subroutine, public opr_cpu_curl(w1, w2, w3, u1, u2, u3, work1, work2, c_xh)
Definition opr_cpu.f90:127
subroutine, public opr_cpu_rotate_cyc_r1(vx, vy, vz, idir, coef)
Definition opr_cpu.f90:334
subroutine, public opr_cpu_lambda2(lambda2, u, v, w, coef)
Definition opr_cpu.f90:249
subroutine, public opr_cpu_rotate_cyc_r4(vx, vy, vz, idir, coef)
Definition opr_cpu.f90:361
real(kind=dp) function, public opr_cpu_cfl(dt, u, v, w, xh, coef, nelv, gdim)
Definition opr_cpu.f90:183
Operators accelerator backends.
subroutine, public opr_device_convect_scalar(du, u_d, cr_d, cs_d, ct_d, xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
subroutine, public opr_device_cdtp(dtx_d, x_d, dr_d, ds_d, dt_d, coef)
subroutine, public opr_device_dudxyz(du_d, u_d, dr_d, ds_d, dt_d, coef)
real(kind=dp) function, public opr_device_cfl(dt, u_d, v_d, w_d, xh, coef, nelv, gdim)
subroutine, public opr_device_conv1(du_d, u_d, vx_d, vy_d, vz_d, xh, coef, nelv, gdim)
subroutine, public opr_device_curl(w1, w2, w3, u1, u2, u3, work1, work2, c_xh, event)
subroutine, public opr_device_set_convect_rst(cr_d, cs_d, ct_d, cx_d, cy_d, cz_d, xh, coef)
subroutine, public opr_device_lambda2(lambda2_d, u_d, v_d, w_d, coef)
subroutine, public opr_device_rotate_cyc(vx_d, vy_d, vz_d, idir, coef)
subroutine, public opr_device_opgrad(ux_d, uy_d, uz_d, u_d, coef)
Operators SX-Aurora backend.
Definition opr_sx.f90:2
subroutine, public opr_sx_curl(w1, w2, w3, u1, u2, u3, work1, work2, c_xh)
Definition opr_sx.f90:103
Operators libxsmm backend.
Definition opr_xsmm.F90:61
subroutine, public opr_xsmm_convect_scalar(du, u, cr, cs, ct, xh_gll, xh_gl, coef_gll, coef_gl, gll_to_gl)
Definition opr_xsmm.F90:370
subroutine, public opr_xsmm_conv1(du, u, vx, vy, vz, xh, coef, nelv, gdim)
Definition opr_xsmm.F90:296
subroutine, public opr_xsmm_cdtp(dtx, x, dr, ds, dt, coef)
Definition opr_xsmm.F90:241
subroutine, public opr_xsmm_curl(w1, w2, w3, u1, u2, u3, work1, work2, c_xh)
Definition opr_xsmm.F90:417
subroutine, public opr_xsmm_dudxyz(du, u, dr, ds, dt, coef)
Definition opr_xsmm.F90:91
subroutine, public opr_xsmm_opgrad(ux, uy, uz, u, coef)
Definition opr_xsmm.F90:145
subroutine, public opr_xsmm_set_convect_rst(cr, cs, ct, cx, cy, cz, xh, coef)
Definition opr_xsmm.F90:474
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Defines a function space.
Definition space.f90:34
Defines a vector.
Definition vector.f90:34
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
Interpolation between two space::space_t.
The function space for the SEM solution fields.
Definition space.f90:64