13 #include "../general/array.hpp"
24 nRowBlocks(offsets.Size() - 1),
25 nColBlocks(offsets.Size() - 1),
28 op(nRowBlocks, nRowBlocks),
29 coef(nRowBlocks, nColBlocks)
38 :
Operator(row_offsets_.Last(), col_offsets_.Last()),
40 nRowBlocks(row_offsets_.Size()-1),
41 nColBlocks(col_offsets_.Size()-1),
44 op(nRowBlocks, nColBlocks),
45 coef(nRowBlocks, nColBlocks)
48 row_offsets.
MakeRef(row_offsets_);
49 col_offsets.
MakeRef(col_offsets_);
61 delete op(iRow, iCol);
66 MFEM_VERIFY(row_offsets[iRow+1] - row_offsets[iRow] == opt->
NumRows() &&
67 col_offsets[iCol+1] - col_offsets[iCol] == opt->
NumCols(),
68 "incompatible Operator dimensions");
74 MFEM_ASSERT(x.
Size() ==
width,
"incorrect input Vector size");
75 MFEM_ASSERT(y.
Size() ==
height,
"incorrect output Vector size");
80 xblock.
Update(const_cast<Vector&>(x),col_offsets);
81 yblock.
Update(y,row_offsets);
83 for (
int iRow=0; iRow < nRowBlocks; ++iRow)
85 tmp.
SetSize(row_offsets[iRow+1] - row_offsets[iRow]);
86 for (
int jCol=0; jCol < nColBlocks; ++jCol)
90 op(iRow,jCol)->Mult(xblock.
GetBlock(jCol), tmp);
96 for (
int iRow=0; iRow < nRowBlocks; ++iRow)
110 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
111 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
116 xblock.
Update(const_cast<Vector&>(x),row_offsets);
117 yblock.
Update(y,col_offsets);
119 for (
int iRow=0; iRow < nColBlocks; ++iRow)
121 tmp.
SetSize(col_offsets[iRow+1] - col_offsets[iRow]);
122 for (
int jCol=0; jCol < nRowBlocks; ++jCol)
126 op(jCol,iRow)->MultTranspose(xblock.
GetBlock(jCol), tmp);
132 for (
int iRow=0; iRow < nColBlocks; ++iRow)
147 for (
int iRow=0; iRow < nRowBlocks; ++iRow)
149 for (
int jCol=0; jCol < nColBlocks; ++jCol)
151 delete op(jCol,iRow);
162 nBlocks(offsets_.Size() - 1),
172 MFEM_VERIFY(offsets[iblock+1] - offsets[iblock] == opt->
Height() &&
173 offsets[iblock+1] - offsets[iblock] == opt->
Width(),
174 "incompatible Operator dimensions");
186 MFEM_ASSERT(x.
Size() ==
width,
"incorrect input Vector size");
187 MFEM_ASSERT(y.
Size() ==
height,
"incorrect output Vector size");
192 xblock.
Update(const_cast<Vector&>(x),offsets);
195 for (
int i=0; i<nBlocks; ++i)
207 for (
int i=0; i<nBlocks; ++i)
222 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
223 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
228 xblock.
Update(const_cast<Vector&>(x),offsets);
231 for (
int i=0; i<nBlocks; ++i)
243 for (
int i=0; i<nBlocks; ++i)
258 for (
int i=0; i<nBlocks; ++i)
267 :
Solver(offsets_.Last()),
269 nBlocks(offsets_.Size() - 1),
280 MFEM_VERIFY(offsets[iblock+1] - offsets[iblock] == op->
Height() &&
281 offsets[iblock+1] - offsets[iblock] == op->
Width(),
282 "incompatible Operator dimensions");
290 MFEM_VERIFY(iRow >= iCol,
"cannot set block in upper triangle");
291 MFEM_VERIFY(offsets[iRow+1] - offsets[iRow] == opt->
NumRows() &&
292 offsets[iCol+1] - offsets[iCol] == opt->
NumCols(),
293 "incompatible Operator dimensions");
295 op(iRow, iCol) = opt;
302 MFEM_ASSERT(x.
Size() ==
width,
"incorrect input Vector size");
303 MFEM_ASSERT(y.
Size() ==
height,
"incorrect output Vector size");
309 for (
int iRow=0; iRow < nBlocks; ++iRow)
311 tmp.
SetSize(offsets[iRow+1] - offsets[iRow]);
312 tmp2.
SetSize(offsets[iRow+1] - offsets[iRow]);
315 for (
int jCol=0; jCol < iRow; ++jCol)
319 op(iRow,jCol)->Mult(yblock.
GetBlock(jCol), tmp);
325 op(iRow,iRow)->Mult(tmp2, yblock.
GetBlock(iRow));
338 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
339 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
345 for (
int iRow=nBlocks-1; iRow >=0; --iRow)
347 tmp.
SetSize(offsets[iRow+1] - offsets[iRow]);
348 tmp2.
SetSize(offsets[iRow+1] - offsets[iRow]);
351 for (
int jCol=iRow+1; jCol < nBlocks; ++jCol)
355 op(jCol,iRow)->MultTranspose(yblock.
GetBlock(jCol), tmp);
361 op(iRow,iRow)->MultTranspose(tmp2, yblock.
GetBlock(iRow));
374 for (
int iRow=0; iRow < nBlocks; ++iRow)
376 for (
int jCol=0; jCol < nBlocks; ++jCol)
378 delete op(jCol,iRow);
void SetSize(int s)
Resize the vector to size s.
int Width() const
Get the width (size of input) of the Operator. Synonym with NumCols().
int Size() const
Returns the size of the vector.
void Update(double *data, const Array< int > &bOffsets)
Update method.
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
double * GetData() const
Return a pointer to the beginning of the Vector data.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
~BlockDiagonalPreconditioner()
void SetBlock(int iRow, int iCol, Operator *op)
Add a block op in the block-entry (iblock, jblock).
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
BlockDiagonalPreconditioner(const Array< int > &offsets)
Constructor that specifies the block structure.
BlockOperator(const Array< int > &offsets)
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
void SetDiagonalBlock(int iblock, Operator *op, double c=1.0)
Add block op in the block-entry (iblock, iblock).
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
~BlockLowerTriangularPreconditioner()
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
int height
Dimension of the output / number of rows in the matrix.
void SetDiagonalBlock(int iblock, Operator *op)
Add block op in the block-entry (iblock, iblock).
Vector & Add(const double a, const Vector &Va)
(*this) += a * Va
const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
void Destroy()
Destroy a vector.
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
int NumBlocks() const
Return the number of blocks.
void MakeRef(T *, int)
Make this Array a reference to a pointer.
BlockLowerTriangularPreconditioner(const Array< int > &offsets)
int width
Dimension of the input / number of columns in the matrix.
void SetBlock(int iRow, int iCol, Operator *op, double c=1.0)
Add a block op in the block-entry (iblock, jblock).
void SetDiagonalBlock(int iblock, Operator *op)
Add a square block op in the block-entry (iblock, iblock).
Vector & GetBlock(int i)
Get the i-th vector in the block.
void SyncAliasMemory(const Vector &v)
Update the alias memory location of the vector to match v.