Skip to content
Snippets Groups Projects
Commit 6cfaeb0b authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

ENH: Move linear solver tolerance to base class

Move linear solver tolerance to base class. The tolerance is automatically set to machine precision.
Add API to query if a solver is iterative or not.
parent 9bf0c5bb
No related branches found
No related tags found
No related merge requests found
......@@ -107,6 +107,10 @@ const double LN10 = 2.30258509299404568402;
const double MAX_D = std::numeric_limits<double>::max();
const double MIN_D = std::numeric_limits<double>::min();
const double MAX_F = std::numeric_limits<float>::max();
const double MIN_F = std::numeric_limits<float>::min();
const double MACHINE_PRECISION = std::numeric_limits<double>::denorm_min();
}
#endif // ifndef imstkMath_h
......@@ -66,6 +66,14 @@ public:
///
void setSystem(std::shared_ptr<LinearSystemType> newSystem) override;
///
/// \brief Returns true if the solver is iterative
///
bool isIterative() const
{
return false;
};
private:
Eigen::LDLT<Matrixd> solver;
};
......
......@@ -60,7 +60,7 @@ IterativeLinearSolver::getResidual(const Vectord& x)
}
void
IterativeLinearSolver::print()
IterativeLinearSolver::print() const
{
// Print Type
LinearSolver::print();
......@@ -68,12 +68,6 @@ IterativeLinearSolver::print()
LOG(INFO) << "Solver type (direct/iterative): Iterative";
}
double
IterativeLinearSolver::getTolerance() const
{
return m_tolerance;
}
void
IterativeLinearSolver::solve(Vectord& x)
{
......@@ -97,10 +91,4 @@ IterativeLinearSolver::solve(Vectord& x)
}
}
void
IterativeLinearSolver::setTolerance(const double tolerance)
{
m_tolerance = tolerance;
}
} //imstk
......@@ -60,24 +60,25 @@ public:
///
virtual double getResidual(const Vectord &x);
///
/// \brief Get/set solver tolerance
///
void setTolerance(const double tolerance);
double getTolerance() const;
///
/// \brief Print solver information.
///
virtual void print() override;
virtual void print() const override;
///
/// \brief Solve the linear system using Gauss-Seidel iterations.
///
virtual void solve(Vectord &x) override;
///
/// \brief Returns true if the solver is iterative
///
bool isIterative() const
{
return true;
};
protected:
double m_tolerance; ///> residual tolerance
size_t m_maxIterations; ///> Maximum number of iterations to be performed.
Vectord m_residual; ///> Storage for residual vector.
};
......
......@@ -46,9 +46,23 @@ LinearSolver<SystemMatrixType>::getSystem() const
template<typename SystemMatrixType>
void
imstk::LinearSolver<SystemMatrixType>::print()
LinearSolver<SystemMatrixType>::print()
{
LOG(INFO) << "Solver type (broad): Linear";
}
template<typename SystemMatrixType>
void
LinearSolver<SystemMatrixType>::setTolerance(const double tolerance)
{
m_tolerance = tolerance;
}
template<typename SystemMatrixType>
double
LinearSolver<SystemMatrixType>::getTolerance() const
{
return m_tolerance;
}
} //imstk
\ No newline at end of file
......@@ -36,7 +36,18 @@ class LinearSolver
{
public:
using MatrixType = SystemMatrixType;
using LinearSystemType = LinearSystem<MatrixType>;
using LinearSystemType = LinearSystem < MatrixType > ;
enum class Type
{
ConjugateGradient,
LUFactorization,
GaussSeidel,
SuccessiveOverRelaxation,
Jacobi,
GMRES,
none
};
public:
///
......@@ -56,13 +67,30 @@ public:
virtual void setSystem(std::shared_ptr<LinearSystemType> newSystem);
std::shared_ptr<LinearSystemType> getSystem() const;
///
/// \brief Set solver tolerance
///
void setTolerance(const double tolerance);
///
/// \brief Get solver tolerance
///
double getTolerance() const;
///
/// \brief Print solver information.
///
virtual void print();
virtual void print() const;
///
/// \brief Returns true if the solver is iterative
///
virtual bool isIterative() const = 0;
protected:
std::shared_ptr<LinearSystemType> m_linearSystem; /// Linear system of equations
Type m_Type; ///> Type of the scene object
double m_tolerance = MACHINE_PRECISION; ///> default tolerance
std::shared_ptr<LinearSystemType> m_linearSystem; /// Linear system of equations
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment