Assemble and solve the equation system.
240 auto& minus_delta_x =
244 bool error_norms_met =
false;
256 double time_dirichlet = 0.0;
259 time_iteration.
start();
261 timer_dirichlet.
start();
262 sys.computeKnownSolutions(*x[process_id], process_id);
263 sys.applyKnownSolutions(*x[process_id]);
264 time_dirichlet += timer_dirichlet.
elapsed();
266 sys.preIteration(iteration, *x[process_id]);
269 time_assembly.
start();
272 sys.assemble(x, x_prev, process_id);
274 catch (AssemblyException
const& e)
276 ERR(
"Abort nonlinear iteration. Repeating timestep. Reason: {:s}",
278 error_norms_met =
false;
282 sys.getResidual(*x[process_id], *x_prev[process_id], res);
284 INFO(
"[time] Assembly took {:g} s.", time_assembly.
elapsed());
290 minus_delta_x.setZero();
292 timer_dirichlet.
start();
293 sys.applyKnownSolutionsNewton(J, res, minus_delta_x);
294 time_dirichlet += timer_dirichlet.
elapsed();
295 INFO(
"[time] Applying Dirichlet BCs took {:g} s.", time_dirichlet);
303 time_linear_solver.
start();
305 INFO(
"[time] Linear solver took {:g} s.", time_linear_solver.
elapsed());
307 if (!iteration_succeeded)
309 ERR(
"Newton: The linear solver failed.");
318 std::vector<GlobalVector*> x_new{x};
324 if (postIterationCallback)
326 postIterationCallback(iteration, x_new);
329 switch (sys.postIteration(*x_new[process_id]))
334 ERR(
"Newton: The postIteration() hook reported a "
335 "non-recoverable error.");
336 iteration_succeeded =
false;
340 "Newton: The postIteration() hook decided that this "
341 "iteration has to be repeated.");
354 if (!iteration_succeeded)
357 error_norms_met =
false;
363 error_norms_met =
true;
377 INFO(
"[time] Iteration #{:d} took {:g} s.", iteration,
395 ERR(
"Newton: Could not solve the given nonlinear system within {:d} "
404 return {error_norms_met, iteration};
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
double elapsed() const
Get the elapsed time in seconds.
void start()
Start the timer.
bool solve(EigenMatrix &A, EigenVector &b, EigenVector &x)
virtual void preFirstIteration()
virtual void checkResidual(GlobalVector const &residual)=0
Check if the residual satisfies the convergence criterion.
virtual bool hasResidualCheck() const =0
virtual bool isSatisfied() const
Tell if the convergence criterion is satisfied.
virtual void checkDeltaX(GlobalVector const &minus_delta_x, GlobalVector const &x)=0
virtual bool hasDeltaXCheck() const =0
virtual GlobalMatrix & getMatrix(std::size_t &id)=0
Get an uninitialized matrix with the given id.
virtual void releaseMatrix(GlobalMatrix const &A)=0
std::size_t _J_id
ID of the Jacobian matrix.
std::size_t _x_new_id
ID of the vector storing .
std::size_t _res_id
ID of the residual vector.
std::size_t _minus_delta_x_id
ID of the vector.
void axpy(PETScVector &y, double const a, PETScVector const &x)
void copy(PETScVector const &x, PETScVector &y)
static NUMLIB_EXPORT MatrixProvider & provider