43 #ifndef IFPACK_SPARSECONTAINER_H 44 #define IFPACK_SPARSECONTAINER_H 47 #include "Epetra_IntSerialDenseVector.h" 48 #include "Epetra_MultiVector.h" 49 #include "Epetra_Vector.h" 50 #include "Epetra_Map.h" 51 #include "Epetra_RowMatrix.h" 52 #include "Epetra_CrsMatrix.h" 53 #include "Epetra_LinearProblem.h" 54 #include "Epetra_IntSerialDenseVector.h" 55 #include "Teuchos_ParameterList.hpp" 56 #include "Teuchos_RefCountPtr.hpp" 58 #include "Epetra_MpiComm.h" 60 #include "Epetra_SerialComm.h" 137 virtual double&
LHS(
const int i,
const int Vector = 0);
140 virtual double&
RHS(
const int i,
const int Vector = 0);
152 virtual int&
ID(
const int i);
205 const Epetra_IntSerialDenseVector&
ID()
const 227 virtual int Compute(
const Epetra_RowMatrix& Matrix_in);
247 return(
Inverse_->InitializeFlops());
271 return(
Inverse_->ApplyInverseFlops());
275 virtual std::ostream&
Print(std::ostream& os)
const;
280 virtual int Extract(
const Epetra_RowMatrix& Matrix_in);
287 Teuchos::RefCountPtr<Epetra_Map>
Map_;
289 Teuchos::RefCountPtr<Epetra_CrsMatrix>
Matrix_;
291 Teuchos::RefCountPtr<Epetra_MultiVector>
LHS_;
293 Teuchos::RefCountPtr<Epetra_MultiVector>
RHS_;
295 Epetra_IntSerialDenseVector
GID_;
315 NumRows_(NumRows_in),
316 NumVectors_(NumVectors_in),
317 IsInitialized_(
false),
334 NumRows_(rhs.NumRows()),
336 IsInitialized_(rhs.IsInitialized()),
337 IsComputed_(rhs.IsComputed())
349 if (!rhs.
Matrix().is_null())
352 if (!rhs.
LHS().is_null())
355 if (!rhs.
RHS().is_null())
370 if (IsInitialized() ==
false)
381 if (IsInitialized_ ==
true)
384 IsInitialized_ =
false;
386 #if !defined(EPETRA_NO_32BIT_GLOBAL_INDICES) || !defined(EPETRA_NO_64BIT_GLOBAL_INDICES) 387 Map_ =
Teuchos::rcp(
new Epetra_Map(NumRows_,0,*SerialComm_) );
390 LHS_ =
Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_) );
391 RHS_ =
Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_) );
392 GID_.Reshape(NumRows_,1);
394 Matrix_ =
Teuchos::rcp(
new Epetra_CrsMatrix(Epetra_DataAccess::Copy,*Map_,0) );
399 if (Inverse_ == Teuchos::null)
408 Label_ =
"Ifpack_SparseContainer";
410 IsInitialized_ =
true;
419 return(((*LHS_)(Vector))->Values()[i]);
426 return(((*RHS_)(Vector))->Values()[i]);
434 if (!IsInitialized())
437 if ((row < 0) || (row >= NumRows())) {
441 if ((col < 0) || (col >= NumRows())) {
445 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES 446 if(Matrix_->RowMatrixRowMap().GlobalIndicesInt()) {
447 int ierr = Matrix_->InsertGlobalValues((
int)row,1,(
double*)&value,(
int*)&col);
449 ierr = Matrix_->SumIntoGlobalValues((
int)row,1,(
double*)&value,(
int*)&col);
456 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES 457 if(Matrix_->RowMatrixRowMap().GlobalIndicesLongLong()) {
458 long long col_LL = col;
459 int ierr = Matrix_->InsertGlobalValues(row,1,(
double*)&value,&col_LL);
461 ierr = Matrix_->SumIntoGlobalValues(row,1,(
double*)&value,&col_LL);
468 throw "Ifpack_SparseContainer<T>::SetMatrixElement: GlobalIndices type unknown";
480 if (!IsInitialized()) {
493 Label_ =
"Ifpack_SparseContainer";
504 if (IsComputed() ==
false) {
510 ApplyFlops_ += 2 * Matrix_->NumGlobalNonzeros64();
531 IsInitialized_ =
false;
558 for (
int j = 0 ; j < NumRows_ ; ++j) {
563 if (
ID(j) > Matrix_in.NumMyRows())
567 int Length = Matrix_in.MaxNumEntries();
568 std::vector<double> Values;
569 Values.resize(Length);
570 std::vector<int> Indices;
571 Indices.resize(Length);
573 for (
int j = 0 ; j < NumRows_ ; ++j) {
580 Matrix_in.ExtractMyRowCopy(LRID, Length, NumEntries,
581 &Values[0], &Indices[0]);
584 for (
int k = 0 ; k < NumEntries ; ++k) {
586 int LCID = Indices[k];
589 if (LCID >= Matrix_in.NumMyRows())
596 for (
int kk = 0 ; kk < NumRows_ ; ++kk)
601 SetMatrixElement(j,jj,Values[k]);
617 os <<
"================================================================================" << endl;
618 os <<
"Ifpack_SparseContainer" << endl;
619 os <<
"Number of rows = " << NumRows() << endl;
620 os <<
"Number of vectors = " <<
NumVectors() << endl;
621 os <<
"IsInitialized() = " << IsInitialized() << endl;
622 os <<
"IsComputed() = " << IsComputed() << endl;
623 os <<
"Flops in Initialize() = " << InitializeFlops() << endl;
624 os <<
"Flops in Compute() = " << ComputeFlops() << endl;
625 os <<
"Flops in ApplyInverse() = " << ApplyInverseFlops() << endl;
626 os <<
"================================================================================" << endl;
631 #endif // IFPACK_SPARSECONTAINER_H int NumRows_
Number of rows in the local matrix.
Ifpack_SparseContainer & operator=(const Ifpack_SparseContainer< T > &rhs)
Operator =.
virtual std::ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all necessary parameters.
virtual double InitializeFlops() const
Returns the flops in Compute().
virtual bool IsComputed() const
Returns true is the container has been successfully computed.
virtual double ApplyFlops() const
Returns the flops in Apply().
Epetra_IntSerialDenseVector GID_
Contains the subrows/subcols of A that will be inserted in Matrix_.
virtual double & LHS(const int i, const int Vector=0)
Returns the i-th component of the vector Vector of LHS.
virtual int Initialize()
Initializes the container, by completing all the operations based on matrix structure.
Teuchos::RefCountPtr< T > Inverse_
Pointer to an Ifpack_Preconditioner object whose ApplyInverse() defined the action of the inverse of ...
bool IsInitialized_
If true, the container has been successfully initialized.
virtual int SetMatrixElement(const int row, const int col, const double value)
Set the matrix element (row,col) to value.
Teuchos::RefCountPtr< Epetra_Map > Map_
Linear map on which the local matrix is based.
Teuchos::RCP< const Epetra_CrsMatrix > Matrix() const
Returns a pointer to the internally stored matrix.
Teuchos::RefCountPtr< Epetra_CrsMatrix > Matrix_
Pointer to the local matrix.
virtual double & RHS(const int i, const int Vector=0)
Returns the i-th component of the vector Vector of RHS.
Teuchos::RCP< const Epetra_Map > Map() const
Returns a pointer to the internally stored map.
Teuchos::RefCountPtr< Epetra_Comm > SerialComm_
Serial communicator (containing only MPI_COMM_SELF if MPI is used).
Teuchos::ParameterList List_
bool IsComputed_
If true, the container has been successfully computed.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
std::string Label_
Label for this object.
bool is_null(const RCP< T > &p)
Ifpack_SparseContainer: a class for storing and solving linear systems using sparse matrices...
Teuchos::RCP< const Epetra_MultiVector > RHS() const
Returns a pointer to the internally stored rhs multi-vector.
virtual int SetNumVectors(const int NumVectors_in)
Sets the number of vectors for LHS/RHS.
virtual int ApplyInverse()
Apply the inverse of the matrix to RHS, result is stored in LHS.
virtual const char * Label() const
Returns the label of this container.
Ifpack_SparseContainer(const int NumRows, const int NumVectors=1)
Constructor.
const Epetra_IntSerialDenseVector & ID() const
Returns a pointer to the internally stored ID's.
Teuchos::RCP< const Epetra_MultiVector > LHS() const
Returns a pointer to the internally stored solution multi-vector.
virtual ~Ifpack_SparseContainer()
Destructor.
virtual int NumRows() const
Returns the number of rows of the matrix and LHS/RHS.
int NumVectors_
Number of vectors in the local linear system.
virtual double ApplyInverseFlops() const
Returns the flops in ApplyInverse().
Teuchos::RefCountPtr< Epetra_MultiVector > RHS_
right-hand side for local problems.
virtual int Destroy()
Destroys all data.
Teuchos::RefCountPtr< Epetra_MultiVector > LHS_
Solution vector.
Ifpack_Container: a pure virtual class for creating and solving local linear problems.
Teuchos::RCP< const T > Inverse() const
Returns a pointer to the internally stored inverse operator.
virtual double ComputeFlops() const
Returns the flops in Compute().
#define IFPACK_CHK_ERR(ifpack_err)
virtual int Compute(const Epetra_RowMatrix &Matrix_in)
Finalizes the linear system matrix and prepares for the application of the inverse.
virtual int NumVectors() const
Returns the number of vectors in LHS/RHS.
virtual int Extract(const Epetra_RowMatrix &Matrix_in)
Extract the submatrices identified by the ID set int ID().
virtual bool IsInitialized() const
Returns true is the container has been successfully initialized.
virtual int Apply()
Apply the matrix to RHS, result is stored in LHS.