// // AMGCLSolver.hpp // #ifdef USE_AMGCL #ifndef AMGCLSolver_hpp #define AMGCLSolver_hpp #include "LinSysSolver.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #define USE_BW_BACKEND // use blockwise backend, must undef USE_BW_AGGREGATION // #define USE_BW_AGGREGATION // use scalar backend but blockwise aggregation, must undef USE_BW_BACKEND // if neither of above is defined, will use scalar backend and aggregation // #define USE_AMG_SOLVER // use a single V-cycle to approximately solve the linear system // if not defined then will use V-cycle preconditioned CG to solve the linear system namespace SIM { template class AMGCLSolver : public LinSysSolver { typedef LinSysSolver Base; #ifdef USE_BW_BACKEND typedef amgcl::static_matrix value_type; typedef amgcl::static_matrix rhs_type; typedef amgcl::backend::builtin BBackend; using Solver = amgcl::make_solver< // Use AMG as preconditioner: amgcl::amg< BBackend, amgcl::coarsening::smoothed_aggregation, amgcl::relaxation::gauss_seidel>, // And BiCGStab as iterative solver: amgcl::solver::lgmres>; #else typedef amgcl::backend::builtin Backend; // Use AMG as preconditioner: typedef amgcl::make_solver< // Use AMG as preconditioner: amgcl::amg< Backend, amgcl::coarsening::smoothed_aggregation, amgcl::relaxation::gauss_seidel>, // And CG as iterative solver: amgcl::solver::lgmres> Solver; #endif protected: Solver* solver; std::vector _ia, _ja; std::vector _a; public: AMGCLSolver(void); ~AMGCLSolver(void); void set_pattern(const std::vector>& vNeighbor); void load(const char* filePath, Eigen::VectorXd& rhs); void load_AMGCL(const char* filePath, Eigen::VectorXd& rhs); void write_AMGCL(const char* filePath, const Eigen::VectorXd& rhs) const; void copyOffDiag_IJ(void); void copyOffDiag_a(void); void analyze_pattern(void); bool factorize(void); void solve(Eigen::VectorXd& rhs, Eigen::VectorXd& result); }; } // namespace SIM #endif /* AMGCLSolver_hpp */ #endif /* USE_AMGCL */