Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_sgs_stats.f90
Go to the documentation of this file.
1! Copyright (c) 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!
36 use mean_field, only : mean_field_t
37 use num_types, only : rp
39 use operators, only : grad
40 use coefs, only : coef_t
41 use field, only : field_t
42 use field_list, only : field_list_t
43 use stats_quant, only : stats_quant_t
44 use registry, only : neko_registry
46 implicit none
47 private
48
49 type, public, extends(stats_quant_t) :: scalar_sgs_stats_t
51 type(field_t), pointer :: alphat => null()
52 type(field_t), pointer :: nut => null()
53 logical :: nut_dependency = .false.
54 real(kind=rp) :: pr_turb
55 type(field_t), pointer :: s => null()
56
57 type(mean_field_t) :: alphat_mean
58
59 type(mean_field_t) :: alphatdsdx
60 type(mean_field_t) :: alphatdsdy
61 type(mean_field_t) :: alphatdsdz
62
64 type(field_t), pointer :: dsdx_work
65 type(field_t), pointer :: dsdy_work
66 type(field_t), pointer :: dsdz_work
67
69 type(coef_t), pointer :: coef => null()
71 integer :: n_stats = 4
74 type(field_list_t) :: stat_fields
75 contains
76 generic :: init => init_alphat, init_nut
78 procedure, pass(this) :: init_alphat => scalar_sgs_stats_init_alphat
79 procedure, pass(this) :: init_nut => scalar_sgs_stats_init_nut
81 procedure, pass(this) :: free => scalar_sgs_stats_free
83 procedure, pass(this) :: update => scalar_sgs_stats_update
85 procedure, pass(this) :: reset => scalar_sgs_stats_reset
86 end type scalar_sgs_stats_t
87
88contains
89
95 subroutine scalar_sgs_stats_init_alphat(this, coef, s_name, alphat_field)
96 class(scalar_sgs_stats_t), intent(inout), target:: this
97 type(coef_t), target, optional :: coef
98 character(len=*), intent(in) :: s_name
99 character(len=*), intent(in) :: alphat_field
100
101 call this%free()
102 this%coef => coef
103
104 this%s => neko_registry%get_field(s_name)
105 this%alphat => neko_registry%get_field(alphat_field)
106 this%nut_dependency = .false.
107
108 ! Initialize mean fields. The fluxes are means of products, updated with
109 ! update_col3, so the field passed to init only provides the dofmap.
110 call this%alphat_mean%init(this%alphat)
111
112 call this%alphatdsdx%init(this%s, trim(s_name) // 'alphatdsdx')
113 call this%alphatdsdy%init(this%s, trim(s_name) // 'alphatdsdy')
114 call this%alphatdsdz%init(this%s, trim(s_name) // 'alphatdsdz')
115
116 allocate(this%stat_fields%items(this%n_stats))
117
118 call this%stat_fields%assign_to_field(1, this%alphat_mean%mf)
119 call this%stat_fields%assign_to_field(2, this%alphatdsdx%mf)
120 call this%stat_fields%assign_to_field(3, this%alphatdsdy%mf)
121 call this%stat_fields%assign_to_field(4, this%alphatdsdz%mf)
122
123 end subroutine scalar_sgs_stats_init_alphat
124
131 subroutine scalar_sgs_stats_init_nut(this, coef, s_name, nut_field, pr_turb)
132 class(scalar_sgs_stats_t), intent(inout), target:: this
133 type(coef_t), target, optional :: coef
134 character(len=*), intent(in) :: s_name
135 character(len=*), intent(in) :: nut_field
136 real(kind=rp), intent(in) :: pr_turb
137
138 call this%free()
139 this%coef => coef
140
141 this%s => neko_registry%get_field(s_name)
142 this%nut => neko_registry%get_field(nut_field)
143 this%pr_turb = pr_turb
144 this%nut_dependency = .true.
145
146 allocate(this%alphat)
147 call this%alphat%init(this%nut%dof, trim(s_name) // 'alphat_temp')
148
149 ! Initialize mean fields. The fluxes are means of products, updated with
150 ! update_col3, so the field passed to init only provides the dofmap.
151 call this%alphat_mean%init(this%alphat)
152
153 call this%alphatdsdx%init(this%s, trim(s_name) // 'alphatdsdx')
154 call this%alphatdsdy%init(this%s, trim(s_name) // 'alphatdsdy')
155 call this%alphatdsdz%init(this%s, trim(s_name) // 'alphatdsdz')
156
157 allocate(this%stat_fields%items(this%n_stats))
158
159 call this%stat_fields%assign_to_field(1, this%alphat_mean%mf)
160 call this%stat_fields%assign_to_field(2, this%alphatdsdx%mf)
161 call this%stat_fields%assign_to_field(3, this%alphatdsdy%mf)
162 call this%stat_fields%assign_to_field(4, this%alphatdsdz%mf)
163
164 end subroutine scalar_sgs_stats_init_nut
165
168 subroutine scalar_sgs_stats_update(this, k)
169 class(scalar_sgs_stats_t), intent(inout) :: this
170 real(kind=rp), intent(in) :: k
171 integer :: temp_indices(3)
172
173 call neko_scratch_registry%request_field(this%dsdx_work, &
174 temp_indices(1), .false.)
175 call neko_scratch_registry%request_field(this%dsdy_work, &
176 temp_indices(2), .false.)
177 call neko_scratch_registry%request_field(this%dsdz_work, &
178 temp_indices(3), .false.)
179
180 if (this%nut_dependency) then
181 call field_cmult2(this%alphat, this%nut, 1.0_rp / this%pr_turb)
182 end if
183 call this%alphat_mean%update(k)
184
185 call grad(this%dsdx_work%x, &
186 this%dsdy_work%x, &
187 this%dsdz_work%x, &
188 this%s%x, this%coef)
189
190 call this%alphatdsdx%update_col3(k, this%alphat, this%dsdx_work)
191 call this%alphatdsdy%update_col3(k, this%alphat, this%dsdy_work)
192 call this%alphatdsdz%update_col3(k, this%alphat, this%dsdz_work)
193
194 call neko_scratch_registry%relinquish_field(temp_indices)
195 end subroutine scalar_sgs_stats_update
196
197
199 subroutine scalar_sgs_stats_free(this)
200 class(scalar_sgs_stats_t), intent(inout) :: this
201
202 call this%alphat_mean%free()
203
204 call this%alphatdsdx%free()
205 call this%alphatdsdy%free()
206 call this%alphatdsdz%free()
207
208 if (this%nut_dependency .and. associated(this%alphat)) then
209 call this%alphat%free()
210 deallocate(this%alphat)
211 end if
212
213 nullify(this%coef)
214 nullify(this%s)
215 nullify(this%alphat)
216
217 call this%stat_fields%free()
218
219 end subroutine scalar_sgs_stats_free
220
222 subroutine scalar_sgs_stats_reset(this)
223 class(scalar_sgs_stats_t), intent(inout), target:: this
224
225 call this%alphat_mean%reset()
226
227 call this%alphatdsdx%reset()
228 call this%alphatdsdy%reset()
229 call this%alphatdsdz%reset()
230
231 end subroutine scalar_sgs_stats_reset
232
233end module scalar_sgs_stats
Compute the gradient of a scalar field, multiplied by the mass matrix.
Definition operators.f90:92
Coefficients.
Definition coef.f90:34
subroutine, public field_cmult2(a, b, c, n)
Multiplication by constant c .
subroutine, public field_cmult(a, c, n)
Multiplication by constant c .
Defines a field.
Definition field.f90:34
Implements mean_field_t.
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
Computes the subgrid-scale contributions for the scalar fluxes. We use the Reynolds decomposition for...
subroutine scalar_sgs_stats_free(this)
Destructor.
subroutine scalar_sgs_stats_init_nut(this, coef, s_name, nut_field, pr_turb)
Constructor. Initialize the fields associated with scalar_sgs_stats. This version uses nut field and ...
subroutine scalar_sgs_stats_reset(this)
Resets all the computed means values and sampling times to zero.
subroutine scalar_sgs_stats_init_alphat(this, coef, s_name, alphat_field)
Constructor. Initialize the fields associated with scalar_sgs_stats. This version uses alphat directl...
subroutine scalar_sgs_stats_update(this, k)
Updates all fields with a new sample.
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 statistical quantity.
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
Computes the temporal mean of a field.
Abstract type defining a statistical quantity.