Skip to content

Commit 87532c6

Browse files
authored
Merge pull request #5959 from akva2/add_voigt_symmtensor
Add VoigtArray and SymmTensor classes
2 parents da8fde3 + 41361ba commit 87532c6

File tree

7 files changed

+567
-0
lines changed

7 files changed

+567
-0
lines changed

CMakeLists_files.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ list (APPEND MAIN_SOURCE_FILES
159159
opm/simulators/utils/PartiallySupportedFlowKeywords.cpp
160160
opm/simulators/utils/PressureAverage.cpp
161161
opm/simulators/utils/SerializationPackers.cpp
162+
opm/simulators/utils/SymmTensor.cpp
162163
opm/simulators/utils/UnsupportedFlowKeywords.cpp
164+
opm/simulators/utils/VoigtArray.cpp
163165
opm/simulators/utils/compressPartition.cpp
164166
opm/simulators/utils/gatherDeferredLogger.cpp
165167
opm/simulators/utils/phaseUsageFromDeck.cpp
@@ -417,8 +419,10 @@ list (APPEND TEST_SOURCE_FILES
417419
tests/test_RestartSerialization.cpp
418420
tests/test_rstconv.cpp
419421
tests/test_stoppedwells.cpp
422+
tests/test_SymmTensor.cpp
420423
tests/test_timer.cpp
421424
tests/test_vfpproperties.cpp
425+
tests/test_VoigtArray.cpp
422426
tests/test_wellmodel.cpp
423427
tests/test_wellprodindexcalculator.cpp
424428
tests/test_wellstate.cpp
@@ -985,6 +989,8 @@ list (APPEND PUBLIC_HEADER_FILES
985989
opm/simulators/utils/ParallelSerialization.hpp
986990
opm/simulators/utils/readDeck.hpp
987991
opm/simulators/utils/satfunc/RelpermDiagnostics.hpp
992+
opm/simulators/utils/SymmTensor.hpp
993+
opm/simulators/utils/VoigtArray.hpp
988994
opm/simulators/wells/ALQState.hpp
989995
opm/simulators/wells/BlackoilWellModel.hpp
990996
opm/simulators/wells/BlackoilWellModel_impl.hpp

opm/simulators/utils/SymmTensor.cpp

+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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+
#include <config.h>
20+
#include <opm/simulators/utils/SymmTensor.hpp>
21+
22+
#include <algorithm>
23+
24+
namespace Opm {
25+
26+
template<class T>
27+
void SymmTensor<T>::
28+
operator+=(const T data)
29+
{
30+
std::for_each(this->data_.begin(), this->data_.end(),
31+
[&data](auto& v) { v += data; });
32+
}
33+
34+
template<class T>
35+
void SymmTensor<T>::
36+
operator+=(const SymmTensor& data)
37+
{
38+
auto it = data.data_.begin();
39+
std::for_each(this->data_.begin(), this->data_.end(),
40+
[&it](auto& v) { v += *it++; });
41+
}
42+
43+
template<class T>
44+
void SymmTensor<T>::
45+
operator*=(const T value)
46+
{
47+
std::for_each(this->data_.begin(), this->data_.end(),
48+
[&value](auto& v) { v *= value; });
49+
}
50+
51+
template<class T>
52+
void SymmTensor<T>::reset()
53+
{
54+
this->data_.fill(T{0});
55+
}
56+
57+
template<class T>
58+
T SymmTensor<T>::
59+
trace() const
60+
{
61+
return (*this)[VoigtIndex::XX] +
62+
(*this)[VoigtIndex::YY] +
63+
(*this)[VoigtIndex::ZZ];
64+
}
65+
66+
template<class T>
67+
T SymmTensor<T>::traction(const Dune::FieldVector<T,3>& normal) const
68+
{
69+
T traction = 0.0;
70+
constexpr auto& ind = Opm::SymmTensor<double>::diag_indices;
71+
for (std::size_t i = 0; i < 3; ++i){
72+
traction += (*this)[ind[i]] * normal[i] * normal[i];
73+
}
74+
traction += T{2} * (*this)[VoigtIndex::YZ] * normal[0] * normal[1]; // xy*nx*ny;
75+
traction += T{2} * (*this)[VoigtIndex::XZ] * normal[0] * normal[2]; // xz*nx*nz
76+
traction += T{2} * (*this)[VoigtIndex::XY] * normal[1] * normal[2]; // yz*ny*nz
77+
78+
return traction;
79+
}
80+
81+
template<class T>
82+
SymmTensor<T>&
83+
SymmTensor<T>::operator=(const T value)
84+
{
85+
this->data_.fill(value);
86+
return *this;
87+
}
88+
89+
template<class T1, class T2>
90+
SymmTensor<T1> operator*(const T2 value, SymmTensor<T1> t1)
91+
{
92+
t1 *= value;
93+
return t1;
94+
}
95+
96+
template<class T1, class T2>
97+
SymmTensor<T1> operator*(SymmTensor<T1> t1, const T2 value)
98+
{
99+
t1 *= value;
100+
return t1;
101+
}
102+
103+
template<class T>
104+
SymmTensor<T> operator+(SymmTensor<T> t1, const SymmTensor<T>& t2)
105+
{
106+
t1 += t2;
107+
return t1;
108+
}
109+
110+
#define INSTANTIATE_OPS(T1, T2) \
111+
template SymmTensor<T1> operator*(const T2, SymmTensor<T1>); \
112+
template SymmTensor<T1> operator*(SymmTensor<T1>, const T2);
113+
114+
#define INSTANTIATE_TYPE(T) \
115+
template class SymmTensor<T>; \
116+
INSTANTIATE_OPS(T, T) \
117+
INSTANTIATE_OPS(T, int) \
118+
INSTANTIATE_OPS(T, unsigned) \
119+
INSTANTIATE_OPS(T, std::size_t) \
120+
template SymmTensor<T> operator+(SymmTensor<T>, const SymmTensor<T>&);
121+
122+
INSTANTIATE_TYPE(double)
123+
124+
#if FLOW_INSTANTIATE_FLOAT
125+
INSTANTIATE_TYPE(float)
126+
#endif
127+
128+
} // namespace Opm

opm/simulators/utils/SymmTensor.hpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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_SYMM_TENSOR_HPP
21+
#define OPM_UTIL_SYMM_TENSOR_HPP
22+
23+
#include <dune/common/fvector.hh>
24+
25+
#include <opm/simulators/utils/VoigtArray.hpp>
26+
27+
#include <utility>
28+
29+
namespace Opm {
30+
31+
template<class T>
32+
class SymmTensor : public VoigtContainer<T>
33+
{
34+
public:
35+
using field_type = T;
36+
37+
SymmTensor() = default;
38+
SymmTensor(std::initializer_list<T> value)
39+
: VoigtContainer<T>(std::move(value))
40+
{}
41+
42+
void operator+=(const T data);
43+
void operator+=(const SymmTensor<T>& data);
44+
45+
void operator*=(const T data);
46+
47+
SymmTensor<T>& operator=(const T value);
48+
49+
void reset();
50+
51+
T trace() const;
52+
T traction(const Dune::FieldVector<T,3>& normal) const;
53+
};
54+
55+
template<class T1, class T2>
56+
SymmTensor<T1> operator*(const T2 value, SymmTensor<T1> t1);
57+
template<class T1, class T2>
58+
SymmTensor<T1> operator*(SymmTensor<T1> t1, const T2 value);
59+
template<class T>
60+
SymmTensor<T> operator+(SymmTensor<T> t1, const SymmTensor<T>& t2);
61+
62+
} // namespace Opm
63+
64+
#endif // OPM_UTIL_SYMM_TENSOR_HPP

opm/simulators/utils/VoigtArray.cpp

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
#include <config.h>
20+
#include <opm/simulators/utils/VoigtArray.hpp>
21+
22+
#include <dune/common/fvector.hh>
23+
24+
#include <algorithm>
25+
26+
namespace Opm {
27+
28+
template<class T>
29+
template<class Array>
30+
VoigtContainer<T>::
31+
VoigtContainer(const Array& array)
32+
{
33+
std::copy(array.begin(), array.end(), data_.begin());
34+
}
35+
36+
template<class Scalar>
37+
VoigtArray<Scalar>::
38+
VoigtArray(const std::size_t size)
39+
{
40+
this->resize(size);
41+
}
42+
43+
template<class Scalar>
44+
void VoigtArray<Scalar>::
45+
resize(const std::size_t size)
46+
{
47+
std::for_each(this->data_.begin(), this->data_.end(),
48+
[size](auto& d) { d.resize(size); });
49+
}
50+
51+
template<class Scalar>
52+
void VoigtArray<Scalar>::
53+
assign(const std::size_t i, const VoigtContainer<Scalar>& array)
54+
{
55+
for (const auto idx : this->unique_indices) {
56+
(*this)[idx][i] = array[idx];
57+
}
58+
}
59+
60+
template<class Scalar>
61+
Scalar VoigtArray<Scalar>::
62+
operator()(const VoigtIndex idx, const std::size_t i) const
63+
{
64+
return (*this)[idx].at(i);
65+
}
66+
67+
template<class Scalar>
68+
Scalar& VoigtArray<Scalar>::
69+
operator()(const VoigtIndex idx, const std::size_t i)
70+
{
71+
return (*this)[idx].at(i);
72+
}
73+
74+
#define INSTANTIATE_TYPE(T) \
75+
template class VoigtArray<T>; \
76+
template VoigtContainer<T>::VoigtContainer(const std::array<T,6>&); \
77+
template VoigtContainer<T>::VoigtContainer(const Dune::FieldVector<T,6>&);
78+
79+
INSTANTIATE_TYPE(double)
80+
81+
#if FLOW_INSTANTIATE_FLOAT
82+
INSTANTIATE_TYPE(float)
83+
#endif
84+
85+
} // namespace Opm

0 commit comments

Comments
 (0)