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/WR2ExplicitExponentialTimeIntegration.h"
26 : #include "neml2/tensors/Scalar.h"
27 : #include "neml2/tensors/Rot.h"
28 : #include "neml2/tensors/WR2.h"
29 : #include "neml2/tensors/Vec.h"
30 :
31 : namespace neml2
32 : {
33 : register_NEML2_object(WR2ExplicitExponentialTimeIntegration);
34 :
35 : OptionSet
36 2 : WR2ExplicitExponentialTimeIntegration::expected_options()
37 : {
38 2 : OptionSet options = Model::expected_options();
39 2 : options.doc() = "Perform explicit discrete exponential time integration of a rotation. The "
40 : "update can be written as \\f$ s = \\exp\\left[ (t-t_n)\\dot{s}\\right] \\circ "
41 2 : "s_n \\f$, where \\f$ \\circ \\f$ denotes the rotation operator.";
42 :
43 4 : options.set_output("variable");
44 4 : options.set("variable").doc() = "Variable being integrated";
45 :
46 4 : options.set_input("rate");
47 2 : options.set("rate").doc() = "Variable rate of change";
48 :
49 6 : options.set_input("time") = VariableName(FORCES, "t");
50 2 : options.set("time").doc() = "Time";
51 :
52 2 : return options;
53 0 : }
54 :
55 1 : WR2ExplicitExponentialTimeIntegration::WR2ExplicitExponentialTimeIntegration(
56 1 : const OptionSet & options)
57 : : Model(options),
58 1 : _s(declare_output_variable<Rot>("variable")),
59 1 : _sn(declare_input_variable<Rot>(_s.name().old())),
60 2 : _s_dot(options.get<VariableName>("rate").empty()
61 4 : ? declare_input_variable<WR2>(_s.name().with_suffix("_rate"))
62 1 : : declare_input_variable<WR2>("rate")),
63 1 : _t(declare_input_variable<Scalar>("time")),
64 2 : _tn(declare_input_variable<Scalar>(_t.name().old()))
65 : {
66 1 : }
67 :
68 : void
69 0 : WR2ExplicitExponentialTimeIntegration::diagnose() const
70 : {
71 0 : Model::diagnose();
72 0 : diagnostic_assert_state(_s);
73 0 : diagnostic_assert_state(_s_dot);
74 0 : diagnostic_assert_force(_t);
75 0 : }
76 :
77 : void
78 2 : WR2ExplicitExponentialTimeIntegration::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
79 : {
80 2 : const auto dt = _t - _tn;
81 :
82 : // Incremental rotation
83 2 : const auto inc = (_s_dot * dt).exp();
84 :
85 2 : if (out)
86 1 : _s = Rot(_sn).rotate(inc);
87 :
88 2 : if (dout_din)
89 : {
90 1 : const auto de = (_s_dot * dt).dexp();
91 1 : _s.d(_s_dot) = Rot(_sn).drotate(inc) * de * dt;
92 :
93 1 : if (currently_solving_nonlinear_system())
94 0 : return;
95 :
96 1 : _s.d(_sn) = Rot(_sn).drotate_self(inc);
97 1 : _s.d(_t) = Rot(_sn).drotate(inc) * de * Vec(_s_dot.value());
98 1 : _s.d(_tn) = -Rot(_sn).drotate(inc) * de * Vec(_s_dot.value());
99 1 : }
100 2 : }
101 :
102 : } // namespace neml2
|