42 use space,
only :
gll,
operator(.ne.)
58 use json_module,
only : json_file
75 class(
ksp_t),
allocatable :: ksp_vel
76 class(
ksp_t),
allocatable :: ksp_prs
77 class(
pc_t),
allocatable :: pc_vel
78 class(
pc_t),
allocatable :: pc_prs
79 integer :: vel_projection_dim
80 integer :: pr_projection_dim
81 integer :: vel_projection_activ_step
82 integer :: pr_projection_activ_step
83 logical :: pr_projection_reorthogonalize_basis
84 logical :: strict_convergence
85 logical :: allow_stabilization
87 logical :: svv_enabled = .false.
96 logical :: forced_flow_rate = .false.
99 character(len=:),
allocatable :: nut_field_name
105 integer(kind=i8) :: glb_n_points
107 integer(kind=i8) :: glb_unique_points
115 procedure, pass(this) :: set_user_initial_condition => &
124 procedure, pass(this) :: set_material_properties => &
138 module subroutine fluid_scheme_factory(object, type_name)
140 character(len=*) :: type_name
141 end subroutine fluid_scheme_factory
144 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
158 subroutine fluid_scheme_init_base(this, msh, lx, params, numerics_params, &
159 scheme, user, kspv_init, output_boundary)
161 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
162 type(
mesh_t),
target,
intent(inout) :: msh
163 integer,
intent(in) :: lx
164 type(json_file),
target,
intent(inout) :: params
165 type(json_file),
target,
intent(inout) :: numerics_params
166 character(len=*),
intent(in) :: scheme
167 type(
user_t),
target,
intent(in) :: user
168 logical,
intent(in) :: kspv_init
169 logical,
intent(in) :: output_boundary
171 character(len=LOG_SIZE) :: log_buf
172 real(kind=
rp),
allocatable :: real_vec(:)
173 real(kind=
rp) :: real_val, kappa, b, z0
174 logical :: logical_val, full_stress_formulation
175 integer :: integer_val, ierr
176 type(json_file) :: wm_json
177 character(len=:),
allocatable :: string_val1, string_val2
178 type(json_file) :: json_subdict, solver_params
186 if (msh%gdim .eq. 2)
then
187 call this%Xh%init(
gll, lx, lx)
189 call this%Xh%init(
gll, lx, lx, lx)
192 call this%dm_Xh%init(msh, this%Xh)
194 call this%gs_Xh%init(this%dm_Xh)
196 call this%c_Xh%init(this%gs_Xh)
209 write(log_buf,
'(A, A)')
'Type : ', trim(scheme)
211 write(log_buf,
'(A, A)')
'Name : ', trim(this%name)
225 call this%set_material_properties(params,
user)
229 'velocity_solver.projection_space_size', &
230 this%vel_projection_dim, 0)
232 'pressure_solver.projection_space_size', &
233 this%pr_projection_dim, 0)
235 'velocity_solver.projection_hold_steps', &
236 this%vel_projection_activ_step, 5)
238 'pressure_solver.projection_hold_steps', &
239 this%pr_projection_activ_step, 5)
241 'pressure_solver.projection_reorthogonalize_basis', &
242 this%pr_projection_reorthogonalize_basis, .false.)
246 if (params%valid_path(
"flow_rate_force"))
then
247 this%forced_flow_rate = .true.
252 write(log_buf,
'(A, I1)')
'Poly order : ', lx-1
253 else if (lx .ge. 10)
then
254 write(log_buf,
'(A, I2)')
'Poly order : ', lx-1
256 write(log_buf,
'(A, I3)')
'Poly order : ', lx-1
259 this%glb_n_points = int(this%msh%glb_nelv,
i8)*int(this%Xh%lxyz,
i8)
260 this%glb_unique_points = int(
glsum(this%c_Xh%mult, this%dm_Xh%size()),
i8)
262 write(log_buf,
'(A, I0)')
'GLL points : ', this%glb_n_points
264 write(log_buf,
'(A, I0)')
'Unique pts.: ', this%glb_unique_points
268 call json_get(numerics_params,
'dealias', logical_val)
269 write(log_buf,
'(A, L1)')
'Dealias : ', logical_val
273 write(log_buf,
'(A, L1)')
'Save bdry : ', output_boundary
277 full_stress_formulation, .false.)
278 write(log_buf,
'(A, L1)')
'Full stress: ', full_stress_formulation
284 'compress_geometric_factors', logical_val, .false.)
285 write(log_buf,
'(A, L1)')
'Compress G : ', logical_val
287 if (logical_val)
then
288 if (numerics_params%valid_path( &
289 'compress_geometric_factors_tolerance'))
then
291 'compress_geometric_factors_tolerance', real_val)
292 call this%c_Xh%enable_geo_compression(real_val)
294 call this%c_Xh%enable_geo_compression()
305 call this%f_x%init(this%dm_Xh, fld_name =
"fluid_rhs_x")
306 call this%f_y%init(this%dm_Xh, fld_name =
"fluid_rhs_y")
307 call this%f_z%init(this%dm_Xh, fld_name =
"fluid_rhs_z")
311 call neko_log%section(
"Velocity solver")
312 call json_get(params,
'velocity_solver', solver_params)
313 call json_get(params,
'velocity_solver.type', string_val1)
314 call json_get(params,
'velocity_solver.preconditioner.type', &
317 'velocity_solver.preconditioner', json_subdict)
319 'velocity_solver.absolute_tolerance', &
322 call neko_log%message(
'Type : ('// trim(string_val1) // &
323 ', ' // trim(string_val2) //
')')
325 write(log_buf,
'(A,ES13.6)')
'Abs tol :', real_val
327 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
329 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
330 this%c_Xh, this%bcs_vel, &
331 string_val2, json_subdict)
337 this%strict_convergence, .false.)
340 this%allow_stabilization, .false.)
344 call this%ulag%init(this%u, 2)
345 call this%vlag%init(this%v, 2)
346 call this%wlag%init(this%w, 2)
356 call neko_log%section(
'Fluid Source term')
357 call this%source_term%init(this%f_x, this%f_y, this%f_z, this%c_Xh,
user, &
359 call this%source_term%add(params,
'source_terms')
362 if (params%valid_path(
'svv'))
then
364 this%svv_enabled, .false.)
365 if (this%svv_enabled)
then
366 if (.not. kspv_init)
then
367 call neko_error(
"SVV is only supported by fluid " // &
368 "schemes with an implicit velocity solve")
370 if (full_stress_formulation)
then
371 if (trim(string_val1) .ne.
'coupled_cg' .and. &
372 trim(string_val1) .ne.
'fused_coupled_cg')
then
373 call neko_error(
"Full-stress SVV requires a " // &
374 "coupled velocity solver (`coupled_cg` or " // &
375 "`fused_coupled_cg`)")
379 call this%svv%init(params, this%c_Xh, this%rho)
383 end subroutine fluid_scheme_init_base
385 subroutine fluid_scheme_free(this)
386 class(fluid_scheme_incompressible_t),
intent(inout) :: this
387 class(
bc_t),
pointer :: bc
391 if (
allocated(this%svv))
then
395 this%svv_enabled = .false.
399 if (
allocated(this%ksp_vel))
then
400 call this%ksp_vel%free()
401 deallocate(this%ksp_vel)
404 if (
allocated(this%ksp_prs))
then
405 call this%ksp_prs%free()
406 deallocate(this%ksp_prs)
409 if (
allocated(this%pc_vel))
then
410 call this%pc_vel%free()
411 deallocate(this%pc_vel)
414 if (
allocated(this%pc_prs))
then
415 call this%pc_prs%free()
416 deallocate(this%pc_prs)
419 do i = 1, this%bcs_vel%size()
420 bc => this%bcs_vel%get(i)
421 if (
associated(
bc))
then
426 call this%bcs_vel%free()
428 do i = 1, this%bcs_prs%size()
429 bc => this%bcs_prs%get(i)
430 if (
associated(
bc))
then
435 call this%bcs_prs%free()
437 call this%source_term%free()
439 call this%gs_Xh%free()
441 call this%c_Xh%free()
452 call this%ulag%free()
453 call this%vlag%free()
454 call this%wlag%free()
457 if (
associated(this%f_x))
then
462 if (
associated(this%f_y))
then
467 if (
associated(this%f_z))
then
479 call this%dm_Xh%free()
483 end subroutine fluid_scheme_free
487 subroutine fluid_scheme_validate(this)
488 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
490 logical :: logical_val
492 if ( (.not.
associated(this%u)) .or. &
493 (.not.
associated(this%v)) .or. &
494 (.not.
associated(this%w)) .or. &
495 (.not.
associated(this%p)))
then
499 if ( (.not.
allocated(this%u%x)) .or. &
500 (.not.
allocated(this%v%x)) .or. &
501 (.not.
allocated(this%w%x)) .or. &
502 (.not.
allocated(this%p%x)))
then
506 if (this%u%Xh .ne. this%v%Xh .or. &
507 this%u%Xh .ne. this%w%Xh)
then
508 call neko_error(
'Different function spaces for velocity components')
511 if (this%u%msh%nelv .ne. this%p%msh%nelv)
then
512 call neko_error(
'Velocity and pressure defined on different meshes')
515 if (.not.
allocated(this%ksp_vel))
then
516 call neko_error(
'No Krylov solver for velocity defined')
519 if (.not.
allocated(this%ksp_prs))
then
520 call neko_error(
'No Krylov solver for pressure defined')
523 end subroutine fluid_scheme_validate
528 subroutine fluid_scheme_set_user_initial_condition(this, user)
529 class(fluid_scheme_incompressible_t),
intent(inout) :: this
530 type(
user_t),
intent(in) :: user
533 this%c_Xh, this%gs_Xh,
user%initial_conditions, this%name)
535 end subroutine fluid_scheme_set_user_initial_condition
541 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
542 class(fluid_scheme_incompressible_t),
intent(inout) :: this
544 logical,
intent(in) :: strong
546 class(
bc_t),
pointer :: b
548 call this%bcs_vel%apply_vector(&
549 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
551 call rotate_cyc(this%u, this%v, this%w, 1, this%c_Xh)
552 call this%gs_Xh%op(this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), &
554 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
558 do i = 1, this%bcs_vel%size()
559 b => this%bcs_vel%get(i)
561 call b%apply_vector_generic(this%u, this%v, this%w,time, strong)
565 call rotate_cyc(this%u, this%v, this%w, 1, this%c_Xh)
566 call this%gs_Xh%op(this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), &
568 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
570 do i = 1, this%bcs_vel%size()
571 b => this%bcs_vel%get(i)
576 end subroutine fluid_scheme_bc_apply_vel
580 subroutine fluid_scheme_bc_apply_prs(this, time)
581 class(fluid_scheme_incompressible_t),
intent(inout) :: this
585 class(
bc_t),
pointer :: b
588 call this%bcs_prs%apply(this%p, time)
591 call this%bcs_prs%apply(this%p, time)
594 do i = 1, this%bcs_prs%size()
595 b => this%bcs_prs%get(i)
600 end subroutine fluid_scheme_bc_apply_prs
604 subroutine fluid_scheme_solver_factory(ksp, n, params)
605 class(
ksp_t),
allocatable,
target,
intent(inout) :: ksp
606 integer,
intent(in),
value :: n
607 type(json_file),
intent(inout) :: params
611 end subroutine fluid_scheme_solver_factory
614 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, bclst, &
616 class(fluid_scheme_incompressible_t),
intent(inout) :: this
617 class(
pc_t),
allocatable,
target,
intent(inout) :: pc
618 class(
ksp_t),
target,
intent(inout) :: ksp
619 type(
coef_t),
target,
intent(in) :: coef
620 type(
bc_list_t),
target,
intent(inout) :: bclst
621 character(len=*) :: pctype
622 type(json_file),
intent(inout) :: json
624 call precon_factory(pc, pctype, coef, bclst, json)
628 end subroutine fluid_scheme_precon_factory
631 function fluid_compute_cfl(this, dt)
result(c)
632 class(fluid_scheme_incompressible_t),
intent(in) :: this
633 real(kind=
dp),
intent(in) :: dt
636 c =
cfl(dt, this%u, this%v, this%w, &
637 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
639 end function fluid_compute_cfl
646 subroutine fluid_scheme_update_material_properties(this, time)
647 class(fluid_scheme_incompressible_t),
intent(inout) :: this
651 call this%user_material_properties(this%name, this%material_properties, &
654 if (len(trim(this%nut_field_name)) > 0)
then
667 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
670 end subroutine fluid_scheme_update_material_properties
675 subroutine fluid_scheme_set_material_properties(this, params, user)
676 class(fluid_scheme_incompressible_t),
target,
intent(inout) :: this
677 type(json_file),
intent(inout) :: params
678 type(
user_t),
target,
intent(in) :: user
679 character(len=LOG_SIZE) :: log_buf
682 logical :: nondimensional
683 real(kind=
rp) :: dummy_lambda, dummy_cp
684 real(kind=
rp) :: const_mu, const_rho
691 call neko_registry%add_field(this%dm_Xh, this%name //
"_mu_tot")
692 call neko_registry%add_field(this%dm_Xh, this%name //
"_rho")
694 this%mu_tot =>
neko_registry%get_field(this%name //
"_mu_tot")
697 call this%material_properties%init(2)
698 call this%material_properties%assign(1, this%rho)
699 call this%material_properties%assign(2, this%mu)
701 if (.not.
associated(
user%material_properties, dummy_mp_ptr))
then
703 write(log_buf,
'(A)')
'Material properties must be set in the user' // &
706 this%user_material_properties =>
user%material_properties
708 call user%material_properties(this%name, this%material_properties, &
714 if (params%valid_path(
'Re') .and. &
715 (params%valid_path(
'mu') .or. &
716 params%valid_path(
'rho')))
then
717 call neko_error(
"To set the material properties for the fluid, " // &
718 "either provide Re OR mu and rho in the case file.")
720 else if (params%valid_path(
'Re'))
then
722 write(log_buf,
'(A)')
'Non-dimensional fluid material properties &
725 write(log_buf,
'(A)')
'Density will be set to 1, dynamic viscosity to&
731 write(log_buf,
'(A)')
'Read non-dimensional material properties'
733 write(log_buf,
'(A,ES13.6)')
'Re :', const_mu
739 const_mu = 1.0_rp/const_mu
749 if (
associated(
user%material_properties, dummy_mp_ptr))
then
756 write(log_buf,
'(A,ES13.6)')
'rho :', const_rho
758 write(log_buf,
'(A,ES13.6)')
'mu :', const_mu
770 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
774 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
777 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.
Factory for Krylov solvers. Both creates and initializes the object, either from its parameters or fr...
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....
Defines format-independent checkpoint registration and restart state.
Device abstraction, common interface for various accelerators.
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, public set_flow_ic_user_incompressible(u, v, w, p, coef, gs, user_proc, scheme_name)
Set initial flow condition (user defined) for incompressible flows.
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_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_solver_factory(ksp, n, params)
Initialize a linear solver from its JSON solver block.
subroutine fluid_scheme_set_user_initial_condition(this, user)
Set the initial condition of the velocity and pressure with the user routine.
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_bc_apply_prs(this, time)
Apply all boundary conditions defined for pressure.
subroutine fluid_scheme_init_base(this, msh, lx, params, numerics_params, scheme, user, kspv_init, output_boundary)
Initialise a fluid scheme.
subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, bclst, pctype, json)
Initialize a Krylov preconditioner.
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 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.
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.
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.
Collection of live simulation data registered for checkpointing.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
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.
Base abstract type for a canonical Krylov method, solving .
Defines a canonical Krylov preconditioner.
Spectral vanishing viscosity configuration and coefficients.
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...