Neko 1.99.10
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
symmetry.f90
Go to the documentation of this file.
1! Copyright (c) 2020-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!
33!> Implements `symmetry_t`.
35 use num_types, only : rp
37 use mixed_bc, only : mixed_bc_t
39 use coefs, only : coef_t
40 use json_module, only : json_file
41 use, intrinsic :: iso_c_binding, only : c_ptr
42 use time_state, only : time_state_t
43 implicit none
44 private
45
46 !> Symmetry boundary condition constraining the normal vector component.
47 !! @details This variant uses projector-provided local basis vectors on the
48 !! resolved mixed support stored in `mixed_bc_t`. The normal component is
49 !! removed while the tangential components are preserved.
50 type, public, extends(mixed_bc_t) :: symmetry_t
51 contains
52 !> No-op scalar application.
53 procedure, pass(this) :: apply_scalar => symmetry_apply_scalar
54 !> Remove the normal component on the CPU.
55 procedure, pass(this) :: apply_vector => symmetry_apply_vector
56 !> No-op scalar application on the device.
57 procedure, pass(this) :: apply_scalar_dev => symmetry_apply_scalar_dev
58 !> Remove the normal component on the device.
59 procedure, pass(this) :: apply_vector_dev => symmetry_apply_vector_dev
60 !> Construct the boundary condition from JSON.
61 procedure, pass(this) :: init => symmetry_init
62 !> Construct the boundary condition from its components.
63 procedure, pass(this) :: init_from_components => &
65 !> Free the boundary condition and its mixed-bc storage.
66 procedure, pass(this) :: free => symmetry_free
67 !> Finalize the boundary condition.
68 procedure, pass(this) :: finalize => symmetry_finalize
69 end type symmetry_t
70
71contains
72
73 !> Construct the boundary condition from JSON.
74 !! @param[in] coef The SEM coefficients.
75 !! @param[inout] json The JSON object configuring the boundary condition.
76 subroutine symmetry_init(this, coef, json)
77 class(symmetry_t), intent(inout), target :: this
78 type(coef_t), target, intent(in) :: coef
79 type(json_file), intent(inout) :: json
80
81 call this%init_from_components(coef)
82 end subroutine symmetry_init
83
84 !> Construct the boundary condition from its components.
85 !! @param[in] coef The SEM coefficients.
86 subroutine symmetry_init_from_components(this, coef)
87 class(symmetry_t), intent(inout), target :: this
88 type(coef_t), target, intent(in) :: coef
89
90 call this%free()
91
92 call this%init_base(coef)
93 this%bc_type = bc_mixed_constrains_normal
95
96 !> Finalize the boundary condition.
97 subroutine symmetry_finalize(this)
98 class(symmetry_t), target, intent(inout) :: this
99
100 ! Reads coef%nx, ny and nz directly, never through get_normal()
101 call this%coef%require_facets('symmetry')
102
103 call this%finalize_base()
104 end subroutine symmetry_finalize
105
106 !> No-op scalar application.
107 !! @param x Scalar field values.
108 !! @param n Number of entries in `x`.
109 !! @param time Current time state.
110 !! @param strong Whether to apply the strong form.
111 subroutine symmetry_apply_scalar(this, x, n, time, strong)
112 class(symmetry_t), intent(inout) :: this
113 integer, intent(in) :: n
114 real(kind=rp), intent(inout), dimension(n) :: x
115 type(time_state_t), intent(in), optional :: time
116 logical, intent(in), optional :: strong
117 end subroutine symmetry_apply_scalar
118
119 !> Remove the normal component on the CPU.
120 !! @details Uses the resolved mixed-node mask together with the local normal
121 !! vector provided by the coupled vector BC projector.
122 !! @param x x-component of the field.
123 !! @param y y-component of the field.
124 !! @param z z-component of the field.
125 !! @param n Number of entries in each component array.
126 !! @param time Current time state.
127 !! @param strong Whether to apply the strong form.
128 subroutine symmetry_apply_vector(this, x, y, z, n, time, strong)
129 class(symmetry_t), intent(inout) :: this
130 integer, intent(in) :: n
131 real(kind=rp), intent(inout), dimension(n) :: x
132 real(kind=rp), intent(inout), dimension(n) :: y
133 real(kind=rp), intent(inout), dimension(n) :: z
134 type(time_state_t), intent(in), optional :: time
135 logical, intent(in), optional :: strong
136 logical :: strong_
137 integer :: i, m, k
138 real(kind=rp) :: normal(3), u_n
139
140 if (present(strong)) then
141 strong_ = strong
142 else
143 strong_ = .true.
144 end if
145
146 if (strong_) then
147 m = this%resolved_msk%size()
148
149 !$omp do
150 do i = 1, m
151 k = this%resolved_msk%get(i)
152 normal = this%n%x(:,i)
153 u_n = x(k) * normal(1) + y(k) * normal(2) + z(k) * normal(3)
154
155 x(k) = x(k) - u_n * normal(1)
156 y(k) = y(k) - u_n * normal(2)
157 z(k) = z(k) - u_n * normal(3)
158 end do
159 !$omp end do
160 end if
161 end subroutine symmetry_apply_vector
162
163 !> No-op scalar application on the device.
164 !! @param x_d Device pointer to the scalar field.
165 !! @param time Current time state.
166 !! @param strong Whether to apply the strong form.
167 !! @param strm Device stream.
168 subroutine symmetry_apply_scalar_dev(this, x_d, time, strong, strm)
169 class(symmetry_t), intent(inout), target :: this
170 type(c_ptr), intent(inout) :: x_d
171 type(time_state_t), intent(in), optional :: time
172 logical, intent(in), optional :: strong
173 type(c_ptr), intent(inout) :: strm
174 end subroutine symmetry_apply_scalar_dev
175
176 !> Remove the normal component on the device.
177 !! @details Uses the resolved mixed-node mask together with the local basis
178 !! vectors provided by the coupled vector BC projector.
179 !! @param x_d Device pointer to the x-component.
180 !! @param y_d Device pointer to the y-component.
181 !! @param z_d Device pointer to the z-component.
182 !! @param time Current time state.
183 !! @param strong Whether to apply the strong form.
184 !! @param strm Device stream.
185 subroutine symmetry_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
186 class(symmetry_t), intent(inout), target :: this
187 type(c_ptr), intent(inout) :: x_d
188 type(c_ptr), intent(inout) :: y_d
189 type(c_ptr), intent(inout) :: z_d
190 type(time_state_t), intent(in), optional :: time
191 logical, intent(in), optional :: strong
192 type(c_ptr), intent(inout) :: strm
193 logical :: strong_
194 integer :: m
195
196 if (present(strong)) then
197 strong_ = strong
198 else
199 strong_ = .true.
200 end if
201
202 if (strong_) then
203 m = this%resolved_msk%size()
204 if (m .gt. 0) then
205 call device_constrain_mixed_bc_zero(this%resolved_msk%get_d(), &
206 x_d, y_d, z_d, 1, 0, 0, this%n%x_d, this%t1%x_d, &
207 this%t2%x_d, m, strm)
208 end if
209 end if
210 end subroutine symmetry_apply_vector_dev
211
212 !> Free the boundary condition and its mixed-bc storage.
213 subroutine symmetry_free(this)
214 class(symmetry_t), target, intent(inout) :: this
215
216 call this%free_mixed()
217 call this%free_base()
218 end subroutine symmetry_free
219
220end module symmetry
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.
Implements mixed_bc_t.
Definition mixed_bc.f90:31
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Implements symmetry_t.
Definition symmetry.f90:34
subroutine symmetry_apply_vector(this, x, y, z, n, time, strong)
Remove the normal component on the CPU.
Definition symmetry.f90:129
subroutine symmetry_apply_scalar(this, x, n, time, strong)
No-op scalar application.
Definition symmetry.f90:112
subroutine symmetry_init_from_components(this, coef)
Construct the boundary condition from its components.
Definition symmetry.f90:87
subroutine symmetry_init(this, coef, json)
Construct the boundary condition from JSON.
Definition symmetry.f90:77
subroutine symmetry_apply_scalar_dev(this, x_d, time, strong, strm)
No-op scalar application on the device.
Definition symmetry.f90:169
subroutine symmetry_finalize(this)
Finalize the boundary condition.
Definition symmetry.f90:98
subroutine symmetry_apply_vector_dev(this, x_d, y_d, z_d, time, strong, strm)
Remove the normal component on the device.
Definition symmetry.f90:186
subroutine symmetry_free(this)
Free the boundary condition and its mixed-bc storage.
Definition symmetry.f90:214
Module with things related to the simulation time.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
Base type for mixed boundary conditions that need projector-provided local-basis data on the physical...
Definition mixed_bc.f90:50
Symmetry boundary condition constraining the normal vector component.
Definition symmetry.f90:50
A struct that contains all info about the time, expand as needed.