Back to index

salome-med  6.5.0
Classes | Public Types | Public Member Functions | Private Attributes | Friends
INTERP_KERNEL::Matrix< T, type > Class Template Reference

#include <InterpKernelMatrix.hxx>

Inheritance diagram for INTERP_KERNEL::Matrix< T, type >:
Inheritance graph
[legend]
Collaboration diagram for INTERP_KERNEL::Matrix< T, type >:
Collaboration graph
[legend]

List of all members.

Classes

class  KeyComparator
class  Row

Public Types

typedef Row value_type

Public Member Functions

 Matrix ()
 Matrix (int nbrows)
 Matrix (std::vector< std::map< int, T > > &matrix)
 Matrix (const Matrix &m)
 Copy constructor.
 ~Matrix ()
Matrixoperator= (const Matrix &m)
void resize (unsigned int nbrows)
 declares a method that specifies the number of rows
void setIJ (int irow, int icol, T value)
 sets (i,j) coefficient to value
void multiply (const T *const input, T *const output)
 Matrix multiplies vector input and stores the result in vector output.
void multiply (const T *const input, T *const output, int nb_comp)
 Matrix multiplies vector input and stores the result in vector output.
void transposeMultiply (const T *const input, T *const output, int nb_cols)
 Transpose-multiplies vector input and stores the result in vector output.
void transposeMultiply (const T *const input, T *const output, int nb_cols, int nb_comp)
 Transpose-multiplies vector input and stores the result in vector output.
void colSum (std::vector< T > &output, int nb_cols)
void rowSum (std::vector< T > &output)
void configure ()
 This operation freezes the profile of the matrix and puts it under a CSR form so that it becomes efficient both in terms of memory occupation and in terms of multiplication.
Rowoperator[] (unsigned int irow)
 0 <= irow < n
int getNbRows ()

Private Attributes

unsigned int _nb_rows
T * _coeffs
unsigned int * _cols
std::vector< unsigned int > _ncols_offset
std::vector< Row_auxiliary_matrix
bool _is_configured

Friends

std::ostream & operator<< (std::ostream &in, const Matrix< T, type > &m)
 output to an ascii file only nonzero elements are written
std::istream & operator>> (std::istream &in, Matrix< T, type > &m)

Detailed Description

template<class T, NumberingPolicy type = ALL_C_MODE>
class INTERP_KERNEL::Matrix< T, type >

Definition at line 42 of file InterpKernelMatrix.hxx.


Member Typedef Documentation

template<class T, NumberingPolicy type = ALL_C_MODE>
typedef Row INTERP_KERNEL::Matrix< T, type >::value_type

Definition at line 91 of file InterpKernelMatrix.hxx.


Constructor & Destructor Documentation

template<class T, NumberingPolicy type = ALL_C_MODE>
INTERP_KERNEL::Matrix< T, type >::Matrix ( ) [inline]

Definition at line 93 of file InterpKernelMatrix.hxx.

            :_coeffs(0), _cols(0), _nb_rows(0), _is_configured(false)
    { }
template<class T, NumberingPolicy type = ALL_C_MODE>
INTERP_KERNEL::Matrix< T, type >::Matrix ( int  nbrows) [inline]

Definition at line 95 of file InterpKernelMatrix.hxx.

                      :_coeffs(0), _cols(0), _is_configured(false)
    { _nb_rows=nbrows; }
template<class T, NumberingPolicy type = ALL_C_MODE>
INTERP_KERNEL::Matrix< T, type >::Matrix ( std::vector< std::map< int, T > > &  matrix) [inline]

