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/tensors/MillerIndex.h"
26 : #include "neml2/tensors/Vec.h"
27 : #include "neml2/tensors/Scalar.h"
28 : #include "neml2/tensors/functions/gcd.h"
29 :
30 : namespace neml2
31 : {
32 : Scalar
33 195 : MillerIndex::operator()(Size i) const
34 : {
35 780 : return Scalar(base_index({i}), batch_sizes());
36 195 : }
37 :
38 : MillerIndex
39 10 : MillerIndex::fill(int64_t a, int64_t b, int64_t c, const TensorOptions & options)
40 : {
41 40 : return MillerIndex::create({a, b, c}, options);
42 10 : }
43 :
44 : MillerIndex
45 65 : MillerIndex::reduce() const
46 : {
47 65 : auto cf = neml2::gcd(neml2::gcd((*this)(0), (*this)(1)), (*this)(2));
48 130 : return *this / cf;
49 65 : }
50 :
51 : Vec
52 66 : MillerIndex::to_vec(const TensorOptions & options) const
53 : {
54 66 : return Vec(this->to(options));
55 : }
56 :
57 : Vec
58 2 : MillerIndex::to_normalized_vec(const TensorOptions & options) const
59 : {
60 2 : auto v = this->to_vec(options);
61 4 : return v / v.norm();
62 2 : }
63 : } // namespace neml2
|