Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
vreman_device.f90
Go to the documentation of this file.
1! Copyright (c) 2023-2026, 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!> Implements the device kernel for the `vreman_t` type.
35 use num_types, only : rp
36 use math, only : neko_eps
38 use registry, only : neko_registry
39 use field, only : field_t
40 use operators, only : dudxyz
41 use coefs, only : coef_t
42 use gs_ops, only : gs_op_add
43 use device, only : glb_cmd_event
44 use device_math, only : device_col2
47
48 implicit none
49 private
50
51 public :: vreman_compute_device
52
53contains
54
55 !> Compute eddy viscosity on the device.
56 !! @param if_ext If extrapolate the velocity field to evaluate
57 !! @param t The time value.
58 !! @param tstep The current time-step.
59 !! @param coef SEM coefficients.
60 !! @param nut The SGS viscosity array.
61 !! @param delta The LES lengthscale.
62 !! @param c The Vreman model constant
63 !! @param if_corr Whether to apply buoyancy correction.
64 !! @param scalar_name The name of the scalar field for buoyancy correction.
65 !! @param ri_c Critical Richardson number.
66 !! @param ref_temp Reference temperature for Richardson number.
67 !! @param g The gravity vector.
68 subroutine vreman_compute_device(if_ext, t, tstep, coef, nut, delta, c,&
69 if_corr, scalar_name, ri_c, ref_temp, g)
70
71 logical, intent(in) :: if_ext
72 real(kind=rp), intent(in) :: t
73 integer, intent(in) :: tstep
74 type(coef_t), intent(in) :: coef
75 type(field_t), intent(inout) :: nut
76 type(field_t), intent(in) :: delta
77 real(kind=rp), intent(in) :: c
78 logical, intent(in) :: if_corr
79 character(len=*), intent(in) :: scalar_name
80 real(kind=rp), intent(in) :: ri_c, ref_temp
81 real(kind=rp), intent(in) :: g(3)
82
83 ! This is the alpha tensor in the paper
84 type(field_t), pointer :: a11, a12, a13, a21, a22, a23, a31, a32, a33
85 type(field_t), pointer :: u, v, w
86 type(field_t), pointer :: temperature, dtdx, dtdy, dtdz
87
88 type(field_t), pointer :: beta11
89 type(field_t), pointer :: beta12
90 type(field_t), pointer :: beta13
91 type(field_t), pointer :: beta22
92 type(field_t), pointer :: beta23
93 type(field_t), pointer :: beta33
94 type(field_t), pointer :: b_beta
95 type(field_t), pointer :: aijaij
96 integer :: temp_indices(9), temp_indices_buoy(3)
97 integer :: e, i
98
99 if (if_ext .eqv. .true.) then
100 u => neko_registry%get_field_by_name("u_e")
101 v => neko_registry%get_field_by_name("v_e")
102 w => neko_registry%get_field_by_name("w_e")
103 else
104 u => neko_registry%get_field_by_name("u")
105 v => neko_registry%get_field_by_name("v")
106 w => neko_registry%get_field_by_name("w")
107 end if
108
109 call neko_scratch_registry%request_field(a11, temp_indices(1), .false.)
110 call neko_scratch_registry%request_field(a12, temp_indices(2), .false.)
111 call neko_scratch_registry%request_field(a13, temp_indices(3), .false.)
112 call neko_scratch_registry%request_field(a21, temp_indices(4), .false.)
113 call neko_scratch_registry%request_field(a22, temp_indices(5), .false.)
114 call neko_scratch_registry%request_field(a23, temp_indices(6), .false.)
115 call neko_scratch_registry%request_field(a31, temp_indices(7), .false.)
116 call neko_scratch_registry%request_field(a32, temp_indices(8), .false.)
117 call neko_scratch_registry%request_field(a33, temp_indices(9), .false.)
118
119 ! Compute the derivatives of the velocity (the alpha tensor)
120 call dudxyz(a11%x_d, u%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
121 call dudxyz(a12%x_d, u%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
122 call dudxyz(a13%x_d, u%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
123
124 call dudxyz(a21%x_d, v%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
125 call dudxyz(a22%x_d, v%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
126 call dudxyz(a23%x_d, v%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
127
128 call dudxyz(a31%x_d, w%x_d, coef%drdx_d, coef%dsdx_d, coef%dtdx_d, coef)
129 call dudxyz(a32%x_d, w%x_d, coef%drdy_d, coef%dsdy_d, coef%dtdy_d, coef)
130 call dudxyz(a33%x_d, w%x_d, coef%drdz_d, coef%dsdz_d, coef%dtdz_d, coef)
131
132 call coef%gs_h%op(a11%x, a12%x, a13%x, a11%dof%size(), gs_op_add, &
134 call coef%gs_h%op(a21%x, a22%x, a23%x, a21%dof%size(), gs_op_add, &
136 call coef%gs_h%op(a31%x, a32%x, a33%x, a31%dof%size(), gs_op_add, &
138
139 if (if_corr) then
140 temperature => neko_registry%get_field_by_name(scalar_name)
141
142 call neko_scratch_registry%request_field(dtdx, temp_indices_buoy(1), &
143 .false.)
144 call neko_scratch_registry%request_field(dtdy, temp_indices_buoy(2), &
145 .false.)
146 call neko_scratch_registry%request_field(dtdz, temp_indices_buoy(3), &
147 .false.)
148
149 call dudxyz(dtdx%x_d, temperature%x_d, coef%drdx_d, coef%dsdx_d, &
150 coef%dtdx_d, coef)
151 call dudxyz(dtdy%x_d, temperature%x_d, coef%drdy_d, coef%dsdy_d, &
152 coef%dtdy_d, coef)
153 call dudxyz(dtdz%x_d, temperature%x_d, coef%drdz_d, coef%dsdz_d, &
154 coef%dtdz_d, coef)
155
156 call device_vreman_nut_compute_buoy(a11%x_d, a12%x_d, a13%x_d, &
157 a21%x_d, a22%x_d, a23%x_d, &
158 a31%x_d, a32%x_d, a33%x_d, &
159 delta%x_d, nut%x_d, coef%mult_d, &
160 c, neko_eps, a11%dof%size(), &
161 dtdx%x_d, dtdy%x_d, dtdz%x_d, &
162 g, ri_c, ref_temp)
163 call neko_scratch_registry%relinquish_field(temp_indices_buoy)
164 else
165 call device_vreman_nut_compute(a11%x_d, a12%x_d, a13%x_d, &
166 a21%x_d, a22%x_d, a23%x_d, &
167 a31%x_d, a32%x_d, a33%x_d, &
168 delta%x_d, nut%x_d, coef%mult_d, &
169 c, neko_eps, a11%dof%size())
170 end if
171
172 call coef%gs_h%op(nut, gs_op_add, glb_cmd_event)
173 call device_col2(nut%x_d, coef%mult_d, nut%dof%size())
174
175 call neko_scratch_registry%relinquish_field(temp_indices)
176 end subroutine vreman_compute_device
177
178end module vreman_device
Compute derivative of a scalar field along a single direction.
Definition operators.f90:79
Coefficients.
Definition coef.f90:34
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
subroutine, public device_vreman_nut_compute(a11_d, a12_d, a13_d, a21_d, a22_d, a23_d, a31_d, a32_d, a33_d, delta_d, nut_d, mult_d, c, eps, n)
Compute the eddy viscosity field for the Sigma model indevice.
subroutine, public device_vreman_nut_compute_buoy(a11_d, a12_d, a13_d, a21_d, a22_d, a23_d, a31_d, a32_d, a33_d, delta_d, nut_d, mult_d, c, eps, n, dtdx_d, dtdy_d, dtdz_d, g, ri_c, ref_temp)
Device abstraction, common interface for various accelerators.
Definition device.F90:34
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Definition device.F90:63
Defines a field.
Definition field.f90:34
Defines Gather-scatter operations.
Definition gs_ops.f90:34
integer, parameter, public gs_op_add
Definition gs_ops.f90:36
Definition math.F90:60
real(kind=rp), parameter, public neko_eps
Machine epsilon .
Definition math.F90:70
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
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.
Implements the device kernel for the vreman_t type.
subroutine, public vreman_compute_device(if_ext, t, tstep, coef, nut, delta, c, if_corr, scalar_name, ri_c, ref_temp, g)
Compute eddy viscosity on the device.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136