Definition at line 97 of file InterpKernelMatrix.hxx.

                                               :
      _coeffs(0), _cols(0), _is_configured(false)
    {
      _nb_rows=matrix.size();
      _auxiliary_matrix.resize(_nb_rows);
      for (int i=0; i<_nb_rows; i++)
        {
          typename std::map<int,T>::iterator it;
          for (it=matrix[i].begin(); it != matrix[i].end(); it++)
            _auxiliary_matrix[i].push_back(*it);//MN: pq push_back plutot que simple affectation?
        }      
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
INTERP_KERNEL::Matrix< T, type >::Matrix ( const Matrix< T, type > &  m) [inline]

Copy constructor.

Definition at line 111 of file InterpKernelMatrix.hxx.

    {
      _is_configured=m._is_configured;
      _nb_rows=m._nb_rows;
      _auxiliary_matrix=m._auxiliary_matrix;
      _ncols_offset=m._ncols_offset;
      if (_is_configured)
        {
          int size=_ncols_offset[_nb_rows];
          _coeffs = new double[size];
          _cols = new unsigned int[size];
          memcpy(_coeffs, m._coeffs, size*sizeof(double));
          memcpy(_cols, m._cols, size*sizeof(int));
        }
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
INTERP_KERNEL::Matrix< T, type >::~Matrix ( ) [inline]

Definition at line 127 of file InterpKernelMatrix.hxx.

    {
      delete[] _coeffs;
      delete[] _cols;
    }

Member Function Documentation

template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::colSum ( std::vector< T > &  output,
int  nb_cols 
) [inline]

Definition at line 283 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      for (int icol=0; icol< nb_cols; icol++)
        output[icol]=0.;
      for (int i=0; i< _nb_rows; i++)
        {
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++)
            {
              int icol = _cols[j];
              output[icol]+=_coeffs[j];
            }
        }
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::configure ( ) [inline]

This operation freezes the profile of the matrix and puts it under a CSR form so that it becomes efficient both in terms of memory occupation and in terms of multiplication.

Definition at line 320 of file InterpKernelMatrix.hxx.

    {
      _ncols_offset.resize(_nb_rows+1);
      _ncols_offset[0]=0;
      for (unsigned int i=0; i<_nb_rows; i++)
        _ncols_offset[i+1]=_ncols_offset[i]+_auxiliary_matrix[i].size();
      int nbcoeffs= _ncols_offset[_nb_rows];
      _cols=new unsigned int[nbcoeffs];
      _coeffs=new T[nbcoeffs];
      unsigned int* cols_ptr=_cols;
      T* coeffs_ptr=_coeffs;
      for (unsigned int i=0; i<_nb_rows; i++)
        {
          for (unsigned int j=0; j<_auxiliary_matrix[i].size(); j++)
            {
              *cols_ptr++ = OTT<int,type>::ind2C(_auxiliary_matrix[i][j].first);
              *coeffs_ptr++ = _auxiliary_matrix[i][j].second;
            }
        }
      _auxiliary_matrix.clear();
      _is_configured=true;
    }

Here is the caller graph for this function:

template<class T, NumberingPolicy type = ALL_C_MODE>
int INTERP_KERNEL::Matrix< T, type >::getNbRows ( ) [inline]

Definition at line 351 of file InterpKernelMatrix.hxx.

    {
      return _nb_rows;
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::multiply ( const T *const  input,
T *const  output 
) [inline]

Matrix multiplies vector input and stores the result in vector output.

The vector pointed by input must be dimensioned to the number of columns while the vector pointed by output must be dimensioned to the number of rows.

Definition at line 181 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      
      for (int i=0; i< _nb_rows; i++)
        {
          output[i]=0.;
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++)
            {
              int icol = _cols[j];
              output[i]+=input[icol]*_coeffs[j];
            }
        }
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::multiply ( const T *const  input,
T *const  output,
int  nb_comp 
) [inline]

Matrix multiplies vector input and stores the result in vector output.

input and output are supposed to represent the same field discretised on two different on meshes. nb_comp is the number of components of the fields input and output The vector pointed by input must be dimensioned to the number of columns times nb_comp while the vector pointed by output must be dimensioned to the number of rows times nb_comp.

Definition at line 207 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      
      for (int i=0; i< _nb_rows; i++)
        {
          for(int comp = 0; comp < nb_comp; comp++)
            output[i*nb_comp+comp]=0.;
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++)
            {
              int icol = _cols[j];
              for(int comp = 0; comp < nb_comp; comp++)
                output[i*nb_comp+comp]+=input[icol*nb_comp+comp]*_coeffs[j];
            }
        }
    }   
template<class T, NumberingPolicy type = ALL_C_MODE>
Matrix& INTERP_KERNEL::Matrix< T, type >::operator= ( const Matrix< T, type > &  m) [inline]

