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 !$omp do
122 do i = 1, m
123 k = this%resolved_msk%get(i)
124 normal = this%n%x(:,i)
125 u_n = x(k) * normal(1) + y(k) * normal(2) + z(k) * normal(3)
126
127 x(k) = x(k) - u_n * normal(1)
128 y(k) = y(k) - u_n * normal(2)
129 z(k) = z(k) - u_n * normal(3)
130 end do
131 !$omp end do
132 else
133 call this%neumann_x%apply_scalar(x, n, strong = .false.)
134 call this%neumann_y%apply_scalar(y, n, strong = .false.)
135 call this%neumann_z%apply_scalar(z, n, strong = .false.)
136 end if
137
138 end subroutine shear_stress_apply_vector
139
142 subroutine shear_stress_apply_scalar_dev(this, x_d, time, strong, strm)
143 class(shear_stress_t), intent(inout), target :: this
144 type(c_ptr), intent(inout) :: x_d
145 type(time_state_t), intent(in), optional :: time
146 logical, intent(in), optional :: strong
147 type(c_ptr), intent(inout) :: strm
148
149 call neko_error("The shear stress bc is not applicable to scalar fields.")
150
151 end subroutine shear_stress_apply_scalar_dev
152
155 subroutine shear_stress_apply_vector_dev(this, x_d, y_d, z_d, time, &
156 strong, strm)
157 class(shear_stress_t), intent(inout), target :: this
158 type(c_ptr), intent(inout) :: x_d
159 type(c_ptr), intent(inout) :: y_d
160 type(c_ptr), intent(inout) :: z_d
161 type(time_state_t), intent(in), optional :: time
162 logical, intent(in), optional :: strong
163 type(c_ptr), intent(inout) :: strm
164 logical :: strong_
165 integer :: m
166
167 if (present(strong)) then
168 strong_ = strong
169 else
170 strong_ = .true.
171 end if
172
173 if (strong_) then
174 m = this%resolved_msk%size()
175 if (m .gt. 0) then
176 call device_constrain_mixed_bc_zero(this%resolved_msk%get_d(), &
177 x_d, y_d, z_d, 1, 0, 0, this%n%x_d, this%t1%x_d, &
178 this%t2%x_d, m, strm)
179 end if
180 else
181 call this%neumann_x%apply_scalar_dev(x_d, strong = .false., strm = strm)
182 call this%neumann_y%apply_scalar_dev(y_d, strong = .false., strm = strm)
183 call this%neumann_z%apply_scalar_dev(z_d, strong = .false., strm = strm)
184 end if
185
186 end subroutine shear_stress_apply_vector_dev
187
191 subroutine shear_stress_init(this, coef, json)
192 class(shear_stress_t), target, intent(inout) :: this
193 type(coef_t), target, intent(in) :: coef
194 type(json_file), intent(inout) ::json
195 real(kind=rp), allocatable :: value(:)
196
197 call json_get_or_lookup(json, 'value', value)
198
199 if (size(value) .ne. 3) then
200 call neko_error ("The shear stress vector provided for the shear stress &
201 & boundary condition should have 3 components.")
202 end if
203
204 call this%init_from_components(coef, value)
205 end subroutine shear_stress_init
206
210 subroutine shear_stress_init_from_components(this, coef, value)
211 class(shear_stress_t), target, intent(inout) :: this
212 type(coef_t), intent(in) :: coef
213 real(kind=rp), intent(in) :: value(3)
214
215 call this%init_base(coef)
216 this%bc_type = bc_mixed_constrains_normal
217
218 call this%neumann_x%free()
219 call this%neumann_y%free()
220 call this%neumann_z%free()
221
222 call this%neumann_x%init_from_components(this%coef, value(1))
223 call this%neumann_y%init_from_components(this%coef, value(2))
224 call this%neumann_z%init_from_components(this%coef, value(3))
225
227
228 subroutine shear_stress_finalize(this)
229 class(shear_stress_t), target, intent(inout) :: this
230 call this%finalize_base()
231
232 call this%neumann_x%mark_facets(this%marked_facet)
233 call this%neumann_y%mark_facets(this%marked_facet)
234 call this%neumann_z%mark_facets(this%marked_facet)
235
236 call this%neumann_x%finalize()
237 call this%neumann_y%finalize()
238 call this%neumann_z%finalize()
239
240 end subroutine shear_stress_finalize
241
243 subroutine shear_stress_set_stress_scalar(this, tau_x, tau_y, tau_z)
244 class(shear_stress_t), intent(inout) :: this
245 real(kind=rp), intent(in) :: tau_x
246 real(kind=rp), intent(in) :: tau_y
247 real(kind=rp), intent(in) :: tau_z
248
249 ! Calls finalize and allocates the flux arrays
250 call this%neumann_x%set_flux(tau_x, 1)
251 call this%neumann_y%set_flux(tau_y, 1)
252 call this%neumann_z%set_flux(tau_z, 1)
253 end subroutine shear_stress_set_stress_scalar
254
259 subroutine shear_stress_set_stress_array(this, tau_x, tau_y, tau_z)
260 class(shear_stress_t), intent(inout) :: this
261 type(vector_t), intent(in) :: tau_x
262 type(vector_t), intent(in) :: tau_y
263 type(vector_t), intent(in) :: tau_z
264
265 call this%neumann_x%set_flux(tau_x, 1)
266 call this%neumann_y%set_flux(tau_y, 1)
267 call this%neumann_z%set_flux(tau_z, 1)
268
269 end subroutine shear_stress_set_stress_array
270
272 subroutine shear_stress_free(this)
273 class(shear_stress_t), target, intent(inout) :: this
274 call this%free_mixed()
275
276 call this%neumann_x%free
277 call this%neumann_y%free
278 call this%neumann_z%free
279
280 end subroutine shear_stress_free
281end 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:68
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:135
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.