FEMTIC
ComplexSparseMatrix.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------------------------------------------
2 // The MIT License (MIT)
3 //
4 // Copyright (c) 2021 Yoshiya Usui
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //-------------------------------------------------------------------------------------------------------
24 #ifndef DBLDEF_COMPLEX_SPARSE_MATRIX
25 #define DBLDEF_COMPLEX_SPARSE_MATRIX
26 
27 #include <complex>
28 //#include <set>
29 #include <map>
30 
32 
33 public:
34 
35  //Default Constructer
36  explicit ComplexSparseMatrix();
37 
38  //Constructer
39  explicit ComplexSparseMatrix( const int nrows, const int ncols, const int nrhs = 1 );
40 
41  //Destructer
42  virtual ~ComplexSparseMatrix();
43 
44  // Set number of rows and columns
45  virtual void setNumRowsAndColumns( const int nrows, const int ncols );
46 
47  // Set matrix structure ( locations of non-zero components ) by triplet format
48  virtual void setStructureByTripletFormat( const int row, const int col );
49 
50  // Set matrix structure ( locations of non-zero components ) and add values by triplet format
51  virtual void setStructureAndAddValueByTripletFormat( const int row, const int col, const std::complex<double>& val );
52 
53  //Convert matrix from triplet format to CRS format
54  void convertToCRSFormat();
55 
56  //Add non-zero value to matrix
57  virtual void addNonZeroValues( const int row, const int col, const std::complex<double>& val );
58 
59  //Check input data and get element number of the array containing non-zero values
60  virtual int checkAndGetLocationNonZeroValue( const int row, const int col );
61 
62  //Add non-zero value to matrix by specifing element number of the array directly
63  virtual void addNonZeroValuesWithoutSearchingLocation( const int loc, const std::complex<double>& val );
64 
65  //Zero clear non-zero values of matrix stored by CSR format
67 
68  //Add non-zero value to the right hand side vector
69  void addRightHandSideVector( const int row, const std::complex<double>& val, const int irhs = 0 );
70 
71  //Zero clear non-zero values of the right hand side vector
73 
74  //Initialize matrix and right-hand side vectors
75  virtual void initializeMatrixAndRhsVectors( const int nrows, const int ncols, const int nrhs );
76 
77  // Get number of rows
78  int getNumRows() const;
79 
80  // Get number of columns
81  int getNumColumns() const;
82 
83  //Get total number of right hand side vector
84  int getNumRightHandSideVectors() const;
85 
86  //Return whether matrix has already been converted to CRS format
87  bool hasConvertedToCRSFormat() const;
88 
89  //Reallocate memory for right hand side vectors
90  void reallocateMemoryForRightHandSideVectors( const int nrhs );
91 
93  //void setNumRightHandSideVectors( const int nrhs );
94 
95  //Release memory
96  virtual void releaseMemory();
97 
99  //void multiplyMatrixByVectorAndAddResult( const std::complex<double>* vecIn, const int* convertArray, std::complex<double>* vecOut ) const;
100 
102  //void multiplyMatrixByVectorAndSubtractResult( const std::complex<double>* vecIn, const int* convertArray, std::complex<double>* vecOut ) const;
103 
104  //Copy right-hand side vector to another vector
105  void copyRhsVector( std::complex<double>* vecOut ) const;
106 
107  //Copy specified components of right-hand side vector to another vector
108  void copyRhsVector( const int numCompsCopied, const int* const compsCopied, std::complex<double>* vecOut ) const;
109 
110  //Debug write matrix componets
111  void debugWriteMatrix() const;
112 
113  //Debug write componets of right hand side vector
114  void debugWriteRightHandSide() const;
115 
116  //Debug write non-zero componets of right hand side vector
117  void debugWriteNonZeroRightHandSide() const;
118 
119 protected:
120  //Delete the matrix of triplet ( Coordinate ) format
121  void deleteTripletMatrix();
122 
123  //Total number of rows
125 
126  //Total number of columns
128 
129  //Total number of non-zero elements in the matrix
131 
132  //Total number of right hand side vectors
134 
135  //Flag indicating whether matrix has already been converted to CRS format
137 
138  //Matrix stored by triplet ( Coordinate ) format
139  //std::set<int>* m_matrixTripletFormat;
140  std::map< int, std::complex<double> >* m_matrixTripletFormat;
141 
142  //Row indices of the compressed row storage format
143  long long int* m_rowIndex;
144 
145  //Columns in which non-zero compnents exist
146  long long int* m_columns;
147 
148  //Values of non-zero compnents
149  std::complex<double>* m_values;
150 
151  //Right hand side vector
152  std::complex<double>* m_rightHandSideVector;
153 
154 private:
155  //Copy constructer
157 
158  // Assignment operator
160 
161 };
162 
163 #endif
Definition: ComplexSparseMatrix.h:31
long long int * m_rowIndex
Definition: ComplexSparseMatrix.h:143
void convertToCRSFormat()
Definition: ComplexSparseMatrix.cpp:176
virtual void initializeMatrixAndRhsVectors(const int nrows, const int ncols, const int nrhs)
Definition: ComplexSparseMatrix.cpp:393
std::complex< double > * m_values
Definition: ComplexSparseMatrix.h:149
int m_numNonZeros
Definition: ComplexSparseMatrix.h:130
int getNumColumns() const
Definition: ComplexSparseMatrix.cpp:463
std::map< int, std::complex< double > > * m_matrixTripletFormat
Definition: ComplexSparseMatrix.h:140
int m_numRows
Definition: ComplexSparseMatrix.h:124
void deleteTripletMatrix()
Definition: ComplexSparseMatrix.cpp:642
virtual ~ComplexSparseMatrix()
Definition: ComplexSparseMatrix.cpp:72
virtual void addNonZeroValues(const int row, const int col, const std::complex< double > &val)
Definition: ComplexSparseMatrix.cpp:249
virtual void addNonZeroValuesWithoutSearchingLocation(const int loc, const std::complex< double > &val)
Definition: ComplexSparseMatrix.cpp:336
int m_numRightHandSideVectors
Definition: ComplexSparseMatrix.h:133
void addRightHandSideVector(const int row, const std::complex< double > &val, const int irhs=0)
Definition: ComplexSparseMatrix.cpp:361
virtual void releaseMemory()
Definition: ComplexSparseMatrix.cpp:478
virtual void setStructureAndAddValueByTripletFormat(const int row, const int col, const std::complex< double > &val)
Definition: ComplexSparseMatrix.cpp:155
int getNumRows() const
Definition: ComplexSparseMatrix.cpp:458
bool m_hasConvertedToCRSFormat
Definition: ComplexSparseMatrix.h:136
std::complex< double > * m_rightHandSideVector
Definition: ComplexSparseMatrix.h:152
void debugWriteMatrix() const
Definition: ComplexSparseMatrix.cpp:598
virtual int checkAndGetLocationNonZeroValue(const int row, const int col)
Definition: ComplexSparseMatrix.cpp:289
ComplexSparseMatrix()
Definition: ComplexSparseMatrix.cpp:34
virtual void setStructureByTripletFormat(const int row, const int col)
Definition: ComplexSparseMatrix.cpp:138
virtual void setNumRowsAndColumns(const int nrows, const int ncols)
Definition: ComplexSparseMatrix.cpp:105
void zeroClearRightHandSideVector()
Definition: ComplexSparseMatrix.cpp:383
void debugWriteRightHandSide() const
Definition: ComplexSparseMatrix.cpp:615
void debugWriteNonZeroRightHandSide() const
Definition: ComplexSparseMatrix.cpp:626
void zeroClearNonZeroValues()
Definition: ComplexSparseMatrix.cpp:344
void copyRhsVector(std::complex< double > *vecOut) const
Definition: ComplexSparseMatrix.cpp:571
int getNumRightHandSideVectors() const
Definition: ComplexSparseMatrix.cpp:468
bool hasConvertedToCRSFormat() const
Definition: ComplexSparseMatrix.cpp:473
int m_numColumns
Definition: ComplexSparseMatrix.h:127
void reallocateMemoryForRightHandSideVectors(const int nrhs)
Definition: ComplexSparseMatrix.cpp:514
long long int * m_columns
Definition: ComplexSparseMatrix.h:146
ComplexSparseMatrix & operator=(const ComplexSparseMatrix &rhs)
Definition: ComplexSparseMatrix.cpp:661