Epetra Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Epetra_SerialDenseSVD.h
Go to the documentation of this file.
1 /*
2 //@HEADER
3 // ************************************************************************
4 //
5 // Epetra: Linear Algebra Services Package
6 // Copyright 2011 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ************************************************************************
41 //@HEADER
42 */
43 
44 #ifndef _EPETRA_SERIALDENSESVD_H_
45 #define _EPETRA_SERIALDENSESVD_H_
46 
47 #if defined(Epetra_SHOW_DEPRECATED_WARNINGS)
48 #ifdef __GNUC__
49 #warning "The Epetra package is deprecated"
50 #endif
51 #endif
52 
53 
54 
57 #include "Epetra_Object.h"
58 #include "Epetra_CompObject.h"
59 #include "Epetra_BLAS.h"
60 #include "Epetra_LAPACK.h"
61 
62 
64 
122 //=========================================================================
123 class EPETRA_LIB_DLL_EXPORT Epetra_SerialDenseSVD : public virtual Epetra_SerialDenseOperator, public Epetra_CompObject, public virtual Epetra_Object, public Epetra_BLAS, public Epetra_LAPACK{
124  public:
125 
127 
130 
132  virtual ~Epetra_SerialDenseSVD();
134 
136 
137 
139  int SetMatrix(Epetra_SerialDenseMatrix & A);
140 
142 
145  int SetVectors(Epetra_SerialDenseMatrix & X, Epetra_SerialDenseMatrix & B);
147 
149 
150 
152 
154 // void FactorWithEquilibration(bool Flag) {Equilibrate_ = Flag; return;};
155 
157  void SolveWithTranspose(bool Flag) {Transpose_ = Flag; if (Flag) TRANS_ = 'T'; else TRANS_ = 'N'; return;};
158 
160 // void SolveToRefinedSolution(bool Flag) {RefineSolution_ = Flag; return;};
161 
162  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
163  // Causes all solves to estimate the forward and backward solution error.
164  /* Error estimates will be in the arrays FERR and BERR, resp, after the solve step is complete.
165  These arrays are accessible via the FERR() and BERR() access functions.
166  */
167 // void EstimateSolutionErrors(bool Flag) {EstimateSolutionErrors_ = Flag; return;};
169 
171 
172 
173  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
174  // Computes the SVD factorization of the matrix using the LAPACK routine \e DGESVD.
175  /*
176  \return Integer error code, set to 0 if successful.
177  */
178 // virtual int Factor(void);
179  virtual int Factor(void);
180 
182 
185  virtual int Solve(void);
186 
188 
191  virtual int Invert( double rthresh = 0.0, double athresh = 0.0 );
192 
193  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
194  // Computes the scaling vector S(i) = 1/sqrt(A(i,i) of the \e this matrix.
195  /*
196  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
197  */
198 // virtual int ComputeEquilibrateScaling(void);
199 
200  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
201  // Equilibrates the \e this matrix.
202  /*
203  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
204  */
205 // virtual int EquilibrateMatrix(void);
206 
207  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
208  // Equilibrates the current RHS.
209  /*
210  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
211  */
212 // int EquilibrateRHS(void);
213 
214 
215  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
216  // Apply Iterative Refinement.
217  /*
218  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
219  */
220 // virtual int ApplyRefinement(void);
221 
222  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
223  // Unscales the solution vectors if equilibration was used to solve the system.
224  /*
225  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
226  */
227 // int UnequilibrateLHS(void);
228 
229  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
230  // Returns the reciprocal of the 1-norm condition number of the \e this matrix.
231  /*
232  \param Value Out
233  On return contains the reciprocal of the 1-norm condition number of the \e this matrix.
234 
235  \return Integer error code, set to 0 if successful. Otherwise returns the LAPACK error code INFO.
236  */
237 // virtual int ReciprocalConditionEstimate(double & Value);
239 
241 
242 
244  bool Transpose() {return(Transpose_);};
245 
247  bool Factored() {return(Factored_);};
248 
249  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
250  // Returns true if factor is equilibrated (factor available via AF() and LDAF()).
251 // bool A_Equilibrated() {return(A_Equilibrated_);};
252 
253  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
254  // Returns true if RHS is equilibrated (RHS available via B() and LDB()).
255 // bool B_Equilibrated() {return(B_Equilibrated_);};
256 
257  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
258  // Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system.
259 // virtual bool ShouldEquilibrate() {ComputeEquilibrateScaling(); return(ShouldEquilibrate_);};
260 
261  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
262  // Returns true if forward and backward error estimated have been computed (available via FERR() and BERR()).
263 // bool SolutionErrorsEstimated() {return(SolutionErrorsEstimated_);};
264 
266  bool Inverted() {return(Inverted_);};
267 
268  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
269  // Returns true if the condition number of the \e this matrix has been computed (value available via ReciprocalConditionEstimate()).
270 // bool ReciprocalConditionEstimated() {return(ReciprocalConditionEstimated_);};
271 
273  bool Solved() {return(Solved_);};
274 
275  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
276  // Returns true if the current set of vectors has been refined.
277 // bool SolutionRefined() {return(SolutionRefined_);};
279 
281 
282 
284  Epetra_SerialDenseMatrix * Matrix() const {return(Matrix_);};
285 
286  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
287  // Returns pointer to factored matrix (assuming factorization has been performed).
288 // Epetra_SerialDenseMatrix * FactoredMatrix() const {return(Factor_);};
289 
291  Epetra_SerialDenseMatrix * InvertedMatrix() const {return(Inverse_);};
292 
294  Epetra_SerialDenseMatrix * LHS() const {return(LHS_);};
295 
297  Epetra_SerialDenseMatrix * RHS() const {return(RHS_);};
298 
300  int M() const {return(M_);};
301 
303  int N() const {return(N_);};
304 
306  double * A() const {return(A_);};
307 
309  int LDA() const {return(LDA_);};
310 
312  double * B() const {return(B_);};
313 
315  int LDB() const {return(LDB_);};
316 
318  int NRHS() const {return(NRHS_);};
319 
321  double * X() const {return(X_);};
322 
324  int LDX() const {return(LDX_);};
325 
326  double * S() const {return(S_);};
327 
328  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
329  // Returns pointer to the factored matrix (may be the same as A() if factorization done in place).
330 // double * AF() const {return(AF_);};
331 
332  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
333  // Returns the leading dimension of the factored matrix.
334 // int LDAF() const {return(LDAF_);};
335 
337  double * AI() const {return(AI_);};
338 
340  int LDAI() const {return(LDAI_);};
341 
342  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
343  // Returns pointer to pivot vector (if factorization has been computed), zero otherwise.
344 // int * IPIV() const {return(IPIV_);};
345 
347  double ANORM() const {return(ANORM_);};
348 
349  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
350  // Returns the reciprocal of the condition number of the \e this matrix (returns -1 if not yet computed).
351 // double RCOND() const {return(RCOND_);};
352 
353  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
354  // Ratio of smallest to largest row scale factors for the \e this matrix (returns -1 if not yet computed).
355  /* If ROWCND() is >= 0.1 and AMAX() is not close to overflow or underflow, then equilibration is not needed.
356  */
357 // double ROWCND() const {return(ROWCND_);};
358 
359  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
360  // Ratio of smallest to largest column scale factors for the \e this matrix (returns -1 if not yet computed).
361  /* If COLCND() is >= 0.1 then equilibration is not needed.
362  */
363 // double COLCND() const {return(COLCND_);};
364 
365  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
366  // Returns the absolute value of the largest entry of the \e this matrix (returns -1 if not yet computed).
367 // double AMAX() const {return(AMAX_);};
368 
369  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
370  // Returns a pointer to the forward error estimates computed by LAPACK.
371 // double * FERR() const {return(FERR_);};
372 
373  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
374  // Returns a pointer to the backward error estimates computed by LAPACK.
375 // double * BERR() const {return(BERR_);};
376 
377  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
378  // Returns a pointer to the row scaling vector used for equilibration.
379 // double * R() const {return(R_);};
380 
381  // NOTE: doxygen-style documentation needs to be re-enabled if this function is re-enabled
382  // Returns a pointer to the column scale vector used for equilibration.
383 // double * C() const {return(C_);};
385 
387 
388  virtual void Print(std::ostream& os) const;
391 
393 
394 
396 
405  virtual int SetUseTranspose(bool use_transpose) { UseTranspose_ = use_transpose; return (0); }
406 
408 
417  { return Ymat.Multiply( UseTranspose_, false, 1.0, *Matrix(), Xmat, 0.0 ); }
418 
420 
430  { SetVectors(const_cast<Epetra_SerialDenseMatrix&>(Xmat),Ymat);
431  SolveWithTranspose(UseTranspose_);
432  return Solve(); }
433 
435  /* Returns the quantity \f$ \| A \|_\infty\f$ such that
436  \f[\| A \|_\infty = \max_{1\lei\lem} \sum_{j=1}^n |a_{ij}| \f].
437 
438  \warning This method must not be called unless HasNormInf() returns true.
439  */
440  virtual double NormInf() const { return Matrix()->NormInf(); }
441 
443  virtual const char * Label() const { return Epetra_Object::Label(); }
444 
446  virtual bool UseTranspose() const { return UseTranspose_; }
447 
449  virtual bool HasNormInf() const { return true; }
450 
452  virtual int RowDim() const { return M(); }
453 
455  virtual int ColDim() const { return N(); }
456 
458 
459  void AllocateWORK() {if (WORK_==0) {LWORK_ = 4*N_; WORK_ = new double[LWORK_];} return;};
460  void AllocateIWORK() {if (IWORK_==0) IWORK_ = new int[N_]; return;};
461  void InitPointers();
462  void DeleteArrays();
463  void ResetMatrix();
464  void ResetVectors();
465 
466 
467 // bool Equilibrate_;
468 // bool ShouldEquilibrate_;
469 // bool A_Equilibrated_;
470 // bool B_Equilibrated_;
472  bool Factored_;
473 // bool EstimateSolutionErrors_;
474 // bool SolutionErrorsEstimated_;
475  bool Solved_;
476  bool Inverted_;
477 // bool ReciprocalConditionEstimated_;
478 // bool RefineSolution_;
479 // bool SolutionRefined_;
480 
481  char TRANS_;
482 
483  int M_;
484  int N_;
485  int Min_MN_;
486  int NRHS_;
487  int LDA_;
488 // int LDAF_;
489  int LDAI_;
490  int LDB_;
491  int LDX_;
492  int INFO_;
493  int LWORK_;
494 
495 // int * IPIV_;
496  int * IWORK_;
497 
498  double ANORM_;
499 // double RCOND_;
500 // double ROWCND_;
501 // double COLCND_;
502 // double AMAX_;
503 
507 // Epetra_SerialDenseMatrix * Factor_;
509 
510  double * A_;
511 // double * FERR_;
512 // double * BERR_;
513 // double * AF_;
514  double * AI_;
515  double * WORK_;
516 // double * R_;
517 // double * C_;
518  double * U_;
519  double * S_;
520  double * Vt_;
521 
522  double * B_;
523  double * X_;
524 
526 
527  private:
528  // Epetra_SerialDenseSolver copy constructor (put here because we don't want user access)
529 
532 };
533 
534 #endif /* _EPETRA_SERIALDENSESVD_H_ */
double * B() const
Returns pointer to current RHS.
virtual void Print(std::ostream &os) const
Print object to an output stream Print method.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
double * A() const
Returns pointer to the this matrix.
Epetra_SerialDenseMatrix * Inverse_
Epetra_SerialDenseMatrix * LHS() const
Returns pointer to current LHS.
Epetra_SerialDenseSVD: A class for SVDing dense linear problems.
double * X() const
Returns pointer to current solution.
Epetra_CompObject & operator=(const Epetra_CompObject &src)
Epetra_SerialDenseMatrix: A class for constructing and using real double precision general dense matr...
double * AI() const
Returns pointer to the inverted matrix (may be the same as A() if factorization done in place)...
int NRHS() const
Returns the number of current right hand sides and solution vectors.
bool Solved()
Returns true if the current set of vectors has been solved.
Epetra_SerialDenseMatrix * Matrix_
virtual int RowDim() const
Returns the row dimension of operator.
int N() const
Returns column dimension of system.
double ANORM() const
Returns the 1-Norm of the this matrix (returns -1 if not yet computed).
int LDA() const
Returns the leading dimension of the this matrix.
Epetra_SerialDenseMatrix * RHS() const
Returns pointer to current RHS.
Epetra_SerialDenseMatrix * InvertedMatrix() const
Returns pointer to inverted matrix (assuming inverse has been performed).
Epetra_BLAS: The Epetra BLAS Wrapper Class.
Definition: Epetra_BLAS.h:78
virtual const char * Label() const
Epetra_Object Label access funtion.
Epetra_Object: The base Epetra class.
Definition: Epetra_Object.h:65
Epetra_SerialDenseMatrix * RHS_
Epetra_CompObject: Functionality and data that is common to all computational classes.
virtual const char * Label() const
Returns a character string describing the operator.
Epetra_LAPACK: The Epetra LAPACK Wrapper Class.
Definition: Epetra_LAPACK.h:75
Epetra_SerialDenseOperator: A pure virtual class for using real-valued double-precision operators...
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
int Multiply(char TransA, char TransB, double ScalarAB, const Epetra_SerialDenseMatrix &A, const Epetra_SerialDenseMatrix &B, double ScalarThis)
Matrix-Matrix multiplication, this = ScalarThis*this + ScalarAB*A*B.
int LDX() const
Returns the leading dimension of the solution.
bool Inverted()
Returns true if matrix inverse has been computed (inverse available via AF() and LDAF()).
virtual int ApplyInverse(const Epetra_SerialDenseMatrix &Xmat, Epetra_SerialDenseMatrix &Ymat)
Returns the result of a Epetra_SerialDenseOperator inverse applied to an Epetra_SerialDenseMatrix X i...
Epetra_SerialDenseMatrix * Matrix() const
Returns pointer to current matrix.
virtual int Apply(const Epetra_SerialDenseMatrix &Xmat, Epetra_SerialDenseMatrix &Ymat)
Returns the result of a Epetra_SerialDenseOperator applied to a Epetra_SerialDenseMatrix X in Y...
int Solve(int, TYPE *, TYPE *, TYPE *)
void SolveWithTranspose(bool Flag)
Causes equilibration to be called just before the matrix factorization as part of the call to Factor...
virtual int ColDim() const
Returns the column dimension of operator.
bool Transpose()
Returns true if transpose of this matrix has and will be used.
virtual double NormInf() const
Returns the infinity norm of the global matrix.
int LDAI() const
Returns the leading dimension of the inverted matrix.
Epetra_SerialDenseMatrix * LHS_
int M() const
Returns row dimension of system.
virtual int SetUseTranspose(bool use_transpose)
If set true, transpose of this operator will be applied.
bool Factored()
Returns true if matrix is factored (factor available via AF() and LDAF()).
int LDB() const
Returns the leading dimension of the RHS.