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

[NL] Copy current Newton applyBCs for PETSc-SNES

The system solved by PETSc-SNES is different one and so far
the methods could be reused. With upcoming changes to the
Newton's version of applying Dirichlet-BCs this is not
going to work anymore.
parent 86c43482
No related branches found
No related tags found
No related merge requests found
...@@ -78,6 +78,13 @@ public: ...@@ -78,6 +78,13 @@ public:
GlobalMatrix& Jac, GlobalVector& res, GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& minus_delta_x) const = 0; GlobalVector& minus_delta_x) const = 0;
//! Apply known solutions to the linearized equation system
//! \f$ \mathit{Jac} \cdot (-\Delta x) = \mathit{res} \f$.
//! \pre computeKnownSolutions() must have been called before.
virtual void applyKnownSolutionsPETScSNES(GlobalMatrix& Jac,
GlobalVector& res,
GlobalVector& x) const = 0;
virtual void updateConstraints(GlobalVector& /*lower*/, virtual void updateConstraints(GlobalVector& /*lower*/,
GlobalVector& /*upper*/, GlobalVector& /*upper*/,
int /*process_id*/) = 0; int /*process_id*/) = 0;
......
...@@ -67,7 +67,7 @@ PetscErrorCode updateResidual(SNES /*snes*/, Vec x, Vec petsc_r, ...@@ -67,7 +67,7 @@ PetscErrorCode updateResidual(SNES /*snes*/, Vec x, Vec petsc_r,
context->J->finalizeAssembly(); context->J->finalizeAssembly();
context->system->getJacobian(*context->J); context->system->getJacobian(*context->J);
context->system->applyKnownSolutionsNewton( context->system->applyKnownSolutionsPETScSNES(
*context->J, *context->r, *context->x[context->process_id]); *context->J, *context->r, *context->x[context->process_id]);
VecCopy(context->r->getRawVector(), petsc_r); VecCopy(context->r->getRawVector(), petsc_r);
......
...@@ -152,6 +152,28 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, ...@@ -152,6 +152,28 @@ void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
MathLib::applyKnownSolution(Jac, res, minus_delta_x, ids, values); MathLib::applyKnownSolution(Jac, res, minus_delta_x, ids, values);
} }
void TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
NonlinearSolverTag::Newton>::
applyKnownSolutionsPETScSNES(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& x) const
{
if (!_known_solutions)
{
return;
}
using IndexType = MathLib::MatrixVectorTraits<GlobalMatrix>::Index;
std::vector<IndexType> ids;
for (auto const& bc : *_known_solutions)
{
ids.insert(end(ids), begin(bc.ids), end(bc.ids));
}
// For the Newton method the values must be zero
std::vector<double> values(ids.size(), 0);
MathLib::applyKnownSolution(Jac, res, x, ids, values);
}
TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear, TimeDiscretizedODESystem<ODESystemTag::FirstOrderImplicitQuasilinear,
NonlinearSolverTag::Picard>:: NonlinearSolverTag::Picard>::
TimeDiscretizedODESystem(const int process_id, ODE& ode, TimeDiscretizedODESystem(const int process_id, ODE& ode,
......
...@@ -108,6 +108,9 @@ public: ...@@ -108,6 +108,9 @@ 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 applyKnownSolutionsPETScSNES(GlobalMatrix& Jac, GlobalVector& res,
GlobalVector& x) const override;
void updateConstraints(GlobalVector& lower, GlobalVector& upper, void updateConstraints(GlobalVector& lower, GlobalVector& upper,
int const process_id) override int const process_id) 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