13 #include "../general/array.hpp" 14 #include "operator.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)
105 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
106 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
111 xblock.
Update(const_cast<Vector&>(x),row_offsets);
112 yblock.
Update(y,col_offsets);
114 for (
int iRow=0; iRow < nColBlocks; ++iRow)
116 tmp.
SetSize(col_offsets[iRow+1] - col_offsets[iRow]);
117 for (
int jCol=0; jCol < nRowBlocks; ++jCol)
121 op(jCol,iRow)->MultTranspose(xblock.
GetBlock(jCol), tmp);
127 for (
int iRow=0; iRow < nColBlocks; ++iRow)
137 for (
int iRow=0; iRow < nRowBlocks; ++iRow)
139 for (
int jCol=0; jCol < nColBlocks; ++jCol)
141 delete op(iRow,jCol);
152 nBlocks(offsets_.Size() - 1),
156 ops =
static_cast<Operator *
>(NULL);
162 MFEM_VERIFY(offsets[iblock+1] - offsets[iblock] == op->
Height() &&
163 offsets[iblock+1] - offsets[iblock] == op->
Width(),
164 "incompatible Operator dimensions");
176 MFEM_ASSERT(x.
Size() ==
width,
"incorrect input Vector size");
177 MFEM_ASSERT(y.
Size() ==
height,
"incorrect output Vector size");
182 xblock.
Update(const_cast<Vector&>(x),offsets);
185 for (
int i=0; i<nBlocks; ++i)
197 for (
int i=0; i<nBlocks; ++i)
207 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
208 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
213 xblock.
Update(const_cast<Vector&>(x),offsets);
216 for (
int i=0; i<nBlocks; ++i)
228 for (
int i=0; i<nBlocks; ++i)
238 for (
int i=0; i<nBlocks; ++i)
247 :
Solver(offsets_.Last()),
249 nBlocks(offsets_.Size() - 1),
251 ops(nBlocks, nBlocks)
253 ops =
static_cast<Operator *
>(NULL);
260 MFEM_VERIFY(offsets[iblock+1] - offsets[iblock] == op->
Height() &&
261 offsets[iblock+1] - offsets[iblock] == op->
Width(),
262 "incompatible Operator dimensions");
270 MFEM_VERIFY(iRow >= iCol,
"cannot set block in upper triangle");
271 MFEM_VERIFY(offsets[iRow+1] - offsets[iRow] == op->
NumRows() &&
272 offsets[iCol+1] - offsets[iCol] == op->
NumCols(),
273 "incompatible Operator dimensions");
275 ops(iRow, iCol) = op;
282 MFEM_ASSERT(x.
Size() ==
width,
"incorrect input Vector size");
283 MFEM_ASSERT(y.
Size() ==
height,
"incorrect output Vector size");
289 for (
int iRow=0; iRow < nBlocks; ++iRow)
291 tmp.
SetSize(offsets[iRow+1] - offsets[iRow]);
292 tmp2.
SetSize(offsets[iRow+1] - offsets[iRow]);
295 for (
int jCol=0; jCol < iRow; ++jCol)
299 ops(iRow,jCol)->Mult(yblock.
GetBlock(jCol), tmp);
305 ops(iRow,iRow)->Mult(tmp2, yblock.
GetBlock(iRow));
318 MFEM_ASSERT(x.
Size() ==
height,
"incorrect input Vector size");
319 MFEM_ASSERT(y.
Size() ==
width,
"incorrect output Vector size");
325 for (
int iRow=nBlocks-1; iRow >=0; --iRow)
327 tmp.
SetSize(offsets[iRow+1] - offsets[iRow]);
328 tmp2.
SetSize(offsets[iRow+1] - offsets[iRow]);
331 for (
int jCol=iRow+1; jCol < nBlocks; ++jCol)
335 ops(jCol,iRow)->MultTranspose(yblock.
GetBlock(jCol), tmp);
341 ops(iRow,iRow)->MultTranspose(tmp2, yblock.
GetBlock(iRow));
354 for (
int iRow=0; iRow < nBlocks; ++iRow)
356 for (
int jCol=0; jCol < nBlocks; ++jCol)
358 delete ops(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 const double * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
int NumRows() const
Get the number of rows (size of output) of the Operator. Synonym with Height().
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
virtual double * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
~BlockDiagonalPreconditioner()
void SetBlock(int iRow, int iCol, Operator *op)
Add a block opt in the block-entry (iblock, jblock).
BlockDiagonalPreconditioner(const Array< int > &offsets)
Constructor that specifies the block structure.
BlockOperator(const Array< int > &offsets)
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
double * GetData() const
Return a pointer to the beginning of the Vector data.
void SetDiagonalBlock(int iblock, Operator *op, double c=1.0)
Add block op in the block-entry (iblock, iblock).
virtual void Mult(const Vector &x, Vector &y) const
Operator application.
~BlockLowerTriangularPreconditioner()
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
int NumCols() const
Get the number of columns (size of input) of the Operator. Synonym with Width().
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
void SyncAliasMemory(const Vector &v) const
Update the alias memory location of the vector to match v.
virtual void MultTranspose(const Vector &x, Vector &y) const
Action of the transpose operator.
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.
virtual void Mult(const Vector &x, Vector &y) const
Operator application.