1 /*!
2  * \file   PlasticInelasticFlow.cxx
3  * \brief
4  * \author Thomas Helfer
5  * \date   28/03/2018
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #include "TFEL/Glossary/Glossary.hxx"
15 #include "TFEL/Glossary/GlossaryEntry.hxx"
16 #include "MFront/ImplicitDSLBase.hxx"
17 #include "MFront/NonLinearSystemSolver.hxx"
18 #include "MFront/BehaviourBrick/BrickUtilities.hxx"
19 #include "MFront/BehaviourBrick/StressCriterion.hxx"
20 #include "MFront/BehaviourBrick/StressPotential.hxx"
21 #include "MFront/BehaviourBrick/IsotropicHardeningRule.hxx"
22 #include "MFront/BehaviourBrick/KinematicHardeningRule.hxx"
23 #include "MFront/BehaviourBrick/OptionDescription.hxx"
24 #include "MFront/BehaviourBrick/PlasticInelasticFlow.hxx"
25 
26 namespace mfront {
27 
28   namespace bbrick {
29 
initialize(BehaviourDescription & bd,AbstractBehaviourDSL & dsl,const std::string & id,const DataMap & d)30     void PlasticInelasticFlow::initialize(BehaviourDescription& bd,
31                                           AbstractBehaviourDSL& dsl,
32                                           const std::string& id,
33                                           const DataMap& d) {
34       using namespace tfel::glossary;
35       InelasticFlowBase::initialize(bd, dsl, id, d);
36       tfel::raise_if(this->ihrs.empty(),
37                      "PlasticInelasticFlow::initialize:"
38                      "no isotropic hardening rule defined");
39       if (id.empty()) {
40         addStateVariable(bd, "strain", "p", Glossary::EquivalentPlasticStrain);
41       } else {
42         addStateVariable(
43             bd, "strain", "p" + id,
44             static_cast<const std::string&>(Glossary::EquivalentPlasticStrain) +
45                 id);
46       }
47     }  // end of PlasticInelasticFlow::initialize
48 
buildFlowImplicitEquations(const BehaviourDescription & bd,const StressPotential & sp,const std::string & id,const bool b) const49     std::string PlasticInelasticFlow::buildFlowImplicitEquations(
50         const BehaviourDescription& bd,
51         const StressPotential& sp,
52         const std::string& id,
53         const bool b) const {
54       auto c = std::string{};
55       tfel::raise_if(this->ihrs.empty(),
56                      "PlasticInelasticFlow::buildFlowImplicitEquations :"
57                      "no isotropic hardening rule defined");
58       const auto snf = sp.getStressNormalisationFactor(bd);
59       const auto R = "R" + id;
60       const auto fp = "fp" + id;
61       const auto seq = "seq" + id;
62       const auto dseq_ds = "dseq" + id + "_ds" + id;
63       if (b) {
64         const auto dR_ddp = "dR" + id + "_ddp" + id;
65         const auto dfp_ddp = "dfp" + id + "_ddp" + id;
66         c += computeElasticLimitAndDerivative(this->ihrs, id);
67         c += fp + " = (" + seq + "-" + R + ")/("+snf+");\n";
68         c += sp.computeDerivatives(bd, "strain", "p" + id,
69                                    dseq_ds + "/(" + snf + ")",
70                                    this->sc->isNormalDeviatoric());
71         c += "if(" + dR_ddp + ">0){\n";
72         c += dfp_ddp + " = -1*std::max(real(1.e-12),(" + dR_ddp +
73              ")/("+snf+"));\n";
74         c += "} else {\n";
75         c += dfp_ddp + " = -1*std::min(-real(1.e-12),(" + dR_ddp +
76              ")/("+snf+"));\n";
77         c += "}\n";
78         auto kid = decltype(khrs.size()){};
79         for (const auto& khr : khrs) {
80           c += khr->computeDerivatives("p", "-dseq_ds/(" + snf + ")", id,
81                                        std::to_string(kid));
82           ++kid;
83         }
84       } else {
85         c += computeElasticLimit(this->ihrs, id);
86         c += fp + " = (" + seq + "-" + R + ")/("+snf+");\n";
87       }
88       return c;
89     }  // end of PlasticInelasticFlow::buildFlowImplicitEquations
90 
91     PlasticInelasticFlow::~PlasticInelasticFlow() = default;
92 
93   }  // end of namespace bbrick
94 
95 }  // end of namespace mfront
96