Skip to content

Commit

Permalink
MatrixBlocks for Array2D<SparseMatrix *> container.
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamer2368 committed Jan 14, 2024
1 parent 0c3ccc0 commit f32dc8e
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions include/linalg_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "mfem.hpp"
#include "librom.h"
#include "etc.hpp"

using namespace mfem;

Expand Down Expand Up @@ -45,6 +46,59 @@ void PrintVector(const CAROM::Vector &vec,
namespace mfem
{

struct MatrixBlocks
{
int nrows;
int ncols;
Array2D<SparseMatrix *> blocks;

MatrixBlocks() : nrows(0), ncols(0), blocks(0, 0) {}
MatrixBlocks(const int nrows_, const int ncols_)
: nrows(nrows_), ncols(ncols_), blocks(nrows_, ncols_)
{ blocks = NULL; }
MatrixBlocks(const Array2D<SparseMatrix *> &mats)
{ *this = mats; }

~MatrixBlocks() { DeletePointers(blocks); }

SparseMatrix* operator()(const int i, const int j) const
{
assert((i >= 0) && (i < nrows));
assert((j >= 0) && (j < ncols));
return blocks(i, j);
}

// MatrixBlocks has the ownership. no copy assignment.
MatrixBlocks& operator=(const Array2D<SparseMatrix *> &mats)
{
printf("operator= const Array2D<SparseMatrix *>.\n");
nrows = mats.NumRows();
ncols = mats.NumCols();
blocks = mats;

return *this;
}

// Copy assignment.
MatrixBlocks& operator=(const MatrixBlocks &matblock)
{
printf("operator= const MatrixBlocks.\n");
if (this == &matblock) return *this;
DeletePointers(blocks);

nrows = matblock.nrows;
ncols = matblock.ncols;
blocks.SetSize(nrows, ncols);
blocks = NULL;

for (int i = 0; i < nrows; i++)
for (int j = 0; j < ncols; j++)
if (matblock(i, j)) blocks(i, j) = new SparseMatrix(*matblock(i, j));

return *this;
}
};

void GramSchmidt(DenseMatrix& mat);

/* Orthonormalize mat over mat1 and itself. */
Expand Down

0 comments on commit f32dc8e

Please sign in to comment.