93 subroutine phmg_init(this, msh, Xh, coef, dof, gs_h, bclst)
94 class(
phmg_t),
intent(inout),
target :: this
95 type(
mesh_t),
intent(inout),
target :: msh
96 type(
space_t),
intent(inout),
target :: Xh
97 type(
coef_t),
intent(in),
target :: coef
98 type(
dofmap_t),
intent(in),
target :: dof
99 type(
gs_t),
intent(inout),
target :: gs_h
100 type(
bc_list_t),
intent(inout),
target :: bclst
101 integer :: lx_crs, lx_mid
102 integer,
allocatable :: lx_lvls(:)
107 this%nlvls = xh%lx - 1
109 allocate(lx_lvls(0:this%nlvls - 1))
111 do i = 1, this%nlvls -1
112 lx_lvls(i) = xh%lx - i
115 allocate(this%phmg_hrchy%lvl(0:this%nlvls - 1))
117 this%phmg_hrchy%lvl(0)%lvl = 0
118 this%phmg_hrchy%lvl(0)%Xh => xh
119 this%phmg_hrchy%lvl(0)%coef => coef
120 this%phmg_hrchy%lvl(0)%dm_Xh => dof
121 this%phmg_hrchy%lvl(0)%gs_h => gs_h
123 do i = 1, this%nlvls - 1
124 allocate(this%phmg_hrchy%lvl(i)%Xh)
125 allocate(this%phmg_hrchy%lvl(i)%dm_Xh)
126 allocate(this%phmg_hrchy%lvl(i)%gs_h)
127 allocate(this%phmg_hrchy%lvl(i)%coef)
129 this%phmg_hrchy%lvl(i)%lvl = i
130 call this%phmg_hrchy%lvl(i)%Xh%init(
gll, lx_lvls(i), lx_lvls(i), lx_lvls(i))
131 call this%phmg_hrchy%lvl(i)%dm_Xh%init(msh, this%phmg_hrchy%lvl(i)%Xh)
132 call this%phmg_hrchy%lvl(i)%gs_h%init(this%phmg_hrchy%lvl(i)%dm_Xh)
133 call this%phmg_hrchy%lvl(i)%coef%init(this%phmg_hrchy%lvl(i)%gs_h)
136 do i = 0, this%nlvls - 1
137 call this%phmg_hrchy%lvl(i)%r%init(this%phmg_hrchy%lvl(i)%dm_Xh)
138 call this%phmg_hrchy%lvl(i)%w%init(this%phmg_hrchy%lvl(i)%dm_Xh)
139 call this%phmg_hrchy%lvl(i)%z%init(this%phmg_hrchy%lvl(i)%dm_Xh)
141 call this%phmg_hrchy%lvl(i)%cheby%init(this%phmg_hrchy%lvl(i)%dm_Xh%size(),
ksp_max_iter)
143 call this%phmg_hrchy%lvl(i)%jacobi%init(this%phmg_hrchy%lvl(i)%coef, &
144 this%phmg_hrchy%lvl(i)%dm_Xh, &
145 this%phmg_hrchy%lvl(i)%gs_h)
147 this%phmg_hrchy%lvl(i)%coef%ifh2 = coef%ifh2
148 call copy(this%phmg_hrchy%lvl(i)%coef%h1, coef%h1, &
149 this%phmg_hrchy%lvl(i)%dm_Xh%size())
151 call this%phmg_hrchy%lvl(i)%bc%init_base(this%phmg_hrchy%lvl(i)%coef)
152 if (bclst%size .gt. 0 )
then
154 call this%phmg_hrchy%lvl(i)%bc%mark_facets(&
155 bclst%items(j)%ptr%marked_facet)
158 call this%phmg_hrchy%lvl(i)%bc%finalize()
159 call this%phmg_hrchy%lvl(i)%bc%set_g(0.0_rp)
160 call this%phmg_hrchy%lvl(i)%bclst%init()
161 call this%phmg_hrchy%lvl(i)%bclst%append(this%phmg_hrchy%lvl(i)%bc)
165 call ax_helm_factory(this%ax, full_formulation = .false.)
168 allocate(this%intrp(this%nlvls - 1))
169 do i = 1, this%nlvls -1
170 call this%intrp(i)%init(this%phmg_hrchy%lvl(i-1)%Xh, this%phmg_hrchy%lvl(i)%Xh)
173 call this%amg_solver%init(this%ax, this%phmg_hrchy%lvl(this%nlvls -1)%Xh, &
174 this%phmg_hrchy%lvl(this%nlvls -1)%coef, this%msh, &
175 this%phmg_hrchy%lvl(this%nlvls-1)%gs_h, 4, &
176 this%phmg_hrchy%lvl(this%nlvls -1)%bclst, 1)
216 mg, intrp, msh, Ax, amg_solver)
217 type(ksp_monitor_t) :: ksp_results
220 type(interpolator_t) :: intrp(1:clvl)
221 type(tamg_solver_t),
intent(inout) :: amg_solver
222 class(ax_t),
intent(inout) :: ax
223 type(mesh_t),
intent(inout) :: msh
224 type(field_t) :: z, r, w
228 ksp_results = mg(lvl)%cheby%solve(ax, z, &
229 r%x, mg(lvl)%dm_Xh%size(), &
230 mg(lvl)%coef, mg(lvl)%bclst, &
231 mg(lvl)%gs_h, niter = 15)
233 call ax%compute(w%x, z%x, mg(lvl)%coef, msh, mg(lvl)%Xh)
237 call intrp(lvl+1)%map(mg(lvl+1)%r%x, w%x, msh%nelv, mg(lvl+1)%Xh)
239 call mg(lvl+1)%gs_h%op(mg(lvl+1)%r%x, mg(lvl+1)%dm_Xh%size(), gs_op_add)
241 call col2(mg(lvl+1)%r%x, mg(lvl+1)%coef%mult, mg(lvl+1)%dm_Xh%size())
244 call mg(lvl+1)%bclst%apply_scalar( &
246 mg(lvl+1)%dm_Xh%size())
248 mg(lvl+1)%z%x = 0.0_rp
249 if (lvl+1 .eq. clvl)
then
251 call amg_solver%solve(mg(lvl+1)%z%x, &
253 mg(lvl+1)%dm_Xh%size())
255 call mg(lvl+1)%bclst%apply_scalar( &
257 mg(lvl+1)%dm_Xh%size())
259 call phmg_mg_cycle(mg(lvl+1)%z, mg(lvl+1)%r, mg(lvl+1)%w, lvl+1, &
260 clvl, mg, intrp, msh, ax, amg_solver)
263 call intrp(lvl+1)%map(w%x, mg(lvl+1)%z%x, msh%nelv, mg(lvl)%Xh)
265 call mg(lvl)%gs_h%op(w%x, mg(lvl)%dm_Xh%size(), gs_op_add)
267 call col2(w%x, mg(lvl)%coef%mult, mg(lvl)%dm_Xh%size())
269 call mg(lvl)%bclst%apply_scalar(w%x, mg(lvl)%dm_Xh%size())
273 ksp_results = mg(lvl)%cheby%solve(ax, z, &
274 r%x, mg(lvl)%dm_Xh%size(), &
275 mg(lvl)%coef, mg(lvl)%bclst, &
276 mg(lvl)%gs_h, niter = 15)