39 BorderedBandMatrix::~BorderedBandMatrix() {
69 const std::vector<unsigned int>* anIndex,
70 const std::vector<double>* aVector) {
72 for (
unsigned int i = 0; i < anIndex->size(); ++i) {
73 int iIndex = (*anIndex)[i] - 1;
74 for (
unsigned int j = 0; j <= i; ++j) {
75 int jIndex = (*anIndex)[j] - 1;
76 if (iIndex < nBorder) {
77 theBorder(iIndex, jIndex) += (*aVector)[i] * aWeight
79 }
else if (jIndex < nBorder) {
80 theMixed(jIndex, iIndex - nBorder) += (*aVector)[i] * aWeight
83 unsigned int nBand = iIndex - jIndex;
84 theBand(nBand, jIndex - nBorder) += (*aVector)[i] * aWeight
98 const std::vector<unsigned int> &anIndex)
const {
100 TMatrixDSym aMatrix(anIndex.size());
102 for (
unsigned int i = 0; i < anIndex.size(); ++i) {
103 int iIndex = anIndex[i] - 1;
104 for (
unsigned int j = 0; j <= i; ++j) {
105 int jIndex = anIndex[j] - 1;
106 if (iIndex < nBorder) {
107 aMatrix(i, j) =
theBorder(iIndex, jIndex);
108 }
else if (jIndex < nBorder) {
109 aMatrix(i, j) = -
theMixed(jIndex, iIndex - nBorder);
111 unsigned int nBand = iIndex - jIndex;
112 aMatrix(i, j) =
theBand(nBand, jIndex - nBorder);
114 aMatrix(j, i) = aMatrix(i, j);
163 const VVector borderSolution = inverseBorder * auxVec;
167 aSolution.
putVec(borderSolution);
181 std::cout <<
"Border part " << std::endl;
183 std::cout <<
"Mixed part " << std::endl;
185 std::cout <<
"Band part " << std::endl;
204 for (
int i = 0; i < nCol; ++i) {
205 auxVec(i) =
theBand(0, i) * 16.0;
207 for (
int i = 0; i < nCol; ++i) {
217 for (
int j = 1; j < std::min(nRow, nCol - i); ++j) {
219 for (
int k = 0; k < std::min(nRow, nCol - i) - j; ++k) {
238 VVector aSolution(aRightHandSide);
239 for (
int i = 0; i < nCol; ++i)
241 for (
int j = 1; j < std::min(nRow, nCol - i); ++j) {
242 aSolution(j + i) -=
theBand(j, i) * aSolution(i);
245 for (
int i = nCol - 1; i >= 0; i--)
247 double rxw =
theBand(0, i) * aSolution(i);
248 for (
int j = 1; j < std::min(nRow, nCol - i); ++j) {
249 rxw -=
theBand(j, i) * aSolution(j + i);
267 VMatrix aSolution(aRightHandSide);
268 for (
unsigned int iBorder = 0; iBorder <
numBorder; iBorder++) {
269 for (
int i = 0; i < nCol; ++i)
271 for (
int j = 1; j < std::min(nRow, nCol - i); ++j) {
272 aSolution(iBorder, j + i) -=
theBand(j, i)
273 * aSolution(iBorder, i);
276 for (
int i = nCol - 1; i >= 0; i--)
278 double rxw =
theBand(0, i) * aSolution(iBorder, i);
279 for (
int j = 1; j < std::min(nRow, nCol - i); ++j) {
280 rxw -=
theBand(j, i) * aSolution(iBorder, j + i);
282 aSolution(iBorder, i) = rxw;
296 VMatrix inverseBand(nRow, nCol);
298 for (
int i = nCol - 1; i >= 0; i--) {
300 for (
int j = i; j >= std::max(0, i - nRow + 1); j--) {
301 for (
int k = j + 1; k < std::min(nCol, j + nRow); ++k) {
302 rxw -= inverseBand(abs(i - k), std::min(i, k))
305 inverseBand(i - j, j) = rxw;
322 VMatrix aBand((nBand + 1), nCol);
323 for (
int i = 0; i < nCol; ++i) {
324 for (
int j = std::max(0, i - nBand); j <= i; ++j) {
326 for (
int l = 0; l < nBorder; ++l) {
327 sum += anArray(i, l) * aSymArray(l, l) * anArray(j, l);
328 for (
int k = 0; k < l; ++k) {
329 sum += anArray(i, l) * aSymArray(l, k) * anArray(j, k)
330 + anArray(i, k) * aSymArray(l, k) * anArray(j, l);
333 aBand(i - j, j) = sum;
BorderedBandMatrix definition.
void resize(unsigned int nSize, unsigned int nBorder=1, unsigned int nBand=5)
Resize bordered band matrix.
VVector solveBand(const VVector &aRightHandSide) const
Solve for band part.
TMatrixDSym getBlockMatrix(const std::vector< unsigned int > &anIndex) const
Retrieve symmetric block matrix.
void printMatrix() const
Print bordered band matrix.
unsigned int numSize
Matrix size.
VSymMatrix theBorder
Border part.
unsigned int numCol
Band matrix size.
VMatrix theMixed
Mixed part.
void addBlockMatrix(double aWeight, const std::vector< unsigned int > *anIndex, const std::vector< double > *aVector)
Add symmetric block matrix.
void decomposeBand()
(root free) Cholesky decomposition of band part: C=LDL^T
BorderedBandMatrix()
Create bordered band matrix.
unsigned int numBand
Band width.
VMatrix invertBand()
Invert band part.
unsigned int numBorder
Border size.
VMatrix theBand
Band part.
VMatrix bandOfAVAT(const VMatrix &anArray, const VSymMatrix &aSymArray) const
Calculate band part of: 'anArray * aSymArray * anArray.T'.
void solveAndInvertBorderedBand(const VVector &aRightHandSide, VVector &aSolution)
Solve linear equation system, partially calculate inverse.
Simple Matrix based on std::vector<double>
void resize(const unsigned int nRows, const unsigned int nCols)
Resize Matrix.
VMatrix transpose() const
Get transposed matrix.
void print() const
Print matrix.
unsigned int getNumRows() const
Get number of rows.
unsigned int getNumCols() const
Get number of columns.
Simple symmetric Matrix based on std::vector<double>
void resize(const unsigned int nRows)
Resize symmetric matrix.
unsigned int invert()
Matrix inversion.
void print() const
Print matrix.
Simple Vector based on std::vector<double>
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
Namespace for the general broken lines package.