Skip to content

Commit

Permalink
Changing order of some functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus committed Mar 25, 2022
1 parent d22e9c7 commit 40fb389
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
__pycache__

_skbuild
_cmake_test_compile

docs/html/*
docs/xml/*

Expand Down
42 changes: 21 additions & 21 deletions include/FrictionQPotFEM/Generic2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ class System {
void timeStep();

/**
Make a number of time steps.
Make a number of time steps, see timeStep().
\param n Number of steps to make.
*/
void timeSteps(size_t n);
Expand Down Expand Up @@ -577,6 +577,26 @@ class System {
*/
size_t timeSteps_boundcheck(size_t n, size_t nmargin = 5);

/**
Perform a series of time-steps until:
- the next plastic event,
- equilibrium, or
- a 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*:
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
timeStepsUntilEvent(double tol = 1e-5, size_t niter_tol = 20, size_t max_iter = 10000000);

/**
Make a number of steps with the following protocol.
(1) Add a displacement \f$ \underline{v} \Delta t \f$ to each of the nodes.
Expand All @@ -601,26 +621,6 @@ class System {
template <class T>
size_t flowSteps_boundcheck(size_t n, const T& v, size_t nmargin = 5);

/**
Perform a series of time-steps until:
- the next plastic event,
- equilibrium, or
- a 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*:
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
timeStepsUntilEvent(double tol = 1e-5, size_t niter_tol = 20, size_t max_iter = 10000000);

/**
Minimise energy: run System::timeStep until a mechanical equilibrium has been reached.
Expand Down
73 changes: 37 additions & 36 deletions include/FrictionQPotFEM/Generic2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,6 @@ inline void System::setFext(const T& fext)
xt::noalias(m_fext) = fext;
}

inline void System::quench()
{
m_v.fill(0.0);
m_a.fill(0.0);
}

inline auto System::elastic() const
{
return m_elem_elas;
Expand Down Expand Up @@ -477,6 +471,13 @@ inline double System::residual() const
return r_fres;
}

inline void System::quench()
{
m_v.fill(0.0);
m_a.fill(0.0);
this->updated_v();
}

inline double System::t() const
{
return m_t;
Expand Down Expand Up @@ -1041,6 +1042,36 @@ inline size_t System::timeSteps_boundcheck(size_t n, size_t nmargin)
return n;
}

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

auto idx_n = this->plastic_CurrentIndex();

for (iiter = 1; iiter < max_iter + 1; ++iiter) {

this->timeStep();

auto idx = this->plastic_CurrentIndex();

if (xt::any(xt::not_equal(idx, idx_n))) {
return iiter;
}

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

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

return iiter;
}

template <class T>
inline void System::flowSteps(size_t n, const T& v)
{
Expand Down Expand Up @@ -1073,36 +1104,6 @@ inline size_t System::flowSteps_boundcheck(size_t n, const T& v, size_t nmargin)
return n;
}

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

auto idx_n = this->plastic_CurrentIndex();

for (iiter = 1; iiter < max_iter + 1; ++iiter) {

this->timeStep();

auto idx = this->plastic_CurrentIndex();

if (xt::any(xt::not_equal(idx, idx_n))) {
return iiter;
}

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

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

return iiter;
}

inline size_t System::minimise(double tol, size_t niter_tol, size_t max_iter)
{
FRICTIONQPOTFEM_REQUIRE(tol < 1.0);
Expand Down

0 comments on commit 40fb389

Please sign in to comment.