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,
146 std::vector<GlobalVector*>
const&)>
const& ,
147 int const process_id)
149 DBUG(
"PETScNonlinearSolver: solve()");
150 using TimeDiscretizedSystem =
156 DBUG(
"PETScNonlinearSolver: create vectors");
159 system->getMatrixSpecifications(process_id),
_jacobian_id);
161 system->getMatrixSpecifications(process_id),
_residual_id);
168 double time_dirichlet = 0.0;
170 timer_dirichlet.
start();
171 system->computeKnownSolutions(*x[process_id], process_id);
172 system->applyKnownSolutions(*x[process_id]);
173 time_dirichlet += timer_dirichlet.
elapsed();
174 INFO(
"[time] Applying Dirichlet BCs took {} s.", time_dirichlet);
179 system->getMatrixSpecifications(process_id),
_petsc_x_id);
182 PetscContext petsc_context{
_equation_system, x, x_prev, &r, &J, process_id};
184 DBUG(
"PETScNonlinearSolver: set function");
185 SNESSetFunction(
_snes_solver, r_snes.getRawVector(), updateResidual,
188 DBUG(
"PETScNonlinearSolver: set jacobian");
190 SNESSetJacobian(
_snes_solver, J_snes.getRawMatrix(), J_snes.getRawMatrix(),
191 updateJacobian, &petsc_context);
193 std::unique_ptr<GlobalVector> xl =
nullptr;
194 std::unique_ptr<GlobalVector> xu =
nullptr;
198 if ((std::strcmp(snes_type, SNESVINEWTONRSLS) == 0) ||
199 (std::strcmp(snes_type, SNESVINEWTONSSLS) == 0))
202 DBUG(
"PETScNonlinearSolver: set constraints");
204 system->getMatrixSpecifications(process_id));
206 system->getMatrixSpecifications(process_id));
208 system->updateConstraints(*xl, *xu, process_id);
212 SNESVISetVariableBounds(
_snes_solver, xl->getRawVector(),
216 DBUG(
"PETScNonlinearSolver: call SNESSolve");
217 SNESSolve(
_snes_solver,
nullptr, x_snes.getRawVector());
219 SNESConvergedReason reason;
225 INFO(
"PETScSNES used {} iterations.", iterations);
236 return {reason >= 0, iterations};
NonlinearSolverStatus solve(std::vector< GlobalVector * > &x, std::vector< GlobalVector * > const &x_prev, std::function< void(int, bool, 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