LCOV - code coverage report
Current view: top level - models/phase_field_fracture - RationalDegradationFunction.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.7 % 43 42
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/phase_field_fracture/RationalDegradationFunction.h"
      26              : #include "neml2/tensors/functions/pow.h"
      27              : #include "neml2/tensors/Scalar.h"
      28              : 
      29              : namespace neml2
      30              : {
      31              : register_NEML2_object(RationalDegradationFunction);
      32              : 
      33              : OptionSet
      34            2 : RationalDegradationFunction::expected_options()
      35              : {
      36            2 :   OptionSet options = DegradationFunction::expected_options();
      37            2 :   options.doc() =
      38              :       "Power degradation function to degrade the elastic strain energy density, \\f$ g "
      39              :       "= \\frac{\\left( 1-d \\right)^p}{\\left( 1-d \\right)^p + Q\\left(d \\right)} \\f$ where, "
      40            2 :       "\\f$ Q\\left(d \\right) = b_{1}d\\left( 1+b_{2}d+b_{2}b_{3}d^2 \\right)\\f$";
      41            4 :   options.set<TensorName<Scalar>>("power");
      42            4 :   options.set("power").doc() = "Power of the degradation function";
      43              : 
      44            4 :   options.set<double>("eta") = 0;
      45            4 :   options.set("eta").doc() = "Residual degradation when d = 1";
      46              : 
      47            4 :   options.set<TensorName<Scalar>>("fitting_param_1");
      48            4 :   options.set("fitting_param_1").doc() = "Material dependent fitting parameter 1";
      49              : 
      50            4 :   options.set<TensorName<Scalar>>("fitting_param_2");
      51            4 :   options.set("fitting_param_2").doc() = "Material dependent fitting parameter 2";
      52              : 
      53            4 :   options.set<TensorName<Scalar>>("fitting_param_3");
      54            4 :   options.set("fitting_param_3").doc() = "Material dependent fitting parameter 3";
      55              : 
      56            2 :   options.set<bool>("define_second_derivatives") = true;
      57              : 
      58            2 :   return options;
      59            0 : }
      60              : 
      61            1 : RationalDegradationFunction::RationalDegradationFunction(const OptionSet & options)
      62              :   : DegradationFunction(options),
      63            4 :     _p(declare_parameter<Scalar>("p", "power")),
      64            1 :     _eta(options.get<double>("eta")),
      65            4 :     _b1(declare_parameter<Scalar>("b1", "fitting_param_1")),
      66            4 :     _b2(declare_parameter<Scalar>("b2", "fitting_param_2")),
      67            5 :     _b3(declare_parameter<Scalar>("b3", "fitting_param_3"))
      68              : 
      69              : {
      70            1 : }
      71              : 
      72              : void
      73            3 : RationalDegradationFunction::set_value(bool out, bool dout_din, bool d2out_din2)
      74              : {
      75            3 :   auto Q = _b1 * _d * (1 + _b2 * _d + _b2 * _b3 * _d * _d);
      76            3 :   if (out)
      77              :   {
      78            1 :     _g = pow((1 - _d), _p) / (pow((1 - _d), _p) + Q) * (1 - _eta) + _eta;
      79              :   }
      80              : 
      81            3 :   auto Q_prime = _b1 * (1 + 2 * _b2 * _d + 3 * _b2 * _b3 * _d * _d);
      82            6 :   auto u = _p * (pow((1 - _d), _p) + Q) * pow((1 - _d), (_p - 1)) * (-1.0) -
      83            9 :            pow((1 - _d), _p) * (_p * pow((1 - _d), (_p - 1)) * (-1.0) + Q_prime);
      84            3 :   auto v = (pow((1 - _d), _p) + Q) * (pow((1 - _d), _p) + Q);
      85              : 
      86            3 :   if (dout_din)
      87              :   {
      88            1 :     _g.d(_d) = (u / v) * (1 - _eta);
      89              :   }
      90              : 
      91            3 :   auto Q_double_prime = _b1 * (2 * _b2 + 6 * _b2 * _b3 * _d);
      92              :   auto u_prime =
      93            6 :       _p * ((_p * pow((1 - _d), (_p - 1)) * (-1.0) + Q_prime) * pow((1 - _d), (_p - 1)) * (-1.0) +
      94           12 :             (_p - 1) * pow((1 - _d), (_p - 2)) * (pow((1 - _d), _p) + Q)) -
      95            6 :       pow((1 - _d), _p) * (_p * (_p - 1) * pow((1 - _d), (_p - 2)) + Q_double_prime) -
      96            9 :       (_p * pow((1 - _d), (_p - 1)) * (-1.0) + Q_prime) * _p * pow((1 - _d), (_p - 1)) * (-1.0);
      97            3 :   auto v_prime = 2 * (pow((1 - _d), _p) + Q) * (_p * pow((1 - _d), (_p - 1)) * (-1.0) + Q_prime);
      98              : 
      99            3 :   if (d2out_din2)
     100              :   {
     101            1 :     _g.d(_d, _d) = ((v * u_prime - u * v_prime) / (v * v)) * (1 - _eta);
     102              :   }
     103            3 : }
     104              : } // namespace neml2
        

Generated by: LCOV version 2.0-1