LCOV - code coverage report
Current view: top level - models/solid_mechanics/crystal_plasticity - CrystalMean.cxx (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.2 % 26 25
Test Date: 2025-06-29 01:25:44 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/CrystalMean.h"
      26              : #include "neml2/models/crystallography/CrystalGeometry.h"
      27              : #include "neml2/tensors/tensors.h"
      28              : #include "neml2/tensors/functions/mean.h"
      29              : 
      30              : namespace neml2
      31              : {
      32              : using SR2CrystalMean = CrystalMean<SR2>;
      33              : register_NEML2_object(SR2CrystalMean);
      34              : 
      35              : template <typename T>
      36              : OptionSet
      37            2 : CrystalMean<T>::expected_options()
      38              : {
      39            2 :   OptionSet options = Model::expected_options();
      40              : 
      41            2 :   options.doc() = "Average the variable over all crystals.";
      42              : 
      43            4 :   options.set_input("from");
      44            4 :   options.set("from").doc() = "Variable to average";
      45              : 
      46            4 :   options.set_output("to");
      47            4 :   options.set("to").doc() = "The averaged variable";
      48              : 
      49            4 :   options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
      50            2 :   options.set("crystal_geometry_name").doc() =
      51              :       "The name of the Data object containing the crystallographic information";
      52              : 
      53            2 :   return options;
      54            0 : }
      55              : 
      56              : template <typename T>
      57            1 : CrystalMean<T>::CrystalMean(const OptionSet & options)
      58              :   : Model(options),
      59            1 :     _crystal_geometry(register_data<crystallography::CrystalGeometry>(
      60              :         options.get<std::string>("crystal_geometry_name"))),
      61            1 :     _from(declare_input_variable<SR2>("from", _crystal_geometry.nslip())),
      62            2 :     _to(declare_output_variable<T>("to"))
      63              : {
      64            1 : }
      65              : 
      66              : template <typename T>
      67              : void
      68            2 : CrystalMean<T>::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
      69              : {
      70            2 :   if (out)
      71            1 :     _to = batch_mean(T(_from), -1);
      72              : 
      73            2 :   if (dout_din)
      74            1 :     if (_from.is_dependent())
      75              :     {
      76            3 :       const auto I = T::identity_map(_from.options())
      77              :                          .base_reshape({T::const_base_storage, T::const_base_storage})
      78            2 :                          .batch_expand_as(T(_from));
      79            1 :       _to.d(_from) = Tensor(I / _from.list_size(0), _from.batch_sizes()).base_transpose(0, 1);
      80            1 :     }
      81            2 : }
      82              : } // namespace neml2
        

Generated by: LCOV version 2.0-1