LCOV - code coverage report
Current view: top level - models/solid_mechanics - KocksMeckingRateSensitivity.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.2 % 57 56
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/KocksMeckingRateSensitivity.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : 
      28              : namespace neml2
      29              : {
      30              : register_NEML2_object(KocksMeckingRateSensitivity);
      31              : 
      32              : OptionSet
      33            2 : KocksMeckingRateSensitivity::expected_options()
      34              : {
      35            2 :   OptionSet options = Model::expected_options();
      36            2 :   options.doc() =
      37              :       "Calculates the temperature-dependent rate sensitivity for a Perzyna-type model using the "
      38              :       "Kocks-Mecking model.  The value is \\f$ n = \\frac{\\mu b^3}{k T A} \\f$ with \\f$ \\mu "
      39              :       "\\f$ the shear modulus, \\f$ b \\f$ the Burgers vector, \\f$  k\\f$ the Boltzmann constant, "
      40            2 :       "\\f$ T \\f$ absolute temperature, and \\f$ A \\f$ the Kocks-Mecking slope parameter.";
      41              : 
      42            4 :   options.set<bool>("define_second_derivatives") = true;
      43              : 
      44            4 :   options.set_parameter<TensorName<Scalar>>("A");
      45            4 :   options.set("A").doc() = "The Kocks-Mecking slope parameter";
      46            4 :   options.set_parameter<TensorName<Scalar>>("shear_modulus");
      47            4 :   options.set("shear_modulus").doc() = "The shear modulus";
      48              : 
      49            4 :   options.set<double>("k");
      50            4 :   options.set("k").doc() = "Boltzmann constant";
      51            4 :   options.set<double>("b");
      52            2 :   options.set("b").doc() = "The Burgers vector";
      53              : 
      54            6 :   options.set_input("temperature") = VariableName(FORCES, "T");
      55            2 :   options.set("temperature").doc() = "Absolute temperature";
      56              : 
      57            2 :   return options;
      58            0 : }
      59              : 
      60            2 : KocksMeckingRateSensitivity::KocksMeckingRateSensitivity(const OptionSet & options)
      61              :   : Model(options),
      62            6 :     _A(declare_parameter<Scalar>("A", "A", /*allow_nonlinear=*/true)),
      63           10 :     _mu(declare_parameter<Scalar>("mu", "shear_modulus", /*allow_nonlinear=*/true)),
      64            4 :     _k(options.get<double>("k")),
      65           10 :     _b3(options.get<double>("b") * options.get<double>("b") * options.get<double>("b")),
      66            2 :     _T(declare_input_variable<Scalar>("temperature")),
      67            4 :     _m(declare_output_variable<Scalar>(VariableName(PARAMETERS, name())))
      68              : {
      69            2 : }
      70              : 
      71              : void
      72            6 : KocksMeckingRateSensitivity::set_value(bool out, bool dout_din, bool d2out_din2)
      73              : {
      74            6 :   if (out)
      75            4 :     _m = -_mu * _b3 / (_k * _T * _A);
      76              : 
      77            6 :   if (dout_din)
      78              :   {
      79            3 :     if (_T.is_dependent())
      80            3 :       _m.d(_T) = _b3 * _mu / (_A * _k * _T * _T);
      81            9 :     if (const auto * const mu = nl_param("mu"))
      82            2 :       _m.d(*mu) = -_b3 / (_A * _k * _T);
      83            9 :     if (const auto * const A = nl_param("A"))
      84            2 :       _m.d(*A) = _b3 * _mu / (_A * _A * _k * _T);
      85              :   }
      86              : 
      87            6 :   if (d2out_din2)
      88              :   {
      89              :     // T, T
      90            2 :     if (_T.is_dependent())
      91            2 :       _m.d(_T, _T) = -2.0 * _b3 * _mu / (_A * _k * _T * _T * _T);
      92              : 
      93            6 :     if (const auto * const A = nl_param("A"))
      94              :     {
      95              :       // A, A
      96            1 :       _m.d(*A, *A) = -2.0 * _b3 * _mu / (_A * _A * _A * _k * _T);
      97              :       // A, T and T, A
      98            1 :       if (_T.is_dependent())
      99              :       {
     100            1 :         auto AT = -_b3 * _mu / (_A * _A * _k * _T * _T);
     101            1 :         _m.d(*A, _T) = AT;
     102            1 :         _m.d(_T, *A) = AT;
     103            1 :       }
     104              :     }
     105              : 
     106            6 :     if (const auto * const mu = nl_param("mu"))
     107              :     {
     108              :       // mu, T and T, mu
     109            1 :       if (_T.is_dependent())
     110              :       {
     111            1 :         auto MT = _b3 / (_A * _k * _T * _T);
     112            1 :         _m.d(*mu, _T) = MT;
     113            1 :         _m.d(_T, *mu) = MT;
     114            1 :       }
     115              : 
     116            3 :       if (const auto * const A = nl_param("A"))
     117              :       {
     118              :         // mu, A and A, mu
     119            1 :         auto MA = _b3 / (_A * _A * _k * _T);
     120            1 :         _m.d(*mu, *A) = MA;
     121            1 :         _m.d(*A, *mu) = MA;
     122            1 :       }
     123              :     }
     124              :   }
     125            6 : }
     126              : } // namespace neml2
        

Generated by: LCOV version 2.0-1