LCOV - code coverage report
Current view: top level - models/solid_mechanics - KocksMeckingYieldStress.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/KocksMeckingYieldStress.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : #include "neml2/tensors/functions/exp.h"
      28              : 
      29              : namespace neml2
      30              : {
      31              : register_NEML2_object(KocksMeckingYieldStress);
      32              : 
      33              : OptionSet
      34            2 : KocksMeckingYieldStress::expected_options()
      35              : {
      36            2 :   OptionSet options = Model::expected_options();
      37              : 
      38            2 :   options.doc() = "The yield stress given by the Kocks-Mecking model.  \\f$ \\sigma_y = \\exp{C} "
      39              :                   "\\mu \\f$ with \\f$ \\mu \\f$ the shear modulus and \\f$ C \\f$ the horizontal "
      40            2 :                   "intercept from the Kocks-Mecking diagram.";
      41              : 
      42            4 :   options.set<bool>("define_second_derivatives") = true;
      43              : 
      44            4 :   options.set_parameter<TensorName<Scalar>>("C");
      45            4 :   options.set("C").doc() = "The Kocks-Mecking horizontal intercept";
      46            4 :   options.set_parameter<TensorName<Scalar>>("shear_modulus");
      47            2 :   options.set("shear_modulus").doc() = "The shear modulus";
      48              : 
      49            2 :   return options;
      50            0 : }
      51              : 
      52            2 : KocksMeckingYieldStress::KocksMeckingYieldStress(const OptionSet & options)
      53              :   : Model(options),
      54            6 :     _C(declare_parameter<Scalar>("C", "C", /*allow_nonlinear=*/true)),
      55            8 :     _mu(declare_parameter<Scalar>("mu", "shear_modulus", /*allow_nonlinear=*/true)),
      56            4 :     _tau(declare_output_variable<Scalar>(VariableName(PARAMETERS, name())))
      57              : {
      58            2 : }
      59              : 
      60              : void
      61            5 : KocksMeckingYieldStress::set_value(bool out, bool dout_din, bool d2out_din2)
      62              : {
      63            5 :   if (out)
      64            4 :     _tau = _mu * exp(_C);
      65              : 
      66            5 :   if (dout_din)
      67              :   {
      68            9 :     if (const auto * const mu = nl_param("mu"))
      69            2 :       _tau.d(*mu) = exp(_C);
      70              : 
      71            9 :     if (const auto * const C = nl_param("C"))
      72            2 :       _tau.d(*C) = _mu * exp(_C);
      73              :   }
      74              : 
      75            5 :   if (d2out_din2)
      76              :   {
      77            3 :     if (const auto * const C = nl_param("C"))
      78              :     {
      79            1 :       _tau.d(*C, *C) = _mu * exp(_C);
      80              : 
      81            3 :       if (const auto * const mu = nl_param("mu"))
      82              :       {
      83            1 :         _tau.d(*C, *mu) = exp(_C);
      84            1 :         _tau.d(*mu, *C) = exp(_C);
      85              :       }
      86              :     }
      87              :   }
      88            5 : }
      89              : } // namespace neml2
        

Generated by: LCOV version 2.0-1