LCOV - code coverage report
Current view: top level - models/solid_mechanics/elasticity - LinearIsotropicElasticity.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.9 % 32 31
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/elasticity/LinearIsotropicElasticity.h"
      26              : #include "neml2/tensors/SSR4.h"
      27              : 
      28              : namespace neml2
      29              : {
      30              : register_NEML2_object(LinearIsotropicElasticity);
      31              : 
      32              : OptionSet
      33            2 : LinearIsotropicElasticity::expected_options()
      34              : {
      35            2 :   OptionSet options = ElasticityInterface<Elasticity, 2>::expected_options();
      36            2 :   options.doc() += " for linear isotropic material. \\f$ \\boldsymbol{\\sigma} = K \\tr "
      37              :                    "\\boldsymbol{\\varepsilon}_e + 2 G \\text{dev} \\boldsymbol{\\varepsilon}_e "
      38              :                    "\\f$, where \\f$ K \\f$ and \\f$ G \\f$ are bulk and shear moduli, "
      39            2 :                    "respectively. Other pairs of Lame parameters are also supported. ";
      40              : 
      41            2 :   return options;
      42            0 : }
      43              : 
      44           21 : LinearIsotropicElasticity::LinearIsotropicElasticity(const OptionSet & options)
      45              :   : ElasticityInterface<Elasticity, 2>(options),
      46           21 :     _converter(_constant_types, _need_derivs)
      47              : {
      48           21 : }
      49              : 
      50              : void
      51           25 : LinearIsotropicElasticity::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      52              : {
      53           25 :   const auto [K_and_dK, G_and_dG] = _converter.convert(_constants);
      54           25 :   const auto & [K, dK] = K_and_dK;
      55           25 :   const auto & [G, dG] = G_and_dG;
      56           25 :   const auto vf = _compliance ? 1 / (3 * K) : 3 * K;
      57           25 :   const auto df = _compliance ? 1 / (2 * G) : 2 * G;
      58              : 
      59           25 :   if (out)
      60           21 :     _to = vf * SR2(_from).vol() + df * SR2(_from).dev();
      61              : 
      62           25 :   if (dout_din)
      63              :   {
      64           10 :     const auto I = SSR4::identity_vol(_from.options());
      65           10 :     const auto J = SSR4::identity_dev(_from.options());
      66              : 
      67           10 :     if (_from.is_dependent())
      68           10 :       _to.d(_from) = vf * I + df * J;
      69              : 
      70           10 :     const auto * const p1 = nl_param(neml2::name(_constant_types[0]));
      71           10 :     const auto * const p2 = nl_param(neml2::name(_constant_types[1]));
      72           10 :     const auto dvf_dK = _compliance ? -vf / K : Scalar::full(3.0, K.options());
      73           10 :     const auto ddf_dG = _compliance ? -df / G : Scalar::full(2.0, G.options());
      74              : 
      75           10 :     if (p1)
      76            2 :       _to.d(*p1) = dvf_dK * dK[0] * SR2(_from).vol() + ddf_dG * dG[0] * SR2(_from).dev();
      77              : 
      78           10 :     if (p2)
      79            2 :       _to.d(*p2) = dvf_dK * dK[1] * SR2(_from).vol() + ddf_dG * dG[1] * SR2(_from).dev();
      80           10 :   }
      81           25 : }
      82              : } // namespace neml2
        

Generated by: LCOV version 2.0-1