Page MenuHomec4science

sparse_qr.hpp
No OneTemporary

File Metadata

Created
Wed, Nov 6, 12:12

sparse_qr.hpp

#ifndef SPECMICP_SPARSESOLVERS_SPARSEQR_HPP
#define SPECMICP_SPARSESOLVERS_SPARSEQR_HPP
#include "sparse_solver_structs.hpp"
#include "sparse_solver_base.hpp"
#include <Eigen/SparseQR>
namespace specmicp {
namespace sparse_solvers {
template <class MatrixT, class DerivedR, class DerivedS>
class SparseSolverQR: public SparseSolverBase<MatrixT, DerivedR, DerivedS>
{
using SolverT = Eigen::SparseQR<MatrixT, Eigen::COLAMDOrdering<int>>;
public:
//! \brief Decompose the jacboian
SparseSolverReturnCode decompose(MatrixT& jacobian)
{
m_solver = SolverT(jacobian);
if (m_solver.info() != Eigen::Success)
{
return SparseSolverReturnCode::FailedDecomposition;
}
return SparseSolverReturnCode::Success;
}
//! \brief Solve the problem
SparseSolverReturnCode solve(
const DerivedR& residuals,
DerivedS& solution
)
{
solution = m_solver.solve(-residuals);
if (m_solver.info() != Eigen::Success)
{
return SparseSolverReturnCode::FailedSystemSolving;
}
return SparseSolverReturnCode::Success;
}
SparseSolverReturnCode solve_scaling(
const DerivedR& residuals,
const DerivedR& scaling,
DerivedS& solution
)
{
solution = m_solver.solve(scaling.asDiagonal()*(-residuals));
if (m_solver.info() != Eigen::Success)
{
return SparseSolverReturnCode::FailedSystemSolving;
}
return SparseSolverReturnCode::Success;
}
private:
SolverT m_solver;
};
} // end namespace sparse_solvers
} // end namespace specmicp
#endif //SPECMICP_SPARSESOLVERS_SPARSEQR_HPP

Event Timeline