190 crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
191 class(
hsmg_t),
intent(inout),
target :: this
192 type(
coef_t),
intent(in),
target :: coef
193 type(
bc_list_t),
intent(inout),
target :: bclst
194 character(len=:),
intent(inout),
allocatable :: crs_solver, crs_pc
195 logical,
intent(inout) :: crs_monitor
196 integer,
intent(in) :: crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree
198 integer :: lx_crs, lx_mid
199 class(
bc_t),
pointer :: bc_i
201 character(len=LOG_SIZE) :: log_buf
207 if (coef%Xh%lx .lt. 5)
then
208 lx_mid =
max(coef%Xh%lx-1,3)
210 if (coef%Xh%lx .le. 2)
then
211 call neko_error(
'Polynomial order < 2 not supported for hsmg precon')
220 if (this%nlvls .lt. 1e1)
then
221 write(log_buf,
'(A,I1,A)')
'HSMG hierarchy : ', &
222 this%nlvls,
' levels'
223 else if (this%nlvls .lt. 1e2)
then
224 write(log_buf,
'(A,I2,A)')
'HSMG hierarchy : ', &
225 this%nlvls,
' levels'
226 else if (this%nlvls .lt. 1e3)
then
227 write(log_buf,
'(A,I3,A)')
'HSMG hierarchy : ', this%nlvls, &
230 write(log_buf,
'(A,I6,A)')
'HSMG hierarchy : ', this%nlvls, &
234 if (trim(crs_solver) .ne.
'tamg' .or. trim(crs_solver) .eq.
'cheby')
then
235 call neko_log%message(
'Coarse grid solver : (' // trim(crs_solver) // &
236 ', ' // trim(crs_pc) //
')')
238 if (this%niter .lt. 1e1)
then
239 write(log_buf,
'(A,I1)')
'Coarse grid iters. : ', this%niter
240 else if (this%niter .lt. 1e2)
then
241 write(log_buf,
'(A,I2)')
'Coarse grid iters. : ', this%niter
242 else if (this%niter .lt. 1e3)
then
243 write(log_buf,
'(A,I3)')
'Coarse grid iters. : ', this%niter
244 else if (this%niter .lt. 1e4)
then
245 write(log_buf,
'(A,I4)')
'Coarse grid iters. : ', this%niter
247 write(log_buf,
'(A,I6)')
'Coarse grid iters. : ', this%niter
252 call neko_log%message(
'Coarse grid solver : ' // trim(crs_solver) )
256 allocate(this%grids(this%nlvls))
257 allocate(this%w(coef%dof%size()))
258 allocate(this%r(coef%dof%size()))
262 call coef%msh%all_deformed()
265 call this%e%init(coef%dof,
'work array')
266 call this%wf%init(coef%dof,
'work 2')
268 call this%Xh_crs%init(
gll, lx_crs, lx_crs, lx_crs)
269 call this%dm_crs%init(coef%msh, this%Xh_crs)
270 call this%gs_crs%init(this%dm_crs)
271 call this%e_crs%init(this%dm_crs,
'work crs')
272 call this%c_crs%init(this%gs_crs)
274 call this%Xh_mg%init(
gll, lx_mid, lx_mid, lx_mid)
275 call this%dm_mg%init(coef%msh, this%Xh_mg)
276 call this%gs_mg%init(this%dm_mg)
277 call this%e_mg%init(this%dm_mg,
'work midl')
278 call this%c_mg%init(this%gs_mg)
281 call ax_helm_factory(this%ax, full_formulation = .false.)
283 call this%bc_crs%init_base(this%c_crs)
284 call this%bc_mg%init_base(this%c_mg)
285 call this%bc_reg%init_base(coef)
286 if (bclst%size() .gt. 0)
then
287 do i = 1, bclst%size()
289 call this%bc_reg%mark_facets(bc_i%marked_facet)
291 call this%bc_crs%mark_facets(bc_i%marked_facet)
293 call this%bc_mg%mark_facets(bc_i%marked_facet)
296 call this%bc_reg%finalize()
297 call this%bc_crs%finalize()
298 call this%bc_mg%finalize()
300 call this%bclst_reg%init()
301 call this%bclst_crs%init()
302 call this%bclst_mg%init()
304 call this%bclst_reg%append(this%bc_reg)
305 call this%bclst_crs%append(this%bc_crs)
306 call this%bclst_mg%append(this%bc_mg)
308 call this%schwarz%init(coef%Xh, coef%dof, coef%gs_h, &
309 this%bclst_reg, coef%msh)
310 call this%schwarz_mg%init(this%Xh_mg, this%dm_mg, this%gs_mg,&
311 this%bclst_mg, coef%msh)
313 call this%interp_fine_mid%init(coef%Xh, this%Xh_mg)
314 call this%interp_mid_crs%init(this%Xh_mg, this%Xh_crs)
317 this%bclst_reg, this%schwarz, this%e, this%grids, 3)
318 call hsmg_fill_grid(this%dm_mg, this%gs_mg, this%Xh_mg, this%c_mg, &
319 this%bclst_mg, this%schwarz_mg, this%e_mg, &
322 this%c_crs, this%bclst_crs, this%schwarz_crs, &
323 this%e_crs, this%grids, 1)
337 if (trim(crs_solver) .eq.
'tamg')
then
338 allocate(this%amg_solver)
339 call this%amg_solver%init(this%ax, this%grids(1)%e%Xh, &
340 this%grids(1)%coef, this%msh, this%grids(1)%gs_h, crs_tamg_lvls, &
341 this%grids(1)%bclst, crs_tamg_itrs, crs_tamg_cheby_degree)
344 call precon_factory(this%pc_crs, crs_pc)
346 select type (pc => this%pc_crs)
348 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
350 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
352 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
355 call krylov_solver_factory(this%crs_solver, &
357 m = this%pc_crs, monitor = crs_monitor)
474 integer,
intent(in) :: n
475 class(
hsmg_t),
intent(inout) :: this
476 real(kind=
rp),
dimension(n),
intent(inout) :: z
477 real(kind=
rp),
dimension(n),
intent(inout) :: r
478 type(c_ptr) :: z_d, r_d
480 integer :: thrdid, nthrds
488 call this%bclst_reg%apply_scalar(this%r, n)
492 call device_col2(this%r_d, this%grids(3)%coef%mult_d, &
493 this%grids(3)%dof%size())
495 call this%interp_fine_mid%map(this%e%x, this%r, &
496 this%msh%nelv, this%grids(2)%Xh)
497 call this%grids(2)%gs_h%op(this%e%x, &
498 this%grids(2)%dof%size(), gs_op_add, this%gs_event)
502 call this%bclst_reg%apply_scalar(this%r, n)
503 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
504 call this%bclst_mg%apply_scalar(this%w, this%grids(2)%dof%size())
506 call device_col2(this%w_d, this%grids(2)%coef%mult_d, &
507 this%grids(2)%dof%size())
509 call this%interp_mid_crs%map(this%wf%x, this%w, this%msh%nelv, &
512 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
513 call this%bclst_mg%apply_scalar(this%w, this%grids(2)%dof%size())
522 if (thrdid .eq. 0)
then
524 call this%grids(3)%schwarz%compute(z, this%r)
525 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
528 if (nthrds .eq. 1 .or. thrdid .eq. 1)
then
530 call this%grids(1)%gs_h%op(this%wf%x, &
531 this%grids(1)%dof%size(), gs_op_add, this%gs_event)
533 call this%grids(1)%bclst%apply_scalar(this%wf%x, &
534 this%grids(1)%dof%size())
536 if (
allocated(this%amg_solver))
then
537 call this%amg_solver%solve(this%grids(1)%e%x, this%wf%x, &
538 this%grids(1)%dof%size())
540 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, &
542 this%grids(1)%dof%size(), &
543 this%grids(1)%coef, &
544 this%grids(1)%bclst, &
545 this%grids(1)%gs_h, this%niter)
548 call this%grids(1)%bclst%apply_scalar(this%grids(1)%e%x,&
549 this%grids(1)%dof%size())
554 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
555 this%msh%nelv, this%grids(2)%Xh)
556 call device_add2(this%grids(2)%e%x_d, this%w_d, this%grids(2)%dof%size())
558 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
559 this%msh%nelv, this%grids(3)%Xh)
560 call device_add2(z_d, this%w_d, this%grids(3)%dof%size())
561 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), &
562 gs_op_add, this%gs_event)
565 this%grids(3)%dof%size())
568 call copy(this%r, r, n)
571 call this%grids(3)%schwarz%compute(z, this%r)
573 call col2(this%r, this%grids(3)%coef%mult, &
574 this%grids(3)%dof%size())
576 call this%interp_fine_mid%map(this%w, this%r, &
577 this%msh%nelv, this%grids(2)%Xh)
578 call this%grids(2)%gs_h%op(this%w, this%grids(2)%dof%size(), gs_op_add)
580 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
581 call col2(this%w, this%grids(2)%coef%mult, this%grids(2)%dof%size())
583 call this%interp_mid_crs%map(this%r, this%w, &
584 this%msh%nelv, this%grids(1)%Xh)
587 call this%grids(1)%gs_h%op(this%r, this%grids(1)%dof%size(), gs_op_add)
588 call this%grids(1)%bclst%apply(this%r, this%grids(1)%dof%size())
591 if (
allocated(this%amg_solver))
then
592 call this%amg_solver%solve(this%grids(1)%e%x, this%r, &
593 this%grids(1)%dof%size())
595 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, this%r, &
596 this%grids(1)%dof%size(), &
597 this%grids(1)%coef, &
598 this%grids(1)%bclst, &
599 this%grids(1)%gs_h, this%niter)
603 call this%grids(1)%bclst%apply_scalar(this%grids(1)%e%x, &
604 this%grids(1)%dof%size())
607 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
608 this%msh%nelv, this%grids(2)%Xh)
609 call add2(this%grids(2)%e%x, this%w, this%grids(2)%dof%size())
611 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
612 this%msh%nelv, this%grids(3)%Xh)
613 call add2(z, this%w, this%grids(3)%dof%size())
614 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), gs_op_add)
615 call col2(z, this%grids(3)%coef%mult, this%grids(3)%dof%size())