7 #include "imstkGaussSeidel.h" 8 #include "imstkLogger.h" 12 GaussSeidel::GaussSeidel(
const SparseMatrixd& A,
const Vectord& rhs) : GaussSeidel()
14 this->setSystem(std::make_shared<LinearSystem<SparseMatrixd>>(A, rhs));
22 LOG(WARNING) <<
"Gauss-Seidel::solve: Linear system is not supplied for Gauss-Seidel solver!";
26 if (!m_FixedLinearProjConstraints)
28 this->gaussSeidelSolve(x);
39 this->setTolerance(tolerance);
46 const auto& b = m_linearSystem->getRHSVector();
47 const auto& A = m_linearSystem->getMatrix();
54 while (iterNum < this->getMaxNumIterations())
56 for (
auto k = 0; k < A.outerSize(); ++k)
59 double aggregate = 0.;
60 for (SparseMatrixd::InnerIterator it(A, k); it; ++it)
65 aggregate += it.value() * x[col];
72 x[k] = (b[k] - aggregate) / diagEle;
75 if ((x - xOld).norm() < 1.0e-4)
113 LOG(INFO) <<
"Solver: Gauss-Seidel";
114 LOG(INFO) <<
"Tolerance: " << m_tolerance;
115 LOG(INFO) <<
"max. iterations: " << m_maxIterations;
void setTolerance(const double tolerance)
Set solver tolerance.
void setSystem(std::shared_ptr< LinearSystemType > newSystem) override
Sets the system. System of linear equations.
virtual void setMaxNumIterations(const size_t maxIter) override
set/get the maximum number of iterations for the iterative solver.
void print() const override
Print solver information.
void gaussSeidelSolve(Vectord &x)
Do one iteration of the method.
virtual void setMaxNumIterations(const size_t maxIter)
Do one iteration of the method.
void print() const override
Print solver information.
Represents the linear system of the form .
void solve(Vectord &x) override
Solve the system of equations.
void setTolerance(const double tolerance)
Set solver tolerance.
double getResidual(const Vectord &x) override
Return the error calculated by the solver.
virtual void setSystem(std::shared_ptr< LinearSystemType > newSystem)
Set/get the system. Replaces/Returns the stored linear system of equations.