Definition at line 133 of file InterpKernelMatrix.hxx.

    {
      _is_configured=m._is_configured;
      _nb_rows=m._nb_rows;
      _auxiliary_matrix=m._auxiliary_matrix;
      _ncols_offset=m._ncols_offset;
      if (_is_configured)
        {
          int size=_ncols_offset[_nb_rows];
          _coeffs = new double[size];
          _cols = new unsigned int[size];
          memcpy(_coeffs, m._coeffs, size*sizeof(double));
          memcpy(_cols, m._cols, size*sizeof(int));
        }
      return this;
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
Row& INTERP_KERNEL::Matrix< T, type >::operator[] ( unsigned int  irow) [inline]

0 <= irow < n

Definition at line 346 of file InterpKernelMatrix.hxx.

    {
      return _auxiliary_matrix[irow];
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::resize ( unsigned int  nbrows) [inline]

declares a method that specifies the number of rows

Definition at line 151 of file InterpKernelMatrix.hxx.

    {
      _nb_rows=nbrows;
      _auxiliary_matrix.resize(nbrows);
    }

Here is the caller graph for this function:

template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::rowSum ( std::vector< T > &  output) [inline]

Definition at line 303 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      for (int i=0; i< _nb_rows; i++)
        {
          output[i]=0;
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++) 
            output[i]+=_coeffs[j];
        }
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::setIJ ( int  irow,
int  icol,
value 
) [inline]

sets (i,j) coefficient to value

Definition at line 158 of file InterpKernelMatrix.hxx.

    {
      if (_is_configured)
        throw Exception("filling a configured matrix");
      if (_auxiliary_matrix.empty())
        _auxiliary_matrix.resize(_nb_rows);
      
      for (unsigned int i=0; i< _auxiliary_matrix[OTT<int,type>::ind2C(irow)].size(); i++)
        if (_auxiliary_matrix[OTT<int,type>::ind2C(irow)][i].first == icol)
          {
            _auxiliary_matrix[OTT<int,type>::ind2C(irow)][i].second = value;
            return;
          }
      _auxiliary_matrix[OTT<int,type>::ind2C(irow)].push_back(std::make_pair(icol, value));
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::transposeMultiply ( const T *const  input,
T *const  output,
int  nb_cols 
) [inline]

Transpose-multiplies vector input and stores the result in vector output.

nb_cols is the number of columns of the matrix, (it is not an attribute of the class) The vector pointed by input must be dimensioned to the number of lines _nb_rows while the vector pointed by output must be dimensioned to the number of columns nb_cols.

Definition at line 232 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      
      for (int icol=0; icol< nb_cols; icol++)
        output[icol]=0.;
      for (int i=0; i< _nb_rows; i++)
        {
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++)
            {
              int icol = _cols[j];
              output[icol]+=input[i]*_coeffs[j];
            }
        }
    }
template<class T, NumberingPolicy type = ALL_C_MODE>
void INTERP_KERNEL::Matrix< T, type >::transposeMultiply ( const T *const  input,
T *const  output,
int  nb_cols,
int  nb_comp 
) [inline]

Transpose-multiplies vector input and stores the result in vector output.

input and output are supposed to represent the same field discretised on two different on meshes. nb_comp is the number of components of the fields input and output nb_cols is the number of columns of the matrix, (it is not an attribute of the class) The vector pointed by input must be dimensioned to _nb_rows*nb_comp while the vector pointed by output must be dimensioned to nb_cols*nb_comp.

Definition at line 259 of file InterpKernelMatrix.hxx.

    {
      if (!_is_configured)
        configure();
      
      for (int icol=0; icol< nb_cols; icol++)
        for(int comp = 0; comp < nb_comp; comp++)
          output[icol*nb_comp+comp]=0.;

      for (int i=0; i< _nb_rows; i++)
        {
          for (unsigned int j=_ncols_offset[i]; j< _ncols_offset[i+1]; j++)
            {
              int icol = _cols[j];
              for(int comp = 0; comp < nb_comp; comp++)
                output[icol*nb_comp+comp]+=input[i*nb_comp+comp]*_coeffs[j];
            }
        }
    }

Friends And Related Function Documentation

