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/FixOrientation.h"
26 :
27 : #include "neml2/tensors/Rot.h"
28 : #include "neml2/tensors/functions/where.h"
29 :
30 : namespace neml2
31 : {
32 : register_NEML2_object(FixOrientation);
33 :
34 : OptionSet
35 2 : FixOrientation::expected_options()
36 : {
37 2 : OptionSet options = Model::expected_options();
38 :
39 2 : options.doc() =
40 : "Checks the value of the modified Rodrigues parameter by checking if "
41 : "\\f$ \\left\\lVert r \\right\\rVert > t \\f$, with \\f$ t \\f$ a threshold value set "
42 : "to 1.0 by default and replacing all the orientations that exceed this limit "
43 2 : "with their shadow parameters values.";
44 :
45 6 : options.set_input("input_orientation") = VariableName(STATE, "orientation");
46 2 : options.set("input_orientation").doc() = "Name of input tensor of orientations to operate on.";
47 :
48 6 : options.set_output("output_orientation") = VariableName(STATE, "orientation");
49 4 : options.set("output_orientation").doc() = "Name of output tensor";
50 :
51 4 : options.set<double>("threshold") = 1.0;
52 2 : options.set("threshold").doc() = "Threshold value for translating to the shadow parameters";
53 :
54 2 : return options;
55 0 : }
56 :
57 1 : FixOrientation::FixOrientation(const OptionSet & options)
58 : : Model(options),
59 1 : _output(declare_output_variable<Rot>("output_orientation")),
60 1 : _input(declare_input_variable<Rot>("input_orientation")),
61 2 : _threshold(options.get<double>("threshold"))
62 : {
63 1 : }
64 :
65 : void
66 2 : FixOrientation::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
67 : {
68 2 : if (out)
69 2 : _output = where(
70 3 : (Rot(_input).norm_sq() < _threshold).unsqueeze(-1), Rot(_input), Rot(_input).shadow());
71 :
72 2 : if (dout_din)
73 1 : if (_input.is_dependent())
74 : {
75 1 : const auto I = R2::identity(_input.options());
76 4 : _output.d(_input) = where((Rot(_input).norm_sq() < _threshold).unsqueeze(-1).unsqueeze(-1),
77 : I,
78 5 : Rot(_input).dshadow());
79 1 : }
80 2 : }
81 : } // namespace neml2
|