https://mooseframework.inl.gov
R2IncrementToRate.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "R2IncrementToRate.h"
11 
12 #ifdef NEML2_ENABLED
13 
14 #include "neml2/tensors/R2.h"
15 #include "neml2/tensors/functions/imap.h"
16 
17 namespace neml2
18 {
19 register_NEML2_object(R2IncrementToRate);
20 
21 OptionSet
23 {
24  OptionSet options = Model::expected_options();
25  options.doc() = "Compute the rate of a rank two tensor given its increment and the time step.";
26  options.add_input("increment", "Increment of the rank two tensor");
27  options.add_input("time", "t", "Current time");
28  options.add_output("rate", "Rate of the rank two tensor");
29  return options;
30 }
31 
32 R2IncrementToRate::R2IncrementToRate(const OptionSet & options)
33  : Model(options),
34  _delta(declare_input_variable<R2>("increment")),
35  _t(declare_input_variable<Scalar>("t")),
36  _t_n(declare_input_variable<Scalar>(history_name(_t.name(), 1))),
37  _rate(declare_output_variable<R2>("rate"))
38 {
39 }
40 
41 void
42 R2IncrementToRate::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
43 {
44  if (out)
45  _rate = _delta / (_t - _t_n);
46 
47  if (dout_din)
48  {
49  _rate.d(_delta) = 1.0 / (_t - _t_n) * imap_v<R2>();
50  _rate.d(_t) = -_delta / (_t - _t_n) / (_t - _t_n);
51  _rate.d(_t_n) = _delta / (_t - _t_n) / (_t - _t_n);
52  }
53 }
54 } // namespace neml2
55 
56 #endif // NEML2_ENABLED
static OptionSet expected_options()
Variable< R2 > & _rate
Rate.
register_NEML2_object(LibtorchModel)
void set_value(bool out, bool dout_din, bool d2out_din2) override
const std::string name
Definition: Setup.h:21
const Variable< Scalar > & _t_n
R2IncrementToRate(const OptionSet &options)
OStreamProxy out
const Variable< Scalar > & _t
Time.
const Variable< R2 > & _delta
Increment of the rank two tensor.