LCOV - code coverage report
Current view: top level - models/solid_mechanics - LinearIsotropicElasticJ2TrialStressUpdate.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 92.7 % 41 38
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/LinearIsotropicElasticJ2TrialStressUpdate.h"
      26              : 
      27              : namespace neml2
      28              : {
      29              : register_NEML2_object(LinearIsotropicElasticJ2TrialStressUpdate);
      30              : 
      31              : OptionSet
      32            2 : LinearIsotropicElasticJ2TrialStressUpdate::expected_options()
      33              : {
      34            2 :   OptionSet options = ElasticityInterface<Model, 2>::expected_options();
      35              : 
      36            2 :   options.doc() = "Update the trial stress under the assumptions of J2 plasticity and isotropic "
      37            2 :                   "linear elasticity";
      38              : 
      39            6 :   options.set_input("elastic_trial_stress") = VariableName(FORCES, "s");
      40            2 :   options.set("elastic_trial_stress").doc() = "Initial trial stress assuming a purely elastic step";
      41              : 
      42            6 :   options.set_input("equivalent_plastic_strain") = VariableName(STATE, "ep");
      43            4 :   options.set("equivalent_plastic_strain").doc() =
      44            2 :       "Current guess for the equivalent plastic strain";
      45              : 
      46            6 :   options.set_output("updated_trial_stress") = VariableName(STATE, "s");
      47            4 :   options.set("updated_trial_stress").doc() =
      48            2 :       "Trial stress corrected for the current increment of plastic deformation";
      49              : 
      50            2 :   return options;
      51            0 : }
      52              : 
      53            1 : LinearIsotropicElasticJ2TrialStressUpdate::LinearIsotropicElasticJ2TrialStressUpdate(
      54            1 :     const OptionSet & options)
      55              :   : ElasticityInterface<Model, 2>(options),
      56            1 :     _elastic_trial_stress(declare_input_variable<Scalar>("elastic_trial_stress")),
      57            1 :     _inelastic_strain(declare_input_variable<Scalar>("equivalent_plastic_strain")),
      58            1 :     _inelastic_strain_old(declare_input_variable<Scalar>(_inelastic_strain.name().old())),
      59            1 :     _updated_trial_stress(declare_output_variable<Scalar>("updated_trial_stress")),
      60            2 :     _converter(_constant_types, _need_derivs)
      61              : {
      62            1 : }
      63              : 
      64              : void
      65            2 : LinearIsotropicElasticJ2TrialStressUpdate::set_value(bool out, bool dout_din, bool d2out_din2)
      66              : {
      67            2 :   const auto [G, dG] = _converter.convert(_constants, ElasticConstant::SHEAR_MODULUS);
      68            2 :   const auto three_shear = 3.0 * G;
      69              : 
      70            2 :   if (out)
      71            2 :     _updated_trial_stress =
      72            3 :         _elastic_trial_stress - three_shear * (_inelastic_strain - _inelastic_strain_old);
      73              : 
      74            2 :   if (dout_din)
      75              :   {
      76            1 :     if (_elastic_trial_stress.is_dependent())
      77            2 :       _updated_trial_stress.d(_elastic_trial_stress) =
      78            3 :           Scalar::identity_map(_elastic_trial_stress.options());
      79              : 
      80            1 :     if (_inelastic_strain.is_dependent())
      81            1 :       _updated_trial_stress.d(_inelastic_strain) = -three_shear;
      82              : 
      83            1 :     if (_inelastic_strain_old.is_dependent())
      84            1 :       _updated_trial_stress.d(_inelastic_strain_old) = three_shear;
      85              : 
      86            1 :     if (const auto * const p1 = nl_param(neml2::name(_constant_types[0])))
      87            0 :       _updated_trial_stress.d(*p1) = -3.0 * dG[0] * (_inelastic_strain - _inelastic_strain_old);
      88              : 
      89            1 :     if (const auto * const p2 = nl_param(neml2::name(_constant_types[1])))
      90            0 :       _updated_trial_stress.d(*p2) = -3.0 * dG[1] * (_inelastic_strain - _inelastic_strain_old);
      91              :   }
      92              : 
      93              :   if (d2out_din2)
      94              :   {
      95              :     // zero
      96              :   }
      97            2 : }
      98              : } // namespace neml2
        

Generated by: LCOV version 2.0-1