Skip to content
Snippets Groups Projects
Commit ea6e36aa authored by oliver.sander_at_tu-dresden.de's avatar oliver.sander_at_tu-dresden.de
Browse files

Make QuadraticIPOptSolver inherit from LinearSolver

Now we can you RTTI to figure out that the solver
has the setProblem(A,x,b) method.
parent 65915581
Branches
No related tags found
No related merge requests found
......@@ -21,7 +21,7 @@
#include <dune/solvers/common/boxconstraint.hh>
#include <dune/solvers/common/canignore.hh>
#include <dune/solvers/solvers/iterativesolver.hh>
#include <dune/solvers/solvers/linearsolver.hh>
#include "IpTNLP.hpp"
#include "IpIpoptApplication.hpp"
......@@ -632,7 +632,7 @@ finalize_solution(Ipopt::SolverReturn status,
*/
template <class MatrixType, class VectorType, class JacobianType=MatrixType>
class QuadraticIPOptSolver
: public IterativeSolver<VectorType>, public CanIgnore<Dune::BitSetVector<VectorType::block_type::dimension> >
: public LinearSolver<MatrixType,VectorType>, public CanIgnore<Dune::BitSetVector<VectorType::block_type::dimension> >
{
enum {blocksize = VectorType::block_type::dimension};
......@@ -647,7 +647,7 @@ class QuadraticIPOptSolver
public:
/** \brief Default constructor */
QuadraticIPOptSolver () : IterativeSolver<VectorType>(1e-8, 100, NumProc::FULL),
QuadraticIPOptSolver () : LinearSolver<MatrixType,VectorType>(NumProc::FULL),
hessian_(NULL), rhs_(NULL),
obstacles_(NULL),
linearSolverType_(""),
......@@ -657,7 +657,9 @@ public:
/** \brief Constructor that only sets solver parameter. */
QuadraticIPOptSolver (field_type tolerance, int numIterations,
NumProc::VerbosityMode verbosity = NumProc::FULL)
: IterativeSolver<VectorType>(tolerance, numIterations, verbosity)
: LinearSolver<MatrixType,VectorType>(verbosity),
tolerance_(tolerance),
maxIterations_(numIterations)
{}
/** \brief Constructor for a linear problem */
......@@ -666,7 +668,9 @@ public:
const VectorType& rhs,
NumProc::VerbosityMode verbosity=NumProc::FULL,
std::string linearSolverType = "")
: IterativeSolver<VectorType>(1e-8, 100, verbosity),
: LinearSolver<MatrixType,VectorType>(verbosity),
tolerance_(1e-8),
maxIterations_(100),
hessian_(&hessian), rhs_(&rhs), obstacles_(NULL),
linearSolverType_(linearSolverType),
constraintObstacles_(nullptr),constraintMatrix_(nullptr)
......@@ -676,7 +680,8 @@ public:
void setProblem(const MatrixType& hessian,
VectorType& x,
const VectorType& rhs) {
const VectorType& rhs) override
{
hessian_ = &hessian;
x_ = &x;
rhs_ = &rhs;
......@@ -694,6 +699,12 @@ public:
// Data
///////////////////////////////////////////////////////
//! Solve the system until the IPOpt error measure drops below this value
double tolerance_;
//! The maximum number of iterations
int maxIterations_;
//! The quadratic term in the quadratic energy, is assumed to be symmetric
const MatrixType* hessian_;
......@@ -733,8 +744,8 @@ void QuadraticIPOptSolver<MatrixType,VectorType,JacobianType>::solve()
Ipopt::SmartPtr<Ipopt::IpoptApplication> app = new Ipopt::IpoptApplication();
// Change some options
app->Options()->SetNumericValue("tol", this->tolerance_);
app->Options()->SetIntegerValue("max_iter", this->maxIterations_);
app->Options()->SetNumericValue("tol", tolerance_);
app->Options()->SetIntegerValue("max_iter", maxIterations_);
app->Options()->SetStringValue("mu_strategy", "adaptive");
if (linearSolverType_!="")
app->Options()->SetStringValue("linear_solver",linearSolverType_);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment