LCOV - code coverage report
Current view: top level - models/solid_mechanics/crystal_plasticity - ElasticStrainRate.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.1 % 54 53
Test Date: 2025-10-02 16:03:03 Functions: 100.0 % 6 6

            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/crystal_plasticity/ElasticStrainRate.h"
      26              : 
      27              : #include "neml2/tensors/SR2.h"
      28              : #include "neml2/tensors/WR2.h"
      29              : #include "neml2/tensors/R4.h"
      30              : #include "neml2/tensors/SSR4.h"
      31              : #include "neml2/tensors/SWR4.h"
      32              : 
      33              : namespace neml2
      34              : {
      35              : register_NEML2_object(ElasticStrainRate);
      36              : 
      37              : OptionSet
      38            2 : ElasticStrainRate::expected_options()
      39              : {
      40            2 :   OptionSet options = Model::expected_options();
      41              : 
      42            2 :   options.doc() = "Calculates the elastic strain rate as \\f$\\dot{\\varepsilon} = d - d^p - "
      43              :                   "\\varepsilon w + w \\varepsilon \\f$ "
      44              :                   "where \\f$ d \\f$ is the deformation rate, \\f$ d^p \\f$ is the plastic "
      45              :                   "deformation rate, \\f$ w \\f$ is the vorticity, and \\f$ \\varepsilon \\f$ is "
      46            2 :                   "the elastic strain.";
      47              : 
      48            6 :   options.set_output("elastic_strain_rate") = VariableName(STATE, "elastic_strain_rate");
      49            2 :   options.set("elastic_strain_rate").doc() = "Name of the elastic strain rate";
      50              : 
      51            6 :   options.set_input("elastic_strain") = VariableName(STATE, "elastic_strain");
      52            2 :   options.set("elastic_strain").doc() = "Name of the elastic strain";
      53              : 
      54            6 :   options.set_input("deformation_rate") = VariableName(FORCES, "deformation_rate");
      55            2 :   options.set("deformation_rate").doc() = "Name of the deformation rate";
      56              : 
      57            6 :   options.set_input("vorticity") = VariableName(FORCES, "vorticity");
      58            2 :   options.set("vorticity").doc() = "Name of the vorticity";
      59              : 
      60            4 :   options.set_input("plastic_deformation_rate") =
      61            6 :       VariableName(STATE, "internal", "plastic_deformation_rate");
      62            2 :   options.set("plastic_deformation_rate").doc() = "Name of the plastic deformation rate";
      63              : 
      64            2 :   return options;
      65            0 : }
      66              : 
      67            2 : ElasticStrainRate::ElasticStrainRate(const OptionSet & options)
      68              :   : Model(options),
      69            2 :     _e_dot(declare_output_variable<SR2>("elastic_strain_rate")),
      70            2 :     _e(declare_input_variable<SR2>("elastic_strain")),
      71            2 :     _d(declare_input_variable<SR2>("deformation_rate")),
      72            2 :     _w(declare_input_variable<WR2>("vorticity")),
      73            4 :     _dp(declare_input_variable<SR2>("plastic_deformation_rate"))
      74              : {
      75            2 : }
      76              : 
      77              : SR2
      78            3 : skew_and_sym_to_sym(const SR2 & e, const WR2 & w)
      79              : {
      80              :   // In NEML we used an unrolled form, I don't think I ever found
      81              :   // a nice direct notation for this one
      82            3 :   auto E = R2(e);
      83            3 :   auto W = R2(w);
      84            6 :   return SR2(W * E - E * W);
      85            3 : }
      86              : 
      87              : SSR4
      88            2 : d_skew_and_sym_to_sym_d_sym(const WR2 & w)
      89              : {
      90            2 :   auto I = R2::identity(w.options());
      91            2 :   auto W = R2(w);
      92              :   return SSR4(
      93           16 :       R4(at::einsum("...ia,...jb->...ijab", {W, I}) - at::einsum("...ia,...bj->...ijab", {I, W})));
      94            6 : }
      95              : 
      96              : SWR4
      97            1 : d_skew_and_sym_to_sym_d_skew(const SR2 & e)
      98              : {
      99            1 :   auto I = R2::identity(e.options());
     100            1 :   auto E = R2(e);
     101              :   return SWR4(
     102            8 :       R4(at::einsum("...ia,...bj->...ijab", {I, E}) - at::einsum("...ia,...jb->...ijab", {E, I})));
     103            3 : }
     104              : 
     105              : void
     106            4 : ElasticStrainRate::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
     107              : {
     108            4 :   if (out)
     109            3 :     _e_dot = _d - _dp + skew_and_sym_to_sym(SR2(_e), WR2(_w));
     110              : 
     111            4 :   if (dout_din)
     112              :   {
     113            2 :     const auto I = SSR4::identity_sym(_d.options());
     114              : 
     115            2 :     if (_e.is_dependent())
     116            2 :       _e_dot.d(_e) = d_skew_and_sym_to_sym_d_sym(WR2(_w));
     117              : 
     118            2 :     if (_d.is_dependent())
     119            1 :       _e_dot.d(_d) = I;
     120              : 
     121            2 :     if (_w.is_dependent())
     122            1 :       _e_dot.d(_w) = d_skew_and_sym_to_sym_d_skew(SR2(_e));
     123              : 
     124            2 :     if (_dp.is_dependent())
     125            2 :       _e_dot.d(_dp) = -I;
     126            2 :   }
     127            4 : }
     128              : } // namespace neml2
        

Generated by: LCOV version 2.0-1