*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 520b7029 authored by Innerberger, Michael's avatar Innerberger, Michael
Browse files

Port other "easy" preconditioners to new interface

parent e6bc3cc8
Branches
Tags
No related merge requests found
% ICholPcgSolver (subclass of PcgSolver) Solves linear equations iteratively
% using the CG method with incomplete Cholesky decomposition preconditioner.
classdef ICholPcgSolver < PcgSolver
%% properties
properties (GetAccess=public,SetAccess=protected)
fes
end
properties (Access=private)
C
end
%% methods
methods (Access=public)
% preconditioner action: inverse of diagonal
function obj = ICholPcgSolver(fes)
arguments
fes FeSpace
end
obj = obj@PcgSolver();
obj.fes = fes;
end
function setupSystemMatrix(obj, A)
obj.C = ichol(A);
setupSystemMatrix@PcgSolver(obj, A);
end
function setupRhs(obj, b, varargin)
setupRhs@PcgSolver(obj, b, varargin{:});
end
function Cx = preconditionAction(obj, x)
Cx = obj.C' \ (obj.C \ x);
end
end
end
\ No newline at end of file
% JacobiPcgSolver (subclass of PcgSolver) Solves linear equations
% iteratively using the CG method with diagonal preconditioner.
classdef JacobiPcgSolver < PcgSolver
%% properties
properties (GetAccess=public,SetAccess=protected)
fes
end
properties (Access=private)
C
end
%% methods
methods (Access=public)
% preconditioner action: inverse of diagonal
function obj = JacobiPcgSolver(fes)
arguments
fes FeSpace
end
obj = obj@PcgSolver();
obj.fes = fes;
end
function setupSystemMatrix(obj, A)
obj.C = full(diag(A)).^(-1);
setupSystemMatrix@PcgSolver(obj, A);
end
function setupRhs(obj, b, varargin)
setupRhs@PcgSolver(obj, b, varargin{:});
end
function Cx = preconditionAction(obj, x)
Cx = obj.C .* x;
end
end
end
\ No newline at end of file
......@@ -18,18 +18,23 @@ P = Prolongation.chooseFor(fes);
switch class
% non-preconditioned CG
case "cg"
solver = PcgSolverTEMP(IdentityPC());
solver = PcgSolverTEMP(NoPreconditioner());
% preconditioned CG family
case "pcg"
solver = [];
switch variant
case "iChol"
solver = ICholPcgSolver(fes);
preconditioner = IncompleteCholesky();
case "jacobi"
if order == 1, solver = JacobiPcgSolver(fes);
else, solver = BlockJacobiPcgSolver(fes, blf); end
if order == 1
preconditioner = DiagonalJacobi();
else
preconditioner = BlockJacobi(fes, blf);
end
case {"", "additiveSchwarzLowOrder"}
if order == 1, solver = LowestOrderAdditiveSchwarzPcg(fes, blf, P);
if order == 1
solver = LowestOrderAdditiveSchwarzPcg(fes, blf, P);
else
solver = AdditiveSchwarzLowOrderPcg(fes, blf);
end
......@@ -38,16 +43,25 @@ switch class
otherwise
error('No PCG variant %s!', variant)
end
if isempty(solver)
solver = PcgSolverTEMP(preconditioner);
end
% geometric multigrid family
case "multigrid"
switch variant
case {"", "lowOrderVcycle"}
if order == 1, solver = LowestOrderLocalMg(fes, blf, P);
else, solver = LocalMgLowOrderVcycle(fes, blf); end
if order == 1
solver = LowestOrderLocalMg(fes, blf, P);
else
solver = LocalMgLowOrderVcycle(fes, blf);
end
case "highOrderVcycle"
if order == 1, solver = LowestOrderLocalMg(fes, blf, P);
else, solver = LocalMgHighOrderVcycle(fes, blf, P); end
if order == 1
solver = LowestOrderLocalMg(fes, blf, P);
else
solver = LocalMgHighOrderVcycle(fes, blf, P);
end
otherwise
error('No multigrid variant %s!', variant)
end
......
% BlockJacobiPcgSolver (subclass of PcgSolver) Solves linear equations
% iteratively using the CG method with block-diagonal preconditioner.
% BlockJacobi (subclass of Preconditioner) block-diagonal preconditioner.
%
% See also: Preconditioner, PcgSolver
classdef BlockJacobiPcgSolver < PcgSolver
classdef BlockJacobi < Preconditioner
%% properties
properties (GetAccess=public,SetAccess=protected)
fes
end
properties (Access=private)
C
fes
blf
end
%% methods
methods (Access=public)
% preconditioner action: patchwise inverse of diagonal
function obj = BlockJacobiPcgSolver(fes, blf)
function obj = BlockJacobi(fes, blf)
arguments
fes FeSpace
blf BilinearForm
end
obj = obj@PcgSolver();
obj.fes = fes;
obj.blf = blf;
end
function setupSystemMatrix(obj, A)
function setup(obj, A)
obj.C = assemblePatchwise(obj.blf, obj.fes, ':');
setupSystemMatrix@PcgSolver(obj, A);
end
function setupRhs(obj, b, varargin)
setupRhs@PcgSolver(obj, b, varargin{:});
end
function Cx = preconditionAction(obj, x)
function Cx = apply(obj, x)
Cx = obj.C \ x;
end
end
......
% DiagonalJacobi (subclass of Preconditioner) diagonal preconditioner.
%
% See also: Preconditioner, PcgSolver
classdef DiagonalJacobi < Preconditioner
%% properties
properties (Access=private)
C
end
%% methods
methods (Access=public)
% preconditioner action: inverse of diagonal
function setup(obj, A)
obj.C = full(diag(A)).^(-1);
end
function Cx = apply(obj, x)
Cx = obj.C .* x;
end
end
end
\ No newline at end of file
% IncompleteCholesky (subclass of Preconditioner) incomplete Cholesky
% decomposition preconditioner.
%
% See also: Preconditioner, PcgSolver
classdef IncompleteCholesky < Preconditioner
%% properties
properties (Access=private)
C
end
%% methods
methods (Access=public)
function setup(obj, A)
obj.C = ichol(A);
end
function Cx = apply(obj, x)
Cx = obj.C' \ (obj.C \ x);
end
end
end
\ No newline at end of file
% IdentityPC (subclass of Preconditioner) identity preconditioner (=no-op).
% NoPreconditioner (subclass of Preconditioner) identity preconditioner (=no-op).
%
% See also: Preconditioner
% See also: Preconditioner, PcgSolver
classdef IdentityPC < Preconditioner
classdef NoPreconditioner < Preconditioner
methods (Access=public)
function Cx = apply(~, x)
Cx = x;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment