52 use precon,
only :
pc_t, precon_factory, precon_destroy
62 use json_module,
only : json_file
78 class(
ksp_t),
allocatable :: ksp_vel
79 class(
ksp_t),
allocatable :: ksp_prs
80 class(
pc_t),
allocatable :: pc_vel
81 class(
pc_t),
allocatable :: pc_prs
82 integer :: vel_projection_dim
83 integer :: pr_projection_dim
84 integer :: vel_projection_activ_step
85 integer :: pr_projection_activ_step
86 logical :: strict_convergence
87 logical :: allow_stabilization
94 logical :: forced_flow_rate = .false.
97 character(len=:),
allocatable :: nut_field_name
103 integer(kind=i8) :: glb_n_points
105 integer(kind=i8) :: glb_unique_points
119 procedure, pass(this) :: set_material_properties => &
133 module subroutine fluid_scheme_factory(object, type_name)
135 character(len=*) :: type_name
136 end subroutine fluid_scheme_factory
139 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
144 subroutine fluid_scheme_init_base(this, msh, lx, params, scheme, user, &
147 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
148 type(
mesh_t),
target,
intent(inout) :: msh
149 integer,
intent(in) :: lx
150 character(len=*),
intent(in) :: scheme
151 type(json_file),
target,
intent(inout) :: params
152 type(
user_t),
target,
intent(in) :: user
153 logical,
intent(in) :: kspv_init
155 character(len=LOG_SIZE) :: log_buf
156 real(kind=
rp),
allocatable :: real_vec(:)
157 real(kind=
rp) :: real_val, kappa, b, z0
158 logical :: logical_val
159 integer :: integer_val, ierr
160 type(json_file) :: wm_json
161 character(len=:),
allocatable :: string_val1, string_val2
162 type(json_file) :: json_subdict
170 if (msh%gdim .eq. 2)
then
171 call this%Xh%init(
gll, lx, lx)
173 call this%Xh%init(
gll, lx, lx, lx)
176 call this%dm_Xh%init(msh, this%Xh)
178 call this%gs_Xh%init(this%dm_Xh)
180 call this%c_Xh%init(this%gs_Xh)
193 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
195 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
209 call this%set_material_properties(params,
user)
213 'case.fluid.velocity_solver.projection_space_size', &
214 this%vel_projection_dim, 0)
216 'case.fluid.pressure_solver.projection_space_size', &
217 this%pr_projection_dim, 0)
219 'case.fluid.velocity_solver.projection_hold_steps', &
220 this%vel_projection_activ_step, 5)
222 'case.fluid.pressure_solver.projection_hold_steps', &
223 this%pr_projection_activ_step, 5)
228 if (params%valid_path(
"case.fluid.flow_rate_force"))
then
229 this%forced_flow_rate = .true.
234 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
235 else if (lx .ge. 10)
then
236 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
238 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
241 this%glb_n_points = int(this%msh%glb_nelv,
i8)*int(this%Xh%lxyz,
i8)
242 this%glb_unique_points = int(
glsum(this%c_Xh%mult, this%dm_Xh%size()),
i8)
244 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
246 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
250 call json_get(params,
'case.numerics.dealias', logical_val)
251 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
257 write(log_buf,
'(A, L1)')
'Save bdry : ', logical_val
261 logical_val, .false.)
262 write(log_buf,
'(A, L1)')
'Full stress: ', logical_val
272 call this%f_x%init(this%dm_Xh, fld_name =
"fluid_rhs_x")
273 call this%f_y%init(this%dm_Xh, fld_name =
"fluid_rhs_y")
274 call this%f_z%init(this%dm_Xh, fld_name =
"fluid_rhs_z")
278 call neko_log%section(
"Velocity solver")
280 'case.fluid.velocity_solver.max_iterations', &
282 call json_get(params,
'case.fluid.velocity_solver.type', string_val1)
283 call json_get(params,
'case.fluid.velocity_solver.preconditioner.type', &
286 'case.fluid.velocity_solver.preconditioner', json_subdict)
287 call json_get(params,
'case.fluid.velocity_solver.absolute_tolerance', &
290 'case.fluid.velocity_solver.monitor', &
291 logical_val, .false.)
293 call neko_log%message(
'Type : ('// trim(string_val1) // &
294 ', ' // trim(string_val2) //
')')
296 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
298 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
299 string_val1, integer_val, real_val, logical_val)
300 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
301 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs_vel, &
302 string_val2, json_subdict)
308 this%strict_convergence, .false.)
311 this%allow_stabilization, .false.)
315 call this%ulag%init(this%u, 2)
316 call this%vlag%init(this%v, 2)
317 call this%wlag%init(this%w, 2)
327 call neko_log%section(
'Fluid Source term')
328 call this%source_term%init(this%f_x, this%f_y, this%f_z, this%c_Xh,
user, &
330 call this%source_term%add(params,
'case.fluid.source_terms')
333 end subroutine fluid_scheme_init_base
335 subroutine fluid_scheme_free(this)
336 class(fluid_scheme_incompressible_t),
intent(inout) :: this
340 if (
allocated(this%ksp_vel))
then
341 call this%ksp_vel%free()
342 deallocate(this%ksp_vel)
345 if (
allocated(this%ksp_prs))
then
346 call this%ksp_prs%free()
347 deallocate(this%ksp_prs)
350 if (
allocated(this%pc_vel))
then
351 call precon_destroy(this%pc_vel)
352 deallocate(this%pc_vel)
355 if (
allocated(this%pc_prs))
then
356 call precon_destroy(this%pc_prs)
357 deallocate(this%pc_prs)
360 call this%source_term%free()
362 call this%gs_Xh%free()
364 call this%c_Xh%free()
375 call this%ulag%free()
376 call this%vlag%free()
377 call this%wlag%free()
380 if (
associated(this%f_x))
then
385 if (
associated(this%f_y))
then
390 if (
associated(this%f_z))
then
402 call this%dm_Xh%free()
406 end subroutine fluid_scheme_free
410 subroutine fluid_scheme_validate(this)
411 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
413 logical :: logical_val
415 if ( (.not.
associated(this%u)) .or. &
416 (.not.
associated(this%v)) .or. &
417 (.not.
associated(this%w)) .or. &
418 (.not.
associated(this%p)))
then
422 if ( (.not.
allocated(this%u%x)) .or. &
423 (.not.
allocated(this%v%x)) .or. &
424 (.not.
allocated(this%w%x)) .or. &
425 (.not.
allocated(this%p%x)))
then
429 if (.not.
allocated(this%ksp_vel))
then
430 call neko_error(
'No Krylov solver for velocity defined')
433 if (.not.
allocated(this%ksp_prs))
then
434 call neko_error(
'No Krylov solver for pressure defined')
437 end subroutine fluid_scheme_validate
443 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
444 class(fluid_scheme_incompressible_t),
intent(inout) :: this
446 logical,
intent(in) :: strong
448 class(
bc_t),
pointer :: b
451 call this%bcs_vel%apply_vector(&
452 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
454 call rotate_cyc(this%u%x, this%v%x, this%w%x, 1, this%c_Xh)
461 call rotate_cyc(this%u%x, this%v%x, this%w%x, 0, this%c_Xh)
464 call this%bcs_vel%apply_vector(&
465 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
467 call rotate_cyc(this%u%x, this%v%x, this%w%x, 1, this%c_Xh)
474 call rotate_cyc(this%u%x, this%v%x, this%w%x, 0, this%c_Xh)
476 do i = 1, this%bcs_vel%size()
477 b => this%bcs_vel%get(i)
482 end subroutine fluid_scheme_bc_apply_vel
486 subroutine fluid_scheme_bc_apply_prs(this, time)
487 class(fluid_scheme_incompressible_t),
intent(inout) :: this
491 class(
bc_t),
pointer :: b
494 call this%bcs_prs%apply(this%p, time)
498 call this%bcs_prs%apply(this%p, time)
502 do i = 1, this%bcs_prs%size()
503 b => this%bcs_prs%get(i)
508 end subroutine fluid_scheme_bc_apply_prs
512 subroutine fluid_scheme_solver_factory(ksp, n, solver, &
513 max_iter, abstol, monitor)
514 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
515 integer,
intent(in),
value :: n
516 character(len=*),
intent(in) :: solver
517 integer,
intent(in) :: max_iter
518 real(kind=
rp),
intent(in) :: abstol
519 logical,
intent(in) :: monitor
521 call krylov_solver_factory(ksp, n, solver, max_iter, abstol, &
524 end subroutine fluid_scheme_solver_factory
527 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, dof, gs, bclst, &
529 class(fluid_scheme_incompressible_t),
intent(inout) :: this
530 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
531 class(
ksp_t),
target,
intent(inout) :: ksp
532 type(
coef_t),
target,
intent(in) :: coef
533 type(
dofmap_t),
target,
intent(in) :: dof
534 type(
gs_t),
target,
intent(inout) :: gs
535 type(
bc_list_t),
target,
intent(inout) :: bclst
536 character(len=*) :: pctype
537 type(json_file),
intent(inout) :: pcparams
539 call precon_factory(pc, pctype)
541 select type (pcp => pc)
543 call pcp%init(coef, dof, gs)
545 call pcp%init(coef, dof, gs)
547 call pcp%init(coef, dof, gs)
549 call pcp%init(coef, bclst, pcparams)
551 call pcp%init(coef, bclst, pcparams)
556 end subroutine fluid_scheme_precon_factory
559 function fluid_compute_cfl(this, dt)
result(c)
560 class(fluid_scheme_incompressible_t),
intent(in) :: this
561 real(kind=
rp),
intent(in) :: dt
564 c =
cfl(dt, this%u%x, this%v%x, this%w%x, &
565 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
567 end function fluid_compute_cfl
574 subroutine fluid_scheme_update_material_properties(this, time)
575 class(fluid_scheme_incompressible_t),
intent(inout) :: this
579 call this%user_material_properties(this%name, this%material_properties, &
582 if (len(trim(this%nut_field_name)) > 0)
then
595 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
598 end subroutine fluid_scheme_update_material_properties
603 subroutine fluid_scheme_set_material_properties(this, params, user)
604 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
605 type(json_file),
intent(inout) :: params
606 type(
user_t),
target,
intent(in) :: user
607 character(len=LOG_SIZE) :: log_buf
610 logical :: nondimensional
611 real(kind=
rp) :: dummy_lambda, dummy_cp
612 real(kind=
rp) :: const_mu, const_rho
619 call neko_registry%add_field(this%dm_Xh, this%name //
"_mu_tot")
620 call neko_registry%add_field(this%dm_Xh, this%name //
"_rho")
622 this%mu_tot =>
neko_registry%get_field(this%name //
"_mu_tot")
625 call this%material_properties%init(2)
626 call this%material_properties%assign(1, this%rho)
627 call this%material_properties%assign(2, this%mu)
629 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
631 write(log_buf,
'(A)')
'Material properties must be set in the user' // &
634 this%user_material_properties =>
user%material_properties
636 call user%material_properties(this%name, this%material_properties, &
642 if (params%valid_path(
'case.fluid.Re') .and. &
643 (params%valid_path(
'case.fluid.mu') .or. &
644 params%valid_path(
'case.fluid.rho')))
then
645 call neko_error(
"To set the material properties for the fluid, " // &
646 "either provide Re OR mu and rho in the case file.")
648 else if (params%valid_path(
'case.fluid.Re'))
then
650 write(log_buf,
'(A)')
'Non-dimensional fluid material properties &
653 write(log_buf,
'(A)')
'Density will be set to 1, dynamic viscosity to&
658 call json_get(params,
'case.fluid.Re', const_mu)
659 write(log_buf,
'(A)')
'Read non-dimensional material properties'
661 write(log_buf,
'(A,ES13.6)')
'Re :', const_mu
667 const_mu = 1.0_rp/const_mu
670 call json_get(params,
'case.fluid.mu', const_mu)
671 call json_get(params,
'case.fluid.rho', const_rho)
677 if (
associated(
user%material_properties, dummy_mp_ptr))
then
684 write(log_buf,
'(A,ES13.6)')
'rho :', const_rho
686 write(log_buf,
'(A,ES13.6)')
'mu :', const_mu
698 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
702 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
705 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...