TDecompSparse.h

Go to the documentation of this file.
00001 // @(#)root/matrix:$Id: TDecompSparse.h 20882 2007-11-19 11:31:26Z rdm $
00002 // Authors: Fons Rademakers, Eddy Offermann   Apr 2004
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TDecompSparse
00013 #define ROOT_TDecompSparse
00014 
00015 ///////////////////////////////////////////////////////////////////////////
00016 //                                                                       //
00017 // Sparse Decomposition class                                            //
00018 //                                                                       //
00019 ///////////////////////////////////////////////////////////////////////////
00020 
00021 #ifndef ROOT_TDecompBase
00022 #include "TDecompBase.h"
00023 #endif
00024 #ifndef ROOT_TMatrixDSparse
00025 #include "TMatrixDSparse.h"
00026 #endif    
00027 #ifndef ROOT_TArrayD
00028 #include "TArrayD.h"
00029 #endif
00030 #ifndef ROOT_TArrayI
00031 #include "TArrayI.h"
00032 #endif
00033 
00034 // globals
00035 const Double_t kInitTreatAsZero         = 1.0e-12;
00036 const Double_t kInitThresholdPivoting   = 1.0e-8;
00037 const Double_t kInitPrecision           = 1.0e-7;
00038 
00039 // the Threshold Pivoting parameter may need to be increased during
00040 // the algorithm if poor precision is obtained from the linear
00041 // solves.  kThresholdPivoting indicates the largest value we are
00042 // willing to tolerate.
00043 
00044 const Double_t kThresholdPivotingMax    = 1.0e-2;
00045 
00046 // the factor in the range (1,inf) by which kThresholdPivoting is
00047 // increased when it is found to be inadequate.
00048 
00049 const Double_t kThresholdPivotingFactor = 10.0;
00050 
00051 class TDecompSparse : public TDecompBase
00052 {
00053 protected :
00054 
00055    Int_t     fVerbose;
00056 
00057    Int_t     fIcntl[31]; // integer control numbers
00058    Double_t  fCntl[6];   // float control numbers
00059    Int_t     fInfo[21];  // array used for communication between programs
00060 
00061    Double_t  fPrecision; // precision we demand from the linear system solver. If it isn't
00062                          // attained on the first solve, we use iterative refinement and
00063                          // possibly refactorization with a higher value of kThresholdPivoting.
00064 
00065    TArrayI   fIkeep;     // pivot sequence and temporary storage information
00066    TArrayI   fIw;
00067    TArrayI   fIw1;
00068    TArrayI   fIw2;
00069    Int_t     fNsteps;
00070    Int_t     fMaxfrt;
00071    TArrayD   fW;         // temporary storage for the factorization
00072 
00073    Double_t  fIPessimism; // amounts by which to increase allocated factorization space when
00074    Double_t  fRPessimism; // inadequate space is detected. fIPessimism is for array "fIw",
00075                           // fRPessimism is for the array "fact".
00076 
00077    TMatrixDSparse fA; // original matrix; needed for the iterative solving procedure
00078    Int_t          fNrows;
00079    Int_t          fNnonZeros;
00080    TArrayD        fFact; // size of fFact array; may be increased during the numerical factorization
00081                          // if the estimate obtained during the symbolic factorization proves to be inadequate.
00082    TArrayI        fRowFact;
00083    TArrayI        fColFact;
00084 
00085    static Int_t NonZerosUpperTriang(const TMatrixDSparse &a);
00086    static void  CopyUpperTriang    (const TMatrixDSparse &a,Double_t *b);
00087 
00088           void  InitParam();
00089    static void  InitPivot (const Int_t n,const Int_t nz,TArrayI &Airn,TArrayI &Aicn,
00090                            TArrayI &Aiw,TArrayI &Aikeep,TArrayI &Aiw1,Int_t &nsteps,
00091                            const Int_t iflag,Int_t *icntl,Double_t *cntl,Int_t *info,Double_t &ops);
00092    static void   Factor   (const Int_t n,const Int_t nz,TArrayI &Airn,TArrayI &Aicn,TArrayD &Aa,
00093                            TArrayI &Aiw,TArrayI &Aikeep,const Int_t nsteps,Int_t &maxfrt,
00094                            TArrayI &Aiw1,Int_t *icntl,Double_t *cntl,Int_t *info);
00095    static void   Solve    (const Int_t n,TArrayD &Aa,TArrayI &Aiw,TArrayD &Aw,const Int_t maxfrt,
00096                            TVectorD &b,TArrayI &Aiw1,const Int_t nsteps,Int_t *icntl,Int_t *info);
00097  
00098    static void   InitPivot_sub1 (const Int_t n,const Int_t nz,Int_t *irn,Int_t *icn,Int_t *iw,Int_t *ipe,
00099                                  Int_t *iq,Int_t *flag,Int_t &iwfr,Int_t *icntl,Int_t *info);
00100    static void   InitPivot_sub2 (const Int_t n,Int_t *ipe,Int_t *iw,const Int_t lw,Int_t &iwfr,Int_t *nv,
00101                                  Int_t *nxt,Int_t *lst,Int_t *ipd,Int_t *flag,const Int_t iovflo,Int_t &ncmpa,
00102                                  const Double_t fratio);
00103    static void   InitPivot_sub2a(const Int_t n,Int_t *ipe,Int_t *iw,const Int_t lw,Int_t &iwfr,Int_t &ncmpa);
00104    static void   InitPivot_sub3 (const Int_t n,const Int_t nz,Int_t *irn,Int_t *icn,Int_t *perm,Int_t *iw,
00105                                  Int_t *ipe,Int_t *iq,Int_t *flag,Int_t &iwfr,Int_t *icntl,Int_t *info);
00106    static void   InitPivot_sub4 (const Int_t n,Int_t *ipe,Int_t *iw,const Int_t lw,Int_t &iwfr,Int_t *ips,
00107                                  Int_t *ipv,Int_t *nv,Int_t *flag,Int_t &ncmpa);
00108    static void   InitPivot_sub5 (const Int_t n,Int_t *ipe,Int_t *nv,Int_t *ips,Int_t *ne,Int_t *na,Int_t *nd,
00109                                  Int_t &nsteps,const Int_t nemin);
00110    static void   InitPivot_sub6 (const Int_t n,const Int_t nz,Int_t *irn,Int_t *icn,Int_t *perm,Int_t *na,
00111                                  Int_t *ne,Int_t *nd,const Int_t nsteps,Int_t *lstki,Int_t *lstkr,Int_t *iw,
00112                                  Int_t *info,Double_t &ops);
00113 
00114    static void   Factor_sub1    (const Int_t n,const Int_t nz,Int_t &nz1,Double_t *a,const Int_t la,
00115                                  Int_t *irn,Int_t *icn,Int_t *iw,const Int_t liw,Int_t *perm,Int_t *iw2,
00116                                  Int_t *icntl,Int_t *info);
00117    static void   Factor_sub2    (const Int_t n,const Int_t nz,Double_t *a,const Int_t la,Int_t *iw,
00118                                  const Int_t liw,Int_t *perm,Int_t *nstk,const Int_t nsteps,Int_t &maxfrt,
00119                                  Int_t *nelim,Int_t *iw2,Int_t *icntl,Double_t *cntl,Int_t *info);
00120    static void   Factor_sub3    (Double_t *a,Int_t *iw,Int_t &j1,Int_t &j2,const Int_t itop,const Int_t ireal,
00121                                  Int_t &ncmpbr,Int_t &ncmpbi);
00122 
00123    static void   Solve_sub1     (const Int_t n,Double_t *a,Int_t *iw,Double_t *w,Double_t *rhs,Int_t *iw2,
00124                                  const Int_t nblk,Int_t &latop,Int_t *icntl);
00125    static void   Solve_sub2     (const Int_t n,Double_t *a,Int_t *iw,Double_t *w,Double_t *rhs,Int_t *iw2,
00126                                  const Int_t nblk,const Int_t latop,Int_t *icntl);
00127    static Int_t  IDiag          (Int_t ix,Int_t iy) { return ((iy-1)*(2*ix-iy+2))/2; }
00128 
00129    inline Int_t IError          () { return fInfo[2]; }
00130    inline Int_t MinRealWorkspace() { return fInfo[5]; }
00131    inline Int_t MinIntWorkspace () { return fInfo[6]; }
00132    inline Int_t ErrorFlag       () { return fInfo[1]; }
00133 
00134    // Takes values in the range [0,1]. Larger values enforce greater stability in
00135    // the factorization as they insist on larger pivots. Smaller values preserve
00136    // sparsity at the cost of using smaller pivots.
00137 
00138    inline Double_t GetThresholdPivoting() { return fCntl[1]; }
00139    inline Double_t GetTreatAsZero      () { return fCntl[3]; }
00140 
00141    // The factorization will not accept a pivot whose absolute value is less than fCntl[3] as
00142    // a 1x1 pivot or as the off-diagonal in a 2x2 pivot.
00143 
00144    inline void     SetThresholdPivoting(Double_t piv) { fCntl[1] = piv; }
00145    inline void     SetTreatAsZero      (Double_t tol) { fCntl[3] = tol; }
00146 
00147    virtual const TMatrixDBase &GetDecompMatrix() const { MayNotUse("GetDecompMatrix()"); return fA; }
00148 
00149 public :
00150 
00151    TDecompSparse();
00152    TDecompSparse(Int_t nRows,Int_t nr_nonZeros,Int_t verbose);
00153    TDecompSparse(Int_t row_lwb,Int_t row_upb,Int_t nr_nonZeros,Int_t verbose);
00154    TDecompSparse(const TMatrixDSparse &a,Int_t verbose);
00155    TDecompSparse(const TDecompSparse &another);
00156    virtual ~TDecompSparse() {}
00157 
00158    inline  void     SetVerbose (Int_t v) { fVerbose = (v) ? 1 : 0;
00159                                             if (fVerbose) { fIcntl[1] = fIcntl[2] = 1; fIcntl[3] = 2; }
00160                                             else          { fIcntl[1] = fIcntl[2] = fIcntl[3] = 0; }
00161                                          }
00162    virtual Int_t    GetNrows   () const { return fA.GetNrows(); }
00163    virtual Int_t    GetNcols   () const { return fA.GetNcols(); }
00164 
00165    virtual void     SetMatrix  (const TMatrixDSparse &a);
00166 
00167    virtual Bool_t   Decompose  ();
00168    virtual Bool_t   Solve      (      TVectorD &b);
00169    virtual TVectorD Solve      (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = Solve(x); return x; }
00170    virtual Bool_t   Solve      (      TMatrixDColumn & /*b*/)
00171                                { MayNotUse("Solve(TMatrixDColumn &)"); return kFALSE; }
00172    virtual Bool_t   TransSolve (      TVectorD &b)            { return Solve(b); }
00173    virtual TVectorD TransSolve (const TVectorD& b,Bool_t &ok) { TVectorD x = b; ok = Solve(x); return x; }
00174    virtual Bool_t   TransSolve (      TMatrixDColumn & /*b*/)
00175                                { MayNotUse("TransSolve(TMatrixDColumn &)"); return kFALSE; }
00176 
00177    virtual void     Det        (Double_t &/*d1*/,Double_t &/*d2*/)
00178                                 { MayNotUse("Det(Double_t&,Double_t&)"); }
00179 
00180    void Print(Option_t *opt ="") const; // *MENU*
00181 
00182    TDecompSparse &operator= (const TDecompSparse &source);
00183 
00184    ClassDef(TDecompSparse,1) // Matrix Decompositition LU
00185 };
00186 
00187 #endif

Generated on Tue Jul 5 14:26:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1