Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
fluid_scheme_incompressible.f90
Go to the documentation of this file.
1! Copyright (c) 2020-2026, The Neko Authors
2! All rights reserved.
3!
4! Redistribution and use in source and binary forms, with or without
5! modification, are permitted provided that the following conditions
6! are met:
7!
8! * Redistributions of source code must retain the above copyright
9! notice, this list of conditions and the following disclaimer.
10!
11! * Redistributions in binary form must reproduce the above
12! copyright notice, this list of conditions and the following
13! disclaimer in the documentation and/or other materials provided
14! with the distribution.
15!
16! * Neither the name of the authors nor the names of its
17! contributors may be used to endorse or promote products derived
18! from this software without specific prior written permission.
19!
20! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24! COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25! INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26! BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27! LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28! CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29! LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30! ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31! POSSIBILITY OF SUCH DAMAGE.
32!
33!> Fluid formulations
36 use gather_scatter, only : gs_t, gs_op_min, gs_op_max
38 use checkpoint, only : chkp_t
39 use num_types, only : rp, i8, dp
41 use field, only : field_t
42 use space, only : gll, operator(.ne.)
43 use dofmap, only : dofmap_t
45 use coefs, only : coef_t
46 use dirichlet, only : dirichlet_t
47 use precon, only : pc_t, precon_factory
48 use fluid_stats, only : fluid_stats_t
49 use bc, only : bc_t, bc_dirichlet
50 use bc_list, only : bc_list_t
51 use mesh, only : mesh_t
52 use math, only : glsum
53 use operators, only : cfl, rotate_cyc
55 use registry, only : neko_registry
58 use json_module, only : json_file
62 use utils, only : neko_error
65 use time_state, only : time_state_t
68 implicit none
69 private
70
71 !> Base type of all fluid formulations
73 !> The source term for the momentum equation.
75 class(ksp_t), allocatable :: ksp_vel !< Krylov solver for velocity
76 class(ksp_t), allocatable :: ksp_prs !< Krylov solver for pressure
77 class(pc_t), allocatable :: pc_vel !< Velocity Preconditioner
78 class(pc_t), allocatable :: pc_prs !< Velocity Preconditioner
79 integer :: vel_projection_dim !< Size of the projection space for ksp_vel
80 integer :: pr_projection_dim !< Size of the projection space for ksp_pr
81 integer :: vel_projection_activ_step !< Steps to activate projection for ksp_vel
82 integer :: pr_projection_activ_step !< Steps to activate projection for ksp_pr
83 logical :: pr_projection_reorthogonalize_basis !< To reorthogonalize proj basis
84 logical :: strict_convergence !< Strict convergence for the velocity solver
85 logical :: allow_stabilization !< Allow stabilization period
86 !> Whether spectral vanishing viscosity is enabled.
87 logical :: svv_enabled = .false.
88 !> Spectral vanishing viscosity object.
89 type(svv_t), allocatable :: svv
90 !> Extrapolation velocity fields for LES
91 type(field_t), pointer :: u_e => null() !< Extrapolated x-Velocity
92 type(field_t), pointer :: v_e => null() !< Extrapolated y-Velocity
93 type(field_t), pointer :: w_e => null() !< Extrapolated z-Velocity
94
95 type(fluid_stats_t) :: stats !< Fluid statistics
96 logical :: forced_flow_rate = .false. !< Is the flow rate forced?
97
98 !> The turbulent kinematic viscosity field name
99 character(len=:), allocatable :: nut_field_name
100
101 ! The total viscosity field
102 type(field_t), pointer :: mu_tot => null()
103
104 !> Global number of GLL points for the fluid (not unique)
105 integer(kind=i8) :: glb_n_points
106 !> Global number of GLL points for the fluid (unique)
107 integer(kind=i8) :: glb_unique_points
108 contains
109 !> Constructor for the base type
110 procedure, pass(this) :: init_base => fluid_scheme_init_base
111 procedure, pass(this) :: scheme_free => fluid_scheme_free
112 !> Validate that all components are properly allocated
113 procedure, pass(this) :: validate => fluid_scheme_validate
114 !> Set the initial condition with the user routine
115 procedure, pass(this) :: set_user_initial_condition => &
117 !> Apply pressure boundary conditions
118 procedure, pass(this) :: bc_apply_vel => fluid_scheme_bc_apply_vel
119 !> Apply velocity boundary conditions
120 procedure, pass(this) :: bc_apply_prs => fluid_scheme_bc_apply_prs
121 !> Compute the CFL number
122 procedure, pass(this) :: compute_cfl => fluid_compute_cfl
123 !> Set rho and mu
124 procedure, pass(this) :: set_material_properties => &
126
127 !> Update variable material properties
128 procedure, pass(this) :: update_material_properties => &
130 !> Linear solver factory, wraps a KSP constructor
131 procedure, nopass :: solver_factory => fluid_scheme_solver_factory
132 !> Preconditioner factory
133 procedure, pass(this) :: precon_factory_ => fluid_scheme_precon_factory
135
136 interface
137 !> Initialise a fluid scheme
138 module subroutine fluid_scheme_factory(object, type_name)
139 class(fluid_scheme_base_t), intent(inout), allocatable :: object
140 character(len=*) :: type_name
141 end subroutine fluid_scheme_factory
142 end interface
143
144 public :: fluid_scheme_incompressible_t, fluid_scheme_factory
145
146contains
147
148 !> Initialize common data for the current scheme
149 !! @param msh The mesh.
150 !! @param lx The number of GLL points in each direction.
151 !! @param params The fluid parameters, i.e. `case.fluid`.
152 !! @param numerics_params The numerical parameters, i.e. `case.numerics`.
153 !! @param scheme The name of the scheme, used in the log.
154 !! @param user Type with user-defined procedures.
155 !! @param kspv_init Whether to initialize the velocity solver.
156 !! @param output_boundary Whether the boundary condition markers are
157 !! written to file, used in the log.
158 subroutine fluid_scheme_init_base(this, msh, lx, params, numerics_params, &
159 scheme, user, kspv_init, output_boundary)
160 implicit none
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
170 type(dirichlet_t) :: bdry_mask
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
179
180 !
181 ! SEM simulation fundamentals
182 !
183
184 this%msh => msh
185
186 if (msh%gdim .eq. 2) then
187 call this%Xh%init(gll, lx, lx)
188 else
189 call this%Xh%init(gll, lx, lx, lx)
190 end if
191
192 call this%dm_Xh%init(msh, this%Xh)
193
194 call this%gs_Xh%init(this%dm_Xh)
195
196 call this%c_Xh%init(this%gs_Xh)
197
198 ! Assign Dofmap to scratch registry
199 call neko_scratch_registry%set_dofmap(this%dm_Xh)
200
201 ! Assign a name
202 call json_get_or_default(params, 'name', this%name, "fluid")
203
204 !
205 ! First section of fluid log
206 !
207
208 call neko_log%section('Fluid')
209 write(log_buf, '(A, A)') 'Type : ', trim(scheme)
210 call neko_log%message(log_buf)
211 write(log_buf, '(A, A)') 'Name : ', trim(this%name)
212 call neko_log%message(log_buf)
213
214 ! Assign velocity fields
215 call neko_registry%add_field(this%dm_Xh, 'u')
216 call neko_registry%add_field(this%dm_Xh, 'v')
217 call neko_registry%add_field(this%dm_Xh, 'w')
218 this%u => neko_registry%get_field('u')
219 this%v => neko_registry%get_field('v')
220 this%w => neko_registry%get_field('w')
221
222 !
223 ! Material properties
224 !
225 call this%set_material_properties(params, user)
226
227 ! Projection spaces
228 call json_get_or_lookup_or_default(params, &
229 'velocity_solver.projection_space_size', &
230 this%vel_projection_dim, 0)
231 call json_get_or_lookup_or_default(params, &
232 'pressure_solver.projection_space_size', &
233 this%pr_projection_dim, 0)
234 call json_get_or_lookup_or_default(params, &
235 'velocity_solver.projection_hold_steps', &
236 this%vel_projection_activ_step, 5)
237 call json_get_or_lookup_or_default(params, &
238 'pressure_solver.projection_hold_steps', &
239 this%pr_projection_activ_step, 5)
240 call json_get_or_default(params, &
241 'pressure_solver.projection_reorthogonalize_basis', &
242 this%pr_projection_reorthogonalize_basis, .false.)
243
244 call json_get_or_default(params, 'freeze', this%freeze, .false.)
245
246 if (params%valid_path("flow_rate_force")) then
247 this%forced_flow_rate = .true.
248 end if
249
250
251 if (lx .lt. 10) then
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
255 else
256 write(log_buf, '(A, I3)') 'Poly order : ', lx-1
257 end if
258 call neko_log%message(log_buf)
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)
261
262 write(log_buf, '(A, I0)') 'GLL points : ', this%glb_n_points
263 call neko_log%message(log_buf)
264 write(log_buf, '(A, I0)') 'Unique pts.: ', this%glb_unique_points
265 call neko_log%message(log_buf)
266
267
268 call json_get(numerics_params, 'dealias', logical_val)
269 write(log_buf, '(A, L1)') 'Dealias : ', logical_val
270 call neko_log%message(log_buf)
271
272
273 write(log_buf, '(A, L1)') 'Save bdry : ', output_boundary
274 call neko_log%message(log_buf)
275
276 call json_get_or_default(params, "full_stress_formulation", &
277 full_stress_formulation, .false.)
278 write(log_buf, '(A, L1)') 'Full stress: ', full_stress_formulation
279 call neko_log%message(log_buf)
280
281 ! Compressed geometric factors, read by the standard Helmholtz
282 ! operators of the fluid, the scalars and the multigrid levels
283 call json_get_or_default(numerics_params, &
284 'compress_geometric_factors', logical_val, .false.)
285 write(log_buf, '(A, L1)') 'Compress G : ', logical_val
286 call neko_log%message(log_buf)
287 if (logical_val) then
288 if (numerics_params%valid_path( &
289 'compress_geometric_factors_tolerance')) then
290 call json_get_or_lookup(numerics_params, &
291 'compress_geometric_factors_tolerance', real_val)
292 call this%c_Xh%enable_geo_compression(real_val)
293 else
294 call this%c_Xh%enable_geo_compression()
295 end if
296 end if
297
298
299 !
300 ! Setup right-hand side fields.
301 !
302 allocate(this%f_x)
303 allocate(this%f_y)
304 allocate(this%f_z)
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")
308
309 ! Initialize velocity solver
310 if (kspv_init) then
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', &
315 string_val2)
316 call json_get(params, &
317 'velocity_solver.preconditioner', json_subdict)
318 call json_get_or_lookup(params, &
319 'velocity_solver.absolute_tolerance', &
320 real_val)
321
322 call neko_log%message('Type : ('// trim(string_val1) // &
323 ', ' // trim(string_val2) // ')')
324
325 write(log_buf, '(A,ES13.6)') 'Abs tol :', real_val
326 call neko_log%message(log_buf)
327 call this%solver_factory(this%ksp_vel, this%dm_Xh%size(), &
328 solver_params)
329 call this%precon_factory_(this%pc_vel, this%ksp_vel, &
330 this%c_Xh, this%bcs_vel, &
331 string_val2, json_subdict)
332 call neko_log%end_section()
333 end if
334
335 ! Strict convergence for the velocity solver
336 call json_get_or_default(params, 'strict_convergence', &
337 this%strict_convergence, .false.)
338 ! Allow stabilization period where we do not warn about non-convergence
339 call json_get_or_default(params, 'allow_stabilization', &
340 this%allow_stabilization, .false.)
341
342
343 !! Initialize time-lag fields
344 call this%ulag%init(this%u, 2)
345 call this%vlag%init(this%v, 2)
346 call this%wlag%init(this%w, 2)
347
348 call neko_registry%add_field(this%dm_Xh, 'u_e')
349 call neko_registry%add_field(this%dm_Xh, 'v_e')
350 call neko_registry%add_field(this%dm_Xh, 'w_e')
351 this%u_e => neko_registry%get_field('u_e')
352 this%v_e => neko_registry%get_field('v_e')
353 this%w_e => neko_registry%get_field('w_e')
354
355 ! Initialize the source term
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, &
358 this%name)
359 call this%source_term%add(params, 'source_terms')
360 call neko_log%end_section()
361
362 if (params%valid_path('svv')) then
363 call json_get_or_default(params, 'svv.enabled', &
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")
369 end if
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`)")
376 end if
377 end if
378 allocate(this%svv)
379 call this%svv%init(params, this%c_Xh, this%rho)
380 end if
381 end if
382
383 end subroutine fluid_scheme_init_base
384
385 subroutine fluid_scheme_free(this)
386 class(fluid_scheme_incompressible_t), intent(inout) :: this
387 class(bc_t), pointer :: bc
388 integer :: i
389
390
391 if (allocated(this%svv)) then
392 call this%svv%free()
393 deallocate(this%svv)
394 end if
395 this%svv_enabled = .false.
396
397 call this%Xh%free()
398
399 if (allocated(this%ksp_vel)) then
400 call this%ksp_vel%free()
401 deallocate(this%ksp_vel)
402 end if
403
404 if (allocated(this%ksp_prs)) then
405 call this%ksp_prs%free()
406 deallocate(this%ksp_prs)
407 end if
408
409 if (allocated(this%pc_vel)) then
410 call this%pc_vel%free()
411 deallocate(this%pc_vel)
412 end if
413
414 if (allocated(this%pc_prs)) then
415 call this%pc_prs%free()
416 deallocate(this%pc_prs)
417 end if
418
419 do i = 1, this%bcs_vel%size()
420 bc => this%bcs_vel%get(i)
421 if (associated(bc)) then
422 call bc%free()
423 deallocate(bc)
424 end if
425 end do
426 call this%bcs_vel%free()
427
428 do i = 1, this%bcs_prs%size()
429 bc => this%bcs_prs%get(i)
430 if (associated(bc)) then
431 call bc%free()
432 deallocate(bc)
433 end if
434 end do
435 call this%bcs_prs%free()
436
437 call this%source_term%free()
438
439 call this%gs_Xh%free()
440
441 call this%c_Xh%free()
442
443 nullify(this%u)
444 nullify(this%v)
445 nullify(this%w)
446 nullify(this%p)
447
448 nullify(this%u_e)
449 nullify(this%v_e)
450 nullify(this%w_e)
451
452 call this%ulag%free()
453 call this%vlag%free()
454 call this%wlag%free()
455
456
457 if (associated(this%f_x)) then
458 call this%f_x%free()
459 deallocate(this%f_x)
460 end if
461
462 if (associated(this%f_y)) then
463 call this%f_y%free()
464 deallocate(this%f_y)
465 end if
466
467 if (associated(this%f_z)) then
468 call this%f_z%free()
469 deallocate(this%f_z)
470 end if
471
472 nullify(this%f_x)
473 nullify(this%f_y)
474 nullify(this%f_z)
475 nullify(this%rho)
476 nullify(this%mu)
477 nullify(this%mu_tot)
478
479 call this%dm_Xh%free()
480 call this%Xh%free()
481 nullify(this%msh)
482
483 end subroutine fluid_scheme_free
484
485 !> Validate that all fields, solvers etc necessary for
486 !! performing time-stepping are defined
487 subroutine fluid_scheme_validate(this)
488 class(fluid_scheme_incompressible_t), target, intent(inout) :: this
489 ! Variables for retrieving json parameters
490 logical :: logical_val
491
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
496 call neko_error('Fields are not registered')
497 end if
498
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
503 call neko_error('Fields are not allocated')
504 end if
505
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')
509 end if
510
511 if (this%u%msh%nelv .ne. this%p%msh%nelv) then
512 call neko_error('Velocity and pressure defined on different meshes')
513 end if
514
515 if (.not. allocated(this%ksp_vel)) then
516 call neko_error('No Krylov solver for velocity defined')
517 end if
518
519 if (.not. allocated(this%ksp_prs)) then
520 call neko_error('No Krylov solver for pressure defined')
521 end if
522
523 end subroutine fluid_scheme_validate
524
525 !> Set the initial condition of the velocity and pressure with the user
526 !! routine.
527 !! @param user Type with user-defined procedures.
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
531
532 call set_flow_ic_user_incompressible(this%u, this%v, this%w, this%p, &
533 this%c_Xh, this%gs_Xh, user%initial_conditions, this%name)
534
535 end subroutine fluid_scheme_set_user_initial_condition
536
537 !> Apply all boundary conditions defined for velocity
538 !! Here we perform additional gs operations to take care of
539 !! shared points between elements that have different BCs, as done in Nek5000.
540 !! @todo Why can't we call the interface here?
541 subroutine fluid_scheme_bc_apply_vel(this, time, strong)
542 class(fluid_scheme_incompressible_t), intent(inout) :: this
543 type(time_state_t), intent(in) :: time
544 logical, intent(in) :: strong
545 integer :: i
546 class(bc_t), pointer :: b
547
548 call this%bcs_vel%apply_vector(&
549 this%u%x, this%v%x, this%w%x, this%dm_Xh%size(), time, strong)
550
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(), &
553 gs_op_min, glb_cmd_event)
554 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
555
556 ! Double pass for Dirichlet bcs only.
557 b => null()
558 do i = 1, this%bcs_vel%size()
559 b => this%bcs_vel%get(i)
560 if (b%bc_type .eq. bc_dirichlet) then
561 call b%apply_vector_generic(this%u, this%v, this%w,time, strong)
562 end if
563 end do
564
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(), &
567 gs_op_max, glb_cmd_event)
568 call rotate_cyc(this%u, this%v, this%w, 0, this%c_Xh)
569
570 do i = 1, this%bcs_vel%size()
571 b => this%bcs_vel%get(i)
572 b%updated = .false.
573 end do
574 nullify(b)
575
576 end subroutine fluid_scheme_bc_apply_vel
577
578 !> Apply all boundary conditions defined for pressure
579 !! @todo Why can't we call the interface here?
580 subroutine fluid_scheme_bc_apply_prs(this, time)
581 class(fluid_scheme_incompressible_t), intent(inout) :: this
582 type(time_state_t), intent(in) :: time
583
584 integer :: i
585 class(bc_t), pointer :: b
586 b => null()
587
588 call this%bcs_prs%apply(this%p, time)
589 call this%gs_Xh%op(this%p, gs_op_min, glb_cmd_event)
590
591 call this%bcs_prs%apply(this%p, time)
592 call this%gs_Xh%op(this%p, gs_op_max, glb_cmd_event)
593
594 do i = 1, this%bcs_prs%size()
595 b => this%bcs_prs%get(i)
596 b%updated = .false.
597 end do
598 nullify(b)
599
600 end subroutine fluid_scheme_bc_apply_prs
601
602 !> Initialize a linear solver from its JSON solver block
603 !! @note Currently only supporting Krylov solvers
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
608
609 call krylov_solver_factory(ksp, n, params)
610
611 end subroutine fluid_scheme_solver_factory
612
613 !> Initialize a Krylov preconditioner
614 subroutine fluid_scheme_precon_factory(this, pc, ksp, coef, bclst, &
615 pctype, json)
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
623
624 call precon_factory(pc, pctype, coef, bclst, json)
625
626 call ksp%set_pc(pc)
627
628 end subroutine fluid_scheme_precon_factory
629
630 !> Compute CFL
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
634 real(kind=dp) :: c
635
636 c = cfl(dt, this%u, this%v, this%w, &
637 this%Xh, this%c_Xh, this%msh%nelv, this%msh%gdim)
638
639 end function fluid_compute_cfl
640
641
642 !> Call user material properties routine and update the values of `mu`
643 !! if necessary.
644 !! @param t Time value.
645 !! @param tstep Current time step.
646 subroutine fluid_scheme_update_material_properties(this, time)
647 class(fluid_scheme_incompressible_t), intent(inout) :: this
648 type(time_state_t), intent(in) :: time
649 type(field_t), pointer :: nut
650
651 call this%user_material_properties(this%name, this%material_properties, &
652 time)
653
654 if (len(trim(this%nut_field_name)) > 0) then
655 nut => neko_registry%get_field(this%nut_field_name)
656 ! Copy material property
657 call field_copy(this%mu_tot, this%mu)
658 ! Add turbulent contribution
659 call field_addcol3(this%mu_tot, nut, this%rho)
660 end if
661
662 ! Since mu, rho is a field_t, and we use the %x(1,1,1,1)
663 ! host array data to pass constant density and viscosity
664 ! to some routines, we need to make sure that the host
665 ! values are also filled
666 if (neko_bcknd_device .eq. 1) then
667 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
668 device_to_host, sync = .false.)
669 end if
670 end subroutine fluid_scheme_update_material_properties
671
672 !> Sets rho and mu
673 !! @param params The case paramter file.
674 !! @param user The user interface.
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
680 ! A local pointer that is needed to make Intel happy
681 procedure(user_material_properties_intf), pointer :: dummy_mp_ptr
682 logical :: nondimensional
683 real(kind=rp) :: dummy_lambda, dummy_cp
684 real(kind=rp) :: const_mu, const_rho
685 type(time_state_t) :: dummy_time_state
686
687
688 dummy_mp_ptr => dummy_user_material_properties
689
690 call neko_registry%add_field(this%dm_Xh, this%name // "_mu")
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")
693 this%mu => neko_registry%get_field(this%name // "_mu")
694 this%mu_tot => neko_registry%get_field(this%name // "_mu_tot")
695 this%rho => neko_registry%get_field(this%name // "_rho")
696
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)
700
701 if (.not. associated(user%material_properties, dummy_mp_ptr)) then
702
703 write(log_buf, '(A)') 'Material properties must be set in the user' // &
704 ' file!'
705 call neko_log%message(log_buf)
706 this%user_material_properties => user%material_properties
707
708 call user%material_properties(this%name, this%material_properties, &
709 dummy_time_state)
710
711 else
712 this%user_material_properties => dummy_user_material_properties
713 ! Incorrect user input
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.")
719
720 else if (params%valid_path('Re')) then
721 ! Non-dimensional case
722 write(log_buf, '(A)') 'Non-dimensional fluid material properties &
723 & input.'
724 call neko_log%message(log_buf, lvl = neko_log_verbose)
725 write(log_buf, '(A)') 'Density will be set to 1, dynamic viscosity to&
726 & 1/Re.'
727 call neko_log%message(log_buf, lvl = neko_log_verbose)
728
729 ! Read Re into mu for further manipulation.
730 call json_get_or_lookup(params, 'Re', const_mu)
731 write(log_buf, '(A)') 'Read non-dimensional material properties'
732 call neko_log%message(log_buf)
733 write(log_buf, '(A,ES13.6)') 'Re :', const_mu
734 call neko_log%message(log_buf)
735
736 ! Set rho to 1 since the setup is non-dimensional.
737 const_rho = 1.0_rp
738 ! Invert the Re to get viscosity.
739 const_mu = 1.0_rp/const_mu
740 else
741 ! Dimensional case
742 call json_get_or_lookup(params, 'mu', const_mu)
743 call json_get_or_lookup(params, 'rho', const_rho)
744 end if
745 end if
746
747 ! We need to fill the fields based on the parsed const values
748 ! if the user routine is not used.
749 if (associated(user%material_properties, dummy_mp_ptr)) then
750 ! Fill mu and rho field with the physical value
751 call field_cfill(this%mu, const_mu)
752 call field_cfill(this%mu_tot, const_mu)
753 call field_cfill(this%rho, const_rho)
754
755
756 write(log_buf, '(A,ES13.6)') 'rho :', const_rho
757 call neko_log%message(log_buf)
758 write(log_buf, '(A,ES13.6)') 'mu :', const_mu
759 call neko_log%message(log_buf)
760 end if
761
762 ! Copy over material property to the total one
763 call field_copy(this%mu_tot, this%mu)
764
765 ! Since mu, rho is a field_t, and we use the %x(1,1,1,1)
766 ! host array data to pass constant density and viscosity
767 ! to some routines, we need to make sure that the host
768 ! values are also filled
769 if (neko_bcknd_device .eq. 1) then
770 call device_memcpy(this%rho%x, this%rho%x_d, this%rho%size(), &
771 device_to_host, sync = .false.)
772 call device_memcpy(this%mu%x, this%mu%x_d, this%mu%size(), &
773 device_to_host, sync = .false.)
774 call device_memcpy(this%mu_tot%x, this%mu_tot%x_d, this%mu%size(), &
775 device_to_host, sync = .false.)
776 end if
777 end subroutine fluid_scheme_set_material_properties
778
Copy data between host and device (or device and device).
Definition device.F90:72
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...
Definition krylov.f90:221
Compute CFL condition.
Definition operators.f90:98
Apply cyclic boundary condition to a vector field.
Abstract interface for setting material properties.
Defines a list of bc_t.
Definition bc_list.f90:34
Defines a boundary condition.
Definition bc.f90:34
integer, parameter, public bc_dirichlet
Supported boundary condition types. The values are set in order of precedence for global resolution....
Definition bc.f90:67
Defines format-independent checkpoint registration and restart state.
Coefficients.
Definition coef.f90:34
Device abstraction, common interface for various accelerators.
Definition device.F90:34
integer, parameter, public device_to_host
Definition device.F90:48
type(c_ptr), bind(C), public glb_cmd_event
Event for the global command queue.
Definition device.F90:63
Defines a dirichlet boundary condition.
Definition dirichlet.f90:34
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
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 field.
Definition field.f90:34
Initial flow condition.
Definition flow_ic.f90:34
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.
Definition flow_ic.f90:156
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_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 = ...
Gather-scatter.
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
Logging routines.
Definition log.f90:34
integer, parameter, public neko_log_verbose
Verbose.
Definition log.f90:54
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
integer, parameter, public log_size
Definition log.f90:46
Definition math.F90:60
real(kind=rp) function, public glsum(a, n)
Sum a vector of length n.
Definition math.F90:643
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public i8
Definition num_types.f90:7
integer, parameter, public dp
Definition num_types.f90:10
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Operators.
Definition operators.f90:34
Krylov preconditioner.
Definition precon.f90:34
Defines a registry for storing solution fields.
Definition registry.f90:34
type(registry_t), target, public neko_registry
Global field registry.
Definition registry.f90:158
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.
Definition space.f90:34
integer, parameter, public gll
Definition space.f90:50
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.
Definition user_intf.f90:34
subroutine, public dummy_user_material_properties(scheme_name, properties, time)
Utilities.
Definition utils.f90:35
Base type for a boundary condition.
Definition bc.f90:73
A list of allocatable `bc_t`. Follows the standard interface of lists.
Definition bc_list.f90:49
Collection of live simulation data registered for checkpointing.
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
Generic Dirichlet boundary condition on .
Definition dirichlet.f90:49
Base type of all fluid formulations.
Wrapper contaning and executing the fluid source terms.
Gather-scatter kernel.
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:77
Defines a canonical Krylov preconditioner.
Definition precon.f90:44
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...