Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
shear_stress.f90
Go to the documentation of this file.
1! Copyright (c) 2024-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!
36 use num_types, only : rp
38 use mixed_bc, only : mixed_bc_t
40 use, intrinsic :: iso_c_binding, only : c_ptr
42 use coefs, only : coef_t
43 use neumann, only : neumann_t
44 use json_module, only : json_file
46 use vector, only : vector_t
47 use time_state, only : time_state_t
48 implicit none
49 private
50
52 type, public, extends(mixed_bc_t) :: shear_stress_t
54 type(neumann_t) :: neumann_x
56 type(neumann_t) :: neumann_y
58 type(neumann_t) :: neumann_z
59 contains
60 procedure, pass(this) :: apply_scalar => shear_stress_apply_scalar
61 procedure, pass(this) :: apply_vector => shear_stress_apply_vector
62 procedure, pass(this) :: apply_scalar_dev => shear_stress_apply_scalar_dev
63 procedure, pass(this) :: apply_vector_dev => shear_stress_apply_vector_dev
65 procedure, pass(this) :: init => shear_stress_init
67 procedure, pass(this) :: init_from_components => &
69 procedure, pass(this) :: set_stress_scalar => &
71 procedure, pass(this) :: set_stress_array => &
74 generic :: set_stress => set_stress_scalar, set_stress_array
76 procedure, pass(this) :: free => shear_stress_free
78 procedure, pass(this) :: finalize => shear_stress_finalize
79 end type shear_stress_t
80
81contains
82
84 subroutine shear_stress_apply_scalar(this, x, n, time, strong)
85 class(shear_stress_t), intent(inout) :: this
86 integer, intent(in) :: n
87 real(kind=rp), intent(inout), dimension(n) :: x
88 type(time_state_t), intent(in), optional :: time
89 logical, intent(in), optional :: strong
90 integer :: i, m, k, facet
91 ! Store non-linear index
92 integer :: idx(4)
93
94 call neko_error("The shear stress bc is not applicable to scalar fields.")
95
96 end subroutine shear_stress_apply_scalar
97
100 subroutine shear_stress_apply_vector(this, x, y, z, n, time, strong)
101 class(shear_stress_t), intent(inout) :: this
102 integer, intent(in) :: n
103 real(kind=rp), intent(inout), dimension(n) :: x
104 real(kind=rp), intent(inout), dimension(n) :: y
105 real(kind=rp), intent(inout), dimension(n) :: z
106 type(time_state_t), intent(in), optional :: time
107 logical, intent(in), optional :: strong
108 logical :: strong_
109 integer :: i, m, k
110 real(kind=rp) :: normal(3), u_n
111
112 if (present(strong)) then
113 strong_ = strong
114 else
115 strong_ = .true.
116 end if
117
118 if (strong_) then
119 m = this%resolved_msk%size()
120
121 do i = 1, m
122 k = this%resolved_msk%get(i)
123 normal = this%n%x(:,i)
124 u_n = x(k) * normal(1) + y(k) * normal(2) + z(k) * normal(3)
125
126 x(k) = x(k) - u_n * normal(1)
127 y(k) = y(k) - u_n * normal(2)
128 z(k) = z(k) - u_n * normal(3)
129 end do
130 else
131 call this%neumann_x%apply_scalar(x, n, strong = .false.)
132 call this%neumann_y%apply_scalar(y, n, strong = .false.)
133 call this%neumann_z%apply_scalar(z, n, strong = .false.)
134 end if
135
136 end subroutine shear_stress_apply_vector
137
140 subroutine shear_stress_apply_scalar_dev(this, x_d, time, strong, strm)
141 class(shear_stress_t), intent(inout), target :: this
142 type(c_ptr), intent(inout) :: x_d
143 type(time_state_t), intent(in), optional :: time
144 logical, intent(in), optional :: strong
145 type(c_ptr), intent(inout) :: strm
146
147 call neko_error("The shear stress bc is not applicable to scalar fields.")
148
149 end subroutine shear_stress_apply_scalar_dev
150
153 subroutine shear_stress_apply_vector_dev(this, x_d, y_d, z_d, time, &
154 strong, strm)
155 class(shear_stress_t), intent(inout), target :: this
156 type(c_ptr), intent(inout) :: x_d
157 type(c_ptr), intent(inout) :: y_d
158 type(c_ptr), intent(inout) :: z_d
159 type(time_state_t), intent(in), optional :: time
160 logical, intent(in), optional :: strong
161 type(c_ptr), intent(inout) :: strm
162 logical :: strong_
163 integer :: m
164
165 if (present(strong)) then
166 strong_ = strong
167 else
168 strong_ = .true.
169 end if
170
171 if (strong_) then
172 m = this%resolved_msk%size()
173 if (m .gt. 0) then
174 call device_constrain_mixed_bc_zero(this%resolved_msk%get_d(), &
175 x_d, y_d, z_d, 1, 0, 0, this%n%x_d, this%t1%x_d, &
176 this%t2%x_d, m, strm)
177 end if
178 else
179 call this%neumann_x%apply_scalar_dev(x_d, strong = .false., strm = strm)
180 call this%neumann_y%apply_scalar_dev(y_d, strong = .false., strm = strm)
181 call this%neumann_z%apply_scalar_dev(z_d, strong = .false., strm = strm)
182 end if
183
184 end subroutine shear_stress_apply_vector_dev
185
189 subroutine shear_stress_init(this, coef, json)
190 class(shear_stress_t), target, intent(inout) :: this
191 type(coef_t), target, intent(in) :: coef
192 type(json_file), intent(inout) ::json
193 real(kind=rp), allocatable :: value(:)
194
195 call json_get_or_lookup(json, 'value', value)
196
197 if (size(value) .ne. 3) then
198 call neko_error ("The shear stress vector provided for the shear stress &
199 & boundary condition should have 3 components.")
200 end if
201
202 call this%init_from_components(coef, value)
203 end subroutine shear_stress_init
204
208 subroutine shear_stress_init_from_components(this, coef, value)
209 class(shear_stress_t), target, intent(inout) :: this
210 type(coef_t), intent(in) :: coef
211 real(kind=rp), intent(in) :: value(3)
212
213 call this%init_base(coef)
214 this%bc_type = bc_mixed_constrains_normal
215
216 call this%neumann_x%free()
217 call this%neumann_y%free()
218 call this%neumann_z%free()
219
220 call this%neumann_x%init_from_components(this%coef, value(1))
221 call this%neumann_y%init_from_components(this%coef, value(2))
222 call this%neumann_z%init_from_components(this%coef, value(3))
223
225
226 subroutine shear_stress_finalize(this)
227 class(shear_stress_t), target, intent(inout) :: this
228 call this%finalize_base()
229
230 call this%neumann_x%mark_facets(this%marked_facet)
231 call this%neumann_y%mark_facets(this%marked_facet)
232 call this%neumann_z%mark_facets(this%marked_facet)
233
234 call this%neumann_x%finalize()
235 call this%neumann_y%finalize()
236 call this%neumann_z%finalize()
237
238 end subroutine shear_stress_finalize
239
241 subroutine shear_stress_set_stress_scalar(this, tau_x, tau_y, tau_z)
242 class(shear_stress_t), intent(inout) :: this
243 real(kind=rp), intent(in) :: tau_x
244 real(kind=rp), intent(in) :: tau_y
245 real(kind=rp), intent(in) :: tau_z
246
247 ! Calls finalize and allocates the flux arrays
248 call this%neumann_x%set_flux(tau_x, 1)
249 call this%neumann_y%set_flux(tau_y, 1)
250 call this%neumann_z%set_flux(tau_z, 1)
251 end subroutine shear_stress_set_stress_scalar
252
257 subroutine shear_stress_set_stress_array(this, tau_x, tau_y, tau_z)
258 class(shear_stress_t), intent(inout) :: this
259 type(vector_t), intent(in) :: tau_x
260 type(vector_t), intent(in) :: tau_y
261 type(vector_t), intent(in) :: tau_z
262
263 call this%neumann_x%set_flux(tau_x, 1)
264 call this%neumann_y%set_flux(tau_y, 1)
265 call this%neumann_z%set_flux(tau_z, 1)
266
267 end subroutine shear_stress_set_stress_array
268
270 subroutine shear_stress_free(this)
271 class(shear_stress_t), target, intent(inout) :: this
272 call this%free_mixed()
273
274 call this%neumann_x%free
275 call this%neumann_y%free
276 call this%neumann_z%free
277
278 end subroutine shear_stress_free
279end module shear_stress
__inline__ __device__ void nonlinear_index(const int idx, const int lx, int *index)
Definition bc_utils.h:44
Defines a boundary condition.
Definition bc.f90:34
integer, parameter, public bc_mixed_constrains_normal
Definition bc.f90:67
Coefficients.
Definition coef.f90:34
Device wrappers for basis-aware mixed boundary-condition constraint kernels. These routines operate o...
subroutine, public device_constrain_mixed_bc_zero(mixed_msk, x, y, z, constraint_n, constraint_t1, constraint_t2, n, t1, t2, m, strm)
Constrain mixed-boundary projections by zeroing the selected local components on the device.
Utilities for retrieving parameters from the case files.
Implements mixed_bc_t.
Definition mixed_bc.f90:31
Defines a Neumann boundary condition.
Definition neumann.f90:34
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Defines a shear stress boundary condition for a vector field. Maintainer: Timofey Mukha.
subroutine shear_stress_init_from_components(this, coef, value)
Constructor from components.
subroutine shear_stress_free(this)
Destructor.
subroutine shear_stress_finalize(this)
subroutine shear_stress_apply_scalar(this, x, n, time, strong)
Apply shear stress for a scalar field x.
subroutine shear_stress_set_stress_array(this, tau_x, tau_y, tau_z)
Set the shear stress components.
subroutine shear_stress_apply_scalar_dev(this, x_d, time, strong, strm)
Boundary condition apply for a generic shear_stress condition to a vector x (device version)
subroutine shear_stress_set_stress_scalar(this, tau_x, tau_y, tau_z)
Set the value of the shear stress vector using 3 scalars.
subroutine shear_stress_init(this, coef, json)
Constructor.
subroutine shear_stress_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
Boundary condition apply for a generic shear_stress condition to vectors x, y and z (device version)
subroutine shear_stress_apply_vector(this, x, y, z, n, time, strong)
Boundary condition apply for a generic shear_stress condition to vectors x, y and z.
Module with things related to the simulation time.
Utilities.
Definition utils.f90:35
Defines a vector.
Definition vector.f90:34
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
Base type for mixed boundary conditions that need projector-provided local-basis data on the physical...
Definition mixed_bc.f90:50
A Neumann boundary condition. Sets the flux of the field to the chosen values.
Definition neumann.f90:60
A shear stress boundary condition.
A struct that contains all info about the time, expand as needed.