Neko 1.99.9
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
scalar_scheme.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!
34
36 use gather_scatter, only : gs_t
37 use checkpoint, only : chkp_t
39 use num_types, only : rp
40 use field, only : field_t
41 use field_list, only : field_list_t
42 use space, only : space_t
43 use dofmap, only : dofmap_t
44 use krylov, only : ksp_t, krylov_solver_factory, ksp_max_iter, ksp_monitor_t
45 use coefs, only : coef_t
46 use jacobi, only : jacobi_t
48 use sx_jacobi, only : sx_jacobi_t
49 use hsmg, only : hsmg_t
50 use bc_list, only : bc_list_t
51 use bc, only : bc_t
52 use precon, only : pc_t, precon_allocator, precon_destroy
53 use mesh, only : mesh_t
56 use registry, only : neko_registry
59 use json_module, only : json_file
62 use utils, only : neko_error
70 use time_state, only : time_state_t
72 use scalar_ic, only : set_scalar_ic
74 implicit none
75
77 type, abstract :: scalar_scheme_t
79 character(len=:), allocatable :: name
81 type(field_t), pointer :: u
83 type(field_t), pointer :: v
85 type(field_t), pointer :: w
87 type(field_t), pointer :: s
89 type(field_series_t) :: slag
91 type(space_t), pointer :: xh
93 type(dofmap_t), pointer :: dm_xh
95 type(gs_t), pointer :: gs_xh
97 type(coef_t), pointer :: c_xh
99 type(field_t), pointer :: f_xh => null()
103 class(ksp_t), allocatable :: ksp
105 integer :: ksp_maxiter
107 integer :: projection_dim
108
109 integer :: projection_activ_step
111 class(pc_t), allocatable :: pc
113 type(bc_list_t) :: bcs
115 type(json_file), pointer :: params => null()
117 type(mesh_t), pointer :: msh => null()
119 type(chkp_t), pointer :: chkp => null()
121 character(len=:), allocatable :: nut_field_name
123 character(len=:), allocatable :: alphat_field_name
125 type(field_t), pointer :: rho => null()
127 type(field_t), pointer :: lambda => null()
129 type(field_t), pointer :: cp => null()
131 type(field_t), pointer :: lambda_tot => null()
133 real(kind=rp) :: pr_turb
135 type(field_list_t) :: material_properties
136 procedure(user_material_properties_intf), nopass, pointer :: &
137 user_material_properties => null()
139 logical :: freeze = .false.
141 logical :: svv_enabled = .false.
143 type(svv_t), allocatable :: svv
144 contains
146 procedure, pass(this) :: scheme_init => scalar_scheme_init
148 procedure, pass(this) :: scheme_free => scalar_scheme_free
150 procedure, pass(this) :: validate => scalar_scheme_validate
152 procedure, pass(this) :: set_initial_condition => &
155 procedure, pass(this) :: register_checkpoint => &
158 procedure, pass(this) :: set_material_properties => &
161 procedure, pass(this) :: update_material_properties => &
164 procedure(scalar_scheme_init_intrf), pass(this), deferred :: init
166 procedure(scalar_scheme_free_intrf), pass(this), deferred :: free
168 procedure(scalar_scheme_step_intrf), pass(this), deferred :: step
170 procedure(scalar_scheme_restart_intrf), pass(this), deferred :: restart
171 end type scalar_scheme_t
172
174 abstract interface
175 subroutine scalar_scheme_init_intrf(this, msh, coef, gs, params, &
176 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
177 import scalar_scheme_t
178 import json_file
179 import coef_t
180 import gs_t
181 import mesh_t
182 import user_t
183 import field_series_t, field_t
185 import rp
186 import chkp_t
187 class(scalar_scheme_t), target, intent(inout) :: this
188 type(mesh_t), target, intent(in) :: msh
189 type(coef_t), target, intent(in) :: coef
190 type(gs_t), target, intent(inout) :: gs
191 type(json_file), target, intent(inout) :: params
192 type(json_file), target, intent(inout) :: numerics_params
193 type(user_t), target, intent(in) :: user
194 type(chkp_t), target, intent(inout) :: chkp
195 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
196 type(time_scheme_controller_t), target, intent(in) :: time_scheme
197 type(field_t), target, intent(in) :: rho
198 end subroutine scalar_scheme_init_intrf
199 end interface
200
202 abstract interface
203 subroutine scalar_scheme_restart_intrf(this, chkp)
204 import scalar_scheme_t
205 import chkp_t
206 import rp
207 class(scalar_scheme_t), target, intent(inout) :: this
208 type(chkp_t), intent(inout) :: chkp
209 end subroutine scalar_scheme_restart_intrf
210 end interface
211
213 abstract interface
215 import scalar_scheme_t
216 class(scalar_scheme_t), intent(inout) :: this
217 end subroutine scalar_scheme_free_intrf
218 end interface
219
221 abstract interface
222 subroutine scalar_scheme_step_intrf(this, time, ext_bdf, dt_controller, &
223 ksp_results)
224 import scalar_scheme_t
225 import time_state_t
228 import ksp_monitor_t
229 class(scalar_scheme_t), intent(inout) :: this
230 type(time_state_t), intent(in) :: time
231 type(time_scheme_controller_t), intent(in) :: ext_bdf
232 type(time_step_controller_t), intent(in) :: dt_controller
233 type(ksp_monitor_t), intent(inout) :: ksp_results
234 end subroutine scalar_scheme_step_intrf
235 end interface
236
237 ! ========================================================================== !
238 ! Helper functions and types for scalar_scheme_t
239 ! ========================================================================== !
240
243 class(scalar_scheme_t), allocatable :: scalar
244 contains
246 procedure, pass(this) :: init => scalar_scheme_wrapper_init
248 procedure, pass(this) :: free => scalar_scheme_wrapper_free
251 procedure, pass(this) :: move_from => &
254 procedure, pass(this) :: is_allocated => &
257
258
259 interface
260
273 module subroutine scalar_scheme_factory(object, msh, coef, gs, params, &
274 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
275 class(scalar_scheme_t), allocatable, intent(inout) :: object
276 type(mesh_t), target, intent(in) :: msh
277 type(coef_t), target, intent(in) :: coef
278 type(gs_t), target, intent(inout) :: gs
279 type(json_file), target, intent(inout) :: params
280 type(json_file), target, intent(inout) :: numerics_params
281 type(user_t), target, intent(in) :: user
282 type(chkp_t), target, intent(inout) :: chkp
283 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
284 type(time_scheme_controller_t), target, intent(in) :: time_scheme
285 type(field_t), target, intent(in) :: rho
286 end subroutine scalar_scheme_factory
287 end interface
288
289 interface
290
293 module subroutine scalar_scheme_allocator(object, type_name)
294 class(scalar_scheme_t), allocatable, intent(inout) :: object
295 character(len=*), intent(in):: type_name
296 end subroutine scalar_scheme_allocator
297 end interface
298
299 !
300 ! Machinery for injecting user-defined types
301 !
302
306 abstract interface
307 subroutine scalar_scheme_allocate(obj)
308 import scalar_scheme_t
309 class(scalar_scheme_t), allocatable, intent(inout) :: obj
310 end subroutine scalar_scheme_allocate
311 end interface
312
313 interface
314
315 module subroutine register_scalar_scheme(type_name, allocator)
316 character(len=*), intent(in) :: type_name
317 procedure(scalar_scheme_allocate), pointer, intent(in) :: allocator
318 end subroutine register_scalar_scheme
319 end interface
320
321 ! A name-allocator pair for user-defined types. A helper type to define a
322 ! registry of custom allocators.
323 type scalar_scheme_allocator_entry
324 character(len=20) :: type_name
325 procedure(scalar_scheme_allocate), pointer, nopass :: allocator
326 end type scalar_scheme_allocator_entry
327
329 type(scalar_scheme_allocator_entry), allocatable, private :: &
330 scalar_scheme_registry(:)
331
333 integer, private :: scalar_scheme_registry_size = 0
334
335contains
336
345 subroutine scalar_scheme_init(this, msh, c_Xh, gs_Xh, params, scheme, user, &
346 rho)
347 class(scalar_scheme_t), target, intent(inout) :: this
348 type(mesh_t), target, intent(in) :: msh
349 type(coef_t), target, intent(in) :: c_Xh
350 type(gs_t), target, intent(inout) :: gs_Xh
351 type(json_file), target, intent(inout) :: params
352 character(len=*), intent(in) :: scheme
353 type(user_t), target, intent(in) :: user
354 type(field_t), target, intent(in) :: rho
355 ! IO buffer for log output
356 character(len=LOG_SIZE) :: log_buf
357 ! Variables for retrieving json parameters
358 logical :: logical_val
359 real(kind=rp) :: real_val, solver_abstol
360 integer :: integer_val, ierr
361 character(len=:), allocatable :: solver_type, solver_precon
362 type(json_file) :: precon_params
363 type(json_file) :: json_subdict
364 logical :: nut_dependency
365
366 this%u => neko_registry%get_field('u')
367 this%v => neko_registry%get_field('v')
368 this%w => neko_registry%get_field('w')
369 this%rho => rho
370
371 ! Assign a name
372 ! Note that the keyword is added by `scalars_t`, so there is always a
373 ! default.
374 call json_get(params, 'name', this%name)
375
376 ! Set the freeze flag
377 call json_get_or_default(params, 'freeze', this%freeze, .false.)
378
379 call neko_log%section('Scalar')
380 call json_get(params, 'solver.type', solver_type)
381 call json_get(params, 'solver.preconditioner.type', &
382 solver_precon)
383 call json_get(params, 'solver.preconditioner', precon_params)
384 call json_get_or_lookup(params, 'solver.absolute_tolerance', &
385 solver_abstol)
386
387 call json_get_or_lookup_or_default(params, &
388 'solver.projection_space_size', &
389 this%projection_dim, 0)
390 call json_get_or_lookup_or_default(params, &
391 'solver.projection_hold_steps', &
392 this%projection_activ_step, 5)
393
394
395 write(log_buf, '(A, A)') 'Type : ', trim(scheme)
396 call neko_log%message(log_buf)
397 write(log_buf, '(A, A)') 'Name : ', trim(this%name)
398 call neko_log%message(log_buf)
399 call neko_log%message('Ksp scalar : ('// trim(solver_type) // &
400 ', ' // trim(solver_precon) // ')')
401 write(log_buf, '(A,ES13.6)') ' `-abs tol :', solver_abstol
402 call neko_log%message(log_buf)
403
404 this%Xh => this%u%Xh
405 this%dm_Xh => this%u%dof
406 if (associated(this%params)) then
407 deallocate(this%params)
408 end if
409 allocate(this%params)
410 this%params = params
411 this%msh => msh
412
413 call neko_registry%add_field(this%dm_Xh, this%name, &
414 ignore_existing = .true.)
415
416 this%s => neko_registry%get_field(this%name)
417
418 call this%slag%init(this%s, 2)
419
420 this%gs_Xh => gs_xh
421 this%c_Xh => c_xh
422
423 !
424 ! Material properties
425 !
426 call this%set_material_properties(params, user)
427
428 !
429 ! Spectral vanishing viscosity
430 !
431 if (params%valid_path('svv')) then
432 call json_get_or_default(params, 'svv.enabled', this%svv_enabled, &
433 .false.)
434 if (this%svv_enabled) then
435 allocate(this%svv)
436 call this%svv%init(params, this%c_Xh, this%rho)
437 end if
438 end if
439
440
441 !
442 ! Turbulence modelling
443 !
444 this%alphat_field_name = ""
445 this%nut_field_name = ""
446 if (params%valid_path('alphat')) then
447 call json_get(this%params, 'alphat', json_subdict)
448 call json_get(json_subdict, 'nut_dependency', nut_dependency)
449 if (nut_dependency) then
450 call json_get_or_lookup(json_subdict, 'Pr_t', this%pr_turb)
451 call json_get(json_subdict, 'nut_field', this%nut_field_name)
452 else
453 call json_get(json_subdict, 'alphat_field', this%alphat_field_name)
454 end if
455 end if
456
457 !
458 ! Setup right-hand side field.
459 !
460 allocate(this%f_Xh)
461 call this%f_Xh%init(this%dm_Xh, fld_name = "scalar_rhs")
462
463 ! Initialize the source term
464 call this%source_term%init(this%f_Xh, this%c_Xh, user, this%name)
465 call this%source_term%add(params, 'source_terms')
466
467 ! todo parameter file ksp tol should be added
468 call json_get_or_lookup_or_default(params, &
469 'solver.max_iterations', &
470 integer_val, ksp_max_iter)
471 call json_get_or_default(params, &
472 'solver.monitor', &
473 logical_val, .false.)
474 call scalar_scheme_solver_factory(this%ksp, this%dm_Xh%size(), &
475 solver_type, integer_val, solver_abstol, logical_val)
476 call scalar_scheme_precon_factory(this%pc, this%ksp, &
477 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs, &
478 solver_precon, precon_params)
479
480 call neko_log%end_section()
481
482 end subroutine scalar_scheme_init
483
487 subroutine scalar_scheme_set_initial_condition(this, user, scalar_index)
488 class(scalar_scheme_t), intent(inout) :: this
489 type(user_t), intent(in) :: user
490 integer, intent(in) :: scalar_index
491 character(len=:), allocatable :: ic_type
492 type(json_file) :: ic_params
493
494 call json_get(this%params, 'initial_condition.type', ic_type)
495 call json_get(this%params, 'initial_condition', ic_params)
496
497 if (trim(ic_type) .ne. 'user') then
498 call set_scalar_ic(this%s, this%c_Xh, this%gs_Xh, ic_type, &
499 ic_params, scalar_index)
500 else
501 call set_scalar_ic(this%name, this%s, this%c_Xh, this%gs_Xh, &
502 user%initial_conditions)
503 end if
504
505 call ic_params%destroy()
506 deallocate(ic_type)
507
508 end subroutine scalar_scheme_set_initial_condition
509
512 subroutine scalar_scheme_register_checkpoint(this, chkp)
513 class(scalar_scheme_t), target, intent(inout) :: this
514 type(chkp_t), intent(inout) :: chkp
515 type(checkpoint_payload_t), pointer :: payload
516
517 payload => chkp%add_payload("scalars/" // trim(this%name))
518 call payload%add_field(this%s)
519 call payload%add_series(this%slag)
520
521 end subroutine scalar_scheme_register_checkpoint
522
523
525 subroutine scalar_scheme_free(this)
526 class(scalar_scheme_t), intent(inout) :: this
527 class(bc_t), pointer :: bc
528 integer :: i
529
530 bc => null()
531
532 if (allocated(this%svv)) then
533 call this%svv%free()
534 deallocate(this%svv)
535 end if
536 this%svv_enabled = .false.
537
538 nullify(this%Xh)
539 nullify(this%dm_Xh)
540 nullify(this%gs_Xh)
541 nullify(this%c_Xh)
542 if (associated(this%params)) then
543 deallocate(this%params)
544 nullify(this%params)
545 end if
546
547 if (allocated(this%ksp)) then
548 call this%ksp%free()
549 deallocate(this%ksp)
550 end if
551
552 if (allocated(this%pc)) then
553 call precon_destroy(this%pc)
554 deallocate(this%pc)
555 end if
556
557 if (allocated(this%name)) then
558 deallocate(this%name)
559 end if
560
561 call this%source_term%free()
562
563 if (associated(this%f_Xh)) then
564 call this%f_Xh%free()
565 deallocate(this%f_Xh)
566 end if
567
568 do i = 1, this%bcs%size()
569 bc => this%bcs%get(i)
570 if (associated(bc)) then
571 call bc%free()
572 deallocate(bc)
573 end if
574 end do
575
576 call this%bcs%free()
577 call this%slag%free()
578 call this%material_properties%free()
579
580 if (allocated(this%nut_field_name)) then
581 deallocate(this%nut_field_name)
582 end if
583
584 if (allocated(this%alphat_field_name)) then
585 deallocate(this%alphat_field_name)
586 end if
587
588 nullify(this%cp)
589 nullify(this%lambda)
590 nullify(this%lambda_tot)
591 nullify(bc)
592
593 end subroutine scalar_scheme_free
594
597 subroutine scalar_scheme_validate(this)
598 class(scalar_scheme_t), target, intent(inout) :: this
599
600 if ( (.not. allocated(this%u%x)) .or. &
601 (.not. allocated(this%v%x)) .or. &
602 (.not. allocated(this%w%x)) .or. &
603 (.not. allocated(this%s%x))) then
604 call neko_error('Fields are not allocated')
605 end if
606
607 if (.not. allocated(this%ksp)) then
608 call neko_error('No Krylov solver for velocity defined')
609 end if
610
611 if (.not. associated(this%Xh)) then
612 call neko_error('No function space defined')
613 end if
614
615 if (.not. associated(this%dm_Xh)) then
616 call neko_error('No dofmap defined')
617 end if
618
619 if (.not. associated(this%c_Xh)) then
620 call neko_error('No coefficients defined')
621 end if
622
623 if (.not. associated(this%f_Xh)) then
624 call neko_error('No rhs allocated')
625 end if
626
627 if (.not. associated(this%params)) then
628 call neko_error('No parameters defined')
629 end if
630
631 if (.not. associated(this%rho)) then
632 call neko_error('No density field defined')
633 end if
634
635 end subroutine scalar_scheme_validate
636
639 subroutine scalar_scheme_solver_factory(ksp, n, solver, max_iter, &
640 abstol, monitor)
641 class(ksp_t), allocatable, target, intent(inout) :: ksp
642 integer, intent(in), value :: n
643 integer, intent(in) :: max_iter
644 character(len=*), intent(in) :: solver
645 real(kind=rp) :: abstol
646 logical, intent(in) :: monitor
647
648 call krylov_solver_factory(ksp, n, solver, max_iter, &
649 abstol, monitor = monitor)
650
651 end subroutine scalar_scheme_solver_factory
652
654 subroutine scalar_scheme_precon_factory(pc, ksp, coef, dof, gs, bclst, &
655 pctype, pcparams)
656 class(pc_t), allocatable, target, intent(inout) :: pc
657 class(ksp_t), target, intent(inout) :: ksp
658 type(coef_t), target, intent(in) :: coef
659 type(dofmap_t), target, intent(in) :: dof
660 type(gs_t), target, intent(inout) :: gs
661 type(bc_list_t), target, intent(inout) :: bclst
662 character(len=*) :: pctype
663 type(json_file), intent(inout) :: pcparams
664
665 call precon_allocator(pc, pctype)
666
667 select type (pcp => pc)
668 type is (jacobi_t)
669 call pcp%init(coef, dof, gs)
670 type is (sx_jacobi_t)
671 call pcp%init(coef, dof, gs)
672 type is (device_jacobi_t)
673 call pcp%init(coef, dof, gs)
674 type is (hsmg_t)
675 call pcp%init(coef, bclst, pcparams)
676 end select
677
678 call ksp%set_pc(pc)
679
680 end subroutine scalar_scheme_precon_factory
681
686 subroutine scalar_scheme_update_material_properties(this, time)
687 class(scalar_scheme_t), intent(inout) :: this
688 type(time_state_t), intent(in) :: time
689 type(field_t), pointer :: nut, alphat
690 integer :: index
691 ! Factor to transform nu_t to lambda_t
692 type(field_t), pointer :: lambda_factor
693
694 call this%user_material_properties(this%name, this%material_properties, &
695 time)
696
697 ! factor = rho * cp / pr_turb
698 if (len_trim(this%nut_field_name) .gt. 0 &
699 .and. len_trim(this%alphat_field_name) .eq. 0 ) then
700 nut => neko_registry%get_field(this%nut_field_name)
701
702 ! lambda_tot = lambda + rho * cp * nut / pr_turb
703 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
704 call field_cmult2(lambda_factor, nut, 1.0_rp / this%pr_turb)
705 call field_col2(lambda_factor, this%cp)
706 call field_col2(lambda_factor, this%rho)
707 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
708 call neko_scratch_registry%relinquish_field(index)
709
710 else if (len_trim(this%alphat_field_name) .gt. 0 &
711 .and. len_trim(this%nut_field_name) .eq. 0 ) then
712 alphat => neko_registry%get_field(this%alphat_field_name)
713
714 ! lambda_tot = lambda + rho * cp * alphat
715 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
716 call field_col3(lambda_factor, this%cp, alphat)
717 call field_col2(lambda_factor, this%rho)
718 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
719 call neko_scratch_registry%relinquish_field(index)
720
721 else if (len_trim(this%alphat_field_name) .gt. 0 &
722 .and. len_trim(this%nut_field_name) .gt. 0 ) then
723 call neko_error("Conflicting definition of eddy diffusivity " // &
724 "for the scalar equation")
725 end if
726
727 ! Since cp is a fields and we use the %x(1,1,1,1) of the
728 ! host array data to pass constant material properties
729 ! to some routines, we need to make sure that the host
730 ! values are also filled
731 if (neko_bcknd_device .eq. 1) then
732 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
733 device_to_host, sync = .false.)
734 end if
735
736 end subroutine scalar_scheme_update_material_properties
737
741 subroutine scalar_scheme_set_material_properties(this, params, user)
742 class(scalar_scheme_t), intent(inout) :: this
743 type(json_file), intent(inout) :: params
744 type(user_t), target, intent(in) :: user
745 character(len=LOG_SIZE) :: log_buf
746 ! A local pointer that is needed to make Intel happy
747 procedure(user_material_properties_intf), pointer :: dummy_mp_ptr
748 real(kind=rp) :: const_cp, const_lambda
749 ! Dummy time state set to 0
750 type(time_state_t) :: time
751
752 dummy_mp_ptr => dummy_user_material_properties
753
754 ! Fill lambda field with the physical value
755
756 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda")
757 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda_tot")
758 call neko_registry%add_field(this%dm_Xh, this%name // "_cp")
759 this%lambda => neko_registry%get_field(this%name // "_lambda")
760 this%lambda_tot => neko_registry%get_field(this%name // "_lambda_tot")
761 this%cp => neko_registry%get_field(this%name // "_cp")
762
763 call this%material_properties%init(2)
764 call this%material_properties%assign(1, this%cp)
765 call this%material_properties%assign(2, this%lambda)
766
767 if (.not. associated(user%material_properties, dummy_mp_ptr)) then
768
769 write(log_buf, '(A)') "Material properties must be set in the user " // &
770 "file!"
771 call neko_log%message(log_buf)
772 this%user_material_properties => user%material_properties
773
774 call user%material_properties(this%name, this%material_properties, time)
775 else
776 this%user_material_properties => dummy_user_material_properties
777 if (params%valid_path('Pe') .and. &
778 (params%valid_path('lambda') .or. &
779 params%valid_path('cp'))) then
780 call neko_error("To set the material properties for the scalar, " // &
781 "either provide Pe OR lambda and cp in the case file.")
782 ! Non-dimensional case
783 else if (params%valid_path('Pe')) then
784 write(log_buf, '(A)') 'Non-dimensional scalar material properties' //&
785 ' input.'
786 call neko_log%message(log_buf, lvl = neko_log_verbose)
787 write(log_buf, '(A)') 'Specific heat capacity will be set to 1, '
788 call neko_log%message(log_buf, lvl = neko_log_verbose)
789 write(log_buf, '(A)') 'conductivity to 1/Pe. Assumes density is 1.'
790 call neko_log%message(log_buf, lvl = neko_log_verbose)
791
792 ! Read Pe into lambda for further manipulation.
793 call json_get_or_lookup(params, 'Pe', const_lambda)
794 write(log_buf, '(A,ES13.6)') 'Pe :', const_lambda
795 call neko_log%message(log_buf)
796
797 ! Set cp and rho to 1 since the setup is non-dimensional.
798 const_cp = 1.0_rp
799 ! Invert the Pe to get conductivity
800 const_lambda = 1.0_rp/const_lambda
801 ! Dimensional case
802 else
803 call json_get_or_lookup(params, 'lambda', const_lambda)
804 call json_get_or_lookup(params, 'cp', const_cp)
805 end if
806 end if
807 ! We need to fill the fields based on the parsed const values
808 ! if the user routine is not used.
809 if (associated(user%material_properties, dummy_mp_ptr)) then
810 ! Fill mu and rho field with the physical value
811 call field_cfill(this%lambda, const_lambda)
812 call field_cfill(this%cp, const_cp)
813
814 write(log_buf, '(A,ES13.6)') 'lambda :', const_lambda
815 call neko_log%message(log_buf)
816 write(log_buf, '(A,ES13.6)') 'cp :', const_cp
817 call neko_log%message(log_buf)
818 end if
819
820 ! Copy over material property to the total one
821 call field_copy(this%lambda_tot, this%lambda)
822
823 ! Since cp is a field and we use the %x(1,1,1,1) of the
824 ! host array data to pass constant material properties
825 ! to some routines, we need to make sure that the host
826 ! values are also filled
827 if (neko_bcknd_device .eq. 1) then
828 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
829 device_to_host, sync = .false.)
830 end if
831 end subroutine scalar_scheme_set_material_properties
832
833 ! ========================================================================== !
834 ! Scalar scheme wrapper type methods
835
837 subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, &
838 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
839 class(scalar_scheme_wrapper_t), intent(inout) :: this
840 type(mesh_t), target, intent(in) :: msh
841 type(coef_t), target, intent(in) :: coef
842 type(gs_t), target, intent(inout) :: gs
843 type(json_file), target, intent(inout) :: params
844 type(json_file), target, intent(inout) :: numerics_params
845 type(user_t), target, intent(in) :: user
846 type(chkp_t), target, intent(inout) :: chkp
847 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
848 type(time_scheme_controller_t), target, intent(in) :: time_scheme
849 type(field_t), target, intent(in) :: rho
850
851 call this%free()
852 call scalar_scheme_factory(this%scalar, msh, coef, gs, params, &
853 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
854
855 end subroutine scalar_scheme_wrapper_init
856
858 subroutine scalar_scheme_wrapper_free(this)
859 class(scalar_scheme_wrapper_t), intent(inout) :: this
860
861 if (allocated(this%scalar)) then
862 call this%scalar%free()
863 deallocate(this%scalar)
864 end if
865
866 end subroutine scalar_scheme_wrapper_free
867
872 subroutine scalar_scheme_wrapper_move_from(this, other)
873 class(scalar_scheme_wrapper_t), intent(inout) :: this
874 class(scalar_scheme_wrapper_t), intent(inout) :: other
875
876 ! Move the pointer
877 call move_alloc(other%scalar, this%scalar)
878
879 end subroutine scalar_scheme_wrapper_move_from
880
883 function scalar_scheme_wrapper_is_allocated(this) result(is_alloc)
884 class(scalar_scheme_wrapper_t), intent(in) :: this
885 logical :: is_alloc
886 is_alloc = allocated(this%scalar)
887 end function scalar_scheme_wrapper_is_allocated
888
889end module scalar_scheme
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.
Abstract interface to dealocate a scalar formulation.
Abstract interface to initialize a scalar formulation.
Abstract interface to restart a scalar formulation.
Abstract interface to compute a time-step.
Abstract interface for setting material properties.
Defines a list of bc_t.
Definition bc_list.f90:34
Defines a boundary condition.
Definition bc.f90:34
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Jacobi preconditioner accelerator backend.
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:48
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
subroutine, public field_col2(a, b, n)
Vector multiplication .
subroutine, public field_cmult2(a, b, c, n)
Multiplication by constant c .
subroutine, public field_cfill(a, c, n)
Set all elements to a constant c .
subroutine, public field_col3(a, b, c, n)
Vector multiplication with 3 vectors .
subroutine, public field_copy(a, b, n)
Copy a vector .
subroutine, public field_add3(a, b, c, n)
Vector addition .
Contains the field_serties_t type.
Defines a field.
Definition field.f90:34
Gather-scatter.
Krylov preconditioner.
Definition pc_hsmg.f90:61
Jacobi preconditioner.
Definition pc_jacobi.f90:34
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
integer, parameter, public ksp_max_iter
Maximum number of iters.
Definition krylov.f90:52
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_verbose
Verbose.
Definition log.f90:54
type(log_t), public neko_log
Global log stream.
Definition log.f90:91
integer, parameter, public log_size
Definition log.f90:46
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Krylov preconditioner.
Definition precon.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
Scalar initial condition.
Definition scalar_ic.f90:34
Contains the scalar_scheme_t type.
subroutine scalar_scheme_init(this, msh, c_xh, gs_xh, params, scheme, user, rho)
Initialize all related components of the current scheme.
logical function scalar_scheme_wrapper_is_allocated(this)
Return allocation status.
subroutine scalar_scheme_wrapper_free(this)
Destructor. Just deallocates the pointer.
subroutine scalar_scheme_free(this)
Deallocate a scalar formulation.
subroutine scalar_scheme_validate(this)
Validate that all fields, solvers etc necessary for performing time-stepping are defined.
subroutine scalar_scheme_update_material_properties(this, time)
Call user material properties routine and update the values of lambda if necessary.
subroutine scalar_scheme_register_checkpoint(this, chkp)
Register this scalar scheme with the checkpoint.
subroutine scalar_scheme_set_material_properties(this, params, user)
Set lamdba and cp.
subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
Constructor. Initializes the object.
subroutine scalar_scheme_wrapper_move_from(this, other)
Move assignment operator for the wrapper, needed for storing schemes in lists and arrays.
subroutine scalar_scheme_set_initial_condition(this, user, scalar_index)
Set the initial condition.
Implements the scalar_source_term_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.
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Defines a function space.
Definition space.f90:34
Data and filter construction for spectral vanishing viscosity.
Jacobi preconditioner SX-Aurora backend.
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
subroutine, public dummy_user_material_properties(scheme_name, properties, time)
Utilities.
Definition utils.f90:35
Base type for a boundary condition.
Definition bc.f90:73
A list of allocatable `bc_t`. Follows the standard interface of lists.
Definition bc_list.f90:49
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:135
Defines a jacobi preconditioner.
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 ...
Gather-scatter kernel.
Defines a jacobi preconditioner.
Definition pc_jacobi.f90:45
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:57
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:74
Defines a canonical Krylov preconditioner.
Definition precon.f90:40
Base type for a scalar advection-diffusion solver.
A helper type that is needed to have an array of polymorphic objects.
Wrapper contaning and executing the scalar source terms.
The function space for the SEM solution fields.
Definition space.f90:64
Spectral vanishing viscosity configuration and coefficients.
Defines a jacobi preconditioner for SX-Aurora.
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...