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/user_tensors/FillSR2.h"
26 : #include "neml2/tensors/Scalar.h"
27 : #include "neml2/misc/assertions.h"
28 :
29 : namespace neml2
30 : {
31 : register_NEML2_object(FillSR2);
32 :
33 : OptionSet
34 2 : FillSR2::expected_options()
35 : {
36 2 : OptionSet options = UserTensorBase::expected_options();
37 2 : options.doc() = "Construct a R2 with a vector of Scalars. The vector length must be 1, 3, or 6. "
38 : "See the full documentation on neml2::SR2 on the dispatch of fill method. When "
39 : "vector length is 1, the Scalar value is used to fill the diagonals; when vector "
40 : "length is 3, the Scalar values are used to fill the respective diagonal "
41 : "entries; when vector length is 6, the Scalar values are used to fill the tensor "
42 2 : "following the Voigt notation.";
43 :
44 4 : options.set<std::vector<TensorName<Scalar>>>("values");
45 2 : options.set("values").doc() = "Scalars used to fill the R2";
46 :
47 2 : return options;
48 0 : }
49 :
50 139 : FillSR2::FillSR2(const OptionSet & options)
51 : : UserTensorBase(options),
52 278 : SR2(fill(options.get<std::vector<TensorName<Scalar>>>("values")))
53 : {
54 139 : }
55 :
56 : SR2
57 139 : FillSR2::fill(const std::vector<TensorName<Scalar>> & values) const
58 : {
59 139 : auto * f = factory();
60 139 : neml_assert(f, "Internal error: factory != nullptr");
61 :
62 139 : if (values.size() == 1)
63 13 : return SR2::fill(values[0].resolve(f));
64 126 : if (values.size() == 3)
65 28 : return SR2::fill(values[0].resolve(f), values[1].resolve(f), values[2].resolve(f));
66 98 : if (values.size() == 6)
67 98 : return SR2::fill(values[0].resolve(f),
68 98 : values[1].resolve(f),
69 98 : values[2].resolve(f),
70 98 : values[3].resolve(f),
71 98 : values[4].resolve(f),
72 98 : values[5].resolve(f));
73 :
74 0 : throw NEMLException("Number of values must be 1, 3, or 6, but " + std::to_string(values.size()) +
75 0 : " values are provided.");
76 : }
77 : } // namespace neml2
|