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
45 use coefs, only : coef_t
46 use bc_list, only : bc_list_t
47 use bc, only : bc_t
48 use precon, only : pc_t, precon_factory
49 use mesh, only : mesh_t
52 use registry, only : neko_registry
55 use json_module, only : json_file
66 use time_state, only : time_state_t
68 use scalar_ic, only : set_scalar_ic
70 implicit none
71
73 type, abstract :: scalar_scheme_t
75 character(len=:), allocatable :: name
77 type(field_t), pointer :: u
79 type(field_t), pointer :: v
81 type(field_t), pointer :: w
83 type(field_t), pointer :: s
85 type(field_series_t) :: slag
87 type(space_t), pointer :: xh
89 type(dofmap_t), pointer :: dm_xh
91 type(gs_t), pointer :: gs_xh
93 type(coef_t), pointer :: c_xh
95 type(field_t), pointer :: f_xh => null()
99 class(ksp_t), allocatable :: ksp
101 integer :: ksp_maxiter
103 integer :: projection_dim
104
105 integer :: projection_activ_step
107 class(pc_t), allocatable :: pc
109 type(bc_list_t) :: bcs
111 type(json_file), pointer :: params => null()
113 type(mesh_t), pointer :: msh => null()
115 type(chkp_t), pointer :: chkp => null()
117 character(len=:), allocatable :: nut_field_name
119 character(len=:), allocatable :: alphat_field_name
121 type(field_t), pointer :: rho => null()
123 type(field_t), pointer :: lambda => null()
125 type(field_t), pointer :: cp => null()
127 type(field_t), pointer :: lambda_tot => null()
129 real(kind=rp) :: pr_turb
131 type(field_list_t) :: material_properties
132 procedure(user_material_properties_intf), nopass, pointer :: &
133 user_material_properties => null()
135 logical :: freeze = .false.
137 logical :: svv_enabled = .false.
139 type(svv_t), allocatable :: svv
140 contains
142 procedure, pass(this) :: scheme_init => scalar_scheme_init
144 procedure, pass(this) :: scheme_free => scalar_scheme_free
146 procedure, pass(this) :: validate => scalar_scheme_validate
148 procedure, pass(this) :: set_initial_condition => &
151 procedure, pass(this) :: register_checkpoint => &
154 procedure, pass(this) :: set_material_properties => &
157 procedure, pass(this) :: update_material_properties => &
160 procedure(scalar_scheme_init_intrf), pass(this), deferred :: init
162 procedure(scalar_scheme_free_intrf), pass(this), deferred :: free
164 procedure(scalar_scheme_step_intrf), pass(this), deferred :: step
166 procedure(scalar_scheme_restart_intrf), pass(this), deferred :: restart
167 end type scalar_scheme_t
168
170 abstract interface
171 subroutine scalar_scheme_init_intrf(this, msh, coef, gs, params, &
172 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
173 import scalar_scheme_t
174 import json_file
175 import coef_t
176 import gs_t
177 import mesh_t
178 import user_t
179 import field_series_t, field_t
181 import rp
182 import chkp_t
183 class(scalar_scheme_t), target, intent(inout) :: this
184 type(mesh_t), target, intent(in) :: msh
185 type(coef_t), target, intent(in) :: coef
186 type(gs_t), target, intent(inout) :: gs
187 type(json_file), target, intent(inout) :: params
188 type(json_file), target, intent(inout) :: numerics_params
189 type(user_t), target, intent(in) :: user
190 type(chkp_t), target, intent(inout) :: chkp
191 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
192 type(time_scheme_controller_t), target, intent(in) :: time_scheme
193 type(field_t), target, intent(in) :: rho
194 end subroutine scalar_scheme_init_intrf
195 end interface
196
198 abstract interface
199 subroutine scalar_scheme_restart_intrf(this, chkp)
200 import scalar_scheme_t
201 import chkp_t
202 import rp
203 class(scalar_scheme_t), target, intent(inout) :: this
204 type(chkp_t), intent(inout) :: chkp
205 end subroutine scalar_scheme_restart_intrf
206 end interface
207
209 abstract interface
211 import scalar_scheme_t
212 class(scalar_scheme_t), intent(inout) :: this
213 end subroutine scalar_scheme_free_intrf
214 end interface
215
217 abstract interface
218 subroutine scalar_scheme_step_intrf(this, time, ext_bdf, dt_controller, &
219 ksp_results)
220 import scalar_scheme_t
221 import time_state_t
224 import ksp_monitor_t
225 class(scalar_scheme_t), intent(inout) :: this
226 type(time_state_t), intent(in) :: time
227 type(time_scheme_controller_t), intent(in) :: ext_bdf
228 type(time_step_controller_t), intent(in) :: dt_controller
229 type(ksp_monitor_t), intent(inout) :: ksp_results
230 end subroutine scalar_scheme_step_intrf
231 end interface
232
233 ! ========================================================================== !
234 ! Helper functions and types for scalar_scheme_t
235 ! ========================================================================== !
236
239 class(scalar_scheme_t), allocatable :: scalar
240 contains
242 procedure, pass(this) :: init => scalar_scheme_wrapper_init
244 procedure, pass(this) :: free => scalar_scheme_wrapper_free
247 procedure, pass(this) :: move_from => &
250 procedure, pass(this) :: is_allocated => &
253
254
255 interface
256
269 module subroutine scalar_scheme_factory(object, msh, coef, gs, params, &
270 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
271 class(scalar_scheme_t), allocatable, intent(inout) :: object
272 type(mesh_t), target, intent(in) :: msh
273 type(coef_t), target, intent(in) :: coef
274 type(gs_t), target, intent(inout) :: gs
275 type(json_file), target, intent(inout) :: params
276 type(json_file), target, intent(inout) :: numerics_params
277 type(user_t), target, intent(in) :: user
278 type(chkp_t), target, intent(inout) :: chkp
279 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
280 type(time_scheme_controller_t), target, intent(in) :: time_scheme
281 type(field_t), target, intent(in) :: rho
282 end subroutine scalar_scheme_factory
283 end interface
284
285 interface
286
289 module subroutine scalar_scheme_allocator(object, type_name)
290 class(scalar_scheme_t), allocatable, intent(inout) :: object
291 character(len=*), intent(in):: type_name
292 end subroutine scalar_scheme_allocator
293 end interface
294
295 !
296 ! Machinery for injecting user-defined types
297 !
298
302 abstract interface
303 subroutine scalar_scheme_allocate(obj)
304 import scalar_scheme_t
305 class(scalar_scheme_t), allocatable, intent(inout) :: obj
306 end subroutine scalar_scheme_allocate
307 end interface
308
309 interface
310
311 module subroutine register_scalar_scheme(type_name, allocator)
312 character(len=*), intent(in) :: type_name
313 procedure(scalar_scheme_allocate), pointer, intent(in) :: allocator
314 end subroutine register_scalar_scheme
315 end interface
316
317 ! A name-allocator pair for user-defined types. A helper type to define a
318 ! registry of custom allocators.
319 type scalar_scheme_allocator_entry
320 character(len=NEKO_TYPENAME_LEN) :: type_name
321 procedure(scalar_scheme_allocate), pointer, nopass :: allocator
322 end type scalar_scheme_allocator_entry
323
325 type(scalar_scheme_allocator_entry), allocatable, private :: &
326 scalar_scheme_registry(:)
327
329 integer, private :: scalar_scheme_registry_size = 0
330
331contains
332
341 subroutine scalar_scheme_init(this, msh, c_Xh, gs_Xh, params, scheme, user, &
342 rho)
343 class(scalar_scheme_t), target, intent(inout) :: this
344 type(mesh_t), target, intent(in) :: msh
345 type(coef_t), target, intent(in) :: c_Xh
346 type(gs_t), target, intent(inout) :: gs_Xh
347 type(json_file), target, intent(inout) :: params
348 character(len=*), intent(in) :: scheme
349 type(user_t), target, intent(in) :: user
350 type(field_t), target, intent(in) :: rho
351 ! IO buffer for log output
352 character(len=LOG_SIZE) :: log_buf
353 ! Variables for retrieving json parameters
354 real(kind=rp) :: real_val, solver_abstol
355 integer :: ierr
356 character(len=:), allocatable :: solver_type, solver_precon
357 type(json_file) :: precon_params
358 type(json_file) :: json_subdict, solver_params
359 logical :: nut_dependency
360
361 this%u => neko_registry%get_field('u')
362 this%v => neko_registry%get_field('v')
363 this%w => neko_registry%get_field('w')
364 this%rho => rho
365
366 ! Assign a name
367 ! Note that the keyword is added by `scalars_t`, so there is always a
368 ! default.
369 call json_get(params, 'name', this%name)
370
371 ! Set the freeze flag
372 call json_get_or_default(params, 'freeze', this%freeze, .false.)
373
374 call neko_log%section('Scalar')
375 call json_get(params, 'solver.type', solver_type)
376 call json_get(params, 'solver.preconditioner.type', &
377 solver_precon)
378 call json_get(params, 'solver.preconditioner', precon_params)
379 call json_get_or_lookup(params, 'solver.absolute_tolerance', &
380 solver_abstol)
381
382 call json_get_or_lookup_or_default(params, &
383 'solver.projection_space_size', &
384 this%projection_dim, 0)
385 call json_get_or_lookup_or_default(params, &
386 'solver.projection_hold_steps', &
387 this%projection_activ_step, 5)
388
389
390 write(log_buf, '(A, A)') 'Type : ', trim(scheme)
391 call neko_log%message(log_buf)
392 write(log_buf, '(A, A)') 'Name : ', trim(this%name)
393 call neko_log%message(log_buf)
394 call neko_log%message('Ksp scalar : ('// trim(solver_type) // &
395 ', ' // trim(solver_precon) // ')')
396 write(log_buf, '(A,ES13.6)') ' `-abs tol :', solver_abstol
397 call neko_log%message(log_buf)
398
399 this%Xh => this%u%Xh
400 this%dm_Xh => this%u%dof
401 if (associated(this%params)) then
402 deallocate(this%params)
403 end if
404 allocate(this%params)
405 this%params = params
406 this%msh => msh
407
408 call neko_registry%add_field(this%dm_Xh, this%name, &
409 ignore_existing = .true.)
410
411 this%s => neko_registry%get_field(this%name)
412
413 call this%slag%init(this%s, 2)
414
415 this%gs_Xh => gs_xh
416 this%c_Xh => c_xh
417
418 !
419 ! Material properties
420 !
421 call this%set_material_properties(params, user)
422
423 !
424 ! Spectral vanishing viscosity
425 !
426 if (params%valid_path('svv')) then
427 call json_get_or_default(params, 'svv.enabled', this%svv_enabled, &
428 .false.)
429 if (this%svv_enabled) then
430 allocate(this%svv)
431 call this%svv%init(params, this%c_Xh, this%rho)
432 end if
433 end if
434
435
436 !
437 ! Turbulence modelling
438 !
439 this%alphat_field_name = ""
440 this%nut_field_name = ""
441 if (params%valid_path('alphat')) then
442 call json_get(this%params, 'alphat', json_subdict)
443 call json_get(json_subdict, 'nut_dependency', nut_dependency)
444 if (nut_dependency) then
445 call json_get_or_lookup(json_subdict, 'Pr_t', this%pr_turb)
446 call json_get(json_subdict, 'nut_field', this%nut_field_name)
447 else
448 call json_get(json_subdict, 'alphat_field', this%alphat_field_name)
449 end if
450 end if
451
452 !
453 ! Setup right-hand side field.
454 !
455 allocate(this%f_Xh)
456 call this%f_Xh%init(this%dm_Xh, fld_name = "scalar_rhs")
457
458 ! Initialize the source term
459 call this%source_term%init(this%f_Xh, this%c_Xh, user, this%name)
460 call this%source_term%add(params, 'source_terms')
461
462 call json_get(params, 'solver', solver_params)
463 call scalar_scheme_solver_factory(this%ksp, this%dm_Xh%size(), &
464 solver_params)
465 call scalar_scheme_precon_factory(this%pc, this%ksp, &
466 this%c_Xh, this%bcs, &
467 solver_precon, precon_params)
468
469 call neko_log%end_section()
470
471 end subroutine scalar_scheme_init
472
476 subroutine scalar_scheme_set_initial_condition(this, user, scalar_index)
477 class(scalar_scheme_t), intent(inout) :: this
478 type(user_t), intent(in) :: user
479 integer, intent(in) :: scalar_index
480 character(len=:), allocatable :: ic_type
481 type(json_file) :: ic_params
482
483 call json_get(this%params, 'initial_condition.type', ic_type)
484 call json_get(this%params, 'initial_condition', ic_params)
485
486 if (trim(ic_type) .ne. 'user') then
487 call set_scalar_ic(this%s, this%c_Xh, this%gs_Xh, ic_type, &
488 ic_params, scalar_index)
489 else
490 call set_scalar_ic(this%name, this%s, this%c_Xh, this%gs_Xh, &
491 user%initial_conditions)
492 end if
493
494 call ic_params%destroy()
495 deallocate(ic_type)
496
497 end subroutine scalar_scheme_set_initial_condition
498
501 subroutine scalar_scheme_register_checkpoint(this, chkp)
502 class(scalar_scheme_t), target, intent(inout) :: this
503 type(chkp_t), intent(inout) :: chkp
504 type(checkpoint_payload_t), pointer :: payload
505
506 payload => chkp%add_payload("scalars/" // trim(this%name))
507 call payload%add_field(this%s)
508 call payload%add_series(this%slag)
509
510 end subroutine scalar_scheme_register_checkpoint
511
512
514 subroutine scalar_scheme_free(this)
515 class(scalar_scheme_t), intent(inout) :: this
516 class(bc_t), pointer :: bc
517 integer :: i
518
519 bc => null()
520
521 if (allocated(this%svv)) then
522 call this%svv%free()
523 deallocate(this%svv)
524 end if
525 this%svv_enabled = .false.
526
527 nullify(this%Xh)
528 nullify(this%dm_Xh)
529 nullify(this%gs_Xh)
530 nullify(this%c_Xh)
531 if (associated(this%params)) then
532 deallocate(this%params)
533 nullify(this%params)
534 end if
535
536 if (allocated(this%ksp)) then
537 call this%ksp%free()
538 deallocate(this%ksp)
539 end if
540
541 if (allocated(this%pc)) then
542 call this%pc%free()
543 deallocate(this%pc)
544 end if
545
546 if (allocated(this%name)) then
547 deallocate(this%name)
548 end if
549
550 call this%source_term%free()
551
552 if (associated(this%f_Xh)) then
553 call this%f_Xh%free()
554 deallocate(this%f_Xh)
555 end if
556
557 do i = 1, this%bcs%size()
558 bc => this%bcs%get(i)
559 if (associated(bc)) then
560 call bc%free()
561 deallocate(bc)
562 end if
563 end do
564
565 call this%bcs%free()
566 call this%slag%free()
567 call this%material_properties%free()
568
569 if (allocated(this%nut_field_name)) then
570 deallocate(this%nut_field_name)
571 end if
572
573 if (allocated(this%alphat_field_name)) then
574 deallocate(this%alphat_field_name)
575 end if
576
577 nullify(this%cp)
578 nullify(this%lambda)
579 nullify(this%lambda_tot)
580 nullify(bc)
581
582 end subroutine scalar_scheme_free
583
586 subroutine scalar_scheme_validate(this)
587 class(scalar_scheme_t), target, intent(inout) :: this
588
589 if ( (.not. allocated(this%u%x)) .or. &
590 (.not. allocated(this%v%x)) .or. &
591 (.not. allocated(this%w%x)) .or. &
592 (.not. allocated(this%s%x))) then
593 call neko_error('Fields are not allocated')
594 end if
595
596 if (.not. allocated(this%ksp)) then
597 call neko_error('No Krylov solver for velocity defined')
598 end if
599
600 if (.not. associated(this%Xh)) then
601 call neko_error('No function space defined')
602 end if
603
604 if (.not. associated(this%dm_Xh)) then
605 call neko_error('No dofmap defined')
606 end if
607
608 if (.not. associated(this%c_Xh)) then
609 call neko_error('No coefficients defined')
610 end if
611
612 if (.not. associated(this%f_Xh)) then
613 call neko_error('No rhs allocated')
614 end if
615
616 if (.not. associated(this%params)) then
617 call neko_error('No parameters defined')
618 end if
619
620 if (.not. associated(this%rho)) then
621 call neko_error('No density field defined')
622 end if
623
624 end subroutine scalar_scheme_validate
625
628 subroutine scalar_scheme_solver_factory(ksp, n, params)
629 class(ksp_t), allocatable, target, intent(inout) :: ksp
630 integer, intent(in), value :: n
631 type(json_file), intent(inout) :: params
632
633 call krylov_solver_factory(ksp, n, params)
634
635 end subroutine scalar_scheme_solver_factory
636
638 subroutine scalar_scheme_precon_factory(pc, ksp, coef, bclst, &
639 pctype, json)
640 class(pc_t), allocatable, target, intent(inout) :: pc
641 class(ksp_t), target, intent(inout) :: ksp
642 type(coef_t), target, intent(in) :: coef
643 type(bc_list_t), target, intent(inout) :: bclst
644 character(len=*) :: pctype
645 type(json_file), intent(inout) :: json
646
647 call precon_factory(pc, pctype, coef, bclst, json)
648
649 call ksp%set_pc(pc)
650
651 end subroutine scalar_scheme_precon_factory
652
657 subroutine scalar_scheme_update_material_properties(this, time)
658 class(scalar_scheme_t), intent(inout) :: this
659 type(time_state_t), intent(in) :: time
660 type(field_t), pointer :: nut, alphat
661 integer :: index
662 ! Factor to transform nu_t to lambda_t
663 type(field_t), pointer :: lambda_factor
664
665 call this%user_material_properties(this%name, this%material_properties, &
666 time)
667
668 ! factor = rho * cp / pr_turb
669 if (len_trim(this%nut_field_name) .gt. 0 &
670 .and. len_trim(this%alphat_field_name) .eq. 0 ) then
671 nut => neko_registry%get_field(this%nut_field_name)
672
673 ! lambda_tot = lambda + rho * cp * nut / pr_turb
674 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
675 call field_cmult2(lambda_factor, nut, 1.0_rp / this%pr_turb)
676 call field_col2(lambda_factor, this%cp)
677 call field_col2(lambda_factor, this%rho)
678 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
679 call neko_scratch_registry%relinquish_field(index)
680
681 else if (len_trim(this%alphat_field_name) .gt. 0 &
682 .and. len_trim(this%nut_field_name) .eq. 0 ) then
683 alphat => neko_registry%get_field(this%alphat_field_name)
684
685 ! lambda_tot = lambda + rho * cp * alphat
686 call neko_scratch_registry%request_field(lambda_factor, index, .false.)
687 call field_col3(lambda_factor, this%cp, alphat)
688 call field_col2(lambda_factor, this%rho)
689 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
690 call neko_scratch_registry%relinquish_field(index)
691
692 else if (len_trim(this%alphat_field_name) .gt. 0 &
693 .and. len_trim(this%nut_field_name) .gt. 0 ) then
694 call neko_error("Conflicting definition of eddy diffusivity " // &
695 "for the scalar equation")
696 end if
697
698 ! Since cp is a fields and we use the %x(1,1,1,1) of the
699 ! host array data to pass constant material properties
700 ! to some routines, we need to make sure that the host
701 ! values are also filled
702 if (neko_bcknd_device .eq. 1) then
703 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
704 device_to_host, sync = .false.)
705 end if
706
707 end subroutine scalar_scheme_update_material_properties
708
712 subroutine scalar_scheme_set_material_properties(this, params, user)
713 class(scalar_scheme_t), intent(inout) :: this
714 type(json_file), intent(inout) :: params
715 type(user_t), target, intent(in) :: user
716 character(len=LOG_SIZE) :: log_buf
717 ! A local pointer that is needed to make Intel happy
718 procedure(user_material_properties_intf), pointer :: dummy_mp_ptr
719 real(kind=rp) :: const_cp, const_lambda
720 ! Dummy time state set to 0
721 type(time_state_t) :: time
722
723 dummy_mp_ptr => dummy_user_material_properties
724
725 ! Fill lambda field with the physical value
726
727 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda")
728 call neko_registry%add_field(this%dm_Xh, this%name // "_lambda_tot")
729 call neko_registry%add_field(this%dm_Xh, this%name // "_cp")
730 this%lambda => neko_registry%get_field(this%name // "_lambda")
731 this%lambda_tot => neko_registry%get_field(this%name // "_lambda_tot")
732 this%cp => neko_registry%get_field(this%name // "_cp")
733
734 call this%material_properties%init(2)
735 call this%material_properties%assign(1, this%cp)
736 call this%material_properties%assign(2, this%lambda)
737
738 if (.not. associated(user%material_properties, dummy_mp_ptr)) then
739
740 write(log_buf, '(A)') "Material properties must be set in the user " // &
741 "file!"
742 call neko_log%message(log_buf)
743 this%user_material_properties => user%material_properties
744
745 call user%material_properties(this%name, this%material_properties, time)
746 else
747 this%user_material_properties => dummy_user_material_properties
748 if (params%valid_path('Pe') .and. &
749 (params%valid_path('lambda') .or. &
750 params%valid_path('cp'))) then
751 call neko_error("To set the material properties for the scalar, " // &
752 "either provide Pe OR lambda and cp in the case file.")
753 ! Non-dimensional case
754 else if (params%valid_path('Pe')) then
755 write(log_buf, '(A)') 'Non-dimensional scalar material properties' //&
756 ' input.'
757 call neko_log%message(log_buf, lvl = neko_log_verbose)
758 write(log_buf, '(A)') 'Specific heat capacity will be set to 1, '
759 call neko_log%message(log_buf, lvl = neko_log_verbose)
760 write(log_buf, '(A)') 'conductivity to 1/Pe. Assumes density is 1.'
761 call neko_log%message(log_buf, lvl = neko_log_verbose)
762
763 ! Read Pe into lambda for further manipulation.
764 call json_get_or_lookup(params, 'Pe', const_lambda)
765 write(log_buf, '(A,ES13.6)') 'Pe :', const_lambda
766 call neko_log%message(log_buf)
767
768 ! Set cp and rho to 1 since the setup is non-dimensional.
769 const_cp = 1.0_rp
770 ! Invert the Pe to get conductivity
771 const_lambda = 1.0_rp/const_lambda
772 ! Dimensional case
773 else
774 call json_get_or_lookup(params, 'lambda', const_lambda)
775 call json_get_or_lookup(params, 'cp', const_cp)
776 end if
777 end if
778 ! We need to fill the fields based on the parsed const values
779 ! if the user routine is not used.
780 if (associated(user%material_properties, dummy_mp_ptr)) then
781 ! Fill mu and rho field with the physical value
782 call field_cfill(this%lambda, const_lambda)
783 call field_cfill(this%cp, const_cp)
784
785 write(log_buf, '(A,ES13.6)') 'lambda :', const_lambda
786 call neko_log%message(log_buf)
787 write(log_buf, '(A,ES13.6)') 'cp :', const_cp
788 call neko_log%message(log_buf)
789 end if
790
791 ! Copy over material property to the total one
792 call field_copy(this%lambda_tot, this%lambda)
793
794 ! Since cp is a field and we use the %x(1,1,1,1) of the
795 ! host array data to pass constant material properties
796 ! to some routines, we need to make sure that the host
797 ! values are also filled
798 if (neko_bcknd_device .eq. 1) then
799 call device_memcpy(this%cp%x, this%cp%x_d, this%cp%size(), &
800 device_to_host, sync = .false.)
801 end if
802 end subroutine scalar_scheme_set_material_properties
803
804 ! ========================================================================== !
805 ! Scalar scheme wrapper type methods
806
808 subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, &
809 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
810 class(scalar_scheme_wrapper_t), intent(inout) :: this
811 type(mesh_t), target, intent(in) :: msh
812 type(coef_t), target, intent(in) :: coef
813 type(gs_t), target, intent(inout) :: gs
814 type(json_file), target, intent(inout) :: params
815 type(json_file), target, intent(inout) :: numerics_params
816 type(user_t), target, intent(in) :: user
817 type(chkp_t), target, intent(inout) :: chkp
818 type(field_series_t), target, intent(in) :: ulag, vlag, wlag
819 type(time_scheme_controller_t), target, intent(in) :: time_scheme
820 type(field_t), target, intent(in) :: rho
821
822 call this%free()
823 call scalar_scheme_factory(this%scalar, msh, coef, gs, params, &
824 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
825
826 end subroutine scalar_scheme_wrapper_init
827
829 subroutine scalar_scheme_wrapper_free(this)
830 class(scalar_scheme_wrapper_t), intent(inout) :: this
831
832 if (allocated(this%scalar)) then
833 call this%scalar%free()
834 deallocate(this%scalar)
835 end if
836
837 end subroutine scalar_scheme_wrapper_free
838
843 subroutine scalar_scheme_wrapper_move_from(this, other)
844 class(scalar_scheme_wrapper_t), intent(inout) :: this
845 class(scalar_scheme_wrapper_t), intent(inout) :: other
846
847 ! Move the pointer
848 call move_alloc(other%scalar, this%scalar)
849
850 end subroutine scalar_scheme_wrapper_move_from
851
854 function scalar_scheme_wrapper_is_allocated(this) result(is_alloc)
855 class(scalar_scheme_wrapper_t), intent(in) :: this
856 logical :: is_alloc
857 is_alloc = allocated(this%scalar)
858 end function scalar_scheme_wrapper_is_allocated
859
860end 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.
Factory for Krylov solvers. Both creates and initializes the object, either from its parameters or fr...
Definition krylov.f90:221
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
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.
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_verbose
Verbose.
Definition log.f90:54
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
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.
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
integer, parameter, public neko_typename_len
Definition utils.f90:44
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: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 ...
Gather-scatter kernel.
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:60
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:77
Defines a canonical Krylov preconditioner.
Definition precon.f90:44
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.
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...