LCOV - code coverage report
Current view: top level - models/solid_mechanics - PowerLawKinematicHardeningStaticRecovery.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.8 % 31 30
Test Date: 2025-10-02 16:03:03 Functions: 100.0 % 3 3

            Line data    Source code
       1              : // Copyright 2024, UChicago Argonne, LLC
       2              : // All Rights Reserved
       3              : // Software Name: NEML2 -- the New Engineering material Model Library, version 2
       4              : // By: Argonne National Laboratory
       5              : // OPEN SOURCE LICENSE (MIT)
       6              : //
       7              : // Permission is hereby granted, free of charge, to any person obtaining a copy
       8              : // of this software and associated documentation files (the "Software"), to deal
       9              : // in the Software without restriction, including without limitation the rights
      10              : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      11              : // copies of the Software, and to permit persons to whom the Software is
      12              : // furnished to do so, subject to the following conditions:
      13              : //
      14              : // The above copyright notice and this permission notice shall be included in
      15              : // all copies or substantial portions of the Software.
      16              : //
      17              : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      18              : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      19              : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      20              : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      21              : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      22              : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      23              : // THE SOFTWARE.
      24              : 
      25              : #include "neml2/models/solid_mechanics/PowerLawKinematicHardeningStaticRecovery.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : #include "neml2/tensors/SR2.h"
      28              : #include "neml2/tensors/SSR4.h"
      29              : #include "neml2/tensors/functions/pow.h"
      30              : #include "neml2/tensors/functions/log.h"
      31              : 
      32              : namespace neml2
      33              : {
      34              : register_NEML2_object(PowerLawKinematicHardeningStaticRecovery);
      35              : 
      36              : OptionSet
      37            2 : PowerLawKinematicHardeningStaticRecovery::expected_options()
      38              : {
      39            2 :   OptionSet options = KinematicHardeningStaticRecovery::expected_options();
      40            2 :   options.doc() +=
      41              :       " This particular model uses a power law for recovery "
      42              :       "\\f$ \\dot{X} = - \\left(\\frac{\\lVert X \\rVert}{\\tau}\\right)^{n-1} \\frac{X}{\\tau} "
      43              :       "\\f$"
      44              :       "where \\f$ n \\f$ is the power law recovery exponent and \\f$\\tau\\f$ is the recovery "
      45            2 :       "rate.";
      46              : 
      47            4 :   options.set_parameter<TensorName<Scalar>>("tau");
      48            4 :   options.set("tau").doc() = "Static recovery rate";
      49              : 
      50            4 :   options.set_parameter<TensorName<Scalar>>("n");
      51            2 :   options.set("n").doc() = "Static recovery exponent";
      52              : 
      53            2 :   return options;
      54            0 : }
      55              : 
      56            1 : PowerLawKinematicHardeningStaticRecovery::PowerLawKinematicHardeningStaticRecovery(
      57            1 :     const OptionSet & options)
      58              :   : KinematicHardeningStaticRecovery(options),
      59            3 :     _tau(declare_parameter<Scalar>("tau", "tau", true)),
      60            5 :     _n(declare_parameter<Scalar>("n", "n", true))
      61              : {
      62            1 : }
      63              : 
      64              : void
      65            2 : PowerLawKinematicHardeningStaticRecovery::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      66              : {
      67            2 :   auto eps = machine_precision(_X.scalar_type());
      68              :   // The effective stress
      69            2 :   auto s = SR2(_X).norm(eps);
      70              : 
      71            2 :   if (out)
      72            2 :     _X_dot = -pow(s / _tau, _n - 1) * _X / _tau;
      73              : 
      74            2 :   if (dout_din)
      75              :   {
      76            1 :     auto I = SR2::identity_map(_X.options());
      77              : 
      78            1 :     if (_X.is_dependent())
      79            2 :       _X_dot.d(_X) =
      80            3 :           -pow(s, _n - 3) * ((_n - 1) * SR2(_X).outer(SR2(_X)) + s * s * I) / pow(_tau, _n);
      81              : 
      82            3 :     if (const auto * const tau = nl_param("tau"))
      83            1 :       _X_dot.d(*tau) = _n * pow(s / _tau, _n - 1) * _X / (_tau * _tau);
      84              : 
      85            3 :     if (const auto * const n = nl_param("n"))
      86            1 :       _X_dot.d(*n) = -_X / s * pow(s / _tau, _n) * log(s / _tau);
      87            1 :   }
      88            2 : }
      89              : 
      90              : } // namespace neml2
        

Generated by: LCOV version 2.0-1