44 #include "Epetra_Util.h" 48 : Epetra_CompObject(),
49 Epetra_Object(-1,
false),
56 if (set_object_label) {
57 SetLabel(
"Epetra::SerialTriDiMatrix");
63 bool set_object_label)
64 : Epetra_CompObject(),
65 Epetra_Object(-1,
false),
72 if (set_object_label) {
73 SetLabel(
"Epetra::SerialTriDiMatrix");
76 throw ReportError(
"NumRows = " +
toString(NumRowCol) +
". Should be >= 0", -1);
78 int errorcode =
Shape(NumRowCol);
80 throw ReportError(
"Shape returned non-zero value", errorcode);
86 bool set_object_label)
87 : Epetra_CompObject(),
88 Epetra_Object(-1,
false),
95 if (set_object_label) {
96 SetLabel(
"Epetra::SerialTriDiMatrix");
99 throw ReportError(
"Null pointer passed as A parameter.", -3);
101 throw ReportError(
"NumRowCol = " +
toString(NumRowCol) +
". Should be >= 0", -1);
104 const int newsize = (
N_ == 1) ? 1 : 4*(
N_-1);
106 A_ =
new double[newsize];
121 : Epetra_CompObject(Source),
128 SetLabel(Source.
Label());
130 const int newsize = (
N_ == 1)? 1 : 4*(
N_-1);
132 A_ =
new double[newsize];
148 if(NumRows < 0 || NumCols < 0)
150 if(NumRows != NumCols)
154 const int newsize = (
N_ == 1)? 1 : 4*(
N_-1);
157 A_tmp =
new double[newsize];
158 for (
int k = 0; k < newsize; k++)
180 if(NumRowCol < 0 || NumRowCol < 0)
186 const int newsize = (
N_ == 1)? 1 : 4*(
N_-1);
188 A_ =
new double[newsize];
189 for (
int k = 0; k < newsize; k++)
221 if((
CV_ == View) && (Source.
CV_ == View) && (
A_ == Source.
A_))
225 throw ReportError(
"operator= type mismatch (lhs = " + std::string(
Label()) +
226 ", rhs = " + std::string(Source.
Label()) +
").", -5);
228 if(Source.
CV_ == View) {
244 const int newsize = 4*
N_ - 4;
246 A_ =
new double[newsize];
260 if(Source.
N_ ==
N_) {
266 const int newsize = (
N_ == 1)? 1 : 4*(
N_-1);
268 A_ =
new double[newsize];
287 if (
N_ != rhs.
N_)
return(
false);
289 const double* A_tmp =
A_;
290 const double* rhsA = rhs.
A_;
292 const int size = (
N_ == 1)? 1 : 4*(
N_-1);
294 for(
int j=0; j<size; ++j) {
295 if (std::abs(A_tmp[j] - rhsA[j]) > Epetra_MinDouble) {
305 if (
N() != Source.
N())
306 throw ReportError(
"Column dimension of source = " +
toString(Source.
N()) +
307 " is different than column dimension of target = " +
toString(
N()), -2);
319 int lmax = EPETRA_MIN(nrowcol,tN);
322 for(
int j=0; j<lmax; ++j) {
323 Target[(tN-1)+j] += Source[(nrowcol-1)+j];
325 Target[j] += Source[j];
326 Target[(tN-1)+tN + j] += Source[(nrowcol-1)+ nrowcol + j];
328 if(j<tN-2) Target[(tN-1)*2 + tN + j] += Source[ (nrowcol-1)*2 +nrowcol + j];
332 for(
int j=0; j<lmax; ++j) {
333 Target[(tN-1)+j] = Source[(nrowcol-1)+j];
335 Target[j] = Source[j];
336 Target[(tN-1)+tN + j] = Source[(nrowcol-1)+ nrowcol + j];
338 if(j<tN-2) Target[(tN-1)*2 + tN + j] = Source[ (nrowcol-1)*2 +nrowcol + j];
350 const int size = (
N_ == 1)? 1 : 4*(
N_-1);
352 for (i=0; i<size; i++) sum += std::abs(*ptr++);
354 anorm = EPETRA_MAX(anorm, sum);
355 UpdateFlops((
double)size );
370 const int size = (
N_ == 1)? 1 : 4*(
N_-1);
372 for (i=0; i<size ; i++) { *ptr = ScalarA * (*ptr); ptr++; }
374 UpdateFlops((
double)
N_*(
double)
N_);
383 double ScalarThis ) {
384 throw ReportError(
"Ifpack_SerialTriDiMatrix::Multiply not implimented ",-2);
394 double* arrayPtr =
A_;
395 const int size = (
N_ == 1)? 1 : 4*(
N_-1);
396 for(
int j = 0; j < size ; j++) {
397 *arrayPtr++ = util.RandomDouble();
404 os <<
" square format:"<<std::endl;
406 os <<
" empty matrix "<<std::endl;
409 for(
int i=0 ; i <
N_ ; ++i) {
410 for(
int j=0 ; j <
N_ ; ++j) {
411 if ( j >= i-1 && j <= i+1) {
412 os << (*this)(i,j)<<
" ";
int Shape(int NumRowCol)
Set dimensions of a Ifpack_SerialTriDiMatrix object; init values to zero.
int N() const
Returns column dimension of system.
void CopyMat(const double *Source, int NumRowCol, double *Target, int NRC2, bool add=false)
virtual double NormInf() const
Computes the Infinity-Norm of the this matrix.
std::string toString(const int &x)
double * A() const
Returns pointer to the this matrix.
virtual void Print(std::ostream &os) const
Print service methods; defines behavior of ostream << operator.
Ifpack_SerialTriDiMatrix & operator+=(const Ifpack_SerialTriDiMatrix &Source)
Add one matrix to another.
virtual double NormOne() const
Computes the 1-Norm of the this matrix.
Ifpack_SerialTriDiMatrix: A class for constructing and using real double precision general TriDi matr...
Ifpack_SerialTriDiMatrix & operator=(const Ifpack_SerialTriDiMatrix &Source)
Value copy from one matrix to another.
int Random()
Column access function.
int Scale(double ScalarA)
Matrix-Vector multiplication, y = A*x, where 'this' == A.
Ifpack_SerialTriDiMatrix(bool set_object_label=true)
Default constructor; defines a zero size object.
virtual const char * Label() const
Returns a character string describing the operator.
virtual ~Ifpack_SerialTriDiMatrix()
Ifpack_SerialTriDiMatrix destructor.
bool operator==(const Ifpack_SerialTriDiMatrix &rhs) const
Comparison operator.
int Multiply(char TransA, char TransB, double ScalarAB, const Ifpack_SerialTriDiMatrix &A, const Ifpack_SerialTriDiMatrix &B, double ScalarThis)
Matrix-Matrix multiplication, this = ScalarThis*this + ScalarAB*A*B.