KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
Classes | List of all members
Kratos::SparseMatrixMultiplicationUtility Class Reference

An utility to multiply sparse matrix in Ublas. More...

#include <sparse_matrix_multiplication_utility.h>

Collaboration diagram for Kratos::SparseMatrixMultiplicationUtility:

Classes

struct  value_type
 Metafunction that returns value type of a matrix or a vector type. More...
 

Public Member Functions

Life Cycle
 SparseMatrixMultiplicationUtility ()
 Default constructor. More...
 
virtual ~SparseMatrixMultiplicationUtility ()=default
 Desctructor. More...
 
Input and output
std::string Info () const
 Turn back information as a string. More...
 
void PrintInfo (std::ostream &rOStream) const
 Print information about this object. More...
 
void PrintData (std::ostream &rOStream) const
 Print object's data. More...
 

Static Public Member Functions

Operations
template<class AMatrix , class BMatrix , class CMatrix >
static void MatrixMultiplication (const AMatrix &rA, const BMatrix &rB, CMatrix &rC)
 Matrix-matrix product C = A·B @detail This method uses a template for each matrix. More...
 
template<class AMatrix , class BMatrix , class CMatrix >
static void MatrixMultiplicationSaad (const AMatrix &A, const BMatrix &B, CMatrix &C)
 The first is an OpenMP-enabled modification of classic algorithm from Saad. More...
 
template<class AMatrix , class BMatrix , class CMatrix >
static void MatrixMultiplicationRMerge (const AMatrix &A, const BMatrix &B, CMatrix &C)
 Row-merge algorithm from Rupp et al. More...
 
template<class AMatrix , class BMatrix >
static void MatrixAdd (AMatrix &A, const BMatrix &B, const double Factor=1.0)
 The first is a method in order to sum to sparse matrices in a efficient way. More...
 
template<class AMatrix , class BMatrix >
static void TransposeMatrix (AMatrix &rA, const BMatrix &rB, const double Factor=1.0)
 This method computes of the transpose matrix of a given matrix. More...
 
template<class CMatrix , typename TSize , typename Ptr , typename IndexType , typename ValueType >
static void CreateSolutionMatrix (CMatrix &C, const TSize NRows, const TSize NCols, const Ptr *CPtr, const IndexType *AuxIndex2C, const ValueType *AuxValC)
 This method is designed to create the final solution sparse matrix from the auxiliar values. More...
 
template<typename TSize , typename Col , typename TIndexType , typename ValueType >
static void SortRows (const TIndexType *CPtr, const TSize NRows, const TSize NCols, Col *Columns, ValueType *Values)
 This method is designed to reorder the rows by columns. More...
 
static void AssembleSparseMatrixByBlocks (CompressedMatrix &rMatrix, const DenseMatrix< CompressedMatrix * > &rMatricespBlocks, DenseMatrix< double > ContributionCoefficients=DenseMatrix< double >(0, 0), DenseMatrix< bool > TransposeBlocks=DenseMatrix< bool >(0, 0))
 This method assembles several sparse matrices into one large sparse matrix. More...
 
static void ComputeNonZeroBlocks (const CompressedMatrix &rMatrix, const int CurrentRow, IndexType &rNonZeroColsAux2)
 This is a method to check the block containing nonzero values. More...
 
static void ComputeAuxiliarValuesBlocks (const CompressedMatrix &rMatrix, IndexType *AuxIndex2, double *AuxVals, const int CurrentRow, IndexType &RowEnd, const SizeType InitialIndexColumn, const double ContributionCoefficient=1.0)
 This is a method to compute the contribution of the auxiliar blocks. More...
 

Type Definitions

typedef std::size_t SizeType
 The size type. More...
 
typedef std::size_t IndexType
 The index type. More...
 
typedef std::ptrdiff_t SignedIndexType
 The signed index type. More...
 
typedef DenseVector< IndexTypeIndexVectorType
 A vector of indexes. More...
 
