queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::GslBlockMatrix Class Reference

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

#include <GslBlockMatrix.h>

Inheritance diagram for QUESO::GslBlockMatrix:
QUESO::Matrix

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 Map m_map
 Mapping 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 }
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
std::vector< GslMatrix * > m_blocks
const BaseEnvironment & m_env
QUESO environment variable.
Definition: Matrix.h:116
Matrix()
Default constructor.
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< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
std::vector< GslMatrix * > m_blocks

Member Function Documentation

int QUESO::GslBlockMatrix::chol ( )
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 73 of file GslBlockMatrix.C.

74 {
75  queso_not_implemented();
76  return 0;
77 }
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, 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 }
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
std::vector< GslMatrix * > m_blocks
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.

67 {
68  queso_not_implemented();
69  return 0;
70 }
unsigned int QUESO::GslBlockMatrix::numRowsGlobal ( ) const
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 59 of file GslBlockMatrix.C.

60 {
61  queso_not_implemented();
62  return 0;
63 }
unsigned int QUESO::GslBlockMatrix::numRowsLocal ( ) const
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 53 of file GslBlockMatrix.C.

54 {
55  queso_not_implemented();
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 }
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.
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:1772
void QUESO::GslBlockMatrix::zeroLower ( bool  includeDiagonal = false)
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 80 of file GslBlockMatrix.C.

81 {
82  queso_not_implemented();
83 }
void QUESO::GslBlockMatrix::zeroUpper ( bool  includeDiagonal = false)
virtual

Not implemented yet.

Implements QUESO::Matrix.

Definition at line 86 of file GslBlockMatrix.C.

87 {
88  queso_not_implemented();
89 }

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 Tue Jun 5 2018 19:49:07 for queso-0.57.1 by  doxygen 1.8.5