Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_pnpn.f90
Go to the documentation of this file.
1! Copyright (c) 2022-2026, 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!> Contains the `scalar_pnpn_t` type.
34
36 use num_types, only : rp, dp
38 rhs_maker_ext_fctry, rhs_maker_bdf_fctry, rhs_maker_oifs_fctry
41 use checkpoint, only : chkp_t
42 use field, only : field_t
44 use mesh, only : mesh_t
45 use coefs, only : coef_t
47 use gather_scatter, only : gs_t, gs_op_add, gs_op_min, gs_op_max
48 use scalar_residual, only : scalar_residual_t, scalar_residual_factory
49 use ax_product, only : ax_t, ax_helm_allocator
50 use ax_helm_svv, only : ax_helm_svv_t
53 use krylov, only : ksp_monitor_t
56 use projection, only : projection_t
57 use math, only : col2, add2s2
61 use advection, only : advection_t, advection_factory
62 use adv_oifs, only : adv_oifs_t
65 use json_module, only : json_file, json_core, json_value
66 use user_intf, only : user_t
69 use time_state, only : time_state_t
71 use bc, only : bc_t, bc_dirichlet
72 use comm, only : neko_comm
73 use mpi_f08, only : mpi_allreduce, mpi_integer, mpi_max
74 implicit none
75 private
76
77
78 type, public, extends(scalar_scheme_t) :: scalar_pnpn_t
79
80 !> The residual of the transport equation.
81 type(field_t) :: s_res
82
83 !> Solution increment.
84 type(field_t) :: ds
85
86 !> Helmholz operator.
87 class(ax_t), allocatable :: ax
88
89 !> Solution projection.
90 type(projection_t) :: proj_s
91
92 !> Projector for the scalar increment constraints.
93 type(scalar_bc_projector_t) :: bc_projector
94
95 !> Advection operator.
96 class(advection_t), allocatable :: adv
97
98 ! Time interpolation scheme
99 logical :: oifs
100
101 ! Advection terms for the oifs method
102 type(field_t) :: advs
103
104 !> Computes the residual of the equation, i.e. `s_res`.
105 class(scalar_residual_t), allocatable :: res
106
107 !> Contributions to kth order extrapolation scheme.
108 class(rhs_maker_ext_t), allocatable :: makeext
109
110 !> Contributions to the RHS from lagged BDF terms.
111 class(rhs_maker_bdf_t), allocatable :: makebdf
112
113 !> Contributions to the RHS from the OIFS method.
114 class(rhs_maker_oifs_t), allocatable :: makeoifs
115
116 !> Lag arrays
117 type(field_t) :: abx1, abx2
118
119 !> Fluid velocity histories used by OIFS scalar advection.
120 type(field_series_t), pointer :: ulag => null()
121 type(field_series_t), pointer :: vlag => null()
122 type(field_series_t), pointer :: wlag => null()
123
124 contains
125 !> Constructor.
126 procedure, pass(this) :: init => scalar_pnpn_init
127 !> To restart
128 procedure, pass(this) :: restart => scalar_pnpn_restart
129 !> Register Pn/Pn-specific fields for checkpointing.
130 procedure, pass(this) :: register_checkpoint => &
132 !> Destructor.
133 procedure, pass(this) :: free => scalar_pnpn_free
134 !> Solve for the current timestep.
135 procedure, pass(this) :: step => scalar_pnpn_step
136 !> Apply strong boundary conditions
137 procedure, pass(this) :: apply_strong_bcs => scalar_scheme_apply_strong_bcs
138 !> Setup the boundary conditions
139 procedure, pass(this) :: setup_bcs_ => scalar_pnpn_setup_bcs_
140 end type scalar_pnpn_t
141
142 interface
143 !> Boundary condition factory. Both constructs and initializes the object.
144 !! @details Will mark a mesh zone for the bc and finalize.
145 !! @param[inout] object The object to be allocated.
146 !! @param[in] scheme The `scalar_pnpn` scheme.
147 !! @param[inout] json JSON object for initializing the bc.
148 !! @param[in] coef SEM coefficients.
149 !! @param[in] user The user interface.
150 module subroutine scalar_pnpn_bc_factory(object, scheme, json, coef, user)
151 class(bc_t), pointer, intent(inout) :: object
152 type(scalar_pnpn_t), intent(in) :: scheme
153 type(json_file), intent(inout) :: json
154 type(coef_t), target, intent(in) :: coef
155 type(user_t), intent(in) :: user
156 end subroutine scalar_pnpn_bc_factory
157 end interface
158
159 interface
160 !> Scalar Pn/Pn boundary condition allocator.
161 !! @param[inout] object The object to be allocated.
162 !! @param[in] type_name The name of the boundary condition type.
163 module subroutine scalar_pnpn_bc_allocator(object, type_name)
164 class(bc_t), pointer, intent(inout) :: object
165 character(len=*), intent(in) :: type_name
166 end subroutine scalar_pnpn_bc_allocator
167 end interface
168
169 !
170 ! Machinery for injecting user-defined types
171 !
172
173 !> Interface for a scalar Pn/Pn boundary condition allocator.
174 !! Implemented in user modules, it should allocate `obj` to the custom user
175 !! type.
176 abstract interface
177 subroutine scalar_pnpn_bc_allocate(obj)
178 import bc_t
179 class(bc_t), pointer, intent(inout) :: obj
180 end subroutine scalar_pnpn_bc_allocate
181 end interface
182
183 interface
184 !> Called in user modules to add an allocator for custom types.
185 !! @param[in] type_name The name of the boundary condition type.
186 !! @param[in] allocator The allocator for the custom user type.
187 module subroutine register_scalar_pnpn_bc(type_name, allocator)
188 character(len=*), intent(in) :: type_name
189 procedure(scalar_pnpn_bc_allocate), pointer, intent(in) :: allocator
190 end subroutine register_scalar_pnpn_bc
191 end interface
192
193 !> A name-allocator pair for user-defined scalar Pn/Pn boundary conditions.
194 type scalar_pnpn_bc_allocator_entry
195 character(len=NEKO_TYPENAME_LEN) :: type_name
196 procedure(scalar_pnpn_bc_allocate), pointer, nopass :: allocator => null()
197 end type scalar_pnpn_bc_allocator_entry
198
199 !> Registry of scalar Pn/Pn boundary condition allocators.
200 type(scalar_pnpn_bc_allocator_entry), allocatable, private :: &
201 scalar_pnpn_bc_registry(:)
202
203 !> The size of `scalar_pnpn_bc_registry`.
204 integer, private :: scalar_pnpn_bc_registry_size = 0
205
206 public :: scalar_pnpn_bc_allocator, scalar_pnpn_bc_allocate, &
207 register_scalar_pnpn_bc
208
209contains
210
211 !> Constructor.
212 !! @param msh The mesh.
213 !! @param coef The coefficients.
214 !! @param gs The gather-scatter.
215 !! @param params The case parameter file in json.
216 !! @param user Type with user-defined procedures.
217 !! @param chkp Set up checkpoint for restarts.
218 !! @param ulag Lag arrays for the x velocity component.
219 !! @param vlag Lag arrays for the y velocity component.
220 !! @param wlag Lag arrays for the z velocity component.
221 !! @param time_scheme The time-integration controller.
222 !! @param rho The fluid density.
223 subroutine scalar_pnpn_init(this, msh, coef, gs, params, numerics_params, &
224 user, chkp, ulag, vlag, wlag, time_scheme, rho)
225 class(scalar_pnpn_t), target, intent(inout) :: this
226 type(mesh_t), target, intent(in) :: msh
227 type(coef_t), target, intent(in) :: coef
228 type(gs_t), target, intent(inout) :: gs
229 type(json_file), target, intent(inout) :: params
230 type(json_file), target, intent(inout) :: numerics_params
231 type(user_t), target, intent(in) :: user
232 type(chkp_t), target, intent(inout) :: chkp
233 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
234 type(time_scheme_controller_t), target, intent(in) :: time_scheme
235 type(field_t), target, intent(in) :: rho
236 integer :: i
237 class(bc_t), pointer :: bc_i
238 character(len=15), parameter :: scheme = 'Modular (Pn/Pn)'
239 logical :: advection
240 real(kind=dp), pointer :: tlag(:), dtlag(:)
241
242 call this%free()
243
244 ! Initiliaze base type.
245 call this%scheme_init(msh, coef, gs, params, scheme, user, rho)
246
247 ! Setup backend dependent Ax routines
248 if (this%svv_enabled) then
249 if (this%svv%formulation .eq. "factorized") then
250 call ax_helm_allocator(this%ax, type_name = "factorized_svv")
251 else
252 call ax_helm_allocator(this%ax, type_name = "one_sided_svv")
253 end if
254 select type (operator => this%ax)
255 class is (ax_helm_svv_t)
256 operator%svv => this%svv
257 end select
258 else if (this%c_Xh%geo_compression) then
259 call ax_helm_allocator(this%ax, type_name = "standard_compr")
260 else
261 call ax_helm_allocator(this%ax, type_name = "standard")
262 end if
263
264 ! Setup backend dependent scalar residual routines
265 call scalar_residual_factory(this%res)
266
267 ! Setup backend dependent summation of extrapolation scheme
268 call rhs_maker_ext_fctry(this%makeext)
269
270 ! Setup backend dependent contributions to F from lagged BD terms
271 call rhs_maker_bdf_fctry(this%makebdf)
272
273 ! Setup backend dependent contributions of the OIFS scheme
274 call rhs_maker_oifs_fctry(this%makeoifs)
275
276 ! Initialize variables specific to this plan
277 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
278 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
279
280 call this%s_res%init(dm_xh, "s_res")
281
282 call this%abx1%init(dm_xh, trim(this%name) // "_abx1")
283
284 call this%abx2%init(dm_xh, trim(this%name) // "_abx2")
285
286 call this%advs%init(dm_xh, "advs")
287
288 call this%ds%init(dm_xh, 'ds')
289
290 end associate
291
292 ! Set up boundary conditions
293 call this%setup_bcs_(user, params)
294
295 do i = 1, this%bcs%size()
296 if (this%bcs%bc_type(i) .eq. bc_dirichlet) then
297 bc_i => this%bcs%get(i)
298 call this%bc_projector%mark(bc_i)
299 end if
300 end do
301
302 ! Initialize projection space
303 call this%proj_s%init(this%dm_Xh%size(), this%projection_dim, &
304 this%projection_activ_step)
305
306 ! Determine the time-interpolation scheme
307 call json_get_or_default(numerics_params, 'oifs', this%oifs, .false.)
308 ! Point to case checkpoint
309 this%chkp => chkp
310 ! Initialize advection factory
311 call json_get_or_default(params, 'advection', advection, .true.)
312 ! OIFS integrates the advection term. With advection disabled, fall back to
313 ! the standard BDF history assembly.
314 this%oifs = this%oifs .and. advection
315
316 this%ulag => ulag
317 this%vlag => vlag
318 this%wlag => wlag
319
320 call chkp%get_time_history(tlag, dtlag)
321 call advection_factory(this%adv, numerics_params, this%c_Xh, &
322 ulag, vlag, wlag, dtlag, &
323 tlag, time_scheme, .not. advection, &
324 this%slag)
325 end subroutine scalar_pnpn_init
326
327 !> Register this scalar scheme with the checkpoint.
328 subroutine scalar_pnpn_register_checkpoint(this, chkp)
329 class(scalar_pnpn_t), target, intent(inout) :: this
330 type(chkp_t), intent(inout) :: chkp
331 type(checkpoint_payload_t), pointer :: payload
332
333 payload => chkp%add_payload("scalars/" // trim(this%name))
334 call payload%add_field(this%s)
335 call payload%add_series(this%slag)
336 call payload%add_field(this%abx1)
337 call payload%add_field(this%abx2)
338
339 end subroutine scalar_pnpn_register_checkpoint
340
341 ! Restarts the scalar from a checkpoint
342 subroutine scalar_pnpn_restart(this, chkp)
343 class(scalar_pnpn_t), target, intent(inout) :: this
344 type(chkp_t), intent(inout) :: chkp
345 integer :: i, n
346 class(bc_t), pointer :: bc_i
347 logical :: interpolated
348
349 n = this%s%dof%size()
350
351 ! Lag fields are restored through the checkpoint's fsp mechanism
352
353 ! The restored fields are continuous unless the checkpoint was written
354 ! on another mesh or at another polynomial order and was interpolated
355 ! on the way in. Only then do the copies of a node shared between
356 ! elements need averaging: scale by the inverse multiplicity, then sum
357 ! the copies with a gather-scatter. On a plain restart that is the
358 ! identity in exact arithmetic but not in floating point, and would put
359 ! about one ulp of error on every shared node. Same guard as the fluid.
360 interpolated = allocated(chkp%previous_mesh%elements) .or. &
361 chkp%previous_Xh%lx .ne. this%Xh%lx
362
363 if (interpolated) then
364 call col2(this%s%x, this%c_Xh%mult, n)
365 call col2(this%slag%lf(1)%x, this%c_Xh%mult, n)
366 call col2(this%slag%lf(2)%x, this%c_Xh%mult, n)
367 end if
368 if (neko_bcknd_device .eq. 1) then
369 call device_memcpy(this%s%x, this%s%x_d, &
370 n, host_to_device, sync = .false.)
371 call device_memcpy(this%slag%lf(1)%x, this%slag%lf(1)%x_d, &
372 n, host_to_device, sync = .false.)
373 call device_memcpy(this%slag%lf(2)%x, this%slag%lf(2)%x_d, &
374 n, host_to_device, sync = .false.)
375 call device_memcpy(this%abx1%x, this%abx1%x_d, &
376 n, host_to_device, sync = .false.)
377 call device_memcpy(this%abx2%x, this%abx2%x_d, &
378 n, host_to_device, sync = .false.)
379 call device_memcpy(this%advs%x, this%advs%x_d, &
380 n, host_to_device, sync = .false.)
381 end if
382
383 if (interpolated) then
384 call this%gs_Xh%op(this%s, gs_op_add)
385 call this%gs_Xh%op(this%slag%lf(1), gs_op_add)
386 call this%gs_Xh%op(this%slag%lf(2), gs_op_add)
387 end if
388
389 ! Restore scalar bcs that need it. This is a no op in most bcs.
390 do i = 1, this%bcs%size()
391 bc_i => this%bcs%get(i)
392 call bc_i%restart(this%s, this%slag)
393 end do
394
395 nullify(bc_i)
396
397 ! The OIFS convecting field series is not in the checkpoint, rebuild it
398 ! from the restored velocity lags of the fluid. The fluid is restarted
399 ! before the scalars, so these lags are already restored.
400 select type (adv => this%adv)
401 type is (adv_oifs_t)
402 call adv%restart()
403 end select
404
405 end subroutine scalar_pnpn_restart
406
407 subroutine scalar_pnpn_free(this)
408 class(scalar_pnpn_t), intent(inout) :: this
409
410 ! Release operator references before scheme_free deallocates their targets.
411 if (allocated(this%Ax)) then
412 call this%Ax%free()
413 deallocate(this%Ax)
414 end if
415
416 !Deallocate scalar field
417 call this%scheme_free()
418
419 call this%bc_projector%free()
420 call this%proj_s%free()
421
422 call this%s_res%free()
423
424 call this%ds%free()
425
426 call this%abx1%free()
427 call this%abx2%free()
428
429 call this%advs%free()
430
431 if (allocated(this%adv)) then
432 call this%adv%free()
433 deallocate(this%adv)
434 end if
435
436 nullify(this%ulag)
437 nullify(this%vlag)
438 nullify(this%wlag)
439
440 if (allocated(this%res)) then
441 deallocate(this%res)
442 end if
443
444 if (allocated(this%makeext)) then
445 deallocate(this%makeext)
446 end if
447
448 if (allocated(this%makebdf)) then
449 deallocate(this%makebdf)
450 end if
451
452 if (allocated(this%makeoifs)) then
453 deallocate(this%makeoifs)
454 end if
455
456 end subroutine scalar_pnpn_free
457
458 subroutine scalar_pnpn_step(this, time, ext_bdf, dt_controller, &
459 ksp_results)
460 class(scalar_pnpn_t), intent(inout) :: this
461 type(time_state_t), intent(in) :: time
462 type(time_scheme_controller_t), intent(in) :: ext_bdf
463 type(time_step_controller_t), intent(in) :: dt_controller
464 type(ksp_monitor_t), intent(inout) :: ksp_results
465 type(field_t), pointer :: rho_cp
466 integer :: rho_cp_index
467 ! Number of degrees of freedom
468 integer :: n
469
470 if (this%freeze) return
471
472 n = this%dm_Xh%size()
473 call neko_scratch_registry%request_field(rho_cp, rho_cp_index, .false.)
474
475 ! The regions are named after the scalar, so they take no fixed id:
476 ! another scalar would start the same id under a different name.
477 call profiler_start_region(trim(this%name))
478 associate(u => this%u, v => this%v, w => this%w, s => this%s, &
479 cp => this%cp, rho => this%rho, lambda_tot => this%lambda_tot, &
480 ds => this%ds, &
481 s_res => this%s_res, &
482 ax => this%Ax, f_xh => this%f_Xh, xh => this%Xh, &
483 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
484 slag => this%slag, oifs => this%oifs, &
485 projection_dim => this%projection_dim, &
486 msh => this%msh, res => this%res, makeoifs => this%makeoifs, &
487 makeext => this%makeext, makebdf => this%makebdf, &
488 t => time%t, tstep => time%tstep, dt => time%dt)
489
490 ! Logs extra information if the log level is NEKO_LOG_DEBUG or above.
491 call print_debug(this)
492
493 ! Update material properties and their pointwise product.
494 call this%update_material_properties(time)
495 call field_col3(rho_cp, rho, cp, n)
496
497 ! Update the SVV coefficient if SVV is enabled.
498 if (this%svv_enabled) then
499 call this%svv%update(rho_cp, tstep)
500 end if
501
502 ! Compute the source terms that are extrapolated in time below
503 call this%source_term%compute(time, extrapolate = .true.)
504
505 if (oifs) then
506 ! The fluid step has already advanced u, v, and w to the new time.
507 ! Its first lag fields contain the velocity at tlag(1), which is the
508 ! latest time represented by the OIFS interpolation history.
509 call this%adv%compute_scalar(this%ulag%lf(1), this%vlag%lf(1), &
510 this%wlag%lf(1), s, this%advs, &
511 xh, this%c_Xh, dm_xh%size())
512 else
513 ! Add the advection operators to the right-hand side.
514 call this%adv%compute_scalar(u, v, w, s, f_xh, &
515 xh, this%c_Xh, dm_xh%size())
516 end if
517
518 ! Scale the volumetric source and advection terms by rho * cp.
519 call field_col2(f_xh, rho_cp, n)
520
521 ! Add weak boundary fluxes without scaling them by rho * cp.
522 call this%bcs%apply_scalar(f_xh%x, n, time, .false.)
523
524 ! Extrapolate the already scaled explicit right-hand side.
525 call makeext%compute_scalar(this%abx1, this%abx2, f_xh%x, &
526 ext_bdf%advection_coeffs%x, n)
527
528 if (oifs) then
529 call makeoifs%compute_scalar(this%advs%x, f_xh%x, &
530 rho_cp, real(dt, kind=rp), n)
531 else
532
533 ! Add the RHS contributions coming from the BDF scheme.
534 call makebdf%compute_scalar(slag, f_xh%x, s, c_xh%B, &
535 rho_cp, real(dt, kind=rp), ext_bdf%diffusion_coeffs%x, &
536 ext_bdf%ndiff, n)
537 end if
538
539 ! Source terms that must not be extrapolated in time are added as
540 ! computed, weighted by the mass matrix and rho * cp like the
541 ! extrapolated terms above.
542 call this%source_term%compute(time, extrapolate = .false., &
543 scale = rho_cp)
544
545 call slag%update()
546
547 !> Apply strong boundary conditions.
548 call this%apply_strong_bcs(time)
549
550 ! Compute scalar residual.
551 ! Every scalar shares the fixed-id regions, which are named the same
552 ! for all, and nests its own named region inside.
553 call profiler_start_region('Scalar_residual', 20)
554 call profiler_start_region(trim(this%name) // '_residual')
555 call res%compute(ax, s, s_res, f_xh, c_xh, msh, xh, lambda_tot, &
556 rho_cp, ext_bdf%diffusion_coeffs%x(1), &
557 real(dt, kind=rp), dm_xh%size())
558
559 call gs_xh%op(s_res, gs_op_add, glb_cmd_event)
560
561 ! Zero-out residual at Dirichlet nodes before solving.
562 call this%bc_projector%apply(s_res%x, dm_xh%size())
563
564 call profiler_end_region(trim(this%name) // '_residual')
565 call profiler_end_region('Scalar_residual', 20)
566
567 call this%proj_s%pre_solving(s_res%x, tstep, c_xh, n, dt_controller)
568
569 call this%pc%update()
570 call profiler_start_region('Scalar_solve', 21)
571 call profiler_start_region(trim(this%name) // '_solve')
572 ksp_results = this%ksp%solve(ax, ds, s_res%x, n, &
573 c_xh, this%bc_projector, gs_xh)
574 ksp_results%name = trim(this%name)
575 call profiler_end_region(trim(this%name) // '_solve')
576 call profiler_end_region('Scalar_solve', 21)
577
578 call this%proj_s%post_solving(ds%x, ax, c_xh, this%bc_projector, gs_xh, &
579 n, tstep, dt_controller)
580
581 ! Update the solution
582 if (neko_bcknd_device .eq. 1) then
583 call device_add2s2(s%x_d, ds%x_d, 1.0_rp, n)
584 else
585 call add2s2(s%x, ds%x, 1.0_rp, n)
586 end if
587
588 end associate
589 call neko_scratch_registry%relinquish_field(rho_cp_index)
590 call profiler_end_region(trim(this%name))
591 end subroutine scalar_pnpn_step
592
593 subroutine print_debug(this)
594 class(scalar_pnpn_t), intent(inout) :: this
595 character(len=LOG_SIZE) :: log_buf
596
597 ! The norms are global reductions, so skip them unless they are logged.
598 if (neko_log%level() .lt. neko_log_debug) return
599
600 write(log_buf, '(A, A, E15.7, A, E15.7, A, E15.7)') 'Scalar debug', &
601 ' l2norm s', field_glsc2(this%s, this%s), &
602 ' slag1', field_glsc2(this%slag%lf(1), this%slag%lf(1)), &
603 ' slag2', field_glsc2(this%slag%lf(2), this%slag%lf(2))
604 call neko_log%message(log_buf, lvl = neko_log_debug)
605 write(log_buf, '(A, A, E15.7, A, E15.7)') 'Scalar debug2', &
606 ' l2norm abx1', field_glsc2(this%abx1, this%abx1), &
607 ' abx2', field_glsc2(this%abx2, this%abx2)
608 call neko_log%message(log_buf, lvl = neko_log_debug)
609 end subroutine print_debug
610
611 !> Initialize boundary conditions
612 !! @param user The user object binding the user-defined routines.
613 !! @param params The parameters of this scalar.
614 subroutine scalar_pnpn_setup_bcs_(this, user, params)
615 class(scalar_pnpn_t), target, intent(inout) :: this
616 type(user_t), target, intent(in) :: user
617 type(json_file), intent(inout) :: params
618 integer :: i, j, n_bcs, zone_size, global_zone_size, ierr
619 type(json_core) :: core
620 type(json_value), pointer :: bc_object
621 type(json_file) :: bc_subdict
622 class(bc_t), pointer :: bc_i
623 logical :: found
624 ! Monitor which boundary zones have been marked
625 logical, allocatable :: marked_zones(:)
626 integer, allocatable :: zone_indices(:)
627 character(len=256) :: error_msg
628
629 if (params%valid_path('boundary_conditions')) then
630 call params%info('boundary_conditions', &
631 n_children = n_bcs)
632 call params%get_core(core)
633 call params%get('boundary_conditions', bc_object, found)
634
635 call this%bcs%init(n_bcs)
636
637 allocate(marked_zones(size(this%msh%labeled_zones)))
638 marked_zones = .false.
639
640 do i = 1, n_bcs
641 ! Create a new json containing just the subdict for this bc
642 call json_extract_item(core, bc_object, i, bc_subdict)
643
644 ! Check that we are not trying to assing a bc to zone, for which one
645 ! has already been assigned and that the zone has more than 0 size
646 ! in the mesh.
647 call json_get(bc_subdict, "zone_indices", zone_indices)
648
649 do j = 1, size(zone_indices)
650 zone_size = this%msh%labeled_zones(zone_indices(j))%size
651 call mpi_allreduce(zone_size, global_zone_size, 1, &
652 mpi_integer, mpi_max, neko_comm, ierr)
653
654 if (global_zone_size .eq. 0) then
655 write(error_msg, '(A, I0, A, A, A, I0, A)') &
656 "Zone index ", zone_indices(j), &
657 " is invalid as this zone has 0 size, meaning it ", &
658 "does not exist in the mesh. Check scalar boundary ", &
659 "condition ", i, "."
660 call neko_error(error_msg)
661 end if
662
663 if (marked_zones(zone_indices(j))) then
664 write(error_msg, '(A, I0, A, A, A, A)')&
665 "Zone with index ", zone_indices(j), &
666 " has already been assigned a boundary condition. ", &
667 "Please check your boundary_conditions entry for the ", &
668 "scalar and make sure that each zone index appears only ",&
669 "in a single boundary condition."
670 call neko_error(error_msg)
671 else
672 marked_zones(zone_indices(j)) = .true.
673 end if
674 end do
675
676 bc_i => null()
677
678 call scalar_pnpn_bc_factory(bc_i, this, bc_subdict, this%c_Xh, user)
679 call this%bcs%append(bc_i)
680 end do
681
682 ! Make sure all labeled zones with non-zero size have been marked
683 do i = 1, size(this%msh%labeled_zones)
684 if ((this%msh%labeled_zones(i)%size .gt. 0) .and. &
685 (.not. marked_zones(i))) then
686 write(error_msg, '(A, I0)') &
687 "No scalar boundary condition assigned to zone ", i
688 call neko_error(error_msg)
689 end if
690 end do
691 else
692 ! Check that there are no labeled zones, i.e. all are periodic.
693 do i = 1, size(this%msh%labeled_zones)
694 if (this%msh%labeled_zones(i)%size .gt. 0) then
695 write(error_msg, '(A, A)') &
696 "No boundary_conditions entry in the case file for scalar ", &
697 this%s%name
698 call neko_error(error_msg)
699 end if
700 end do
701
702 ! For a pure periodic case, we still need to initilise the bc lists
703 ! to a zero size to avoid issues with apply() in step()
704 call this%bcs%init()
705
706 end if
707 end subroutine scalar_pnpn_setup_bcs_
708
709 !> Apply strong boundary conditions.
710 !! @param time The current time state.
711 subroutine scalar_scheme_apply_strong_bcs(this, time)
712 class(scalar_pnpn_t), intent(inout) :: this
713 type(time_state_t), intent(in) :: time
714
715 integer :: i
716 class(bc_t), pointer :: bc_i
717 bc_i => null()
718
719 ! First apply call, sets the Dirichlet value, let's call it d.
720 call this%bcs%apply(this%s, time = time, strong = .true.)
721 ! If we now have local nodes sharing the same global node, and with
722 ! some nodes not masked as Dirichlet, the node which *is* masked
723 ! will have the value d, and the the other ones just some value u.
724 ! Take a nodewise minimum between the local nodes.
725 ! Now, all local nodes store m = min(d, u)
726 call this%gs_Xh%op(this%s, gs_op_min, glb_cmd_event)
727
728 ! Second apply call, so Dirichlet nodes again store d, the rest still store
729 ! m, where m < d by construction.
730 call this%bcs%apply(this%s, time = time, strong = .true.)
731 ! Now apply a max, which guarantees that d wins and gets stored in all the
732 ! local nodes.
733 call this%gs_Xh%op(this%s, gs_op_max, glb_cmd_event)
734
735 ! Reset updated flags
736 do i = 1, this%bcs%size()
737 bc_i => this%bcs%get(i)
738 bc_i%updated = .false.
739 end do
740 nullify(bc_i)
741
742 end subroutine scalar_scheme_apply_strong_bcs
743
744
745end module scalar_pnpn
double real
Copy data between host and device (or device and device).
Definition device.F90:72
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Retrieves a parameter by name or throws an error.
Subroutines to add advection terms to the RHS of a transport equation.
Definition adv_oifs.f90:34
Subroutines to add advection terms to the RHS of a transport equation.
Definition advection.f90:34
Base type for an SVV Helmholtz operator.
Defines a Matrix-vector product.
Definition ax.f90:34
Defines a boundary condition.
Definition bc.f90:34
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
Definition bc.f90:67
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Definition comm.F90:1
type(mpi_comm), public neko_comm
MPI communicator.
Definition comm.F90:46
subroutine, public device_add2s2(a_d, b_d, c1, n, strm)
Vector addition with scalar multiplication (multiplication on first argument).
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public host_to_device
Definition device.F90:48
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Definition device.F90:63
Dirichlet condition applied in the facet normal direction.
subroutine, public field_col2(a, b, n)
Vector multiplication .
real(kind=rp) function, public field_glsc2(a, b, n)
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Gather-scatter.
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_debug
Debug.
Definition log.f90:56
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
integer, parameter, public log_size
Definition log.f90:46
Definition math.F90:60
subroutine, public col2(a, b, n)
Vector multiplication .
Definition math.F90:1095
subroutine, public add2s2(a, b, c1, n)
Vector addition with scalar multiplication (multiplication on second argument).
Definition math.F90:1047
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public dp
Definition num_types.f90:10
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.
Routines to generate the right-hand sides for the convection-diffusion equation. Employs the EXT/BDF ...
Definition rhs_maker.f90:38
Implements scalar_projector_t.
Contains the scalar_pnpn_t type.
subroutine scalar_pnpn_step(this, time, ext_bdf, dt_controller, ksp_results)
subroutine scalar_scheme_apply_strong_bcs(this, time)
Apply strong boundary conditions.
subroutine scalar_pnpn_restart(this, chkp)
subroutine scalar_pnpn_register_checkpoint(this, chkp)
Register this scalar scheme with the checkpoint.
subroutine scalar_pnpn_setup_bcs_(this, user, params)
Initialize boundary conditions.
subroutine scalar_pnpn_init(this, msh, coef, gs, params, numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
Constructor.
subroutine scalar_pnpn_free(this)
Defines the residual for the scalar transport equation.
Contains the scalar_scheme_t type.
Defines a registry for storing and requesting temporary objects This can be used when you have a func...
type(scratch_registry_t), target, public neko_scratch_registry
Global scratch registry.
Compound scheme for the advection and diffusion operators in a transport equation.
Base class for time integration schemes.
Module with things related to the simulation time.
Implements type time_step_controller.
Interfaces for user interaction with NEKO.
Definition user_intf.f90:34
Utilities.
Definition utils.f90:35
integer, parameter, public neko_typename_len
Definition utils.f90:44
Base abstract type for computing the advection operator.
Definition advection.f90:46
Helmholtz operator carrying a non-owning SVV object.
Base type for a matrix-vector product providing .
Definition ax.f90:44
Base type for a boundary condition.
Definition bc.f90:73
Collection of live simulation data registered for checkpointing.
A named collection of live fields to checkpoint together.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
Dirichlet condition in facet normal direction.
Stores a series (sequence) of fields, logically connected to a base field, and arranged according to ...
Gather-scatter kernel.
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:60
Abstract type to add contributions to F from lagged BD terms.
Definition rhs_maker.f90:59
Abstract type to sum up contributions to kth order extrapolation scheme.
Definition rhs_maker.f90:52
Abstract type to add contributions of kth order OIFS scheme.
Definition rhs_maker.f90:66
Projector for scalar boundary conditions.
Abstract type to compute scalar residual.
Base type for a scalar advection-diffusion solver.
Implements the logic to compute the time coefficients for the advection and diffusion operators in a ...
A struct that contains all info about the time, expand as needed.
A type collecting all the overridable user routines and flag to suppress type injection from custom m...