Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
projection_vel.f90
Go to the documentation of this file.
1! Copyright (c) 2024, 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, c_rp
37 use math, only : add2, copy
38 use coefs, only : coef_t
39 use ax_product, only : ax_t
41 use gather_scatter, only : gs_t, gs_op_add
43 use device, only : device_get_ptr
46 use, intrinsic :: iso_c_binding
49
50 implicit none
51 private
52
53 type, public :: projection_vel_t
54 type(projection_t) :: proj_u, proj_v, proj_w
55 integer :: activ_step
56 integer :: l
57 contains
58 procedure, pass(this) :: init => projection_init_vel
59 procedure, pass(this) :: free => projection_free_vel
60 procedure, pass(this) :: pre_solving => projection_pre_solving_vel
61 procedure, pass(this) :: post_solving => projection_post_solving_vel
62 procedure, pass(this) :: project_back => bcknd_project_back_vel
63 end type projection_vel_t
64
65contains
66
67 subroutine projection_init_vel(this, n, L, activ_step)
68 class(projection_vel_t), target, intent(inout) :: this
69 integer, intent(in) :: n
70 integer, intent(in) :: L, activ_step
71
72 call this%free()
73
74 call this%proj_u%init(n, l, activ_step)
75 call this%proj_v%init(n, l, activ_step)
76 call this%proj_w%init(n, l, activ_step)
77
78 this%L = l
79 this%activ_step = activ_step
80
81
82 end subroutine projection_init_vel
83
84 subroutine projection_free_vel(this)
85 class(projection_vel_t), intent(inout) :: this
86 integer :: i
87
88 call this%proj_u%free()
89 call this%proj_v%free()
90 call this%proj_w%free()
91
92 end subroutine projection_free_vel
93
94 subroutine projection_pre_solving_vel(this, b_u, b_v, b_w, tstep, coef, n, &
95 dt_controller, &
96 stringx, stringy, stringz)
97 class(projection_vel_t), intent(inout) :: this
98 integer, intent(inout) :: n
99 real(kind=rp), intent(inout), dimension(n) :: b_u, b_v, b_w
100 integer, intent(in) :: tstep
101 class(coef_t), intent(inout) :: coef
102 type(time_step_controller_t), intent(in) :: dt_controller
103 character(len=*), optional :: stringx, stringy, stringz
104
105 call this%proj_u%pre_solving(b_u, tstep, coef, n, dt_controller, stringx)
106 call this%proj_v%pre_solving(b_v, tstep, coef, n, dt_controller, stringy)
107 call this%proj_w%pre_solving(b_w, tstep, coef, n, dt_controller, stringz)
108
109 end subroutine projection_pre_solving_vel
110
111 subroutine projection_post_solving_vel(this, x_u, x_v, x_w, Ax, coef, &
112 bc_projector, &
113 gs_h, n, tstep, dt_controller)
114 class(projection_vel_t), intent(inout) :: this
115 integer, intent(inout) :: n
116 class(ax_t), intent(inout) :: Ax
117 class(coef_t), intent(inout) :: coef
118 class(vector_bc_projector_t), intent(inout) :: bc_projector
119 type(gs_t), intent(inout) :: gs_h
120 real(kind=rp), intent(inout), dimension(n) :: x_u, x_v, x_w
121 integer, intent(in) :: tstep
122 type(time_step_controller_t), intent(in) :: dt_controller
123
124 ! Here we assume the projection space sizes and activate steps
125 ! for all three velocity equations are the same
126 if (tstep .gt. this%activ_step .and. this%L .gt. 0) then
127 if ((.not. dt_controller%is_variable_dt) .or. &
128 (dt_controller%dt_last_change .gt. this%activ_step - 1)) then
129 call this%project_back(x_u, x_v, x_w, ax, coef, bc_projector, gs_h, n)
130 end if
131 end if
132
133 end subroutine projection_post_solving_vel
134
135 subroutine bcknd_project_back_vel(this, x_u, x_v, x_w, &
136 Ax, coef, bc_projector, gs_h, n)
137 class(projection_vel_t) :: this
138 integer, intent(inout) :: n
139 class(ax_t), intent(inout) :: Ax
140 class(coef_t), intent(inout) :: coef
141 class(vector_bc_projector_t), intent(inout) :: bc_projector
142 type(gs_t), intent(inout) :: gs_h
143 real(kind=rp), intent(inout), dimension(n) :: x_u, x_v, x_w
144 type(c_ptr) :: x_u_d, x_v_d, x_w_d
145
146 call profiler_start_region('Project back', 17)
147
148 if (neko_bcknd_device .eq. 1) then
149 x_u_d = device_get_ptr(x_u)
150 x_v_d = device_get_ptr(x_v)
151 x_w_d = device_get_ptr(x_w)
152 if (this%proj_u%m .gt. 0) then ! Restore desired solution
153 call device_add2(x_u_d, this%proj_u%xbar_d, n)
154 end if
155 if (this%proj_v%m .gt. 0) then ! Restore desired solution
156 call device_add2(x_v_d, this%proj_v%xbar_d, n)
157 end if
158 if (this%proj_w%m .gt. 0) then ! Restore desired solution
159 call device_add2(x_w_d, this%proj_w%xbar_d, n)
160 end if
161
162 if (this%proj_u%m .eq. this%proj_u%L) then
163 this%proj_u%m = 1
164 else
165 this%proj_u%m = min(this%proj_u%m + 1, this%proj_u%L)
166 end if
167 if (this%proj_v%m .eq. this%proj_v%L) then
168 this%proj_v%m = 1
169 else
170 this%proj_v%m = min(this%proj_v%m + 1, this%proj_v%L)
171 end if
172 if (this%proj_w%m .eq. this%proj_w%L) then
173 this%proj_w%m = 1
174 else
175 this%proj_w%m = min(this%proj_w%m + 1, this%proj_w%L)
176 end if
177
178 call device_copy(this%proj_u%xx_d(this%proj_u%m), &
179 x_u_d,n) ! Update (X,B)
180 call device_copy(this%proj_v%xx_d(this%proj_v%m), &
181 x_v_d,n) ! Update (X,B)
182 call device_copy(this%proj_w%xx_d(this%proj_w%m), &
183 x_w_d,n) ! Update (X,B)
184
185 else
186 if (this%proj_u%m .gt. 0) then
187 call add2(x_u, this%proj_u%xbar, n) ! Restore desired solution
188 end if
189 if (this%proj_v%m .gt. 0) then
190 call add2(x_v, this%proj_v%xbar, n) ! Restore desired solution
191 end if
192 if (this%proj_w%m .gt. 0) then
193 call add2(x_w, this%proj_w%xbar, n) ! Restore desired solution
194 end if
195
196 if (this%proj_u%m .eq. this%proj_u%L) then
197 this%proj_u%m = 1
198 else
199 this%proj_u%m = min(this%proj_u%m + 1, this%proj_u%L)
200 end if
201 if (this%proj_v%m .eq. this%proj_v%L) then
202 this%proj_v%m = 1
203 else
204 this%proj_v%m = min(this%proj_v%m + 1, this%proj_v%L)
205 end if
206 if (this%proj_w%m .eq. this%proj_w%L) then
207 this%proj_w%m = 1
208 else
209 this%proj_w%m = min(this%proj_w%m + 1, this%proj_w%L)
210 end if
211
212 call copy(this%proj_u%xx(1, this%proj_u%m), x_u, n) ! Update (X,B)
213 call copy(this%proj_v%xx(1, this%proj_v%m), x_v, n) ! Update (X,B)
214 call copy(this%proj_w%xx(1, this%proj_w%m), x_w, n) ! Update (X,B)
215 end if
216
217 call ax%compute_vector(this%proj_u%bb(1, this%proj_u%m), &
218 this%proj_v%bb(1, this%proj_v%m), &
219 this%proj_w%bb(1, this%proj_w%m), x_u, x_v, x_w, &
220 coef, coef%msh, coef%Xh)
221
222 call gs_h%gs_op_vector(this%proj_u%bb(1, this%proj_u%m), n, gs_op_add)
223 call gs_h%gs_op_vector(this%proj_v%bb(1, this%proj_v%m), n, gs_op_add)
224 call gs_h%gs_op_vector(this%proj_w%bb(1, this%proj_w%m), n, gs_op_add)
225
226 call bc_projector%apply(this%proj_u%bb(1, this%proj_u%m), &
227 this%proj_v%bb(1, this%proj_v%m), this%proj_w%bb(1, this%proj_w%m), n)
228
229 call proj_ortho(this%proj_u, coef, n)
230 call proj_ortho(this%proj_v, coef, n)
231 call proj_ortho(this%proj_w, coef, n)
232 call profiler_end_region('Project back', 17)
233 end subroutine bcknd_project_back_vel
234end module projection_vel
Return the device pointer for an associated Fortran array.
Definition device.F90:113
Defines a Matrix-vector product.
Definition ax.f90:34
Coefficients.
Definition coef.f90:34
subroutine, public device_add2(a_d, b_d, n, strm)
Vector addition .
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
Gather-scatter.
Definition math.f90:60
subroutine, public add2(a, b, n)
Vector addition .
Definition math.f90:903
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.f90:294
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public c_rp
Definition num_types.f90:15
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Profiling interface.
Definition profiler.F90:34
subroutine, public profiler_start_region(name, region_id)
Started a named (name) profiler region.
Definition profiler.F90:79
subroutine, public profiler_end_region(name, region_id)
End the most recently started profiler region.
Definition profiler.F90:116
Project x onto X , the space of old solutions and back again Couple projections for velocity.
subroutine projection_init_vel(this, n, l, activ_step)
subroutine bcknd_project_back_vel(this, x_u, x_v, x_w, ax, coef, bc_projector, gs_h, n)
subroutine projection_post_solving_vel(this, x_u, x_v, x_w, ax, coef, bc_projector, gs_h, n, tstep, dt_controller)
subroutine projection_free_vel(this)
subroutine projection_pre_solving_vel(this, b_u, b_v, b_w, tstep, coef, n, dt_controller, stringx, stringy, stringz)
Project x onto X, the space of old solutions and back again.
subroutine, public proj_ortho(this, coef, n)
Implements type time_step_controller.
Implements boundary condition projectors for vector fields. Two types concrete types are provided: se...
Base type for a matrix-vector product providing .
Definition ax.f90:43
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:93
Gather-scatter kernel.
Abstract type for resolving vector boundary conditions.