Skip to content

Commit

Permalink
Adding "timeSteps_residualcheck" (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Feb 17, 2022
1 parent 931f9d2 commit 378e087
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
41 changes: 23 additions & 18 deletions include/FrictionQPotFEM/Generic2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,15 +527,30 @@ class System {
*/
void timeSteps(size_t n);

/**
Make a number of time steps.
\param n Number of steps to make.
\param tol Relative force tolerance for equilibrium. See System::residual for definition.
\param niter_tol Enforce the residual check for ``niter_tol`` consecutive increments.
\return
- *Number of iterations*:
If stopped by a plastic event or the maximum number of iterations.
- `0`:
If stopped when the residual is reached
(so no plastic event occurred and the number of iterations was lower than the maximum).
*/
size_t timeSteps_residualcheck(size_t n, double tol = 1e-5, size_t niter_tol = 20);

/**
\copydoc timeSteps(size_t)
This function stops if the yield-index in any of the plastic elements is close the end.
In that case the function returns zero, in all other cases the function returns a
positive number.
\param nmargin
Number of potentials to leave as margin.
\param nmargin Number of potentials to leave as margin.
*/
size_t timeSteps_boundcheck(size_t n, size_t nmargin = 5);

Expand Down Expand Up @@ -569,14 +584,9 @@ class System {
- equilibrium, or
- the maximum number of iterations.
\param tol
Relative force tolerance for equilibrium. See System::residual for definition.
\param niter_tol
Enforce the residual check for ``niter_tol`` consecutive increments.
\param max_iter
Maximum number of iterations.
\param tol Relative force tolerance for equilibrium. See System::residual for definition.
\param niter_tol Enforce the residual check for ``niter_tol`` consecutive increments.
\param max_iter Maximum number of iterations.
\return
- *Number of iterations*:
Expand All @@ -591,14 +601,9 @@ class System {
/**
Minimise energy: run System::timeStep until a mechanical equilibrium has been reached.
\param tol
Relative force tolerance for equilibrium. See System::residual for definition.
\param niter_tol
Enforce the residual check for ``niter_tol`` consecutive increments.
\param max_iter
Maximum number of iterations. Throws ``std::runtime_error`` otherwise.
\param tol Relative force tolerance for equilibrium. See System::residual for definition.
\param niter_tol Enforce the residual check for ``niter_tol`` consecutive increments.
\param max_iter Maximum number of iterations. Throws ``std::runtime_error`` otherwise.
\return The number of iterations.
*/
Expand Down
21 changes: 21 additions & 0 deletions include/FrictionQPotFEM/Generic2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,27 @@ inline void System::timeSteps(size_t n)
}
}

inline size_t System::timeSteps_residualcheck(size_t n, double tol, size_t niter_tol)
{
FRICTIONQPOTFEM_REQUIRE(tol < 1.0);
double tol2 = tol * tol;
GooseFEM::Iterate::StopList residuals(niter_tol);

for (size_t i = 0; i < n; ++i) {

this->timeStep();

residuals.roll_insert(this->residual());

if ((residuals.descending() && residuals.all_less(tol)) || residuals.all_less(tol2)) {
this->quench();
return 0;
}
}

return n;
}

inline size_t System::timeSteps_boundcheck(size_t n, size_t nmargin)
{
if (!this->boundcheck_right(nmargin)) {
Expand Down
10 changes: 9 additions & 1 deletion python/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,15 @@ PYBIND11_MODULE(_FrictionQPotFEM, mod)
py::arg("iterative") = false);

cls.def("timeStep", &SUB::System::timeStep, "timeStep");
cls.def("timeSteps", &SUB::System::timeSteps, "timeSteps", py::arg("n"));
cls.def("timeSteps", &SUB::System::timeSteps, "timeSteps");

cls.def(
"timeSteps_residualcheck",
&SUB::System::timeSteps_residualcheck,
"timeSteps_residualcheck",
py::arg("n"),
py::arg("tol") = 1e-5,
py::arg("niter_tol") = 20);

cls.def(
"timeSteps_boundcheck",
Expand Down

0 comments on commit 378e087

Please sign in to comment.