8 #include "imstkLogger.h" 9 #include "imstkLinearProjectionConstraint.h" 13 SOR::SOR(
const SparseMatrixd& A,
const Vectord& rhs) : SOR()
15 this->setSystem(std::make_shared<LinearSystem<SparseMatrixd>>(A, rhs));
23 LOG(WARNING) <<
"SOR::solve: Linear system is not supplied for Gauss-Seidel solver!";
27 if (m_FixedLinearProjConstraints->size() == 0)
40 this->setTolerance(tolerance);
47 const auto& b = m_linearSystem->getRHSVector();
48 const auto& A = m_linearSystem->getMatrix();
55 while (iterNum < this->getMaxNumIterations())
57 for (
auto k = 0; k < A.outerSize(); ++k)
60 double aggregate = 0.;
61 for (SparseMatrixd::InnerIterator it(A, k); it; ++it)
66 aggregate += it.value() * x[col];
73 x[k] = (b[k] - aggregate) / diagEle;
75 x *= m_relaxationFactor;
76 x += (1. - m_relaxationFactor) * xOld;
78 if ((x - xOld).norm() < 1.0e-4)
116 LOG(INFO) <<
"Solver: SOR";
117 LOG(INFO) <<
"Tolerance: " << m_tolerance;
118 LOG(INFO) <<
"max. iterations: " << m_maxIterations;
void setTolerance(const double tolerance)
Set solver tolerance.
void solve(Vectord &x) override
Solve the system of equations.
void setTolerance(const double tolerance)
Set solver tolerance.
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 print() const override
Print solver information.
double getResidual(const Vectord &x) override
Return the error calculated by the solver.
void SORSolve(Vectord &x)
Do one iteration of the method.
void setMaxNumIterations(const size_t maxIter) override
set/get the maximum number of iterations for the iterative solver.
virtual void setSystem(std::shared_ptr< LinearSystemType > newSystem)
Set/get the system. Replaces/Returns the stored linear system of equations.
void setSystem(std::shared_ptr< LinearSystemType > newSystem) override
Sets the system. System of linear equations.