NEML2 1.4.0
Loading...
Searching...
No Matches
WR2ImplicitExponentialTimeIntegration.cxx
1// Copyright 2023, 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/Rot.h"
28#include "neml2/tensors/WR2.h"
29#include "neml2/tensors/R2.h"
30#include "neml2/tensors/Vec.h"
31
32namespace neml2
33{
35
38{
40 options.doc() = "Define the implicit discrete exponential time integration residual of a "
41 "rotation variable. The residual can be written as \\f$ r = s - \\exp\\left[ "
42 "(t-t_n)\\dot{s}\\right] \\circ s_n \\f$, where \\f$ \\circ \\f$ denotes the "
43 "rotation operator.";
44
46
47 options.set<VariableName>("variable");
48 options.set("variable").doc() = "Variable being integrated";
49
50 options.set<VariableName>("time") = VariableName("t");
51 options.set("time").doc() = "Time";
52
53 return options;
54}
55
57 const OptionSet & options)
58 : Model(options),
59 _var_name(options.get<VariableName>("variable")),
60 _var_rate_name(_var_name.with_suffix("_rate")),
61 _r(declare_output_variable<Vec>(_var_name.on("residual"))),
62 _s_dot(declare_input_variable<WR2>(_var_rate_name.on("state"))),
63 _s(declare_input_variable<Rot>(_var_name.on("state"))),
64 _sn(declare_input_variable<Rot>(_var_name.on("old_state"))),
65 _t(declare_input_variable<Scalar>(options.get<VariableName>("time").on("forces"))),
66 _tn(declare_input_variable<Scalar>(options.get<VariableName>("time").on("old_forces")))
67{
68}
69
70void
72{
73 neml_assert_dbg(!d2out_din2, "Second derivative not implemented.");
74
75 const auto dt = _t - _tn;
76 const auto inc = (_s_dot * dt).exp();
77
78 if (out)
79 _r = _s - Rot(_sn).rotate(inc);
80
81 if (dout_din)
82 {
83 const auto de = (_s_dot * dt).dexp();
84 _r.d(_s) = R2::identity(options());
85 _r.d(_s_dot) = -Rot(_sn).drotate(inc) * de * dt;
87 {
88 _r.d(_sn) = -Rot(_sn).drotate_self(inc);
89 _r.d(_t) = -Rot(_sn).drotate(inc) * de * Vec(_s_dot.value());
90 _r.d(_tn) = Rot(_sn).drotate(inc) * de * Vec(_s_dot.value());
91 }
92 }
93}
94} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
The accessor containing all the information needed to access an item in a LabeledAxis.
Definition LabeledAxisAccessor.h:44
The base class for all constitutive models.
Definition Model.h:53
const torch::TensorOptions & options() const
This model's tensor options.
Definition Model.h:116
@ UPDATING
Definition Model.h:188
static OptionSet expected_options()
Definition Model.cxx:32
static enum neml2::Model::Stage stage
Definition Model.cxx:29
static void enable_automatic_scaling(OptionSet &options)
Definition NonlinearSystem.cxx:62
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
static R2 identity(const torch::TensorOptions &options=default_tensor_options())
Identity.
Definition R2Base.cxx:170
Rotation stored as modified Rodrigues parameters.
Definition Rot.h:49
Rot rotate(const Rot &r) const
Rotate.
Definition Rot.cxx:81
R2 drotate_self(const Rot &r) const
Derivative of the rotated Rodrigues vector w.r.t. this vector.
Definition Rot.cxx:103
R2 drotate(const Rot &r) const
Derivative of the rotated Rodrigues vector w.r.t. the other Rodrigues vector.
Definition Rot.cxx:87
The (logical) scalar.
Definition Scalar.h:38
The (logical) vector.
Definition Vec.h:42
Implicit exponential time integration for rotations.
Definition WR2ImplicitExponentialTimeIntegration.h:34
const Variable< WR2 > & _s_dot
Current variable spin rate.
Definition WR2ImplicitExponentialTimeIntegration.h:55
WR2ImplicitExponentialTimeIntegration(const OptionSet &options)
Definition WR2ImplicitExponentialTimeIntegration.cxx:56
const Variable< Scalar > & _t
Current time.
Definition WR2ImplicitExponentialTimeIntegration.h:64
Variable< Vec > & _r
Nonlinear residual.
Definition WR2ImplicitExponentialTimeIntegration.h:52
const Variable< Scalar > & _tn
Previous time.
Definition WR2ImplicitExponentialTimeIntegration.h:67
static OptionSet expected_options()
Definition WR2ImplicitExponentialTimeIntegration.cxx:37
const Variable< Rot > & _sn
Previous value.
Definition WR2ImplicitExponentialTimeIntegration.h:61
const Variable< Rot > & _s
Current guess at next value.
Definition WR2ImplicitExponentialTimeIntegration.h:58
void set_value(bool out, bool dout_din, bool d2out_din2) override
Perform the update by defining the nonlinear residual and it's derivatives.
Definition WR2ImplicitExponentialTimeIntegration.cxx:71
A skew rank 2, represented as an axial vector.
Definition WR2.h:43
Definition CrossRef.cxx:32
void neml_assert_dbg(bool assertion, Args &&... args)
Definition error.h:85
LabeledAxisAccessor VariableName
Definition Variable.h:35