Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
spalding.f90
Go to the documentation of this file.
1! Copyright (c) 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!
36 use field, only: field_t
37 use num_types, only : rp
38 use json_module, only : json_file
39 use coefs, only : coef_t
41 use wall_model, only : wall_model_t
44 use user_intf, only : user_t
45 use registry, only : neko_registry
49 use field_math, only: field_invcol3
50 use vector, only : vector_t
51 use math, only: masked_gather_copy_0
54 use logger, only : log_size, neko_log
55
56 implicit none
57 private
58
61 type, public, extends(wall_model_t) :: spalding_t
63 real(kind=rp) :: kappa = 0.41_rp
65 real(kind=rp) :: b = 5.2_rp
67 type(vector_t) :: nu
68 ! The fluid density at the boundary
69 type(vector_t) :: rho_w
71 type(vector_t) :: u_s, v_s, w_s
72 contains
74 procedure, pass(this) :: init => spalding_init
77 procedure, pass(this) :: partial_init => spalding_partial_init
79 procedure, pass(this) :: finalize => spalding_finalize
81 procedure, pass(this) :: init_from_components => &
84 procedure, pass(this) :: free => spalding_free
86 procedure, pass(this) :: compute_nu => spalding_compute_nu
88 procedure, pass(this) :: compute => spalding_compute
89 end type spalding_t
90
91contains
98 subroutine spalding_init(this, scheme_name, coef, msk, facet, json)
99 class(spalding_t), intent(inout) :: this
100 character(len=*), intent(in) :: scheme_name
101 type(coef_t), intent(in) :: coef
102 integer, intent(in) :: msk(:)
103 integer, intent(in) :: facet(:)
104 type(json_file), intent(inout) :: json
105 real(kind=rp) :: kappa, b
106 class(wall_sampler_t), allocatable :: sampler
107
108 call json_get_or_lookup(json, "kappa", kappa)
109 call json_get_or_lookup(json, "B", b)
110
111 call wall_sampler_factory(sampler, json)
112 call this%init_from_components(scheme_name, coef, msk, facet, sampler, &
113 kappa, b)
114 end subroutine spalding_init
115
119 subroutine spalding_partial_init(this, coef, scheme_name, json)
120 class(spalding_t), intent(inout) :: this
121 type(coef_t), intent(in) :: coef
122 character(len=*), intent(in) :: scheme_name
123 type(json_file), intent(inout) :: json
124 character(len=LOG_SIZE) :: log_buf
125
126 call this%partial_init_base(coef, scheme_name, json)
127 call json_get_or_lookup(json, "kappa", this%kappa)
128 call json_get_or_lookup(json, "B", this%B)
129
130 call neko_log%section('Wall model')
131 write(log_buf, '(A)') 'Model : Spalding'
132 call neko_log%message(log_buf)
133 write(log_buf, '(A, E15.7)') 'kappa : ', this%kappa
134 call neko_log%message(log_buf)
135 write(log_buf, '(A, E15.7)') 'B : ', this%B
136 call neko_log%message(log_buf)
137 call neko_log%end_section()
138
139 end subroutine spalding_partial_init
140
144 subroutine spalding_finalize(this, msk, facet, bc_name, user)
145 class(spalding_t), intent(inout) :: this
146 integer, intent(in) :: msk(:)
147 integer, intent(in) :: facet(:)
148 character(len=*), optional, intent(in) :: bc_name
149 type(user_t), target, optional, intent(in) :: user
150
151 call this%finalize_base(msk, facet, bc_name, user)
152 call this%nu%init(this%n_nodes)
153 call this%rho_w%init(this%n_nodes)
154 call this%validate_single_sample()
155 call this%u_s%init(this%n_nodes)
156 call this%v_s%init(this%n_nodes)
157 call this%w_s%init(this%n_nodes)
158 end subroutine spalding_finalize
159
168 subroutine spalding_init_from_components(this, scheme_name, coef, msk, &
169 facet, sampler, kappa, B)
170 class(spalding_t), intent(inout) :: this
171 character(len=*), intent(in) :: scheme_name
172 type(coef_t), intent(in) :: coef
173 integer, intent(in) :: msk(:)
174 integer, intent(in) :: facet(:)
175 class(wall_sampler_t), allocatable, intent(inout) :: sampler
176 real(kind=rp), intent(in) :: kappa
177 real(kind=rp), intent(in) :: b
178
179 call this%free()
180 call this%init_base(scheme_name, coef, msk, facet, sampler)
181
182 this%kappa = kappa
183 this%B = b
184
185 call this%nu%init(this%n_nodes)
186 call this%rho_w%init(this%n_nodes)
187 call this%validate_single_sample()
188 call this%u_s%init(this%n_nodes)
189 call this%v_s%init(this%n_nodes)
190 call this%w_s%init(this%n_nodes)
191 end subroutine spalding_init_from_components
192
194 subroutine spalding_compute_nu(this)
195 class(spalding_t), intent(inout) :: this
196 type(field_t), pointer :: temp
197 integer :: idx
198
199 call neko_scratch_registry%request_field(temp, idx, .false.)
200 call field_invcol3(temp, this%mu, this%rho)
201
202 if (neko_bcknd_device .eq. 1) then
203 call device_masked_gather_copy_0(this%nu%x_d, temp%x_d, this%msk_d, &
204 temp%size(), this%nu%size())
205 call device_masked_gather_copy_0(this%rho_w%x_d, this%rho%x_d, &
206 this%msk_d, &
207 this%rho%size(), this%rho_w%size())
208 else
209 call masked_gather_copy_0(this%nu%x, temp%x, this%msk, temp%size(), &
210 this%nu%size())
211 call masked_gather_copy_0(this%rho_w%x, this%rho%x, this%msk, &
212 this%rho%size(), this%rho_w%size())
213 end if
214
215 call neko_scratch_registry%relinquish_field(idx)
216 end subroutine spalding_compute_nu
217
219 subroutine spalding_free(this)
220 class(spalding_t), intent(inout) :: this
221
222 call this%nu%free()
223 call this%rho_w%free()
224 call this%u_s%free()
225 call this%v_s%free()
226 call this%w_s%free()
227 call this%free_base()
228
229 end subroutine spalding_free
230
234 subroutine spalding_compute(this, t, tstep)
235 class(spalding_t), intent(inout) :: this
236 real(kind=rp), intent(in) :: t
237 integer, intent(in) :: tstep
238 type(field_t), pointer :: u
239 type(field_t), pointer :: v
240 type(field_t), pointer :: w
241
242 call this%compute_nu()
243
244 u => neko_registry%get_field("u")
245 v => neko_registry%get_field("v")
246 w => neko_registry%get_field("w")
247
248 call this%sampler%sample(u, this%u_s)
249 call this%sampler%sample(v, this%v_s)
250 call this%sampler%sample(w, this%w_s)
251
252 if (neko_bcknd_device .eq. 1) then
253 call spalding_compute_device(this%u_s%x_d, this%v_s%x_d, &
254 this%w_s%x_d, &
255 this%n_x%x_d, this%n_y%x_d, this%n_z%x_d, &
256 this%nu%x_d, this%rho_w%x_d, this%sampler%h%x_d, &
257 this%tau_x%x_d, this%tau_y%x_d, this%tau_z%x_d, &
258 this%n_nodes, &
259 this%kappa, this%B, tstep)
260 else
261 call spalding_compute_cpu(this%u_s%x, this%v_s%x, this%w_s%x, &
262 this%n_x%x, this%n_y%x, this%n_z%x, &
263 this%nu%x, this%rho_w%x, this%sampler%h%x, &
264 this%tau_x%x, this%tau_y%x, this%tau_z%x, &
265 this%n_nodes, &
266 this%kappa, this%B, tstep)
267 end if
268
269 nullify(u, v, w)
270
271 end subroutine spalding_compute
272end module spalding
__global__ void spalding_compute(const T *__restrict__ u_d, const T *__restrict__ v_d, const T *__restrict__ w_d, const T *__restrict__ n_x_d, const T *__restrict__ n_y_d, const T *__restrict__ n_z_d, const T *__restrict__ nu_d, const T *__restrict__ rho_w_d, const T *__restrict__ h_d, T *__restrict__ tau_x_d, T *__restrict__ tau_y_d, T *__restrict__ tau_z_d, const int n_nodes, const T kappa, const T B, const int tstep)
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Coefficients.
Definition coef.f90:34
subroutine, public device_masked_gather_copy_0(a_d, b_d, mask_d, n, n_mask, strm)
Gather a masked vector .
subroutine, public field_invcol3(a, b, c, n)
Invert a vector .
Defines a field.
Definition field.f90:34
Utilities for retrieving parameters from the case files.
Logging routines.
Definition log.f90:34
type(log_t), public neko_log
Global log stream.
Definition log.f90:80
integer, parameter, public log_size
Definition log.f90:46
Definition math.f90:60
subroutine, public masked_gather_copy_0(a, b, mask, n, n_mask)
Gather a masked vector to reduced contigous vector .
Definition math.f90:363
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:144
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 CPU kernel for the spalding_t type.
subroutine, public spalding_compute_cpu(u, v, w, n_x, n_y, n_z, nu, rho_w, h, tau_x, tau_y, tau_z, n_nodes, kappa, b, tstep)
Compute the wall shear stress on cpu using Spalding's model.
Implements the device kernel for the spalding_t type.
subroutine, public spalding_compute_device(u_d, v_d, w_d, n_x_d, n_y_d, n_z_d, nu_d, rho_w_d, h_d, tau_x_d, tau_y_d, tau_z_d, n_nodes, kappa, b, tstep)
Compute the wall shear stress on device using Spalding's model.
Implements spalding_t.
Definition spalding.f90:35
subroutine spalding_init_from_components(this, scheme_name, coef, msk, facet, sampler, kappa, b)
Constructor from components.
Definition spalding.f90:170
subroutine spalding_partial_init(this, coef, scheme_name, json)
Constructor from JSON.
Definition spalding.f90:120
subroutine spalding_init(this, scheme_name, coef, msk, facet, json)
Constructor from JSON.
Definition spalding.f90:99
subroutine spalding_compute_nu(this)
Compute the kinematic viscosity vector.
Definition spalding.f90:195
subroutine spalding_finalize(this, msk, facet, bc_name, user)
Finalize the construction using the mask and facet arrays of the bc.
Definition spalding.f90:145
subroutine spalding_free(this)
Destructor for the spalding_t (base) class.
Definition spalding.f90:220
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Defines a vector.
Definition vector.f90:34
Implements wall_model_t.
Factory for wall-model samplers.
subroutine, public wall_sampler_factory(object, json)
Wall sampler factory.
Defines the abstract interface for wall-model field samplers.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
Wall model based on Spalding's law of the wall. Reference: http://dx.doi.org/10.1115/1....
Definition spalding.f90:61
A type collecting all the overridable user routines and flag to suppress type injection from custom m...
Base abstract type for wall-stress models for wall-modelled LES.
Base type for sampling solution fields at points associated with wall nodes. Samples belonging to one...