Skip to content

Commit

Permalink
Adding "minimise_truncate" overload to deal with triggering (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored Feb 8, 2022
1 parent c28379d commit 931f9d2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
18 changes: 18 additions & 0 deletions include/FrictionQPotFEM/Generic2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,24 @@ class System {
size_t niter_tol = 20,
size_t max_iter = 10000000);

/**
\copydoc System::minimise_truncate(size_t, size_t, double, size_t, size_t)
This overload can be used to specify a reference state when manually triggering.
If triggering is done before calling this function, already one block yielded,
making `A_truncate` and `S_truncate` inaccurate.
\param idx_n Reference potential index of the first integration point.
*/
template <class T>
size_t minimise_truncate(
const T& idx_n,
size_t A_truncate = 0,
size_t S_truncate = 0,
double tol = 1e-5,
size_t niter_tol = 20,
size_t max_iter = 10000000);

/**
Get the displacement field that corresponds to an affine simple shear of a certain strain.
The displacement of the bottom boundary is zero, while it is maximal for the top boundary.
Expand Down
16 changes: 14 additions & 2 deletions include/FrictionQPotFEM/Generic2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,21 +988,22 @@ System::minimise_boundcheck(size_t nmargin, double tol, size_t niter_tol, size_t
return 0; // irrelevant, the code never goes here
}

template <class T>
inline size_t System::minimise_truncate(
const T& idx_n,
size_t A_truncate,
size_t S_truncate,
double tol,
size_t niter_tol,
size_t max_iter)
{
FRICTIONQPOTFEM_REQUIRE(xt::has_shape(idx_n, std::array<size_t, 1>{m_N}));
FRICTIONQPOTFEM_REQUIRE(S_truncate == 0);
FRICTIONQPOTFEM_REQUIRE(A_truncate > 0);
FRICTIONQPOTFEM_REQUIRE(tol < 1.0);
double tol2 = tol * tol;
GooseFEM::Iterate::StopList residuals(niter_tol);

xt::xtensor<size_t, 1> idx_n = xt::view(this->plastic_CurrentIndex(), xt::all(), 0);

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

this->timeStep();
Expand All @@ -1025,6 +1026,17 @@ inline size_t System::minimise_truncate(
return 0; // irrelevant, the code never goes here
}

inline size_t System::minimise_truncate(
size_t A_truncate,
size_t S_truncate,
double tol,
size_t niter_tol,
size_t max_iter)
{
xt::xtensor<size_t, 1> idx_n = xt::view(this->plastic_CurrentIndex(), xt::all(), 0);
return this->minimise_truncate(idx_n, A_truncate, S_truncate, tol, niter_tol, max_iter);
}

inline xt::xtensor<double, 2> System::affineSimpleShear(double delta_gamma) const
{
xt::xtensor<double, 2> ret = xt::zeros_like(m_u);
Expand Down
16 changes: 15 additions & 1 deletion python/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,28 @@ PYBIND11_MODULE(_FrictionQPotFEM, mod)

cls.def(
"minimise_truncate",
&SUB::System::minimise_truncate,
static_cast<size_t (SUB::System::*)(size_t, size_t, double, size_t, size_t)>(
&SUB::System::minimise_truncate),
"minimise_truncate",
py::arg("A_truncate") = 0,
py::arg("S_truncate") = 0,
py::arg("tol") = 1e-5,
py::arg("niter_tol") = 20,
py::arg("max_iter") = 10000000);

cls.def(
"minimise_truncate",
static_cast<size_t (SUB::System::*)(
const xt::pytensor<size_t, 1>&, size_t, size_t, double, size_t, size_t)>(
&SUB::System::minimise_truncate<xt::pytensor<size_t, 1>>),
"minimise_truncate",
py::arg("idx_n"),
py::arg("A_truncate") = 0,
py::arg("S_truncate") = 0,
py::arg("tol") = 1e-5,
py::arg("niter_tol") = 20,
py::arg("max_iter") = 10000000);

cls.def(
"affineSimpleShear",
&SUB::System::affineSimpleShear,
Expand Down

0 comments on commit 931f9d2

Please sign in to comment.