numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
compute_strong_connection_list.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cmath>
23
27
29
39template <base::concepts::sparse_matrix Matrix>
41 const Matrix& matrix, typename Matrix::Scalar strong_coeff_rate_threshold)
43 using scalar_type = typename Matrix::Scalar;
44 using std::abs;
45
47
48 const index_type num_nodes = matrix.outerSize();
49 for (index_type i = 0; i < num_nodes; ++i) {
50 auto max_coeff = static_cast<scalar_type>(0);
51 for (typename Matrix::InnerIterator iter(matrix, i); iter; ++iter) {
52 const auto abs_coeff = abs(iter.value());
53 if (iter.index() != i && abs_coeff > max_coeff) {
54 max_coeff = abs_coeff;
55 }
56 }
57 const auto strong_coeff_threshold =
58 strong_coeff_rate_threshold * max_coeff;
59 for (typename Matrix::InnerIterator iter(matrix, i); iter; ++iter) {
60 if (iter.index() != i &&
61 abs(iter.value()) >= strong_coeff_threshold) {
62 list.push_back(iter.index());
63 }
64 }
66 }
67
68 return list;
69}
70
71} // namespace num_collect::linear::impl::amg
Class of lists of connected nodes per node.
void finish_current_node()
Finish adding connected nodes to the current node and start the next node.
void push_back(storage_index_type node_index)
Add a connected node to the current node.
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of internal implementations of algebraic multigrid method ruge1987.
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.
Definition of node_connection_list class.
Definition of sparse_matrix concept.