[eigen] Reusing preconditioners |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Reusing preconditioners
- From: fpp2005st@xxxxxxxxxxx
- Date: Tue, 8 Mar 2022 20:13:40 +0000
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=HmKHGiIjuFdzK3+j0+vrZw4QwEqG7e8Idzd54n61ynw=; b=X1w1pNqyTP7fDD2OVgQOLcuHcwSy3HF+5hbON8fJUEVvgDniZe8JJv35ThFF4uUpGLOwwreLN0AdvKAodwnAwuY/vsGG8H4ngI44rldmY73IRgNLlaZaD8F3j7CYXGi+22G5VAKEAOrgDRD6FwpQdi4dkhVk5ixpTsLjD/1X/+H3GNoif1ORIcqIhPViyFNm8XYRUA5CkBJhKWkVc64nhU1FQVQRm7OkhNiX18MbY9P+tI13tjplCNMZimmrn/IXt/TZtSsSdh/zZAISGnjcueyDGmugNFfyPbF4TkRBgcs7mUImyrO4ZRVWIko2f7+XT6nPfDb2MHbyh75431oj+Q==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iowPJd7XejC59q0Wcn716saQAegOxvuA3sTqcK9yMYT5g8Ji29iv0B7oX1XbKxFrq0pbS1ycZxC2TRfdt++uWvpkxOKiMui776nBwr2JEAYQGoliQxbRpKwgJCJeOZuRM1rCtNl7rE5+LC0pvPLvK0dqVunyDzDMQ5/dro24NzQtlNYxJ1LJYmC4j5Qw2+SMps95GGFIXcevd0WXcC3cBOGFDWH0dfW2cu9+nxuOwQIlKmsIR0zCcEcIps+DNoyVDq5Zf/Zl/Nf948S4QUcR0q6uuOQDCM0z7snTjqield34zwvEU50ukL/OZ0MVHoO5bzYIgzEJcnqj5r2b4rJ+3g==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HmKHGiIjuFdzK3+j0+vrZw4QwEqG7e8Idzd54n61ynw=; b=cTnePQFpVbPJbltTutEmNk6v/lR/5YSqOg7EhZTA7qvY/s+LFklyffK0E3CnqePZdl1YCzjQBl4FRN8Xz42Qrk9SitzuLDvTCKDS64HnZMdutR8ORdgXAiPp60bvc9eiDL2x8Yf1+Nvarvzfbedy9AhWi3r4uF0NU1q3G6MdzG15GOKa+xjTegBatdhcEnkKbL9B8CwnPwBoB8r0KHvQhdXr1x/9ZgLeDf1f5W+RMsTx9ADPvatL4EjrBeuroi87kxO0n81NuuzK1aqfrYM4lJuy+FTaaWXGMKwjHtVFz0fLstP/krLbpu+kc+MxowY0+nUkUt2TUdudgowugLkbPQ==
Dear all,
While upgrading from Eigen 3.2.x to 3.4.0 I faced a issue in my code,
related with the reuse of preconditioners. Say for example that you have
initially a given sparse matrix A and the corresponding iterative solver
and preconditioner, that you use to solve for a given rhs vector b.
Then, the non-zero coefficients of matrix A get slightly modified, such
that I would like to keep reusing the same preconditioner to solve for
the same or different vector b. With Eigen 3.2.x, I could directly call
for solve() with the second matrix (without a previous call to
compute(), as this would create a new preconditioner) and it would work.
With 3.4.0, it only works if the second matrix is not reset with a call
to setFromTriplets(), for example if the second matrix results from the
first one multiplied by a factor.
From what I have read in the documentation, there are several warnings
stating that the solver creates a link to matrix A and if it changes,
then one needs to compute() or factorize() before a new solve(), i.e. it
shall not be possible to reuse the preconditioner. However, that was
allowed in 3.2.x and it keeps working in 3.4 as long as there is no call
to setFromTriplets(). That was a quite handy feature, as it allowed
reusing the preconditioner (factorization) in similar matrices, i.e.
sparse matrices with the same filling pattern, but different
coefficients. This happens a lot in finite element analysis.
My question is: is it possible to reuse a preconditioner in Eigen 3.4
after calling setFromTriplets() in the matrix originally used to build
the preconditioner? I think that this should be allowed as long as we
ensure that the non-zero patterns keeps unchanged. Please find bellow a
snippet showing what I described:
//****
#include <Eigen/IterativeLinearSolvers>
#include <vector>
#include <iostream>
typedef Eigen::SparseMatrix<double> SpMat;
typedef Eigen::Triplet<double> T;
void popTri
(
std::vector<T>& tripletList,
double f
)
{
tripletList.push_back(T(0,0,-4*f));
tripletList.push_back(T(0,1,2*f));
tripletList.push_back(T(1,0,1*f));
tripletList.push_back(T(1,1,-4*f));
tripletList.push_back(T(1,2,1*f));
tripletList.push_back(T(2,1,1*f));
tripletList.push_back(T(2,2,-4*f));
}
int main()
{
SpMat A(3,3);
std::vector<T> tripletList;
Eigen::Vector3d b1(1,2,3);
Eigen::BiCGSTAB<SpMat, Eigen::IncompleteLUT<double> > solver;
// Solve 1 (ok in both 3.2 and 3.4)
popTri(tripletList,1);
A.setFromTriplets(tripletList.begin(), tripletList.end());
solver.analyzePattern(A);
solver.factorize(A);
std::cout << "A1\n" << solver.solve(b1) << std::endl;
// Solve 2 (ok in both 3.2 and 3.4)
A*=2.;
std::cout << "A2\n" << solver.solve(b1) << std::endl;
// Solve 3 (ok in 3.2 but not in 3.4)
// Note: solve 3 makes the same modification in A as solve 2,
// with the only difference that it uses setFromTriplets instead of
// directly multiplying by the factor
tripletList.clear();
popTri(tripletList,2);
A.setFromTriplets(tripletList.begin(), tripletList.end());
std::cout << "A3\n" << solver.solve(b1) << std::endl;
return 0;
}
//***
Thank you very much for your time.
Best regards,
Fernando.