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/PlasticSpatialVelocityGradient.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(PlasticSpatialVelocityGradient);
38 :
39 : OptionSet
40 2 : PlasticSpatialVelocityGradient::expected_options()
41 : {
42 2 : OptionSet options = Model::expected_options();
43 :
44 2 : options.doc() =
45 : "Caclulates the plastic spatial velocity gradient as \\f$ l^p = \\sum_{i=1}^{n_{slip}} "
46 : "\\dot{\\gamma}_i Q \\left(d_i \\otimes n_i \\right) Q^T "
47 : "\\f$ with \\f$ l^p \\f$ the plastic spatial velocity gradient, \\f$ \\dot{\\gamma}_i "
48 : "\\f$ the slip rate on the ith slip system, \\f$Q \\f$ the orientation, \\f$ d_i "
49 2 : "\\f$ the slip system direction, and \\f$ n_i \\f$ the slip system normal.";
50 :
51 4 : options.set_output("plastic_spatial_velocity_gradient") =
52 6 : VariableName(STATE, "internal", "plastic_spatial_velocity_gradient");
53 4 : options.set("plastic_spatial_velocity_gradient").doc() =
54 2 : "The name of the plastic spatial velocity gradient";
55 :
56 6 : options.set_input("orientation") = VariableName(STATE, "orientation_matrix");
57 2 : options.set("orientation").doc() = "The name of the orientation matrix tensor";
58 :
59 6 : options.set_input("slip_rates") = VariableName(STATE, "internal", "slip_rates");
60 4 : options.set("slip_rates").doc() = "The name of the tensor containg the current slip rates";
61 :
62 4 : options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
63 4 : options.set("crystal_geometry_name").doc() =
64 2 : "The name of the Data object containing the crystallographic information for the material";
65 :
66 2 : return options;
67 0 : }
68 :
69 1 : PlasticSpatialVelocityGradient::PlasticSpatialVelocityGradient(const OptionSet & options)
70 : : Model(options),
71 1 : _crystal_geometry(register_data<crystallography::CrystalGeometry>(
72 2 : options.get<std::string>("crystal_geometry_name"))),
73 1 : _lp(declare_output_variable<R2>("plastic_spatial_velocity_gradient")),
74 1 : _R(declare_input_variable<R2>("orientation")),
75 2 : _g(declare_input_variable<Scalar>("slip_rates", _crystal_geometry.nslip()))
76 : {
77 1 : }
78 :
79 : void
80 2 : PlasticSpatialVelocityGradient::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
81 : {
82 2 : const auto lp_crystal = batch_sum(_g * _crystal_geometry.A(), -1);
83 :
84 2 : if (out)
85 2 : _lp = lp_crystal.rotate(_R);
86 :
87 2 : if (dout_din)
88 : {
89 1 : if (_g.is_dependent())
90 : {
91 1 : const auto dlp_dg = _crystal_geometry.A().rotate(R2(_R).batch_unsqueeze(-1));
92 1 : _lp.d(_g) = Tensor(dlp_dg.movedim(-3, -1), dlp_dg.batch_sizes().slice(0, -1));
93 1 : }
94 :
95 1 : if (_R.is_dependent())
96 1 : _lp.d(_R) = lp_crystal.drotate(_R);
97 : }
98 2 : }
99 : } // namespace neml2
|