queso-0.53.0
GslBlockMatrix.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2015 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #include <queso/GslBlockMatrix.h>
26 
27 namespace QUESO {
28 
29 GslBlockMatrix::GslBlockMatrix(const std::vector<unsigned int> & blockSizes,
30  const GslVector & v, double diagValue)
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++) {
37  "block_param_", blockSizes[i], NULL);
38  this->m_blocks[i] = new GslMatrix(this->m_vectorSpaces[i]->zeroVector(),
39  diagValue);
40  }
41 }
42 
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 }
50 
51 
52 unsigned int
54 {
56 }
57 
58 unsigned int
60 {
62  return 0;
63 }
64 
65 unsigned int
67 {
69  return 0;
70 }
71 
72 int
74 {
76  return 0;
77 }
78 
79 void
80 GslBlockMatrix::zeroLower(bool includeDiagonal)
81 {
83 }
84 
85 void
86 GslBlockMatrix::zeroUpper(bool includeDiagonal)
87 {
89 }
90 
91 
92 GslMatrix &
93 GslBlockMatrix::getBlock(unsigned int i) const
94 {
95  return *(this->m_blocks[i]);
96 }
97 
98 unsigned int
100 {
101  return this->m_blocks.size();
102 }
103 
104 void
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 }
146 
147 void
148 GslBlockMatrix::print(std::ostream& os) const
149 {
150  for (unsigned int i = 0; i < this->numBlocks(); i++) {
151  this->getBlock(i).print(os);
152  }
153 }
154 
155 std::ostream&
156 operator<<(std::ostream& os, const GslBlockMatrix & obj)
157 {
158  obj.print(os);
159 
160  return os;
161 }
162 
163 } // End namespace QUESO
virtual void zeroLower(bool includeDiagonal=false)
Not implemented yet.
Class for matrix operations using GSL library.
Definition: GslMatrix.h:47
const BaseEnvironment & m_env
QUESO environment variable.
Definition: Matrix.h:116
Class for matrix operations (virtual).
Definition: Matrix.h:46
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.
unsigned int sizeLocal() const
Returns the length of this vector.
Definition: GslVector.C:253
virtual void zeroUpper(bool includeDiagonal=false)
Not implemented yet.
#define queso_error_msg(msg)
Definition: asserts.h:47
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
std::vector< GslMatrix * > m_blocks
virtual unsigned int numCols() const
Not implemented yet.
GslMatrix & getBlock(unsigned int i) const
Return block i in the block diagonal matrix.
virtual int chol()
Not implemented yet.
Class for representing block matrices using GSL library.
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
Class for vector operations using GSL library.
Definition: GslVector.h:48
#define queso_not_implemented()
Definition: asserts.h:56
virtual unsigned int numRowsGlobal() const
Not implemented yet.
~GslBlockMatrix()
Destructor.
virtual void print(std::ostream &os) const
Print method. Defines the behavior of operator&lt;&lt; inherited from the Object class. ...
void invertMultiply(const GslVector &b, GslVector &x) const
This function calculates the inverse of this matrix, multiplies it with vector b and stores the resul...
virtual unsigned int numRowsLocal() const
Not implemented yet.
A class representing a vector space.
Definition: VectorSet.h:49
std::vector< VectorSpace< GslVector, GslMatrix > * > m_vectorSpaces
unsigned int numBlocks() const
Return the number of blocks in the block diagonal matrix.

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