Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
wall_sampler.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!
35 use num_types, only : rp, dp
36 use field, only : field_t
37 use coefs, only : coef_t
38 use vector, only : vector_t
39 use json_module, only : json_file
40 use user_intf, only : user_t
45 use device, only : host_to_device
46 use utils, only : neko_error
47 implicit none
48 private
49
53 type, abstract, public :: wall_sampler_t
55 integer :: n_nodes = 0
57 integer :: n_samples = 0
59 logical :: user_values = .false.
61 logical :: output_h_enabled = .true.
64 type(vector_t) :: h
65 contains
67 procedure, pass(this) :: init_base => wall_sampler_init_base
69 procedure, pass(this) :: output_h => wall_sampler_output_h
71 procedure(wall_sampler_init), pass(this), deferred :: init
73 procedure(wall_sampler_finalize), pass(this), deferred :: finalize
75 procedure(wall_sampler_sample), pass(this), deferred :: sample
77 procedure(wall_sampler_free), pass(this), deferred :: free
78 end type wall_sampler_t
79
80 abstract interface
81
83 subroutine wall_sampler_init(this, json)
84 import wall_sampler_t, json_file
85 class(wall_sampler_t), intent(inout) :: this
86 type(json_file), intent(inout) :: json
87 end subroutine wall_sampler_init
88
100 subroutine wall_sampler_finalize(this, coef, msk, facet, n_x, n_y, n_z, &
101 bc_name, user)
103 class(wall_sampler_t), intent(inout) :: this
104 type(coef_t), intent(in) :: coef
105 integer, intent(in) :: msk(0:)
106 integer, intent(in) :: facet(0:)
107 type(vector_t), intent(in) :: n_x, n_y, n_z
108 character(len=*), optional, intent(in) :: bc_name
109 type(user_t), target, optional, intent(in) :: user
110 end subroutine wall_sampler_finalize
111
115 subroutine wall_sampler_sample(this, field, values)
117 class(wall_sampler_t), intent(inout) :: this
118 type(field_t), intent(inout) :: field
119 type(vector_t), intent(inout) :: values
120 end subroutine wall_sampler_sample
121
123 subroutine wall_sampler_free(this)
124 import wall_sampler_t
125 class(wall_sampler_t), intent(inout) :: this
126 end subroutine wall_sampler_free
127 end interface
128
129contains
130
136 subroutine wall_sampler_init_base(this, n_nodes, n_samples, h, output_h)
137 class(wall_sampler_t), intent(inout) :: this
138 integer, intent(in) :: n_nodes
139 integer, intent(in) :: n_samples
140 type(vector_t), intent(in) :: h
141 logical, intent(in) :: output_h
142
143 if (n_nodes < 1 .or. n_samples < 1) then
144 call neko_error('Wall sampler dimensions must be positive')
145 end if
146 if (h%size() /= n_nodes * n_samples) then
147 call neko_error('Wall sampler distances have an invalid size')
148 end if
149
150 call this%h%free()
151 this%n_nodes = n_nodes
152 this%n_samples = n_samples
153 this%user_values = .false.
154 this%output_h_enabled = output_h
155 this%h = h
156 end subroutine wall_sampler_init_base
157
164 subroutine wall_sampler_output_h(this, coef, msk, bc_name)
165 class(wall_sampler_t), intent(inout) :: this
166 type(coef_t), intent(in) :: coef
167 integer, intent(in) :: msk(0:)
168 character(len=*), intent(in) :: bc_name
169 type(field_t), pointer :: h_field
170 type(vector_t) :: h_at_wall
171 type(fld_file_output_t) :: output
172 integer :: i, scratch_index
173
174 if (msk(0) /= this%n_nodes) then
175 call neko_error('Wall sampler mask has an invalid size')
176 end if
177
178 ! Extract the first sample associated with every wall node. Current wall
179 ! models use one sample, while this also keeps the diagnostic valid for
180 ! future multi-sample models.
181 call h_at_wall%init(this%n_nodes)
182 do i = 1, this%n_nodes
183 h_at_wall%x(i) = this%h%x((i - 1) * this%n_samples + 1)
184 end do
185 if (neko_bcknd_device .eq. 1) then
186 call h_at_wall%copy_from(host_to_device, sync = .true.)
187 end if
188
189 call neko_scratch_registry%set_dofmap(coef%dof)
190 call neko_scratch_registry%request_field(h_field, scratch_index, .true.)
191 call vector_masked_scatter_copy_0(h_field%x(:,1,1,1), h_at_wall, msk, &
192 h_field%size(), this%n_nodes)
193
194 call output%init(rp, 'wall_model_h_' // trim(bc_name), 1)
195 call output%fields%assign_to_ptr(1, h_field)
196 call output%sample(0.0_dp)
197 call output%free()
198
199 call neko_scratch_registry%relinquish_field(scratch_index)
200 call h_at_wall%free()
201 end subroutine wall_sampler_output_h
202
203end module wall_sampler
Complete sampler setup after geometric and wall-node data are known.
Release sampler resources.
Parse sampler-specific configuration from JSON.
Evaluate and store sampled field values at all sampling points.
Coefficients.
Definition coef.f90:34
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
Defines a field.
Definition field.f90:34
Implements fld_file_output_t.
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines an output.
Definition output.f90:34
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.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Utilities.
Definition utils.f90:35
subroutine, public vector_masked_scatter_copy_0(a, b, mask, n, n_mask)
Scatter a contiguous vector into an array .
Defines a vector.
Definition vector.f90:34
Defines the abstract interface for wall-model field samplers.
subroutine wall_sampler_output_h(this, coef, msk, bc_name)
Write the first sampling distance at every wall node to a field file.
subroutine wall_sampler_init_base(this, n_nodes, n_samples, h, output_h)
Initialise state common to all fully constructed wall samplers.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
A simple output saving a list of fields to a .fld file.
A type collecting all the overridable user routines and flag to suppress type injection from custom m...
Base type for sampling solution fields at points associated with wall nodes. Samples belonging to one...