opm-simulators
FacePropertiesTPSA.hpp
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
3 /*
4  Copyright 2025 NORCE AS
5 
6  This file is part of the Open Porous Media project (OPM).
7 
8  OPM is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 2 of the License, or
11  (at your option) any later version.
12 
13  OPM is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OPM. If not, see <http://www.gnu.org/licenses/>.
20 
21  Consult the COPYING file in the top-level source directory of this
22  module for the precise wording of the license and the list of
23  copyright holders.
24 */
25 #ifndef TPSA_FACE_PROPERTIES_HPP
26 #define TPSA_FACE_PROPERTIES_HPP
27 
28 #include <dune/common/fvector.hh>
29 
30 #include <opm/grid/LookUpData.hh>
31 
32 #include <cstdint>
33 #include <map>
34 #include <vector>
35 #include <utility>
36 
37 
38 namespace Opm {
39 
40 class EclipseState;
41 
47 template<class Grid, class GridView, class ElementMapper, class CartesianIndexMapper, class Scalar>
49 
50  enum { dimWorld = GridView::dimensionworld };
51 
52 public:
53  using DimVector = Dune::FieldVector<Scalar, dimWorld>;
54 
55  FacePropertiesTPSA(const EclipseState& eclState,
56  const GridView& gridView,
57  const CartesianIndexMapper& cartMapper,
58  const Grid& grid,
59  std::function<std::array<double, dimWorld>(int)> centroids);
60 
61  void finishInit();
62 
63  void update();
64 
65  Scalar weightAverage(unsigned elemIdx1, unsigned elemIdx2) const;
66  Scalar weightAverageBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const;
67  Scalar weightProduct(unsigned elemIdx1, unsigned elemIdx2) const;
68  Scalar weightProductBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const;
69  Scalar normalDistance(unsigned elemIdx1, unsigned elemIdx2) const;
70  Scalar normalDistanceBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const;
71  DimVector cellFaceNormal(unsigned elemIdx1, unsigned elemIdx2);
72  const DimVector& cellFaceNormalBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const;
73 
77  const Scalar shearModulus(unsigned elemIdx) const
78  { return sModulus_[elemIdx]; }
79 
80 
81 protected:
82  struct FaceInfo
83  {
84  DimVector faceCenter;
85  int faceIdx;
86  unsigned elemIdx;
87  unsigned cartElemIdx;
88  };
89 
90  template <class Intersection>
91  void computeCellProperties(const Intersection& intersection,
92  FaceInfo& inside,
93  FaceInfo& outside,
94  DimVector& faceNormal,
95  /*isCpGrid=*/std::false_type) const;
96 
97  template <class Intersection>
98  void computeCellProperties(const Intersection& intersection,
99  FaceInfo& inside,
100  FaceInfo& outside,
101  DimVector& faceNormal,
102  /*isCpGrid=*/std::true_type) const;
103 
104  Scalar computeDistance_(const DimVector& distVec, const DimVector& faceNormal);
105 
106  Scalar computeWeight_(const Scalar distance, const Scalar smod);
107 
108  DimVector distanceVector_(const DimVector& faceCenter, const unsigned& cellIdx) const;
109 
110  void extractSModulus_();
111 
112  std::vector<Scalar> sModulus_;
113  std::unordered_map<std::uint64_t, Scalar> weightsAvg_;
114  std::unordered_map<std::uint64_t, Scalar> weightsProd_;
115  std::unordered_map<std::uint64_t, Scalar> distance_;
116  std::unordered_map<std::uint64_t, DimVector> faceNormal_;
117 
118  std::map<std::pair<unsigned, unsigned>, Scalar> weightsAvgBoundary_;
119  std::map<std::pair<unsigned, unsigned>, Scalar> weightsProdBoundary_;
120  std::map<std::pair<unsigned, unsigned>, Scalar> distanceBoundary_;
121  std::map<std::pair<unsigned, unsigned>, DimVector> faceNormalBoundary_;
122 
123  const EclipseState& eclState_;
124  const GridView& gridView_;
125  const CartesianIndexMapper& cartMapper_;
126  const Grid& grid_;
127  std::function<std::array<double, dimWorld>(int)> centroids_;
128  std::vector<std::array<double, dimWorld>> centroids_cache_;
129 
130  const LookUpData<Grid, GridView> lookUpData_;
131  const LookUpCartesianData<Grid, GridView> lookUpCartesianData_;
132 
133 }; // FacePropertiesTPSA
134 
135 namespace details {
136  std::uint64_t isIdTPSA(std::uint32_t elemIdx1, std::uint32_t elemIdx2);
137 } // namespace details
138 
139 } // namespace Opm
140 
141 #endif
Scalar weightProduct(unsigned elemIdx1, unsigned elemIdx2) const
Product of weights at interface between two elements.
Definition: FacePropertiesTPSA_impl.hpp:342
const Scalar shearModulus(unsigned elemIdx) const
Return shear modulus of an element.
Definition: FacePropertiesTPSA.hpp:77
Cell face properties needed in TPSA equation calculations.
Definition: FacePropertiesTPSA.hpp:48
Scalar weightAverageBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const
Average (half-)weight at boundary interface.
Definition: FacePropertiesTPSA_impl.hpp:328
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
DimVector cellFaceNormal(unsigned elemIdx1, unsigned elemIdx2)
Cell face normal at interface between two elements.
Definition: FacePropertiesTPSA_impl.hpp:401
void update()
Compute TPSA face properties.
Definition: FacePropertiesTPSA_impl.hpp:106
Definition: FlowGenericProblem.hpp:51
Scalar computeDistance_(const DimVector &distVec, const DimVector &faceNormal)
Compute normal distance from cell center to face center.
Definition: FacePropertiesTPSA_impl.hpp:440
FacePropertiesTPSA(const EclipseState &eclState, const GridView &gridView, const CartesianIndexMapper &cartMapper, const Grid &grid, std::function< std::array< double, dimWorld >(int)> centroids)
Constructor.
Definition: FacePropertiesTPSA_impl.hpp:77
Scalar weightAverage(unsigned elemIdx1, unsigned elemIdx2) const
Average (half-)weight at interface between two elements.
Definition: FacePropertiesTPSA_impl.hpp:303
Definition: FacePropertiesTPSA.hpp:82
void extractSModulus_()
Extract shear modulus from eclState.
Definition: FacePropertiesTPSA_impl.hpp:553
Scalar normalDistanceBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const
Distance to boundary interface.
Definition: FacePropertiesTPSA_impl.hpp:384
Definition: GenericThresholdPressure.hpp:40
DimVector distanceVector_(const DimVector &faceCenter, const unsigned &cellIdx) const
Distance vector from cell center to face center.
Definition: FacePropertiesTPSA_impl.hpp:532
Scalar weightProductBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const
Product of weights at boundary interface.
Definition: FacePropertiesTPSA_impl.hpp:356
Scalar computeWeight_(const Scalar distance, const Scalar smod)
Compute weight ratio between distance and shear modulus.
Definition: FacePropertiesTPSA_impl.hpp:517
Scalar normalDistance(unsigned elemIdx1, unsigned elemIdx2) const
Distance between two elements.
Definition: FacePropertiesTPSA_impl.hpp:370
void finishInit()
Compute TPSA face properties.
Definition: FacePropertiesTPSA_impl.hpp:96
const DimVector & cellFaceNormalBoundary(unsigned elemIdx1, unsigned boundaryFaceIdx) const
Cell face normal of boundary interface.
Definition: FacePropertiesTPSA_impl.hpp:423