Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
deardorff_device.f90
Go to the documentation of this file.
1! Copyright (c) 2025-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 `deardorff_t` type.
35 use num_types, only : rp
36 use utils, only : neko_error
37 use math, only : neko_eps
39 use registry, only : neko_registry
40 use field, only : field_t
41 use operators, only : grad
42 use coefs, only : coef_t
43 use gs_ops, only : gs_op_add
44 use device, only : glb_cmd_event
45 use device_math, only : device_col2
47 implicit none
48 private
49
51
52contains
53
54 !> Compute eddy viscosity on the device.
55 !! @param t The time value.
56 !! @param tstep The current time-step.
57 !! @param coef SEM coefficients.
58 !! @param temperature_field_name The name of the temperature field.
59 !! @param TKE_field_name The name of the TKE field.
60 !! @param nut The eddy viscosity field.
61 !! @param temperature_alphat The eddy diffusivity field for temperature.
62 !! @param TKE_alphat The eddy diffusivity field for TKE.
63 !! @param TKE_source The source terms for TKE equation.
64 !! @param delta The LES lengthscale.
65 !! @param c_k The deardorff model constant
66 !! @param T0 The reference temperature.
67 !! @param g The gravitational acceleration vector.
68 subroutine deardorff_compute_device(t, tstep, coef, &
69 temperature_field_name, TKE_field_name, &
70 nut, temperature_alphat, &
71 TKE_alphat, TKE_source, &
72 delta, c_k, T0, g)
73 real(kind=rp), intent(in) :: t
74 integer, intent(in) :: tstep
75 type(coef_t), intent(in) :: coef
76 character(len=*), intent(in) :: temperature_field_name
77 character(len=*), intent(in) :: tke_field_name
78 type(field_t), intent(inout) :: nut, temperature_alphat
79 type(field_t), intent(inout) :: tke_alphat, tke_source
80 type(field_t), intent(in) :: delta
81 real(kind=rp), intent(in) :: c_k, t0, g(3)
82
83 type(field_t), pointer :: tke, temperature
84 type(field_t), pointer :: dtdx, dtdy, dtdz
85 type(field_t), pointer :: u, v, w
86 type(field_t), pointer :: a11, a12, a13, a21, a22, a23, a31, a32, a33
87 integer :: temp_indices(12)
88
89 tke => neko_registry%get_field_by_name(tke_field_name)
90 temperature => neko_registry%get_field_by_name(temperature_field_name)
91
92 u => neko_registry%get_field_by_name("u")
93 v => neko_registry%get_field_by_name("v")
94 w => neko_registry%get_field_by_name("w")
95
96 call neko_scratch_registry%request_field(dtdx, temp_indices(1), .false.)
97 call neko_scratch_registry%request_field(dtdy, temp_indices(2), .false.)
98 call neko_scratch_registry%request_field(dtdz, temp_indices(3), .false.)
99
100 ! Calculate vertical temperature gradients
101 call grad(dtdx%x, dtdy%x, dtdz%x, temperature%x, coef)
102
103 call coef%gs_h%op(dtdx%x, dtdy%x, dtdz%x, dtdx%dof%size(), gs_op_add, &
105 call device_col2(dtdx%x_d, coef%mult_d, nut%dof%size())
106 call device_col2(dtdy%x_d, coef%mult_d, nut%dof%size())
107 call device_col2(dtdz%x_d, coef%mult_d, nut%dof%size())
108
109 ! Compute velocity gradients
110 call neko_scratch_registry%request_field(a11, temp_indices(4), .false.)
111 call neko_scratch_registry%request_field(a12, temp_indices(5), .false.)
112 call neko_scratch_registry%request_field(a13, temp_indices(6), .false.)
113 call neko_scratch_registry%request_field(a21, temp_indices(7), .false.)
114 call neko_scratch_registry%request_field(a22, temp_indices(8), .false.)
115 call neko_scratch_registry%request_field(a23, temp_indices(9), .false.)
116 call neko_scratch_registry%request_field(a31, temp_indices(10), .false.)
117 call neko_scratch_registry%request_field(a32, temp_indices(11), .false.)
118 call neko_scratch_registry%request_field(a33, temp_indices(12), .false.)
119
120 call grad(a11%x, a12%x, a13%x, u%x, coef)
121 call grad(a21%x, a22%x, a23%x, v%x, coef)
122 call grad(a31%x, a32%x, a33%x, w%x, coef)
123
124 call coef%gs_h%op(a11%x, a12%x, a13%x, a11%dof%size(), gs_op_add, &
126 call coef%gs_h%op(a21%x, a22%x, a23%x, a21%dof%size(), gs_op_add, &
128 call coef%gs_h%op(a31%x, a32%x, a33%x, a31%dof%size(), gs_op_add, &
130
131 call device_col2(a11%x_d, coef%mult_d, nut%dof%size())
132 call device_col2(a12%x_d, coef%mult_d, nut%dof%size())
133 call device_col2(a13%x_d, coef%mult_d, nut%dof%size())
134 call device_col2(a21%x_d, coef%mult_d, nut%dof%size())
135 call device_col2(a22%x_d, coef%mult_d, nut%dof%size())
136 call device_col2(a23%x_d, coef%mult_d, nut%dof%size())
137 call device_col2(a31%x_d, coef%mult_d, nut%dof%size())
138 call device_col2(a32%x_d, coef%mult_d, nut%dof%size())
139 call device_col2(a33%x_d, coef%mult_d, nut%dof%size())
140
141 call device_deardorff_nut_compute(tke%x_d, &
142 dtdx%x_d, dtdy%x_d, dtdz%x_d, &
143 a11%x_d, a12%x_d, a13%x_d, &
144 a21%x_d, a22%x_d, a23%x_d, &
145 a31%x_d, a32%x_d, a33%x_d, &
146 delta%x_d, nut%x_d, temperature_alphat%x_d, &
147 tke_alphat%x_d, tke_source%x_d, &
148 c_k, t0, g, neko_eps, a11%dof%size())
149
150 call neko_scratch_registry%relinquish_field(temp_indices)
151 end subroutine deardorff_compute_device
152
153end module deardorff_device
154
Compute the gradient of a scalar field, multiplied by the mass matrix.
Definition operators.f90:92
Coefficients.
Definition coef.f90:34
Implements the device kernel for the deardorff_t type.
subroutine, public deardorff_compute_device(t, tstep, coef, temperature_field_name, tke_field_name, nut, temperature_alphat, tke_alphat, tke_source, delta, c_k, t0, g)
Compute eddy viscosity on the device.
Device kernel wrapper for computing Deardorff SGS quantities.
subroutine, public device_deardorff_nut_compute(tke_d, dtdx_d, dtdy_d, dtdz_d, a11_d, a12_d, a13_d, a21_d, a22_d, a23_d, a31_d, a32_d, a33_d, delta_d, nut_d, temperature_alphat, tke_alphat, tke_source, c_k, t0, g, eps, n)
Compute Deardorff SGS quantities on the device backend.
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
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.
Utilities.
Definition utils.f90:35
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136