28 use,
intrinsic :: iso_fortran_env
45 integer,
parameter :: &
61 real(real64),
public :: threshold
62 real(real64) :: relax_factor
64 integer,
public :: maxcycles = 0
67 integer :: restriction_method
68 integer :: relaxation_method
71 integer,
parameter,
public :: &
80 type(mg_solver_t),
intent(out) :: this
81 type(namespace_t),
intent(in) :: namespace
82 class(space_t),
intent(in) :: space
83 type(mesh_t),
intent(inout) :: mesh
84 real(real64),
intent(in) :: thr
98 call parse_variable(namespace,
'MultigridPresmoothingSteps', 1, this%presteps)
108 call parse_variable(namespace,
'MultigridPostsmoothingSteps', 4, this%poststeps)
118 call parse_variable(namespace,
'MultigridMaxCycles', 100, this%maxcycles)
131 call parse_variable(namespace,
'MultigridRestrictionMethod', 2, this%restriction_method)
148 call parse_variable(namespace,
'MultigridRelaxationMethod', gauss_seidel, this%relaxation_method)
164 call parse_variable(namespace,
'MultigridRelaxationFactor', 0.6666_real64, this%relax_factor)
179 real(real64),
contiguous,
intent(inout) :: sol(:)
180 real(real64),
contiguous,
intent(in) :: rhs(:)
182 real(real64),
allocatable :: residue(:), coarse_residue(:), correction(:), coarse_correction(:)
186 safe_allocate(residue(1:der%mesh%np_part))
188 if (
associated(der%coarser))
then
189 assert(
associated(op%coarser))
191 safe_allocate(correction(1:der%mesh%np_part))
192 safe_allocate(coarse_residue(1:der%coarser%mesh%np_part))
193 safe_allocate(coarse_correction(1:der%coarser%mesh%np_part))
202 message(1) =
"Debug: Multigrid restriction"
205 call dmultigrid_fine2coarse(der%to_coarser, der, der%coarser%mesh, residue, coarse_residue, this%restriction_method)
208 coarse_correction =
m_zero
212 message(1) =
"Debug: Multigrid prolongation"
221 safe_deallocate_a(correction)
222 safe_deallocate_a(coarse_residue)
223 safe_deallocate_a(coarse_correction)
226 call multigrid_relax(this, der%mesh, der, op, sol, rhs, this%poststeps)
234 safe_deallocate_a(residue)
247 real(real64),
contiguous,
intent(inout) :: sol(:)
248 real(real64),
contiguous,
intent(in) :: rhs(:)
250 real(real64),
allocatable :: residue(:), coarse_residue(:), correction(:), coarse_correction(:)
254 safe_allocate(residue(1:der%mesh%np_part))
256 if (
associated(der%coarser))
then
257 assert(
associated(op%coarser))
259 safe_allocate(correction(1:der%mesh%np_part))
260 safe_allocate(coarse_residue(1:der%coarser%mesh%np_part))
261 safe_allocate(coarse_correction(1:der%coarser%mesh%np_part))
270 message(1) =
"Debug: Multigrid restriction"
273 call dmultigrid_fine2coarse(der%to_coarser, der, der%coarser%mesh, residue, coarse_residue, this%restriction_method)
276 coarse_correction =
m_zero
280 message(1) =
"Debug: Multigrid prolongation"
296 message(1) =
"Debug: Multigrid restriction"
299 call dmultigrid_fine2coarse(der%to_coarser, der, der%coarser%mesh, residue, coarse_residue, this%restriction_method)
302 coarse_correction =
m_zero
306 message(1) =
"Debug: Multigrid prolongation"
315 safe_deallocate_a(correction)
316 safe_deallocate_a(coarse_residue)
317 safe_deallocate_a(coarse_correction)
320 call multigrid_relax(this, der%mesh, der, op, sol, rhs, this%poststeps)
328 safe_deallocate_a(residue)
343 real(real64),
contiguous,
intent(inout) :: sol(:)
344 real(real64),
contiguous,
intent(inout) :: rhs(:)
345 integer,
intent(in) :: multigrid_shape
348 real(real64) :: resnorm
349 real(real64),
allocatable :: err(:)
353 safe_allocate(err(1:der%mesh%np))
355 do iter = 1, this%maxcycles
357 select case (multigrid_shape)
370 if (resnorm < this%threshold)
exit
372 write(
message(1),
'(a,i5,a,e13.6)')
"Multigrid: base level: iter ", iter,
" res ", resnorm
377 if (resnorm >= this%threshold)
then
378 message(1) =
'Multigrid Poisson solver did not converge.'
379 write(
message(2),
'(a,e14.6)')
' Abs. norm of the residue = ', resnorm
382 write(
message(1),
'(a,i4,a)')
"Multigrid Poisson solver converged in ", iter,
" iterations."
383 write(
message(2),
'(a,e14.6)')
' Abs. norm of the residue = ', resnorm
387 safe_deallocate_a(err)
402 real(real64),
contiguous,
intent(inout) :: sol(:)
403 real(real64),
contiguous,
intent(inout) :: rhs(:)
405 real(real64),
allocatable :: coarse_solution(:), coarse_rhs(:), residue(:)
409 if (
associated(der%coarser))
then
410 assert(
associated(op%coarser))
412 safe_allocate(coarse_rhs(1:der%coarser%mesh%np_part))
413 safe_allocate(coarse_solution(1:der%coarser%mesh%np_part))
416 message(1) =
"Debug: Full Multigrid restriction"
419 call dmultigrid_fine2coarse(der%to_coarser, der, der%coarser%mesh, rhs, coarse_rhs, this%restriction_method)
423 call multigrid_fmg_solver(this, namespace, der%coarser, op%coarser, coarse_solution, coarse_rhs)
426 message(1) =
"Debug: Full Multigrid prolongation"
435 safe_deallocate_a(coarse_solution)
436 safe_deallocate_a(coarse_rhs)
440 safe_allocate(residue(1:der%mesh%np))
442 safe_deallocate_a(residue)
455 real(real64),
contiguous,
intent(inout) :: sol(:)
456 real(real64),
contiguous,
intent(in) :: rhs(:)
457 real(real64),
contiguous,
intent(inout) :: residue(:)
460 real(real64) :: resnorm
465 do iter = 1, this%maxcycles
470 resnorm =
dmf_nrm2(der%mesh, residue)
471 if (resnorm < this%threshold)
exit
475 write(
message(1),
'(a,i4,a)')
"Debug: Multigrid coarsest grid solver converged in ", iter,
" iterations."
476 write(
message(2),
'(a,es18.6)')
" Residue norm is ", resnorm
487 real(real64),
contiguous,
intent(inout) :: sol(:)
488 real(real64),
contiguous,
intent(in) :: rhs(:)
489 real(real64),
contiguous,
intent(inout) :: residue(:)
496 do ip = 1, der%mesh%np
497 residue(ip) = rhs(ip) - residue(ip)
508 type(
mesh_t),
intent(in) :: mesh
511 real(real64),
contiguous,
intent(inout) :: sol(:)
512 real(real64),
contiguous,
intent(in) :: rhs(:)
513 integer,
intent(in) :: steps
515 integer :: istep, index
516 integer :: ip, nn, is
517 real(real64) :: point, factor
518 real(real64),
allocatable :: op_sol(:), diag(:)
523 select case (this%relaxation_method)
531 if (mesh%parallel_in_domains)
then
538 factor = -
m_one/op%w(op%stencil%center, 1)
540 op%ri(1, 1), op%rimap_inv(1), op%rimap_inv(2), factor, sol(1), rhs(1))
547 point = point + op%w(is, ip)*sol(index)
549 sol(ip) = sol(ip) - (point-rhs(ip))/op%w(op%stencil%center, ip)
558 safe_allocate(op_sol(1:mesh%np))
559 safe_allocate(diag(1:mesh%np))
564 diag(ip) = this%relax_factor/diag(ip)
571 sol(ip) = sol(ip) - diag(ip)*(op_sol(ip) - rhs(ip))
575 safe_deallocate_a(diag)
576 safe_deallocate_a(op_sol)
constant times a vector plus a vector
Module implementing boundary conditions in Octopus.
subroutine, public dpar_vec_ghost_update(pv, v_local)
Updates ghost points of every node.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public dderivatives_perform(op, der, ff, op_ff, ghost_update, set_bc, factor)
apply a nl_operator to a mesh function
subroutine, public dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
real(real64), parameter, public m_zero
real(real64), parameter, public m_one
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_input_error(namespace, var, details, row, column)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
subroutine, public dmultigrid_coarse2fine(tt, coarse_der, fine_mesh, f_coarse, f_fine, set_bc)
subroutine, public dmultigrid_fine2coarse(tt, fine_der, coarse_mesh, f_fine, f_coarse, method_p)
This modules provides the routines for solving Ax=b using the V-shaped multigrid method.
recursive subroutine, public multigrid_fmg_solver(this, namespace, der, op, sol, rhs)
Full multigrid (FMG) solver.
recursive subroutine, public multigrid_solver_v_cycle(this, der, op, sol, rhs)
Performs one cycle of a V-shaped multigrid solver.
recursive subroutine, public multigrid_solver_w_cycle(this, der, op, sol, rhs)
Performs one cycle of a W-shaped multigrid solver.
subroutine multigrid_solver_solve_coarsest(this, der, op, sol, rhs, residue)
Computes the solution on the coarsest grid.
subroutine, public multigrid_iterative_solver(this, namespace, der, op, sol, rhs, multigrid_shape)
An iterative multigrid solver.
integer, parameter weighted_jacobi
subroutine, public multigrid_solver_init(this, namespace, space, mesh, thr)
integer, parameter, public mg_fmg
subroutine get_residual(op, der, sol, rhs, residue)
Computes the residual.
subroutine multigrid_relax(this, mesh, der, op, sol, rhs, steps)
Given a nonlocal operator op, perform the relaxation operator.
integer, parameter, public mg_w_shape
This module defines non-local operators.
subroutine, public dnl_operator_operate_diag(op, fo)
integer pure function, public nl_operator_get_index(op, is, ip)
This module contains interfaces for routines in operate.c.
Some general things and nomenclature:
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
class representing derivatives
Describes mesh distribution to nodes.
data type for non local operators