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)
481 integer,
intent(in) :: n
482 class(
hsmg_t),
intent(inout) :: this
483 real(kind=
rp),
dimension(n),
intent(inout) :: z
484 real(kind=
rp),
dimension(n),
intent(inout) :: r
485 type(c_ptr) :: z_d, r_d
487 integer :: thrdid, nthrds
495 call this%bc_projector_reg%apply(this%r, n)
499 call device_col2(this%r_d, this%grids(3)%coef%mult_d, &
500 this%grids(3)%dof%size())
502 call this%interp_fine_mid%map(this%e%x, this%r, &
503 this%msh%nelv, this%grids(2)%Xh)
504 call this%grids(2)%gs_h%op(this%e%x, &
505 this%grids(2)%dof%size(), gs_op_add, this%gs_event)
509 call this%bc_projector_reg%apply(this%r, n)
510 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
511 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
513 call device_col2(this%w_d, this%grids(2)%coef%mult_d, &
514 this%grids(2)%dof%size())
516 call this%interp_mid_crs%map(this%wf%x, this%w, this%msh%nelv, &
519 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
520 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
529 if (thrdid .eq. 0)
then
531 call this%grids(3)%schwarz%compute(z, this%r)
532 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
535 if (nthrds .eq. 1 .or. thrdid .eq. 1)
then
537 call this%grids(1)%gs_h%op(this%wf%x, &
538 this%grids(1)%dof%size(), gs_op_add, this%gs_event)
540 call this%grids(1)%bc_projector%apply(this%wf%x, &
541 this%grids(1)%dof%size())
543 if (
allocated(this%amg_solver))
then
544 call this%amg_solver%solve(this%grids(1)%e%x, this%wf%x, &
545 this%grids(1)%dof%size())
547 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, &
549 this%grids(1)%dof%size(), &
550 this%grids(1)%coef, &
551 this%grids(1)%bc_projector, &
552 this%grids(1)%gs_h, this%niter)
555 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x,&
556 this%grids(1)%dof%size())
561 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
562 this%msh%nelv, this%grids(2)%Xh)
563 call device_add2(this%grids(2)%e%x_d, this%w_d, this%grids(2)%dof%size())
565 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
566 this%msh%nelv, this%grids(3)%Xh)
567 call device_add2(z_d, this%w_d, this%grids(3)%dof%size())
568 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), &
569 gs_op_add, this%gs_event)
572 this%grids(3)%dof%size())
575 call copy(this%r, r, n)
578 call this%grids(3)%schwarz%compute(z, this%r)
580 call col2(this%r, this%grids(3)%coef%mult, &
581 this%grids(3)%dof%size())
583 call this%interp_fine_mid%map(this%w, this%r, &
584 this%msh%nelv, this%grids(2)%Xh)
585 call this%grids(2)%gs_h%op(this%w, this%grids(2)%dof%size(), gs_op_add)
587 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
588 call col2(this%w, this%grids(2)%coef%mult, this%grids(2)%dof%size())
590 call this%interp_mid_crs%map(this%r, this%w, &
591 this%msh%nelv, this%grids(1)%Xh)
594 call this%grids(1)%gs_h%op(this%r, this%grids(1)%dof%size(), gs_op_add)
595 call this%grids(1)%bc_projector%apply(this%r, this%grids(1)%dof%size())
598 if (
allocated(this%amg_solver))
then
599 call this%amg_solver%solve(this%grids(1)%e%x, this%r, &
600 this%grids(1)%dof%size())
602 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, this%r, &
603 this%grids(1)%dof%size(), &
604 this%grids(1)%coef, &
605 this%grids(1)%bc_projector, &
606 this%grids(1)%gs_h, this%niter)
610 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x, &
611 this%grids(1)%dof%size())
614 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
615 this%msh%nelv, this%grids(2)%Xh)
616 call add2(this%grids(2)%e%x, this%w, this%grids(2)%dof%size())
618 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
619 this%msh%nelv, this%grids(3)%Xh)
620 call add2(z, this%w, this%grids(3)%dof%size())
621 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), gs_op_add)
622 call col2(z, this%grids(3)%coef%mult, this%grids(3)%dof%size())