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/PlasticDeformationRate.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/SR2.h"
31 : #include "neml2/tensors/SFFR4.h"
32 : #include "neml2/tensors/list_tensors.h"
33 : #include "neml2/tensors/functions/sum.h"
34 :
35 : namespace neml2
36 : {
37 : register_NEML2_object(PlasticDeformationRate);
38 :
39 : OptionSet
40 2 : PlasticDeformationRate::expected_options()
41 : {
42 2 : OptionSet options = Model::expected_options();
43 :
44 2 : options.doc() = "Caclulates the plastic deformation rate as \\f$ d^p = \\sum_{i=1}^{n_{slip}} "
45 : "\\dot{\\gamma}_i Q \\operatorname{sym}{\\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 4 : options.set_output("plastic_deformation_rate") =
51 6 : VariableName(STATE, "internal", "plastic_deformation_rate");
52 2 : options.set("plastic_deformation_rate").doc() = "The name of the plastic deformation rate tensor";
53 :
54 6 : options.set_input("orientation") = VariableName(STATE, "orientation_matrix");
55 2 : options.set("orientation").doc() = "The name of the orientation matrix tensor";
56 :
57 6 : options.set_input("slip_rates") = VariableName(STATE, "internal", "slip_rates");
58 4 : options.set("slip_rates").doc() = "The name of the tensor containg the current slip rates";
59 :
60 4 : options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
61 4 : options.set("crystal_geometry_name").doc() =
62 2 : "The name of the Data object containing the crystallographic information for the material";
63 :
64 2 : return options;
65 0 : }
66 :
67 2 : PlasticDeformationRate::PlasticDeformationRate(const OptionSet & options)
68 : : Model(options),
69 2 : _crystal_geometry(register_data<crystallography::CrystalGeometry>(
70 4 : options.get<std::string>("crystal_geometry_name"))),
71 2 : _dp(declare_output_variable<SR2>("plastic_deformation_rate")),
72 2 : _R(declare_input_variable<R2>("orientation")),
73 4 : _g(declare_input_variable<Scalar>("slip_rates", _crystal_geometry.nslip()))
74 : {
75 2 : }
76 :
77 : void
78 4 : PlasticDeformationRate::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
79 : {
80 4 : const auto dp_crystal = batch_sum(_g * _crystal_geometry.M(), -1);
81 :
82 4 : if (out)
83 4 : _dp = dp_crystal.rotate(_R);
84 :
85 4 : if (dout_din)
86 : {
87 2 : if (_g.is_dependent())
88 : {
89 2 : const auto ddp_dg = _crystal_geometry.M().rotate(R2(_R).batch_unsqueeze(-1));
90 2 : _dp.d(_g) = Tensor(ddp_dg, ddp_dg.batch_sizes().slice(0, -1)).base_transpose(-2, -1);
91 2 : }
92 :
93 2 : if (_R.is_dependent())
94 2 : _dp.d(_R) = dp_crystal.drotate(_R);
95 : }
96 4 : }
97 : } // namespace neml2
|