194 crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
195 class(
hsmg_t),
intent(inout),
target :: this
196 type(
coef_t),
intent(in),
target :: coef
197 type(
bc_list_t),
intent(inout),
target :: bclst
198 character(len=:),
intent(inout),
allocatable :: crs_solver, crs_pc
199 logical,
intent(inout) :: crs_monitor
200 integer,
intent(in) :: crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree
202 integer :: lx_crs, lx_mid
203 class(
bc_t),
pointer :: bc_i
205 character(len=LOG_SIZE) :: log_buf
212 if (coef%Xh%lx .lt. 5)
then
213 lx_mid =
max(coef%Xh%lx-1,3)
215 if (coef%Xh%lx .le. 2)
then
216 call neko_error(
'Polynomial order < 2 not supported for hsmg precon')
225 if (this%nlvls .lt. 1e1)
then
226 write(log_buf,
'(A,I1,A)')
'HSMG hierarchy : ', &
227 this%nlvls,
' levels'
228 else if (this%nlvls .lt. 1e2)
then
229 write(log_buf,
'(A,I2,A)')
'HSMG hierarchy : ', &
230 this%nlvls,
' levels'
231 else if (this%nlvls .lt. 1e3)
then
232 write(log_buf,
'(A,I3,A)')
'HSMG hierarchy : ', this%nlvls, &
235 write(log_buf,
'(A,I6,A)')
'HSMG hierarchy : ', this%nlvls, &
239 if (trim(crs_solver) .ne.
'tamg' .or. trim(crs_solver) .eq.
'cheby')
then
240 call neko_log%message(
'Coarse grid solver : (' // trim(crs_solver) // &
241 ', ' // trim(crs_pc) //
')')
243 if (this%niter .lt. 1e1)
then
244 write(log_buf,
'(A,I1)')
'Coarse grid iters. : ', this%niter
245 else if (this%niter .lt. 1e2)
then
246 write(log_buf,
'(A,I2)')
'Coarse grid iters. : ', this%niter
247 else if (this%niter .lt. 1e3)
then
248 write(log_buf,
'(A,I3)')
'Coarse grid iters. : ', this%niter
249 else if (this%niter .lt. 1e4)
then
250 write(log_buf,
'(A,I4)')
'Coarse grid iters. : ', this%niter
252 write(log_buf,
'(A,I6)')
'Coarse grid iters. : ', this%niter
257 call neko_log%message(
'Coarse grid solver : ' // trim(crs_solver) )
261 allocate(this%grids(this%nlvls))
262 allocate(this%w(coef%dof%size()))
263 allocate(this%r(coef%dof%size()))
267 call coef%msh%all_deformed()
270 call this%e%init(coef%dof,
'work array')
271 call this%wf%init(coef%dof,
'work 2')
273 call this%Xh_crs%init(
gll, lx_crs, lx_crs, lx_crs)
274 call this%dm_crs%init(coef%msh, this%Xh_crs)
275 call this%gs_crs%init(this%dm_crs)
276 call this%e_crs%init(this%dm_crs,
'work crs')
281 call this%Xh_mg%init(
gll, lx_mid, lx_mid, lx_mid)
282 call this%dm_mg%init(coef%msh, this%Xh_mg)
283 call this%gs_mg%init(this%dm_mg)
284 call this%e_mg%init(this%dm_mg,
'work midl')
288 call ax_helm_allocator(this%ax, type_name =
"standard")
290 call this%bc_crs%init_base(this%c_crs)
291 call this%bc_mg%init_base(this%c_mg)
292 call this%bc_reg%init_base(coef)
293 if (bclst%size() .gt. 0)
then
294 do i = 1, bclst%size()
296 call this%bc_reg%mark_facets(bc_i%marked_facet)
298 call this%bc_crs%mark_facets(bc_i%marked_facet)
300 call this%bc_mg%mark_facets(bc_i%marked_facet)
303 call this%bc_reg%finalize()
304 call this%bc_crs%finalize()
305 call this%bc_mg%finalize()
307 call this%bc_projector_reg%mark(this%bc_reg)
308 call this%bc_projector_crs%mark(this%bc_crs)
309 call this%bc_projector_mg%mark(this%bc_mg)
311 call this%schwarz%init(coef%Xh, coef%dof, coef%gs_h, &
312 this%bc_projector_reg, coef%msh)
313 call this%schwarz_mg%init(this%Xh_mg, this%dm_mg, this%gs_mg,&
314 this%bc_projector_mg, coef%msh)
316 call this%interp_fine_mid%init(coef%Xh, this%Xh_mg)
317 call this%interp_mid_crs%init(this%Xh_mg, this%Xh_crs)
320 this%bc_projector_reg, this%schwarz, this%e, this%grids, 3)
321 call hsmg_fill_grid(this%dm_mg, this%gs_mg, this%Xh_mg, this%c_mg, &
322 this%bc_projector_mg, this%schwarz_mg, this%e_mg, this%grids, 2)
324 this%c_crs, this%bc_projector_crs, this%schwarz_crs, &
325 this%e_crs, this%grids, 1)
339 if (trim(crs_solver) .eq.
'tamg')
then
340 allocate(this%amg_solver)
341 call this%amg_solver%init(this%ax, this%grids(1)%e%Xh, &
342 this%grids(1)%coef, this%msh, this%grids(1)%gs_h, crs_tamg_lvls, &
343 this%grids(1)%bc_projector, crs_tamg_itrs, crs_tamg_cheby_degree)
346 call precon_allocator(this%pc_crs, crs_pc)
348 select type (pc => this%pc_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)
354 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
357 call krylov_solver_factory(this%crs_solver, &
359 m = this%pc_crs, monitor = crs_monitor)
482 integer,
intent(in) :: n
483 class(
hsmg_t),
intent(inout) :: this
484 real(kind=
rp),
dimension(n),
intent(inout) :: z
485 real(kind=
rp),
dimension(n),
intent(inout) :: r
486 type(c_ptr) :: z_d, r_d
488 integer :: thrdid, nthrds
496 call this%bc_projector_reg%apply(this%r, n)
500 call device_col2(this%r_d, this%grids(3)%coef%mult_d, &
501 this%grids(3)%dof%size())
503 call this%interp_fine_mid%map(this%e%x, this%r, &
504 this%msh%nelv, this%grids(2)%Xh)
505 call this%grids(2)%gs_h%op(this%e%x, &
506 this%grids(2)%dof%size(), gs_op_add, this%gs_event)
510 call this%bc_projector_reg%apply(this%r, n)
511 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
512 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
514 call device_col2(this%w_d, this%grids(2)%coef%mult_d, &
515 this%grids(2)%dof%size())
517 call this%interp_mid_crs%map(this%wf%x, this%w, this%msh%nelv, &
520 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
521 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
530 if (thrdid .eq. 0)
then
532 call this%grids(3)%schwarz%compute(z, this%r)
533 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
536 if (nthrds .eq. 1 .or. thrdid .eq. 1)
then
538 call this%grids(1)%gs_h%op(this%wf%x, &
539 this%grids(1)%dof%size(), gs_op_add, this%gs_event)
541 call this%grids(1)%bc_projector%apply(this%wf%x, &
542 this%grids(1)%dof%size())
544 if (
allocated(this%amg_solver))
then
545 call this%amg_solver%solve(this%grids(1)%e%x, this%wf%x, &
546 this%grids(1)%dof%size())
548 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, &
550 this%grids(1)%dof%size(), &
551 this%grids(1)%coef, &
552 this%grids(1)%bc_projector, &
553 this%grids(1)%gs_h, this%niter)
556 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x,&
557 this%grids(1)%dof%size())
562 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
563 this%msh%nelv, this%grids(2)%Xh)
564 call device_add2(this%grids(2)%e%x_d, this%w_d, this%grids(2)%dof%size())
566 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
567 this%msh%nelv, this%grids(3)%Xh)
568 call device_add2(z_d, this%w_d, this%grids(3)%dof%size())
569 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), &
570 gs_op_add, this%gs_event)
573 this%grids(3)%dof%size())
576 call copy(this%r, r, n)
579 call this%grids(3)%schwarz%compute(z, this%r)
581 call col2(this%r, this%grids(3)%coef%mult, &
582 this%grids(3)%dof%size())
584 call this%interp_fine_mid%map(this%w, this%r, &
585 this%msh%nelv, this%grids(2)%Xh)
586 call this%grids(2)%gs_h%op(this%w, this%grids(2)%dof%size(), gs_op_add)
588 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
589 call col2(this%w, this%grids(2)%coef%mult, this%grids(2)%dof%size())
591 call this%interp_mid_crs%map(this%r, this%w, &
592 this%msh%nelv, this%grids(1)%Xh)
595 call this%grids(1)%gs_h%op(this%r, this%grids(1)%dof%size(), gs_op_add)
596 call this%grids(1)%bc_projector%apply(this%r, this%grids(1)%dof%size())
599 if (
allocated(this%amg_solver))
then
600 call this%amg_solver%solve(this%grids(1)%e%x, this%r, &
601 this%grids(1)%dof%size())
603 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, this%r, &
604 this%grids(1)%dof%size(), &
605 this%grids(1)%coef, &
606 this%grids(1)%bc_projector, &
607 this%grids(1)%gs_h, this%niter)
611 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x, &
612 this%grids(1)%dof%size())
615 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
616 this%msh%nelv, this%grids(2)%Xh)
617 call add2(this%grids(2)%e%x, this%w, this%grids(2)%dof%size())
619 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
620 this%msh%nelv, this%grids(3)%Xh)
621 call add2(z, this%w, this%grids(3)%dof%size())
622 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), gs_op_add)
623 call col2(z, this%grids(3)%coef%mult, this%grids(3)%dof%size())