LCOV - code coverage report
Current view: top level - models/solid_mechanics - KocksMeckingIntercept.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.8 % 45 44
Test Date: 2025-06-29 01:25:44 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/KocksMeckingIntercept.h"
      26              : #include "neml2/tensors/Scalar.h"
      27              : #include "neml2/tensors/functions/pow.h"
      28              : 
      29              : namespace neml2
      30              : {
      31              : register_NEML2_object(KocksMeckingIntercept);
      32              : 
      33              : OptionSet
      34            2 : KocksMeckingIntercept::expected_options()
      35              : {
      36            2 :   OptionSet options = Model::expected_options();
      37            2 :   options.doc() = "The critical value of the normalized activation energy given by \\f$ g_0 "
      38            2 :                   "\\frac{C-B}{A} \\f$";
      39              : 
      40            4 :   options.set<bool>("define_second_derivatives") = true;
      41              : 
      42            4 :   options.set_parameter<TensorName<Scalar>>("A");
      43            4 :   options.set("A").doc() = "The Kocks-Mecking slope";
      44              : 
      45            4 :   options.set_parameter<TensorName<Scalar>>("B");
      46            4 :   options.set("B").doc() = "The Kocks-Mecking intercept";
      47              : 
      48            4 :   options.set_parameter<TensorName<Scalar>>("C");
      49            4 :   options.set("C").doc() = "The Kocks-Mecking horizontal value";
      50              : 
      51            4 :   options.set_output("intercept");
      52            2 :   options.set("intercept").doc() = "The intercept";
      53              : 
      54            2 :   return options;
      55            0 : }
      56              : 
      57            2 : KocksMeckingIntercept::KocksMeckingIntercept(const OptionSet & options)
      58              :   : Model(options),
      59            6 :     _A(declare_parameter<Scalar>("A", "A", true)),
      60            8 :     _B(declare_parameter<Scalar>("B", "B", true)),
      61            8 :     _C(declare_parameter<Scalar>("C", "C", true)),
      62            4 :     _b(declare_output_variable<Scalar>(VariableName(PARAMETERS, name())))
      63              : {
      64            2 : }
      65              : 
      66              : void
      67            6 : KocksMeckingIntercept::set_value(bool out, bool dout_din, bool d2out_din2)
      68              : {
      69            6 :   if (out)
      70            4 :     _b = (_C - _B) / _A;
      71              : 
      72            6 :   if (dout_din)
      73              :   {
      74            9 :     if (const auto * const A = nl_param("A"))
      75            2 :       _b.d(*A) = -(_C - _B) / pow(_A, 2.0);
      76              : 
      77            9 :     if (const auto * const B = nl_param("B"))
      78            2 :       _b.d(*B) = -1.0 / _A;
      79              : 
      80            9 :     if (const auto * const C = nl_param("C"))
      81            2 :       _b.d(*C) = 1.0 / _A;
      82              :   }
      83              : 
      84            6 :   if (d2out_din2)
      85              :   {
      86            6 :     if (const auto * const A = nl_param("A"))
      87              :     {
      88            1 :       _b.d(*A, *A) = 2.0 * (_C - _B) / pow(_A, 3.0);
      89            3 :       if (const auto * const B = nl_param("B"))
      90            1 :         _b.d(*A, *B) = 1.0 / pow(_A, 2.0);
      91            3 :       if (const auto * const C = nl_param("C"))
      92            1 :         _b.d(*A, *C) = -1.0 / pow(_A, 2.0);
      93              :     }
      94              : 
      95            6 :     if (const auto * const B = nl_param("B"))
      96            3 :       if (const auto * const A = nl_param("A"))
      97            1 :         _b.d(*B, *A) = 1.0 / pow(_A, 2.0);
      98              : 
      99            6 :     if (const auto * const C = nl_param("C"))
     100            3 :       if (const auto * const A = nl_param("A"))
     101            1 :         _b.d(*C, *A) = -1.0 / pow(_A, 2.0);
     102              :   }
     103            6 : }
     104              : } // namespace neml2
        

Generated by: LCOV version 2.0-1