42 use krylov,
only: ksp_t, ksp_monitor_t, krylov_solver_factory, &
145 type(coef_t),
intent(inout) :: coef
149 n = this%coef%dof%size()
152 call this%bclst_filt%init()
155 call ax_helm_factory(this%Ax, full_formulation = .false.)
158 call krylov_solver_factory(this%ksp_filt, n, this%ksp_solver, &
159 this%ksp_max_iter, this%abstol_filt)
163 this%coef, this%coef%dof, this%coef%gs_h, this%bclst_filt, &
164 this%precon_type_filt)
197 type(field_t),
intent(in) :: X_in
198 type(field_t),
intent(inout) :: X_out
200 type(field_t),
pointer :: RHS, d_X_out
201 character(len=LOG_SIZE) :: log_buf
202 integer :: temp_indices(2)
204 n = this%coef%dof%size()
205 call neko_scratch_registry%request_field(rhs, temp_indices(1))
206 call neko_scratch_registry%request_field(d_x_out, temp_indices(2))
219 if (neko_bcknd_device .eq. 1)
then
222 call device_cfill(this%coef%h1_d, this%r**2, n)
223 call device_cfill(this%coef%h2_d, 1.0_rp, n)
226 this%coef%h1 = this%r**2
228 this%coef%h2 = 1.0_rp
230 this%coef%ifh2 = .true.
235 call field_copy(d_x_out, x_in)
236 call this%Ax%compute(rhs%x, d_x_out%x, this%coef, this%coef%msh, &
239 if (neko_bcknd_device .eq. 1)
then
240 call device_subcol3(rhs%x_d, x_in%x_d, this%coef%B_d, n)
241 call device_cmult(rhs%x_d, -1.0_rp, n)
245 rhs%x(i,1,1,1) = x_in%x(i,1,1,1) * this%coef%B(i,1,1,1) &
251 call this%coef%gs_h%op(rhs, gs_op_add)
254 call this%bclst_filt%apply_scalar(rhs%x, n)
257 call profiler_start_region(
'filter solve')
258 this%ksp_results(1) = &
259 this%ksp_filt%solve(this%Ax, d_x_out, rhs%x, n, this%coef, &
260 this%bclst_filt, this%coef%gs_h)
262 call profiler_end_region
265 call field_add3(x_out, x_in, d_x_out)
267 call this%pc_filt%update()
270 call neko_log%message(
'Filter')
272 write(log_buf,
'(A,A,A)')
'Iterations: ',&
273 'Start residual: ',
'Final residual:'
274 call neko_log%message(log_buf)
275 write(log_buf,
'(I11,3x, E15.7,5x, E15.7)') this%ksp_results%iter, &
276 this%ksp_results%res_start, this%ksp_results%res_final
277 call neko_log%message(log_buf)
279 call neko_scratch_registry%relinquish_field(temp_indices)
305 type(field_t),
intent(in) :: X_in
306 type(field_t),
intent(in) :: df_dX_out
307 type(field_t),
intent(inout) :: df_dX_in
309 type(field_t),
pointer :: RHS, delta
310 integer :: temp_indices(2)
311 character(len=LOG_SIZE) :: log_buf
313 n = this%coef%dof%size()
315 call neko_scratch_registry%request_field(rhs, temp_indices(1))
316 call neko_scratch_registry%request_field(delta, temp_indices(2))
319 if (neko_bcknd_device .eq. 1)
then
322 call device_cfill(this%coef%h1_d, this%r**2, n)
323 call device_cfill(this%coef%h2_d, 1.0_rp, n)
326 this%coef%h1 = this%r**2
328 this%coef%h2 = 1.0_rp
330 this%coef%ifh2 = .true.
335 call field_copy(delta, df_dx_out)
336 call this%Ax%compute(rhs%x, delta%x, this%coef, this%coef%msh, &
339 if (neko_bcknd_device .eq. 1)
then
340 call device_subcol3(rhs%x_d, df_dx_out%x_d, this%coef%B_d, n)
341 call device_cmult(rhs%x_d, -1.0_rp, n)
345 rhs%x(i,1,1,1) = df_dx_out%x(i,1,1,1) * this%coef%B(i,1,1,1) &
351 call this%coef%gs_h%op(rhs, gs_op_add)
354 call this%bclst_filt%apply_scalar(rhs%x, n)
357 call profiler_start_region(
'filter solve')
358 this%ksp_results(1) = &
359 this%ksp_filt%solve(this%Ax, delta, rhs%x, n, this%coef, &
360 this%bclst_filt, this%coef%gs_h)
363 call field_add3(df_dx_in, df_dx_out, delta)
365 call profiler_end_region
368 call this%pc_filt%update()
371 call neko_log%message(
'Filter')
373 write(log_buf,
'(A,A,A)')
'Iterations: ',&
374 'Start residual: ',
'Final residual:'
375 call neko_log%message(log_buf)
376 write(log_buf,
'(I11,3x, E15.7,5x, E15.7)') this%ksp_results%iter, &
377 this%ksp_results%res_start, this%ksp_results%res_final
378 call neko_log%message(log_buf)
380 call neko_scratch_registry%relinquish_field(temp_indices)
387 class(pc_t),
allocatable,
target,
intent(inout) :: pc
388 class(ksp_t),
target,
intent(inout) :: ksp
389 type(coef_t),
target,
intent(in) :: coef
390 type(dofmap_t),
target,
intent(in) :: dof
391 type(gs_t),
target,
intent(inout) :: gs
392 type(bc_list_t),
target,
intent(inout) :: bclst
393 character(len=*) :: pctype
395 call precon_factory(pc, pctype)
397 select type (pcp => pc)
399 call pcp%init(coef, dof, gs)
400 type is (sx_jacobi_t)
401 call pcp%init(coef, dof, gs)
402 type is (device_jacobi_t)
403 call pcp%init(coef, dof, gs)
405 if (len_trim(pctype) .gt. 4)
then
406 if (index(pctype,
'+') .eq. 5)
then
407 call pcp%init(dof%msh, dof%Xh, coef, dof, gs, &
408 bclst, trim(pctype(6:)))
410 call neko_error(
'Unknown coarse grid solver')
413 call pcp%init(dof%msh, dof%Xh, coef, dof, gs, bclst)