Nektar++
Public Types | Public Member Functions | Private Attributes | Static Private Attributes | List of all members
Nektar::MultiRegions::GlobalMatrix Class Reference

Represents a matrix of all degrees of freedom. More...

#include <GlobalMatrix.h>

Public Types

typedef NekSparseMatrix< StorageSmvBsr< NekDouble > > DNekSmvBsrMat
 
typedef std::shared_ptr< DNekSmvBsrMatDNekSmvBsrMatSharedPtr
 

Public Member Functions

 GlobalMatrix (const LibUtilities::SessionReaderSharedPtr &pSession, unsigned int rows, unsigned int columns, const COOMatType &cooMat, const MatrixStorage &matStorage=eFULL)
 Construct a new matrix. More...
 
 ~GlobalMatrix ()
 
void Multiply (const Array< OneD, const NekDouble > &in, Array< OneD, NekDouble > &out)
 Perform a matrix-vector multiply. More...
 
unsigned long GetMulCallsCounter () const
 
unsigned int GetNumNonZeroEntries () const
 

Private Attributes

DNekSmvBsrMatSharedPtr m_smvbsrmatrix
 Pointer to a double-precision Nektar++ sparse matrix. More...
 
unsigned int m_rows
 
Array< OneD, NekDoublem_tmpin
 
Array< OneD, NekDoublem_tmpout
 
unsigned long m_mulCallsCounter
 
bool m_copyOp
 

Static Private Attributes

static std::string def
 
static std::string lookupIds []
 

Detailed Description

Represents a matrix of all degrees of freedom.

This matrix is essentially a wrapper around a DNekSparseMat.

Definition at line 46 of file GlobalMatrix.h.

Member Typedef Documentation

◆ DNekSmvBsrMat

Definition at line 49 of file GlobalMatrix.h.

◆ DNekSmvBsrMatSharedPtr

Definition at line 50 of file GlobalMatrix.h.

Constructor & Destructor Documentation

◆ GlobalMatrix()

Nektar::MultiRegions::GlobalMatrix::GlobalMatrix ( const LibUtilities::SessionReaderSharedPtr pSession,
unsigned int  rows,
unsigned int  columns,
const COOMatType cooMat,
const MatrixStorage matStorage = eFULL 
)

Construct a new matrix.

Allocates a new DNekSparseMat object from the given specification.

Parameters
rowsNumber of rows in matrix.
columnsNumber of columns in matrix.
cooMat?

Definition at line 67 of file GlobalMatrix.cpp.

72{
73 MatrixStorageType storageType =
74 pSession->GetSolverInfoAsEnum<MatrixStorageType>(
75 "GlobalMatrixStorageType");
76
77 unsigned int brows, bcols;
78
79 // Size of dense matrix sub-blocks
80 int block_size = 1;
81
82 BCOMatType bcoMat;
83
84 // assuming current sparse format allows
85 // block-sparse data representation
86
87 if (pSession->DefinesParameter("SparseBlockSize"))
88 {
89 pSession->LoadParameter("SparseBlockSize", block_size);
90 ASSERTL1(block_size > 0,
91 "SparseBlockSize parameter must to be positive");
92 }
93
94 brows = rows / block_size + (rows % block_size > 0);
95 bcols = columns / block_size + (columns % block_size > 0);
96
97 if (rows % block_size > 0)
98 m_copyOp = true;
99
100 if (m_copyOp)
101 {
102 m_tmpin = Array<OneD, NekDouble>(brows * block_size, 0.0);
103 m_tmpout = Array<OneD, NekDouble>(brows * block_size, 0.0);
104 }
105
106 convertCooToBco(block_size, cooMat, bcoMat);
107
108 size_t matBytes = 0;
109 switch (storageType)
110 {
111 case eSmvBSR:
112 {
113
114 // Create zero-based Smv-multiply BSR sparse storage holder
117 brows, bcols, block_size, bcoMat, matStorage);
118
119 // Create sparse matrix
122
123 matBytes = m_smvbsrmatrix->GetMemoryFootprint();
124 }
125 break;
126
127 default:
129 "Unsupported sparse storage type chosen");
130 }
131
132 cout << "Global matrix storage type: " << MatrixStorageTypeMap[storageType]
133 << endl;
134 std::cout << "Global matrix memory, bytes = " << matBytes;
135 if (matBytes / (1024 * 1024) > 0)
136 {
137 std::cout << " (" << matBytes / (1024 * 1024) << " MB)" << std::endl;
138 }
139 else
140 {
141 std::cout << " (" << matBytes / 1024 << " KB)" << std::endl;
142 }
143 std::cout << "Sparse storage block size = " << block_size << std::endl;
144}
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:249
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
DNekSmvBsrMatSharedPtr m_smvbsrmatrix
Pointer to a double-precision Nektar++ sparse matrix.
Definition: GlobalMatrix.h:71
Array< OneD, NekDouble > m_tmpout
Definition: GlobalMatrix.h:75
Array< OneD, NekDouble > m_tmpin
Definition: GlobalMatrix.h:74
std::shared_ptr< SparseStorageType > SparseStorageSharedPtr
const char *const MatrixStorageTypeMap[]
std::map< CoordType, BCOEntryType > BCOMatType
void convertCooToBco(const unsigned int blkDim, const COOMatType &cooMat, BCOMatType &bcoMat)
Definition: SparseUtils.cpp:48

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), ASSERTL1, Nektar::convertCooToBco(), Nektar::ErrorUtil::efatal, Nektar::MultiRegions::eSmvBSR, m_copyOp, m_smvbsrmatrix, m_tmpin, m_tmpout, Nektar::MultiRegions::MatrixStorageTypeMap, and NEKERROR.

