00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TDecompSparse
00013 #define ROOT_TDecompSparse
00014
00015
00016
00017
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
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
00040
00041
00042
00043
00044 const Double_t kThresholdPivotingMax = 1.0e-2;
00045
00046
00047
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];
00058 Double_t fCntl[6];
00059 Int_t fInfo[21];
00060
00061 Double_t fPrecision;
00062
00063
00064
00065 TArrayI fIkeep;
00066 TArrayI fIw;
00067 TArrayI fIw1;
00068 TArrayI fIw2;
00069 Int_t fNsteps;
00070 Int_t fMaxfrt;
00071 TArrayD fW;
00072
00073 Double_t fIPessimism;
00074 Double_t fRPessimism;
00075
00076
00077 TMatrixDSparse fA;
00078 Int_t fNrows;
00079 Int_t fNnonZeros;
00080 TArrayD fFact;
00081
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
00135
00136
00137
00138 inline Double_t GetThresholdPivoting() { return fCntl[1]; }
00139 inline Double_t GetTreatAsZero () { return fCntl[3]; }
00140
00141
00142
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 & )
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 & )
00175 { MayNotUse("TransSolve(TMatrixDColumn &)"); return kFALSE; }
00176
00177 virtual void Det (Double_t &,Double_t &)
00178 { MayNotUse("Det(Double_t&,Double_t&)"); }
00179
00180 void Print(Option_t *opt ="") const;
00181
00182 TDecompSparse &operator= (const TDecompSparse &source);
00183
00184 ClassDef(TDecompSparse,1)
00185 };
00186
00187 #endif