55 use json_module,
only : json_file
75 character(len=:),
allocatable :: name
91 type(
gs_t),
pointer :: gs_xh
99 class(
ksp_t),
allocatable :: ksp
101 integer :: ksp_maxiter
103 integer :: projection_dim
105 integer :: projection_activ_step
111 type(json_file),
pointer :: params => null()
117 character(len=:),
allocatable :: nut_field_name
119 character(len=:),
allocatable :: alphat_field_name
127 type(
field_t),
pointer :: lambda_tot => null()
129 real(kind=
rp) :: pr_turb
133 user_material_properties => null()
135 logical :: freeze = .false.
137 logical :: svv_enabled = .false.
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 => &
172 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
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
193 type(
field_t),
target,
intent(in) :: rho
204 type(
chkp_t),
intent(inout) :: chkp
247 procedure, pass(this) :: move_from => &
250 procedure, pass(this) :: is_allocated => &
269 module subroutine scalar_scheme_factory(object, msh, coef, gs, params, &
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
278 type(
chkp_t),
target,
intent(inout) :: chkp
281 type(
field_t),
target,
intent(in) :: rho
282 end subroutine scalar_scheme_factory
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
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
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
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
325 type(scalar_scheme_allocator_entry),
allocatable,
private :: &
326 scalar_scheme_registry(:)
329 integer,
private :: scalar_scheme_registry_size = 0
341 subroutine scalar_scheme_init(this, msh, c_Xh, gs_Xh, params, scheme, user, &
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
352 character(len=LOG_SIZE) :: log_buf
354 real(kind=
rp) :: real_val, solver_abstol
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
369 call json_get(params,
'name', this%name)
375 call json_get(params,
'solver.type', solver_type)
376 call json_get(params,
'solver.preconditioner.type', &
378 call json_get(params,
'solver.preconditioner', precon_params)
383 'solver.projection_space_size', &
384 this%projection_dim, 0)
386 'solver.projection_hold_steps', &
387 this%projection_activ_step, 5)
390 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
392 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
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
400 this%dm_Xh => this%u%dof
401 if (
associated(this%params))
then
402 deallocate(this%params)
404 allocate(this%params)
409 ignore_existing = .true.)
413 call this%slag%init(this%s, 2)
421 call this%set_material_properties(params,
user)
426 if (params%valid_path(
'svv'))
then
429 if (this%svv_enabled)
then
431 call this%svv%init(params, this%c_Xh, this%rho)
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
446 call json_get(json_subdict,
'nut_field', this%nut_field_name)
448 call json_get(json_subdict,
'alphat_field', this%alphat_field_name)
456 call this%f_Xh%init(this%dm_Xh, fld_name =
"scalar_rhs")
459 call this%source_term%init(this%f_Xh, this%c_Xh,
user, this%name)
460 call this%source_term%add(params,
'source_terms')
462 call json_get(params,
'solver', solver_params)
463 call scalar_scheme_solver_factory(this%ksp, this%dm_Xh%size(), &
465 call scalar_scheme_precon_factory(this%pc, this%ksp, &
466 this%c_Xh, this%bcs, &
467 solver_precon, precon_params)
471 end subroutine scalar_scheme_init
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
483 call json_get(this%params,
'initial_condition.type', ic_type)
484 call json_get(this%params,
'initial_condition', ic_params)
486 if (trim(ic_type) .ne.
'user')
then
488 ic_params, scalar_index)
490 call set_scalar_ic(this%name, this%s, this%c_Xh, this%gs_Xh, &
491 user%initial_conditions)
494 call ic_params%destroy()
497 end subroutine scalar_scheme_set_initial_condition
501 subroutine scalar_scheme_register_checkpoint(this, chkp)
502 class(scalar_scheme_t),
target,
intent(inout) :: this
503 type(
chkp_t),
intent(inout) :: chkp
506 payload => chkp%add_payload(
"scalars/" // trim(this%name))
507 call payload%add_field(this%s)
508 call payload%add_series(this%slag)
510 end subroutine scalar_scheme_register_checkpoint
514 subroutine scalar_scheme_free(this)
515 class(scalar_scheme_t),
intent(inout) :: this
516 class(
bc_t),
pointer :: bc
521 if (
allocated(this%svv))
then
525 this%svv_enabled = .false.
531 if (
associated(this%params))
then
532 deallocate(this%params)
536 if (
allocated(this%ksp))
then
541 if (
allocated(this%pc))
then
546 if (
allocated(this%name))
then
547 deallocate(this%name)
550 call this%source_term%free()
552 if (
associated(this%f_Xh))
then
553 call this%f_Xh%free()
554 deallocate(this%f_Xh)
557 do i = 1, this%bcs%size()
558 bc => this%bcs%get(i)
559 if (
associated(
bc))
then
566 call this%slag%free()
567 call this%material_properties%free()
569 if (
allocated(this%nut_field_name))
then
570 deallocate(this%nut_field_name)
573 if (
allocated(this%alphat_field_name))
then
574 deallocate(this%alphat_field_name)
579 nullify(this%lambda_tot)
582 end subroutine scalar_scheme_free
586 subroutine scalar_scheme_validate(this)
587 class(scalar_scheme_t),
target,
intent(inout) :: this
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
596 if (.not.
allocated(this%ksp))
then
597 call neko_error(
'No Krylov solver for velocity defined')
600 if (.not.
associated(this%Xh))
then
604 if (.not.
associated(this%dm_Xh))
then
608 if (.not.
associated(this%c_Xh))
then
612 if (.not.
associated(this%f_Xh))
then
616 if (.not.
associated(this%params))
then
620 if (.not.
associated(this%rho))
then
624 end subroutine scalar_scheme_validate
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
635 end subroutine scalar_scheme_solver_factory
638 subroutine scalar_scheme_precon_factory(pc, ksp, coef, bclst, &
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
647 call precon_factory(pc, pctype, coef, bclst, json)
651 end subroutine scalar_scheme_precon_factory
657 subroutine scalar_scheme_update_material_properties(this, time)
658 class(scalar_scheme_t),
intent(inout) :: this
660 type(
field_t),
pointer :: nut, alphat
663 type(
field_t),
pointer :: lambda_factor
665 call this%user_material_properties(this%name, this%material_properties, &
669 if (len_trim(this%nut_field_name) .gt. 0 &
670 .and. len_trim(this%alphat_field_name) .eq. 0 )
then
675 call field_cmult2(lambda_factor, nut, 1.0_rp / this%pr_turb)
678 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
681 else if (len_trim(this%alphat_field_name) .gt. 0 &
682 .and. len_trim(this%nut_field_name) .eq. 0 )
then
687 call field_col3(lambda_factor, this%cp, alphat)
689 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
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")
707 end subroutine scalar_scheme_update_material_properties
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
719 real(kind=
rp) :: const_cp, const_lambda
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")
730 this%lambda =>
neko_registry%get_field(this%name //
"_lambda")
731 this%lambda_tot =>
neko_registry%get_field(this%name //
"_lambda_tot")
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)
738 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
740 write(log_buf,
'(A)')
"Material properties must be set in the user " // &
743 this%user_material_properties =>
user%material_properties
745 call user%material_properties(this%name, this%material_properties, time)
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.")
754 else if (params%valid_path(
'Pe'))
then
755 write(log_buf,
'(A)')
'Non-dimensional scalar material properties' //&
758 write(log_buf,
'(A)')
'Specific heat capacity will be set to 1, '
760 write(log_buf,
'(A)')
'conductivity to 1/Pe. Assumes density is 1.'
765 write(log_buf,
'(A,ES13.6)')
'Pe :', const_lambda
771 const_lambda = 1.0_rp/const_lambda
780 if (
associated(
user%material_properties, dummy_mp_ptr))
then
785 write(log_buf,
'(A,ES13.6)')
'lambda :', const_lambda
787 write(log_buf,
'(A,ES13.6)')
'cp :', const_cp
802 end subroutine scalar_scheme_set_material_properties
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
820 type(
field_t),
target,
intent(in) :: rho
823 call scalar_scheme_factory(this%scalar, msh, coef, gs, params, &
826 end subroutine scalar_scheme_wrapper_init
829 subroutine scalar_scheme_wrapper_free(this)
830 class(scalar_scheme_wrapper_t),
intent(inout) :: this
832 if (
allocated(this%scalar))
then
833 call this%scalar%free()
834 deallocate(this%scalar)
837 end subroutine scalar_scheme_wrapper_free
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
848 call move_alloc(other%scalar, this%scalar)
850 end subroutine scalar_scheme_wrapper_move_from
854 function scalar_scheme_wrapper_is_allocated(this)
result(is_alloc)
855 class(scalar_scheme_wrapper_t),
intent(in) :: this
857 is_alloc =
allocated(this%scalar)
858 end function scalar_scheme_wrapper_is_allocated
Copy data between host and device (or device and device)
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...
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 boundary condition.
Format-independent checkpoint payloads.
Defines format-independent checkpoint registration and restart state.
Device abstraction, common interface for various accelerators.
integer, parameter, public device_to_host
Defines a mapping of the degrees of freedom.
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.
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
integer, parameter, public neko_log_verbose
Verbose.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Defines a registry for storing solution fields.
type(registry_t), target, public neko_registry
Global field registry.
Scalar initial condition.
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.
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.
subroutine, public dummy_user_material_properties(scheme_name, properties, time)
integer, parameter, public neko_typename_len
Base type for a boundary condition.
A list of allocatable `bc_t`. Follows the standard interface of lists.
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,...
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 ...
Type for storing initial and final residuals in a Krylov solver.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.
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.
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.
Provides a tool to set time step dt.
A type collecting all the overridable user routines and flag to suppress type injection from custom m...