opm-common
VoigtArray.hpp
1 /*
2  Copyright 2025 Equinor ASA
3 
4  This file is part of the Open Porous Media Project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_UTIL_VOIGT_ARRAY_HPP
21 #define OPM_UTIL_VOIGT_ARRAY_HPP
22 
23 #include <algorithm>
24 #include <array>
25 #include <cstddef>
26 #include <initializer_list>
27 #include <type_traits>
28 #include <vector>
29 
30 namespace Opm {
31 
32 enum class VoigtIndex {
33  XX = 0, XY = 5, XZ = 4,
34  YX = XY, YY = 1, YZ = 3,
35  ZX = XZ, ZY = YZ, ZZ = 2,
36 };
37 
38 template<class T>
40 {
41 public:
42  static constexpr auto indices = std::array<VoigtIndex, 9>{ // NVCC needs templates specified
43  Opm::VoigtIndex::XX,
44  Opm::VoigtIndex::XY,
45  Opm::VoigtIndex::XZ,
46  Opm::VoigtIndex::YX,
47  Opm::VoigtIndex::YY,
48  Opm::VoigtIndex::YZ,
49  Opm::VoigtIndex::ZX,
50  Opm::VoigtIndex::ZY,
51  Opm::VoigtIndex::ZZ,
52  };
53 
54  static constexpr auto unique_indices = std::array<VoigtIndex, 6>{ // NVCC needs templates specified
55  Opm::VoigtIndex::XX,
56  Opm::VoigtIndex::YY,
57  Opm::VoigtIndex::ZZ,
58  Opm::VoigtIndex::YZ,
59  Opm::VoigtIndex::XZ,
60  Opm::VoigtIndex::XY
61  };
62 
63  static constexpr auto diag_indices = std::array<VoigtIndex, 3>{ // NVCC needs templates specified
64  Opm::VoigtIndex::XX,
65  Opm::VoigtIndex::YY,
66  Opm::VoigtIndex::ZZ,
67  };
68 
69  VoigtContainer() = default;
70 
71  template<class Array>
72  explicit VoigtContainer(const Array& array);
73 
74  VoigtContainer(std::initializer_list<T> value)
75  {
76  std::copy_n(value.begin(),
77  std::min(data_.size(), value.size()),
78  data_.begin());
79  }
80 
81  const T& operator[](const VoigtIndex idx) const
82  { return data_[static_cast<std::underlying_type_t<VoigtIndex>>(idx)]; }
83 
84  T& operator [](const VoigtIndex idx)
85  { return data_[static_cast<std::underlying_type_t<VoigtIndex>>(idx)]; }
86 
87  constexpr std::size_t size() const { return data_.size(); }
88 
89 protected:
90  std::array<T, 6> data_{};
91 };
92 
93 template<class Scalar>
94 class VoigtArray : public VoigtContainer<std::vector<Scalar>>
95 {
96 public:
97  VoigtArray() = default;
98  explicit VoigtArray(const std::size_t size);
99 
100  void resize(const std::size_t size);
101 
102  Scalar operator()(const VoigtIndex idx, const std::size_t i) const;
103  Scalar& operator()(const VoigtIndex idx, const std::size_t i);
104 
105  void assign(const std::size_t i, const VoigtContainer<Scalar>& array);
106 };
107 
108 } // namespace Opm
109 
110 #endif // OPM_UTIL_VOIGT_ARRAY_HPP
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: VoigtArray.hpp:94
Definition: VoigtArray.hpp:39