My Project
Loading...
Searching...
No Matches
ParallelWBPCalculation.hpp
1/*
2 Copyright 2023 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 PARALLEL_WBP_CALCULATION_HPP
21#define PARALLEL_WBP_CALCULATION_HPP
22
23#include <opm/simulators/wells/ParallelPAvgDynamicSourceData.hpp>
24
25#include <opm/simulators/utils/ParallelCommunication.hpp>
26
27#include <opm/simulators/wells/PerforationData.hpp>
28
29#include <opm/input/eclipse/Schedule/Well/PAvgCalculator.hpp>
30#include <opm/input/eclipse/Schedule/Well/PAvgCalculatorCollection.hpp>
31
32#include <cstddef>
33#include <functional>
34#include <memory>
35#include <vector>
36
37namespace Opm {
38 class GridDims;
39 class ParallelWellInfo;
40 class PAvg;
41 class Well;
42}
43
44namespace Opm {
45
50{
51public:
55
58
62 using EvaluatorFactory = std::function<Evaluator()>;
63
69 explicit ParallelWBPCalculation(const GridDims& cellIndexMap,
70 const Parallel::Communication& gridComm);
71
80
88
113 std::size_t
114 createCalculator(const Well& well,
115 const ParallelWellInfo& parallelWellInfo,
116 const std::vector<int>& localConnIdx,
117 EvaluatorFactory makeWellSourceEvaluator);
118
125 void defineCommunication();
126
140
153 void inferBlockAveragePressures(const std::size_t calcIndex,
154 const PAvg& controls,
155 const double gravity,
156 const double refDepth);
157
166 const PAvgCalculator::Result&
167 averagePressures(const std::size_t calcIndex) const;
168
169private:
171 class LocalConnSet
172 {
173 public:
184 explicit LocalConnSet(const std::vector<int>& localConnIdx);
185
194 int localIndex(const std::size_t connIdx) const;
195
196 private:
205 std::vector<int> localConnIdx_{};
206 };
207
209 class SourceData
210 {
211 public:
216 operator const ParallelPAvgDynamicSourceData&() const
217 {
218 return *this->srcData_;
219 }
220
224 explicit SourceData(const Parallel::Communication& comm);
225
233 SourceData& localIndex(GlobalToLocal localIdx);
234
241 SourceData& evaluator(Evaluator eval);
242
251 SourceData& evaluatorFactory(EvaluatorFactory evalFactory);
252
262 void buildStructure(const std::vector<std::size_t>& sourceLocations);
263
273 void collectDynamicValues();
274
278 const Parallel::Communication& comm() const
279 {
280 return this->comm_.get();
281 }
282
292 std::vector<int>
293 getLocalIndex(const std::vector<std::size_t>& globalIndex) const;
294
295 private:
297 using DataPtr = std::unique_ptr<ParallelPAvgDynamicSourceData>;
298
300 std::reference_wrapper<const Parallel::Communication> comm_;
301
303 GlobalToLocal localIdx_{};
304
307 Evaluator eval_{};
308
312 EvaluatorFactory evalFactory_{};
313
315 DataPtr srcData_{};
316 };
317
319 using WellID = std::vector<SourceData>::size_type;
320
322 std::reference_wrapper<const GridDims> cellIndexMap_;
323
325 SourceData reservoirSrc_;
326
329 PAvgCalculatorCollection calculators_{};
330
332 std::vector<SourceData> wellConnSrc_{};
333
335 std::vector<LocalConnSet> localConnSet_{};
336
339 void pruneInactiveWBPCells();
340
342 void pruneInactiveWBPCellsSerial();
343
345 void pruneInactiveWBPCellsParallel();
346
348 void defineReservoirCommunication();
349
354 void defineWellCommunication(const std::size_t well);
355
363 PAvgCalculator::Sources makeEvaluationSources(const WellID well) const;
364};
365
366} // namespace Opm
367
368#endif // PARALLEL_WBP_CALCULATION_HPP
std::function< void(int, SourceDataSpan< double >)> Evaluator
Collect source term contributions from local, on-rank, cell.
Definition ParallelPAvgDynamicSourceData.hpp:52
std::function< int(const std::size_t)> GlobalToLocal
Translate globally unique, linearised Cartesian cell indices to local, on-rank, cell indices.
Definition ParallelPAvgDynamicSourceData.hpp:41
Parallel facility for managing the on-rank collection and global distribution of WBPn source values a...
Definition ParallelWBPCalculation.hpp:50
ParallelPAvgDynamicSourceData::Evaluator Evaluator
Callback for evaluating WBPn source terms on the current MPI rank.
Definition ParallelWBPCalculation.hpp:57
void defineCommunication()
Set up communication patterns for both cell and connection level source terms and partial/intermediat...
Definition ParallelWBPCalculation.cpp:208
ParallelPAvgDynamicSourceData::GlobalToLocal GlobalToLocal
Callback for inferring the source locations which are active on the current MPI rank.
Definition ParallelWBPCalculation.hpp:54
ParallelWBPCalculation & localCellIndex(GlobalToLocal localCellIdx)
Assign translation function for inferring the on-rank IDs of the known source locations.
Definition ParallelWBPCalculation.cpp:160
void inferBlockAveragePressures(const std::size_t calcIndex, const PAvg &controls, const double gravity, const double refDepth)
Compute WBPn report values for a single well.
Definition ParallelWBPCalculation.cpp:233
void collectDynamicValues()
Collect all on-rank source term value and distribute those on-rank values to all other MPI ranks.
Definition ParallelWBPCalculation.cpp:222
std::size_t createCalculator(const Well &well, const ParallelWellInfo &parallelWellInfo, const std::vector< int > &localConnIdx, EvaluatorFactory makeWellSourceEvaluator)
Create, or reassign, a WBPn calculation object for a particular well.
Definition ParallelWBPCalculation.cpp:175
ParallelWBPCalculation & evalCellSource(Evaluator evalCellSrc)
Assign evaluation function for computing the on-rank, cell level WBPn source terms.
Definition ParallelWBPCalculation.cpp:167
std::function< Evaluator()> EvaluatorFactory
Callback for constructing a source term evaluation function on the current MPI rank.
Definition ParallelWBPCalculation.hpp:62
const PAvgCalculator::Result & averagePressures(const std::size_t calcIndex) const
Retrieve results from most recent WBPn value calculation for specified well.
Definition ParallelWBPCalculation.cpp:244
Class encapsulating some information about parallel wells.
Definition ParallelWellInfo.hpp:184
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition BlackoilPhases.hpp:27