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