NEML2 1.4.0
Loading...
Searching...
No Matches
StateRate.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/StateRate.h"
26#include "neml2/tensors/SSR4.h"
27
28namespace neml2
29{
30register_NEML2_object(ScalarStateRate);
31register_NEML2_object(SR2StateRate);
32
33template <typename T>
36{
38 options.doc() = "Calculate the first order discrete time derivative of a state variable as \\f$ "
39 "\\dot{s} = \\frac{s-s_n}{t-t_n} \\f$, where \\f$ s \\f$ is the state variable, "
40 "and \\f$ t \\f$ is time.";
41
42 options.set<VariableName>("state");
43 options.set("state").doc() = "The state variable to take time derivative with";
44
45 options.set<VariableName>("time") = VariableName("t");
46 options.set("time").doc() = "Time";
47
48 return options;
49}
50
51template <typename T>
53 : Model(options),
54 _s(declare_input_variable<T>(options.get<VariableName>("state").on("state"))),
55 _sn(declare_input_variable<T>(options.get<VariableName>("state").on("old_state"))),
56 _t(declare_input_variable<Scalar>(options.get<VariableName>("time").on("forces"))),
57 _tn(declare_input_variable<Scalar>(options.get<VariableName>("time").on("old_forces"))),
58 _ds_dt(declare_output_variable<T>(
59 options.get<VariableName>("state").with_suffix("_rate").on("state")))
60{
61}
62
63template <typename T>
64void
66{
67 auto ds = _s - _sn;
68 auto dt = _t - _tn;
69
70 if (out)
71 _ds_dt = ds / dt;
72
73 if (dout_din || d2out_din2)
74 {
75 auto I = T::identity_map(options());
76
77 if (dout_din)
78 {
79 _ds_dt.d(_s) = I / dt;
80 _ds_dt.d(_sn) = -I / dt;
81 _ds_dt.d(_t) = -ds / dt / dt;
82 _ds_dt.d(_tn) = ds / dt / dt;
83 }
84
85 if (d2out_din2)
86 {
87 _ds_dt.d(_s, _t) = -I / dt / dt;
88 _ds_dt.d(_s, _tn) = I / dt / dt;
89
90 _ds_dt.d(_sn, _t) = I / dt / dt;
91 _ds_dt.d(_sn, _tn) = -I / dt / dt;
92
93 _ds_dt.d(_t, _s) = -I / dt / dt;
94 _ds_dt.d(_t, _sn) = I / dt / dt;
95 _ds_dt.d(_t, _t) = 2 * ds / dt / dt / dt;
96 _ds_dt.d(_t, _tn) = -2 * ds / dt / dt / dt;
97
98 _ds_dt.d(_tn, _s) = I / dt / dt;
99 _ds_dt.d(_tn, _sn) = -I / dt / dt;
100 _ds_dt.d(_tn, _t) = -2 * ds / dt / dt / dt;
101 _ds_dt.d(_tn, _tn) = 2 * ds / dt / dt / dt;
102 }
103 }
104}
105
106template class StateRate<Scalar>;
107template class StateRate<SR2>;
108} // namespace neml2
The wrapper (decorator) for cross-referencing unresolved values at parse time.
Definition CrossRef.h:52
CrossRef()=default
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
static OptionSet expected_options()
Definition Model.cxx:33
A custom map-like data structure. The keys are strings, and the values can be nonhomogeneously typed.
Definition OptionSet.h:59
const std::string & doc() const
A readonly reference to the option set's docstring.
Definition OptionSet.h:91
T & set(const std::string &)
Definition OptionSet.h:436
The (logical) scalar.
Definition Scalar.h:38
static OptionSet expected_options()
Definition StateRate.cxx:35
StateRate(const OptionSet &options)
Definition StateRate.cxx:52
void set_value(bool out, bool dout_din, bool d2out_din2) override
The map between input -> output, and optionally its derivatives.
Definition StateRate.cxx:65
Definition CrossRef.cxx:32
LabeledAxisAccessor VariableName
Definition Variable.h:35