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/YieldFunction.h"
26 : #include "neml2/tensors/Scalar.h"
27 :
28 : namespace neml2
29 : {
30 : register_NEML2_object(YieldFunction);
31 :
32 : OptionSet
33 2 : YieldFunction::expected_options()
34 : {
35 2 : OptionSet options = Model::expected_options();
36 2 : options.doc() =
37 : "Classical macroscale plasticity yield function, \\f$ f = \\bar{\\sigma} - \\sigma_y - h "
38 : "\\f$, where \\f$ \\bar{\\sigma} \\f$ is the effective stress, \\f$ \\sigma_y \\f$ is the "
39 2 : "yield stress, and \\f$ h \\f$ is the isotropic hardening.";
40 :
41 4 : options.set<bool>("define_second_derivatives") = true;
42 :
43 4 : options.set_parameter<TensorName<Scalar>>("yield_stress");
44 2 : options.set("yield_stress").doc() = "Yield stress";
45 :
46 6 : options.set_input("effective_stress") = VariableName(STATE, "internal", "s");
47 4 : options.set("effective_stress").doc() = "Effective stress";
48 :
49 4 : options.set_input("isotropic_hardening");
50 2 : options.set("isotropic_hardening").doc() = "Isotropic hardening";
51 :
52 6 : options.set_output("yield_function") = VariableName(STATE, "internal", "fp");
53 2 : options.set("yield_function").doc() = "Yield function";
54 :
55 2 : return options;
56 0 : }
57 :
58 13 : YieldFunction::YieldFunction(const OptionSet & options)
59 : : Model(options),
60 13 : _s(declare_input_variable<Scalar>("effective_stress")),
61 26 : _h(options.get<VariableName>("isotropic_hardening").empty()
62 13 : ? nullptr
63 13 : : &declare_input_variable<Scalar>("isotropic_hardening")),
64 13 : _f(declare_output_variable<Scalar>("yield_function")),
65 65 : _sy(declare_parameter<Scalar>("sy", "yield_stress", /*allow_nonlinear=*/true))
66 : {
67 13 : }
68 :
69 : void
70 32 : YieldFunction::set_value(bool out, bool dout_din, bool d2out_din2)
71 : {
72 32 : if (out)
73 : {
74 32 : if (_h)
75 12 : _f = std::sqrt(2.0 / 3.0) * (_s - _sy - (*_h));
76 : else
77 20 : _f = std::sqrt(2.0 / 3.0) * (_s - _sy);
78 : }
79 :
80 32 : if (dout_din)
81 : {
82 23 : auto I = Scalar::identity_map(_s.options());
83 :
84 23 : if (_s.is_dependent())
85 23 : _f.d(_s) = std::sqrt(2.0 / 3.0) * I;
86 :
87 23 : if (_h)
88 9 : _f.d(*_h) = -std::sqrt(2.0 / 3.0) * I;
89 :
90 69 : if (const auto * const sy = nl_param("sy"))
91 4 : _f.d(*sy) = -std::sqrt(2.0 / 3.0) * I;
92 23 : }
93 :
94 : if (d2out_din2)
95 : {
96 : // zero
97 : }
98 32 : }
99 : } // namespace neml2
|