opm-simulators
FlowsContainer.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  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 2 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  Consult the COPYING file in the top-level source directory of this
19  module for the precise wording of the license and the list of
20  copyright holders.
21 */
22 #ifndef OPM_FLOWS_CONTAINER_HPP
23 #define OPM_FLOWS_CONTAINER_HPP
24 
25 #include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
26 #include <opm/simulators/flow/FlowsData.hpp>
27 
28 #include <algorithm>
29 #include <array>
30 #include <cstddef>
31 #include <functional>
32 #include <map>
33 #include <string>
34 #include <vector>
35 
36 namespace Opm {
37 
38 namespace data { class Solution; }
39 class Schedule;
40 class SummaryConfig;
41 
42 template<class FluidSystem>
44 {
45  using Scalar = typename FluidSystem::Scalar;
46  using ScalarBuffer = std::vector<Scalar>;
47 
48  static constexpr auto numPhases = FluidSystem::numPhases;
49  static constexpr auto gasPhaseIdx = FluidSystem::gasPhaseIdx;
50  static constexpr auto oilPhaseIdx = FluidSystem::oilPhaseIdx;
51  static constexpr auto waterPhaseIdx = FluidSystem::waterPhaseIdx;
52 
53  static constexpr auto gasCompIdx = FluidSystem::gasCompIdx;
54  static constexpr auto oilCompIdx = FluidSystem::oilCompIdx;
55  static constexpr auto waterCompIdx = FluidSystem::waterCompIdx;
56 
57 public:
58  FlowsContainer(const Schedule& schedule,
59  const SummaryConfig& summaryConfig,
60  std::function<bool(const int)> );
61 
62  void allocate(const std::size_t bufferSize,
63  const SummaryConfig& summaryConfig,
64  const unsigned numOutputNnc,
65  const bool allocRestart,
66  std::map<std::string, int>& rstKeywords);
67 
68  void assignFlores(const unsigned globalDofIdx,
69  const int faceId,
70  const unsigned nncId,
71  const Scalar gas,
72  const Scalar oil,
73  const Scalar water);
74 
75  void assignBlockVelocity(const unsigned globalDofIdx,
76  const int faceId,
77  const int comp_idx,
78  const Scalar velocity);
79 
80  void assignBlockFlows(const unsigned globalDofIdx,
81  const int faceId,
82  const int comp_idx,
83  const Scalar flow);
84 
85  void assignFlows(const unsigned globalDofIdx,
86  const int faceId,
87  const unsigned nncId,
88  const Scalar gas,
89  const Scalar oil,
90  const Scalar water);
91 
92  void outputRestart(data::Solution& sol);
93 
94  const std::array<FlowsData<double>, 3>& getFlowsn() const
95  { return this->flowsn_; }
96 
97  bool hasFlowsn() const
98  { return enableFlowsn_; }
99 
100  bool hasFlows() const
101  { return enableFlows_; }
102 
103  const std::vector<int> blockVelocity() const
104  { return blockVelocityAllIds_; }
105 
106  const std::vector<int> blockFlows() const
107  { return blockFlowsAllIds_; }
108 
109  unsigned blockFlowsIds(const unsigned globalDofIdx,
110  const int dir,
111  const int comp_idx) const
112  {
113  const auto& blockIdxs = blockFlowsIds_[comp_idx][dir];
114  auto it = std::lower_bound(blockIdxs.begin(), blockIdxs.end(), globalDofIdx);
115  return std::distance(blockIdxs.begin(), it);
116  }
117 
118  unsigned blockVelocityIds(const unsigned globalDofIdx,
119  const int dir,
120  const int comp_idx) const
121  {
122  const auto& blockIdxs = blockVelocityIds_[comp_idx][dir];
123  auto it = std::lower_bound(blockIdxs.begin(), blockIdxs.end(), globalDofIdx);
124  return std::distance(blockIdxs.begin(), it);
125  }
126 
127  bool anyFlows() const
128  { return anyFlows_; }
129 
130  const std::array<FlowsData<double>, 3>& getFloresn() const
131  { return this->floresn_; }
132 
133  bool hasFloresn() const
134  { return enableFloresn_; }
135 
136  bool hasFlores() const
137  { return enableFlores_; }
138 
139  bool anyFlores() const
140  { return anyFlores_; }
141 
142  bool hasBlockVelocityValue(const unsigned globalDofIdx,
143  const int dir,
144  const int comp_idx) const
145  {
146  const auto& blockIdxs = blockVelocityIds_[comp_idx][dir];
147  return std::ranges::binary_search(blockIdxs, globalDofIdx);
148  }
149 
150  bool hasBlockFlowValue(const unsigned globalDofIdx,
151  const int dir,
152  const int comp_idx) const
153  {
154  const auto& blockIdxs = blockFlowsIds_[comp_idx][dir];
155  return std::ranges::binary_search(blockIdxs, globalDofIdx);
156  }
157 
158  Scalar getVelocity(const unsigned globalDofIdx,
159  const FaceDir::DirEnum dir,
160  const int comp_idx) const
161  { return velocity_[comp_idx][FaceDir::ToIntersectionIndex(dir)][globalDofIdx]; }
162 
163  Scalar getFlow(const unsigned globalDofIdx,
164  const FaceDir::DirEnum dir,
165  const int comp_idx) const
166  { return flows_[comp_idx][FaceDir::ToIntersectionIndex(dir)][globalDofIdx]; }
167 
168 private:
169  bool anyFlows_{false};
170  bool anyFlores_{false};
171  bool enableFlows_{false};
172  bool enableFlores_{false};
173  bool enableFlowsn_{false};
174  bool enableFloresn_{false};
175 
176  std::array<std::array<ScalarBuffer, 6>, numPhases> flows_;
177  std::array<std::array<ScalarBuffer, 6>, numPhases> flores_;
178  std::array<std::array<ScalarBuffer, 6>, numPhases> velocity_;
179 
180  std::array<FlowsData<double>, 3> floresn_;
181  std::array<FlowsData<double>, 3> flowsn_;
182 
183  std::vector<int> blockFlowsAllIds_;
184  std::vector<int> blockVelocityAllIds_;
185  std::array<std::array<std::vector<int>, 6>, numPhases> blockFlowsIds_;
186  std::array<std::array<std::vector<int>, 6>, numPhases> blockVelocityIds_;
187 };
188 
189 } // namespace Opm
190 
191 #endif // OPM_FLOWS_CONTAINER_HPP
Definition: FlowsContainer.hpp:43
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45