Advanced Multi-Physics (AMP)
On-Line Documentation
MatrixDataTransforms.h
Go to the documentation of this file.
1#ifndef included_MatrixDataTransforms_h
2#define included_MatrixDataTransforms_h
3
4#include "AMP/matrices/Matrix.h"
5
6#include <numeric>
7#include <type_traits>
8
9namespace AMP::LinearAlgebra {
10
11template<typename Policy>
12void transformDofToCSR( std::shared_ptr<Matrix> matrix,
13 typename Policy::gidx_t &startRow,
14 typename Policy::gidx_t &endRow,
15 typename Policy::gidx_t &startCol,
16 typename Policy::gidx_t &endCol,
17 std::vector<typename Policy::lidx_t> &rs_d,
18 std::vector<typename Policy::gidx_t> &cols_d,
19 std::vector<typename Policy::scalar_t> &coeffs_d,
20 std::vector<typename Policy::lidx_t> &rs_od,
21 std::vector<typename Policy::gidx_t> &cols_od,
22 std::vector<typename Policy::scalar_t> &coeffs_od )
23{
24 using gidx_t = typename Policy::gidx_t;
25 using lidx_t = typename Policy::lidx_t;
26 using scalar_t = typename Policy::scalar_t;
27
28 AMP_ASSERT( matrix );
29
30 auto lDOF = matrix->getLeftDOFManager();
31 auto rDOF = matrix->getRightDOFManager();
32
33 startRow = static_cast<gidx_t>( rDOF->beginDOF() );
34 endRow = static_cast<gidx_t>( rDOF->endDOF() );
35 startCol = static_cast<gidx_t>( lDOF->beginDOF() );
36 endCol = static_cast<gidx_t>( lDOF->endDOF() );
37
38 // prime rowstart vectors with first zero entry
39 rs_d.push_back( 0 );
40 rs_od.push_back( 0 );
41
42 // loop over rows and examine structure
43 for ( auto row = startRow; row < endRow; ++row ) {
44
45 std::vector<size_t> rcols;
46 std::vector<scalar_t> rvals;
47
48 matrix->getRowByGlobalID( row, rcols, rvals );
49
50 // Loop over columns and insert into on and off diagonal blocks
51 lidx_t nnzd = 0, nnzod = 0;
52 for ( size_t i = 0; i < rcols.size(); ++i ) {
53 const auto col = static_cast<gidx_t>( rcols[i] );
54 if ( startCol <= col && col < endCol ) {
55 ++nnzd;
56 cols_d.push_back( col );
57 coeffs_d.push_back( static_cast<scalar_t>( rvals[i] ) );
58 } else {
59 ++nnzod;
60 cols_od.push_back( col );
61 coeffs_od.push_back( static_cast<scalar_t>( rvals[i] ) );
62 }
63 }
64 const lidx_t prev_rs_d = rs_d.back();
65 const lidx_t prev_rs_od = rs_od.back();
66 rs_d.push_back( prev_rs_d + nnzd );
67 rs_od.push_back( prev_rs_od + nnzod );
68 }
69}
70} // namespace AMP::LinearAlgebra
71
72#endif
#define AMP_ASSERT(EXP)
Assert error.
void transformDofToCSR(std::shared_ptr< Matrix > matrix, typename Policy::gidx_t &startRow, typename Policy::gidx_t &endRow, typename Policy::gidx_t &startCol, typename Policy::gidx_t &endCol, std::vector< typename Policy::lidx_t > &rs_d, std::vector< typename Policy::gidx_t > &cols_d, std::vector< typename Policy::scalar_t > &coeffs_d, std::vector< typename Policy::lidx_t > &rs_od, std::vector< typename Policy::gidx_t > &cols_od, std::vector< typename Policy::scalar_t > &coeffs_od)



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:40.
Comments on this page