Skip to content

Commit

Permalink
Fix Issues #265 and #275
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfer committed Aug 8, 2022
1 parent 819e216 commit 2dc612b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 15 deletions.
4 changes: 4 additions & 0 deletions docs/web/release-notes-4.0.1.md
Expand Up @@ -19,6 +19,10 @@ eqnPrefixTemplate: "($$i$$)"

# Issues fixed

## Issue #275: [mtest] `MTest` segfaults with generic behaviours having additional tangent operator blocks

For more details, see <https://github.com/thelfer/tfel/issues/275>

## Issue #257: [mfront] Warnings in behavior

For more details, see <https://github.com/thelfer/tfel/issues/257>
Expand Down
4 changes: 4 additions & 0 deletions docs/web/release-notes-4.1.md
Expand Up @@ -2021,6 +2021,10 @@ This feature is described in Section @sec:tfel_4.1:tfel_math:issue_266.

For more details, see <https://github.com/thelfer/tfel/issues/266>

## Issue #265: [mfront] Add MTest file generation capability for `generic` behaviours

For more details, see <https://github.com/thelfer/tfel/issues/265>

## Issue #264: Add support to compute linear intepolation

This feature is described in Section @sec:tfel_4.1:tfel_math:issue_264.
Expand Down
83 changes: 68 additions & 15 deletions mtest/src/GenericBehaviour.cxx
Expand Up @@ -271,13 +271,62 @@ namespace mtest {
"GenericBehaviour::allocate: "
"unsupported tangent operator type");
}
} else if ((this->btype == 1u) || (btype == 3u)) {
wk.D.resize(nth, ndv);
wk.k.resize(nth, ndv);
wk.kt.resize(nth, ndv);
} else {
constexpr unsigned short one = 1u;
const auto enth = std::max(nth, one);
const auto endv = std::max(ndv, one);
wk.D.resize(enth, endv);
wk.k.resize(enth, endv);
using size_type = tfel::math::matrix<real>::size_type;
constexpr auto one = size_type{1u};
const auto endv = ndv == 0u ? one : ndv;
const auto enth = nth == 0u ? one : nth;
const auto tobs_size = [this] {
const auto h = this->getHypothesis();
auto s = size_type{};
for (const auto& to : this->getTangentOperatorBlocks()) {
const auto ptf =
std::find(this->thnames.begin(), this->thnames.end(), to.first);
const auto piv =
std::find(this->ivnames.begin(), this->ivnames.end(), to.first);
const auto pg =
std::find(this->gnames.begin(), this->gnames.end(), to.second);
const auto pev =
std::find(this->evnames.begin(), this->evnames.end(), to.second);
const auto to_ro = [&, this]() -> size_type {
if (pev != this->evnames.end()) {
return mtest::getVariableSize(
this->evtypes[pev - this->evnames.begin()], h);
}
if (pg == this->gnames.end()) {
tfel::raise(
"GenericBehaviour::call_behaviour(1): "
"invalid tangent operator block ('" +
to.first + "'" + " vs '" + to.second + "')");
}
return mtest::getVariableSize(
this->gtypes[pg - this->gnames.begin()], h);
}();
const auto to_co = [&, this]() -> size_type {
if (piv != this->ivnames.end()) {
return mtest::getVariableSize(
this->ivtypes[piv - this->ivnames.begin()], h);
}
if (ptf == this->thnames.end()) {
tfel::raise(
"GenericBehaviour::call_behaviour(2): "
"invalid tangent operator block ('" +
to.first + "'" + " vs '" + to.second + "')");
}
return mtest::getVariableSize(
this->thtypes[ptf - this->thnames.begin()], h);
}();
s += to_ro * to_co;
}
return s;
}();
wk.D.resize(std::max(tobs_size, one), 1u);
wk.kt.resize(enth, endv);
wk.k.resize(enth, endv);
}
wk.nk.resize(nth, ndv);
wk.ne.resize(ndv);
Expand Down Expand Up @@ -353,7 +402,8 @@ namespace mtest {
return &t[0];
};
throw_if(wk.mps.size() != s.mprops1.size(),
"temporary material properties vector was not allocated properly");
"temporary material properties vector was not allocated "
"properly");
throw_if(wk.ivs0.size() != s.iv0.size(),
"temporary internal state variable vector was not allocated "
"properly");
Expand Down Expand Up @@ -385,9 +435,12 @@ namespace mtest {
} else {
throw_if(true, "unsupported tangent operator");
}
} else if ((this->btype == 1u) || (this->btype == 3u)) {
throw_if(((wk.D.getNbRows() != Kt.getNbRows()) ||
(wk.D.getNbCols() != Kt.getNbCols())),
"the memory has not been allocated correctly");
} else {
throw_if((wk.D.getNbRows() != Kt.getNbRows()) ||
(wk.D.getNbCols() != Kt.getNbCols()),
throw_if(wk.D.getNbCols() != 1u,
"the memory has not been allocated correctly");
}
std::fill(wk.D.begin(), wk.D.end(), 0.);
Expand Down Expand Up @@ -484,7 +537,8 @@ namespace mtest {
}
// turn back the gradients in the global frame
if (stype == 1u) {
// here we use the fact that d.s1.gradients is a pointer to &(wk.e0[0])
// here we use the fact that d.s1.gradients is a pointer to
// &(wk.e0[0])
this->rg_fct(&(wk.e0[0]), &(wk.e0[0]), ir.begin());
this->rg_fct(&(wk.e1[0]), &(wk.e1[0]), ir.begin());
}
Expand All @@ -506,7 +560,7 @@ namespace mtest {
if (this->stype == 1u) {
this->rto_fct(&(wk.D(0, 0)), &(wk.D(0, 0)), s.r.begin());
}
if ((this->gtypes.size() == 1u) && (this->thtypes.size() == 1u)) {
if (this->btype != 0u) {
for (unsigned short i = 0; i != nth; ++i) {
for (unsigned short j = 0; j != ndv; ++j) {
Kt(i, j) = wk.D(i, j);
Expand Down Expand Up @@ -534,7 +588,8 @@ namespace mtest {
std::find(this->evnames.begin(), this->evnames.end(), to.second);
const auto to_ro = [&, this]() -> size_type {
if (pev != this->evnames.end()) {
return 1;
return mtest::getVariableSize(
this->evtypes[pev - this->evnames.begin()], h);
}
if (pg == this->gnames.end()) {
tfel::raise(
Expand Down Expand Up @@ -650,8 +705,7 @@ namespace mtest {
} else {
throw_if(true, "internal error, unexpected stress measure");
}
} // end of
// GenericBehaviour::executeFiniteStrainBehaviourStressPreProcessing
} // end of executeFiniteStrainBehaviourStressPreProcessing

void
GenericBehaviour::executeFiniteStrainBehaviourTangentOperatorPreProcessing(
Expand All @@ -671,8 +725,7 @@ namespace mtest {
"internal error, unexpected tangent operator type");
}
}
} // end of
// GenericBehaviour::executeFiniteStrainBehaviourTangentOperatorPreProcessing
} // end of executeFiniteStrainBehaviourTangentOperatorPreProcessing

void GenericBehaviour::executeFiniteStrainBehaviourStressPostProcessing(
BehaviourWorkSpace& wk, mfront::gb::BehaviourData& d) const {
Expand Down

0 comments on commit 2dc612b

Please sign in to comment.