52 use precon,
only :
pc_t, precon_allocator, precon_destroy
63 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 :: pr_projection_reorthogonalize_basis
89 logical :: strict_convergence
90 logical :: allow_stabilization
92 logical :: svv_enabled = .false.
101 logical :: forced_flow_rate = .false.
104 character(len=:),
allocatable :: nut_field_name
110 integer(kind=i8) :: glb_n_points
112 integer(kind=i8) :: glb_unique_points
126 procedure, pass(this) :: set_material_properties => &
140 module subroutine fluid_scheme_factory(object, type_name)
142 character(len=*) :: type_name
143 end subroutine fluid_scheme_factory
146 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
151 subroutine fluid_scheme_init_base(this, msh, lx, params, scheme, user, &
154 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
155 type(
mesh_t),
target,
intent(inout) :: msh
156 integer,
intent(in) :: lx
157 character(len=*),
intent(in) :: scheme
158 type(json_file),
target,
intent(inout) :: params
159 type(
user_t),
target,
intent(in) :: user
160 logical,
intent(in) :: kspv_init
162 character(len=LOG_SIZE) :: log_buf
163 real(kind=
rp),
allocatable :: real_vec(:)
164 real(kind=
rp) :: real_val, kappa, b, z0
165 logical :: logical_val, full_stress_formulation
166 integer :: integer_val, ierr
167 type(json_file) :: wm_json
168 character(len=:),
allocatable :: string_val1, string_val2
169 type(json_file) :: json_subdict
177 if (msh%gdim .eq. 2)
then
178 call this%Xh%init(
gll, lx, lx)
180 call this%Xh%init(
gll, lx, lx, lx)
183 call this%dm_Xh%init(msh, this%Xh)
185 call this%gs_Xh%init(this%dm_Xh)
187 call this%c_Xh%init(this%gs_Xh)
200 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
202 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
216 call this%set_material_properties(params,
user)
220 'case.fluid.velocity_solver.projection_space_size', &
221 this%vel_projection_dim, 0)
223 'case.fluid.pressure_solver.projection_space_size', &
224 this%pr_projection_dim, 0)
226 'case.fluid.velocity_solver.projection_hold_steps', &
227 this%vel_projection_activ_step, 5)
229 'case.fluid.pressure_solver.projection_hold_steps', &
230 this%pr_projection_activ_step, 5)
232 'case.fluid.pressure_solver.projection_reorthogonalize_basis', &
233 this%pr_projection_reorthogonalize_basis, .false.)
237 if (params%valid_path(
"case.fluid.flow_rate_force"))
then
238 this%forced_flow_rate = .true.
243 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
244 else if (lx .ge. 10)
then
245 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
247 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
250 this%glb_n_points = int(this%msh%glb_nelv,
i8)*int(this%Xh%lxyz,
i8)
251 this%glb_unique_points = int(
glsum(this%c_Xh%mult, this%dm_Xh%size()),
i8)
253 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
255 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
259 call json_get(params,
'case.numerics.dealias', logical_val)
260 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
266 write(log_buf,
'(A, L1)')
'Save bdry : ', logical_val
270 full_stress_formulation, .false.)
271 write(log_buf,
'(A, L1)')
'Full stress: ', full_stress_formulation
281 call this%f_x%init(this%dm_Xh, fld_name =
"fluid_rhs_x")
282 call this%f_y%init(this%dm_Xh, fld_name =
"fluid_rhs_y")
283 call this%f_z%init(this%dm_Xh, fld_name =
"fluid_rhs_z")
287 call neko_log%section(
"Velocity solver")
289 'case.fluid.velocity_solver.max_iterations', &
291 call json_get(params,
'case.fluid.velocity_solver.type', string_val1)
292 call json_get(params,
'case.fluid.velocity_solver.preconditioner.type', &
295 'case.fluid.velocity_solver.preconditioner', json_subdict)
297 'case.fluid.velocity_solver.absolute_tolerance', &
300 'case.fluid.velocity_solver.monitor', &
301 logical_val, .false.)
303 call neko_log%message(
'Type : ('// trim(string_val1) // &
304 ', ' // trim(string_val2) //
')')
306 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
308 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
309 string_val1, integer_val, real_val, logical_val)
310 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
311 this%c_Xh, this%dm_Xh, this%gs_Xh, this%bcs_vel, &
312 string_val2, json_subdict)
318 this%strict_convergence, .false.)
321 this%allow_stabilization, .false.)
325 call this%ulag%init(this%u, 2)
326 call this%vlag%init(this%v, 2)
327 call this%wlag%init(this%w, 2)
337 call neko_log%section(
'Fluid Source term')
338 call this%source_term%init(this%f_x, this%f_y, this%f_z, this%c_Xh,
user, &
340 call this%source_term%add(params,
'case.fluid.source_terms')
343 if (params%valid_path(
'case.fluid.svv'))
then
344 call json_get(params,
'case.fluid', json_subdict)
346 this%svv_enabled, .false.)
347 if (this%svv_enabled)
then
348 if (.not. kspv_init)
then
349 call neko_error(
"SVV is only supported by fluid " // &
350 "schemes with an implicit velocity solve")
352 if (full_stress_formulation)
then
353 if (trim(string_val1) .ne.
'coupled_cg' .and. &
354 trim(string_val1) .ne.
'fused_coupled_cg')
then
355 call neko_error(
"Full-stress SVV requires a " // &
356 "coupled velocity solver (`coupled_cg` or " // &
357 "`fused_coupled_cg`)")
361 call this%svv%init(json_subdict, this%c_Xh, this%rho)
365 end subroutine fluid_scheme_init_base
367 subroutine fluid_scheme_free(this)
368 class(fluid_scheme_incompressible_t),
intent(inout) :: this
369 class(
bc_t),
pointer :: bc
373 if (
allocated(this%svv))
then
377 this%svv_enabled = .false.
381 if (
allocated(this%ksp_vel))
then
382 call this%ksp_vel%free()
383 deallocate(this%ksp_vel)
386 if (
allocated(this%ksp_prs))
then
387 call this%ksp_prs%free()
388 deallocate(this%ksp_prs)
391 if (
allocated(this%pc_vel))
then
392 call precon_destroy(this%pc_vel)
393 deallocate(this%pc_vel)
396 if (
allocated(this%pc_prs))
then
397 call precon_destroy(this%pc_prs)
398 deallocate(this%pc_prs)
401 do i = 1, this%bcs_vel%size()
402 bc => this%bcs_vel%get(i)
403 if (
associated(
bc))
then
408 call this%bcs_vel%free()
410 do i = 1, this%bcs_prs%size()
411 bc => this%bcs_prs%get(i)
412 if (
associated(
bc))
then
417 call this%bcs_prs%free()
419 call this%source_term%free()
421 call this%gs_Xh%free()
423 call this%c_Xh%free()
434 call this%ulag%free()
435 call this%vlag%free()
436 call this%wlag%free()
439 if (
associated(this%f_x))
then
444 if (
associated(this%f_y))
then
449 if (
associated(this%f_z))
then
461 call this%dm_Xh%free()
465 end subroutine fluid_scheme_free
469 subroutine fluid_scheme_validate(this)
470 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
472 logical :: logical_val
474 if ( (.not.
associated(this%u)) .or. &
475 (.not.
associated(this%v)) .or. &
476 (.not.
associated(this%w)) .or. &
477 (.not.
associated(this%p)))
then
481 if ( (.not.
allocated(this%u%x)) .or. &
482 (.not.
allocated(this%v%x)) .or. &
483 (.not.
allocated(this%w%x)) .or. &
484 (.not.
allocated(this%p%x)))
then
488 if (.not.
allocated(this%ksp_vel))
then
489 call neko_error(
'No Krylov solver for velocity defined')
492 if (.not.
allocated(this%ksp_prs))
then
493 call neko_error(
'No Krylov solver for pressure defined')
496 end subroutine fluid_scheme_validate
502 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
503 class(fluid_scheme_incompressible_t),
intent(inout) :: this
505 logical,
intent(in) :: strong
507 class(
bc_t),
pointer :: b
509 call this%bcs_vel%apply_vector(&
510 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
512 call rotate_cyc(this%u, this%v, this%w, 1, this%c_Xh)
519 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
523 do i = 1, this%bcs_vel%size()
524 b => this%bcs_vel%get(i)
526 call b%apply_vector_generic(this%u, this%v, this%w,time, strong)
530 call rotate_cyc(this%u, this%v, this%w, 1, this%c_Xh)
537 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
539 do i = 1, this%bcs_vel%size()
540 b => this%bcs_vel%get(i)
545 end subroutine fluid_scheme_bc_apply_vel
549 subroutine fluid_scheme_bc_apply_prs(this, time)
550 class(fluid_scheme_incompressible_t),
intent(inout) :: this
554 class(
bc_t),
pointer :: b
557 call this%bcs_prs%apply(this%p, time)
561 call this%bcs_prs%apply(this%p, time)
565 do i = 1, this%bcs_prs%size()
566 b => this%bcs_prs%get(i)
571 end subroutine fluid_scheme_bc_apply_prs
575 subroutine fluid_scheme_solver_factory(ksp, n, solver, &
576 max_iter, abstol, monitor)
577 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
578 integer,
intent(in),
value :: n
579 character(len=*),
intent(in) :: solver
580 integer,
intent(in) :: max_iter
581 real(kind=
rp),
intent(in) :: abstol
582 logical,
intent(in) :: monitor
584 call krylov_solver_factory(ksp, n, solver, max_iter, abstol, &
587 end subroutine fluid_scheme_solver_factory
590 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, dof, gs, bclst, &
592 class(fluid_scheme_incompressible_t),
intent(inout) :: this
593 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
594 class(
ksp_t),
target,
intent(inout) :: ksp
595 type(
coef_t),
target,
intent(in) :: coef
596 type(
dofmap_t),
target,
intent(in) :: dof
597 type(
gs_t),
target,
intent(inout) :: gs
598 type(
bc_list_t),
target,
intent(inout) :: bclst
599 character(len=*) :: pctype
600 type(json_file),
intent(inout) :: pcparams
602 call precon_allocator(pc, pctype)
604 select type (pcp => pc)
606 call pcp%init(coef, dof, gs)
608 call pcp%init(coef, dof, gs)
610 call pcp%init(coef, dof, gs)
612 call pcp%init(coef, bclst, pcparams)
614 call pcp%init(coef, bclst, pcparams)
619 end subroutine fluid_scheme_precon_factory
622 function fluid_compute_cfl(this, dt)
result(c)
623 class(fluid_scheme_incompressible_t),
intent(in) :: this
624 real(kind=
dp),
intent(in) :: dt
627 c =
cfl(dt, this%u, this%v, this%w, &
628 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
630 end function fluid_compute_cfl
637 subroutine fluid_scheme_update_material_properties(this, time)
638 class(fluid_scheme_incompressible_t),
intent(inout) :: this
642 call this%user_material_properties(this%name, this%material_properties, &
645 if (len(trim(this%nut_field_name)) > 0)
then
658 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
661 end subroutine fluid_scheme_update_material_properties
666 subroutine fluid_scheme_set_material_properties(this, params, user)
667 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
668 type(json_file),
intent(inout) :: params
669 type(
user_t),
target,
intent(in) :: user
670 character(len=LOG_SIZE) :: log_buf
673 logical :: nondimensional
674 real(kind=
rp) :: dummy_lambda, dummy_cp
675 real(kind=
rp) :: const_mu, const_rho
682 call neko_registry%add_field(this%dm_Xh, this%name //
"_mu_tot")
683 call neko_registry%add_field(this%dm_Xh, this%name //
"_rho")
685 this%mu_tot =>
neko_registry%get_field(this%name //
"_mu_tot")
688 call this%material_properties%init(2)
689 call this%material_properties%assign(1, this%rho)
690 call this%material_properties%assign(2, this%mu)
692 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
694 write(log_buf,
'(A)')
'Material properties must be set in the user' // &
697 this%user_material_properties =>
user%material_properties
699 call user%material_properties(this%name, this%material_properties, &
705 if (params%valid_path(
'case.fluid.Re') .and. &
706 (params%valid_path(
'case.fluid.mu') .or. &
707 params%valid_path(
'case.fluid.rho')))
then
708 call neko_error(
"To set the material properties for the fluid, " // &
709 "either provide Re OR mu and rho in the case file.")
711 else if (params%valid_path(
'case.fluid.Re'))
then
713 write(log_buf,
'(A)')
'Non-dimensional fluid material properties &
716 write(log_buf,
'(A)')
'Density will be set to 1, dynamic viscosity to&
722 write(log_buf,
'(A)')
'Read non-dimensional material properties'
724 write(log_buf,
'(A,ES13.6)')
'Re :', const_mu
730 const_mu = 1.0_rp/const_mu
740 if (
associated(
user%material_properties, dummy_mp_ptr))
then
747 write(log_buf,
'(A,ES13.6)')
'rho :', const_rho
749 write(log_buf,
'(A,ES13.6)')
'mu :', const_mu
761 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
765 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
768 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.
Apply cyclic boundary condition to a vector field.
Abstract interface for setting material properties.
Defines a boundary condition.
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
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=dp) 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.
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 dp
integer, parameter, public rp
Global precision used in computations.
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
Data and filter construction for spectral vanishing viscosity.
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.
Spectral vanishing viscosity configuration and coefficients.
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...