54 use precon,
only :
pc_t, precon_factory, precon_destroy
64 use json_module,
only : json_file
80 class(
ksp_t),
allocatable :: ksp_vel
81 class(
ksp_t),
allocatable :: ksp_prs
82 class(
pc_t),
allocatable :: pc_vel
83 class(
pc_t),
allocatable :: pc_prs
84 integer :: vel_projection_dim
85 integer :: pr_projection_dim
86 integer :: vel_projection_activ_step
87 integer :: pr_projection_activ_step
88 logical :: strict_convergence
97 logical :: forced_flow_rate = .false.
100 character(len=:),
allocatable :: nut_field_name
106 integer(kind=i8) :: glb_n_points
108 integer(kind=i8) :: glb_unique_points
123 procedure, pass(this) :: set_material_properties => &
137 module subroutine fluid_scheme_factory(object, type_name)
139 character(len=*) :: type_name
140 end subroutine fluid_scheme_factory
143 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
148 subroutine fluid_scheme_init_base(this, msh, lx, params, scheme, user, &
151 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
152 type(
mesh_t),
target,
intent(inout) :: msh
153 integer,
intent(in) :: lx
154 character(len=*),
intent(in) :: scheme
155 type(json_file),
target,
intent(inout) :: params
156 type(
user_t),
target,
intent(in) :: user
157 logical,
intent(in) :: kspv_init
159 character(len=LOG_SIZE) :: log_buf
160 real(kind=
rp),
allocatable :: real_vec(:)
161 real(kind=
rp) :: real_val, kappa, b, z0
162 logical :: logical_val
163 integer :: integer_val, ierr
164 type(json_file) :: wm_json
165 character(len=:),
allocatable :: string_val1, string_val2
166 real(kind=
rp) :: gjp_param_a, gjp_param_b
167 type(json_file) :: json_subdict
175 if (msh%gdim .eq. 2)
then
176 call this%Xh%init(
gll, lx, lx)
178 call this%Xh%init(
gll, lx, lx, lx)
181 call this%dm_Xh%init(msh, this%Xh)
183 call this%gs_Xh%init(this%dm_Xh)
185 call this%c_Xh%init(this%gs_Xh)
188 call this%scratch%init(this%dm_Xh, 10, 2)
198 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
200 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
214 call this%set_material_properties(params,
user)
218 'case.fluid.velocity_solver.projection_space_size', &
219 this%vel_projection_dim, 0)
221 'case.fluid.pressure_solver.projection_space_size', &
222 this%pr_projection_dim, 0)
224 'case.fluid.velocity_solver.projection_hold_steps', &
225 this%vel_projection_activ_step, 5)
227 'case.fluid.pressure_solver.projection_hold_steps', &
228 this%pr_projection_activ_step, 5)
233 if (params%valid_path(
"case.fluid.flow_rate_force"))
then
234 this%forced_flow_rate = .true.
239 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
240 else if (lx .ge. 10)
then
241 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
243 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
246 this%glb_n_points = int(this%msh%glb_nelv,
i8)*int(this%Xh%lxyz,
i8)
247 this%glb_unique_points = int(
glsum(this%c_Xh%mult, this%dm_Xh%size()),
i8)
249 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
251 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
255 call json_get(params,
'case.numerics.dealias', logical_val)
256 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
262 write(log_buf,
'(A, L1)')
'Save bdry : ', logical_val
266 logical_val, .false.)
267 write(log_buf,
'(A, L1)')
'Full stress: ', logical_val
277 call this%f_x%init(this%dm_Xh, fld_name =
"fluid_rhs_x")
278 call this%f_y%init(this%dm_Xh, fld_name =
"fluid_rhs_y")
279 call this%f_z%init(this%dm_Xh, fld_name =
"fluid_rhs_z")
283 call neko_log%section(
"Velocity solver")
285 'case.fluid.velocity_solver.max_iterations', &
287 call json_get(params,
'case.fluid.velocity_solver.type', string_val1)
288 call json_get(params,
'case.fluid.velocity_solver.preconditioner.type', &
291 'case.fluid.velocity_solver.preconditioner', json_subdict)
292 call json_get(params,
'case.fluid.velocity_solver.absolute_tolerance', &
295 'case.fluid.velocity_solver.monitor', &
296 logical_val, .false.)
298 call neko_log%message(
'Type : ('// trim(string_val1) // &
299 ', ' // trim(string_val2) //
')')
301 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
303 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
304 string_val1, integer_val, real_val, logical_val)
305 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
306 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs_vel, &
307 string_val2, json_subdict)
313 this%strict_convergence, .false.)
317 call this%ulag%init(this%u, 2)
318 call this%vlag%init(this%v, 2)
319 call this%wlag%init(this%w, 2)
329 call this%source_term%init(this%f_x, this%f_y, this%f_z, this%c_Xh,
user, &
331 call this%source_term%add(params,
'case.fluid.source_terms')
334 end subroutine fluid_scheme_init_base
336 subroutine fluid_scheme_free(this)
337 class(fluid_scheme_incompressible_t),
intent(inout) :: this
341 if (
allocated(this%ksp_vel))
then
342 call this%ksp_vel%free()
343 deallocate(this%ksp_vel)
346 if (
allocated(this%ksp_prs))
then
347 call this%ksp_prs%free()
348 deallocate(this%ksp_prs)
351 if (
allocated(this%pc_vel))
then
352 call precon_destroy(this%pc_vel)
353 deallocate(this%pc_vel)
356 if (
allocated(this%pc_prs))
then
357 call precon_destroy(this%pc_prs)
358 deallocate(this%pc_prs)
361 call this%source_term%free()
363 call this%gs_Xh%free()
365 call this%c_Xh%free()
367 call this%scratch%free()
378 call this%ulag%free()
379 call this%vlag%free()
380 call this%wlag%free()
383 if (
associated(this%f_x))
then
387 if (
associated(this%f_y))
then
391 if (
associated(this%f_z))
then
402 end subroutine fluid_scheme_free
406 subroutine fluid_scheme_validate(this)
407 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
409 logical :: logical_val
411 if ( (.not.
associated(this%u)) .or. &
412 (.not.
associated(this%v)) .or. &
413 (.not.
associated(this%w)) .or. &
414 (.not.
associated(this%p)))
then
418 if ( (.not.
allocated(this%u%x)) .or. &
419 (.not.
allocated(this%v%x)) .or. &
420 (.not.
allocated(this%w%x)) .or. &
421 (.not.
allocated(this%p%x)))
then
425 if (.not.
allocated(this%ksp_vel))
then
426 call neko_error(
'No Krylov solver for velocity defined')
429 if (.not.
allocated(this%ksp_prs))
then
430 call neko_error(
'No Krylov solver for pressure defined')
433 end subroutine fluid_scheme_validate
439 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
440 class(fluid_scheme_incompressible_t),
intent(inout) :: this
442 logical,
intent(in) :: strong
444 class(
bc_t),
pointer :: b
447 call this%bcs_vel%apply_vector(&
448 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
457 call this%bcs_vel%apply_vector(&
458 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
466 do i = 1, this%bcs_vel%size()
467 b => this%bcs_vel%get(i)
472 end subroutine fluid_scheme_bc_apply_vel
476 subroutine fluid_scheme_bc_apply_prs(this, time)
477 class(fluid_scheme_incompressible_t),
intent(inout) :: this
481 class(
bc_t),
pointer :: b
484 call this%bcs_prs%apply(this%p, time)
488 call this%bcs_prs%apply(this%p, time)
492 do i = 1, this%bcs_prs%size()
493 b => this%bcs_prs%get(i)
498 end subroutine fluid_scheme_bc_apply_prs
502 subroutine fluid_scheme_solver_factory(ksp, n, solver, &
503 max_iter, abstol, monitor)
504 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
505 integer,
intent(in),
value :: n
506 character(len=*),
intent(in) :: solver
507 integer,
intent(in) :: max_iter
508 real(kind=
rp),
intent(in) :: abstol
509 logical,
intent(in) :: monitor
511 call krylov_solver_factory(ksp, n, solver, max_iter, abstol, &
514 end subroutine fluid_scheme_solver_factory
517 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, dof, gs, bclst, &
519 class(fluid_scheme_incompressible_t),
intent(inout) :: this
520 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
521 class(
ksp_t),
target,
intent(inout) :: ksp
522 type(
coef_t),
target,
intent(in) :: coef
523 type(
dofmap_t),
target,
intent(in) :: dof
524 type(
gs_t),
target,
intent(inout) :: gs
525 type(
bc_list_t),
target,
intent(inout) :: bclst
526 character(len=*) :: pctype
527 type(json_file),
intent(inout) :: pcparams
529 call precon_factory(pc, pctype)
531 select type (pcp => pc)
533 call pcp%init(coef, dof, gs)
535 call pcp%init(coef, dof, gs)
537 call pcp%init(coef, dof, gs)
539 call pcp%init(coef, bclst, pcparams)
541 call pcp%init(coef, bclst, pcparams)
546 end subroutine fluid_scheme_precon_factory
549 function fluid_compute_cfl(this, dt)
result(c)
550 class(fluid_scheme_incompressible_t),
intent(in) :: this
551 real(kind=
rp),
intent(in) :: dt
554 c =
cfl(dt, this%u%x, this%v%x, this%w%x, &
555 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
557 end function fluid_compute_cfl
564 subroutine fluid_scheme_update_material_properties(this, time)
565 class(fluid_scheme_incompressible_t),
intent(inout) :: this
569 call this%user_material_properties(this%name, this%material_properties, &
572 if (len(trim(this%nut_field_name)) > 0)
then
585 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
588 end subroutine fluid_scheme_update_material_properties
593 subroutine fluid_scheme_set_material_properties(this, params, user)
594 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
595 type(json_file),
intent(inout) :: params
596 type(
user_t),
target,
intent(in) :: user
597 character(len=LOG_SIZE) :: log_buf
600 logical :: nondimensional
601 real(kind=
rp) :: dummy_lambda, dummy_cp
602 real(kind=
rp) :: const_mu, const_rho
615 call this%material_properties%init(2)
616 call this%material_properties%assign(1, this%rho)
617 call this%material_properties%assign(2, this%mu)
619 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
621 write(log_buf,
'(A)')
'Material properties must be set in the user' // &
624 this%user_material_properties =>
user%material_properties
626 call user%material_properties(this%name, this%material_properties, &
632 if (params%valid_path(
'case.fluid.Re') .and. &
633 (params%valid_path(
'case.fluid.mu') .or. &
634 params%valid_path(
'case.fluid.rho')))
then
635 call neko_error(
"To set the material properties for the fluid, " // &
636 "either provide Re OR mu and rho in the case file.")
638 else if (params%valid_path(
'case.fluid.Re'))
then
640 write(log_buf,
'(A)')
'Non-dimensional fluid material properties &
643 write(log_buf,
'(A)')
'Density will be set to 1, dynamic viscosity to&
648 call json_get(params,
'case.fluid.Re', const_mu)
649 write(log_buf,
'(A)')
'Read non-dimensional material properties'
651 write(log_buf,
'(A,ES13.6)')
'Re :', const_mu
657 const_mu = 1.0_rp/const_mu
660 call json_get(params,
'case.fluid.mu', const_mu)
661 call json_get(params,
'case.fluid.rho', const_rho)
667 if (
associated(
user%material_properties, dummy_mp_ptr))
then
674 write(log_buf,
'(A,ES13.6)')
'rho :', const_rho
676 write(log_buf,
'(A,ES13.6)')
'mu :', const_mu
688 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
692 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
695 end subroutine fluid_scheme_set_material_properties
Copy data between host and device (or device and device)
Abstract interface to sets rho and mu.
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 for setting material properties.
Defines a boundary condition.
Jacobi preconditioner accelerator backend.
Device abstraction, common interface for various accelerators.
subroutine, public device_event_sync(event)
Synchronize an event.
integer, parameter, public device_to_host
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Defines a dirichlet boundary condition.
Defines a mapping of the degrees of freedom.
subroutine, public field_cfill(a, c, n)
Set all elements to a constant c .
subroutine, public field_addcol3(a, b, c, n)
Returns .
subroutine, public field_copy(a, b, n)
Copy a vector .
Defines a registry for storing solution fields.
type(field_registry_t), target, public neko_field_registry
Global field registry.
subroutine fluid_scheme_set_material_properties(this, params, user)
Sets rho and mu.
subroutine fluid_scheme_update_material_properties(this, time)
Call user material properties routine and update the values of mu if necessary.
subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, dof, gs, bclst, pctype, pcparams)
Initialize a Krylov preconditioner.
subroutine fluid_scheme_free(this)
subroutine fluid_scheme_validate(this)
Validate that all fields, solvers etc necessary for performing time-stepping are defined.
real(kind=rp) function fluid_compute_cfl(this, dt)
Compute CFL.
subroutine fluid_scheme_bc_apply_vel(this, time, strong)
Apply all boundary conditions defined for velocity Here we perform additional gs operations to take c...
subroutine fluid_scheme_solver_factory(ksp, n, solver, max_iter, abstol, monitor)
Initialize a linear solver.
subroutine fluid_scheme_bc_apply_prs(this, time)
Apply all boundary conditions defined for pressure.
subroutine fluid_scheme_init_base(this, msh, lx, params, scheme, user, kspv_init)
Initialise a fluid scheme.
Implements the fluid_source_term_t type.
Computes various statistics for the fluid fields. We use the Reynolds decomposition for a field u = ...
Utilities for retrieving parameters from the case files.
subroutine, public json_extract_object(json, name, object)
Extract object as a separate JSON dictionary.
Implements the base abstract type for Krylov solvers plus helper types.
integer, parameter, public ksp_max_iter
Maximum number of iters.
integer, parameter, public neko_log_verbose
Verbose log level.
type(log_t), public neko_log
Global log stream.
integer, parameter, public log_size
real(kind=rp) function, public glsum(a, n)
Sum a vector of length n.
Defines a mean flow field.
Defines a mean squared flow field.
integer, parameter neko_bcknd_device
integer, parameter, public i8
integer, parameter, public rp
Global precision used in computations.
real(kind=rp) function, public cfl(dt, u, v, w, xh, coef, nelv, gdim)
Hybrid ph-multigrid preconditioner.
Defines a registry for storing and requesting temporary fields This can be used when you have a funct...
Implements the source_term_t type and a wrapper source_term_wrapper_t.
Defines a function space.
integer, parameter, public gll
Defines a container for all statistics.
Jacobi preconditioner SX-Aurora backend.
Module with things related to the simulation time.
Interfaces for user interaction with NEKO.
subroutine, public dummy_user_material_properties(scheme_name, properties, time)
Base type for a boundary condition.
A list of allocatable `bc_t`. Follows the standard interface of lists.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Defines a jacobi preconditioner.
Generic Dirichlet boundary condition on .
Base type of all fluid formulations.
Base type of all fluid formulations.
Wrapper contaning and executing the fluid source terms.
Defines a jacobi preconditioner.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.
Defines a jacobi preconditioner for SX-Aurora.
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...