Ipopt  3.11.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
IpCompoundSymMatrix.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2008 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // $Id: IpCompoundSymMatrix.hpp 1861 2010-12-21 21:34:47Z andreasw $
6 //
7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
8 
9 #ifndef __IPCOMPOUNDSYMMATRIX_HPP__
10 #define __IPCOMPOUNDSYMMATRIX_HPP__
11 
12 #include "IpUtils.hpp"
13 #include "IpSymMatrix.hpp"
14 
15 namespace Ipopt
16 {
17 
18  /* forward declarations */
19  class CompoundSymMatrixSpace;
20 
25  {
26  public:
27 
30 
36  CompoundSymMatrix(const CompoundSymMatrixSpace* owner_space);
37 
41 
46  void SetComp(Index irow, Index jcol, const Matrix& matrix);
47 
49  void SetCompNonConst(Index irow, Index jcol, Matrix& matrix);
50 
55  {
56  return ConstComp(irow,jcol);
57  }
58 
63  {
64  ObjectChanged();
65  return Comp(irow,jcol);
66  }
67 
70 
71  // The following don't seem to be necessary
72  /* Number of block rows of this compound matrix. */
73  // Index NComps_NRows() const { return NComps_Dim(); }
74 
75  /* Number of block colmuns of this compound matrix. */
76  // Index NComps_NCols() const { return NComps_Dim(); }
77 
79  Index NComps_Dim() const;
80 
81  protected:
84  virtual void MultVectorImpl(Number alpha, const Vector& x,
85  Number beta, Vector& y) const;
86 
89  virtual bool HasValidNumbersImpl() const;
90 
91  virtual void ComputeRowAMaxImpl(Vector& rows_norms, bool init) const;
92 
93  virtual void PrintImpl(const Journalist& jnlst,
94  EJournalLevel level,
95  EJournalCategory category,
96  const std::string& name,
97  Index indent,
98  const std::string& prefix) const;
100 
101  private:
112 
115 
117  void operator=(const CompoundSymMatrix&);
119 
121  std::vector<std::vector<SmartPtr<Matrix> > > comps_;
122 
124  std::vector<std::vector<SmartPtr<const Matrix> > > const_comps_;
125 
128 
130  mutable bool matrices_valid_;
131 
133  bool MatricesValid() const;
134 
136  const Matrix* ConstComp(Index irow, Index jcol) const
137  {
138  DBG_ASSERT(irow < NComps_Dim());
139  DBG_ASSERT(jcol <= irow);
140  if (IsValid(comps_[irow][jcol])) {
141  return GetRawPtr(comps_[irow][jcol]);
142  }
143  else if (IsValid(const_comps_[irow][jcol])) {
144  return GetRawPtr(const_comps_[irow][jcol]);
145  }
146 
147  return NULL;
148  }
149 
151  Matrix* Comp(Index irow, Index jcol)
152  {
153  DBG_ASSERT(irow < NComps_Dim());
154  DBG_ASSERT(jcol <= irow);
155  // We shouldn't be asking for a non-const if this entry holds a
156  // const one...
157  DBG_ASSERT(IsNull(const_comps_[irow][jcol]));
158  if (IsValid(comps_[irow][jcol])) {
159  return GetRawPtr(comps_[irow][jcol]);
160  }
161 
162  return NULL;
163  }
164  };
165 
172  {
173  public:
179  CompoundSymMatrixSpace(Index ncomp_spaces, Index total_dim);
180 
183  {}
185 
189  void SetBlockDim(Index irow_jcol, Index dim);
190 
192  Index GetBlockDim(Index irow_jcol) const;
193 
200  void SetCompSpace(Index irow, Index jcol,
201  const MatrixSpace& mat_space,
202  bool auto_allocate = false);
204 
209  {
211  DBG_ASSERT(jcol<=irow);
212  return comp_spaces_[irow][jcol];
213  }
214 
218  {
219  return ncomp_spaces_;
220  }
222 
225 
228  virtual SymMatrix* MakeNewSymMatrix() const
229  {
230  return MakeNewCompoundSymMatrix();
231  }
232 
233  private:
244 
247 
251 
254 
259  std::vector<Index> block_dim_;
260 
263  std::vector<std::vector<SmartPtr<const MatrixSpace> > > comp_spaces_;
264 
267  std::vector<std::vector< bool > > allocate_block_;
268 
270  mutable bool dimensions_set_;
271 
273  bool DimensionsSet() const;
274  };
275 
276  inline
278  {
280  }
281 
282 } // namespace Ipopt
283 #endif