146    type(
mesh_t), 
target, 
intent(inout) :: msh
 
  147    integer, 
intent(inout) :: lx
 
  148    type(json_file), 
target, 
intent(inout) :: params
 
  149    type(
user_t), 
target, 
intent(in) :: user
 
  151    character(len=15), 
parameter :: scheme = 
'Modular (Pn/Pn)' 
  156    call this%scheme_init(msh, lx, params, .true., .true., scheme, user)
 
  158    if (this%variable_material_properties .eqv. .true.) 
then 
  160       call ax_helm_factory(this%Ax_vel, full_formulation = .true.)
 
  163       call pnpn_prs_res_stress_factory(this%prs_res)
 
  166       call pnpn_vel_res_stress_factory(this%vel_res)
 
  169       call ax_helm_factory(this%Ax_vel, full_formulation = .false.)
 
  172       call pnpn_prs_res_factory(this%prs_res)
 
  175       call pnpn_vel_res_factory(this%vel_res)
 
  179    call ax_helm_factory(this%Ax_prs, full_formulation = .false.)
 
  183    call rhs_maker_sumab_fctry(this%sumab)
 
  186    call rhs_maker_ext_fctry(this%makeabf)
 
  189    call rhs_maker_bdf_fctry(this%makebdf)
 
  192    call rhs_maker_oifs_fctry(this%makeoifs)
 
  195    associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
 
  196         dm_xh => this%dm_Xh, nelv => this%msh%nelv)
 
  198      call this%p_res%init(dm_xh, 
"p_res")
 
  199      call this%u_res%init(dm_xh, 
"u_res")
 
  200      call this%v_res%init(dm_xh, 
"v_res")
 
  201      call this%w_res%init(dm_xh, 
"w_res")
 
  202      call this%abx1%init(dm_xh, 
"abx1")
 
  203      call this%aby1%init(dm_xh, 
"aby1")
 
  204      call this%abz1%init(dm_xh, 
"abz1")
 
  205      call this%abx2%init(dm_xh, 
"abx2")
 
  206      call this%aby2%init(dm_xh, 
"aby2")
 
  207      call this%abz2%init(dm_xh, 
"abz2")
 
  208      call this%advx%init(dm_xh, 
"advx")
 
  209      call this%advy%init(dm_xh, 
"advy")
 
  210      call this%advz%init(dm_xh, 
"advz")
 
  221      call this%du%init(dm_xh, 
'du')
 
  222      call this%dv%init(dm_xh, 
'dv')
 
  223      call this%dw%init(dm_xh, 
'dw')
 
  224      call this%dp%init(dm_xh, 
'dp')
 
  229    call this%bc_prs_surface%init_base(this%c_Xh)
 
  230    call this%bc_prs_surface%mark_zone(msh%inlet)
 
  231    call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
 
  235    call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
 
  236                                                 'd_vel_u', this%bc_labels)
 
  237    call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
 
  238                                                 'd_vel_v', this%bc_labels)
 
  239    call this%bc_prs_surface%mark_zones_from_list(msh%labeled_zones,&
 
  240                                                 'd_vel_w', this%bc_labels)
 
  241    call this%bc_prs_surface%finalize()
 
  243    call this%bc_sym_surface%init_base(this%c_Xh)
 
  244    call this%bc_sym_surface%mark_zone(msh%sympln)
 
  245    call this%bc_sym_surface%mark_zones_from_list(msh%labeled_zones,&
 
  246                                                 'sym', this%bc_labels)
 
  248    call this%bc_sym_surface%finalize()
 
  250    call this%bc_vel_res_non_normal%init_base(this%c_Xh)
 
  251    call this%bc_vel_res_non_normal%mark_zone(msh%outlet_normal)
 
  252    call this%bc_vel_res_non_normal%mark_zones_from_list(msh%labeled_zones,&
 
  253                                                         'on', this%bc_labels)
 
  254    call this%bc_vel_res_non_normal%mark_zones_from_list(msh%labeled_zones,&
 
  257    call this%bc_vel_res_non_normal%finalize()
 
  258    call this%bc_vel_res_non_normal%init(this%c_Xh)
 
  260    call this%bc_field_dirichlet_p%init_base(this%c_Xh)
 
  261    call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
 
  262      'on+dong', this%bc_labels)
 
  263    call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
 
  264      'o+dong', this%bc_labels)
 
  265    call this%bc_field_dirichlet_p%mark_zones_from_list(msh%labeled_zones, &
 
  266      'd_pres', this%bc_labels)
 
  267    call this%bc_field_dirichlet_p%finalize()
 
  268    call this%bc_field_dirichlet_p%set_g(0.0_rp)
 
  270    call bc_list_add(this%bclst_dp, this%bc_field_dirichlet_p)
 
  274    call this%bc_field_dirichlet_u%init_base(this%c_Xh)
 
  275    call this%bc_field_dirichlet_u%mark_zones_from_list( &
 
  276      msh%labeled_zones, 
'd_vel_u', this%bc_labels)
 
  277    call this%bc_field_dirichlet_u%finalize()
 
  278    call this%bc_field_dirichlet_u%set_g(0.0_rp)
 
  280    call this%bc_field_dirichlet_v%init_base(this%c_Xh)
 
  281    call this%bc_field_dirichlet_v%mark_zones_from_list(msh%labeled_zones, &
 
  284    call this%bc_field_dirichlet_v%finalize()
 
  285    call this%bc_field_dirichlet_v%set_g(0.0_rp)
 
  287    call this%bc_field_dirichlet_w%init_base(this%c_Xh)
 
  288    call this%bc_field_dirichlet_w%mark_zones_from_list(msh%labeled_zones, &
 
  291    call this%bc_field_dirichlet_w%finalize()
 
  292    call this%bc_field_dirichlet_w%set_g(0.0_rp)
 
  294    call this%bc_vel_res%init_base(this%c_Xh)
 
  295    call this%bc_vel_res%mark_zone(msh%inlet)
 
  296    call this%bc_vel_res%mark_zone(msh%wall)
 
  297    call this%bc_vel_res%mark_zones_from_list(msh%labeled_zones, &
 
  299    call this%bc_vel_res%mark_zones_from_list(msh%labeled_zones, &
 
  301    call this%bc_vel_res%finalize()
 
  302    call this%bc_vel_res%set_g(0.0_rp)
 
  304    call bc_list_add(this%bclst_vel_res, this%bc_vel_res)
 
  305    call bc_list_add(this%bclst_vel_res, this%bc_vel_res_non_normal)
 
  307    call bc_list_add(this%bclst_vel_res, this%bc_sh%symmetry)
 
  308    call bc_list_add(this%bclst_vel_res, this%bc_wallmodel%symmetry)
 
  313    call bc_list_add(this%bclst_du, this%bc_sh%symmetry%bc_x)
 
  314    call bc_list_add(this%bclst_du, this%bc_wallmodel%symmetry%bc_x)
 
  315    call bc_list_add(this%bclst_du, this%bc_vel_res_non_normal%bc_x)
 
  317    call bc_list_add(this%bclst_du, this%bc_field_dirichlet_u)
 
  321    call bc_list_add(this%bclst_dv, this%bc_sh%symmetry%bc_y)
 
  322    call bc_list_add(this%bclst_dv, this%bc_wallmodel%symmetry%bc_y)
 
  323    call bc_list_add(this%bclst_dv, this%bc_vel_res_non_normal%bc_y)
 
  325    call bc_list_add(this%bclst_dv, this%bc_field_dirichlet_v)
 
  329    call bc_list_add(this%bclst_dw, this%bc_sh%symmetry%bc_z)
 
  330    call bc_list_add(this%bclst_dw, this%bc_wallmodel%symmetry%bc_z)
 
  331    call bc_list_add(this%bclst_dw, this%bc_vel_res_non_normal%bc_z)
 
  333    call bc_list_add(this%bclst_dw, this%bc_field_dirichlet_w)
 
  337    if (this%variable_material_properties .and. &
 
  338          this%vel_projection_dim .gt. 0) 
then 
  339       call neko_error(
"Velocity projection not available for full stress & 
  344    call this%proj_prs%init(this%dm_Xh%size(), this%pr_projection_dim, &
 
  345                              this%pr_projection_activ_step)
 
  347    call this%proj_u%init(this%dm_Xh%size(), this%vel_projection_dim, &
 
  348                              this%vel_projection_activ_step)
 
  349    call this%proj_v%init(this%dm_Xh%size(), this%vel_projection_dim, &
 
  350                              this%vel_projection_activ_step)
 
  351    call this%proj_w%init(this%dm_Xh%size(), this%vel_projection_dim, &
 
  352                              this%vel_projection_activ_step)
 
  356    call this%chkp%add_lag(this%ulag, this%vlag, this%wlag)
 
  362    call advection_factory(this%adv, params, this%c_Xh, &
 
  363                           this%ulag, this%vlag, this%wlag, &
 
  366    if (params%valid_path(
'case.fluid.flow_rate_force')) 
then 
  367       call this%vol_flow%init(this%dm_Xh, params)
 
 
  374    real(kind=rp) :: dtlag(10), tlag(10)
 
  375    type(field_t) :: u_temp, v_temp, w_temp
 
  378    n = this%u%dof%size()
 
  379    if (
allocated(this%chkp%previous_mesh%elements) .or. &
 
  380        this%chkp%previous_Xh%lx .ne. this%Xh%lx) 
then 
  381       call col2(this%u%x, this%c_Xh%mult, this%u%dof%size())
 
  382       call col2(this%v%x, this%c_Xh%mult, this%u%dof%size())
 
  383       call col2(this%w%x, this%c_Xh%mult, this%u%dof%size())
 
  384       call col2(this%p%x, this%c_Xh%mult, this%u%dof%size())
 
  385       do i = 1, this%ulag%size()
 
  386          call col2(this%ulag%lf(i)%x, this%c_Xh%mult, this%u%dof%size())
 
  387          call col2(this%vlag%lf(i)%x, this%c_Xh%mult, this%u%dof%size())
 
  388          call col2(this%wlag%lf(i)%x, this%c_Xh%mult, this%u%dof%size())
 
  392    if (neko_bcknd_device .eq. 1) 
then 
  393       associate(u => this%u, v => this%v, w => this%w, &
 
  394            ulag => this%ulag, vlag => this%vlag, wlag => this%wlag,&
 
  396         call device_memcpy(u%x, u%x_d, u%dof%size(), &
 
  397                            host_to_device, sync = .false.)
 
  398         call device_memcpy(v%x, v%x_d, v%dof%size(), &
 
  399                            host_to_device, sync = .false.)
 
  400         call device_memcpy(w%x, w%x_d, w%dof%size(), &
 
  401                            host_to_device, sync = .false.)
 
  402         call device_memcpy(p%x, p%x_d, p%dof%size(), &
 
  403                            host_to_device, sync = .false.)
 
  404         call device_memcpy(ulag%lf(1)%x, ulag%lf(1)%x_d, &
 
  405                            u%dof%size(), host_to_device, sync = .false.)
 
  406         call device_memcpy(ulag%lf(2)%x, ulag%lf(2)%x_d, &
 
  407                            u%dof%size(), host_to_device, sync = .false.)
 
  409         call device_memcpy(vlag%lf(1)%x, vlag%lf(1)%x_d, &
 
  410                            v%dof%size(), host_to_device, sync = .false.)
 
  411         call device_memcpy(vlag%lf(2)%x, vlag%lf(2)%x_d, &
 
  412                            v%dof%size(), host_to_device, sync = .false.)
 
  414         call device_memcpy(wlag%lf(1)%x, wlag%lf(1)%x_d, &
 
  415                            w%dof%size(), host_to_device, sync = .false.)
 
  416         call device_memcpy(wlag%lf(2)%x, wlag%lf(2)%x_d, &
 
  417                            w%dof%size(), host_to_device, sync = .false.)
 
  418         call device_memcpy(this%abx1%x, this%abx1%x_d, &
 
  419                            w%dof%size(), host_to_device, sync = .false.)
 
  420         call device_memcpy(this%abx2%x, this%abx2%x_d, &
 
  421                            w%dof%size(), host_to_device, sync = .false.)
 
  422         call device_memcpy(this%aby1%x, this%aby1%x_d, &
 
  423                            w%dof%size(), host_to_device, sync = .false.)
 
  424         call device_memcpy(this%aby2%x, this%aby2%x_d, &
 
  425                            w%dof%size(), host_to_device, sync = .false.)
 
  426         call device_memcpy(this%abz1%x, this%abz1%x_d, &
 
  427                            w%dof%size(), host_to_device, sync = .false.)
 
  428         call device_memcpy(this%abz2%x, this%abz2%x_d, &
 
  429                            w%dof%size(), host_to_device, sync = .false.)
 
  430         call device_memcpy(this%advx%x, this%advx%x_d, &
 
  431                            w%dof%size(), host_to_device, sync = .false.)
 
  432         call device_memcpy(this%advy%x, this%advy%x_d, &
 
  433                            w%dof%size(), host_to_device, sync = .false.)
 
  434         call device_memcpy(this%advz%x, this%advz%x_d, &
 
  435                            w%dof%size(), host_to_device, sync = .false.)
 
  442    if (
allocated(this%chkp%previous_mesh%elements) &
 
  443         .or. this%chkp%previous_Xh%lx .ne. this%Xh%lx) 
then 
  444       call this%gs_Xh%op(this%u, gs_op_add)
 
  445       call this%gs_Xh%op(this%v, gs_op_add)
 
  446       call this%gs_Xh%op(this%w, gs_op_add)
 
  447       call this%gs_Xh%op(this%p, gs_op_add)
 
  449       do i = 1, this%ulag%size()
 
  450          call this%gs_Xh%op(this%ulag%lf(i), gs_op_add)
 
  451          call this%gs_Xh%op(this%vlag%lf(i), gs_op_add)
 
  452          call this%gs_Xh%op(this%wlag%lf(i), gs_op_add)
 
 
  594    real(kind=rp), 
intent(inout) :: t
 
  595    integer, 
intent(inout) :: tstep
 
  596    real(kind=rp), 
intent(in) :: dt
 
  597    type(time_scheme_controller_t), 
intent(inout) :: ext_bdf
 
  598    type(time_step_controller_t), 
intent(in) :: dt_controller
 
  602    type(ksp_monitor_t) :: ksp_results(4)
 
  604    type(field_t), 
pointer :: u_e, v_e, w_e
 
  606    integer :: temp_indices(3)
 
  608    if (this%freeze) 
return 
  610    n = this%dm_Xh%size()
 
  612    call profiler_start_region(
'Fluid', 1)
 
  613    associate(u => this%u, v => this%v, w => this%w, p => this%p, &
 
  614         du => this%du, dv => this%dv, dw => this%dw, dp => this%dp, &
 
  615         u_res => this%u_res, v_res => this%v_res, w_res => this%w_res, &
 
  616         p_res => this%p_res, ax_vel => this%Ax_vel, ax_prs => this%Ax_prs, &
 
  618         c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
 
  619         ulag => this%ulag, vlag => this%vlag, wlag => this%wlag, &
 
  620         msh => this%msh, prs_res => this%prs_res, &
 
  621         source_term => this%source_term, vel_res => this%vel_res, &
 
  622         sumab => this%sumab, makeoifs => this%makeoifs, &
 
  623         makeabf => this%makeabf, makebdf => this%makebdf, &
 
  624         vel_projection_dim => this%vel_projection_dim, &
 
  625         pr_projection_dim => this%pr_projection_dim, &
 
  626         rho => this%rho, mu => this%mu, oifs => this%oifs, &
 
  627         rho_field => this%rho_field, mu_field => this%mu_field, &
 
  628         f_x => this%f_x, f_y => this%f_y, f_z => this%f_z, &
 
  629         if_variable_dt => dt_controller%if_variable_dt, &
 
  630         dt_last_change => dt_controller%dt_last_change)
 
  633      call this%scratch%request_field(u_e, temp_indices(1))
 
  634      call this%scratch%request_field(v_e, temp_indices(2))
 
  635      call this%scratch%request_field(w_e, temp_indices(3))
 
  636      call sumab%compute_fluid(u_e, v_e, w_e, u, v, w, &
 
  637           ulag, vlag, wlag, ext_bdf%advection_coeffs, ext_bdf%nadv)
 
  640      call this%source_term%compute(t, tstep)
 
  643      call bc_list_apply_vector(this%bclst_vel_neumann, f_x%x, f_y%x, f_z%x, &
 
  644           this%dm_Xh%size(), t, tstep)
 
  647      if (this%if_gradient_jump_penalty .eqv. .true.) 
then 
  648         call this%gradient_jump_penalty_u%compute(u, v, w, u)
 
  649         call this%gradient_jump_penalty_v%compute(u, v, w, v)
 
  650         call this%gradient_jump_penalty_w%compute(u, v, w, w)
 
  651         call this%gradient_jump_penalty_u%perform(f_x)
 
  652         call this%gradient_jump_penalty_v%perform(f_y)
 
  653         call this%gradient_jump_penalty_w%perform(f_z)
 
  658         call this%adv%compute(u, v, w, &
 
  659                               this%advx, this%advy, this%advz, &
 
  660                               xh, this%c_Xh, dm_xh%size(), dt)
 
  666         call makeabf%compute_fluid(this%abx1, this%aby1, this%abz1,&
 
  667                                    this%abx2, this%aby2, this%abz2, &
 
  668                                    f_x%x, f_y%x, f_z%x, &
 
  669                                    rho, ext_bdf%advection_coeffs, n)
 
  672         call makeoifs%compute_fluid(this%advx%x, this%advy%x, this%advz%x, &
 
  673                                     f_x%x, f_y%x, f_z%x, &
 
  677         call this%adv%compute(u, v, w, &
 
  679                               xh, this%c_Xh, dm_xh%size())
 
  685         call makeabf%compute_fluid(this%abx1, this%aby1, this%abz1,&
 
  686                              this%abx2, this%aby2, this%abz2, &
 
  687                              f_x%x, f_y%x, f_z%x, &
 
  688                              rho, ext_bdf%advection_coeffs, n)
 
  691         call makebdf%compute_fluid(ulag, vlag, wlag, f_x%x, f_y%x, f_z%x, &
 
  692                              u, v, w, c_xh%B, rho, dt, &
 
  693                              ext_bdf%diffusion_coeffs, ext_bdf%ndiff, n)
 
  703      call this%user_field_bc_vel%update(this%user_field_bc_vel%field_list, &
 
  704              this%user_field_bc_vel%bc_list, this%c_Xh, t, tstep, 
"fluid")
 
  706      call this%bc_apply_vel(t, tstep)
 
  707      call this%bc_apply_prs(t, tstep)
 
  710      call this%update_material_properties()
 
  713      call profiler_start_region(
'Pressure_residual', 18)
 
  714      call prs_res%compute(p, p_res,&
 
  719                           this%bc_prs_surface, this%bc_sym_surface,&
 
  720                           ax_prs, ext_bdf%diffusion_coeffs(1), dt, &
 
  723      call gs_xh%op(p_res, gs_op_add)
 
  724      call bc_list_apply_scalar(this%bclst_dp, p_res%x, p%dof%size(), t, tstep)
 
  725      call profiler_end_region(
'Pressure_residual', 18)
 
  727      call this%proj_prs%pre_solving(p_res%x, tstep, c_xh, n, dt_controller, &
 
  730      call this%pc_prs%update()
 
  731      call profiler_start_region(
'Pressure_solve', 3)
 
  733         this%ksp_prs%solve(ax_prs, dp, p_res%x, n, c_xh, this%bclst_dp, gs_xh)
 
  735      call profiler_end_region(
'Pressure_solve', 3)
 
  737      call this%proj_prs%post_solving(dp%x, ax_prs, c_xh, &
 
  738                                 this%bclst_dp, gs_xh, n, tstep, dt_controller)
 
  740      call field_add2(p, dp, n)
 
  743      call profiler_start_region(
'Velocity_residual', 19)
 
  744      call vel_res%compute(ax_vel, u, v, w, &
 
  745                           u_res, v_res, w_res, &
 
  749                           mu_field, rho_field, ext_bdf%diffusion_coeffs(1), &
 
  752      call gs_xh%op(u_res, gs_op_add)
 
  753      call gs_xh%op(v_res, gs_op_add)
 
  754      call gs_xh%op(w_res, gs_op_add)
 
  756      call bc_list_apply_vector(this%bclst_vel_res,&
 
  757                                u_res%x, v_res%x, w_res%x, dm_xh%size(),&
 
  762      if (neko_bcknd_device .eq. 1) 
then 
  763         call this%bc_field_dirichlet_u%apply_scalar_dev(u_res%x_d, t, tstep)
 
  764         call this%bc_field_dirichlet_v%apply_scalar_dev(v_res%x_d, t, tstep)
 
  765         call this%bc_field_dirichlet_w%apply_scalar_dev(w_res%x_d, t, tstep)
 
  767         call this%bc_field_dirichlet_u%apply_scalar(u_res%x, n, t, tstep)
 
  768         call this%bc_field_dirichlet_v%apply_scalar(v_res%x, n, t, tstep)
 
  769         call this%bc_field_dirichlet_w%apply_scalar(w_res%x, n, t, tstep)
 
  772      call profiler_end_region(
'Velocity_residual', 19)
 
  774      call this%proj_u%pre_solving(u_res%x, tstep, c_xh, n, dt_controller)
 
  775      call this%proj_v%pre_solving(v_res%x, tstep, c_xh, n, dt_controller)
 
  776      call this%proj_w%pre_solving(w_res%x, tstep, c_xh, n, dt_controller)
 
  778      call this%pc_vel%update()
 
  780      call profiler_start_region(
"Velocity_solve", 4)
 
  781      ksp_results(2:4) = this%ksp_vel%solve_coupled(ax_vel, du, dv, dw, &
 
  782           u_res%x, v_res%x, w_res%x, n, c_xh, &
 
  783           this%bclst_du, this%bclst_dv, this%bclst_dw, gs_xh, &
 
  784           this%ksp_vel%max_iter)
 
  785      call profiler_end_region(
"Velocity_solve", 4)
 
  787      call this%proj_u%post_solving(du%x, ax_vel, c_xh, &
 
  788                                 this%bclst_du, gs_xh, n, tstep, dt_controller)
 
  789      call this%proj_v%post_solving(dv%x, ax_vel, c_xh, &
 
  790                                 this%bclst_dv, gs_xh, n, tstep, dt_controller)
 
  791      call this%proj_w%post_solving(dw%x, ax_vel, c_xh, &
 
  792                                 this%bclst_dw, gs_xh, n, tstep, dt_controller)
 
  794      if (neko_bcknd_device .eq. 1) 
then 
  795         call device_opadd2cm(u%x_d, v%x_d, w%x_d, &
 
  796              du%x_d, dv%x_d, dw%x_d, 1.0_rp, n, msh%gdim)
 
  798         call opadd2cm(u%x, v%x, w%x, du%x, dv%x, dw%x, 1.0_rp, n, msh%gdim)
 
  801      if (this%forced_flow_rate) 
then 
  802         call this%vol_flow%adjust( u, v, w, p, u_res, v_res, w_res, p_res, &
 
  803              c_xh, gs_xh, ext_bdf, rho, mu, dt, &
 
  804              this%bclst_dp, this%bclst_du, this%bclst_dv, &
 
  805              this%bclst_dw, this%bclst_vel_res, ax_vel, ax_prs, this%ksp_prs, &
 
  806              this%ksp_vel, this%pc_prs, this%pc_vel, this%ksp_prs%max_iter, &
 
  807              this%ksp_vel%max_iter)
 
  810      call fluid_step_info(tstep, t, dt, ksp_results)
 
  812      call this%scratch%relinquish_field(temp_indices)
 
  815    call profiler_end_region(
'Fluid', 1)