Neko 1.99.11
A portable framework for high-order spectral element flow simulations
Loading...
Searching...
No Matches
pc_hsmg.f90
Go to the documentation of this file.
1! Copyright (c) 2008-2020, UCHICAGO ARGONNE, LLC.
2!
3! The UChicago Argonne, LLC as Operator of Argonne National
4! Laboratory holds copyright in the Software. The copyright holder
5! reserves all rights except those expressly granted to licensees,
6! and U.S. Government license rights.
7!
8! Redistribution and use in source and binary forms, with or without
9! modification, are permitted provided that the following conditions
10! are met:
11!
12! 1. Redistributions of source code must retain the above copyright
13! notice, this list of conditions and the disclaimer below.
14!
15! 2. Redistributions in binary form must reproduce the above copyright
16! notice, this list of conditions and the disclaimer (as noted below)
17! in the documentation and/or other materials provided with the
18! distribution.
19!
20! 3. Neither the name of ANL nor the names of its contributors
21! may be used to endorse or promote products derived from this software
22! without specific prior written permission.
23!
24! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25! "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26! LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27! FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
28! UCHICAGO ARGONNE, LLC, THE U.S. DEPARTMENT OF
29! ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
31! TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32! DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33! THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34! (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35! OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36!
37! Additional BSD Notice
38! ---------------------
39! 1. This notice is required to be provided under our contract with
40! the U.S. Department of Energy (DOE). This work was produced at
41! Argonne National Laboratory under Contract
42! No. DE-AC02-06CH11357 with the DOE.
43!
44! 2. Neither the United States Government nor UCHICAGO ARGONNE,
45! LLC nor any of their employees, makes any warranty,
46! express or implied, or assumes any liability or responsibility for the
47! accuracy, completeness, or usefulness of any information, apparatus,
48! product, or process disclosed, or represents that its use would not
49! infringe privately-owned rights.
50!
51! 3. Also, reference herein to any specific commercial products, process,
52! or services by trade name, trademark, manufacturer or otherwise does
53! not necessarily constitute or imply its endorsement, recommendation,
54! or favoring by the United States Government or UCHICAGO ARGONNE LLC.
55! The views and opinions of authors expressed
56! herein do not necessarily state or reflect those of the United States
57! Government or UCHICAGO ARGONNE, LLC, and shall
58! not be used for advertising or product endorsement purposes.
59!
60!> Krylov preconditioner
61module hsmg
63 use num_types, only : rp
64 use math, only : copy, col2, add2
65 use utils, only : neko_error
66 use precon, only : pc_t, precon_allocator
67 use ax_product, only : ax_t, ax_helm_allocator
68 use gather_scatter, only : gs_t, gs_op_add
70 use bc, only : bc_t
71 use bc_list, only : bc_list_t
73 use dirichlet, only : dirichlet_t
74 use schwarz, only : schwarz_t
75 use jacobi, only : jacobi_t
76 use sx_jacobi, only : sx_jacobi_t
83 use space, only : space_t, gll
84 use dofmap, only : dofmap_t
85 use field, only : field_t
86 use coefs, only : coef_t, coef_operator
87 use mesh, only : mesh_t
88 use json_module, only : json_file
90 use krylov, only : ksp_t, ksp_monitor_t, ksp_max_iter, &
94 use logger, only : neko_log, log_size
95 use, intrinsic :: iso_c_binding, only : c_ptr, c_null_ptr, c_associated
96 !$ use omp_lib
97 implicit none
98 private
99
100 !Struct to arrange our multigridlevels
101 type, private :: multigrid_t
102 type(dofmap_t), pointer :: dof => null()
103 type(gs_t), pointer :: gs_h => null()
104 type(space_t), pointer :: xh => null()
105 type(coef_t), pointer :: coef => null()
106 type(scalar_bc_projector_t), pointer :: bc_projector => null()
107 type(schwarz_t), pointer :: schwarz => null()
108 type(field_t), pointer :: e => null()
109 end type multigrid_t
110
111 type, public, extends(pc_t) :: hsmg_t
112 type(mesh_t), pointer :: msh => null()
113 integer :: nlvls !< Number of levels in the multigrid
114 type(multigrid_t), allocatable :: grids(:) !< array for multigrids
115 type(gs_t) :: gs_crs, gs_mg !< gather scatter for lower levels
116 type(space_t) :: xh_crs, xh_mg !< spaces for lower levels
117 type(dofmap_t) :: dm_crs, dm_mg
118 type(coef_t) :: c_crs, c_mg
119 type(zero_dirichlet_t) :: bc_crs, bc_mg, bc_reg
120 type(scalar_bc_projector_t) :: bc_projector_crs, bc_projector_mg, &
121 bc_projector_reg
122 type(schwarz_t) :: schwarz, schwarz_mg, schwarz_crs !< Schwarz
123 !! decompositions
124 type(field_t) :: e, e_mg, e_crs !< Solve fields
125 type(field_t) :: wf !< Work fields
126 class(ksp_t), allocatable :: crs_solver !< Solver for course problem
127 type(tamg_solver_t), allocatable :: amg_solver
128 integer :: niter !< Number of iter of crs iterations
129 class(pc_t), allocatable :: pc_crs !< Some basic precon for crs
130 class(ax_t), allocatable :: ax !< Matrix for crs solve
131 real(kind=rp), allocatable :: r(:)!< Residual work array
132 type(interpolator_t) :: interp_fine_mid
133 type(interpolator_t) :: interp_mid_crs
134 real(kind=rp), allocatable :: w(:) !< work array
135 type(c_ptr) :: w_d = c_null_ptr
136 type(c_ptr) :: r_d = c_null_ptr
137 type(c_ptr) :: hsmg_event = c_null_ptr
138 type(c_ptr) :: gs_event = c_null_ptr
139 contains
140 procedure, pass(this) :: init => hsmg_init
141 procedure, pass(this) :: init_from_components => &
143 procedure, pass(this) :: free => hsmg_free
144 procedure, pass(this) :: solve => hsmg_solve
145 procedure, pass(this) :: update => hsmg_set_h
146 end type hsmg_t
147
148contains
149
150 subroutine hsmg_init(this, coef, bclst, json)
151 class(hsmg_t), intent(inout), target :: this
152 type(coef_t), intent(in), target :: coef
153 type(bc_list_t), intent(inout), target :: bclst
154 type(json_file), intent(inout) :: json
155 character(len=:), allocatable :: crs_solver, crs_pc
156 logical :: crs_monitor
157 integer :: crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree
158
159 ! Exract coarse grid parameters
160
161 ! Common parameters for the coarse grid
162 call json_get_or_default(json, 'coarse_grid.solver', &
163 crs_solver, "cg")
164
165 !
166 ! Parameters for a Krylov based coarse grid solverthis
167 !
168 call json_get_or_default(json, 'coarse_grid.iterations', &
169 this%niter, 10)
170
171 call json_get_or_default(json, 'coarse_grid.preconditioner', &
172 crs_pc, "jacobi")
173
174 call json_get_or_default(json, 'coarse_grid.monitor', &
175 crs_monitor, .false.)
176
177 !
178 ! Parameters for a tree-amg based coarse grid solver
179 !
180 call json_get_or_default(json, 'coarse_grid.levels', &
181 crs_tamg_lvls, 3)
182
183 call json_get_or_default(json, 'coarse_grid.iterations', &
184 crs_tamg_itrs, 1)
185
186 call json_get_or_default(json, 'coarse_grid.cheby_degree', &
187 crs_tamg_cheby_degree, 4)
188
189 call this%init_from_components(coef, bclst, crs_solver, crs_pc, &
190 crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
191
192 end subroutine hsmg_init
193
194 subroutine hsmg_init_from_components(this, coef, bclst, crs_solver, crs_pc, &
195 crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
196 class(hsmg_t), intent(inout), target :: this
197 type(coef_t), intent(in), target :: coef
198 type(bc_list_t), intent(inout), target :: bclst
199 character(len=:), intent(inout), allocatable :: crs_solver, crs_pc
200 logical, intent(inout) :: crs_monitor
201 integer, intent(in) :: crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree
202 integer :: n, i
203 integer :: lx_crs, lx_mid
204 class(bc_t), pointer :: bc_i
205
206 character(len=LOG_SIZE) :: log_buf
207
208 call this%free()
209 !> @note I do not think we actually use the same grids as they do
210 !! in the original!
211 this%nlvls = 3
212 lx_crs = 2
213 if (coef%Xh%lx .lt. 5) then
214 lx_mid = max(coef%Xh%lx-1,3)
215
216 if (coef%Xh%lx .le. 2) then
217 call neko_error('Polynomial order < 2 not supported for hsmg precon')
218 end if
219
220 else
221 lx_mid = 4
222 end if
223
224
225 call neko_log%section('HSMG')
226 if (this%nlvls .lt. 1e1) then
227 write(log_buf, '(A,I1,A)') 'HSMG hierarchy : ', &
228 this%nlvls, ' levels'
229 else if (this%nlvls .lt. 1e2) then
230 write(log_buf, '(A,I2,A)') 'HSMG hierarchy : ', &
231 this%nlvls, ' levels'
232 else if (this%nlvls .lt. 1e3) then
233 write(log_buf, '(A,I3,A)') 'HSMG hierarchy : ', this%nlvls, &
234 ' levels'
235 else
236 write(log_buf, '(A,I6,A)') 'HSMG hierarchy : ', this%nlvls, &
237 ' levels'
238 end if
239 call neko_log%message(log_buf)
240 if (trim(crs_solver) .ne. 'tamg' .or. trim(crs_solver) .eq. 'cheby') then
241 call neko_log%message('Coarse grid solver : (' // trim(crs_solver) // &
242 ', ' // trim(crs_pc) // ')')
243
244 if (this%niter .lt. 1e1) then
245 write(log_buf, '(A,I1)') 'Coarse grid iters. : ', this%niter
246 else if (this%niter .lt. 1e2) then
247 write(log_buf, '(A,I2)') 'Coarse grid iters. : ', this%niter
248 else if (this%niter .lt. 1e3) then
249 write(log_buf, '(A,I3)') 'Coarse grid iters. : ', this%niter
250 else if (this%niter .lt. 1e4) then
251 write(log_buf, '(A,I4)') 'Coarse grid iters. : ', this%niter
252 else
253 write(log_buf, '(A,I6)') 'Coarse grid iters. : ', this%niter
254 end if
255
256 call neko_log%message(log_buf)
257 else
258 call neko_log%message('Coarse grid solver : ' // trim(crs_solver) )
259 end if
260
261 this%msh => coef%msh
262 allocate(this%grids(this%nlvls))
263 allocate(this%w(coef%dof%size()))
264 allocate(this%r(coef%dof%size()))
265
266
267 ! Compute all elements as if they are deformed
268 call coef%msh%all_deformed()
269
270 n = coef%dof%size()
271 call this%e%init(coef%dof, 'work array')
272 call this%wf%init(coef%dof, 'work 2')
273
274 call this%Xh_crs%init(gll, lx_crs, lx_crs, lx_crs)
275 call this%dm_crs%init(coef%msh, this%Xh_crs)
276 call this%gs_crs%init(this%dm_crs)
277 call this%e_crs%init(this%dm_crs, 'work crs')
278 ! Both coarse levels read G_ij, h1, h2, B and mult and nothing else, and
279 ! hsmg never rebuilds their geometry, so the rest is dead weight.
280 call this%c_crs%init(this%gs_crs, coef_operator)
281
282 call this%Xh_mg%init(gll, lx_mid, lx_mid, lx_mid)
283 call this%dm_mg%init(coef%msh, this%Xh_mg)
284 call this%gs_mg%init(this%dm_mg)
285 call this%e_mg%init(this%dm_mg, 'work midl')
286 call this%c_mg%init(this%gs_mg, coef_operator)
287
288 ! Create backend specific Ax operator. The coarse levels compress their
289 ! geometric factors when the fine level does
290 if (coef%geo_compression) then
291 call this%c_crs%enable_geo_compression(coef%geo_compression_tol)
292 call this%c_mg%enable_geo_compression(coef%geo_compression_tol)
293 call ax_helm_allocator(this%ax, type_name = "standard_compr")
294 else
295 call ax_helm_allocator(this%ax, type_name = "standard")
296 end if
297
298 call this%bc_crs%init_base(this%c_crs)
299 call this%bc_mg%init_base(this%c_mg)
300 call this%bc_reg%init_base(coef)
301 if (bclst%size() .gt. 0) then
302 do i = 1, bclst%size()
303 bc_i => bclst%get(i)
304 call this%bc_reg%mark_facets(bc_i%marked_facet)
305 bc_i => bclst%get(i)
306 call this%bc_crs%mark_facets(bc_i%marked_facet)
307 bc_i => bclst%get(i)
308 call this%bc_mg%mark_facets(bc_i%marked_facet)
309 end do
310 end if
311 call this%bc_reg%finalize()
312 call this%bc_crs%finalize()
313 call this%bc_mg%finalize()
314
315 call this%bc_projector_reg%mark(this%bc_reg)
316 call this%bc_projector_crs%mark(this%bc_crs)
317 call this%bc_projector_mg%mark(this%bc_mg)
318
319 call this%schwarz%init(coef%Xh, coef%dof, coef%gs_h, &
320 this%bc_projector_reg, coef%msh)
321 call this%schwarz_mg%init(this%Xh_mg, this%dm_mg, this%gs_mg,&
322 this%bc_projector_mg, coef%msh)
323
324 call this%interp_fine_mid%init(coef%Xh, this%Xh_mg)
325 call this%interp_mid_crs%init(this%Xh_mg, this%Xh_crs)
326
327 call hsmg_fill_grid(coef%dof, coef%gs_h, coef%Xh, coef, &
328 this%bc_projector_reg, this%schwarz, this%e, this%grids, 3)
329 call hsmg_fill_grid(this%dm_mg, this%gs_mg, this%Xh_mg, this%c_mg, &
330 this%bc_projector_mg, this%schwarz_mg, this%e_mg, this%grids, 2)
331 call hsmg_fill_grid(this%dm_crs, this%gs_crs, this%Xh_crs, &
332 this%c_crs, this%bc_projector_crs, this%schwarz_crs, &
333 this%e_crs, this%grids, 1)
334
335 call hsmg_set_h(this)
336 if (neko_bcknd_device .eq. 1) then
337 call device_map(this%w, this%w_d, n)
338 call device_map(this%r, this%r_d, n)
339 end if
340
341 call device_event_create(this%hsmg_event, 2)
342 call device_event_create(this%gs_event, 2)
343
344
345
346 ! Create a backend specific krylov solver
347 if (trim(crs_solver) .eq. 'tamg') then
348 allocate(this%amg_solver)
349 call this%amg_solver%init(this%ax, this%grids(1)%e%Xh, &
350 this%grids(1)%coef, this%msh, this%grids(1)%gs_h, crs_tamg_lvls, &
351 this%grids(1)%bc_projector, crs_tamg_itrs, crs_tamg_cheby_degree)
352 else
353 ! Create a backend specific preconditioner
354 call precon_allocator(this%pc_crs, crs_pc)
355
356 select type (pc => this%pc_crs)
357 type is (jacobi_t)
358 call pc%init_from_components(this%c_crs, this%dm_crs, this%gs_crs)
359 type is (sx_jacobi_t)
360 call pc%init_from_components(this%c_crs, this%dm_crs, this%gs_crs)
361 type is (device_jacobi_t)
362 call pc%init_from_components(this%c_crs, this%dm_crs, this%gs_crs)
363 end select
364
365 call krylov_solver_factory(this%crs_solver, &
366 this%dm_crs%size(), trim(crs_solver), ksp_max_iter, &
367 m = this%pc_crs, monitor = crs_monitor)
368 end if
369
370 call neko_log%end_section()
371
372 end subroutine hsmg_init_from_components
373
374 subroutine hsmg_set_h(this)
375 class(hsmg_t), intent(inout) :: this
376 ! integer :: i
377 ! Yeah I dont really know what to do here. For incompressible flow not
378 ! much happens
379 this%grids(1)%coef%ifh2 = .false.
380 call copy(this%grids(1)%coef%h1, this%grids(3)%coef%h1, &
381 this%grids(1)%dof%size())
382 if (neko_bcknd_device .eq. 1) then
383 call device_copy(this%grids(1)%coef%h1_d, this%grids(3)%coef%h1_d, &
384 this%grids(1)%dof%size())
385 end if
386 end subroutine hsmg_set_h
387
388
389 subroutine hsmg_fill_grid(dof, gs_h, Xh, coef, bc_projector, schwarz, e, grids, l)
390 type(dofmap_t), target, intent(in) :: dof
391 type(gs_t), target, intent(in) :: gs_h
392 type(space_t), target, intent(in) :: Xh
393 type(coef_t), target, intent(in) :: coef
394 type(scalar_bc_projector_t), target, intent(in) :: bc_projector
395 type(schwarz_t), target, intent(in) :: schwarz
396 type(field_t), target, intent(in) :: e
397 integer, intent(in) :: l
398 type(multigrid_t), intent(inout), dimension(l) :: grids
399
400
401 grids(l)%dof => dof
402 grids(l)%gs_h => gs_h
403 grids(l)%Xh => xh
404 grids(l)%coef => coef
405 grids(l)%bc_projector => bc_projector
406 grids(l)%schwarz => schwarz
407 grids(l)%e => e
408
409 end subroutine hsmg_fill_grid
410
411 subroutine hsmg_free(this)
412 class(hsmg_t), intent(inout) :: this
413
414 if (allocated(this%ax)) then
415 call this%ax%free()
416 deallocate(this%ax)
417 end if
418
419 if (allocated(this%grids)) then
420 deallocate(this%grids)
421 end if
422
423 if (allocated(this%w)) then
424 if (c_associated(this%w_d)) then
425 call device_unmap(this%w, this%w_d)
426 end if
427 deallocate(this%w)
428 end if
429
430 if (allocated(this%r)) then
431 if (c_associated(this%r_d)) then
432 call device_unmap(this%r, this%r_d)
433 end if
434 deallocate(this%r)
435 end if
436
437 call this%schwarz%free()
438 call this%schwarz_mg%free()
439
440 call this%c_crs%free()
441 call this%c_mg%free()
442 call this%e%free()
443 call this%e_mg%free()
444 call this%e_crs%free()
445 call this%wf%free()
446
447 call this%gs_crs%free()
448 call this%gs_mg%free()
449 call this%interp_mid_crs%free()
450 call this%interp_fine_mid%free()
451
452 call this%bc_crs%free()
453 call this%bc_mg%free()
454 call this%bc_reg%free()
455
456 call this%bc_projector_reg%free()
457 call this%bc_projector_crs%free()
458 call this%bc_projector_mg%free()
459
460 if (allocated(this%crs_solver)) then
461 call this%crs_solver%free()
462 deallocate(this%crs_solver)
463 end if
464
465 if (allocated(this%amg_solver)) then
466 call this%amg_solver%free()
467 deallocate(this%amg_solver)
468 end if
469
470 if (allocated(this%pc_crs)) then
471 call this%pc_crs%free()
472 end if
473
474 if (c_associated(this%hsmg_event)) then
475 call device_event_destroy(this%hsmg_event)
476 end if
477 if (c_associated(this%gs_event)) then
478 call device_event_destroy(this%gs_event)
479 end if
480
481 call this%dm_crs%free()
482 call this%dm_mg%free()
483 call this%Xh_crs%free()
484 call this%Xh_mg%free()
485
486 end subroutine hsmg_free
487
488 !> The h1mg preconditioner from Nek5000.
489 subroutine hsmg_solve(this, z, r, n)
490 integer, intent(in) :: n
491 class(hsmg_t), intent(inout) :: this
492 real(kind=rp), dimension(n), intent(inout) :: z
493 real(kind=rp), dimension(n), intent(inout) :: r
494 type(c_ptr) :: z_d, r_d
495 type(ksp_monitor_t) :: crs_info
496 integer :: thrdid, nthrds
497
498 call profiler_start_region('HSMG_solve', 8)
499 if (neko_bcknd_device .eq. 1) then
500 z_d = device_get_ptr(z)
501 r_d = device_get_ptr(r)
502 !We should not work with the input
503 call device_copy(this%r_d, r_d, n)
504 call this%bc_projector_reg%apply(this%r, n)
505
506 !OVERLAPPING Schwarz exchange and solve
507 !! DOWNWARD Leg of V-cycle, we are pretty hardcoded here but w/e
508 call device_col2(this%r_d, this%grids(3)%coef%mult_d, &
509 this%grids(3)%dof%size())
510 !Restrict to middle level
511 call this%interp_fine_mid%map(this%e%x, this%r, &
512 this%msh%nelv, this%grids(2)%Xh)
513 call this%grids(2)%gs_h%op(this%e%x, &
514 this%grids(2)%dof%size(), gs_op_add, this%gs_event)
515 !This should probably be double checked again
516 call device_copy(this%r_d, r_d, n)
517 call this%bc_projector_reg%apply(this%r, n)
518 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
519 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
520 !OVERLAPPING Schwarz exchange and solve
521 call device_col2(this%w_d, this%grids(2)%coef%mult_d, &
522 this%grids(2)%dof%size())
523 !restrict residual to crs
524 call this%interp_mid_crs%map(this%wf%x, this%w, this%msh%nelv, &
525 this%grids(1)%Xh)
526 !Crs solve
527 call device_copy(this%w_d, this%e%x_d, this%grids(2)%dof%size())
528 call this%bc_projector_mg%apply(this%w, this%grids(2)%dof%size())
529
530 ! Both Schwarz levels run on the aux queue and depend only on what
531 ! has been queued on the global queue up to this point. Record that
532 ! point here, before the coarse grid thread starts queueing its solve
533 ! on the global queue.
534 call device_event_record(this%hsmg_event, glb_cmd_queue)
535
536 ! Only threads 0 and 1 have work here (Schwarz and coarse grid), so
537 ! ask for a team of two rather than the full team spinning at the
538 ! join. Capped by the default team size so a single-threaded run,
539 ! which initialised MPI without thread support, stays single-threaded.
540 !$omp parallel num_threads(min(2, omp_get_max_threads())) &
541 !$omp private(thrdid, nthrds)
542
543 thrdid = 0
544 nthrds = 1
545 !$ thrdid = omp_get_thread_num()
546 !$ nthrds = omp_get_num_threads()
547
548 if (thrdid .eq. 0) then
549 call profiler_start_region('HSMG_schwarz', 9)
550 call this%grids(3)%schwarz%compute(z, this%r, this%hsmg_event)
551 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w, &
552 this%hsmg_event)
553 call profiler_end_region('HSMG_schwarz', 9)
554 end if
555 if (nthrds .eq. 1 .or. thrdid .eq. 1) then
556 call profiler_start_region('HSMG_coarse_grid', 10)
557 call this%grids(1)%gs_h%op(this%wf%x, &
558 this%grids(1)%dof%size(), gs_op_add, this%gs_event)
559 call this%grids(1)%bc_projector%apply(this%wf%x, &
560 this%grids(1)%dof%size())
561 call profiler_start_region('HSMG_coarse_solve', 11)
562 if (allocated(this%amg_solver)) then
563 call this%amg_solver%solve(this%grids(1)%e%x, this%wf%x, &
564 this%grids(1)%dof%size())
565 else
566 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, &
567 this%wf%x, &
568 this%grids(1)%dof%size(), &
569 this%grids(1)%coef, &
570 this%grids(1)%bc_projector, &
571 this%grids(1)%gs_h, this%niter)
572 end if
573 call profiler_end_region('HSMG_coarse_solve', 11)
574 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x,&
575 this%grids(1)%dof%size())
576 call profiler_end_region('HSMG_coarse_grid', 10)
577 end if
578 !$omp end parallel
579
580 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
581 this%msh%nelv, this%grids(2)%Xh)
582 call device_add2(this%grids(2)%e%x_d, this%w_d, this%grids(2)%dof%size())
583
584 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
585 this%msh%nelv, this%grids(3)%Xh)
586 call device_add2(z_d, this%w_d, this%grids(3)%dof%size())
587 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), &
588 gs_op_add, this%gs_event)
589 call device_col2(z_d, this%grids(3)%coef%mult_d, &
590 this%grids(3)%dof%size())
591 else
592 !We should not work with the input
593 call copy(this%r, r, n)
594
595 !OVERLAPPING Schwarz exchange and solve
596 call this%grids(3)%schwarz%compute(z, this%r)
597 ! DOWNWARD Leg of V-cycle, we are pretty hardcoded here but w/e
598 call col2(this%r, this%grids(3)%coef%mult, &
599 this%grids(3)%dof%size())
600 !Restrict to middle level
601 call this%interp_fine_mid%map(this%w, this%r, &
602 this%msh%nelv, this%grids(2)%Xh)
603 call this%grids(2)%gs_h%op(this%w, this%grids(2)%dof%size(), gs_op_add)
604 !OVERLAPPING Schwarz exchange and solve
605 call this%grids(2)%schwarz%compute(this%grids(2)%e%x, this%w)
606 call col2(this%w, this%grids(2)%coef%mult, this%grids(2)%dof%size())
607 !restrict residual to crs
608 call this%interp_mid_crs%map(this%r, this%w, &
609 this%msh%nelv, this%grids(1)%Xh)
610 !Crs solve
611
612 call this%grids(1)%gs_h%op(this%r, this%grids(1)%dof%size(), gs_op_add)
613 call this%grids(1)%bc_projector%apply(this%r, this%grids(1)%dof%size())
614
615 call profiler_start_region('HSMG_coarse-solve', 11)
616 if (allocated(this%amg_solver)) then
617 call this%amg_solver%solve(this%grids(1)%e%x, this%r, &
618 this%grids(1)%dof%size())
619 else
620 crs_info = this%crs_solver%solve(this%Ax, this%grids(1)%e, this%r, &
621 this%grids(1)%dof%size(), &
622 this%grids(1)%coef, &
623 this%grids(1)%bc_projector, &
624 this%grids(1)%gs_h, this%niter)
625 end if
626 call profiler_end_region('HSMG_coarse-solve', 11)
627
628 call this%grids(1)%bc_projector%apply(this%grids(1)%e%x, &
629 this%grids(1)%dof%size())
630
631
632 call this%interp_mid_crs%map(this%w, this%grids(1)%e%x, &
633 this%msh%nelv, this%grids(2)%Xh)
634 call add2(this%grids(2)%e%x, this%w, this%grids(2)%dof%size())
635
636 call this%interp_fine_mid%map(this%w, this%grids(2)%e%x, &
637 this%msh%nelv, this%grids(3)%Xh)
638 call add2(z, this%w, this%grids(3)%dof%size())
639 call this%grids(3)%gs_h%op(z, this%grids(3)%dof%size(), gs_op_add)
640 call col2(z, this%grids(3)%coef%mult, this%grids(3)%dof%size())
641
642 end if
643 call profiler_end_region('HSMG_solve', 8)
644 end subroutine hsmg_solve
645end module hsmg
__device__ T solve(const T u, const T y, const T guess, const T nu, const T kappa, const T B)
Return the device pointer for an associated Fortran array.
Definition device.F90:113
Map a Fortran array to a device (allocate and associate).
Definition device.F90:83
Unmap a Fortran array from a device (deassociate and free).
Definition device.F90:89
Retrieves a parameter by name or assigns a provided default value. In the latter case also adds the m...
Factory for Krylov solvers. Both creates and initializes the object, either from its parameters or fr...
Definition krylov.f90:221
Defines a Matrix-vector product.
Definition ax.f90:34
Defines a list of bc_t.
Definition bc_list.f90:34
Defines a boundary condition.
Definition bc.f90:34
Coefficients.
Definition coef.f90:34
integer, parameter, public coef_operator
Retain only what applying a discrete operator needs: , h1, h2, B and mult.
Definition coef.f90:132
Jacobi preconditioner accelerator backend.
subroutine, public device_add2(a_d, b_d, n, strm)
Vector addition .
subroutine, public device_copy(a_d, b_d, n, strm)
Copy a vector .
subroutine, public device_col2(a_d, b_d, n, strm)
Vector multiplication .
Device abstraction, common interface for various accelerators.
Definition device.F90:34
subroutine, public device_event_record(event, stream)
Record a device event.
Definition device.F90:1682
subroutine, public device_event_destroy(event)
Destroy a device event.
Definition device.F90:1661
type(c_ptr), bind(C), public glb_cmd_queue
Global command queue.
Definition device.F90:52
subroutine, public device_event_create(event, flags)
Create a device event queue.
Definition device.F90:1627
Defines a dirichlet boundary condition.
Definition dirichlet.f90:34
Defines a mapping of the degrees of freedom.
Definition dofmap.f90:35
Defines a field.
Definition field.f90:34
Gather-scatter.
Krylov preconditioner.
Definition pc_hsmg.f90:61
subroutine hsmg_init(this, coef, bclst, json)
Definition pc_hsmg.f90:151
subroutine hsmg_solve(this, z, r, n)
The h1mg preconditioner from Nek5000.
Definition pc_hsmg.f90:490
subroutine hsmg_set_h(this)
Definition pc_hsmg.f90:375
subroutine hsmg_free(this)
Definition pc_hsmg.f90:412
subroutine hsmg_init_from_components(this, coef, bclst, crs_solver, crs_pc, crs_monitor, crs_tamg_lvls, crs_tamg_itrs, crs_tamg_cheby_degree)
Definition pc_hsmg.f90:196
subroutine hsmg_fill_grid(dof, gs_h, xh, coef, bc_projector, schwarz, e, grids, l)
Definition pc_hsmg.f90:390
Routines to interpolate between different spaces.
Jacobi preconditioner.
Definition pc_jacobi.f90:34
Utilities for retrieving parameters from the case files.
Implements the base abstract type for Krylov solvers plus helper types.
Definition krylov.f90:34
integer, parameter, public ksp_max_iter
Maximum number of iters.
Definition krylov.f90:55
Logging routines.
Definition log.f90:34
type(log_t), public neko_log
Global log stream.
Definition log.f90:92
integer, parameter, public log_size
Definition log.f90:46
Definition math.F90:60
subroutine, public add2(a, b, n)
Vector addition .
Definition math.F90:949
subroutine, public col2(a, b, n)
Vector multiplication .
Definition math.F90:1095
subroutine, public copy(a, b, n)
Copy a vector .
Definition math.F90:305
Defines a mesh.
Definition mesh.f90:34
Build configurations.
integer, parameter neko_bcknd_device
integer, parameter, public rp
Global precision used in computations.
Definition num_types.f90:14
Krylov preconditioner.
Definition precon.f90:34
Profiling interface.
Definition profiler.F90:34
subroutine, public profiler_start_region(name, region_id)
Started a named (name) profiler region.
Definition profiler.F90:79
subroutine, public profiler_end_region(name, region_id)
End the most recently started profiler region.
Definition profiler.F90:116
Implements scalar_projector_t.
Overlapping schwarz solves.
Definition schwarz.f90:61
Defines a function space.
Definition space.f90:34
integer, parameter, public gll
Definition space.f90:50
Jacobi preconditioner SX-Aurora backend.
Implements multigrid using the TreeAMG hierarchy structure. USE:
Utilities.
Definition utils.f90:35
Defines a zero-valued Dirichlet boundary condition.
Base type for a matrix-vector product providing .
Definition ax.f90:44
Base type for a boundary condition.
Definition bc.f90:73
A list of allocatable `bc_t`. Follows the standard interface of lists.
Definition bc_list.f90:49
Coefficients defined on a given (mesh, ) tuple. Arrays use indices (i,j,k,e): element e,...
Definition coef.f90:136
Defines a jacobi preconditioner.
Generic Dirichlet boundary condition on .
Definition dirichlet.f90:49
Gather-scatter kernel.
Interpolation between two space::space_t.
Defines a jacobi preconditioner.
Definition pc_jacobi.f90:47
Type for storing initial and final residuals in a Krylov solver.
Definition krylov.f90:60
Base abstract type for a canonical Krylov method, solving .
Definition krylov.f90:77
Defines a canonical Krylov preconditioner.
Definition precon.f90:44
Projector for scalar boundary conditions.
The function space for the SEM solution fields.
Definition space.f90:64
Defines a jacobi preconditioner for SX-Aurora.
Type for the TreeAMG solver.
Zero-valued Dirichlet boundary condition. Used for no-slip walls, but also for various auxillary cond...
#define max(a, b)
Definition tensor.cu:40