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/solid_mechanics/RateIndependentPlasticFlowConstraint.h"
26 : #include "neml2/tensors/Scalar.h"
27 : #include "neml2/tensors/functions/sqrt.h"
28 :
29 : namespace neml2
30 : {
31 : register_NEML2_object(RateIndependentPlasticFlowConstraint);
32 :
33 : OptionSet
34 2 : RateIndependentPlasticFlowConstraint::expected_options()
35 : {
36 2 : OptionSet options = Model::expected_options();
37 2 : options.doc() = "Solve the consistent plasticity yield envelope by solving the equivalent "
38 : "complementarity condition \\f[ r = \\dot{\\gamma} - f^p - "
39 2 : "\\sqrt{{\\dot{\\gamma}}^2 + {f^p}^2} \\f]";
40 :
41 6 : options.set_input("yield_function") = VariableName(STATE, "internal", "fp");
42 2 : options.set("yield_function").doc() = "Yield function";
43 :
44 6 : options.set_input("flow_rate") = VariableName(STATE, "internal", "gamma_rate");
45 2 : options.set("flow_rate").doc() = "Flow rate";
46 :
47 2 : return options;
48 0 : }
49 :
50 1 : RateIndependentPlasticFlowConstraint::RateIndependentPlasticFlowConstraint(
51 1 : const OptionSet & options)
52 : : Model(options),
53 1 : _fp(declare_input_variable<Scalar>("yield_function")),
54 1 : _gamma_dot(declare_input_variable<Scalar>("flow_rate")),
55 2 : _r(declare_output_variable<Scalar>(_gamma_dot.name().remount(RESIDUAL)))
56 : {
57 1 : }
58 :
59 : void
60 2 : RateIndependentPlasticFlowConstraint::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
61 : {
62 2 : const auto FB = _gamma_dot - _fp - sqrt(_gamma_dot * _gamma_dot + _fp * _fp);
63 :
64 2 : if (out)
65 1 : _r = FB;
66 :
67 2 : if (dout_din)
68 : {
69 1 : const auto I = Scalar::identity_map(_gamma_dot.options());
70 1 : const auto eps = machine_precision(_gamma_dot.scalar_type());
71 :
72 1 : if (_gamma_dot.is_dependent())
73 1 : _r.d(_gamma_dot) = I - _gamma_dot / sqrt(_gamma_dot * _gamma_dot + _fp * _fp + eps);
74 :
75 1 : if (_fp.is_dependent())
76 1 : _r.d(_fp) = -I - _fp / sqrt(_gamma_dot * _gamma_dot + _fp * _fp + eps);
77 1 : }
78 2 : }
79 :
80 : } // namespace neml2
|