#include <deal.II/lac/solver_minres.h>
#include <deal.II/lac/solver_richardson.h>
#include <deal.II/lac/vector.h>
-#include <deal.II/lac/vector_memory.h>
DEAL_II_NAMESPACE_OPEN
*
* <h3>Usage</h3> The simplest use of this class is the following:
* @code
- * // generate a @p SolverControl and a @p VectorMemory
- * SolverControl control;
- * VectorMemory<Vector<double> > memory;
- *
- * // Line 3:
* // generate a @p SolverSelector that calls the @p SolverCG
- * SolverSelector<Vector<double> >
- * solver_selector("cg", control, memory);
+ * SolverConrtol control;
+ * SolverSelector<Vector<double> > solver_selector ("cg", control);
*
* // generate e.g. a @p PreconditionRelaxation
* PreconditionRelaxation<SparseMatrix<double>, Vector<double> >
* ...
* @endcode
* Assuming that in the users parameter file there exists the line
- * @verbatim
+ * @code
* set solver = cg
- * @endverbatim
- * then `Line 3' of the above example reads
+ * @endcode
+ * then the constructor call in the above example can be written as
* @code
* SolverSelector<SparseMatrix<double>, Vector<double> >
- * solver_selector(prm.get("solver"), control, memory);
+ * solver_selector(prm.get("solver"), control);
* @endcode
*
*
* to change his program. Only in the implementation of the @p SolverSelector
* the calling of this solver has to be added and each user with program lines
* quoted above only needs to 'set solver = xyz' in his parameter file to get
- * access to that new solver. :-)
- *
- * (By the way, thanks to Wolfgang for implementing the @p ParameterHandler.)
+ * access to that new solver.
*
* @author Ralf Hartmann, 1999
*/
*/
SolverSelector() = default;
+ /**
+ * Constructor, selecting the solver @p name
+ * and the SolverControl object @p control already.
+ */
+ SolverSelector(const std::string &name, SolverControl &control);
+
/**
* Destructor
*/
/* --------------------- Inline and template functions ------------------- */
+template <typename VectorType>
+SolverSelector<VectorType>::SolverSelector(const std::string &name,
+ SolverControl & solver_control)
+ : solver_name(name)
+ , control(&solver_control)
+{}
+
+
+
template <typename VectorType>
SolverSelector<VectorType>::~SolverSelector()
{}
+
template <typename VectorType>
void
SolverSelector<VectorType>::select(const std::string &name)
}
+
template <typename VectorType>
template <class Matrix, class Preconditioner>
void
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_control(SolverControl &ctrl)
}
+
template <typename VectorType>
std::string
SolverSelector<VectorType>::get_solver_names()
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
}
+
template <typename VectorType>
void
SolverSelector<VectorType>::set_data(
bicgstab_data = data;
}
-
DEAL_II_NAMESPACE_CLOSE
#endif
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2018 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.md at
+// the top level directory of deal.II.
+//
+// ---------------------------------------------------------------------
+
+
+// Test the SolverSelector class using the constructor that initializes the
+// object already.
+
+#include <deal.II/lac/solver_selector.h>
+#include <deal.II/lac/sparse_matrix.h>
+#include <deal.II/lac/vector.h>
+#include <deal.II/lac/vector_memory.h>
+
+#include "../testmatrix.h"
+#include "../tests.h"
+
+
+template <typename MatrixType, typename VectorType>
+void
+check(const MatrixType &A, const VectorType &f)
+{
+ std::vector<std::string> names;
+ names.push_back("cg");
+ names.push_back("gmres");
+
+ SolverControl cont(100, 1.e-7);
+ SolverSelector<VectorType> solver;
+ PreconditionSSOR<SparseMatrix<double>> pre;
+ pre.initialize(A);
+
+ VectorType u;
+ u.reinit(f);
+
+ for (const auto &name : names)
+ {
+ SolverSelector<VectorType> solver(name, cont);
+ u = 0.;
+ solver.solve(A, u, f, pre);
+ }
+}
+
+
+int
+main()
+{
+ initlog();
+ deallog << std::setprecision(4);
+
+ unsigned int size = 37;
+ 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();
+ SparseMatrix<double> A(structure);
+ testproblem.five_point(A);
+ Vector<double> f(dim);
+ f = 1.;
+
+ check(A, f);
+}