Neko 1.99.10
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
adv_oifs.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!
33!> Subroutines to add advection terms to the RHS of a transport equation.
35 use advection, only : advection_t
36 use num_types, only : rp, dp
37 use space, only : space_t, gl
38 use field, only : field_t
39 use coefs, only : coef_t
40 use math, only : copy, rzero
46 use field_list, only : field_list_t
48 use device, only : device_map, device_unmap
50 use, intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr
51 implicit none
52 private
53
54 !! Type encapsulating operator-integration-factor splitting advection
55 !! routines with dealiasing applied
56 !! Literature:
57 !! https://www.mcs.anl.gov/~fischer/nek5000/oifs.pdf
58 !! https://publications.anl.gov/anlpubs/2017/12/140626.pdf
59 !! https://dl.acm.org/doi/abs/10.1007/BF01063118
60 type, public, extends(advection_t) :: adv_oifs_t
61 !> Number of RK4 sub-steps
62 integer :: ntaubd = 0
63 !> Coeffs of the higher-order space
64 type(coef_t) :: coef_gl
65 !> Coeffs of the original space in the simulation
66 type(coef_t), pointer :: coef_gll => null()
67 !> Interpolator between the original and higher-order spaces
68 type(interpolator_t) :: gll_to_gl
69 !> The additional higher-order space used in dealiasing
70 type(space_t) :: xh_gl
71 !> The original space used in the simulation
72 type(space_t), pointer :: xh_gll => null()
73 !> The time interpolator scheme
74 type(time_interpolator_t) :: dtime
75 !> The lagged velocity and scalar fields
76 type(field_series_t), pointer :: ulag, vlag, wlag, slag => null()
77 !> The times corresponding to the lagged fields
78 real(kind=dp), pointer :: ctlag(:) => null()
79 !> The time-steps corresponding to the lagged fields
80 real(kind=dp), pointer :: dctlag(:) => null()
81 !> The time scheme controller for the oifs scheme
82 type(time_scheme_controller_t), pointer :: oifs_scheme => null()
83 !> The current convecting field in GL space and rst format
84 type(field_t) :: cr_gl, cs_gl, ct_gl
85 !> The convecting field series in GL space and rst format
86 type(field_series_t) :: convr_gl, convs_gl, convt_gl
87 !> The time interpolated convecting field used in Runge_Kutta method
88 type(field_t), pointer :: cr_k1 => null(), cs_k1 => null(), &
89 ct_k1 => null()
90 type(field_t), pointer :: cr_k23 => null(), cs_k23 => null(), &
91 ct_k23 => null()
92 type(field_t), pointer :: cr_k4 => null(), cs_k4 => null(), &
93 ct_k4 => null()
94 !> The field_list containing the time interpolated convecting field
95 type(field_list_t) :: conv_k1, conv_k23, conv_k4
96 !> The convecting velocity field in GL space
97 real(kind=rp), allocatable :: cx(:), cy(:), cz(:)
98 !> Device pointers for cx, cy, cz
99 type(c_ptr) :: cx_d = c_null_ptr, cy_d = c_null_ptr, cz_d = c_null_ptr
100
101 contains
102 !> Add the advection term for the fluid, i.e. \f$u \cdot \nabla u \f$, to
103 !! the RHS
104 procedure, pass(this) :: compute => adv_oifs_compute
105 !> Add the advection term for a scalar, i.e. \f$u \cdot \nabla s \f$, to
106 !! the RHS
107 procedure, pass(this) :: compute_scalar => adv_oifs_compute_scalar
108 !> Constructor
109 procedure, pass(this) :: init => adv_oifs_init
110 !> setting characteristic convecting field
111 procedure, pass(this) :: set_conv_velocity_fst
112 !> Rebuild the convecting field series after a restart
113 procedure, pass(this) :: restart => adv_oifs_restart
114 !> Destructor
115 procedure, pass(this) :: free => adv_oifs_free
116 !> add the advection term for ALE, i.e. \f$(u - w_m) \cdot \nabla s \f$, to
117 !> the RHS
118 procedure, pass(this) :: compute_ale => adv_oifs_compute_ale
119 !> Update any metrics needed for the advection computation in ALE.
120 procedure, pass(this) :: recompute_metrics => recompute_metrics_oifs
121 end type adv_oifs_t
122
123contains
124
125 !> Constructor
126 !! @param lxd The polynomial order of the space used in the dealiasing.
127 !! @param coef The coefficients of the (space, mesh) pair.
128 !! @param ctarget Target CFL number.
129 !! @param ulag The x component of lagged velocity.
130 !! @param vlag The y component of lagged velocity.
131 !! @param wlag The z component of lagged velocity.
132 !! @param dtlag Lagged time steps.
133 !! @param tlag Lagged simulation times.
134 !! @param time_scheme The bdf-ext time scheme used in the method.
135 !! @param slag The lagged scalar field.
136 subroutine adv_oifs_init(this, lxd, coef, ctarget, ulag, vlag, wlag, &
137 dtlag, tlag, time_scheme, slag)
138 implicit none
139 class(adv_oifs_t), intent(inout) :: this
140 integer, intent(in) :: lxd
141 type(coef_t), target :: coef
142 real(kind=rp), intent(in) :: ctarget
143 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
144 real(kind=dp), target, intent(in) :: dtlag(10)
145 real(kind=dp), target, intent(in) :: tlag(10)
146 type(time_scheme_controller_t), target, intent(in) :: time_scheme
147 type(field_series_t), target, optional :: slag
148 integer :: nel, n_GL, n, idx, idy, idz
149 real(kind=rp) :: max_cfl_rk4
150
151 call this%free()
152
153 ! stability limit for RK4 including safety factor
154 max_cfl_rk4 = 2.0
155 this%ntaubd = max(int(ctarget/max_cfl_rk4),1)
156
157 call this%Xh_GL%init(gl, lxd, lxd, lxd)
158 this%Xh_GLL => coef%Xh
159 this%coef_GLL => coef
160 call this%GLL_to_GL%init(this%Xh_GL, this%Xh_GLL)
161
162 call this%coef_GL%init(this%Xh_GL, coef%msh)
163
164 call this%cr_GL%init(coef%msh, this%Xh_GL)
165 call this%cs_GL%init(coef%msh, this%Xh_GL)
166 call this%ct_GL%init(coef%msh, this%Xh_GL)
167
168 nel = coef%msh%nelv
169 n_gl = nel*this%Xh_GL%lxyz
170 n = nel*coef%Xh%lxyz
171
172 call this%GLL_to_GL%map(this%coef_GL%drdx, coef%drdx, nel, this%Xh_GL)
173 call this%GLL_to_GL%map(this%coef_GL%dsdx, coef%dsdx, nel, this%Xh_GL)
174 call this%GLL_to_GL%map(this%coef_GL%dtdx, coef%dtdx, nel, this%Xh_GL)
175 call this%GLL_to_GL%map(this%coef_GL%drdy, coef%drdy, nel, this%Xh_GL)
176 call this%GLL_to_GL%map(this%coef_GL%dsdy, coef%dsdy, nel, this%Xh_GL)
177 call this%GLL_to_GL%map(this%coef_GL%dtdy, coef%dtdy, nel, this%Xh_GL)
178 call this%GLL_to_GL%map(this%coef_GL%drdz, coef%drdz, nel, this%Xh_GL)
179 call this%GLL_to_GL%map(this%coef_GL%dsdz, coef%dsdz, nel, this%Xh_GL)
180 call this%GLL_to_GL%map(this%coef_GL%dtdz, coef%dtdz, nel, this%Xh_GL)
181
182
183 allocate(this%cx(n_gl))
184 allocate(this%cy(n_gl))
185 allocate(this%cz(n_gl))
186
187 allocate(this%cr_k1)
188 allocate(this%cs_k1)
189 allocate(this%ct_k1)
190 allocate(this%cr_k23)
191 allocate(this%cs_k23)
192 allocate(this%ct_k23)
193 allocate(this%cr_k4)
194 allocate(this%cs_k4)
195 allocate(this%ct_k4)
196
197
198 call this%cr_k1%init(coef%msh, this%Xh_GL)
199 call this%cs_k1%init(coef%msh, this%Xh_GL)
200 call this%ct_k1%init(coef%msh, this%Xh_GL)
201
202 call this%cr_k23%init(coef%msh, this%Xh_GL)
203 call this%cs_k23%init(coef%msh, this%Xh_GL)
204 call this%ct_k23%init(coef%msh, this%Xh_GL)
205
206 call this%cr_k4%init(coef%msh, this%Xh_GL)
207 call this%cs_k4%init(coef%msh, this%Xh_GL)
208 call this%ct_k4%init(coef%msh, this%Xh_GL)
209
210 call this%conv_k1%init(3)
211 call this%conv_k23%init(3)
212 call this%conv_k4%init(3)
213
214 call this%conv_k1%assign(1, this%cr_k1)
215 call this%conv_k1%assign(2, this%cs_k1)
216 call this%conv_k1%assign(3, this%ct_k1)
217
218 call this%conv_k23%assign(1, this%cr_k23)
219 call this%conv_k23%assign(2, this%cs_k23)
220 call this%conv_k23%assign(3, this%ct_k23)
221
222 call this%conv_k4%assign(1, this%cr_k4)
223 call this%conv_k4%assign(2, this%cs_k4)
224 call this%conv_k4%assign(3, this%ct_k4)
225
226 call this%dtime%init(1)
227 this%ulag => ulag
228 this%vlag => vlag
229 this%wlag => wlag
230 this%ctlag => tlag
231 this%dctlag => dtlag
232 this%oifs_scheme => time_scheme
233
234 if (neko_bcknd_device .eq. 1) then
235 call device_map(this%cx, this%cx_d, n_gl)
236 call device_map(this%cy, this%cy_d, n_gl)
237 call device_map(this%cz, this%cz_d, n_gl)
238 end if
239
240 ! Initializing the convecting fields
241 ! Map the velocity fields from GLL space to GL space
242 call this%GLL_to_GL%map(this%cx, this%ulag%f%x, nel, this%Xh_GL)
243 call this%GLL_to_GL%map(this%cy, this%vlag%f%x, nel, this%Xh_GL)
244 call this%GLL_to_GL%map(this%cz, this%wlag%f%x, nel, this%Xh_GL)
245
246 ! Set the convecting field in the rst format
247 call set_convect_rst(this%cr_GL, this%cs_GL, this%ct_GL, &
248 this%cx, this%cy, this%cz, this%Xh_GL, this%coef_GL)
249
250 ! Set the convecting field series
251 call this%convr_GL%init(this%cr_GL, 3)
252 call this%convs_GL%init(this%cs_GL, 3)
253 call this%convt_GL%init(this%ct_GL, 3)
254
255 ! Repeat for previous time-steps
256 call this%GLL_to_GL%map(this%cx, this%ulag%lf(1)%x, nel, this%Xh_GL)
257 call this%GLL_to_GL%map(this%cy, this%vlag%lf(1)%x, nel, this%Xh_GL)
258 call this%GLL_to_GL%map(this%cz, this%wlag%lf(1)%x, nel, this%Xh_GL)
259
260 call set_convect_rst(this%cr_GL, this%cs_GL, this%ct_GL, &
261 this%cx, this%cy, this%cz, this%Xh_GL, this%coef_GL)
262
263 this%convr_GL%lf(1) = this%cr_GL
264 this%convs_GL%lf(1) = this%cs_GL
265 this%convt_GL%lf(1) = this%ct_GL
266
267 call this%GLL_to_GL%map(this%cx, this%ulag%lf(2)%x, nel, this%Xh_GL)
268 call this%GLL_to_GL%map(this%cy, this%vlag%lf(2)%x, nel, this%Xh_GL)
269 call this%GLL_to_GL%map(this%cz, this%wlag%lf(2)%x, nel, this%Xh_GL)
270
271 call set_convect_rst(this%cr_GL, this%cs_GL, this%ct_GL, &
272 this%cx, this%cy, this%cz, this%Xh_GL, this%coef_GL)
273
274 this%convr_GL%lf(2) = this%cr_GL
275 this%convs_GL%lf(2) = this%cs_GL
276 this%convt_GL%lf(2) = this%ct_GL
277
278 ! Initilize the lagged scalar field, if present.
279 if (present(slag)) then
280 this%slag => slag
281 end if
282
283 end subroutine adv_oifs_init
284
285 !> Destructor
286 subroutine adv_oifs_free(this)
287 class(adv_oifs_t), intent(inout) :: this
288
289 call this%conv_k1%free()
290 call this%conv_k23%free()
291 call this%conv_k4%free()
292
293 if (associated(this%cr_k1)) then
294 call this%cr_k1%free()
295 deallocate(this%cr_k1)
296 end if
297 if (associated(this%cs_k1)) then
298 call this%cs_k1%free()
299 deallocate(this%cs_k1)
300 end if
301 if (associated(this%ct_k1)) then
302 call this%ct_k1%free()
303 deallocate(this%ct_k1)
304 end if
305 if (associated(this%cr_k23)) then
306 call this%cr_k23%free()
307 deallocate(this%cr_k23)
308 end if
309 if (associated(this%cs_k23)) then
310 call this%cs_k23%free()
311 deallocate(this%cs_k23)
312 end if
313 if (associated(this%ct_k23)) then
314 call this%ct_k23%free()
315 deallocate(this%ct_k23)
316 end if
317 if (associated(this%cr_k4)) then
318 call this%cr_k4%free()
319 deallocate(this%cr_k4)
320 end if
321 if (associated(this%cs_k4)) then
322 call this%cs_k4%free()
323 deallocate(this%cs_k4)
324 end if
325 if (associated(this%ct_k4)) then
326 call this%ct_k4%free()
327 deallocate(this%ct_k4)
328 end if
329
330 nullify(this%cr_k1)
331 nullify(this%cs_k1)
332 nullify(this%ct_k1)
333 nullify(this%cr_k23)
334 nullify(this%cs_k23)
335 nullify(this%ct_k23)
336 nullify(this%cr_k4)
337 nullify(this%cs_k4)
338 nullify(this%ct_k4)
339
340 call this%convr_GL%free()
341 call this%convs_GL%free()
342 call this%convt_GL%free()
343
344 call this%cr_GL%free()
345 call this%cs_GL%free()
346 call this%ct_GL%free()
347
348 if (allocated(this%cx)) then
349 if (neko_bcknd_device .eq. 1) then
350 call device_unmap(this%cx, this%cx_d)
351 end if
352 deallocate(this%cx)
353 end if
354 if (allocated(this%cy)) then
355 if (neko_bcknd_device .eq. 1) then
356 call device_unmap(this%cy, this%cy_d)
357 end if
358 deallocate(this%cy)
359 end if
360 if (allocated(this%cz)) then
361 if (neko_bcknd_device .eq. 1) then
362 call device_unmap(this%cz, this%cz_d)
363 end if
364 deallocate(this%cz)
365 end if
366
367 call this%dtime%free()
368 call this%GLL_to_GL%free()
369 call this%coef_GL%free()
370 call this%Xh_GL%free()
371
372 nullify(this%coef_GLL)
373 nullify(this%Xh_GLL)
374 nullify(this%ulag)
375 nullify(this%vlag)
376 nullify(this%wlag)
377 nullify(this%slag)
378 nullify(this%ctlag)
379 nullify(this%dctlag)
380 nullify(this%oifs_scheme)
381
382 this%ntaubd = 0
383
384 end subroutine adv_oifs_free
385
386 !> Mapping the velocity fields to GL space and transforming them to the rst format
387 !! @param u Velocity component in x-direction
388 !! @param v Velocity component in y-direction
389 !! @param w Velocity component in z-direction
390 !! @note similar to set_ct_cvx in NEK5000
391 subroutine set_conv_velocity_fst(this, u, v, w)
392 implicit none
393 class(adv_oifs_t), intent(inout) :: this
394 type(field_t), intent(inout) :: u, v, w
395 integer :: i, nel, n_GL, idx, idy, idz
396
397 nel = this%coef_GLL%msh%nelv
398 n_gl = nel*this%Xh_GL%lxyz
399
400 call this%convr_GL%update()
401 call this%convs_GL%update()
402 call this%convt_GL%update()
403
404 call this%GLL_to_GL%map(this%cx, u%x, nel, this%Xh_GL)
405 call this%GLL_to_GL%map(this%cy, v%x, nel, this%Xh_GL)
406 call this%GLL_to_GL%map(this%cz, w%x, nel, this%Xh_GL)
407
408 call set_convect_rst(this%cr_GL, this%cs_GL, this%ct_GL, &
409 this%cx, this%cy, this%cz, this%Xh_GL, this%coef_GL)
410
411 this%convr_GL%f = this%cr_GL
412 this%convs_GL%f = this%cs_GL
413 this%convt_GL%f = this%ct_GL
414
415 end subroutine set_conv_velocity_fst
416
417 !> Rebuild the convecting field series after a restart.
418 !! @details `convr_GL`, `convs_GL` and `convt_GL` are not stored in the
419 !! checkpoint. They are recomputed from the restored lagged velocities,
420 !! first `lf(2)` and then `lf(1)`. The next call to `compute` or
421 !! `compute_scalar` adds the current velocity, as in a run without restart.
422 subroutine adv_oifs_restart(this)
423 class(adv_oifs_t), intent(inout) :: this
424
425 call this%set_conv_velocity_fst(this%ulag%lf(2), this%vlag%lf(2), &
426 this%wlag%lf(2))
427 call this%set_conv_velocity_fst(this%ulag%lf(1), this%vlag%lf(1), &
428 this%wlag%lf(1))
429
430 end subroutine adv_oifs_restart
431
432
433 !> Add the advection term for the fluid, i.e. \f$u \cdot \nabla u \f$, to
434 !! the RHS using the OIFS method.
435 !! @param vx The x component of velocity.
436 !! @param vy The y component of velocity.
437 !! @param vz The z component of velocity.
438 !! @param fx The x component of source term.
439 !! @param fy The y component of source term.
440 !! @param fz The z component of source term.
441 !! @param Xh The function space.
442 !! @param coef The coefficients of the (Xh, mesh) pair.
443 !! @param n Typically the size of the mesh.
444 !! @param dt Current time-step.
445 subroutine adv_oifs_compute(this, vx, vy, vz, fx, fy, fz, Xh, coef, n, dt)
446 implicit none
447 class(adv_oifs_t), intent(inout) :: this
448 type(field_t), intent(inout) :: vx, vy, vz
449 type(field_t), intent(inout) :: fx, fy, fz
450 type(space_t), intent(in) :: Xh
451 type(coef_t), intent(in) :: coef
452 integer, intent(in) :: n
453 real(kind=rp), intent(in), optional :: dt
454 real(kind=dp) :: tau, tau1, th, dtau
455 integer :: i, ilag, itau, nel, n_GL
456
457 nel = coef%msh%nelv
458 n_gl = nel * this%Xh_GL%lxyz
459
460 associate(ulag => this%ulag, vlag => this%vlag, wlag => this%wlag, &
461 ctlag => this%ctlag, dctlag => this%dctlag, dtime => this%dtime, &
462 xh_gl => this%Xh_GL, coef_gl => this%coef_GL, ntaubd => this%ntaubd, &
463 gll_to_gl => this%GLL_to_GL, oifs_scheme => this%oifs_scheme, &
464 cr_k1 => this%cr_K1, cs_k1 => this%cs_K1, ct_k1 => this%ct_K1, &
465 cr_k23 => this%cr_K23, cs_k23 => this%cs_K23, ct_k23 => this%ct_K23, &
466 cr_k4 => this%cr_K4, cs_k4 => this%cs_K4, ct_k4 => this%ct_K4, &
467 convr_gl => this%convr_GL, convs_gl => this%convs_GL, &
468 convt_gl => this%convt_GL, conv_k1 => this%conv_k1, &
469 conv_k23 => this%conv_k23, conv_k4 => this%conv_k4)
470
471 call dtime%init(oifs_scheme%ndiff)
472
473 tau = ctlag(oifs_scheme%ndiff)
474
475 call this%set_conv_velocity_fst(vx, vy, vz)
476
477 if (neko_bcknd_device .eq. 1) then
478 call device_rzero(fx%x_d,n)
479 call device_rzero(fy%x_d,n)
480 call device_rzero(fz%x_d,n)
481 else
482 call rzero(fx%x,n)
483 call rzero(fy%x,n)
484 call rzero(fz%x,n)
485 end if
486
487 do ilag = oifs_scheme%ndiff, 1, -1
488 if (neko_bcknd_device .eq. 1) then
489 if (ilag .eq. 1) then
490 call device_addcol3s2(fx%x_d, vx%x_d, coef%B_d, &
491 oifs_scheme%diffusion_coeffs%x(2), n)
492 call device_addcol3s2(fy%x_d, vy%x_d, coef%B_d, &
493 oifs_scheme%diffusion_coeffs%x(2), n)
494 call device_addcol3s2(fz%x_d, vz%x_d, coef%B_d, &
495 oifs_scheme%diffusion_coeffs%x(2), n)
496 else
497 call device_addcol3s2(fx%x_d, ulag%lf(ilag-1)%x_d, coef%B_d, &
498 oifs_scheme%diffusion_coeffs%x(ilag+1), n)
499 call device_addcol3s2(fy%x_d, vlag%lf(ilag-1)%x_d, coef%B_d, &
500 oifs_scheme%diffusion_coeffs%x(ilag+1), n)
501 call device_addcol3s2(fz%x_d, wlag%lf(ilag-1)%x_d, coef%B_d, &
502 oifs_scheme%diffusion_coeffs%x(ilag+1), n)
503 end if
504 else
505 if (ilag .eq. 1) then
506 do i = 1, n
507 fx%x(i,1,1,1) = fx%x(i,1,1,1) + &
508 oifs_scheme%diffusion_coeffs%x(2) &
509 * vx%x(i,1,1,1) * coef%B(i,1,1,1)
510 fy%x(i,1,1,1) = fy%x(i,1,1,1) + &
511 oifs_scheme%diffusion_coeffs%x(2) &
512 * vy%x(i,1,1,1) * coef%B(i,1,1,1)
513 fz%x(i,1,1,1) = fz%x(i,1,1,1) + &
514 oifs_scheme%diffusion_coeffs%x(2) &
515 * vz%x(i,1,1,1) * coef%B(i,1,1,1)
516 end do
517 else
518 do i = 1, n
519 fx%x(i,1,1,1) = fx%x(i,1,1,1) + &
520 oifs_scheme%diffusion_coeffs%x(ilag+1) &
521 * ulag%lf(ilag-1)%x(i,1,1,1) &
522 * coef%B(i,1,1,1)
523 fy%x(i,1,1,1) = fy%x(i,1,1,1) + &
524 oifs_scheme%diffusion_coeffs%x(ilag+1) &
525 * vlag%lf(ilag-1)%x(i,1,1,1) &
526 * coef%B(i,1,1,1)
527 fz%x(i,1,1,1) = fz%x(i,1,1,1) + &
528 oifs_scheme%diffusion_coeffs%x(ilag+1) &
529 * wlag%lf(ilag-1)%x(i,1,1,1) &
530 * coef%B(i,1,1,1)
531 end do
532 end if
533 end if
534 dtau = dctlag(ilag)/real(ntaubd)
535 do itau = 1, ntaubd
536 th = tau + dtau/2.
537 tau1 = tau + dtau
538 call dtime%interpolate_scalar(tau, cr_k1, convr_gl, ctlag, n_gl)
539 call dtime%interpolate_scalar(tau, cs_k1, convs_gl, ctlag, n_gl)
540 call dtime%interpolate_scalar(tau, ct_k1, convt_gl, ctlag, n_gl)
541 call dtime%interpolate_scalar(th, cr_k23, convr_gl, ctlag, n_gl)
542 call dtime%interpolate_scalar(th, cs_k23, convs_gl, ctlag, n_gl)
543 call dtime%interpolate_scalar(th, ct_k23, convt_gl, ctlag, n_gl)
544 call dtime%interpolate_scalar(tau1, cr_k4, convr_gl, ctlag, n_gl)
545 call dtime%interpolate_scalar(tau1, cs_k4, convs_gl, ctlag, n_gl)
546 call dtime%interpolate_scalar(tau1, ct_k4, convt_gl, ctlag, n_gl)
547 call runge_kutta(fx, conv_k1, conv_k23, conv_k4, xh, xh_gl, &
548 coef, coef_gl, gll_to_gl, tau, dtau, &
549 n, nel, n_gl)
550 call runge_kutta(fy, conv_k1, conv_k23, conv_k4, xh, xh_gl, &
551 coef, coef_gl, gll_to_gl, tau, dtau, &
552 n, nel, n_gl)
553 call runge_kutta(fz, conv_k1, conv_k23, conv_k4, xh, xh_gl, &
554 coef, coef_gl, gll_to_gl, tau, dtau, &
555 n, nel, n_gl)
556 tau = tau1
557 end do
558 end do
559
560 end associate
561
562 end subroutine adv_oifs_compute
563 !> Add the advection term for a scalar, i.e. \f$u \cdot \nabla s \f$, to the
564 !! RHS.
565 !! @param this The object.
566 !! @param vx The x component of velocity.
567 !! @param vy The y component of velocity.
568 !! @param vz The z component of velocity.
569 !! @param s The scalar.
570 !! @param fs The source term.
571 !! @param Xh The function space.
572 !! @param coef The coefficients of the (Xh, mesh) pair.
573 !! @param n Typically the size of the mesh.
574 !! @param dt Current time-step.
575 subroutine adv_oifs_compute_scalar(this, vx, vy, vz, s, fs, Xh, coef, n, dt)
576 implicit none
577 class(adv_oifs_t), intent(inout) :: this
578 type(field_t), intent(inout) :: vx, vy, vz
579 type(field_t), intent(inout) :: fs
580 type(field_t), intent(inout) :: s
581 type(space_t), intent(in) :: Xh
582 type(coef_t), intent(in) :: coef
583 integer, intent(in) :: n
584 real(kind=rp), intent(in), optional :: dt
585
586 real(kind=dp) :: tau, tau1, th, dtau
587 integer :: i, ilag, itau, nel, n_GL
588 nel = coef%msh%nelv
589 n_gl = nel * this%Xh_GL%lxyz
590
591 associate(slag => this%slag, ctlag => this%ctlag, dctlag => this%dctlag, &
592 dtime => this%dtime, xh_gl => this%Xh_GL, coef_gl => this%coef_GL, &
593 ntaubd => this%ntaubd, gll_to_gl => this%GLL_to_GL, &
594 oifs_scheme => this%oifs_scheme, cr_k1 => this%cr_K1, &
595 cs_k1 => this%cs_K1, ct_k1 => this%ct_K1, cr_k23 => this%cr_K23, &
596 cs_k23 => this%cs_K23, ct_k23 => this%ct_K23, cr_k4 => this%cr_K4, &
597 cs_k4 => this%cs_K4, ct_k4 => this%ct_K4, &
598 convr_gl => this%convr_GL, convs_gl => this%convs_GL, &
599 convt_gl => this%convt_GL, conv_k1 => this%conv_k1, &
600 conv_k23 => this%conv_k23, conv_k4 => this%conv_k4)
601
602 call dtime%init(oifs_scheme%ndiff)
603
604 tau = ctlag(oifs_scheme%ndiff)
605
606 call this%set_conv_velocity_fst(vx, vy, vz)
607
608 if (neko_bcknd_device .eq. 1) then
609 call device_rzero(fs%x_d,n)
610 else
611 call rzero(fs%x,n)
612 end if
613
614 do ilag = oifs_scheme%ndiff, 1, -1
615 if (neko_bcknd_device .eq. 1) then
616 if (ilag .eq. 1) then
617 call device_addcol3s2(fs%x_d, s%x_d, coef%B_d, &
618 oifs_scheme%diffusion_coeffs%x(2), n)
619 else
620 call device_addcol3s2(fs%x_d, slag%lf(ilag-1)%x_d, coef%B_d, &
621 oifs_scheme%diffusion_coeffs%x(ilag+1), n)
622 end if
623 else
624 if (ilag .eq. 1) then
625 do i = 1, n
626 fs%x(i,1,1,1) = fs%x(i,1,1,1) + &
627 oifs_scheme%diffusion_coeffs%x(2) &
628 * s%x(i,1,1,1) * coef%B(i,1,1,1)
629 end do
630 else
631 do i = 1, n
632 fs%x(i,1,1,1) = fs%x(i,1,1,1) + &
633 oifs_scheme%diffusion_coeffs%x(ilag+1) &
634 * slag%lf(ilag-1)%x(i,1,1,1) * coef%B(i,1,1,1)
635 end do
636 end if
637 end if
638 dtau = dctlag(ilag)/real(ntaubd)
639 do itau = 1, ntaubd
640 th = tau + dtau/2.
641 tau1 = tau + dtau
642 call dtime%interpolate_scalar(tau, cr_k1, convr_gl, ctlag, n_gl)
643 call dtime%interpolate_scalar(tau, cs_k1, convs_gl, ctlag, n_gl)
644 call dtime%interpolate_scalar(tau, ct_k1, convt_gl, ctlag, n_gl)
645 call dtime%interpolate_scalar(th, cr_k23, convr_gl, ctlag, n_gl)
646 call dtime%interpolate_scalar(th, cs_k23, convs_gl, ctlag, n_gl)
647 call dtime%interpolate_scalar(th, ct_k23, convt_gl, ctlag, n_gl)
648 call dtime%interpolate_scalar(tau1, cr_k4, convr_gl, ctlag, n_gl)
649 call dtime%interpolate_scalar(tau1, cs_k4, convs_gl, ctlag, n_gl)
650 call dtime%interpolate_scalar(tau1, ct_k4, convt_gl, ctlag, n_gl)
651 call runge_kutta(fs, conv_k1, conv_k23, conv_k4, xh, xh_gl, &
652 coef, coef_gl, gll_to_gl, tau, dtau, &
653 n, nel, n_gl)
654 tau = tau1
655 end do
656 end do
657
658 end associate
659
660 end subroutine adv_oifs_compute_scalar
661 subroutine recompute_metrics_oifs(this, coef, moving_boundary)
662 class(adv_oifs_t), intent(inout) :: this
663 type(coef_t), intent(in) :: coef
664 logical, intent(in) :: moving_boundary
665 ! no-op
666 end subroutine recompute_metrics_oifs
667
668
669 subroutine adv_oifs_compute_ale(this, vx, vy, vz, wm_x, wm_y, wm_z, &
670 fx, fy, fz, Xh, coef, n, dt)
671 class(adv_oifs_t), intent(inout) :: this
672 type(field_t), intent(inout) :: vx, vy, vz
673 type(field_t), intent(inout) :: wm_x, wm_y, wm_z
674 type(field_t), intent(inout) :: fx, fy, fz
675 type(space_t), intent(in) :: Xh
676 type(coef_t), intent(in) :: coef
677 integer, intent(in) :: n
678 real(kind=rp), intent(in), optional :: dt
679 ! no-op
680 end subroutine adv_oifs_compute_ale
681end module adv_oifs
double real
Map a Fortran array to a device (allocate and associate).
Definition device.F90:83
Unmap a Fortran array from a device (deassociate and free).
Definition device.F90:89
Subroutines to add advection terms to the RHS of a transport equation.
Definition adv_oifs.f90:34
subroutine adv_oifs_compute_scalar(this, vx, vy, vz, s, fs, xh, coef, n, dt)
Add the advection term for a scalar, i.e. , to the RHS.
Definition adv_oifs.f90:576
subroutine adv_oifs_restart(this)
Rebuild the convecting field series after a restart.
Definition adv_oifs.f90:423
subroutine adv_oifs_compute_ale(this, vx, vy, vz, wm_x, wm_y, wm_z, fx, fy, fz, xh, coef, n, dt)
Definition adv_oifs.f90:671
subroutine adv_oifs_compute(this, vx, vy, vz, fx, fy, fz, xh, coef, n, dt)
Add the advection term for the fluid, i.e. , to the RHS using the OIFS method.
Definition adv_oifs.f90:446
subroutine recompute_metrics_oifs(this, coef, moving_boundary)
Definition adv_oifs.f90:662
subroutine set_conv_velocity_fst(this, u, v, w)
Mapping the velocity fields to GL space and transforming them to the rst format.
Definition adv_oifs.f90:392
subroutine adv_oifs_init(this, lxd, coef, ctarget, ulag, vlag, wlag, dtlag, tlag, time_scheme, slag)
Constructor.
Definition adv_oifs.f90:138
subroutine adv_oifs_free(this)
Destructor.
Definition adv_oifs.f90:287
Subroutines to add advection terms to the RHS of a transport equation.
Definition advection.f90:34
Coefficients.
Definition coef.f90:34
subroutine, public device_rzero(a_d, n, strm)
Zero a real vector.
subroutine, public device_addcol3s2(a_d, b_d, c_d, s, n, strm)
Returns .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Routines to interpolate between different spaces.
Definition math.F90:60
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
subroutine, public rzero(a, n)
Zero a real vector.
Definition math.F90:249
Build configurations.
integer, parameter neko_bcknd_sx
integer, parameter neko_bcknd_device
integer, parameter neko_bcknd_xsmm
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
subroutine, public set_convect_rst(cr, cs, ct, cx, cy, cz, xh, coef)
Transforms the convecting velocity field to the rst form of the GL space.
subroutine, public runge_kutta(phi, conv_k1, conv_k23, conv_k4, xh_gll, xh_gl, coef, coef_gl, gll_to_gl, tau, dtau, n, nel, n_gl)
Compute one step of Runge Kutta time interpolation for OIFS scheme.
Defines a function space.
Definition space.f90:34
integer, parameter, public gl
Definition space.f90:50
Implements type time_interpolator_t.
Compound scheme for the advection and diffusion operators in a transport equation.
Base class for time integration schemes.
Base abstract type for computing the advection operator.
Definition advection.f90:46
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
field_list_t, To be able to group fields together
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
Interpolation between two space::space_t.
The function space for the SEM solution fields.
Definition space.f90:64
Provides a tool to perform interpolation in time.
Implements the logic to compute the time coefficients for the advection and diffusion operators in a ...
#define max(a, b)
Definition tensor.cu:40