148 type(
mesh_t),
target,
intent(inout) :: msh
149 integer,
intent(in) :: lx
150 type(json_file),
target,
intent(inout) :: params
151 type(
user_t),
target,
intent(in) :: user
153 character(len=15),
parameter :: scheme =
'Modular (Pn/Pn)'
159 call this%scheme_init(msh, lx, params, .true., .true., scheme, user)
161 if (this%variable_material_properties .eqv. .true.)
then
163 call ax_helm_factory(this%Ax_vel, full_formulation = .true.)
166 call pnpn_prs_res_stress_factory(this%prs_res)
169 call pnpn_vel_res_stress_factory(this%vel_res)
172 call ax_helm_factory(this%Ax_vel, full_formulation = .false.)
175 call pnpn_prs_res_factory(this%prs_res)
178 call pnpn_vel_res_factory(this%vel_res)
182 call ax_helm_factory(this%Ax_prs, full_formulation = .false.)
186 call rhs_maker_sumab_fctry(this%sumab)
189 call rhs_maker_ext_fctry(this%makeabf)
192 call rhs_maker_bdf_fctry(this%makebdf)
195 call rhs_maker_oifs_fctry(this%makeoifs)
198 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
199 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
201 call this%p_res%init(dm_xh,
"p_res")
202 call this%u_res%init(dm_xh,
"u_res")
203 call this%v_res%init(dm_xh,
"v_res")
204 call this%w_res%init(dm_xh,
"w_res")
205 call this%abx1%init(dm_xh,
"abx1")
206 call this%aby1%init(dm_xh,
"aby1")
207 call this%abz1%init(dm_xh,
"abz1")
208 call this%abx2%init(dm_xh,
"abx2")
209 call this%aby2%init(dm_xh,
"aby2")
210 call this%abz2%init(dm_xh,
"abz2")
211 call this%advx%init(dm_xh,
"advx")
212 call this%advy%init(dm_xh,
"advy")
213 call this%advz%init(dm_xh,
"advz")
224 call this%du%init(dm_xh,
'du')
225 call this%dv%init(dm_xh,
'dv')
226 call this%dw%init(dm_xh,
'dw')
227 call this%dp%init(dm_xh,
'dp')
232 call this%bc_prs_surface%init_base(this%c_Xh)
233 call this%bc_prs_surface%mark_zone(msh%inlet)
234 call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
238 call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
239 'd_vel_u', this%bc_labels)
240 call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
241 'd_vel_v', this%bc_labels)
242 call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
243 'd_vel_w', this%bc_labels)
244 call this%bc_prs_surface%finalize()
246 call this%bc_sym_surface%init_base(this%c_Xh)
247 call this%bc_sym_surface%mark_zone(msh%sympln)
248 call this%bc_sym_surface%mark_zones_from_list(msh%labeled_zones,&
249 'sym', this%bc_labels)
251 call this%bc_sym_surface%finalize()
253 call this%bc_vel_res_non_normal%init_base(this%c_Xh)
254 call this%bc_vel_res_non_normal%mark_zone(msh%outlet_normal)
255 call this%bc_vel_res_non_normal%mark_zones_from_list(msh%labeled_zones,&
256 'on', this%bc_labels)
257 call this%bc_vel_res_non_normal%mark_zones_from_list(msh%labeled_zones,&
260 call this%bc_vel_res_non_normal%finalize()
261 call this%bc_vel_res_non_normal%init(this%c_Xh)
263 call this%bc_field_dirichlet_p%init_base(this%c_Xh)
264 call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
265 'on+dong', this%bc_labels)
266 call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
267 'o+dong', this%bc_labels)
268 call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
269 'd_pres', this%bc_labels)
270 call this%bc_field_dirichlet_p%finalize()
271 call this%bc_field_dirichlet_p%set_g(0.0_rp)
272 call this%bclst_dp%init()
273 call this%bclst_dp%append(this%bc_field_dirichlet_p)
275 call this%bclst_dp%append(this%bc_prs)
277 this%prs_dirichlet = .not. this%bclst_dp%is_empty()
279 call mpi_allreduce(mpi_in_place, this%prs_dirichlet, 1, &
283 call this%bc_field_dirichlet_u%init_base(this%c_Xh)
284 call this%bc_field_dirichlet_u%mark_zones_from_list( &
285 msh%labeled_zones,
'd_vel_u', this%bc_labels)
286 call this%bc_field_dirichlet_u%finalize()
287 call this%bc_field_dirichlet_u%set_g(0.0_rp)
289 call this%bc_field_dirichlet_v%init_base(this%c_Xh)
290 call this%bc_field_dirichlet_v%mark_zones_from_list(msh%labeled_zones, &
293 call this%bc_field_dirichlet_v%finalize()
294 call this%bc_field_dirichlet_v%set_g(0.0_rp)
296 call this%bc_field_dirichlet_w%init_base(this%c_Xh)
297 call this%bc_field_dirichlet_w%mark_zones_from_list(msh%labeled_zones, &
300 call this%bc_field_dirichlet_w%finalize()
301 call this%bc_field_dirichlet_w%set_g(0.0_rp)
303 call this%bc_vel_res%init_base(this%c_Xh)
304 call this%bc_vel_res%mark_zone(msh%inlet)
305 call this%bc_vel_res%mark_zone(msh%wall)
306 call this%bc_vel_res%mark_zones_from_list(msh%labeled_zones, &
308 call this%bc_vel_res%mark_zones_from_list(msh%labeled_zones, &
310 call this%bc_vel_res%finalize()
311 call this%bc_vel_res%set_g(0.0_rp)
312 call this%bclst_vel_res%init()
313 call this%bclst_vel_res%append(this%bc_vel_res)
314 call this%bclst_vel_res%append(this%bc_vel_res_non_normal)
315 call this%bclst_vel_res%append(this%bc_sym)
316 call this%bclst_vel_res%append(this%bc_sh%symmetry)
317 call this%bclst_vel_res%append(this%bc_wallmodel%symmetry)
320 call this%bclst_du%init()
321 call this%bclst_du%append(this%bc_sym%bc_x)
322 call this%bclst_du%append(this%bc_sh%symmetry%bc_x)
323 call this%bclst_du%append(this%bc_wallmodel%symmetry%bc_x)
324 call this%bclst_du%append(this%bc_vel_res_non_normal%bc_x)
325 call this%bclst_du%append(this%bc_vel_res)
326 call this%bclst_du%append(this%bc_field_dirichlet_u)
328 call this%bclst_dv%init()
329 call this%bclst_dv%append(this%bc_sym%bc_y)
330 call this%bclst_dv%append(this%bc_sh%symmetry%bc_y)
331 call this%bclst_dv%append(this%bc_wallmodel%symmetry%bc_y)
332 call this%bclst_dv%append(this%bc_vel_res_non_normal%bc_y)
333 call this%bclst_dv%append(this%bc_vel_res)
334 call this%bclst_dv%append(this%bc_field_dirichlet_v)
336 call this%bclst_dw%init()
337 call this%bclst_dw%append(this%bc_sym%bc_z)
338 call this%bclst_dw%append(this%bc_sh%symmetry%bc_z)
339 call this%bclst_dw%append(this%bc_wallmodel%symmetry%bc_z)
340 call this%bclst_dw%append(this%bc_vel_res_non_normal%bc_z)
341 call this%bclst_dw%append(this%bc_vel_res)
342 call this%bclst_dw%append(this%bc_field_dirichlet_w)
346 if (this%variable_material_properties .and. &
347 this%vel_projection_dim .gt. 0)
then
348 call neko_error(
"Velocity projection not available for full stress &
353 call this%proj_prs%init(this%dm_Xh%size(), this%pr_projection_dim, &
354 this%pr_projection_activ_step)
356 call this%proj_u%init(this%dm_Xh%size(), this%vel_projection_dim, &
357 this%vel_projection_activ_step)
358 call this%proj_v%init(this%dm_Xh%size(), this%vel_projection_dim, &
359 this%vel_projection_activ_step)
360 call this%proj_w%init(this%dm_Xh%size(), this%vel_projection_dim, &
361 this%vel_projection_activ_step)
365 call this%chkp%add_lag(this%ulag, this%vlag, this%wlag)
372 call advection_factory(this%adv, params, this%c_Xh, &
373 this%ulag, this%vlag, this%wlag, &
377 if (params%valid_path(
'case.fluid.flow_rate_force'))
then
378 call this%vol_flow%init(this%dm_Xh, params)
385 real(kind=rp) :: dtlag(10), tlag(10)
386 type(field_t) :: u_temp, v_temp, w_temp
389 n = this%u%dof%size()
390 if (
allocated(this%chkp%previous_mesh%elements) .or. &
391 this%chkp%previous_Xh%lx .ne. this%Xh%lx)
then
392 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
393 c_xh => this%c_Xh, ulag => this%ulag, vlag => this%vlag, &
396 u%x(j,1,1,1) = u%x(j,1,1,1) * c_xh%mult(j,1,1,1)
397 v%x(j,1,1,1) = v%x(j,1,1,1) * c_xh%mult(j,1,1,1)
398 w%x(j,1,1,1) = w%x(j,1,1,1) * c_xh%mult(j,1,1,1)
399 p%x(j,1,1,1) = p%x(j,1,1,1) * c_xh%mult(j,1,1,1)
401 do i = 1, this%ulag%size()
403 ulag%lf(i)%x(j,1,1,1) = ulag%lf(i)%x(j,1,1,1) &
405 vlag%lf(i)%x(j,1,1,1) = vlag%lf(i)%x(j,1,1,1) &
407 wlag%lf(i)%x(j,1,1,1) = wlag%lf(i)%x(j,1,1,1) &
414 if (neko_bcknd_device .eq. 1)
then
415 associate(u => this%u, v => this%v, w => this%w, &
416 ulag => this%ulag, vlag => this%vlag, wlag => this%wlag,&
418 call device_memcpy(u%x, u%x_d, u%dof%size(), &
419 host_to_device, sync = .false.)
420 call device_memcpy(v%x, v%x_d, v%dof%size(), &
421 host_to_device, sync = .false.)
422 call device_memcpy(w%x, w%x_d, w%dof%size(), &
423 host_to_device, sync = .false.)
424 call device_memcpy(p%x, p%x_d, p%dof%size(), &
425 host_to_device, sync = .false.)
426 call device_memcpy(ulag%lf(1)%x, ulag%lf(1)%x_d, &
427 u%dof%size(), host_to_device, sync = .false.)
428 call device_memcpy(ulag%lf(2)%x, ulag%lf(2)%x_d, &
429 u%dof%size(), host_to_device, sync = .false.)
431 call device_memcpy(vlag%lf(1)%x, vlag%lf(1)%x_d, &
432 v%dof%size(), host_to_device, sync = .false.)
433 call device_memcpy(vlag%lf(2)%x, vlag%lf(2)%x_d, &
434 v%dof%size(), host_to_device, sync = .false.)
436 call device_memcpy(wlag%lf(1)%x, wlag%lf(1)%x_d, &
437 w%dof%size(), host_to_device, sync = .false.)
438 call device_memcpy(wlag%lf(2)%x, wlag%lf(2)%x_d, &
439 w%dof%size(), host_to_device, sync = .false.)
440 call device_memcpy(this%abx1%x, this%abx1%x_d, &
441 w%dof%size(), host_to_device, sync = .false.)
442 call device_memcpy(this%abx2%x, this%abx2%x_d, &
443 w%dof%size(), host_to_device, sync = .false.)
444 call device_memcpy(this%aby1%x, this%aby1%x_d, &
445 w%dof%size(), host_to_device, sync = .false.)
446 call device_memcpy(this%aby2%x, this%aby2%x_d, &
447 w%dof%size(), host_to_device, sync = .false.)
448 call device_memcpy(this%abz1%x, this%abz1%x_d, &
449 w%dof%size(), host_to_device, sync = .false.)
450 call device_memcpy(this%abz2%x, this%abz2%x_d, &
451 w%dof%size(), host_to_device, sync = .false.)
452 call device_memcpy(this%advx%x, this%advx%x_d, &
453 w%dof%size(), host_to_device, sync = .false.)
454 call device_memcpy(this%advy%x, this%advy%x_d, &
455 w%dof%size(), host_to_device, sync = .false.)
456 call device_memcpy(this%advz%x, this%advz%x_d, &
457 w%dof%size(), host_to_device, sync = .false.)
464 if (
allocated(this%chkp%previous_mesh%elements) &
465 .or. this%chkp%previous_Xh%lx .ne. this%Xh%lx)
then
466 call this%gs_Xh%op(this%u, gs_op_add)
467 call this%gs_Xh%op(this%v, gs_op_add)
468 call this%gs_Xh%op(this%w, gs_op_add)
469 call this%gs_Xh%op(this%p, gs_op_add)
471 do i = 1, this%ulag%size()
472 call this%gs_Xh%op(this%ulag%lf(i), gs_op_add)
473 call this%gs_Xh%op(this%vlag%lf(i), gs_op_add)
474 call this%gs_Xh%op(this%wlag%lf(i), gs_op_add)
616 real(kind=rp),
intent(in) :: t
617 integer,
intent(in) :: tstep
618 real(kind=rp),
intent(in) :: dt
619 type(time_scheme_controller_t),
intent(in) :: ext_bdf
620 type(time_step_controller_t),
intent(in) :: dt_controller
624 type(ksp_monitor_t) :: ksp_results(4)
626 type(field_t),
pointer :: u_e, v_e, w_e
628 integer :: temp_indices(3)
630 if (this%freeze)
return
632 n = this%dm_Xh%size()
634 call profiler_start_region(
'Fluid', 1)
635 associate(u => this%u, v => this%v, w => this%w, p => this%p, &
636 du => this%du, dv => this%dv, dw => this%dw, dp => this%dp, &
637 u_res => this%u_res, v_res => this%v_res, w_res => this%w_res, &
638 p_res => this%p_res, ax_vel => this%Ax_vel, ax_prs => this%Ax_prs, &
640 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
641 ulag => this%ulag, vlag => this%vlag, wlag => this%wlag, &
642 msh => this%msh, prs_res => this%prs_res, &
643 source_term => this%source_term, vel_res => this%vel_res, &
644 sumab => this%sumab, makeoifs => this%makeoifs, &
645 makeabf => this%makeabf, makebdf => this%makebdf, &
646 vel_projection_dim => this%vel_projection_dim, &
647 pr_projection_dim => this%pr_projection_dim, &
648 rho => this%rho, mu => this%mu, oifs => this%oifs, &
649 rho_field => this%rho_field, mu_field => this%mu_field, &
650 f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
651 if_variable_dt => dt_controller%if_variable_dt, &
652 dt_last_change => dt_controller%dt_last_change)
655 call this%scratch%request_field(u_e, temp_indices(1))
656 call this%scratch%request_field(v_e, temp_indices(2))
657 call this%scratch%request_field(w_e, temp_indices(3))
658 call sumab%compute_fluid(u_e, v_e, w_e, u, v, w, &
659 ulag, vlag, wlag, ext_bdf%advection_coeffs, ext_bdf%nadv)
662 call this%source_term%compute(t, tstep)
665 call this%bclst_vel_neumann%apply_vector(f_x%x, f_y%x, f_z%x, &
666 this%dm_Xh%size(), t, tstep)
669 if (this%if_gradient_jump_penalty .eqv. .true.)
then
670 call this%gradient_jump_penalty_u%compute(u, v, w, u)
671 call this%gradient_jump_penalty_v%compute(u, v, w, v)
672 call this%gradient_jump_penalty_w%compute(u, v, w, w)
673 call this%gradient_jump_penalty_u%perform(f_x)
674 call this%gradient_jump_penalty_v%perform(f_y)
675 call this%gradient_jump_penalty_w%perform(f_z)
680 call this%adv%compute(u, v, w, &
681 this%advx, this%advy, this%advz, &
682 xh, this%c_Xh, dm_xh%size(), dt)
688 call makeabf%compute_fluid(this%abx1, this%aby1, this%abz1,&
689 this%abx2, this%aby2, this%abz2, &
690 f_x%x, f_y%x, f_z%x, &
691 rho, ext_bdf%advection_coeffs, n)
694 call makeoifs%compute_fluid(this%advx%x, this%advy%x, this%advz%x, &
695 f_x%x, f_y%x, f_z%x, &
699 call this%adv%compute(u, v, w, &
701 xh, this%c_Xh, dm_xh%size())
707 call makeabf%compute_fluid(this%abx1, this%aby1, this%abz1,&
708 this%abx2, this%aby2, this%abz2, &
709 f_x%x, f_y%x, f_z%x, &
710 rho, ext_bdf%advection_coeffs, n)
713 call makebdf%compute_fluid(ulag, vlag, wlag, f_x%x, f_y%x, f_z%x, &
714 u, v, w, c_xh%B, rho, dt, &
715 ext_bdf%diffusion_coeffs, ext_bdf%ndiff, n)
725 call this%user_field_bc_vel%update(this%user_field_bc_vel%field_list, &
726 this%user_field_bc_vel%bc_list, this%c_Xh, t, tstep,
"fluid")
728 call this%bc_apply_vel(t, tstep)
729 call this%bc_apply_prs(t, tstep)
732 call this%update_material_properties()
735 call profiler_start_region(
'Pressure_residual', 18)
736 call prs_res%compute(p, p_res,&
741 this%bc_prs_surface, this%bc_sym_surface,&
742 ax_prs, ext_bdf%diffusion_coeffs(1), dt, &
745 if (.not. this%prs_dirichlet)
call ortho(p_res%x, this%glb_n_points, n)
746 call gs_xh%op(p_res, gs_op_add)
747 call this%bclst_dp%apply_scalar(p_res%x, p%dof%size(), t, tstep)
748 call profiler_end_region(
'Pressure_residual', 18)
750 call this%proj_prs%pre_solving(p_res%x, tstep, c_xh, n, dt_controller, &
753 call this%pc_prs%update()
754 call profiler_start_region(
'Pressure_solve', 3)
756 this%ksp_prs%solve(ax_prs, dp, p_res%x, n, c_xh, this%bclst_dp, gs_xh)
758 call profiler_end_region(
'Pressure_solve', 3)
760 call this%proj_prs%post_solving(dp%x, ax_prs, c_xh, &
761 this%bclst_dp, gs_xh, n, tstep, dt_controller)
763 call field_add2(p, dp, n)
764 if (.not. this%prs_dirichlet)
call ortho(p%x, this%glb_n_points, n)
767 call profiler_start_region(
'Velocity_residual', 19)
768 call vel_res%compute(ax_vel, u, v, w, &
769 u_res, v_res, w_res, &
773 mu_field, rho_field, ext_bdf%diffusion_coeffs(1), &
776 call gs_xh%op(u_res, gs_op_add)
777 call gs_xh%op(v_res, gs_op_add)
778 call gs_xh%op(w_res, gs_op_add)
780 call this%bclst_vel_res%apply_vector(u_res%x, v_res%x, w_res%x, &
781 dm_xh%size(), t, tstep)
785 if (neko_bcknd_device .eq. 1)
then
786 call this%bc_field_dirichlet_u%apply_scalar_dev(u_res%x_d, t, tstep)
787 call this%bc_field_dirichlet_v%apply_scalar_dev(v_res%x_d, t, tstep)
788 call this%bc_field_dirichlet_w%apply_scalar_dev(w_res%x_d, t, tstep)
790 call this%bc_field_dirichlet_u%apply_scalar(u_res%x, n, t, tstep)
791 call this%bc_field_dirichlet_v%apply_scalar(v_res%x, n, t, tstep)
792 call this%bc_field_dirichlet_w%apply_scalar(w_res%x, n, t, tstep)
795 call profiler_end_region(
'Velocity_residual', 19)
797 call this%proj_u%pre_solving(u_res%x, tstep, c_xh, n, dt_controller)
798 call this%proj_v%pre_solving(v_res%x, tstep, c_xh, n, dt_controller)
799 call this%proj_w%pre_solving(w_res%x, tstep, c_xh, n, dt_controller)
801 call this%pc_vel%update()
803 call profiler_start_region(
"Velocity_solve", 4)
804 ksp_results(2:4) = this%ksp_vel%solve_coupled(ax_vel, du, dv, dw, &
805 u_res%x, v_res%x, w_res%x, n, c_xh, &
806 this%bclst_du, this%bclst_dv, this%bclst_dw, gs_xh, &
807 this%ksp_vel%max_iter)
808 call profiler_end_region(
"Velocity_solve", 4)
810 call this%proj_u%post_solving(du%x, ax_vel, c_xh, &
811 this%bclst_du, gs_xh, n, tstep, dt_controller)
812 call this%proj_v%post_solving(dv%x, ax_vel, c_xh, &
813 this%bclst_dv, gs_xh, n, tstep, dt_controller)
814 call this%proj_w%post_solving(dw%x, ax_vel, c_xh, &
815 this%bclst_dw, gs_xh, n, tstep, dt_controller)
817 if (neko_bcknd_device .eq. 1)
then
818 call device_opadd2cm(u%x_d, v%x_d, w%x_d, &
819 du%x_d, dv%x_d, dw%x_d, 1.0_rp, n, msh%gdim)
821 call opadd2cm(u%x, v%x, w%x, du%x, dv%x, dw%x, 1.0_rp, n, msh%gdim)
824 if (this%forced_flow_rate)
then
825 call this%vol_flow%adjust( u, v, w, p, u_res, v_res, w_res, p_res, &
826 c_xh, gs_xh, ext_bdf, rho, mu, dt, &
827 this%bclst_dp, this%bclst_du, this%bclst_dv, &
828 this%bclst_dw, this%bclst_vel_res, ax_vel, ax_prs, this%ksp_prs, &
829 this%ksp_vel, this%pc_prs, this%pc_vel, this%ksp_prs%max_iter, &
830 this%ksp_vel%max_iter)
833 call fluid_step_info(tstep, t, dt, ksp_results, this%strict_convergence)
835 call this%scratch%relinquish_field(temp_indices)
838 call profiler_end_region(
'Fluid', 1)