Neko 1.99.2
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
entropy_viscosity_device.F90
Go to the documentation of this file.
1! Copyright (c) 2025, 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!
35 use, intrinsic :: iso_c_binding, only: c_ptr, c_int
36 use num_types, only: rp, c_rp
37 use utils, only: neko_error
38 implicit none
39 private
40
41#ifdef HAVE_HIP
42 interface
43 subroutine hip_entropy_visc_compute_residual(entropy_residual_d, &
44 S_d, S_lag1_d, S_lag2_d, S_lag3_d, &
45 bdf1, bdf2, bdf3, bdf4, dt, n) &
46 bind(c, name = 'hip_entropy_visc_compute_residual')
47 use, intrinsic :: iso_c_binding
48 import c_rp
49 type(c_ptr), value :: entropy_residual_d
50 type(c_ptr), value :: S_d, S_lag1_d, S_lag2_d, S_lag3_d
51 real(c_rp) :: bdf1, bdf2, bdf3, bdf4, dt
52 integer(c_int) :: n
54 end interface
55
56 interface
57 subroutine hip_entropy_visc_compute_viscosity(reg_coeff_d, &
58 entropy_residual_d, h_d, c_avisc_entropy, n_S, n) &
59 bind(c, name = 'hip_entropy_visc_compute_viscosity')
60 use, intrinsic :: iso_c_binding
61 import c_rp
62 type(c_ptr), value :: reg_coeff_d, entropy_residual_d, h_d
63 real(c_rp) :: c_avisc_entropy, n_S
64 integer(c_int) :: n
66 end interface
67
68 interface
69 subroutine hip_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv) &
70 bind(c, name = 'hip_entropy_visc_apply_element_max')
71 use, intrinsic :: iso_c_binding
72 type(c_ptr), value :: reg_coeff_d
73 integer(c_int) :: lx, nelv
75 end interface
76
77 interface
78 subroutine hip_entropy_visc_clamp_to_low_order(reg_coeff_d, &
79 h_d, max_wave_speed_d, c_avisc_low, n) &
80 bind(c, name = 'hip_entropy_visc_clamp_to_low_order')
81 use, intrinsic :: iso_c_binding
82 import c_rp
83 type(c_ptr), value :: reg_coeff_d, h_d, max_wave_speed_d
84 real(c_rp) :: c_avisc_low
85 integer(c_int) :: n
87 end interface
88
89 interface
90 subroutine hip_entropy_visc_smooth_divide(reg_coeff_d, &
91 temp_field_d, mult_field_d, n) &
92 bind(c, name = 'hip_entropy_visc_smooth_divide')
93 use, intrinsic :: iso_c_binding
94 type(c_ptr), value :: reg_coeff_d, temp_field_d, mult_field_d
95 integer(c_int) :: n
97 end interface
98
99#elif HAVE_CUDA
100 interface
101 subroutine cuda_entropy_visc_compute_residual(entropy_residual_d, &
102 S_d, S_lag1_d, S_lag2_d, S_lag3_d, &
103 bdf1, bdf2, bdf3, bdf4, dt, n) &
104 bind(c, name = 'cuda_entropy_visc_compute_residual')
105 use, intrinsic :: iso_c_binding
106 import c_rp
107 type(c_ptr), value :: entropy_residual_d
108 type(c_ptr), value :: S_d, S_lag1_d, S_lag2_d, S_lag3_d
109 real(c_rp) :: bdf1, bdf2, bdf3, bdf4, dt
110 integer(c_int) :: n
112 end interface
113
114 interface
115 subroutine cuda_entropy_visc_compute_viscosity(reg_coeff_d, &
116 entropy_residual_d, h_d, c_avisc_entropy, n_S, n) &
117 bind(c, name = 'cuda_entropy_visc_compute_viscosity')
118 use, intrinsic :: iso_c_binding
119 import c_rp
120 type(c_ptr), value :: reg_coeff_d, entropy_residual_d, h_d
121 real(c_rp) :: c_avisc_entropy, n_S
122 integer(c_int) :: n
124 end interface
125
126 interface
127 subroutine cuda_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv) &
128 bind(c, name = 'cuda_entropy_visc_apply_element_max')
129 use, intrinsic :: iso_c_binding
130 type(c_ptr), value :: reg_coeff_d
131 integer(c_int) :: lx, nelv
133 end interface
134
135 interface
136 subroutine cuda_entropy_visc_clamp_to_low_order(reg_coeff_d, &
137 h_d, max_wave_speed_d, c_avisc_low, n) &
138 bind(c, name = 'cuda_entropy_visc_clamp_to_low_order')
139 use, intrinsic :: iso_c_binding
140 import c_rp
141 type(c_ptr), value :: reg_coeff_d, h_d, max_wave_speed_d
142 real(c_rp) :: c_avisc_low
143 integer(c_int) :: n
145 end interface
146
147 interface
148 subroutine cuda_entropy_visc_smooth_divide(reg_coeff_d, &
149 temp_field_d, mult_field_d, n) &
150 bind(c, name = 'cuda_entropy_visc_smooth_divide')
151 use, intrinsic :: iso_c_binding
152 type(c_ptr), value :: reg_coeff_d, temp_field_d, mult_field_d
153 integer(c_int) :: n
155 end interface
156
157#elif HAVE_OPENCL
158 interface
159 subroutine opencl_entropy_visc_compute_residual(entropy_residual_d, &
160 S_d, S_lag1_d, S_lag2_d, S_lag3_d, &
161 bdf1, bdf2, bdf3, bdf4, dt, n) &
162 bind(c, name = 'opencl_entropy_visc_compute_residual')
163 use, intrinsic :: iso_c_binding
164 import c_rp
165 type(c_ptr), value :: entropy_residual_d
166 type(c_ptr), value :: S_d, S_lag1_d, S_lag2_d, S_lag3_d
167 real(c_rp), value :: bdf1, bdf2, bdf3, bdf4, dt
168 integer(c_int), value :: n
170 end interface
171
172 interface
173 subroutine opencl_entropy_visc_compute_viscosity(reg_coeff_d, &
174 entropy_residual_d, h_d, c_avisc_entropy, n_S, n) &
175 bind(c, name = 'opencl_entropy_visc_compute_viscosity')
176 use, intrinsic :: iso_c_binding
177 import c_rp
178 type(c_ptr), value :: reg_coeff_d, entropy_residual_d, h_d
179 real(c_rp), value :: c_avisc_entropy, n_S
180 integer(c_int), value :: n
182 end interface
183
184 interface
185 subroutine opencl_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv) &
186 bind(c, name = 'opencl_entropy_visc_apply_element_max')
187 use, intrinsic :: iso_c_binding
188 type(c_ptr), value :: reg_coeff_d
189 integer(c_int), value :: lx, nelv
191 end interface
192
193 interface
194 subroutine opencl_entropy_visc_clamp_to_low_order(reg_coeff_d, &
195 h_d, max_wave_speed_d, c_avisc_low, n) &
196 bind(c, name = 'opencl_entropy_visc_clamp_to_low_order')
197 use, intrinsic :: iso_c_binding
198 import c_rp
199 type(c_ptr), value :: reg_coeff_d, h_d, max_wave_speed_d
200 real(c_rp), value :: c_avisc_low
201 integer(c_int), value :: n
203 end interface
204
205 interface
206 subroutine opencl_entropy_visc_smooth_divide(reg_coeff_d, &
207 temp_field_d, mult_field_d, n) &
208 bind(c, name = 'opencl_entropy_visc_smooth_divide')
209 use, intrinsic :: iso_c_binding
210 type(c_ptr), value :: reg_coeff_d, temp_field_d, mult_field_d
211 integer(c_int), value :: n
213 end interface
214#endif
215
221
222contains
223
225 subroutine entropy_viscosity_compute_residual_device(entropy_residual_d, &
226 S_d, S_lag1_d, S_lag2_d, S_lag3_d, bdf_coeffs, dt, n)
227 type(c_ptr), intent(in) :: entropy_residual_d
228 type(c_ptr), intent(in) :: s_d, s_lag1_d, s_lag2_d, s_lag3_d
229 real(kind=rp), intent(in) :: bdf_coeffs(4)
230 real(kind=rp), intent(in) :: dt
231 integer, intent(in) :: n
232
233#ifdef HAVE_HIP
234 call hip_entropy_visc_compute_residual(entropy_residual_d, &
235 s_d, s_lag1_d, s_lag2_d, s_lag3_d, &
236 bdf_coeffs(1), bdf_coeffs(2), bdf_coeffs(3), bdf_coeffs(4), dt, n)
237#elif HAVE_CUDA
238 call cuda_entropy_visc_compute_residual(entropy_residual_d, &
239 s_d, s_lag1_d, s_lag2_d, s_lag3_d, &
240 bdf_coeffs(1), bdf_coeffs(2), bdf_coeffs(3), bdf_coeffs(4), dt, n)
241#elif HAVE_OPENCL
242 call opencl_entropy_visc_compute_residual(entropy_residual_d, &
243 s_d, s_lag1_d, s_lag2_d, s_lag3_d, &
244 bdf_coeffs(1), bdf_coeffs(2), bdf_coeffs(3), bdf_coeffs(4), dt, n)
245#else
246 call neko_error('No device backend configured')
247#endif
249
252 entropy_residual_d, h_d, c_avisc_entropy, n_S, n)
253 type(c_ptr), intent(in) :: reg_coeff_d, entropy_residual_d, h_d
254 real(kind=rp), intent(in) :: c_avisc_entropy, n_s
255 integer, intent(in) :: n
256
257#ifdef HAVE_HIP
258 call hip_entropy_visc_compute_viscosity(reg_coeff_d, &
259 entropy_residual_d, h_d, c_avisc_entropy, n_s, n)
260#elif HAVE_CUDA
261 call cuda_entropy_visc_compute_viscosity(reg_coeff_d, &
262 entropy_residual_d, h_d, c_avisc_entropy, n_s, n)
263#elif HAVE_OPENCL
264 call opencl_entropy_visc_compute_viscosity(reg_coeff_d, &
265 entropy_residual_d, h_d, c_avisc_entropy, n_s, n)
266#else
267 call neko_error('No device backend configured')
268#endif
270
272 subroutine entropy_viscosity_apply_element_max_device(reg_coeff_d, lx, nelv)
273 type(c_ptr), intent(in) :: reg_coeff_d
274 integer, intent(in) :: lx, nelv
275
276#ifdef HAVE_HIP
277 call hip_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv)
278#elif HAVE_CUDA
279 call cuda_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv)
280#elif HAVE_OPENCL
281 call opencl_entropy_visc_apply_element_max(reg_coeff_d, lx, nelv)
282#else
283 call neko_error('No device backend configured')
284#endif
286
289 h_d, max_wave_speed_d, c_avisc_low, n)
290 type(c_ptr), intent(in) :: reg_coeff_d, h_d, max_wave_speed_d
291 real(kind=rp), intent(in) :: c_avisc_low
292 integer, intent(in) :: n
293
294#ifdef HAVE_HIP
295 call hip_entropy_visc_clamp_to_low_order(reg_coeff_d, &
296 h_d, max_wave_speed_d, c_avisc_low, n)
297#elif HAVE_CUDA
298 call cuda_entropy_visc_clamp_to_low_order(reg_coeff_d, &
299 h_d, max_wave_speed_d, c_avisc_low, n)
300#elif HAVE_OPENCL
302 h_d, max_wave_speed_d, c_avisc_low, n)
303#else
304 call neko_error('No device backend configured')
305#endif
307
310 temp_field_d, mult_field_d, n)
311 type(c_ptr), intent(in) :: reg_coeff_d, temp_field_d, mult_field_d
312 integer, intent(in) :: n
313
314#ifdef HAVE_HIP
315 call hip_entropy_visc_smooth_divide(reg_coeff_d, &
316 temp_field_d, mult_field_d, n)
317#elif HAVE_CUDA
318 call cuda_entropy_visc_smooth_divide(reg_coeff_d, &
319 temp_field_d, mult_field_d, n)
320#elif HAVE_OPENCL
321 call opencl_entropy_visc_smooth_divide(reg_coeff_d, &
322 temp_field_d, mult_field_d, n)
323#else
324 call neko_error('No device backend configured')
325#endif
327
329
void opencl_entropy_visc_compute_viscosity(void *reg_coeff, void *entropy_residual, void *h, real c_avisc_entropy, real n_S, int n)
void opencl_entropy_visc_compute_residual(void *entropy_residual, void *S, void *S_lag1, void *S_lag2, void *S_lag3, real bdf1, real bdf2, real bdf3, real bdf4, real dt, int n)
void opencl_entropy_visc_smooth_divide(void *reg_coeff, void *temp_field, void *mult_field, int n)
void opencl_entropy_visc_clamp_to_low_order(void *reg_coeff, void *h, void *max_wave_speed, real c_avisc_low, int n)
void opencl_entropy_visc_apply_element_max(void *reg_coeff, int lx, int nelv)
void cuda_entropy_visc_apply_element_max(void *reg_coeff, int *lx, int *nelv)
void cuda_entropy_visc_smooth_divide(void *reg_coeff, void *temp_field, void *mult_field, int *n)
void cuda_entropy_visc_compute_residual(void *entropy_residual, void *S, void *S_lag1, void *S_lag2, void *S_lag3, real *bdf1, real *bdf2, real *bdf3, real *bdf4, real *dt, int *n)
void cuda_entropy_visc_clamp_to_low_order(void *reg_coeff, void *h, void *max_wave_speed, real *c_avisc_low, int *n)
void cuda_entropy_visc_compute_viscosity(void *reg_coeff, void *entropy_residual, void *h, real *c_avisc_entropy, real *n_S, int *n)
Device backend for entropy viscosity regularization.
subroutine, public entropy_viscosity_smooth_divide_device(reg_coeff_d, temp_field_d, mult_field_d, n)
Divide by multiplicity for smoothing on device.
subroutine, public entropy_viscosity_clamp_to_low_order_device(reg_coeff_d, h_d, max_wave_speed_d, c_avisc_low, n)
Clamp regularization coefficient to low-order viscosity on device.
subroutine, public entropy_viscosity_apply_element_max_device(reg_coeff_d, lx, nelv)
Apply element-wise maximum on device.
subroutine, public entropy_viscosity_compute_residual_device(entropy_residual_d, s_d, s_lag1_d, s_lag2_d, s_lag3_d, bdf_coeffs, dt, n)
Compute entropy residual on device.
subroutine, public entropy_viscosity_compute_viscosity_device(reg_coeff_d, entropy_residual_d, h_d, c_avisc_entropy, n_s, n)
Compute viscosity from entropy residual on device.
integer, parameter, public c_rp
Definition num_types.f90:13
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:12
Utilities.
Definition utils.f90:35