typedef DenseVector< SignedIndexTypeSignedIndexVectorType
 A vector of indexes (signed) More...
 
 KRATOS_CLASS_POINTER_DEFINITION (SparseMatrixMultiplicationUtility)
 Pointer definition of TreeContactSearch. More...
 

Detailed Description

An utility to multiply sparse matrix in Ublas.

Taken and adapted for ublas from external_libraries/amgcl/detail/spgemm.hpp by Denis Demidov denni.nosp@m.s.de.nosp@m.midov.nosp@m.@gma.nosp@m.il.co.nosp@m.m

Todo:
Remove as soon as we do not depend of Ublas anymore...
Author
Vicente Mataix Ferrandiz

Member Typedef Documentation

◆ IndexType

The index type.

◆ IndexVectorType

A vector of indexes.

◆ SignedIndexType

The signed index type.

◆ SignedIndexVectorType

A vector of indexes (signed)

◆ SizeType

The size type.

Constructor & Destructor Documentation

◆ SparseMatrixMultiplicationUtility()

Kratos::SparseMatrixMultiplicationUtility::SparseMatrixMultiplicationUtility ( )
inline

Default constructor.

◆ ~SparseMatrixMultiplicationUtility()

virtual Kratos::SparseMatrixMultiplicationUtility::~SparseMatrixMultiplicationUtility ( )
virtualdefault

Desctructor.

Member Function Documentation

◆ AssembleSparseMatrixByBlocks()

static void Kratos::SparseMatrixMultiplicationUtility::AssembleSparseMatrixByBlocks ( CompressedMatrix rMatrix,
const DenseMatrix< CompressedMatrix * > &  rMatricespBlocks,
DenseMatrix< double ContributionCoefficients = DenseMatrix<double>(0,0),
DenseMatrix< bool TransposeBlocks = DenseMatrix<bool>(0,0) 
)
inlinestatic

This method assembles several sparse matrices into one large sparse matrix.

