52 use precon,
only :
pc_t, precon_factory, precon_destroy
63 use json_module,
only : json_file
79 class(
ksp_t),
allocatable :: ksp_vel
80 class(
ksp_t),
allocatable :: ksp_prs
81 class(
pc_t),
allocatable :: pc_vel
82 class(
pc_t),
allocatable :: pc_prs
83 integer :: vel_projection_dim
84 integer :: pr_projection_dim
85 integer :: vel_projection_activ_step
86 integer :: pr_projection_activ_step
87 logical :: strict_convergence
88 logical :: allow_stabilization
95 logical :: forced_flow_rate = .false.
98 character(len=:),
allocatable :: nut_field_name
104 integer(kind=i8) :: glb_n_points
106 integer(kind=i8) :: glb_unique_points
120 procedure, pass(this) :: set_material_properties => &
134 module subroutine fluid_scheme_factory(object, type_name)
136 character(len=*) :: type_name
137 end subroutine fluid_scheme_factory
140 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
145 subroutine fluid_scheme_init_base(this, msh, lx, params, scheme, user, &
148 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
149 type(
mesh_t),
target,
intent(inout) :: msh
150 integer,
intent(in) :: lx
151 character(len=*),
intent(in) :: scheme
152 type(json_file),
target,
intent(inout) :: params
153 type(
user_t),
target,
intent(in) :: user
154 logical,
intent(in) :: kspv_init
156 character(len=LOG_SIZE) :: log_buf
157 real(kind=
rp),
allocatable :: real_vec(:)
158 real(kind=
rp) :: real_val, kappa, b, z0
159 logical :: logical_val
160 integer :: integer_val, ierr
161 type(json_file) :: wm_json
162 character(len=:),
allocatable :: string_val1, string_val2
163 type(json_file) :: json_subdict
171 if (msh%gdim .eq. 2)
then
172 call this%Xh%init(
gll, lx, lx)
174 call this%Xh%init(
gll, lx, lx, lx)
177 call this%dm_Xh%init(msh, this%Xh)
179 call this%gs_Xh%init(this%dm_Xh)
181 call this%c_Xh%init(this%gs_Xh)
194 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
196 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
210 call this%set_material_properties(params,
user)
214 'case.fluid.velocity_solver.projection_space_size', &
215 this%vel_projection_dim, 0)
217 'case.fluid.pressure_solver.projection_space_size', &
218 this%pr_projection_dim, 0)
220 'case.fluid.velocity_solver.projection_hold_steps', &
221 this%vel_projection_activ_step, 5)
223 'case.fluid.pressure_solver.projection_hold_steps', &
224 this%pr_projection_activ_step, 5)
229 if (params%valid_path(
"case.fluid.flow_rate_force"))
then
230 this%forced_flow_rate = .true.
235 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
236 else if (lx .ge. 10)
then
237 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
239 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
242 this%glb_n_points = int(this%msh%glb_nelv,
i8)*int(this%Xh%lxyz,
i8)
243 this%glb_unique_points = int(
glsum(this%c_Xh%mult, this%dm_Xh%size()),
i8)
245 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
247 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
251 call json_get(params,
'case.numerics.dealias', logical_val)
252 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
258 write(log_buf,
'(A, L1)')
'Save bdry : ', logical_val
262 logical_val, .false.)
263 write(log_buf,
'(A, L1)')
'Full stress: ', logical_val
273 call this%f_x%init(this%dm_Xh, fld_name =
"fluid_rhs_x")
274 call this%f_y%init(this%dm_Xh, fld_name =
"fluid_rhs_y")
275 call this%f_z%init(this%dm_Xh, fld_name =
"fluid_rhs_z")
279 call neko_log%section(
"Velocity solver")
281 'case.fluid.velocity_solver.max_iterations', &
283 call json_get(params,
'case.fluid.velocity_solver.type', string_val1)
284 call json_get(params,
'case.fluid.velocity_solver.preconditioner.type', &
287 'case.fluid.velocity_solver.preconditioner', json_subdict)
289 'case.fluid.velocity_solver.absolute_tolerance', &
292 'case.fluid.velocity_solver.monitor', &
293 logical_val, .false.)
295 call neko_log%message(
'Type : ('// trim(string_val1) // &
296 ', ' // trim(string_val2) //
')')
298 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
300 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
301 string_val1, integer_val, real_val, logical_val)
302 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
303 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs_vel, &
304 string_val2, json_subdict)
310 this%strict_convergence, .false.)
313 this%allow_stabilization, .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 neko_log%section(
'Fluid Source term')
330 call this%source_term%init(this%f_x, this%f_y, this%f_z, this%c_Xh,
user, &
332 call this%source_term%add(params,
'case.fluid.source_terms')
335 end subroutine fluid_scheme_init_base
337 subroutine fluid_scheme_free(this)
338 class(fluid_scheme_incompressible_t),
intent(inout) :: this
339 class(
bc_t),
pointer :: bc
345 if (
allocated(this%ksp_vel))
then
346 call this%ksp_vel%free()
347 deallocate(this%ksp_vel)
350 if (
allocated(this%ksp_prs))
then
351 call this%ksp_prs%free()
352 deallocate(this%ksp_prs)
355 if (
allocated(this%pc_vel))
then
356 call precon_destroy(this%pc_vel)
357 deallocate(this%pc_vel)
360 if (
allocated(this%pc_prs))
then
361 call precon_destroy(this%pc_prs)
362 deallocate(this%pc_prs)
365 do i = 1, this%bcs_vel%size()
366 bc => this%bcs_vel%get(i)
369 call this%bcs_vel%free()
371 do i = 1, this%bcs_prs%size()
372 bc => this%bcs_prs%get(i)
375 call this%bcs_prs%free()
377 call this%source_term%free()
379 call this%gs_Xh%free()
381 call this%c_Xh%free()
392 call this%ulag%free()
393 call this%vlag%free()
394 call this%wlag%free()
397 if (
associated(this%f_x))
then
402 if (
associated(this%f_y))
then
407 if (
associated(this%f_z))
then
419 call this%dm_Xh%free()
423 end subroutine fluid_scheme_free
427 subroutine fluid_scheme_validate(this)
428 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
430 logical :: logical_val
432 if ( (.not.
associated(this%u)) .or. &
433 (.not.
associated(this%v)) .or. &
434 (.not.
associated(this%w)) .or. &
435 (.not.
associated(this%p)))
then
439 if ( (.not.
allocated(this%u%x)) .or. &
440 (.not.
allocated(this%v%x)) .or. &
441 (.not.
allocated(this%w%x)) .or. &
442 (.not.
allocated(this%p%x)))
then
446 if (.not.
allocated(this%ksp_vel))
then
447 call neko_error(
'No Krylov solver for velocity defined')
450 if (.not.
allocated(this%ksp_prs))
then
451 call neko_error(
'No Krylov solver for pressure defined')
454 end subroutine fluid_scheme_validate
460 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
461 class(fluid_scheme_incompressible_t),
intent(inout) :: this
463 logical,
intent(in) :: strong
465 class(
bc_t),
pointer :: b
468 call this%bcs_vel%apply_vector(&
469 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
471 call rotate_cyc(this%u%x, this%v%x, this%w%x, 1, this%c_Xh)
478 call rotate_cyc(this%u%x, this%v%x, this%w%x, 0, this%c_Xh)
481 call this%bcs_vel%apply_vector(&
482 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
484 call rotate_cyc(this%u%x, this%v%x, this%w%x, 1, this%c_Xh)
491 call rotate_cyc(this%u%x, this%v%x, this%w%x, 0, this%c_Xh)
493 do i = 1, this%bcs_vel%size()
494 b => this%bcs_vel%get(i)
499 end subroutine fluid_scheme_bc_apply_vel
503 subroutine fluid_scheme_bc_apply_prs(this, time)
504 class(fluid_scheme_incompressible_t),
intent(inout) :: this
508 class(
bc_t),
pointer :: b
511 call this%bcs_prs%apply(this%p, time)
515 call this%bcs_prs%apply(this%p, time)
519 do i = 1, this%bcs_prs%size()
520 b => this%bcs_prs%get(i)
525 end subroutine fluid_scheme_bc_apply_prs
529 subroutine fluid_scheme_solver_factory(ksp, n, solver, &
530 max_iter, abstol, monitor)
531 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
532 integer,
intent(in),
value :: n
533 character(len=*),
intent(in) :: solver
534 integer,
intent(in) :: max_iter
535 real(kind=
rp),
intent(in) :: abstol
536 logical,
intent(in) :: monitor
538 call krylov_solver_factory(ksp, n, solver, max_iter, abstol, &
541 end subroutine fluid_scheme_solver_factory
544 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, dof, gs, bclst, &
546 class(fluid_scheme_incompressible_t),
intent(inout) :: this
547 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
548 class(
ksp_t),
target,
intent(inout) :: ksp
549 type(
coef_t),
target,
intent(in) :: coef
550 type(
dofmap_t),
target,
intent(in) :: dof
551 type(
gs_t),
target,
intent(inout) :: gs
552 type(
bc_list_t),
target,
intent(inout) :: bclst
553 character(len=*) :: pctype
554 type(json_file),
intent(inout) :: pcparams
556 call precon_factory(pc, pctype)
558 select type (pcp => pc)
560 call pcp%init(coef, dof, gs)
562 call pcp%init(coef, dof, gs)
564 call pcp%init(coef, dof, gs)
566 call pcp%init(coef, bclst, pcparams)
568 call pcp%init(coef, bclst, pcparams)
573 end subroutine fluid_scheme_precon_factory
576 function fluid_compute_cfl(this, dt)
result(c)
577 class(fluid_scheme_incompressible_t),
intent(in) :: this
578 real(kind=
rp),
intent(in) :: dt
581 c =
cfl(dt, this%u%x, this%v%x, this%w%x, &
582 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
584 end function fluid_compute_cfl
591 subroutine fluid_scheme_update_material_properties(this, time)
592 class(fluid_scheme_incompressible_t),
intent(inout) :: this
596 call this%user_material_properties(this%name, this%material_properties, &
599 if (len(trim(this%nut_field_name)) > 0)
then
612 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
615 end subroutine fluid_scheme_update_material_properties
620 subroutine fluid_scheme_set_material_properties(this, params, user)
621 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
622 type(json_file),
intent(inout) :: params
623 type(
user_t),
target,
intent(in) :: user
624 character(len=LOG_SIZE) :: log_buf
627 logical :: nondimensional
628 real(kind=
rp) :: dummy_lambda, dummy_cp
629 real(kind=
rp) :: const_mu, const_rho
636 call neko_registry%add_field(this%dm_Xh, this%name //
"_mu_tot")
637 call neko_registry%add_field(this%dm_Xh, this%name //
"_rho")
639 this%mu_tot =>
neko_registry%get_field(this%name //
"_mu_tot")
642 call this%material_properties%init(2)
643 call this%material_properties%assign(1, this%rho)
644 call this%material_properties%assign(2, this%mu)
646 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
648 write(log_buf,
'(A)')
'Material properties must be set in the user' // &
651 this%user_material_properties =>
user%material_properties
653 call user%material_properties(this%name, this%material_properties, &
659 if (params%valid_path(
'case.fluid.Re') .and. &
660 (params%valid_path(
'case.fluid.mu') .or. &
661 params%valid_path(
'case.fluid.rho')))
then
662 call neko_error(
"To set the material properties for the fluid, " // &
663 "either provide Re OR mu and rho in the case file.")
665 else if (params%valid_path(
'case.fluid.Re'))
then
667 write(log_buf,
'(A)')
'Non-dimensional fluid material properties &
670 write(log_buf,
'(A)')
'Density will be set to 1, dynamic viscosity to&
676 write(log_buf,
'(A)')
'Read non-dimensional material properties'
678 write(log_buf,
'(A,ES13.6)')
'Re :', const_mu
684 const_mu = 1.0_rp/const_mu
694 if (
associated(
user%material_properties, dummy_mp_ptr))
then
701 write(log_buf,
'(A,ES13.6)')
'rho :', const_rho
703 write(log_buf,
'(A,ES13.6)')
'mu :', const_mu
715 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
719 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
722 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 .
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.
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.
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 solution fields.
type(registry_t), target, public neko_registry
Global field registry.
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.
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...