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 44 of file GlobalMatrix.h.

Member Typedef Documentation

◆ DNekSmvBsrMat

Definition at line 47 of file GlobalMatrix.h.

◆ DNekSmvBsrMatSharedPtr

Definition at line 48 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 65 of file GlobalMatrix.cpp.

70{
71 MatrixStorageType storageType =
72 pSession->GetSolverInfoAsEnum<MatrixStorageType>(
73 "GlobalMatrixStorageType");
74
75 unsigned int brows, bcols;
76
77 // Size of dense matrix sub-blocks
78 int block_size = 1;
79
80 BCOMatType bcoMat;
81
82 // assuming current sparse format allows
83 // block-sparse data representation
84
85 if (pSession->DefinesParameter("SparseBlockSize"))
86 {
87 pSession->LoadParameter("SparseBlockSize", block_size);
88 ASSERTL1(block_size > 0,
89 "SparseBlockSize parameter must to be positive");
90 }
91
92 brows = rows / block_size + (rows % block_size > 0);
93 bcols = columns / block_size + (columns % block_size > 0);
94
95 if (rows % block_size > 0)
96 {
97 m_copyOp = true;
98 }
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:202
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
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:69
Array< OneD, NekDouble > m_tmpout
Definition: GlobalMatrix.h:73
Array< OneD, NekDouble > m_tmpin
Definition: GlobalMatrix.h:72
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:46

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 56 of file GlobalMatrix.h.

57 {
58 }

Member Function Documentation

◆ GetMulCallsCounter()

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

Definition at line 179 of file GlobalMatrix.cpp.

180{
181 if (m_smvbsrmatrix)
182 {
183 return m_smvbsrmatrix->GetMulCallsCounter();
184 }
185 return -1;
186}

References m_smvbsrmatrix.

◆ GetNumNonZeroEntries()

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

Definition at line 188 of file GlobalMatrix.cpp.

189{
190 if (m_smvbsrmatrix)
191 {
192 return m_smvbsrmatrix->GetNumNonZeroEntries();
193 }
194 return -1;
195}

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 {
159 m_smvbsrmatrix->Multiply(in, out);
160 }
161 }
162 else
163 {
164 // if block size makes the last row/column bigger, one needs
165 // using temporary storage for rhs and result vectors.
166 Vmath::Vcopy(m_rows, &in[0], 1, &m_tmpin[0], 1);
167
168 if (m_smvbsrmatrix)
169 {
170 m_smvbsrmatrix->Multiply(m_tmpin, m_tmpout);
171 }
172
173 Vmath::Vcopy(m_rows, &m_tmpout[0], 1, &out[0], 1);
174 }
175
177}
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825

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 79 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 80 of file GlobalMatrix.h.

◆ m_copyOp

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

Definition at line 77 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

◆ m_mulCallsCounter

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

Definition at line 75 of file GlobalMatrix.h.

Referenced by Multiply().

◆ m_rows

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

Definition at line 71 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 69 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 72 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().

◆ m_tmpout

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

Definition at line 73 of file GlobalMatrix.h.

Referenced by GlobalMatrix(), and Multiply().