◆ ~GlobalMatrix()

Nektar::MultiRegions::GlobalMatrix::~GlobalMatrix ( )
inline

Definition at line 58 of file GlobalMatrix.h.

59 {
60 }

Member Function Documentation

◆ GetMulCallsCounter()

unsigned long Nektar::MultiRegions::GlobalMatrix::GetMulCallsCounter ( ) const

Definition at line 175 of file GlobalMatrix.cpp.

176{
177 if (m_smvbsrmatrix)
178 return m_smvbsrmatrix->GetMulCallsCounter();
179 return -1;
180}

References m_smvbsrmatrix.

◆ GetNumNonZeroEntries()

unsigned int Nektar::MultiRegions::GlobalMatrix::GetNumNonZeroEntries ( ) const

Definition at line 182 of file GlobalMatrix.cpp.

183{
184 if (m_smvbsrmatrix)
185 return m_smvbsrmatrix->GetNumNonZeroEntries();
186 return -1;
187}

References m_smvbsrmatrix.

◆ Multiply()

void Nektar::MultiRegions::GlobalMatrix::Multiply ( const Array< OneD, const NekDouble > &  in,
Array< OneD, NekDouble > &  out 
)

Perform a matrix-vector multiply.

Performs a matrix-vector multiply using the sparse format-specific multiply routine.

Parameters
inInput vector.
outOutput vector.

Definition at line 152 of file GlobalMatrix.cpp.

154{
155 if (!m_copyOp)
156 {
157 if (m_smvbsrmatrix)
158 m_smvbsrmatrix->Multiply(in, out);
159 }
160 else
161 {
162 // if block size makes the last row/column bigger, one needs
163 // using temporary storage for rhs and result vectors.
164 Vmath::Vcopy(m_rows, &in[0], 1, &m_tmpin[0], 1);
165
166 if (m_smvbsrmatrix)
167 m_smvbsrmatrix->Multiply(m_tmpin, m_tmpout);
168
169 Vmath::Vcopy(m_rows, &m_tmpout[0], 1, &out[0], 1);
170 }
171
173}
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1191

References m_copyOp, m_mulCallsCounter, m_rows, m_smvbsrmatrix, m_tmpin, m_tmpout, and Vmath::Vcopy().

Member Data Documentation

◆ def

std::string Nektar::MultiRegions::GlobalMatrix::def
staticprivate
Initial value:
=
"GlobalMatrixStorageType", "SmvBSR")
static std::string RegisterDefaultSolverInfo(const std::string &pName, const std::string &pValue)
Registers the default string value of a solver info property.

Definition at line 81 of file GlobalMatrix.h.

◆ lookupIds

std::string Nektar::MultiRegions::GlobalMatrix::lookupIds
staticprivate
Initial value:
= {
"GlobalMatrixStorageType", "SmvBSR", MultiRegions::eSmvBSR)}
static std::string RegisterEnumValue(std::string pEnum, std::string pString, int pEnumValue)
Registers an enumeration value.

Definition at line 82 of file GlobalMatrix.h.

◆ m_copyOp

bool Nektar::MultiRegions::GlobalMatrix::m_copyOp
private

Definition at line 79 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

◆ m_mulCallsCounter

unsigned long Nektar::MultiRegions::GlobalMatrix::m_mulCallsCounter
private

Definition at line 77 of file GlobalMatrix.h.

Referenced by Multiply().

◆ m_rows

unsigned int Nektar::MultiRegions::GlobalMatrix::m_rows
private

Definition at line 73 of file GlobalMatrix.h.

Referenced by Multiply().

◆ m_smvbsrmatrix

DNekSmvBsrMatSharedPtr Nektar::MultiRegions::GlobalMatrix::m_smvbsrmatrix
private

Pointer to a double-precision Nektar++ sparse matrix.

Definition at line 71 of file GlobalMatrix.h.

Referenced by GetMulCallsCounter(), GetNumNonZeroEntries(), GlobalMatrix(), and Multiply().

◆ m_tmpin

Array<OneD, NekDouble> Nektar::MultiRegions::GlobalMatrix::m_tmpin
private

Definition at line 74 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

◆ m_tmpout

Array<OneD, NekDouble> Nektar::MultiRegions::GlobalMatrix::m_tmpout
private

Definition at line 75 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().