classdef CustomSolver < LinearSolverAD
properties
options = struct("type","ilutp","droptol",1e-6);
end
methods
function solver = CustomSolver(varargin)
solver@LinearSolverAD();
solver = merge_options(solver, varargin{:});
end
function [result, report] = solveLinearSystem(solver, A, b, varargin)
timer = tic();
try
setup.type = 'ilutp';
setup.droptol = max(1e-3, solver.options.droptol); % larger drop tolerance -> cheaper
setup.udiag = 1; % keep unit diagonal if appropriate
[L,U] = ilu(sparse(A), setup);
catch
d = diag(A);
d(abs(d) < eps) = 1; % avoid division by zero
Dinv = spdiags(1./d, 0, size(A,1), size(A,2));
L = speye(size(A,1)); % treat as M1 = I
U = Dinv; % treat as M2 = D^{-1} (applied on right in bicgstab/gmres calls)
end
result = bicgstab(A,b,1e-4,100,L,U);
t_solve = toc(timer);
report = solver.getSolveReport('LinearSolutionTime', t_solve);
end
function [d, sn] = getDescription(solver)
sn = 'mldivide';
d = 'Matlab \ operator (mldivide direct solver)';
end
end
end