43 #ifndef IFPACK_SPARSECONTAINER_H 44 #define IFPACK_SPARSECONTAINER_H 46 #include "Ifpack_Container.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" 127 if (NumVectors_ != NumVectors_in)
129 NumVectors_=NumVectors_in;
130 LHS_=Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_));
131 RHS_=Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_));
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);
162 return(IsInitialized_);
177 return(Label_.c_str());
181 Teuchos::RCP<const Epetra_Map>
Map()
const 187 Teuchos::RCP<const Epetra_MultiVector>
LHS()
const 193 Teuchos::RCP<const Epetra_MultiVector>
RHS()
const 199 Teuchos::RCP<const Epetra_CrsMatrix>
Matrix()
const 205 const Epetra_IntSerialDenseVector&
ID()
const 227 virtual int Compute(
const Epetra_RowMatrix& Matrix_in);
244 if (Inverse_ == Teuchos::null)
247 return(Inverse_->InitializeFlops());
253 if (Inverse_ == Teuchos::null)
256 return(Inverse_->ComputeFlops());
268 if (Inverse_ == Teuchos::null)
271 return(Inverse_->ApplyInverseFlops());
275 virtual 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_;
301 Teuchos::RefCountPtr<Epetra_Comm> SerialComm_;
303 Teuchos::RefCountPtr<T> Inverse_;
306 Teuchos::ParameterList List_;
315 NumRows_(NumRows_in),
316 NumVectors_(NumVectors_in),
317 IsInitialized_(false),
323 SerialComm_ = Teuchos::rcp(
new Epetra_MpiComm(MPI_COMM_SELF) );
325 SerialComm_ = Teuchos::rcp(
new Epetra_SerialComm );
341 SerialComm_ = Teuchos::rcp(
new Epetra_MpiComm(MPI_COMM_SELF) );
343 SerialComm_ = Teuchos::rcp(
new Epetra_SerialComm );
347 Map_ = Teuchos::rcp(
new Epetra_Map(*rhs.
Map()) );
350 Matrix_ = Teuchos::rcp(
new Epetra_CrsMatrix(*rhs.
Matrix()) );
353 LHS_ = Teuchos::rcp(
new Epetra_MultiVector(*rhs.
LHS()) );
356 RHS_ = Teuchos::rcp(
new Epetra_MultiVector(*rhs.
RHS()) );
381 if (IsInitialized_ ==
true)
384 IsInitialized_ =
false;
386 Map_ = Teuchos::rcp(
new Epetra_Map(NumRows_,0,*SerialComm_) );
388 LHS_ = Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_) );
389 RHS_ = Teuchos::rcp(
new Epetra_MultiVector(*Map_,NumVectors_) );
390 GID_.Reshape(NumRows_,1);
392 Matrix_ = Teuchos::rcp(
new Epetra_CrsMatrix(Copy,*Map_,0) );
395 Inverse_ = Teuchos::rcp(
new T(Matrix_.get()) );
397 if (Inverse_ == Teuchos::null)
400 IFPACK_CHK_ERR(Inverse_->SetParameters(List_));
406 Label_ =
"Ifpack_SparseContainer";
408 IsInitialized_ =
true;
417 return(((*LHS_)(Vector))->Values()[i]);
424 return(((*RHS_)(Vector))->Values()[i]);
435 if ((row < 0) || (row >=
NumRows())) {
439 if ((col < 0) || (col >=
NumRows())) {
443 int ierr = Matrix_->InsertGlobalValues((
int)row,1,(
double*)&value,(
int*)&col);
445 ierr = Matrix_->SumIntoGlobalValues((
int)row,1,(
double*)&value,(
int*)&col);
465 IFPACK_CHK_ERR(Extract(Matrix_in));
468 IFPACK_CHK_ERR(Inverse_->Initialize());
471 IFPACK_CHK_ERR(Inverse_->Compute());
473 Label_ =
"Ifpack_SparseContainer";
488 IFPACK_CHK_ERR(Matrix_->Apply(*RHS_, *LHS_));
490 ApplyFlops_ += 2 * Matrix_->NumGlobalNonzeros();
501 IFPACK_CHK_ERR(Inverse_->ApplyInverse(*RHS_, *LHS_));
511 IsInitialized_ =
false;
538 for (
int j = 0 ; j < NumRows_ ; ++j) {
543 if (
ID(j) > Matrix_in.NumMyRows())
547 int Length = Matrix_in.MaxNumEntries();
548 std::vector<double> Values;
549 Values.resize(Length);
550 std::vector<int> Indices;
551 Indices.resize(Length);
553 for (
int j = 0 ; j < NumRows_ ; ++j) {
560 Matrix_in.ExtractMyRowCopy(LRID, Length, NumEntries,
561 &Values[0], &Indices[0]);
562 IFPACK_CHK_ERR(ierr);
564 for (
int k = 0 ; k < NumEntries ; ++k) {
566 int LCID = Indices[k];
569 if (LCID >= Matrix_in.NumMyRows())
576 for (
int kk = 0 ; kk < NumRows_ ; ++kk)
586 IFPACK_CHK_ERR(Matrix_->FillComplete());
595 os <<
"================================================================================" << endl;
596 os <<
"Ifpack_SparseContainer" << endl;
597 os <<
"Number of rows = " <<
NumRows() << endl;
598 os <<
"Number of vectors = " <<
NumVectors() << endl;
600 os <<
"IsComputed() = " <<
IsComputed() << endl;
602 os <<
"Flops in Compute() = " <<
ComputeFlops() << endl;
604 os <<
"================================================================================" << endl;
609 #endif // IFPACK_SPARSECONTAINER_H virtual double ComputeFlops() const
Returns the flops in Compute().
virtual double InitializeFlops() const
Returns the flops in Compute().
Teuchos::RCP< const Epetra_MultiVector > LHS() const
Returns a pointer to the internally stored solution multi-vector.
virtual int NumRows() const
Returns the number of rows of the matrix and LHS/RHS.
Ifpack_SparseContainer & operator=(const Ifpack_SparseContainer< T > &rhs)
Operator =.
Teuchos::RCP< const Epetra_MultiVector > RHS() const
Returns a pointer to the internally stored rhs multi-vector.
virtual int SetParameters(Teuchos::ParameterList &List)
Sets all necessary parameters.
virtual bool IsInitialized() const
Returns true is the container has been successfully initialized.
Teuchos::RCP< const Epetra_CrsMatrix > Matrix() const
Returns a pointer to the internally stored 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.
virtual int SetMatrixElement(const int row, const int col, const double value)
Set the matrix element (row,col) to value.
virtual const char * Label() const
Returns the label of this container.
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.
virtual int NumVectors() const
Returns the number of vectors in LHS/RHS.
Ifpack_SparseContainer: a class for storing and solving linear systems using sparse matrices...
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.
Ifpack_SparseContainer(const int NumRows, const int NumVectors=1)
Constructor.
virtual double ApplyFlops() const
Returns the flops in Apply().
virtual ~Ifpack_SparseContainer()
Destructor.
Teuchos::RCP< const T > Inverse() const
Returns a pointer to the internally stored inverse operator.
virtual ostream & Print(std::ostream &os) const
Prints basic information on iostream. This function is used by operator<<.
const Epetra_IntSerialDenseVector & ID() const
Returns a pointer to the internally stored ID's.
virtual int Destroy()
Destroys all data.
Ifpack_Container: a pure virtual class for creating and solving local linear problems.
virtual bool IsComputed() const
Returns true is the container has been successfully computed.
virtual int Compute(const Epetra_RowMatrix &Matrix_in)
Finalizes the linear system matrix and prepares for the application of the inverse.
virtual double ApplyInverseFlops() const
Returns the flops in ApplyInverse().
virtual int Apply()
Apply the matrix to RHS, result is stored in LHS.