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
115 character(len=:),
allocatable :: nut_field_name
117 character(len=:),
allocatable :: alphat_field_name
125 type(
field_t),
pointer :: lambda_tot => null()
127 real(kind=
rp) :: pr_turb
131 user_material_properties => null()
133 logical :: freeze = .false.
135 logical :: svv_enabled = .false.
146 procedure, pass(this) :: set_initial_condition => &
149 procedure, pass(this) :: register_checkpoint => &
152 procedure, pass(this) :: set_material_properties => &
155 procedure, pass(this) :: update_material_properties => &
170 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
182 type(
mesh_t),
target,
intent(in) :: msh
183 type(
coef_t),
target,
intent(in) :: coef
184 type(
gs_t),
target,
intent(inout) :: gs
185 type(json_file),
target,
intent(inout) :: params
186 type(json_file),
target,
intent(inout) :: numerics_params
187 type(
user_t),
target,
intent(in) :: user
188 type(
chkp_t),
target,
intent(inout) :: chkp
191 type(
field_t),
target,
intent(in) :: rho
202 type(
chkp_t),
intent(inout) :: chkp
245 procedure, pass(this) :: move_from => &
248 procedure, pass(this) :: is_allocated => &
267 module subroutine scalar_scheme_factory(object, msh, coef, gs, params, &
269 class(scalar_scheme_t),
allocatable,
intent(inout) :: object
270 type(
mesh_t),
target,
intent(in) :: msh
271 type(
coef_t),
target,
intent(in) :: coef
272 type(
gs_t),
target,
intent(inout) :: gs
273 type(json_file),
target,
intent(inout) :: params
274 type(json_file),
target,
intent(inout) :: numerics_params
276 type(
chkp_t),
target,
intent(inout) :: chkp
279 type(
field_t),
target,
intent(in) :: rho
280 end subroutine scalar_scheme_factory
287 module subroutine scalar_scheme_allocator(object, type_name)
288 class(scalar_scheme_t),
allocatable,
intent(inout) :: object
289 character(len=*),
intent(in):: type_name
290 end subroutine scalar_scheme_allocator
301 subroutine scalar_scheme_allocate(obj)
302 import scalar_scheme_t
303 class(scalar_scheme_t),
allocatable,
intent(inout) :: obj
304 end subroutine scalar_scheme_allocate
309 module subroutine register_scalar_scheme(type_name, allocator)
310 character(len=*),
intent(in) :: type_name
311 procedure(scalar_scheme_allocate),
pointer,
intent(in) :: allocator
312 end subroutine register_scalar_scheme
317 type scalar_scheme_allocator_entry
318 character(len=NEKO_TYPENAME_LEN) :: type_name
319 procedure(scalar_scheme_allocate),
pointer,
nopass :: allocator
320 end type scalar_scheme_allocator_entry
323 type(scalar_scheme_allocator_entry),
allocatable,
private :: &
324 scalar_scheme_registry(:)
327 integer,
private :: scalar_scheme_registry_size = 0
339 subroutine scalar_scheme_init(this, msh, c_Xh, gs_Xh, params, scheme, user, &
341 class(scalar_scheme_t),
target,
intent(inout) :: this
342 type(
mesh_t),
target,
intent(in) :: msh
343 type(
coef_t),
target,
intent(in) :: c_Xh
344 type(
gs_t),
target,
intent(inout) :: gs_Xh
345 type(json_file),
target,
intent(inout) :: params
346 character(len=*),
intent(in) :: scheme
347 type(
user_t),
target,
intent(in) :: user
348 type(
field_t),
target,
intent(in) :: rho
350 character(len=LOG_SIZE) :: log_buf
352 real(kind=
rp) :: real_val, solver_abstol
354 character(len=:),
allocatable :: solver_type, solver_precon
355 type(json_file) :: precon_params
356 type(json_file) :: json_subdict, solver_params
357 logical :: nut_dependency
367 call json_get(params,
'name', this%name)
373 call json_get(params,
'solver.type', solver_type)
374 call json_get(params,
'solver.preconditioner.type', &
376 call json_get(params,
'solver.preconditioner', precon_params)
381 'solver.projection_space_size', &
382 this%projection_dim, 0)
384 'solver.projection_hold_steps', &
385 this%projection_activ_step, 5)
388 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
390 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
392 call neko_log%message(
'Ksp scalar : ('// trim(solver_type) // &
393 ', ' // trim(solver_precon) //
')')
394 write(log_buf,
'(A,ES13.6)')
' `-abs tol :', solver_abstol
398 this%dm_Xh => this%u%dof
402 ignore_existing = .true.)
406 call this%slag%init(this%s, 2)
414 call this%set_material_properties(params,
user)
419 if (params%valid_path(
'svv'))
then
422 if (this%svv_enabled)
then
424 call this%svv%init(params, this%c_Xh, this%rho)
432 this%alphat_field_name =
""
433 this%nut_field_name =
""
434 if (params%valid_path(
'alphat'))
then
435 call json_get(params,
'alphat', json_subdict)
436 call json_get(json_subdict,
'nut_dependency', nut_dependency)
437 if (nut_dependency)
then
439 call json_get(json_subdict,
'nut_field', this%nut_field_name)
441 call json_get(json_subdict,
'alphat_field', this%alphat_field_name)
449 call this%f_Xh%init(this%dm_Xh, fld_name =
"scalar_rhs")
452 call this%source_term%init(this%f_Xh, this%c_Xh,
user, this%name)
453 call this%source_term%add(params,
'source_terms')
455 call json_get(params,
'solver', solver_params)
456 call scalar_scheme_solver_factory(this%ksp, this%dm_Xh%size(), &
458 call scalar_scheme_precon_factory(this%pc, this%ksp, &
459 this%c_Xh, this%bcs, &
460 solver_precon, precon_params)
464 end subroutine scalar_scheme_init
471 subroutine scalar_scheme_set_initial_condition(this, params, user, &
473 class(scalar_scheme_t),
intent(inout) :: this
474 type(json_file),
intent(inout) :: params
475 type(
user_t),
intent(in) :: user
476 integer,
intent(in) :: scalar_index
477 character(len=:),
allocatable :: ic_type
478 type(json_file) :: ic_params
480 call json_get(params,
'initial_condition.type', ic_type)
481 call json_get(params,
'initial_condition', ic_params)
483 if (trim(ic_type) .ne.
'user')
then
485 ic_params, scalar_index)
487 call set_scalar_ic(this%name, this%s, this%c_Xh, this%gs_Xh, &
488 user%initial_conditions)
491 call ic_params%destroy()
494 end subroutine scalar_scheme_set_initial_condition
498 subroutine scalar_scheme_register_checkpoint(this, chkp)
499 class(scalar_scheme_t),
target,
intent(inout) :: this
500 type(
chkp_t),
intent(inout) :: chkp
503 payload => chkp%add_payload(
"scalars/" // trim(this%name))
504 call payload%add_field(this%s)
505 call payload%add_series(this%slag)
507 end subroutine scalar_scheme_register_checkpoint
511 subroutine scalar_scheme_free(this)
512 class(scalar_scheme_t),
intent(inout) :: this
513 class(
bc_t),
pointer :: bc
518 if (
allocated(this%svv))
then
522 this%svv_enabled = .false.
529 if (
allocated(this%ksp))
then
534 if (
allocated(this%pc))
then
539 if (
allocated(this%name))
then
540 deallocate(this%name)
543 call this%source_term%free()
545 if (
associated(this%f_Xh))
then
546 call this%f_Xh%free()
547 deallocate(this%f_Xh)
550 do i = 1, this%bcs%size()
551 bc => this%bcs%get(i)
552 if (
associated(
bc))
then
559 call this%slag%free()
560 call this%material_properties%free()
562 if (
allocated(this%nut_field_name))
then
563 deallocate(this%nut_field_name)
566 if (
allocated(this%alphat_field_name))
then
567 deallocate(this%alphat_field_name)
572 nullify(this%lambda_tot)
575 end subroutine scalar_scheme_free
579 subroutine scalar_scheme_validate(this)
580 class(scalar_scheme_t),
target,
intent(inout) :: this
582 if ( (.not.
allocated(this%u%x)) .or. &
583 (.not.
allocated(this%v%x)) .or. &
584 (.not.
allocated(this%w%x)) .or. &
585 (.not.
allocated(this%s%x)))
then
589 if (.not.
allocated(this%ksp))
then
590 call neko_error(
'No Krylov solver for velocity defined')
593 if (.not.
associated(this%Xh))
then
597 if (.not.
associated(this%dm_Xh))
then
601 if (.not.
associated(this%c_Xh))
then
605 if (.not.
associated(this%f_Xh))
then
609 if (.not.
associated(this%rho))
then
613 end subroutine scalar_scheme_validate
617 subroutine scalar_scheme_solver_factory(ksp, n, params)
618 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
619 integer,
intent(in),
value :: n
620 type(json_file),
intent(inout) :: params
624 end subroutine scalar_scheme_solver_factory
627 subroutine scalar_scheme_precon_factory(pc, ksp, coef, bclst, &
629 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
630 class(
ksp_t),
target,
intent(inout) :: ksp
631 type(
coef_t),
target,
intent(in) :: coef
632 type(
bc_list_t),
target,
intent(inout) :: bclst
633 character(len=*) :: pctype
634 type(json_file),
intent(inout) :: json
636 call precon_factory(pc, pctype, coef, bclst, json)
640 end subroutine scalar_scheme_precon_factory
646 subroutine scalar_scheme_update_material_properties(this, time)
647 class(scalar_scheme_t),
intent(inout) :: this
649 type(
field_t),
pointer :: nut, alphat
652 type(
field_t),
pointer :: lambda_factor
654 call this%user_material_properties(this%name, this%material_properties, &
658 if (len_trim(this%nut_field_name) .gt. 0 &
659 .and. len_trim(this%alphat_field_name) .eq. 0 )
then
664 call field_cmult2(lambda_factor, nut, 1.0_rp / this%pr_turb)
667 call field_add3(this%lambda_tot, this%lambda, lambda_factor)
670 else if (len_trim(this%alphat_field_name) .gt. 0 &
671 .and. len_trim(this%nut_field_name) .eq. 0 )
then
676 call field_col3(lambda_factor, this%cp, alphat)
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) .gt. 0 )
then
683 call neko_error(
"Conflicting definition of eddy diffusivity " // &
684 "for the scalar equation")
696 end subroutine scalar_scheme_update_material_properties
701 subroutine scalar_scheme_set_material_properties(this, params, user)
702 class(scalar_scheme_t),
intent(inout) :: this
703 type(json_file),
intent(inout) :: params
704 type(
user_t),
target,
intent(in) :: user
705 character(len=LOG_SIZE) :: log_buf
708 real(kind=
rp) :: const_cp, const_lambda
716 call neko_registry%add_field(this%dm_Xh, this%name //
"_lambda")
717 call neko_registry%add_field(this%dm_Xh, this%name //
"_lambda_tot")
719 this%lambda =>
neko_registry%get_field(this%name //
"_lambda")
720 this%lambda_tot =>
neko_registry%get_field(this%name //
"_lambda_tot")
723 call this%material_properties%init(2)
724 call this%material_properties%assign(1, this%cp)
725 call this%material_properties%assign(2, this%lambda)
727 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
729 write(log_buf,
'(A)')
"Material properties must be set in the user " // &
732 this%user_material_properties =>
user%material_properties
734 call user%material_properties(this%name, this%material_properties, time)
737 if (params%valid_path(
'Pe') .and. &
738 (params%valid_path(
'lambda') .or. &
739 params%valid_path(
'cp')))
then
740 call neko_error(
"To set the material properties for the scalar, " // &
741 "either provide Pe OR lambda and cp in the case file.")
743 else if (params%valid_path(
'Pe'))
then
744 write(log_buf,
'(A)')
'Non-dimensional scalar material properties' //&
747 write(log_buf,
'(A)')
'Specific heat capacity will be set to 1, '
749 write(log_buf,
'(A)')
'conductivity to 1/Pe. Assumes density is 1.'
754 write(log_buf,
'(A,ES13.6)')
'Pe :', const_lambda
760 const_lambda = 1.0_rp/const_lambda
769 if (
associated(
user%material_properties, dummy_mp_ptr))
then
774 write(log_buf,
'(A,ES13.6)')
'lambda :', const_lambda
776 write(log_buf,
'(A,ES13.6)')
'cp :', const_cp
791 end subroutine scalar_scheme_set_material_properties
797 subroutine scalar_scheme_wrapper_init(this, msh, coef, gs, params, &
798 numerics_params, user, chkp, ulag, vlag, wlag, time_scheme, rho)
799 class(scalar_scheme_wrapper_t),
intent(inout) :: this
800 type(
mesh_t),
target,
intent(in) :: msh
801 type(
coef_t),
target,
intent(in) :: coef
802 type(
gs_t),
target,
intent(inout) :: gs
803 type(json_file),
target,
intent(inout) :: params
804 type(json_file),
target,
intent(inout) :: numerics_params
805 type(
user_t),
target,
intent(in) :: user
806 type(
chkp_t),
target,
intent(inout) :: chkp
809 type(
field_t),
target,
intent(in) :: rho
812 call scalar_scheme_factory(this%scalar, msh, coef, gs, params, &
815 end subroutine scalar_scheme_wrapper_init
818 subroutine scalar_scheme_wrapper_free(this)
819 class(scalar_scheme_wrapper_t),
intent(inout) :: this
821 if (
allocated(this%scalar))
then
822 call this%scalar%free()
823 deallocate(this%scalar)
826 end subroutine scalar_scheme_wrapper_free
832 subroutine scalar_scheme_wrapper_move_from(this, other)
833 class(scalar_scheme_wrapper_t),
intent(inout) :: this
834 class(scalar_scheme_wrapper_t),
intent(inout) :: other
837 call move_alloc(other%scalar, this%scalar)
839 end subroutine scalar_scheme_wrapper_move_from
843 function scalar_scheme_wrapper_is_allocated(this)
result(is_alloc)
844 class(scalar_scheme_wrapper_t),
intent(in) :: this
846 is_alloc =
allocated(this%scalar)
847 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, params, 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...