LCOV - code coverage report
Current view: top level - models/solid_mechanics/crystal_plasticity - PlasticVorticity.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.1 % 35 34
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/crystal_plasticity/PlasticVorticity.h"
      26              : #include "neml2/models/crystallography/CrystalGeometry.h"
      27              : 
      28              : #include "neml2/tensors/Scalar.h"
      29              : #include "neml2/tensors/R2.h"
      30              : #include "neml2/tensors/WR2.h"
      31              : #include "neml2/tensors/R3.h"
      32              : #include "neml2/tensors/list_tensors.h"
      33              : #include "neml2/tensors/functions/sum.h"
      34              : 
      35              : namespace neml2
      36              : {
      37              : register_NEML2_object(PlasticVorticity);
      38              : 
      39              : OptionSet
      40            2 : PlasticVorticity::expected_options()
      41              : {
      42            2 :   OptionSet options = Model::expected_options();
      43              : 
      44            2 :   options.doc() = "Caclulates the plastic vorcitity as \\f$ w^p = \\sum_{i=1}^{n_{slip}} "
      45              :                   "\\dot{\\gamma}_i Q \\operatorname{skew}{\\left(d_i \\otimes n_i \\right)} Q^T "
      46              :                   "\\f$ with \\f$ d^p \\f$ the plastic deformation rate, \\f$ \\dot{\\gamma}_i "
      47              :                   "\\f$ the slip rate on the ith slip system, \\f$Q \\f$ the orientation, \\f$ d_i "
      48            2 :                   "\\f$ the slip system direction, and \\f$ n_i \\f$ the slip system normal.";
      49              : 
      50            6 :   options.set_output("plastic_vorticity") = VariableName(STATE, "internal", "plastic_vorticity");
      51            2 :   options.set("plastic_vorticity").doc() = "The name of the plastic vorticity tensor";
      52              : 
      53            6 :   options.set_input("orientation") = VariableName(STATE, "orientation_matrix");
      54            2 :   options.set("orientation").doc() = "The name of the orientation matrix tensor";
      55              : 
      56            6 :   options.set_input("slip_rates") = VariableName(STATE, "internal", "slip_rates");
      57            4 :   options.set("slip_rates").doc() = "The name of the tensor containg the current slip rates";
      58              : 
      59            4 :   options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
      60            4 :   options.set("crystal_geometry_name").doc() =
      61            2 :       "The name of the Data object containing the crystallographic information for the material";
      62              : 
      63            2 :   return options;
      64            0 : }
      65              : 
      66            2 : PlasticVorticity::PlasticVorticity(const OptionSet & options)
      67              :   : Model(options),
      68            2 :     _crystal_geometry(register_data<crystallography::CrystalGeometry>(
      69            4 :         options.get<std::string>("crystal_geometry_name"))),
      70            2 :     _Wp(declare_output_variable<WR2>("plastic_vorticity")),
      71            2 :     _R(declare_input_variable<R2>("orientation")),
      72            4 :     _gamma_dot(declare_input_variable<Scalar>("slip_rates", _crystal_geometry.nslip()))
      73              : {
      74            2 : }
      75              : 
      76              : void
      77            4 : PlasticVorticity::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      78              : {
      79            4 :   const auto Wp_crystal = batch_sum(_gamma_dot * _crystal_geometry.W(), -1);
      80              : 
      81            4 :   if (out)
      82            4 :     _Wp = Wp_crystal.rotate(_R);
      83              : 
      84            4 :   if (dout_din)
      85              :   {
      86            2 :     if (_gamma_dot.is_dependent())
      87              :     {
      88            2 :       const auto d_Wp_d_gamma_dot = _crystal_geometry.W().rotate(R2(_R).batch_unsqueeze(-1));
      89            2 :       const auto B = d_Wp_d_gamma_dot.batch_sizes().slice(0, -1);
      90            2 :       _Wp.d(_gamma_dot) = Tensor(d_Wp_d_gamma_dot, B).base_transpose(-1, -2);
      91            2 :     }
      92              : 
      93            2 :     if (_R.is_dependent())
      94            2 :       _Wp.d(_R) = Wp_crystal.drotate(_R);
      95              :   }
      96            4 : }
      97              : } // namespace neml2
        

Generated by: LCOV version 2.0-1