19 #ifndef GEOS_LINEARALGEBRA_UTILITIES_BLOCKOPERATORVIEW_HPP_
20 #define GEOS_LINEARALGEBRA_UTILITIES_BLOCKOPERATORVIEW_HPP_
22 #include "codingUtilities/SFINAE_Macros.hpp"
40 template<
typename VECTOR,
typename OPERATOR = LinearOperator< VECTOR > >
89 Vector & dst )
const override
93 dst.block( i ).zero();
94 VECTOR temp( dst.block( i ) );
97 if( m_operators( i, j ) != nullptr )
99 m_operators( i, j )->apply( src.block( j ), temp );
100 dst.block( i ).axpy( 1.0, temp );
115 template<
typename OP = OPERATOR >
116 std::enable_if_t< traits::VectorBasedTraits< Vector >::template HasMemberFunction_applyTranspose< OP > >
122 dst.
block( j ).zero();
123 VECTOR temp( dst.
block( j ) );
126 if( m_operators( j, i ) != nullptr )
128 m_operators( j, i )->applyTranspose( src.
block( i ), temp );
129 dst.
block( j ).axpy( 1.0, temp );
141 return computeRowSize( []( OPERATOR
const &
block ) {
return block.numGlobalRows(); } );
150 return computeColSize( []( OPERATOR
const &
block ) {
return block.numGlobalCols(); } );
160 return computeRowSize( []( OPERATOR
const &
block ) {
return block.numLocalRows(); } );
170 return computeColSize( []( OPERATOR
const &
block ) {
return block.numLocalCols(); } );
180 virtual MPI_Comm
comm()
const override
182 return m_operators( 0, 0 )->comm();
198 return m_operators.size( 0 );
207 return m_operators.size( 1 );
218 GEOS_LAI_ASSERT( m_operators( blockRowIndex, blockColIndex ) !=
nullptr );
219 return *m_operators( blockRowIndex, blockColIndex );
227 GEOS_LAI_ASSERT( m_operators( blockRowIndex, blockColIndex ) !=
nullptr );
228 return *m_operators( blockRowIndex, blockColIndex );
236 return block( blockRowIndex, blockColIndex );
244 return block( blockRowIndex, blockColIndex );
257 : m_operators( nRows, nCols )
287 m_operators( blockRowIndex, blockColIndex ) = op;
292 template<
typename FUNC >
293 auto computeRowSize( FUNC func )
const -> decltype( func( std::declval< OPERATOR const >() ) );
295 template<
typename FUNC >
296 auto computeColSize( FUNC func )
const -> decltype( func( std::declval< OPERATOR const >() ) );
302 template<
typename VECTOR,
typename OPERATOR >
303 template<
typename FUNC >
304 auto BlockOperatorView< VECTOR, OPERATOR >::computeRowSize( FUNC func )
const -> decltype( func( std::declval< OPERATOR const >() ) )
306 using sizeType = decltype( func( std::declval< OPERATOR const >() ) );
307 sizeType rowSize = 0;
308 for(
localIndex i = 0; i < numBlockRows(); ++i )
310 for(
localIndex j = 0; j < numBlockCols(); ++j )
312 if( m_operators( i, j ) != nullptr )
314 rowSize += func( block( i, j ) );
322 template<
typename VECTOR,
typename OPERATOR >
323 template<
typename FUNC >
324 auto BlockOperatorView< VECTOR, OPERATOR >::computeColSize( FUNC func )
const -> decltype( func( std::declval< OPERATOR const >() ) )
326 using sizeType = decltype( func( std::declval< OPERATOR const >() ) );
327 sizeType colSize = 0;
328 for(
localIndex j = 0; j < numBlockCols(); j++ )
330 for(
localIndex i = 0; i < numBlockRows(); ++i )
332 if( m_operators( i, j ) != nullptr )
334 colSize += func( block( i, j ) );
Abstract view of a block operator.
BlockOperatorView & operator=(BlockOperatorView &&)=delete
Deleted move assignment.
virtual globalIndex numGlobalCols() const override
Get the number of global columns.
virtual globalIndex numGlobalRows() const override
Get the number of global rows.
virtual MPI_Comm comm() const override
Get the MPI communicator the matrix was created with.
OPERATOR const & operator()(localIndex const blockRowIndex, localIndex const blockColIndex=0) const
Get the operator corresponding to a sub-block.
BlockOperatorView(BlockOperatorView< VECTOR, OPERATOR > &&x)=default
Move constructor.
localIndex numBlockCols() const
Get number of block columns.
virtual void apply(Vector const &src, Vector &dst) const override
Apply operator to a vector.
virtual localIndex numLocalCols() const override
Get the number of local columns.
localIndex numBlockRows() const
Get number of block rows.
typename Base::Vector Vector
Alias for vector type.
BlockOperatorView(localIndex const nRows, localIndex const nCols)
Create an operator with given number of block rows and columns.
OPERATOR & operator()(localIndex const blockRowIndex, localIndex const blockColIndex=0)
Get the operator corresponding to a sub-block.
std::enable_if_t< traits::VectorBasedTraits< Vector >::template HasMemberFunction_applyTranspose< OP > > applyTranspose(BlockVectorView< VECTOR > const &src, BlockVectorView< VECTOR > &dst) const
Apply the transpose of block operator to a block vector.
BlockOperatorView(BlockOperatorView< VECTOR, OPERATOR > const &x)=default
Copy constructor.
BlockOperatorView & operator=(BlockOperatorView const &)=delete
Deleted copy assignment.
void setPointer(localIndex const blockRowIndex, localIndex const blockColIndex, OPERATOR *op)
Set/replace a pointer to a block.
virtual ~BlockOperatorView() override=default
Destructor.
virtual localIndex numLocalRows() const override
Get the number of local rows.
OPERATOR const & block(localIndex const blockRowIndex, localIndex const blockColIndex) const
Get the operator corresponding to a sub-block.
OPERATOR & block(localIndex const blockRowIndex, localIndex const blockColIndex)
Get the operator corresponding to a sub-block.
Abstract view of a block vector.
VECTOR const & block(localIndex const blockIndex) const
Get a reference to the vector corresponding to block blockRowIndex.
Abstract base class for linear operators.
BlockVectorView< VECTOR > Vector
Alias for template parameter.
#define GEOS_LAI_ASSERT_GE(lhs, rhs)
#define GEOS_LAI_ASSERT_GT(lhs, rhs)
#define GEOS_LAI_ASSERT(expr)
Array< T, 2, PERMUTATION > array2d
Alias for 2D array.
GEOSX_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
GEOSX_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).