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/SumSlipRates.h"
26 :
27 : #include "neml2/models/crystallography/CrystalGeometry.h"
28 :
29 : #include "neml2/tensors/Scalar.h"
30 : #include "neml2/tensors/list_tensors.h"
31 : #include "neml2/tensors/functions/abs.h"
32 : #include "neml2/tensors/functions/sum.h"
33 : #include "neml2/tensors/functions/sign.h"
34 :
35 : namespace neml2
36 : {
37 : register_NEML2_object(SumSlipRates);
38 :
39 : OptionSet
40 2 : SumSlipRates::expected_options()
41 : {
42 2 : OptionSet options = Model::expected_options();
43 2 : options.doc() = "Calculates the sum of the absolute value of all the slip rates as \\f$ "
44 2 : "\\sum_{i=1}^{n_{slip}} \\left| \\dot{\\gamma}_i \\right| \\f$.";
45 :
46 6 : options.set_input("slip_rates") = VariableName(STATE, "internal", "slip_rates");
47 2 : options.set("slip_rates").doc() = "The name of individual slip rates";
48 :
49 6 : options.set_output("sum_slip_rates") = VariableName(STATE, "internal", "sum_slip_rates");
50 4 : options.set("sum_slip_rates").doc() = "The outut name for the scalar sum of the slip rates";
51 :
52 4 : options.set<std::string>("crystal_geometry_name") = "crystal_geometry";
53 4 : options.set("crystal_geometry_name").doc() =
54 2 : "The name of the Data object containing the crystallographic information";
55 :
56 2 : return options;
57 0 : }
58 :
59 2 : SumSlipRates::SumSlipRates(const OptionSet & options)
60 : : Model(options),
61 2 : _crystal_geometry(register_data<crystallography::CrystalGeometry>(
62 4 : options.get<std::string>("crystal_geometry_name"))),
63 2 : _sg(declare_output_variable<Scalar>("sum_slip_rates")),
64 4 : _g(declare_input_variable<Scalar>("slip_rates", _crystal_geometry.nslip()))
65 : {
66 2 : }
67 :
68 : void
69 4 : SumSlipRates::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
70 : {
71 4 : if (out)
72 3 : _sg = batch_sum(abs(_g.value()), -1);
73 :
74 4 : if (dout_din)
75 2 : if (_g.is_dependent())
76 2 : _sg.d(_g) = Tensor(sign(_g.value()).batch_unsqueeze(-1), _g.batch_dim());
77 4 : }
78 :
79 : } // namespace neml2
|