Parameters
rMatricespBlocksThe pointers to the matrices we are interested in assemble
ContributionCoefficientsThe matrix containing the coefficients to be considered (copy, so we don't need to provide it)
TransposeBlocksThe matrix containing the flags telling us to transpose the blocks (copy, so we don't need to provide it)

◆ ComputeAuxiliarValuesBlocks()

static void Kratos::SparseMatrixMultiplicationUtility::ComputeAuxiliarValuesBlocks ( const CompressedMatrix rMatrix,
IndexType AuxIndex2,
double AuxVals,
const int  CurrentRow,
IndexType RowEnd,
const SizeType  InitialIndexColumn,
const double  ContributionCoefficient = 1.0 
)
inlinestatic

This is a method to compute the contribution of the auxiliar blocks.

Parameters
AuxKThe auxiliar block
AuxIndex2The indexes of the non zero columns
AuxValsThe values of the final matrix
CurrentRowThe current row computed
RowEndThe last column computed
InitialIndexColumnThe initial column index of the auxiliar block in the final matrix

◆ ComputeNonZeroBlocks()

static void Kratos::SparseMatrixMultiplicationUtility::ComputeNonZeroBlocks ( const CompressedMatrix rMatrix,
const int  CurrentRow,
IndexType rNonZeroColsAux2 
)
inlinestatic

This is a method to check the block containing nonzero values.

Parameters
rMatrixThe auxiliar block
CurrentRowThe current row computed
rNonZeroColsAux2The nonzero rows array

◆ CreateSolutionMatrix()

template<class CMatrix , typename TSize , typename Ptr , typename IndexType , typename ValueType >
static void Kratos::SparseMatrixMultiplicationUtility::CreateSolutionMatrix ( CMatrix &  C,
const TSize  NRows,
const TSize  NCols,
const Ptr *  CPtr,
const IndexType AuxIndex2C,
const ValueType *  AuxValC 
)
inlinestatic

This method is designed to create the final solution sparse matrix from the auxiliar values.

Parameters
CThe matrix solution
NRowsThe number of rows of the matrix
NColsThe number of columns of the matrix
CPtrThe indexes taht indicate the number of nonzero values in each column
AuxIndex2CThe indexes of the nonzero columns
AuxValCThe C array containing the values of the sparse matrix

◆ Info()

std::string Kratos::SparseMatrixMultiplicationUtility::Info ( ) const
inline

Turn back information as a string.

◆ KRATOS_CLASS_POINTER_DEFINITION()

Kratos::SparseMatrixMultiplicationUtility::KRATOS_CLASS_POINTER_DEFINITION ( SparseMatrixMultiplicationUtility  )

Pointer definition of TreeContactSearch.

◆ MatrixAdd()

template<class AMatrix , class BMatrix >
static void Kratos::SparseMatrixMultiplicationUtility::MatrixAdd ( AMatrix &  A,
const BMatrix &  B,
const double  Factor = 1.0 
)
inlinestatic

The first is a method in order to sum to sparse matrices in a efficient way.

Parameters
AThe resulting matrix
BThe second matrix to sum

◆ MatrixMultiplication()

template<class AMatrix , class BMatrix , class CMatrix >
static void Kratos::SparseMatrixMultiplicationUtility::MatrixMultiplication ( const AMatrix &  rA,
const BMatrix &  rB,
CMatrix &  rC 
)
inlinestatic

Matrix-matrix product C = A·B @detail This method uses a template for each matrix.

Parameters
rAThe first matrix
rBThe second matrix
rCThe resulting matrix

◆ MatrixMultiplicationRMerge()

template<class AMatrix , class BMatrix , class CMatrix >
static void Kratos::SparseMatrixMultiplicationUtility::MatrixMultiplicationRMerge ( const AMatrix &  A,
const BMatrix &  B,
CMatrix &  C 
)
inlinestatic

Row-merge algorithm from Rupp et al.

The algorithm requires less memory and shows much better scalability than classic one. It is used when number of OpenMP cores is more than 4.

Parameters
AThe first matrix to multiply
BThe second matrix to multiply
CThe resulting matrix

◆ MatrixMultiplicationSaad()

template<class AMatrix , class BMatrix , class CMatrix >
static void Kratos::SparseMatrixMultiplicationUtility::MatrixMultiplicationSaad ( const AMatrix &  A,
const BMatrix &  B,
CMatrix &  C 
)
inlinestatic

The first is an OpenMP-enabled modification of classic algorithm from Saad.

It is used whenever number of OpenMP cores is 4 or less. Saad, Yousef. Iterative methods for sparse linear systems. Siam, 2003.

Parameters
AThe first matrix to multiply
BThe second matrix to multiply
CThe resulting matrix

◆ PrintData()

void Kratos::SparseMatrixMultiplicationUtility::PrintData ( std::ostream &  rOStream) const
inline

Print object's data.

◆ PrintInfo()

void Kratos::SparseMatrixMultiplicationUtility::PrintInfo ( std::ostream &  rOStream) const
inline

Print information about this object.

◆ SortRows()

template<typename TSize , typename Col , typename TIndexType , typename ValueType >
static void Kratos::SparseMatrixMultiplicationUtility::SortRows ( const TIndexType *  CPtr,
const TSize  NRows,
const TSize  NCols,
Col *  Columns,
ValueType *  Values 
)
inlinestatic

This method is designed to reorder the rows by columns.

Parameters
NRowsThe number of rows of the matrix
NColsThe number of columns of the matrix
CPtrThe indexes taht indicate the number of nonzero values in each column
ColumnsThe columns of the problem
ValuesThe values (to be ordered with the rows)

◆ TransposeMatrix()

template<class AMatrix , class BMatrix >
static void Kratos::SparseMatrixMultiplicationUtility::TransposeMatrix ( AMatrix &  rA,
const BMatrix &  rB,
const double  Factor = 1.0 
)
inlinestatic

This method computes of the transpose matrix of a given matrix.

Parameters
rAThe resulting matrix
rBThe second matrix to transpose

The documentation for this class was generated from the following file: