95 prefix = prefix +
"_";
103 PetscReal atol, rtol, stol;
105 SNESGetTolerances(
_snes_solver, &atol, &rtol, &stol,
nullptr, &maxf);
106 SNESSetTolerances(
_snes_solver, atol, rtol, stol, maxiter, maxf);
110 PetscOptionsView(
nullptr, PETSC_VIEWER_STDOUT_WORLD);
142 std::vector<GlobalVector*>& x,
143 std::vector<GlobalVector*>
const& x_prev,
144 std::function<
void(
int, std::vector<GlobalVector*>
const&)>
const&
146 int const process_id)
148 DBUG(
"PETScNonlinearSolver: solve()");
149 using TimeDiscretizedSystem =
155 DBUG(
"PETScNonlinearSolver: create vectors");
158 system->getMatrixSpecifications(process_id),
_jacobian_id);
160 system->getMatrixSpecifications(process_id),
_residual_id);
167 double time_dirichlet = 0.0;
169 timer_dirichlet.
start();
170 system->computeKnownSolutions(*x[process_id], process_id);
171 system->applyKnownSolutions(*x[process_id]);
172 time_dirichlet += timer_dirichlet.
elapsed();
173 INFO(
"[time] Applying Dirichlet BCs took {} s.", time_dirichlet);
178 system->getMatrixSpecifications(process_id),
_petsc_x_id);
181 PetscContext petsc_context{
_equation_system, x, x_prev, &r, &J, process_id};
183 DBUG(
"PETScNonlinearSolver: set function");
184 SNESSetFunction(
_snes_solver, r_snes.getRawVector(), updateResidual,
187 DBUG(
"PETScNonlinearSolver: set jacobian");
189 SNESSetJacobian(
_snes_solver, J_snes.getRawMatrix(), J_snes.getRawMatrix(),
190 updateJacobian, &petsc_context);
192 std::unique_ptr<GlobalVector> xl =
nullptr;
193 std::unique_ptr<GlobalVector> xu =
nullptr;
197 if ((std::strcmp(snes_type, SNESVINEWTONRSLS) == 0) ||
198 (std::strcmp(snes_type, SNESVINEWTONSSLS) == 0))
201 DBUG(
"PETScNonlinearSolver: set constraints");
203 system->getMatrixSpecifications(process_id));
205 system->getMatrixSpecifications(process_id));
207 system->updateConstraints(*xl, *xu, process_id);
211 SNESVISetVariableBounds(
_snes_solver, xl->getRawVector(),
215 DBUG(
"PETScNonlinearSolver: call SNESSolve");
216 SNESSolve(
_snes_solver,
nullptr, x_snes.getRawVector());
218 SNESConvergedReason reason;
224 INFO(
"PETScSNES used {} iterations.", iterations);
235 return {reason >= 0, iterations};
NonlinearSolverStatus solve(std::vector< GlobalVector * > &x, std::vector< GlobalVector * > const &x_prev, std::function< void(int, std::vector< GlobalVector * > const &)> const &postIterationCallback, int const process_id) override
std::vector< GlobalVector * > & x
NumLib::NonlinearSystem< NumLib::NonlinearSolverTag::Newton > System
std::vector< GlobalVector * > const & x_prev