template <typename Number>
class PreconditionBase
{
- public :
- /**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
- */
- struct AdditionalData
- {};
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {};
- /**
- * Constructor. Does not do anything.
- */
- PreconditionBase ();
+ /**
+ * Constructor. Does not do anything.
+ */
+ PreconditionBase ();
- friend class SolverBase;
+ friend class SolverBase;
- protected :
- /**
- * This is a pointer to the preconditioner object that is used when
- * applying the preconditioner.
- */
- std_cxx1x::shared_ptr<paralution::Preconditioner<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number> > preconditioner;
+ protected :
+ /**
+ * This is a pointer to the preconditioner object that is used when
+ * applying the preconditioner.
+ */
+ std_cxx1x::shared_ptr<paralution::Preconditioner<paralution::LocalMatrix<Number>,
+ paralution::LocalVector<Number>,Number> > preconditioner;
};
template <typename Number>
class PreconditionJacobi : public PreconditionBase<Number>
{
- public :
- /**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
- */
- struct AdditionalData
- {};
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {};
- /**
- * Constructor.
- */
- PreconditionJacobi ();
+ /**
+ * Constructor.
+ */
+ PreconditionJacobi ();
private :
/**
template <typename Number>
class PreconditionSGS : public PreconditionBase<Number>
{
- public :
- /**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
- */
- struct AdditionalData
- {};
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {};
- /**
- * Constructor.
- */
- PreconditionSGS ();
+ /**
+ * Constructor.
+ */
+ PreconditionSGS ();
private :
/**
template <typename Number>
class PreconditionMultiColoredSGS : public PreconditionBase<Number>
{
- public :
- /**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
- */
- struct AdditionalData
- {};
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {};
- /**
- * Constructor.
- */
- PreconditionMultiColoredSGS ();
+ /**
+ * Constructor.
+ */
+ PreconditionMultiColoredSGS ();
private :
/**
template <typename Number>
class PreconditionMultiColoredSOR : public PreconditionBase<Number>
{
- public :
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {
/**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
- */
- struct AdditionalData
- {
- /**
- * Constructor. By default, set the damping parameter to one.
- */
- AdditionalData (const double omega = 1);
-
- /**
- * Relaxation parameter.
- */
- double omega;
- };
-
- /**
- * Constructor. Take additional flags if there are any.
+ * Constructor. By default, set the damping parameter to one.
*/
- PreconditionMultiColoredSOR (const AdditionalData &additional_data = AdditionalData());
+ AdditionalData (const double omega = 1);
/**
- * This function changes the value of the additional flags.
+ * Relaxation parameter.
*/
- void initialize (const AdditionalData &additional_data = AdditionalData());
+ double omega;
+ };
- private :
- /**
- * Store a copy of the flags for this particular preconditioner.
- */
- AdditionalData additional_data;
+ /**
+ * Constructor. Take additional flags if there are any.
+ */
+ PreconditionMultiColoredSOR (const AdditionalData &additional_data = AdditionalData());
+
+ /**
+ * This function changes the value of the additional flags.
+ */
+ void initialize (const AdditionalData &additional_data = AdditionalData());
+
+ private :
+ /**
+ * Store a copy of the flags for this particular preconditioner.
+ */
+ AdditionalData additional_data;
};
template <typename Number>
class PreconditionILU : public PreconditionBase<Number>
{
- public :
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {
/**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
+ * Constructor. By default, set the fill-in parameter to zero.
*/
- struct AdditionalData
- {
- /**
- * Constructor. By default, set the fill-in parameter to zero.
- */
- AdditionalData (const unsigned int levels = 0);
-
- /**
- * Fill-in parameter.
- */
- unsigned int levels;
- };
+ AdditionalData (const unsigned int levels = 0);
/**
- * Constructor. Take additional flags if there are any.
+ * Fill-in parameter.
*/
- PreconditionILU (const AdditionalData &additional_data = AdditionalData());
+ unsigned int levels;
+ };
- /**
- * This function changes the value of the additional flags.
- */
- void initialize (const AdditionalData &additional_data = AdditionalData());
+ /**
+ * Constructor. Take additional flags if there are any.
+ */
+ PreconditionILU (const AdditionalData &additional_data = AdditionalData());
- private :
- /**
- * Store a copy of the flags for this particular preconditioner.
- */
- AdditionalData additional_data;
+ /**
+ * This function changes the value of the additional flags.
+ */
+ void initialize (const AdditionalData &additional_data = AdditionalData());
+
+ private :
+ /**
+ * Store a copy of the flags for this particular preconditioner.
+ */
+ AdditionalData additional_data;
};
template <typename Number>
class PreconditionILUT : public PreconditionBase<Number>
{
- public :
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {
/**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
+ * Constructor. By default, set the threshold to zero.
*/
- struct AdditionalData
- {
- /**
- * Constructor. By default, set the threshold to zero.
- */
- AdditionalData (const Number threshold = 0.);
-
- /**
- * Constructor.
- */
- AdditionalData (const Number threshold, const unsigned int max_row);
-
- /**
- * Threshold.
- */
- Number threshold;
-
- /**
- * Maximum number of elements per row.
- */
- unsigned int max_row;
- };
+ AdditionalData (const Number threshold = 0.);
/**
- * Constructor. Take additional flags if there are any.
+ * Constructor.
*/
- PreconditionILUT (const AdditionalData &additional_data = AdditionalData());
+ AdditionalData (const Number threshold, const unsigned int max_row);
/**
- * This function changes the value of the additional flags.
+ * Threshold.
*/
- void initialize (const AdditionalData &additional_data = AdditionalData());
+ Number threshold;
- private :
/**
- * Store a copy of the flags for this particular preconditioner.
+ * Maximum number of elements per row.
*/
- AdditionalData additional_data;
+ unsigned int max_row;
+ };
+
+ /**
+ * Constructor. Take additional flags if there are any.
+ */
+ PreconditionILUT (const AdditionalData &additional_data = AdditionalData());
+
+ /**
+ * This function changes the value of the additional flags.
+ */
+ void initialize (const AdditionalData &additional_data = AdditionalData());
+
+ private :
+ /**
+ * Store a copy of the flags for this particular preconditioner.
+ */
+ AdditionalData additional_data;
};
template <typename Number>
class PreconditionMultiColoredILU : public PreconditionBase<Number>
{
- public :
+ public :
+ /**
+ * Standardized data struct to pipe additional flags to the
+ * preconditioner.
+ */
+ struct AdditionalData
+ {
/**
- * Standardized data struct to pipe additional flags to the
- * preconditioner.
+ * Constructor. By default, set the fill-in parameter to zero and the
+ * power-pattern to one.
*/
- struct AdditionalData
- {
- /**
- * Constructor. By default, set the fill-in parameter to zero and the
- * power-pattern to one.
- */
- AdditionalData (const unsigned int levels = 0, const unsigned int power = 1);
-
- /**
- * Fill-in parameter.
- */
- unsigned int levels;
-
- /**
- * Power parameter.
- */
- unsigned int power;
- };
+ AdditionalData (const unsigned int levels = 0, const unsigned int power = 1);
/**
- * Constructor. Take additional flags if there are any.
+ * Fill-in parameter.
*/
- PreconditionMultiColoredILU (const AdditionalData &additional_data = AdditionalData());
+ unsigned int levels;
/**
- * This function changes the value of additional flags.
+ * Power parameter.
*/
- void initialize (const AdditionalData &additional_data = AdditionalData());
+ unsigned int power;
+ };
- private :
- /**
- * Store a copy of the flags for this particular preconditioner.
- */
- AdditionalData additional_data;
+ /**
+ * Constructor. Take additional flags if there are any.
+ */
+ PreconditionMultiColoredILU (const AdditionalData &additional_data = AdditionalData());
+
+ /**
+ * This function changes the value of additional flags.
+ */
+ void initialize (const AdditionalData &additional_data = AdditionalData());
+
+ private :
+ /**
+ * Store a copy of the flags for this particular preconditioner.
+ */
+ AdditionalData additional_data;
};
}
PreconditionJacobi<Number>::PreconditionJacobi()
{
this->preconditioner.reset(new paralution::Jacobi<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
}
PreconditionSGS<Number>::PreconditionSGS()
{
this->preconditioner.reset(new paralution::SGS<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
}
PreconditionMultiColoredSGS<Number>::PreconditionMultiColoredSGS()
{
this->preconditioner.reset(new paralution::MultiColoredSGS<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
}
template <typename Number>
PreconditionMultiColoredSOR<Number>::AdditionalData::
- AdditionalData(const double omega)
- :
+ AdditionalData(const double omega)
+ :
omega(omega)
{}
+
template <typename Number>
PreconditionMultiColoredSOR<Number>::PreconditionMultiColoredSOR(
- const AdditionalData &additional_data)
- :
+ const AdditionalData &additional_data)
+ :
additional_data(additional_data)
{
this->preconditioner.reset(new paralution::MultiColoredGS<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
initialize(additional_data);
}
+
+
template <typename Number>
void PreconditionMultiColoredSOR<Number>::initialize(const AdditionalData &additional_data)
{
// Downcast the preconditioner pointer to use SetRelaxation
paralution::MultiColoredGS<paralution::LocalMatrix<Number>,paralution::
- LocalVector<Number>,Number>* downcasted_ptr = static_cast<paralution::
- MultiColoredGS<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
- Number>* >(this->preconditioner.get());
+ LocalVector<Number>,Number>* downcasted_ptr = static_cast<paralution::
+ MultiColoredGS<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
+ Number>* >(this->preconditioner.get());
downcasted_ptr->SetRelaxation(additional_data.omega);
- }
+ }
template <typename Number>
PreconditionILU<Number>::AdditionalData::AdditionalData(const unsigned int levels)
- :
+ :
levels(levels)
{}
+
+
template <typename Number>
PreconditionILU<Number>::PreconditionILU(const AdditionalData &additional_data)
- :
+ :
additional_data(additional_data)
{
this->preconditioner.reset(new paralution::ILU<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
-
+ paralution::LocalVector<Number>,Number>);
+
initialize(additional_data);
}
+
+
template <typename Number>
void PreconditionILU<Number>::initialize(const AdditionalData &additional_data)
{
// Downcast the preconditioner pointer to use Set
paralution::ILU<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
- Number>* downcasted_ptr = static_cast<paralution::ILU<paralution::
- LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+ Number>* downcasted_ptr = static_cast<paralution::ILU<paralution::
+ LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
downcasted_ptr->Set(additional_data.levels);
}
template <typename Number>
PreconditionILUT<Number>::AdditionalData::AdditionalData(const Number threshold)
- :
+ :
threshold(threshold),
max_row(0)
{}
+
+
template <typename Number>
PreconditionILUT<Number>::AdditionalData::AdditionalData(const Number threshold,
- const unsigned int max_row)
- :
+ const unsigned int max_row)
+ :
threshold(threshold),
max_row(max_row)
{}
+
+
template <typename Number>
PreconditionILUT<Number>::PreconditionILUT(const AdditionalData &additional_data)
- :
+ :
additional_data(additional_data)
{
this->preconditioner.reset(new paralution::ILUT<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
initialize(additional_data);
- }
-
+ }
+
+
+
template <typename Number>
void PreconditionILUT<Number>::initialize(const AdditionalData &additional_data)
{
// Downcast the preconditioner pointer to use Set
paralution::ILUT<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
- Number>* downcasted_ptr = static_cast<paralution::ILUT<paralution::
- LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+ Number>* downcasted_ptr = static_cast<paralution::ILUT<paralution::
+ LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
- if (additional_data.max_row==0)
- downcasted_ptr->Set(additional_data.threshold);
- else
- downcasted_ptr->Set(additional_data.threshold,additional_data.max_row);
+ if (additional_data.max_row==0)
+ downcasted_ptr->Set(additional_data.threshold);
+ else
+ downcasted_ptr->Set(additional_data.threshold,additional_data.max_row);
}
template <typename Number>
PreconditionMultiColoredILU<Number>::AdditionalData::
AdditionalData(const unsigned int levels, const unsigned int power)
- :
+ :
levels(levels),
power(power)
{}
+
+
template <typename Number>
PreconditionMultiColoredILU<Number>::
PreconditionMultiColoredILU(const AdditionalData &additional_data)
- :
+ :
additional_data(additional_data)
{
this->preconditioner.reset(new paralution::MultiColoredILU<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number>);
initialize(additional_data);
}
+
+
template <typename Number>
void PreconditionMultiColoredILU<Number>::initialize(const AdditionalData &additional_data)
{
// Downcast the preconditioner pointer to use Set
paralution::MultiColoredILU<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
- Number>* downcasted_ptr = static_cast<paralution::MultiColoredILU<paralution::
- LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+ Number>* downcasted_ptr = static_cast<paralution::MultiColoredILU<paralution::
+ LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
downcasted_ptr->Set(additional_data.levels,additional_data.power);
}
// Set absolute tolerance, relative tolerance, divergence tolerance,
// maximum number of iterations.
solver->Init(solver_control.tolerance(),0.,1.e100,
- solver_control.max_steps());
+ solver_control.max_steps());
// Move the solver to the accelerator if necessary.
if (move_to_accelerator==true)
bool move_to_accelerator)
{
std_cxx1x::shared_ptr<paralution::CG<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number> > solver(new paralution::
- CG<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number> > solver(new paralution::
+ CG<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
}
bool move_to_accelerator)
{
std_cxx1x::shared_ptr<paralution::BiCGStab<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number> > solver(new paralution::
- BiCGStab<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number> > solver(new paralution::
+ BiCGStab<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
}
/* --------------------- SolverGMRES ----------------------- */
+ SolverGMRES::AdditionalData::AdditionalData(const unsigned int restart_parameter)
+ :
+ restart_parameter(restart_parameter)
+ {}
+
+
+
+
SolverGMRES::SolverGMRES (SolverControl &cn,
const AdditionalData &data)
:
bool move_to_accelerator)
{
std_cxx1x::shared_ptr<paralution::GMRES<paralution::LocalMatrix<Number>,
- paralution::LocalVector<Number>,Number> > solver(new paralution::
- GMRES<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
+ paralution::LocalVector<Number>,Number> > solver(new paralution::
+ GMRES<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
// Set the restart parameter.
solver->SetBasisSize(additional_data.restart_parameter);
--- /dev/null
+// ---------------------------------------------------------------------
+// $Id: paralution_solver_01.cc 31349 2013-10-20 19:07:06Z maier $
+//
+// Copyright (C) 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+// Create a test for ParalutionWrappers::SolverGMRES
+
+#include "../tests.h"
+#include "testmatrix.h"
+#include <cmath>
+#include <fstream>
+#include <iomanip>
+#include <deal.II/base/logstream.h>
+#include <deal.II/lac/paralution_sparse_matrix.h>
+#include <deal.II/lac/paralution_vector.h>
+#include <deal.II/lac/paralution_solver.h>
+#include <deal.II/lac/paralution_precondition.h>
+
+int main()
+{
+ paralution::init_paralution();
+
+ std::ofstream logfile("output");
+ deallog << std::fixed;
+ deallog << std::setprecision(0);
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ SolverControl control(100,1.e-3);
+ ParalutionWrappers::SolverGMRES solver(control);
+
+ for (unsigned int size=4; size<=30; size*=3)
+ {
+ unsigned int dim = (size-1)*(size-1);
+
+ deallog << "Size "<< size <<" Unknowns "<< dim << std::endl;
+
+ // Make matrix
+ FDMatrix testproblem(size, size);
+ SparsityPattern structure(dim, dim, 5);
+ testproblem.five_point_structure(structure);
+ structure.compress();
+ ParalutionWrappers::SparseMatrix<double> A(structure);
+ testproblem.five_point(A);
+ A.convert_to_paralution_csr();
+
+ //Preconditioner
+ ParalutionWrappers::PreconditionMultiColoredSOR<double> p(1.);
+
+ ParalutionWrappers::Vector<double> u(dim);
+ ParalutionWrappers::Vector<double> f(dim);
+ for (unsigned int i=0; i<dim; ++i)
+ {
+ u[i] = 0.;
+ f[i] = 1.;
+ }
+ solver.solve(A,u,f,p);
+ }
+
+ paralution::stop_paralution();
+}
--- /dev/null
+
+DEAL::Size 4 Unknowns 9
+DEAL::Size 12 Unknowns 121