G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsBlockOp.hpp
Go to the documentation of this file.
1
14namespace gismo
15{
16
17template<typename T>
19{
20 m_blockPrec.resize(nRows, nCols);
21 m_blockTargetPositions.setZero(nRows);
22 m_blockInputPositions.setZero(nCols);
23 // Fill up all block entries with null pointers.
24 for (index_t i = 0; i < nRows; ++i)
25 for (index_t j = 0; j < nCols; ++j)
26 m_blockPrec(i,j).reset();
27}
28
29template<typename T>
31{
32 GISMO_ASSERT( row >= 0 && row < m_blockPrec.rows(), "The given row is not feasible." );
33 GISMO_ASSERT( col >= 0 && col < m_blockPrec.cols(), "The given column is not feasible." );
34 GISMO_ASSERT( op->rows() == m_blockTargetPositions[row] || m_blockTargetPositions[row] == 0,
35 "The size of the given preconditioner does not fit to the other preconditioners in the same row." );
36 GISMO_ASSERT( op->cols() == m_blockInputPositions[col] || m_blockInputPositions[col] == 0,
37 "The size of the given preconditioner does not fit to the other preconditioners in the same column." );
38
39 m_blockPrec(row, col) = op;
40 m_blockTargetPositions[row] = op->rows();
41 m_blockInputPositions[col] = op->cols();
42}
43
44
45template<typename T>
46void gsBlockOp<T>::apply(const gsMatrix<T> & input, gsMatrix<T> & result) const
47{
48 result.setZero(m_blockTargetPositions.sum(), input.cols());
49 gsVector<index_t> singleCol(1);
50 singleCol << input.cols();
51 typename gsMatrix<T>::BlockView resultBlocks = result.blockView(m_blockTargetPositions, singleCol);
52
53 for (index_t i = 0; i < m_blockPrec.rows() ; ++i)
54 {
55 index_t inputIndex = 0;
56 for (index_t j = 0; j < m_blockPrec.cols(); ++j)
57 {
58 if (!m_blockPrec(i,j))// if the block is a null pointer
59 {
60 inputIndex += m_blockInputPositions(j);
61 continue;
62 }
63
64 gsMatrix<T> tmp_result;
65 m_blockPrec(i,j)->apply(input.block(inputIndex,0,m_blockInputPositions(j),input.cols()),tmp_result);
66 resultBlocks(i) += tmp_result;
67 inputIndex += m_blockInputPositions(j);
68 }
69 }
70}
71
72}
memory::shared_ptr< gsLinearOperator< T > > BasePtr
Base class.
Definition gsBlockOp.h:54
gsBlockOp(index_t nRows, index_t nCols)
Constructor. Takes the number of blocks (nRows, nCols). Provide the contents of the blocks with addOp...
Definition gsBlockOp.hpp:18
void addOperator(index_t row, index_t col, const BasePtr &op)
Add a preconditioner to the block structure.
Definition gsBlockOp.hpp:30
void apply(const gsMatrix< T > &input, gsMatrix< T > &result) const
Apply the correct segment of the input vector on the preconditioners in the block structure and store...
Definition gsBlockOp.hpp:46
Represents a block-view of the given matrix.
Definition gsMatrixBlockView.h:32
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
BlockView blockView(const gsVector< index_t > &rowSizes, const gsVector< index_t > &colSizes)
Return a block view of the matrix with rowSizes and colSizes.
Definition gsMatrix.h:381
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
#define index_t
Definition gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.