4 #include <opm/common/utility/numeric/VectorUtil.hpp> 13 constexpr
double epslon = 1e-6;
15 double calculateRectangleArea(
double width,
double height);
17 template <
typename T =
double>
18 T calcTetraVol(
const std::array<T,4>& x,
const std::array<T,4>& y,
const std::array<T,4>& z ){
19 T det = x[0]*y[2]*z[1] - x[0]*y[1]*z[2] + x[1]*y[0]*z[2]
20 - x[1]*y[2]*z[0] - x[2]*y[0]*z[1] + x[2]*y[1]*z[0]
21 + x[0]*y[1]*z[3] - x[0]*y[3]*z[1] - x[1]*y[0]*z[3]
22 + x[1]*y[3]*z[0] + x[3]*y[0]*z[1] - x[3]*y[1]*z[0]
23 - x[0]*y[2]*z[3] + x[0]*y[3]*z[2] + x[2]*y[0]*z[3]
24 - x[2]*y[3]*z[0] - x[3]*y[0]*z[2] + x[3]*y[2]*z[0]
25 + x[1]*y[2]*z[3] - x[1]*y[3]*z[2] - x[2]*y[1]*z[3]
26 + x[2]*y[3]*z[1] + x[3]*y[1]*z[2] - x[3]*y[2]*z[1];
27 return std::abs(det)/6;
30 template <
typename T =
double>
31 T calcHexaVol(
const std::array<T,8>& x,
const std::array<T,8>& y,
const std::array<T,8>& z,
32 const T& cx,
const T& cy,
const T& cz )
34 constexpr std::array<std::array<int, 3>, 12> faceConfigurations
36 std::array<int, 3>{0, 1, 5},
49 auto getNodes = [](
const std::array<T, 8>& X,
const std::array<T, 8>& Y,
const std::array<T, 8>& Z,
50 const std::array<int,3>& ind){
51 std::array<T, 3> filtered_vectorX;
52 std::array<T, 3> filtered_vectorY;
53 std::array<T, 3> filtered_vectorZ;
54 for (std::size_t index = 0; index < ind.size(); index++) {
55 filtered_vectorX[index] = X[ind[index]];
56 filtered_vectorY[index] = Y[ind[index]];
57 filtered_vectorZ[index] = Z[ind[index]];
59 return std::make_tuple(filtered_vectorX,filtered_vectorY,filtered_vectorZ);
65 for (std::size_t i = 0; i < faceConfigurations.size(); i += 2) {
66 auto [fX0, fY0, fZ0] = getNodes(x, y, z, faceConfigurations[i]);
67 totalVolume += std::apply(calcTetraVol<T>, VectorUtil::appendNode<double>(fX0, fY0, fZ0, cx, cy, cz));
69 auto [fX1, fY1, fZ1] = getNodes(x, y, z, faceConfigurations[i + 1]);
70 totalVolume += std::apply(calcTetraVol<T>, VectorUtil::appendNode<double>(fX1, fY1, fZ1, cx, cy, cz));
75 template <
typename T =
double>
76 std::vector<int> isInsideElement(
const std::vector<T>& tpX,
const std::vector<T>& tpY,
const std::vector<T>& tpZ,
77 const std::vector<std::array<T, 8>>& X,
const std::vector<std::array<T, 8>>& Y,
78 const std::vector<std::array<T, 8>>& Z)
80 std::vector<int> in_elements(tpX.size(),0);
82 T minX, minY, minZ, maxX, maxY, maxZ;
83 T pcX, pcY, pcZ, element_volume, test_element_volume;
85 for (std::size_t outerIndex = 0; outerIndex < X.size(); outerIndex++) {
86 minX = *std::ranges::min_element(X[outerIndex]);
87 minY = *std::ranges::min_element(Y[outerIndex]);
88 minZ = *std::ranges::min_element(Z[outerIndex]);
89 maxX = *std::ranges::max_element(X[outerIndex]);
90 maxY = *std::ranges::max_element(Y[outerIndex]);
91 maxZ = *std::ranges::max_element(Z[outerIndex]);
92 pcX = std::accumulate(X[outerIndex].begin(), X[outerIndex].end(), 0.0)/8;
93 pcY = std::accumulate(Y[outerIndex].begin(), Y[outerIndex].end(), 0.0)/8;
94 pcZ = std::accumulate(Z[outerIndex].begin(), Z[outerIndex].end(), 0.0)/8;
95 element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex], pcX, pcY,pcZ);
96 for (std::size_t innerIndex = 0; innerIndex < tpX.size(); innerIndex++){
99 flag = (minX < tpX[innerIndex]) && (maxX > tpX[innerIndex]) &&
100 (minY < tpY[innerIndex]) && (maxY > tpY[innerIndex]) &&
101 (minZ < tpZ[innerIndex]) && (maxZ > tpZ[innerIndex]);
102 if (flag && (in_elements[innerIndex] == 0)) {
103 test_element_volume = calcHexaVol(X[outerIndex],Y[outerIndex],Z[outerIndex],
104 tpX[innerIndex], tpY[innerIndex],tpZ[innerIndex]);
105 if (std::abs(test_element_volume - element_volume) < epslon){
106 in_elements[innerIndex] =
static_cast<int>(outerIndex);
119 #endif // GEOMETRY_UTILS_H Definition: GeometryUtil.hpp:11