Skip to content
Snippets Groups Projects
Commit 847e2ebb authored by Dmitri Naumov's avatar Dmitri Naumov Committed by Dmitri Naumov
Browse files

[NL] SNES Add inequality constraints callback.

This allows a process to set lower or upper bounds
to the solution vector for SNESVI solvers.

Only two types of SNES solver support this.
parent dad7c47b
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,10 @@ public: ...@@ -71,6 +71,10 @@ public:
virtual void applyKnownSolutionsNewton( virtual void applyKnownSolutionsNewton(
GlobalMatrix& Jac, GlobalVector& res, GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) const = 0; GlobalVector& minus_delta_x) const = 0;
virtual void updateConstraints(GlobalVector& /*lower*/,
GlobalVector& /*upper*/,
int /*process_id*/) = 0;
}; };
/*! A System of nonlinear equations to be solved with the Picard fixpoint /*! A System of nonlinear equations to be solved with the Picard fixpoint
......
...@@ -66,6 +66,10 @@ public: ...@@ -66,6 +66,10 @@ public:
{ {
return nullptr; // by default there are no known solutions return nullptr; // by default there are no known solutions
} }
virtual void updateConstraints(GlobalVector& /*lower*/,
GlobalVector& /*upper*/,
int const /*process_id*/){};
}; };
/*! Interface for a first-order implicit quasi-linear ODE. /*! Interface for a first-order implicit quasi-linear ODE.
......
...@@ -156,6 +156,29 @@ NonlinearSolverStatus PETScNonlinearSolver::solve( ...@@ -156,6 +156,29 @@ NonlinearSolverStatus PETScNonlinearSolver::solve(
SNESSetJacobian(_snes_solver, J_snes.getRawMatrix(), J_snes.getRawMatrix(), SNESSetJacobian(_snes_solver, J_snes.getRawMatrix(), J_snes.getRawMatrix(),
updateJacobian, &petsc_context); updateJacobian, &petsc_context);
std::unique_ptr<GlobalVector> xl = nullptr;
std::unique_ptr<GlobalVector> xu = nullptr;
SNESType snes_type;
SNESGetType(_snes_solver, &snes_type);
if ((std::strcmp(snes_type, SNESVINEWTONRSLS) == 0) ||
(std::strcmp(snes_type, SNESVINEWTONSSLS) == 0))
{
// Set optional constraints via callback.
DBUG("PETScNonlinearSolver: set constraints");
xl = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(
system->getMatrixSpecifications(process_id));
xu = MathLib::MatrixVectorTraits<GlobalVector>::newInstance(
system->getMatrixSpecifications(process_id));
system->updateConstraints(*xl, *xu, process_id);
MathLib::finalizeVectorAssembly(*xl);
MathLib::finalizeVectorAssembly(*xu);
SNESVISetVariableBounds(_snes_solver, xl->getRawVector(),
xu->getRawVector());
}
DBUG("PETScNonlinearSolver: call SNESSolve"); DBUG("PETScNonlinearSolver: call SNESSolve");
SNESSolve(_snes_solver, nullptr, x_snes.getRawVector()); SNESSolve(_snes_solver, nullptr, x_snes.getRawVector());
......
...@@ -100,6 +100,12 @@ public: ...@@ -100,6 +100,12 @@ public:
void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res, void applyKnownSolutionsNewton(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) const override; GlobalVector& minus_delta_x) const override;
void updateConstraints(GlobalVector& lower, GlobalVector& upper,
int const process_id) override
{
_ode.updateConstraints(lower, upper, process_id);
}
bool isLinear() const override { return _ode.isLinear(); } bool isLinear() const override { return _ode.isLinear(); }
void preIteration(const unsigned iter, GlobalVector const& x) override void preIteration(const unsigned iter, GlobalVector const& x) override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment