queso-0.53.0
Public Member Functions | Private Attributes | List of all members
QUESO::GslBlockMatrix Class Reference

Class for representing block matrices using GSL library. More...

#include <GslBlockMatrix.h>

Inheritance diagram for QUESO::GslBlockMatrix:
Inheritance graph
[legend]
Collaboration diagram for QUESO::GslBlockMatrix:
Collaboration graph
[legend]

Public Member Functions

virtual unsigned int numRowsLocal () const
 Not implemented yet. More...
 
virtual unsigned int numRowsGlobal () const
 Not implemented yet. More...
 
virtual unsigned int numCols () const
 Not implemented yet. More...
 
virtual int chol ()
 Not implemented yet. More...
 
virtual void zeroLower (bool includeDiagonal=false)
 Not implemented yet. More...
 
virtual void zeroUpper (bool includeDiagonal=false)
 Not implemented yet. More...
 
GslMatrixgetBlock (unsigned int i) const
 Return block i in the block diagonal matrix. More...
 
unsigned int numBlocks () const
 Return the number of blocks in the block diagonal matrix. More...
 
void invertMultiply (const GslVector &b, GslVector &x) const
 This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x. More...
 
Constructor/Destructor methods
 GslBlockMatrix (const std::vector< unsigned int > &blockSizes, const GslVector &v, double diagValue)
 Creates a square matrix with size defined by v and diagonal values all equal to diagValue. More...
 
 ~GslBlockMatrix ()
 Destructor. More...
 
I/O methods
virtual void print (std::ostream &os) const
 Print method. Defines the behavior of operator<< inherited from the Object class. More...
 

Private Attributes

std::vector< VectorSpace
< GslVector, GslMatrix > * > 
m_vectorSpaces
 
std::vector< GslMatrix * > m_blocks
 
- Private Attributes inherited from QUESO::Matrix
const BaseEnvironmentm_env
 QUESO environment variable. More...
 
const Mapm_map
 Mapping variable. More...
 
bool m_printHorizontally
 Flag for either or not print this matrix. More...
 
bool m_inDebugMode
 Flag for either or not QUESO is in debug mode. More...
 

Additional Inherited Members

- Private Member Functions inherited from QUESO::Matrix
 Matrix (const BaseEnvironment &env, const Map &map)
 Shaped constructor. More...
 
virtual ~Matrix ()
 Virtual Destructor. More...
 
const BaseEnvironmentenv () const
 
const Mapmap () const
 
unsigned int numOfProcsForStorage () const
 
void setPrintHorizontally (bool value) const
 Determines whether the matrix should be printed horizontally. More...
 
bool getPrintHorizontally () const
 Checks if matrix will be is printed horizontally. More...
 
void setInDebugMode (bool value) const
 Determines whether QUESO will run through this class in debug mode. More...
 
bool getInDebugMode () const
 Checks if QUESO will run through this class in debug mode. More...
 
virtual void base_copy (const Matrix &src)
 Copies base data from matrix src to this matrix. More...
 

Detailed Description

Class for representing block matrices using GSL library.

This class provides basic 'invertMultiply' support for matrices of block diagonal structure. Each block is implemented as a GslMatrix object.

Definition at line 50 of file GslBlockMatrix.h.

Constructor & Destructor Documentation

QUESO::GslBlockMatrix::GslBlockMatrix ( const std::vector< unsigned int > &  blockSizes,
const GslVector v,
double  diagValue 
)

Creates a square matrix with size defined by v and diagonal values all equal to diagValue.

The blockSizes array determines the sizes of each (square) block.

Definition at line 29 of file GslBlockMatrix.C.

References m_blocks, QUESO::Matrix::m_env, and m_vectorSpaces.

31  : Matrix(v.env(), v.map()),
32  m_vectorSpaces(blockSizes.size()),
33  m_blocks(blockSizes.size())
34 {
35  for (unsigned int i = 0; i < this->m_vectorSpaces.size(); i++) {
36  this->m_vectorSpaces[i] = new VectorSpace<GslVector, GslMatrix>(m_env,
37  "block_param_", blockSizes[i], NULL);
38  this->m_blocks[i] = new GslMatrix(this->m_vectorSpaces[i]->zeroVector(),
39  diagValue);
40  }
41 }
const BaseEnvironment & m_env
QUESO environment variable.
Definition: Matrix.h:116
Matrix()
Default constructor.
std::vector< GslMatrix * > m_blocks
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
QUESO::GslBlockMatrix::~GslBlockMatrix ( )

Destructor.

Definition at line 43 of file GslBlockMatrix.C.

References m_blocks, and m_vectorSpaces.

44 {
45  for (unsigned int i = 0; i < this->m_vectorSpaces.size(); i++) {
46  delete this->m_blocks[i];
47  delete this->m_vectorSpaces[i];
48  }
49 }
std::vector< GslMatrix * > m_blocks
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces

Member Function Documentation

int QUESO::GslBlockMatrix::chol ( )
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 73 of file GslBlockMatrix.C.

