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/elasticity/CubicElasticityTensor.h"
26 : #include "neml2/tensors/SSR4.h"
27 :
28 : namespace neml2
29 : {
30 : register_NEML2_object(CubicElasticityTensor);
31 :
32 : OptionSet
33 2 : CubicElasticityTensor::expected_options()
34 : {
35 2 : OptionSet options = ElasticityInterface<Model, 3>::expected_options();
36 2 : options.doc() = "This class defines a cubic anisotropic elasticity tensor using three parameters."
37 2 : " Various options are available for which three parameters to provide.";
38 :
39 2 : return options;
40 0 : }
41 :
42 2 : CubicElasticityTensor::CubicElasticityTensor(const OptionSet & options)
43 : : ElasticityInterface<Model, 3>(options),
44 2 : _converter(_constant_types, _need_derivs),
45 2 : _C(declare_output_variable<SSR4>(VariableName(PARAMETERS, name())))
46 : {
47 2 : }
48 :
49 : void
50 4 : CubicElasticityTensor::set_value(bool out, bool dout_din, bool /*d2out_din2*/)
51 : {
52 4 : const auto [C1_and_dC1, C2_and_dC2, C3_and_dC3] = _converter.convert(_constants);
53 4 : const auto & [C1, dC1] = C1_and_dC1;
54 4 : const auto & [C2, dC2] = C2_and_dC2;
55 4 : const auto & [C3, dC3] = C3_and_dC3;
56 :
57 4 : const auto I1 = SSR4::identity_C1(C1.options());
58 4 : const auto I2 = SSR4::identity_C2(C2.options());
59 4 : const auto I3 = SSR4::identity_C3(C3.options());
60 :
61 4 : if (out)
62 4 : _C = C1 * I1 + C2 * I2 + C3 * I3;
63 :
64 4 : if (dout_din)
65 : {
66 2 : if (const auto * const p1 = nl_param(neml2::name(_constant_types[0])))
67 2 : _C.d(*p1) = dC1[0] * I1 + dC2[0] * I2 + dC3[0] * I3;
68 :
69 2 : if (const auto * const p2 = nl_param(neml2::name(_constant_types[1])))
70 2 : _C.d(*p2) = dC1[1] * I1 + dC2[1] * I2 + dC3[1] * I3;
71 :
72 2 : if (const auto * const p3 = nl_param(neml2::name(_constant_types[2])))
73 2 : _C.d(*p3) = dC1[2] * I1 + dC2[2] * I2 + dC3[2] * I3;
74 : }
75 4 : }
76 :
77 : } // namespace neml2
|