template<class T, NumberingPolicy type = ALL_C_MODE>
std::ostream& operator<< ( std::ostream &  in,
const Matrix< T, type > &  m 
) [friend]

output to an ascii file only nonzero elements are written

  • the first line contains the indexing (0 or 1)
  • the second line contains the number of rows.
  • for each row, a line contains:
  • the number of nonzero coeffs
  • and for each coeff : icol, value

for instance, matrix | 1.0 0.0 0.5 | | 0.0 1.0 0.0 | | 0.2 0.0 1.0 | will be displayed in 0-indexing as 0 3 2 0 1.0 2 0.5 1 1 1.0 2 0 0.2 2 1.0

Definition at line 379 of file InterpKernelMatrix.hxx.

  {
    if (m._is_configured)
      {
        out << OTT<unsigned int,type>::indFC(0) <<std::endl;
        out << m._nb_rows<<std::endl;
        for (unsigned int i=0; i<m._nb_rows; i++)
          {
            out << m._ncols_offset[i+1]-m._ncols_offset[i];
            for (unsigned int j=m._ncols_offset[i]; j<m._ncols_offset[i+1]; j++)
              out <<"\t"<< OTT<unsigned int,type>::indFC(m._cols[j]) <<"\t"<<m._coeffs[j];
            out<<std::endl;
          }
      }
    else
      {
        out << OTT<unsigned int,type>::indFC(0) <<"\n";
        out << m._nb_rows <<"\n";
        for (unsigned int i=0; i<m._nb_rows; i++)
          {
            out<< m._auxiliary_matrix[i].size();
            for (unsigned int j=0; j<m._auxiliary_matrix[i].size(); j++)
              out << "\t" <<m._auxiliary_matrix[i][j].first <<"\t"
                  <<m._auxiliary_matrix[i][j].second;
            out <<"\n";
          }
      }
    return out;
  }
template<class T, NumberingPolicy type = ALL_C_MODE>
std::istream& operator>> ( std::istream &  in,
Matrix< T, type > &  m 
) [friend]

Definition at line 410 of file InterpKernelMatrix.hxx.

  {
    int index_base_test;
    in >> index_base_test;
    if (index_base_test!=OTT<unsigned int,type>::indFC(0))
      {
        std::cerr << "file index is "<<index_base_test<<std::endl;
        throw Exception("incompatible indexing reading matrix");
      }
    in >> m._nb_rows;
    m._auxiliary_matrix.resize(m._nb_rows);
    for (unsigned int i=0; i<m._nb_rows; i++)
      {
        unsigned int ncols;
        in >> ncols;
        m._auxiliary_matrix[i].resize(ncols);
        double value;
        unsigned int col;
        for (unsigned int j=0; j<ncols; j++)
          {
            in>>col;
            in>>value;
            m._auxiliary_matrix[i].push_back(std::make_pair(col, value));
          }
      }
    return in;
  }

Member Data Documentation

template<class T, NumberingPolicy type = ALL_C_MODE>
std::vector< Row > INTERP_KERNEL::Matrix< T, type >::_auxiliary_matrix [private]

Definition at line 86 of file InterpKernelMatrix.hxx.

template<class T, NumberingPolicy type = ALL_C_MODE>
T* INTERP_KERNEL::Matrix< T, type >::_coeffs [private]

Definition at line 83 of file InterpKernelMatrix.hxx.

template<class T, NumberingPolicy type = ALL_C_MODE>
unsigned int* INTERP_KERNEL::Matrix< T, type >::_cols [private]

Definition at line 84 of file InterpKernelMatrix.hxx.

template<class T, NumberingPolicy type = ALL_C_MODE>
bool INTERP_KERNEL::Matrix< T, type >::_is_configured [private]

Definition at line 89 of file InterpKernelMatrix.hxx.

template<class T, NumberingPolicy type = ALL_C_MODE>
unsigned int INTERP_KERNEL::Matrix< T, type >::_nb_rows [private]

Definition at line 82 of file InterpKernelMatrix.hxx.

template<class T, NumberingPolicy type = ALL_C_MODE>
std::vector<unsigned int> INTERP_KERNEL::Matrix< T, type >::_ncols_offset [private]

Definition at line 85 of file InterpKernelMatrix.hxx.


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