00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "Ifpack_ConfigDefs.h"
00044 #include "Ifpack_TriDiContainer.h"
00045 #include "Epetra_RowMatrix.h"
00046
00047
00048 int Ifpack_TriDiContainer::NumRows() const
00049 {
00050 return(NumRows_);
00051 }
00052
00053
00054 int Ifpack_TriDiContainer::Initialize()
00055 {
00056
00057 IsInitialized_ = false;
00058
00059 IFPACK_CHK_ERR(LHS_.Reshape(NumRows_,NumVectors_));
00060 IFPACK_CHK_ERR(RHS_.Reshape(NumRows_,NumVectors_));
00061 IFPACK_CHK_ERR(ID_.Reshape(NumRows_,NumVectors_));
00062 IFPACK_CHK_ERR(Matrix_.Reshape(NumRows_,NumRows_));
00063
00064
00065
00066
00067
00068
00069 if(Matrix_.A() == NULL ) Matrix_.Shape(NumRows_);
00070 int size = (NumRows_ == 1) ? 1 : 4*(NumRows_ -1);
00071 memset(Matrix_.A(),0,sizeof(double)*size);
00072
00073
00074 for (int i = 0 ; i < NumRows_ ; ++i)
00075 for (int j = 0 ; j < NumVectors_ ; ++j) {
00076 LHS_(i,j) = 0.0;
00077 RHS_(i,j) = 0.0;
00078 }
00079
00080
00081 for (int i = 0 ; i < NumRows_ ; ++i)
00082 ID_(i) = -1;
00083
00084 if (NumRows_ != 0) {
00085 IFPACK_CHK_ERR(Solver_.SetMatrix(Matrix_));
00086 IFPACK_CHK_ERR(Solver_.SetVectors(LHS_,RHS_));
00087 }
00088
00089 IsInitialized_ = true;
00090 return(0);
00091
00092 }
00093
00094
00095 double& Ifpack_TriDiContainer::LHS(const int i, const int Vector)
00096 {
00097 return(LHS_.A()[Vector * NumRows_ + i]);
00098 }
00099
00100
00101 double& Ifpack_TriDiContainer::RHS(const int i, const int Vector)
00102 {
00103 return(RHS_.A()[Vector * NumRows_ + i]);
00104 }
00105
00106
00107 int Ifpack_TriDiContainer::
00108 SetMatrixElement(const int row, const int col, const double value)
00109 {
00110 if (IsInitialized() == false)
00111 IFPACK_CHK_ERR(Initialize());
00112
00113 if ((row < 0) || (row >= NumRows())) {
00114 IFPACK_CHK_ERR(-2);
00115 }
00116
00117 if ((col < 0) || (col >= NumRows())) {
00118 IFPACK_CHK_ERR(-2);
00119 }
00120
00121 Matrix_(row, col) = value;
00122
00123 return(0);
00124
00125 }
00126
00127
00128 int Ifpack_TriDiContainer::ApplyInverse()
00129 {
00130
00131 if (!IsComputed()) {
00132 IFPACK_CHK_ERR(-1);
00133 }
00134
00135 if (NumRows_ != 0)
00136 IFPACK_CHK_ERR(Solver_.Solve());
00137
00138 #ifdef IFPACK_FLOPCOUNTERS
00139 ApplyInverseFlops_ += 2.0 * NumVectors_ * NumRows_ * NumRows_;
00140 #endif
00141 return(0);
00142 }
00143
00144
00145 int& Ifpack_TriDiContainer::ID(const int i)
00146 {
00147 return(ID_[i]);
00148 }
00149
00150
00151
00152 int Ifpack_TriDiContainer::Extract(const Epetra_RowMatrix& Matrix_in)
00153 {
00154
00155 for (int j = 0 ; j < NumRows_ ; ++j) {
00156
00157 if (ID(j) == -1)
00158 IFPACK_CHK_ERR(-2);
00159
00160 if (ID(j) > Matrix_in.NumMyRows())
00161 IFPACK_CHK_ERR(-2);
00162 }
00163
00164
00165 int Length = Matrix_in.MaxNumEntries();
00166 std::vector<double> Values;
00167 Values.resize(Length);
00168 std::vector<int> Indices;
00169 Indices.resize(Length);
00170
00171 for (int j = 0 ; j < NumRows_ ; ++j) {
00172
00173 int LRID = ID(j);
00174
00175 int NumEntries;
00176
00177 int ierr =
00178 Matrix_in.ExtractMyRowCopy(LRID, Length, NumEntries,
00179 &Values[0], &Indices[0]);
00180 IFPACK_CHK_ERR(ierr);
00181
00182 for (int k = 0 ; k < NumEntries ; ++k) {
00183
00184 int LCID = Indices[k];
00185
00186
00187 if (LCID >= Matrix_in.NumMyRows())
00188 continue;
00189
00190
00191
00192
00193 int jj = -1;
00194 for (int kk = 0 ; kk < NumRows_ ; ++kk)
00195 if (ID(kk) == LCID)
00196 jj = kk;
00197
00198 if (jj != -1)
00199 SetMatrixElement(j,jj,Values[k]);
00200
00201 }
00202 }
00203
00204 return(0);
00205 }
00206
00207
00208 int Ifpack_TriDiContainer::Compute(const Epetra_RowMatrix& Matrix_in)
00209 {
00210 IsComputed_ = false;
00211 if (IsInitialized() == false) {
00212 IFPACK_CHK_ERR(Initialize());
00213 }
00214
00215 if (KeepNonFactoredMatrix_)
00216 NonFactoredMatrix_ = Matrix_;
00217
00218
00219 IFPACK_CHK_ERR(Extract(Matrix_in));
00220
00221 if (KeepNonFactoredMatrix_)
00222 NonFactoredMatrix_ = Matrix_;
00223
00224
00225 if (NumRows_ != 0)
00226 IFPACK_CHK_ERR(Solver_.Factor());
00227
00228 Label_ = "Ifpack_TriDiContainer";
00229
00230
00231 #ifdef IFPACK_FLOPCOUNTERS
00232 ComputeFlops_ += 4.0 * NumRows_ * NumRows_ * NumRows_ / 3;
00233 #endif
00234 IsComputed_ = true;
00235
00236 return(0);
00237 }
00238
00239
00240 int Ifpack_TriDiContainer::Apply()
00241 {
00242 IFPACK_CHK_ERR(-300);
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 return(0);
00256 }
00257
00258
00259 ostream& Ifpack_TriDiContainer::Print(ostream & os) const
00260 {
00261 os << "================================================================================" << endl;
00262 os << "Ifpack_TriDiContainer" << endl;
00263 os << "Number of rows = " << NumRows() << endl;
00264 os << "Number of vectors = " << NumVectors() << endl;
00265 os << "IsInitialized() = " << IsInitialized() << endl;
00266 os << "IsComputed() = " << IsComputed() << endl;
00267 #ifdef IFPACK_FLOPCOUNTERS
00268 os << "Flops in Compute() = " << ComputeFlops() << endl;
00269 os << "Flops in ApplyInverse() = " << ApplyInverseFlops() << endl;
00270 #endif
00271 os << "================================================================================" << endl;
00272 os << endl;
00273
00274 return(os);
00275 }