31 using namespace Eigen;
37 BorderedBandMatrix::BorderedBandMatrix() :
38 numSize(0), numBorder(0), numBand(0), numCol(0) {
71 const std::vector<unsigned int>* anIndex,
72 const std::vector<double>* aVector) {
74 for (
unsigned int i = 0;
i < anIndex->size(); ++
i) {
75 int iIndex = (*anIndex)[
i] - 1;
76 for (
unsigned int j = 0; j <=
i; ++j) {
77 int jIndex = (*anIndex)[j] - 1;
78 if (iIndex < nBorder) {
79 theBorder(iIndex, jIndex) += (*aVector)[
i] * aWeight
81 }
else if (jIndex < nBorder) {
82 theMixed(jIndex, iIndex - nBorder) += (*aVector)[
i] * aWeight
85 unsigned int nBand = iIndex - jIndex;
86 theBand(nBand, jIndex - nBorder) += (*aVector)[
i] * aWeight
105 unsigned int* anIndex,
double* aVector) {
107 for (
unsigned int i = 0;
i < aSize; ++
i) {
108 int iIndex = anIndex[
i] - 1;
109 for (
unsigned int j = 0; j <=
i; ++j) {
110 int jIndex = anIndex[j] - 1;
111 if (iIndex < nBorder) {
112 theBorder(iIndex, jIndex) += aVector[
i] * aWeight * aVector[j];
113 }
else if (jIndex < nBorder) {
114 theMixed(jIndex, iIndex - nBorder) += aVector[
i] * aWeight
117 unsigned int nBand = iIndex - jIndex;
118 theBand(nBand, jIndex - nBorder) += aVector[
i] * aWeight
132 const std::vector<unsigned int> anIndex)
const {
134 MatrixXd aMatrix(anIndex.size(), anIndex.size());
136 for (
unsigned int i = 0;
i < anIndex.size(); ++
i) {
137 int iIndex = anIndex[
i] - 1;
138 for (
unsigned int j = 0; j <=
i; ++j) {
139 int jIndex = anIndex[j] - 1;
140 if (iIndex < nBorder) {
142 }
else if (jIndex < nBorder) {
143 aMatrix(
i, j) = -
theMixed(jIndex, iIndex - nBorder);
145 unsigned int nBand = iIndex - jIndex;
146 aMatrix(
i, j) =
theBand(nBand, jIndex - nBorder);
148 aMatrix(j,
i) = aMatrix(
i, j);
161 unsigned int* anIndex)
const {
163 MatrixXd aMatrix(aSize, aSize);
165 for (
unsigned int i = 0;
i < aSize; ++
i) {
166 int iIndex = anIndex[
i] - 1;
167 for (
unsigned int j = 0; j <=
i; ++j) {
168 int jIndex = anIndex[j] - 1;
169 if (iIndex < nBorder) {
171 }
else if (jIndex < nBorder) {
172 aMatrix(
i, j) = -
theMixed(jIndex, iIndex - nBorder);
174 unsigned int nBand = iIndex - jIndex;
175 aMatrix(
i, j) =
theBand(nBand, jIndex - nBorder);
177 aMatrix(j,
i) = aMatrix(
i, j);
226 const VVector borderSolution = inverseBorder * auxVec;
230 aSolution.
putVec(borderSolution);
244 std::cout <<
"Border part " << std::endl;
267 for (
int i = 0;
i < nCol; ++
i) {
270 for (
int i = 0;
i < nCol; ++
i) {
280 for (
int j = 1; j <
std::min(nRow, nCol -
i); ++j) {
282 for (
int k = 0;
k <
std::min(nRow, nCol -
i) - j; ++
k) {
301 VVector aSolution(aRightHandSide);
302 for (
int i = 0;
i < nCol; ++
i)
304 for (
int j = 1; j <
std::min(nRow, nCol -
i); ++j) {
305 aSolution(j +
i) -=
theBand(j,
i) * aSolution(
i);
308 for (
int i = nCol - 1;
i >= 0;
i--)
310 double rxw =
theBand(0,
i) * aSolution(
i);
311 for (
int j = 1; j <
std::min(nRow, nCol -
i); ++j) {
330 VMatrix aSolution(aRightHandSide);
331 for (
unsigned int iBorder = 0; iBorder <
numBorder; iBorder++) {
332 for (
int i = 0;
i < nCol; ++
i)
334 for (
int j = 1; j <
std::min(nRow, nCol -
i); ++j) {
335 aSolution(iBorder, j +
i) -=
theBand(j,
i)
336 * aSolution(iBorder,
i);
339 for (
int i = nCol - 1;
i >= 0;
i--)
341 double rxw =
theBand(0,
i) * aSolution(iBorder,
i);
342 for (
int j = 1; j <
std::min(nRow, nCol -
i); ++j) {
343 rxw -=
theBand(j,
i) * aSolution(iBorder, j +
i);
345 aSolution(iBorder,
i) = rxw;
359 VMatrix inverseBand(nRow, nCol);
361 for (
int i = nCol - 1;
i >= 0;
i--) {
363 for (
int j =
i; j >=
std::max(0,
i - nRow + 1); j--) {
364 for (
int k = j + 1;
k <
std::min(nCol, j + nRow); ++
k) {
365 rxw -= inverseBand(
abs(
i -
k), std::min(
i,
k))
368 inverseBand(
i - j, j) = rxw;
385 VMatrix aBand((nBand + 1), nCol);
386 for (
int i = 0;
i < nCol; ++
i) {
387 for (
int j =
std::max(0,
i - nBand); j <=
i; ++j) {
389 for (
int l = 0;
l < nBorder; ++
l) {
390 sum += anArray(
i,
l) * aSymArray(
l,
l) * anArray(j,
l);
391 for (
int k = 0;
k <
l; ++
k) {
392 sum += anArray(
i, l) * aSymArray(l,
k) * anArray(j,
k)
393 + anArray(
i,
k) * aSymArray(l,
k) * anArray(j, l);
396 aBand(
i - j, j) = sum;
void printMatrix() const
Print bordered band matrix.
VVector getVec(unsigned int len, unsigned int start=0) const
Get part of vector.
void addBlockMatrix(double aWeight, const std::vector< unsigned int > *anIndex, const std::vector< double > *aVector)
Add symmetric block matrix.
void print() const
Print matrix.
unsigned int getNumRows() const
Get number of rows.
Simple Matrix based on std::vector<double>
Eigen::MatrixXd getBlockMatrix(const std::vector< unsigned int > anIndex) const
Retrieve symmetric block matrix.
virtual ~BorderedBandMatrix()
unsigned int invert()
Matrix inversion.
void putVec(const VVector &aVector, unsigned int start=0)
Put part of vector.
void resize(const unsigned int nRows, const unsigned int nCols)
Resize Matrix.
unsigned int numCol
Band matrix size.
void resize(const unsigned int nRows)
Resize symmetric matrix.
VMatrix transpose() const
Get transposed matrix.
VMatrix invertBand()
Invert band part.
VMatrix theMixed
Mixed part.
Abs< T >::type abs(const T &t)
void decomposeBand()
(root free) Cholesky decomposition of band part: C=LDL^T
Namespace for the general broken lines package.
unsigned int numBorder
Border size.
Simple symmetric Matrix based on std::vector<double>
VSymMatrix theBorder
Border part.
void print() const
Print matrix.
unsigned int getNumCols() const
Get number of columns.
void resize(unsigned int nSize, unsigned int nBorder=1, unsigned int nBand=5)
Resize bordered band matrix.
VMatrix theBand
Band part.
VMatrix bandOfAVAT(const VMatrix &anArray, const VSymMatrix &aSymArray) const
Calculate band part of: 'anArray * aSymArray * anArray.T'.
Simple Vector based on std::vector<double>
unsigned int numSize
Matrix size.
VVector solveBand(const VVector &aRightHandSide) const
Solve for band part.
void solveAndInvertBorderedBand(const VVector &aRightHandSide, VVector &aSolution)
Solve linear equation system, partially calculate inverse.
unsigned int numBand
Band width.