| 1 |
/*! \file TridiagMatrix.hpp |
| 2 |
\brief management of threads for factorization and Fw/Bw substitution |
| 3 |
\author Atsushi Suzuki, Laboratoire Jacques-Louis Lions |
| 4 |
\date Jun. 20th 2014 |
| 5 |
\date Jul. 12th 2015 |
| 6 |
\date Nov. 30th 2016 |
| 7 |
*/ |
| 8 |
|
| 9 |
// This file is part of Dissection |
| 10 |
// |
| 11 |
// Dissection is free software: you can redistribute it and/or modify |
| 12 |
// it under the terms of the GNU General Public License as published by |
| 13 |
// the Free Software Foundation, either version 3 of the License, or |
| 14 |
// (at your option) any later version. |
| 15 |
// |
| 16 |
// Linking Dissection statically or dynamically with other modules is making |
| 17 |
// a combined work based on Disssection. Thus, the terms and conditions of |
| 18 |
// the GNU General Public License cover the whole combination. |
| 19 |
// |
| 20 |
// As a special exception, the copyright holders of Dissection give you |
| 21 |
// permission to combine Dissection program with free software programs or |
| 22 |
// libraries that are released under the GNU LGPL and with independent modules |
| 23 |
// that communicate with Dissection solely through the Dissection-fortran |
| 24 |
// interface. You may copy and distribute such a system following the terms of |
| 25 |
// the GNU GPL for Dissection and the licenses of the other code concerned, |
| 26 |
// provided that you include the source code of that other code when and as |
| 27 |
// the GNU GPL requires distribution of source code and provided that you do |
| 28 |
// not modify the Dissection-fortran interface. |
| 29 |
// |
| 30 |
// Note that people who make modified versions of Dissection are not obligated |
| 31 |
// to grant this special exception for their modified versions; it is their |
| 32 |
// choice whether to do so. The GNU General Public License gives permission to |
| 33 |
// release a modified version without this exception; this exception also makes |
| 34 |
// it possible to release a modified version which carries forward this |
| 35 |
// exception. If you modify the Dissection-fortran interface, this exception |
| 36 |
// does not apply to your modified version of Dissection, and you must remove |
| 37 |
// this exception when you distribute your modified version. |
| 38 |
// |
| 39 |
// This exception is an additional permission under section 7 of the GNU |
| 40 |
// General Public License, version 3 ("GPLv3") |
| 41 |
// |
| 42 |
// Dissection is distributed in the hope that it will be useful, |
| 43 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 44 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 45 |
// GNU General Public License for more details. |
| 46 |
// |
| 47 |
// You should have received a copy of the GNU General Public License |
| 48 |
// along with Dissection. If not, see <http://www.gnu.org/licenses/>. |
| 49 |
// |
| 50 |
|
| 51 |
# ifndef _DRIVER_TRIDIAGMATRIX_ |
| 52 |
# define _DRIVER_TRIDIAGMATRIX_ |
| 53 |
#include <complex> |
| 54 |
#include <vector> |
| 55 |
#include "Driver/C_threads_tasks.hpp" |
| 56 |
#include "Algebra/SquareBlockMatrix.hpp" |
| 57 |
|
| 58 |
using std::vector; |
| 59 |
|
| 60 |
template<typename T> |
| 61 |
class TridiagMatrix |
| 62 |
{ |
| 63 |
public: |
| 64 |
TridiagMatrix(int dim, |
| 65 |
int nnz, int *ptrows, int *indcols, int *indvals, |
| 66 |
int *remap_eqn, |
| 67 |
bool isSym, |
| 68 |
bool isMapped) : |
| 69 |
_nrow(dim), _nnz(nnz), _isSym(isSym), _isMapped(isMapped) |
| 70 |
{ |
| 71 |
_ptrows = new int[dim + 1]; |
| 72 |
_indcols = new int[nnz]; |
| 73 |
_indvals = new int[nnz]; |
| 74 |
_remap_eqn = new int[dim]; |
| 75 |
|
| 76 |
for (int i = 0; i < (dim + 1); i++) { |
| 77 |
_ptrows[i] = ptrows[i] + 1; // C to Fortran |
| 78 |
} |
| 79 |
for (int i = 0; i < nnz; i++) { |
| 80 |
_indcols[i] = indcols[i] + 1; // C to Fortran |
| 81 |
_indvals[i] = indvals[i] + 1; // C to Fortran |
| 82 |
} |
| 83 |
for (int i = 0; i < dim; i++) { |
| 84 |
_remap_eqn[i] = remap_eqn[i]; |
| 85 |
} |
| 86 |
_diag = new SquareBlockMatrix<T>; // to keep pivot information |
| 87 |
} |
| 88 |
/** Destructor. |
| 89 |
*/ |
| 90 |
~TridiagMatrix() |
| 91 |
{ |
| 92 |
// FORTRAN_DECL(tridiag_free)(_tridiag_sparse); |
| 93 |
delete [] _ptrows; |
| 94 |
delete [] _indcols; |
| 95 |
delete [] _indvals; |
| 96 |
delete [] _remap_eqn; |
| 97 |
delete _diag; |
| 98 |
} |
| 99 |
|
| 100 |
int nrow() { |
| 101 |
return _nrow; |
| 102 |
} |
| 103 |
int nnz() { |
| 104 |
return _nnz; |
| 105 |
} |
| 106 |
void setGlobalNonzero(int nnz) { |
| 107 |
_nnz_global = nnz; |
| 108 |
} |
| 109 |
int nnz_global() { |
| 110 |
return _nnz_global; |
| 111 |
} |
| 112 |
int *ptRows() { |
| 113 |
return _ptrows; |
| 114 |
} |
| 115 |
int *indCols() { |
| 116 |
return _indcols; |
| 117 |
} |
| 118 |
int *indVals() { |
| 119 |
return _indvals; |
| 120 |
} |
| 121 |
int *remap_eqn() { |
| 122 |
return _remap_eqn; |
| 123 |
} |
| 124 |
void setCoef(T *coef) { |
| 125 |
_coef = coef; |
| 126 |
} |
| 127 |
T *getCoef() { |
| 128 |
return _coef; |
| 129 |
} |
| 130 |
SquareBlockMatrix<T>* Diag() { |
| 131 |
return _diag; |
| 132 |
} |
| 133 |
bool isSym() const { return _isSym; } |
| 134 |
|
| 135 |
bool isMapped() const { return _isMapped; } |
| 136 |
|
| 137 |
void setPtr(void *tridiag_sparse) |
| 138 |
{ |
| 139 |
_tridiag_sparse = tridiag_sparse; |
| 140 |
} |
| 141 |
void* &getPtr() {return _tridiag_sparse; } |
| 142 |
const void* &getPtr() const {return _tridiag_sparse; } |
| 143 |
|
| 144 |
private: |
| 145 |
// Attributs : |
| 146 |
// Dissection::Tree _btree; |
| 147 |
int _nrow; |
| 148 |
int _nnz; |
| 149 |
int _nnz_global; |
| 150 |
int *_ptrows; |
| 151 |
int *_indcols; |
| 152 |
int *_indvals; |
| 153 |
int *_remap_eqn; |
| 154 |
T* _coef; |
| 155 |
void *_tridiag_sparse; |
| 156 |
bool _isSym; |
| 157 |
bool _isMapped; |
| 158 |
SquareBlockMatrix<T> *_diag; |
| 159 |
}; |
| 160 |
|
| 161 |
#endif |