FE-Project
Loading...
Searching...
No Matches
scale_multigrid_solver_base.F90
Go to the documentation of this file.
1!-------------------------------------------------------------------------------
2!> module FElib / Multigrid / Solver base
3!!
4!! @par Description
5!! A base module to provide a multigrid solver
6!!
7!! @author Yuta Kawai, Team SCALE
8!<
9!-------------------------------------------------------------------------------
10#include "scaleFElib.h"
12
13 !-----------------------------------------------------------------------------
14 !
15 !++ used modules
16 !
17 !
18 use scale_precision
19 use scale_io
20 use scale_prc, only: prc_abort
21
22 use scale_mesh_hierarchy_base, only: &
24 pmg_finest_level => mesh_hierarchy_pmg_finest_level, &
25 hmg_finest_level => mesh_hierarchy_hmg_finest_level, &
28
29 !-----------------------------------------------------------------------------
30 implicit none
31 private
32
33 !-----------------------------------------------------------------------------
34 !
35 !++ Public type & procedure
36 !
37
38 !> Base type for multigrid solver
39 type, public :: multigridsolverbase
40 integer :: current_p_lev !< Current p-MG level
41 integer :: current_h_lev !< Current h-MG level
42
43 integer :: vcyc_num_max
44 real(rp) :: history_residual_l2_initial !< Initial residual L2 norm
45 real(rp) :: history_residual_max_initial !< Initial residual max norm
46
47 real(rp) :: threshold_ratio_residual_l2 !< Threshold of decreasing ratio of residual for smoothing (L2 norm)
48 real(rp) :: threshold_residual_l2 !< Residual threshold for smoothing (L2 norm)
49 real(rp) :: threshold_residual_max !< Residual threshold for smoothing (max norm)
50 contains
51 procedure :: set_vcycle_parameter => multigridsolverbase_set_vcyc_param
52 procedure :: is_converged => multigridsolverbase_is_converged
53 end type multigridsolverbase
54
57
58 !-----------------------------------------------------------------------------
59 !
60 !++ Public parameters & variables
61 !
62
63 !-----------------------------------------------------------------------------
64 !
65 !++ Private procedure
66 !
67
68 !-----------------------------------------------------------------------------
69 !
70 !++ Private parameters & variables
71 !
72contains
73 !> Initialize a base object for multigrid solver
74!OCL SERIAL
75 subroutine multigridsolverbase_init( this, &
76 mesh_hierarchy )
77 implicit none
78 class(multigridsolverbase), intent(inout) :: this
79 class(meshhierarchybase), intent(in) :: mesh_hierarchy !< Object to manage mesh hierarchy
80 !-------------------------------------------------------------
81
82 !-
83 this%vcyc_num_max = 10
84 return
85 end subroutine multigridsolverbase_init
86
87 !> Finalize a base object for multigrid solver
88!OCL SERIAL
90 implicit none
91 class(multigridsolverbase), intent(inout) :: this
92 !-------------------------------------------------------------
93 return
94 end subroutine multigridsolverbase_final
95
96 !> Set parameters for V-cycle
97!OCL SERIAL
98 subroutine multigridsolverbase_set_vcyc_param( this, &
99 vcyc_num_max, threshold_ratio_residual_l2, threshold_residual_l2, threshold_residual_max )
100 implicit none
101 class(multigridsolverbase), intent(inout) :: this
102 integer, intent(in) :: vcyc_num_max
103 real(rp), intent(in) :: threshold_ratio_residual_l2
104 real(rp), intent(in) :: threshold_residual_l2
105 real(rp), intent(in) :: threshold_residual_max
106 !-------------------------------------------------------------
107 this%vcyc_num_max = vcyc_num_max
108 this%threshold_ratio_residual_l2 = threshold_ratio_residual_l2
109 this%threshold_residual_l2 = threshold_residual_l2
110 this%threshold_residual_max = threshold_residual_max
111 return
112 end subroutine multigridsolverbase_set_vcyc_param
113
114 !> Check convergence of multigrid solver
115!OCL SERIAL
116 function multigridsolverbase_is_converged( this, smoother ) result( conv_flag )
118 implicit none
119 class(multigridsolverbase), intent(in) :: this
120 class(mgsmootherbase), intent(in) :: smoother
121 logical :: conv_flag
122
123 real(rp) :: res_l2, res_max
124 real(rp) :: res_decrease_ratio_l2
125 !---------------------------------------------------------------------
126
127 call smoother%Get_current_residual_statistics( res_l2, res_max )
128
129 res_decrease_ratio_l2 = res_l2 / this%history_residual_l2_initial
130 if ( ( res_decrease_ratio_l2 < this%threshold_ratio_residual_l2 ) &
131 .or. ( res_l2 < this%threshold_residual_l2 &
132 .and. res_max < this%threshold_residual_max ) ) then
133 conv_flag = .true.
134 else
135 conv_flag = .false.
136 end if
137 return
138 end function multigridsolverbase_is_converged
139
module FElib / Mesh / Hierarchy base
integer, parameter, public mesh_hierarchy_type_pmg
Type ID of mesh hierarchy: p-MG.
integer, parameter, public mesh_hierarchy_hmg_finest_level
Finest level index in h-MG.
integer, parameter, public mesh_hierarchy_type_hmg
Type ID of mesh hierarchy: h-MG.
integer, parameter, public mesh_hierarchy_pmg_finest_level
Finest level index in p-MG.
module FElib / Multigrid / Smoother base
module FElib / Multigrid / Solver base
subroutine, public multigridsolverbase_final(this)
Finalize a base object for multigrid solver.
subroutine, public multigridsolverbase_init(this, mesh_hierarchy)
Initialize a base object for multigrid solver.