IpCompoundMatrix.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __IPCOMPOUNDMATRIX_HPP__
00010 #define __IPCOMPOUNDMATRIX_HPP__
00011
00012 #include "IpUtils.hpp"
00013 #include "IpMatrix.hpp"
00014
00015 namespace Ipopt
00016 {
00017
00018
00019 class CompoundMatrixSpace;
00020
00034 class CompoundMatrix : public Matrix
00035 {
00036 public:
00037
00040
00047 CompoundMatrix(const CompoundMatrixSpace* owner_space);
00048
00050 ~CompoundMatrix();
00052
00056 void SetComp(Index irow, Index jcol, const Matrix& matrix);
00057
00059 void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
00060
00062 void CreateBlockFromSpace(Index irow, Index jcol);
00063
00067 SmartPtr<const Matrix> GetComp(Index irow, Index jcol) const
00068 {
00069 return ConstComp(irow, jcol);
00070 }
00071
00076 SmartPtr<Matrix> GetCompNonConst(Index irow, Index jcol)
00077 {
00078 ObjectChanged();
00079 return Comp(irow, jcol);
00080 }
00081
00083 inline Index NComps_Rows() const;
00085 inline Index NComps_Cols() const;
00086
00087 protected:
00090 virtual void MultVectorImpl(Number alpha, const Vector& x,
00091 Number beta, Vector& y) const;
00092
00093 virtual void TransMultVectorImpl(Number alpha, const Vector& x,
00094 Number beta, Vector& y) const;
00095
00098 virtual void AddMSinvZImpl(Number alpha, const Vector& S, const Vector& Z,
00099 Vector& X) const;
00100
00103 virtual void SinvBlrmZMTdBrImpl(Number alpha, const Vector& S,
00104 const Vector& R, const Vector& Z,
00105 const Vector& D, Vector& X) const;
00106
00109 virtual bool HasValidNumbersImpl() const;
00110
00111 virtual void PrintImpl(const Journalist& jnlst,
00112 EJournalLevel level,
00113 EJournalCategory category,
00114 const std::string& name,
00115 Index indent,
00116 const std::string& prefix) const;
00118
00119 private:
00129 CompoundMatrix();
00130
00132 CompoundMatrix(const CompoundMatrix&);
00133
00135 void operator=(const CompoundMatrix&);
00137
00139 std::vector<std::vector<SmartPtr<Matrix> > > comps_;
00140
00142 std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
00143
00146 const CompoundMatrixSpace* owner_space_;
00147
00149 mutable bool matrices_valid_;
00150
00152 bool MatricesValid() const;
00153
00154 inline const Matrix* ConstComp(Index irow, Index jcol) const;
00155
00156 inline Matrix* Comp(Index irow, Index jcol);
00157 };
00158
00164 class CompoundMatrixSpace : public MatrixSpace
00165 {
00166 public:
00172 CompoundMatrixSpace(Index ncomps_rows,
00173 Index ncomps_cols,
00174 Index total_nRows,
00175 Index total_nCols);
00176
00178 ~CompoundMatrixSpace()
00179 {}
00180 ;
00182
00186 void SetBlockRows(Index irow, Index nrows);
00187
00189 void SetBlockCols(Index jcol, Index ncols);
00190
00192 Index GetBlockRows(Index irow) const;
00193
00195 Index GetBlockCols(Index jcol) const;
00196
00203 void SetCompSpace(Index irow, Index jcol,
00204 const MatrixSpace& mat_space,
00205 bool auto_allocate = false);
00207
00211 SmartPtr<const MatrixSpace> GetCompSpace(Index irow, Index jcol) const
00212 {
00213 DBG_ASSERT(irow<NComps_Rows());
00214 DBG_ASSERT(jcol<NComps_Cols());
00215 return comp_spaces_[irow][jcol];
00216 }
00217
00221 Index NComps_Rows() const
00222 {
00223 return ncomps_rows_;
00224 }
00226 Index NComps_Cols() const
00227 {
00228 return ncomps_cols_;
00229 }
00230
00232 bool Diagonal() const
00233 {
00234 return diagonal_;
00235 }
00237
00239 CompoundMatrix* MakeNewCompoundMatrix() const;
00240
00243 virtual Matrix* MakeNew() const
00244 {
00245 return MakeNewCompoundMatrix();
00246 }
00247
00248 private:
00258 CompoundMatrixSpace();
00259
00261 CompoundMatrixSpace(const CompoundMatrixSpace&);
00262
00264 CompoundMatrixSpace& operator=(const CompoundMatrixSpace&);
00266
00268 Index ncomps_rows_;
00269
00271 Index ncomps_cols_;
00272
00274 mutable bool dimensions_set_;
00275
00277 std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
00278
00281 std::vector<std::vector< bool > > allocate_block_;
00282
00284 std::vector<Index> block_rows_;
00285
00287 std::vector<Index> block_cols_;
00288
00293 bool diagonal_;
00294
00297 bool DimensionsSet() const;
00298 };
00299
00300
00301 inline
00302 Index CompoundMatrix::NComps_Rows() const
00303 {
00304 return owner_space_->NComps_Rows();
00305 }
00306
00307 inline
00308 Index CompoundMatrix::NComps_Cols() const
00309 {
00310 return owner_space_->NComps_Cols();
00311 }
00312
00313 inline
00314 const Matrix* CompoundMatrix::ConstComp(Index irow, Index jcol) const
00315 {
00316 DBG_ASSERT(irow < NComps_Rows());
00317 DBG_ASSERT(jcol < NComps_Cols());
00318 if (IsValid(comps_[irow][jcol])) {
00319 return GetRawPtr(comps_[irow][jcol]);
00320 }
00321 else if (IsValid(const_comps_[irow][jcol])) {
00322 return GetRawPtr(const_comps_[irow][jcol]);
00323 }
00324
00325 return NULL;
00326 }
00327
00328 inline
00329 Matrix* CompoundMatrix::Comp(Index irow, Index jcol)
00330 {
00331 DBG_ASSERT(irow < NComps_Rows());
00332 DBG_ASSERT(jcol < NComps_Cols());
00333 return GetRawPtr(comps_[irow][jcol]);
00334 }
00335
00336 }
00337 #endif