170 subroutine scalar_pnpn_init(this, msh, coef, gs, params, numerics_params, &
171 user, chkp, ulag, vlag, wlag, time_scheme, rho)
172 class(scalar_pnpn_t),
target,
intent(inout) :: this
173 type(
mesh_t),
target,
intent(in) :: msh
174 type(
coef_t),
target,
intent(in) :: coef
175 type(
gs_t),
target,
intent(inout) :: gs
176 type(json_file),
target,
intent(inout) :: params
177 type(json_file),
target,
intent(inout) :: numerics_params
178 type(
user_t),
target,
intent(in) :: user
179 type(
chkp_t),
target,
intent(inout) :: chkp
182 type(
field_t),
target,
intent(in) :: rho
184 class(
bc_t),
pointer :: bc_i
185 character(len=15),
parameter :: scheme =
'Modular (Pn/Pn)'
191 call this%scheme_init(msh, coef, gs, params, scheme,
user, rho)
194 call ax_helm_factory(this%ax, full_formulation = .false.)
197 call scalar_residual_factory(this%res)
200 call rhs_maker_ext_fctry(this%makeext)
203 call rhs_maker_bdf_fctry(this%makebdf)
206 call rhs_maker_oifs_fctry(this%makeoifs)
209 associate(xh_lx => this%Xh%lx, xh_ly => this%Xh%ly, xh_lz => this%Xh%lz, &
210 dm_xh => this%dm_Xh, nelv => this%msh%nelv)
212 call this%s_res%init(dm_xh,
"s_res")
214 call this%abx1%init(dm_xh, trim(this%name)//
"_abx1")
215 call neko_field_registry%add_field(dm_xh, trim(this%name)//
"_abx1", ignore_existing = .true.)
217 call this%abx2%init(dm_xh, trim(this%name)//
"_abx2")
218 call neko_field_registry%add_field(dm_xh, trim(this%name)//
"_abx2", ignore_existing = .true.)
220 call this%advs%init(dm_xh,
"advs")
222 call this%ds%init(dm_xh,
'ds')
227 call this%setup_bcs_(
user)
230 call this%bc_res%init(this%c_Xh, params)
231 do i = 1, this%bcs%size()
232 if (this%bcs%strong(i))
then
233 bc_i => this%bcs%get(i)
234 call this%bc_res%mark_facets(bc_i%marked_facet)
239 call this%bc_res%finalize()
241 call this%bclst_ds%init()
242 call this%bclst_ds%append(this%bc_res)
246 call this%proj_s%init(this%dm_Xh%size(), this%projection_dim, &
247 this%projection_activ_step)
256 call advection_factory(this%adv, numerics_params, this%c_Xh, &
257 ulag, vlag, wlag, this%chkp%dtlag, &
263 subroutine scalar_pnpn_restart(this, chkp)
264 class(scalar_pnpn_t),
target,
intent(inout) :: this
265 type(chkp_t),
intent(inout) :: chkp
266 real(kind=rp) :: dtlag(10), tlag(10)
268 type(field_t),
pointer :: temp_field
272 n = this%s%dof%size()
276 call col2(this%s%x, this%c_Xh%mult, n)
277 call col2(this%slag%lf(1)%x, this%c_Xh%mult, n)
278 call col2(this%slag%lf(2)%x, this%c_Xh%mult, n)
279 if (neko_bcknd_device .eq. 1)
then
280 call device_memcpy(this%s%x, this%s%x_d, &
281 n, host_to_device, sync = .false.)
282 call device_memcpy(this%slag%lf(1)%x, this%slag%lf(1)%x_d, &
283 n, host_to_device, sync = .false.)
284 call device_memcpy(this%slag%lf(2)%x, this%slag%lf(2)%x_d, &
285 n, host_to_device, sync = .false.)
286 call device_memcpy(this%abx1%x, this%abx1%x_d, &
287 n, host_to_device, sync = .false.)
288 call device_memcpy(this%abx2%x, this%abx2%x_d, &
289 n, host_to_device, sync = .false.)
290 call device_memcpy(this%advs%x, this%advs%x_d, &
291 n, host_to_device, sync = .false.)
294 call this%gs_Xh%op(this%s, gs_op_add)
295 call this%gs_Xh%op(this%slag%lf(1), gs_op_add)
296 call this%gs_Xh%op(this%slag%lf(2), gs_op_add)
340 subroutine scalar_pnpn_step(this, time, ext_bdf, dt_controller, &
342 class(scalar_pnpn_t),
intent(inout) :: this
343 type(time_state_t),
intent(in) :: time
344 type(time_scheme_controller_t),
intent(in) :: ext_bdf
345 type(time_step_controller_t),
intent(in) :: dt_controller
346 type(ksp_monitor_t),
intent(inout) :: ksp_results
350 n = this%dm_Xh%size()
352 call profiler_start_region(trim(this%name), 2)
353 associate(u => this%u, v => this%v, w => this%w, s => this%s, &
354 cp => this%cp, rho => this%rho, lambda_tot => this%lambda_tot, &
356 s_res => this%s_res, &
357 ax => this%Ax, f_xh => this%f_Xh, xh => this%Xh, &
358 c_xh => this%c_Xh, dm_xh => this%dm_Xh, gs_xh => this%gs_Xh, &
359 slag => this%slag, oifs => this%oifs, &
360 projection_dim => this%projection_dim, &
361 msh => this%msh, res => this%res, makeoifs => this%makeoifs, &
362 makeext => this%makeext, makebdf => this%makebdf, &
363 t => time%t, tstep => time%tstep, dt => time%dt)
366 call print_debug(this)
368 call this%source_term%compute(time)
371 call this%bcs%apply_scalar(this%f_Xh%x, dm_xh%size(), time, .false.)
375 call this%adv%compute_scalar(u, v, w, s, this%advs, &
376 xh, this%c_Xh, dm_xh%size())
378 call makeext%compute_scalar(this%abx1, this%abx2, f_xh%x, &
379 rho%x(1,1,1,1), ext_bdf%advection_coeffs, n)
381 call makeoifs%compute_scalar(this%advs%x, f_xh%x, rho%x(1,1,1,1), dt,&
385 call this%adv%compute_scalar(u, v, w, s, f_xh, &
386 xh, this%c_Xh, dm_xh%size())
392 call makeext%compute_scalar(this%abx1, this%abx2, f_xh%x, &
393 rho%x(1,1,1,1), ext_bdf%advection_coeffs, n)
396 call makebdf%compute_scalar(slag, f_xh%x, s, c_xh%B, rho%x(1,1,1,1), &
397 dt, ext_bdf%diffusion_coeffs, ext_bdf%ndiff, n)
403 call this%bcs%apply_scalar(this%s%x, this%dm_Xh%size(), time, .true.)
406 call this%update_material_properties(time)
409 call profiler_start_region(trim(this%name) //
'_residual', 20)
410 call res%compute(ax, s, s_res, f_xh, c_xh, msh, xh, lambda_tot, &
411 rho%x(1,1,1,1)*cp%x(1,1,1,1), ext_bdf%diffusion_coeffs(1), dt, &
414 call gs_xh%op(s_res, gs_op_add)
417 call this%bclst_ds%apply_scalar(s_res%x, dm_xh%size())
419 call profiler_end_region(trim(this%name) //
'_residual', 20)
421 call this%proj_s%pre_solving(s_res%x, tstep, c_xh, n, dt_controller)
423 call this%pc%update()
424 call profiler_start_region(trim(this%name) //
'_solve', 21)
425 ksp_results = this%ksp%solve(ax, ds, s_res%x, n, &
426 c_xh, this%bclst_ds, gs_xh)
427 ksp_results%name = trim(this%name)
428 call profiler_end_region(trim(this%name) //
'_solve', 21)
430 call this%proj_s%post_solving(ds%x, ax, c_xh, this%bclst_ds, gs_xh, &
431 n, tstep, dt_controller)
434 if (neko_bcknd_device .eq. 1)
then
435 call device_add2s2(s%x_d, ds%x_d, 1.0_rp, n)
437 call add2s2(s%x, ds%x, 1.0_rp, n)
441 call profiler_end_region(trim(this%name), 2)
464 subroutine scalar_pnpn_setup_bcs_(this, user)
465 class(scalar_pnpn_t),
intent(inout) :: this
466 type(user_t),
target,
intent(in) :: user
467 integer :: i, j, n_bcs, zone_size, global_zone_size, ierr
468 type(json_core) :: core
469 type(json_value),
pointer :: bc_object
470 type(json_file) :: bc_subdict
471 class(bc_t),
pointer :: bc_i
474 logical,
allocatable :: marked_zones(:)
475 integer,
allocatable :: zone_indices(:)
477 if (this%params%valid_path(
'boundary_conditions'))
then
478 call this%params%info(
'boundary_conditions', &
480 call this%params%get_core(core)
481 call this%params%get(
'boundary_conditions', bc_object, found)
483 call this%bcs%init(n_bcs)
485 allocate(marked_zones(
size(this%msh%labeled_zones)))
486 marked_zones = .false.
490 call json_extract_item(core, bc_object, i, bc_subdict)
495 call json_get(bc_subdict,
"zone_indices", zone_indices)
497 do j = 1,
size(zone_indices)
498 zone_size = this%msh%labeled_zones(zone_indices(j))%size
499 call mpi_allreduce(zone_size, global_zone_size, 1, &
500 mpi_integer, mpi_max, neko_comm, ierr)
502 if (global_zone_size .eq. 0)
then
503 write(error_unit,
'(A, A, I0, A, A, I0, A)')
"*** ERROR ***: ",&
504 "Zone index ", zone_indices(j), &
505 " is invalid as this zone has 0 size, meaning it ", &
506 "does not exist in the mesh. Check scalar boundary condition ", &
511 if (marked_zones(zone_indices(j)) .eqv. .true.)
then
512 write(error_unit,
'(A, A, I0, A, A, A, A)')
"*** ERROR ***: ", &
513 "Zone with index ", zone_indices(j), &
514 " has already been assigned a boundary condition. ", &
515 "Please check your boundary_conditions entry for the ", &
516 "scalar and make sure that each zone index appears only ",&
517 "in a single boundary condition."
520 marked_zones(zone_indices(j)) = .true.
526 call bc_factory(bc_i, this, bc_subdict, this%c_Xh,
user)
527 call this%bcs%append(bc_i)
531 do i = 1,
size(this%msh%labeled_zones)
532 if ((this%msh%labeled_zones(i)%size .gt. 0) .and. &
533 (marked_zones(i) .eqv. .false.))
then
534 write(error_unit,
'(A, A, I0)')
"*** ERROR ***: ", &
535 "No scalar boundary condition assigned to zone ", i
541 do i = 1,
size(this%msh%labeled_zones)
542 if (this%msh%labeled_zones(i)%size .gt. 0)
then
543 write(error_unit,
'(A, A, A)')
"*** ERROR ***: ", &
544 "No boundary_conditions entry in the case file for scalar ", &