# endif
# include <Epetra_Map.h>
-# include <Teuchos_RCP.hpp>
# include <Teuchos_ParameterList.hpp>
# include <Epetra_Operator.h>
# include <Epetra_Vector.h>
*/
~PreconditionBase ();
+ /**
+ * Destroys the preconditioner, leaving
+ * an object like just after having
+ * called the constructor.
+ */
+ void clear ();
+
/**
* Apply the preconditioner.
*/
* is used when applying the
* preconditioner.
*/
- Teuchos::RCP<const Epetra_Operator> preconditioner;
+ std_cxx1x::shared_ptr<Epetra_Operator> preconditioner;
/**
* Internal communication
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Preconditioner> ifpack;
};
*/
void initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data = AdditionalData());
-
- private:
- /**
- * This is a pointer to the
- * Ifpack data contained in
- * this preconditioner.
- */
- Teuchos::RCP<Ifpack_Chebyshev> ifpack;
};
*/
void reinit ();
+ /**
+ * Destroys the preconditioner, leaving
+ * an object like just after having
+ * called the constructor.
+ */
+ void clear ();
+
/**
* Prints an estimate of the memory
* consumption of this class.
unsigned int memory_consumption () const;
private:
-
- /**
- * A pointer to the preconditioner
- * object.
- */
- Teuchos::RCP<ML_Epetra::MultiLevelPreconditioner> multilevel_operator;
-
/**
* A copy of the deal.II matrix into
* Trilinos format.
*/
- std_cxx1x::shared_ptr<SparseMatrix> Matrix;
+ std_cxx1x::shared_ptr<SparseMatrix> trilinos_matrix;
};
PreconditionBase::~PreconditionBase()
+ {}
+
+
+
+ void PreconditionBase::clear ()
{
- preconditioner.release();
+ preconditioner.reset();
+#ifdef DEAL_II_COMPILER_SUPPORTS_MPI
+ communicator = MPI_COMM_SELF;
+#endif
+ vector_distributor.reset();
}
PreconditionJacobi::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("point relaxation",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- 0));
+ // release memory before reallocation
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("point relaxation",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ 0));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionSSOR::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("point relaxation",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("point relaxation",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionSOR::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("point relaxation",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("point relaxation",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionIC::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("IC",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("IC",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionILU::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("ILU",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("ILU",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionILUT::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
-
- ifpack = Teuchos::rcp (Ifpack().Create
- ("ILUT",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("ILUT",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionBlockwiseDirect::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
+ preconditioner.reset ();
+ preconditioner.reset (Ifpack().Create
+ ("Amesos",
+ const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
+ additional_data.overlap));
- ifpack = Teuchos::rcp (Ifpack().Create
- ("Amesos",
- const_cast<Epetra_CrsMatrix*>(&matrix.trilinos_matrix()),
- additional_data.overlap));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Preconditioner * ifpack = static_cast<Ifpack_Preconditioner*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionChebyshev::initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.release();
- ifpack.release();
+ preconditioner.reset ();
+ preconditioner.reset (new Ifpack_Chebyshev (&matrix.trilinos_matrix()));
- ifpack = Teuchos::rcp (new Ifpack_Chebyshev (&matrix.trilinos_matrix()));
- Assert (ifpack.get() != 0, ExcMessage ("Trilinos could not create this "
- "preconditioner"));
+ Ifpack_Chebyshev * ifpack = static_cast<Ifpack_Chebyshev*>
+ (preconditioner.get());
+ Assert (ifpack != 0, ExcMessage ("Trilinos could not create this "
+ "preconditioner"));
int ierr;
ierr = ifpack->Compute();
AssertThrow (ierr == 0, ExcTrilinosError(ierr));
-
- preconditioner = Teuchos::rcp (ifpack.get(), false);
}
PreconditionAMG:: initialize (const SparseMatrix &matrix,
const AdditionalData &additional_data)
{
- preconditioner.reset ();
- multilevel_operator.reset ();
-
const unsigned int n_rows = matrix.m();
// Build the AMG preconditioner.
for (unsigned int row=0; row<my_size; ++row)
{
int global_row_id = constant_modes_are_global ? domain_map.GID(row) : row;
- distributed_constant_modes.ReplaceMyValue(row, d,
- static_cast<double>(additional_data.constant_modes[d][global_row_id]));
+ distributed_constant_modes[d][row] =
+ additional_data.constant_modes[d][global_row_id];
}
parameter_list.set("null space: type", "pre-computed");
initialize (matrix, parameter_list);
if (additional_data.output_details)
- multilevel_operator->PrintUnused(0);
+ {
+ ML_Epetra::MultiLevelPreconditioner * multilevel_operator =
+ dynamic_cast<ML_Epetra::MultiLevelPreconditioner*> (preconditioner.get());
+ Assert (multilevel_operator != 0,
+ ExcMessage ("Preconditioner setup failed."));
+ multilevel_operator->PrintUnused(0);
+ }
}
PreconditionAMG::initialize (const SparseMatrix &matrix,
const Teuchos::ParameterList &ml_parameters)
{
- multilevel_operator.reset (new ML_Epetra::MultiLevelPreconditioner
- (matrix.trilinos_matrix(), ml_parameters));
- preconditioner.reset (multilevel_operator.get(), false);
+ preconditioner.reset ();
+ preconditioner.reset (new ML_Epetra::MultiLevelPreconditioner
+ (matrix.trilinos_matrix(), ml_parameters));
}
const ::dealii::SparsityPattern *use_this_sparsity)
{
preconditioner.reset();
- multilevel_operator.reset ();
const unsigned int n_rows = deal_ii_sparse_matrix.m();
// Init Epetra Matrix using an
// elements.
vector_distributor.reset (new Epetra_Map(n_rows, 0, communicator));
- if (Matrix.get() == 0)
- Matrix.reset (new SparseMatrix());
+ if (trilinos_matrix.get() == 0)
+ trilinos_matrix.reset (new SparseMatrix());
- Matrix->reinit (*vector_distributor, *vector_distributor,
- deal_ii_sparse_matrix, drop_tolerance, true,
- use_this_sparsity);
+ trilinos_matrix->reinit (*vector_distributor, *vector_distributor,
+ deal_ii_sparse_matrix, drop_tolerance, true,
+ use_this_sparsity);
- initialize (*Matrix, additional_data);
+ initialize (*trilinos_matrix, additional_data);
}
void PreconditionAMG::reinit ()
{
+ ML_Epetra::MultiLevelPreconditioner * multilevel_operator =
+ dynamic_cast<ML_Epetra::MultiLevelPreconditioner*> (preconditioner.get());
multilevel_operator->ReComputePreconditioner();
}
+
+ void PreconditionAMG::clear ()
+ {
+ PreconditionBase::clear();
+ trilinos_matrix.reset();
+ }
+
+
+
unsigned int PreconditionAMG::memory_consumption() const
{
unsigned int memory = sizeof(this);
// todo: find a way to read out ML's data
// sizes
- if (Matrix.get() != 0)
- memory += Matrix->memory_consumption();
+ if (trilinos_matrix.get() != 0)
+ memory += trilinos_matrix->memory_consumption();
return memory;
}