Advanced Multi-Physics (AMP)
On-Line Documentation
Strength.h
Go to the documentation of this file.
1#ifndef included_AMP_AMG_STRENGTH
2#define included_AMP_AMG_STRENGTH
3
4#include "AMP/matrices/CSRMatrix.h"
5#include "AMP/solvers/amg/Util.h"
6
7#include <tuple>
8#include <vector>
9
10namespace AMP::Solver::AMG {
11
12template<class Mat>
13struct Strength {
14 explicit Strength( csr_view<Mat> A );
15 using mask_t = typename csr_view<Mat>::mask_t;
16 using lidx_t = typename csr_view<Mat>::lidx_t;
18
19 constexpr auto diag_row( lidx_t r ) { return d_diag.row( r ); }
20
21 constexpr auto diag_row( lidx_t r ) const { return d_diag.row( r ); }
22
23 constexpr auto offd_row( lidx_t r ) { return d_offd.row( r ); }
24
25 constexpr auto offd_row( lidx_t r ) const { return d_offd.row( r ); }
26
27 constexpr lidx_t numLocalRows() const { return d_diag.rowptr.size() - 1; }
28
29 bool is_strong( lidx_t i, lidx_t j ) const
30 {
31 auto search = [=]( auto ptrs ) {
32 auto [rowptr, colind, values] = ptrs;
33 for ( lidx_t off = rowptr[i]; off < rowptr[i + 1]; ++off ) {
34 if ( j == colind[off] && values[off] )
35 return true;
36 }
37 return false;
38 };
39
40 return search( diag() ) || search( offd() );
41 }
42
43 template<class F>
44 void do_strong( lidx_t r, F &&f ) const
45 {
46 auto loop = [=]( auto ptrs ) {
47 auto [rowptr, colind, values] = ptrs;
48 for ( lidx_t off = rowptr[r]; off < rowptr[r + 1]; ++off ) {
49 if ( values[off] )
50 f( colind[off] );
51 }
52 };
53 loop( diag() );
54 // loop(offd());
55 }
56
57 template<class F>
58 void do_strong_val( lidx_t r, F &&f ) const
59 {
60 auto loop = [=]( auto ptrs, auto mat_values ) {
61 auto [rowptr, colind, values] = ptrs;
62 for ( lidx_t off = rowptr[r]; off < rowptr[r + 1]; ++off ) {
63 if ( values[off] )
64 f( colind[off], mat_values[off] );
65 }
66 };
67 loop( diag(), d_diag.mat_values );
68 // loop(offd());
69 }
70
71private:
72 struct storage {
73 using alloc_t = typename std::allocator_traits<
76
82
84 : rowptr( std::get<0>( A_ptrs ) ),
85 colind( std::get<1>( A_ptrs ) ),
86 mat_values( std::get<2>( A_ptrs ) )
87 {
88 values = valueAllocator.allocate( colind.size() );
89 }
90
91 ~storage() { valueAllocator.deallocate( values, colind.size() ); }
92
93 struct reference {
94 using ref_type = mask_t &;
95 using const_ref_type = const mask_t &;
98 constexpr ref_type operator[]( lidx_t i ) { return ptr[offset + i]; }
99 constexpr const_ref_type operator[]( lidx_t i ) const { return ptr[offset + i]; }
100 };
101 constexpr reference row( lidx_t r ) { return { values, rowptr[r] }; }
102
103 constexpr reference row( lidx_t r ) const { return { values, rowptr[r] }; }
105
106public:
107 using rep_type = std::tuple<span<const lidx_t>, span<const lidx_t>, const mask_t *>;
108 auto diag() const { return rep_type{ d_diag.rowptr, d_diag.colind, d_diag.values }; }
109
110 auto offd() const { return rep_type{ d_offd.rowptr, d_offd.colind, d_offd.values }; }
111
112 const auto diag_mask_data() const { return d_diag.values; }
113
114 const auto offd_mask_data() const { return d_offd.values; }
115
116 auto diag_mask_data() { return d_diag.values; }
117
118 auto offd_mask_data() { return d_offd.values; }
119};
120
121enum class norm { abs, min };
122template<norm norm_type>
124
125template<norm norm_type>
127
128template<class StrengthPolicy, class Mat>
130
131} // namespace AMP::Solver::AMG
132
133#endif
Strength< Mat > compute_soc(csr_view< Mat > A, float threshold)
typename std::allocator_traits< A >::template rebind_alloc< T > rebind_alloc
Definition Util.h:114
constexpr const_ref_type operator[](lidx_t i) const
Definition Strength.h:99
constexpr ref_type operator[](lidx_t i)
Definition Strength.h:98
span< const lidx_t > colind
Definition Strength.h:78
constexpr reference row(lidx_t r) const
Definition Strength.h:103
typename std::allocator_traits< typename csr_view< Mat >::allocator_type >::template rebind_alloc< mask_t > alloc_t
Definition Strength.h:74
span< const scalar_t > mat_values
Definition Strength.h:79
typename csr_view< Mat >::csr_ptrs_t csr_ptrs_t
Definition Strength.h:75
span< const lidx_t > rowptr
Definition Strength.h:77
constexpr reference row(lidx_t r)
Definition Strength.h:101
constexpr auto diag_row(lidx_t r) const
Definition Strength.h:21
constexpr auto offd_row(lidx_t r) const
Definition Strength.h:25
Strength(csr_view< Mat > A)
const auto offd_mask_data() const
Definition Strength.h:114
constexpr auto diag_row(lidx_t r)
Definition Strength.h:19
std::tuple< span< const lidx_t >, span< const lidx_t >, const mask_t * > rep_type
Definition Strength.h:107
struct AMP::Solver::AMG::Strength::storage d_diag
void do_strong_val(lidx_t r, F &&f) const
Definition Strength.h:58
typename csr_view< Mat >::mask_t mask_t
Definition Strength.h:15
void do_strong(lidx_t r, F &&f) const
Definition Strength.h:44
constexpr lidx_t numLocalRows() const
Definition Strength.h:27
constexpr auto offd_row(lidx_t r)
Definition Strength.h:23
const auto diag_mask_data() const
Definition Strength.h:112
typename csr_view< Mat >::lidx_t lidx_t
Definition Strength.h:16
bool is_strong(lidx_t i, lidx_t j) const
Definition Strength.h:29
struct AMP::Solver::AMG::Strength::storage d_offd
typename csr_view< Mat >::scalar_t scalar_t
Definition Strength.h:17
constexpr size_type size() const noexcept
Definition Util.h:69



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:41.
Comments on this page