192 crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
193 class(
hsmg_t),
intent(inout),
target :: this
194 type(
coef_t),
intent(in),
target :: coef
195 type(
bc_list_t),
intent(inout),
target :: bclst
196 character(len=:),
intent(inout),
allocatable :: crs_solver, crs_pc
197 logical,
intent(inout) :: crs_monitor
198 integer,
intent(in) :: crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree
200 integer :: lx_crs, lx_mid
201 class(
bc_t),
pointer :: bc_i
203 character(len=LOG_SIZE) :: log_buf
210 if (coef%Xh%lx .lt. 5)
then
211 lx_mid =
max(coef%Xh%lx-1,3)
213 if (coef%Xh%lx .le. 2)
then
214 call neko_error(
'Polynomial order < 2 not supported for hsmg precon')
223 if (this%nlvls .lt. 1e1)
then
224 write(log_buf,
'(A,I1,A)')
'HSMG hierarchy : ', &
225 this%nlvls,
' levels'
226 else if (this%nlvls .lt. 1e2)
then
227 write(log_buf,
'(A,I2,A)')
'HSMG hierarchy : ', &
228 this%nlvls,
' levels'
229 else if (this%nlvls .lt. 1e3)
then
230 write(log_buf,
'(A,I3,A)')
'HSMG hierarchy : ', this%nlvls, &
233 write(log_buf,
'(A,I6,A)')
'HSMG hierarchy : ', this%nlvls, &
237 if (trim(crs_solver) .ne.
'tamg' .or. trim(crs_solver) .eq.
'cheby')
then
238 call neko_log%message(
'Coarse grid solver : (' // trim(crs_solver) // &
239 ', ' // trim(crs_pc) //
')')
241 if (this%niter .lt. 1e1)
then
242 write(log_buf,
'(A,I1)')
'Coarse grid iters. : ', this%niter
243 else if (this%niter .lt. 1e2)
then
244 write(log_buf,
'(A,I2)')
'Coarse grid iters. : ', this%niter
245 else if (this%niter .lt. 1e3)
then
246 write(log_buf,
'(A,I3)')
'Coarse grid iters. : ', this%niter
247 else if (this%niter .lt. 1e4)
then
248 write(log_buf,
'(A,I4)')
'Coarse grid iters. : ', this%niter
250 write(log_buf,
'(A,I6)')
'Coarse grid iters. : ', this%niter
255 call neko_log%message(
'Coarse grid solver : ' // trim(crs_solver) )
259 allocate(this%grids(this%nlvls))
260 allocate(this%w(coef%dof%size()))
261 allocate(this%r(coef%dof%size()))
265 call coef%msh%all_deformed()
268 call this%e%init(coef%dof,
'work array')
269 call this%wf%init(coef%dof,
'work 2')
271 call this%Xh_crs%init(
gll, lx_crs, lx_crs, lx_crs)
272 call this%dm_crs%init(coef%msh, this%Xh_crs)
273 call this%gs_crs%init(this%dm_crs)
274 call this%e_crs%init(this%dm_crs,
'work crs')
275 call this%c_crs%init(this%gs_crs)
277 call this%Xh_mg%init(
gll, lx_mid, lx_mid, lx_mid)
278 call this%dm_mg%init(coef%msh, this%Xh_mg)
279 call this%gs_mg%init(this%dm_mg)
280 call this%e_mg%init(this%dm_mg,
'work midl')
281 call this%c_mg%init(this%gs_mg)
284 call ax_helm_factory(this%ax, full_formulation = .false.)
286 call this%bc_crs%init_base(this%c_crs)
287 call this%bc_mg%init_base(this%c_mg)
288 call this%bc_reg%init_base(coef)
289 if (bclst%size() .gt. 0)
then
290 do i = 1, bclst%size()
292 call this%bc_reg%mark_facets(bc_i%marked_facet)
294 call this%bc_crs%mark_facets(bc_i%marked_facet)
296 call this%bc_mg%mark_facets(bc_i%marked_facet)
299 call this%bc_reg%finalize()
300 call this%bc_crs%finalize()
301 call this%bc_mg%finalize()
303 call this%bclst_reg%init()
304 call this%bclst_crs%init()
305 call this%bclst_mg%init()
307 call this%bclst_reg%append(this%bc_reg)
308 call this%bclst_crs%append(this%bc_crs)
309 call this%bclst_mg%append(this%bc_mg)
311 call this%schwarz%init(coef%Xh, coef%dof, coef%gs_h, &
312 this%bclst_reg, coef%msh)
313 call this%schwarz_mg%init(this%Xh_mg, this%dm_mg, this%gs_mg,&
314 this%bclst_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%bclst_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%bclst_mg, this%schwarz_mg, this%e_mg, &
325 this%c_crs, this%bclst_crs, this%schwarz_crs, &
326 this%e_crs, this%grids, 1)
340 if (trim(crs_solver) .eq.
'tamg')
then
341 allocate(this%amg_solver)
342 call this%amg_solver%init(this%ax, this%grids(1)%e%Xh, &
343 this%grids(1)%coef, this%msh, this%grids(1)%gs_h, crs_tamg_lvls, &
344 this%grids(1)%bclst, crs_tamg_itrs, crs_tamg_cheby_degree)
347 call precon_factory(this%pc_crs, crs_pc)
349 select type (pc => this%pc_crs)
351 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
353 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
355 call pc%init(this%c_crs, this%dm_crs, this%gs_crs)
358 call krylov_solver_factory(this%crs_solver, &
360 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%bclst_reg%apply_scalar(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%bclst_reg%apply_scalar(this%r, n)
511 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
512 call this%bclst_mg%apply_scalar(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%bclst_mg%apply_scalar(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)%bclst%apply_scalar(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)%bclst, &
553 this%grids(1)%gs_h, this%niter)
556 call this%grids(1)%bclst%apply_scalar(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)%bclst%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)%bclst, &
607 this%grids(1)%gs_h, this%niter)
611 call this%grids(1)%bclst%apply_scalar(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())