References queso_not_implemented.

74 {
76  return 0;
77 }
#define queso_not_implemented()
Definition: asserts.h:56
GslMatrix & QUESO::GslBlockMatrix::getBlock ( unsigned int  i) const
void QUESO::GslBlockMatrix::invertMultiply ( const GslVector b,
GslVector x 
) const

This function calculates the inverse of this matrix, multiplies it with vector b and stores the result in vector x.

It checks for a previous LU decomposition of each block matrix and does not recompute it if m_MU != NULL for each block.

Definition at line 105 of file GslBlockMatrix.C.

References m_blocks, m_vectorSpaces, queso_error_msg, and QUESO::GslVector::sizeLocal().

106 {
107  unsigned int totalCols = 0;
108 
109  for (unsigned int i = 0; i < this->m_blocks.size(); i++) {
110  totalCols += this->m_blocks[i]->numCols();
111  }
112 
113  if (totalCols != b.sizeLocal()) {
114  queso_error_msg("block matrix and rhs have incompatible sizes");
115  }
116 
117  if (x.sizeLocal() != b.sizeLocal()) {
118  queso_error_msg("solution and rhs have incompatible sizes");
119  }
120 
121  unsigned int blockOffset = 0;
122 
123  // Do an invertMultiply for each block
124  for (unsigned int i = 0; i < this->m_blocks.size(); i++) {
125  GslVector blockRHS(this->m_vectorSpaces[i]->zeroVector());
126  GslVector blockSol(this->m_vectorSpaces[i]->zeroVector());
127 
128  // Be sure to copy over the RHS to the right sized vector
129  for (unsigned int j = 0; j < this->m_blocks[i]->numCols(); j++) {
130  blockRHS[j] = b[blockOffset + j];
131  }
132 
133  // Solve
134  this->m_blocks[i]->invertMultiply(blockRHS, blockSol);
135 
136  // Be sure to copy the block solution back to the global solution vector
137  for (unsigned int j = 0; j < this->m_blocks[i]->numCols(); j++) {
138  x[blockOffset + j] = blockSol[j];
139  }
140 
141  // Remember to increment the offset so we don't lose our place for the next
142  // block
143  blockOffset += this->m_blocks[i]->numCols();
144  }
145 }
#define queso_error_msg(msg)
Definition: asserts.h:47
std::vector< GslMatrix * > m_blocks
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
unsigned int QUESO::GslBlockMatrix::numBlocks ( ) const
unsigned int QUESO::GslBlockMatrix::numCols ( ) const
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 66 of file GslBlockMatrix.C.

References queso_not_implemented.

67 {
69  return 0;
70 }
#define queso_not_implemented()
Definition: asserts.h:56
unsigned int QUESO::GslBlockMatrix::numRowsGlobal ( ) const
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 59 of file GslBlockMatrix.C.

References queso_not_implemented.

60 {
62  return 0;
63 }
#define queso_not_implemented()
Definition: asserts.h:56
unsigned int QUESO::GslBlockMatrix::numRowsLocal ( ) const
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 53 of file GslBlockMatrix.C.

References queso_not_implemented.

54 {
56 }
#define queso_not_implemented()
Definition: asserts.h:56
void QUESO::GslBlockMatrix::print ( std::ostream &  os) const
virtual

Print method. Defines the behavior of operator<< inherited from the Object class.

Implements QUESO::Matrix.

Definition at line 148 of file GslBlockMatrix.C.

References getBlock(), numBlocks(), and QUESO::GslMatrix::print().

Referenced by QUESO::operator<<().

149 {
150  for (unsigned int i = 0; i < this->numBlocks(); i++) {
151  this->getBlock(i).print(os);
152  }
153 }
GslMatrix & getBlock(unsigned int i) const
Return block i in the block diagonal matrix.
void print(std::ostream &os) const
Print method. Defines the behavior of the ostream &lt;&lt; operator inherited from the Object class...
Definition: GslMatrix.C:1762
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.
void QUESO::GslBlockMatrix::zeroLower ( bool  includeDiagonal = false)
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 80 of file GslBlockMatrix.C.

References queso_not_implemented.

81 {
83 }
#define queso_not_implemented()
Definition: asserts.h:56
void QUESO::GslBlockMatrix::zeroUpper ( bool  includeDiagonal = false)
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 86 of file GslBlockMatrix.C.

References queso_not_implemented.

87 {
89 }
#define queso_not_implemented()
Definition: asserts.h:56

Member Data Documentation

std::vector<GslMatrix *> QUESO::GslBlockMatrix::m_blocks
private
std::vector<VectorSpace<GslVector, GslMatrix> *> QUESO::GslBlockMatrix::m_vectorSpaces
private

Definition at line 104 of file GslBlockMatrix.h.

Referenced by GslBlockMatrix(), invertMultiply(), and ~GslBlockMatrix().


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

Generated on Thu Jun 11 2015 13:52:34 for queso-0.53.0 by  doxygen 1.8.5