27#include <Eigen/Cholesky>
48template <base::concepts::sparse_matrix Matrix>
62template <base::concepts::sparse_matrix Matrix>
76template <base::concepts::sparse_matrix Matrix>
81 "Complex matrices are not supported.");
117 this->
logger(),
"AMG layer size {} (first layer)", coeff.cols());
130 this->
logger(),
"AMG layer size {}", next_matrix_size);
133 next_layer.
coeff_matrix = (*current_prolongation).transpose() *
134 (*current_matrix) * (*current_prolongation);
149 (*current_matrix) * (*current_prolongation);
175 template <base::concepts::dense_vector_of<scalar_type> Right,
176 base::concepts::dense_vector_of<scalar_type> Solution>
178 const auto& coeff_ref =
coeff();
181 this->logger(),
"Coefficient matrix must be a square matrix.");
184 "Right-hand-side vector must have the number of elements same as "
185 "the size of the coefficient matrix.");
188 "Solution vector must have the number of elements same as the size "
189 "of the coefficient matrix.");
203 "Solved a linear equation with {} iterations. (Residual rate: {})",
216 "The maximum size of matrices to solve directly must be a positive "
251 template <base::concepts::dense_vector_of<scalar_type> Right,
252 base::concepts::dense_vector_of<scalar_type> Solution>
253 void iterate(
const Right& right, Solution& solution)
const {
258 (right -
coeff() * solution);
301 const auto transposed_connections = connections.transpose();
303 connections, transposed_connections);
305 connections, transposed_connections, node_classification);
307 prolongation_matrix, transposed_connections, node_classification);
Definition of build_first_coarse_grid_candidate function.
Class to solve linear equations using algebraic multigrid method ruge1987.
final_layer_data final_layer_
Data of the final layer.
std::vector< dense_vector_type > residual_buffers_
Buffers of residuals in layers except for the first layer.
real_scalar_type strong_coeff_rate_threshold_
Threshold of the rate of coefficients to determine strong connections.
Eigen::MatrixX< scalar_type > dense_matrix_type
Type of the dense matrix used in this algorithm.
auto maximum_directly_solved_matrix_size(index_type value) -> algebraic_multigrid_solver &
Set the maximum size of matrices to solve directly.
void solve_vector_in_place(const Right &right, Solution &solution) const
Iterate repeatedly until stop criterion is satisfied for a vector.
index_type maximum_directly_solved_matrix_size_
Maximum size of matrices to solve directly.
algebraic_multigrid_solver()
Constructor.
void compute_prolongation_matrix(matrix_type &prolongation_matrix, const matrix_type &coeff_matrix)
Compute prolongation matrix from a coefficient matrix.
index_type iterations_
Number of iterations.
void compute(const matrix_type &coeff)
Prepare to solve.
auto iterations() const noexcept -> index_type
Get the number of iterations.
Eigen::VectorX< scalar_type > dense_vector_type
Type of the dense vector used in this algorithm.
static constexpr index_type default_maximum_directly_solved_matrix_size
Default value of the maximum size of matrices to solve directly.
first_layer_data first_layer_
Data of the first layer.
static constexpr auto default_strong_coeff_rate_threshold
Default value of the threshold of the rate of coefficients to determine strong connections.
std::deque< intermidiate_layer_data > intermidiate_layers_
Data of the intermidiate layers.
void iterate(const Right &right, Solution &solution) const
Iterate once.
std::vector< dense_vector_type > solution_buffers_
Buffers of solutions in layers except for the first layer.
auto residual_rate() const noexcept -> scalar_type
Get the rate of the last residual.
Base class of iterative solvers.
StorageIndex storage_index_type
auto coeff() const noexcept -> const matrix_type &
auto tolerance() const noexcept -> real_scalar_type
RealScalar real_scalar_type
auto compute(const matrix_type &coeff) -> algebraic_multigrid_solver< Matrix > &
auto max_iterations() const noexcept -> index_type
Get the maximum number of iterations.
Class to solve linear equations using symmetric successive over-relaxation using threads golub2013.
void solve_vector_in_place(const Right &right, Solution &solution) const
Iterate repeatedly until stop criterion is satisfied for a vector.
auto residual_rate() const noexcept -> scalar_type
Get the rate of the last residual.
void compute(const matrix_type &coeff)
Prepare to solve.
Class of tags of logs without memory management.
Class to incorporate logging in algorithms.
logging_mixin(log_tag_view tag)
Constructor.
auto logger() const noexcept -> const num_collect::logging::logger &
Access to the logger.
Definition of compute_strong_connection_list function.
Definition of create_prolongation_matrix function.
Definition of dense_vector_of concept.
Definition of exceptions.
Definition of index_type type.
Definition of iterative_solver_base class.
Definition of log_tag_view class.
Definition of macros for logging.
#define NUM_COLLECT_LOG_SUMMARY(LOGGER,...)
Write a summary log.
#define NUM_COLLECT_LOG_TRACE(LOGGER,...)
Write a trace log.
Definition of logging_mixin class.
std::ptrdiff_t index_type
Type of indices in this library.
void create_prolongation_matrix(Matrix &prolongation_matrix, const node_connection_list< typename Matrix::StorageIndex > &transposed_connections, const util::vector< node_layer > &node_classification)
Create a prolongation matrix.
void tune_coarse_grid_selection(const node_connection_list< StorageIndex > &connections, const node_connection_list< StorageIndex > &transposed_connections, util::vector< node_layer > &node_classification)
Tune a coarse grid to satisfy the condition for interpolation specified in ruge1987.
auto build_first_coarse_grid_candidate(const node_connection_list< StorageIndex > &connections, const node_connection_list< StorageIndex > &transposed_connections) -> util::vector< node_layer >
Build the first candidate of a coarse grid.
auto compute_strong_connection_list(const Matrix &matrix, typename Matrix::Scalar strong_coeff_rate_threshold) -> node_connection_list< typename Matrix::StorageIndex >
Compute a list of strong connections in a matrix ruge1987.
Namespace of solvers of linear equations.
constexpr auto algebraic_multigrid_solver_tag
Log tag for num_collect::linear::algebraic_multigrid_solver.
Definition of parallel_symmetric_successive_over_relaxation class.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of real_scalar concept.
Definition of sparse_matrix concept.
Struct of internal data for the final layer.
Eigen::LLT< dense_matrix_type > solver
Solver of the final coefficient matrix.
dense_matrix_type coeff_matrix
Coefficient matrix in this layer.
Struct of internal data for the first layer.
matrix_type prolongation_matrix
Prolongation matrix from the next layer.
parallel_symmetric_successive_over_relaxation< matrix_type > smoother
Smoother in this layer.
Struct of internal data for the intermidiate layers.
matrix_type prolongation_matrix
Prolongation matrix from the next layer.
parallel_symmetric_successive_over_relaxation< matrix_type > smoother
Smoother in this layer.
matrix_type coeff_matrix
Coefficient matrix in this layer.
Matrix matrix_type
Type of the matrix.
Traits of iterative solvers.
Definition of tune_coarse_grid_selection function.