ParallelPAvgDynamicSourceData.hpp
Go to the documentation of this file.
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_PAVG_DYNAMIC_SOURCE_DATA_HPP
21#define PARALLEL_PAVG_DYNAMIC_SOURCE_DATA_HPP
22
23#include <opm/input/eclipse/Schedule/Well/PAvgDynamicSourceData.hpp>
24
26
27#include <cstddef>
28#include <functional>
29#include <vector>
30
31namespace Opm {
32
35template<class Scalar>
36class ParallelPAvgDynamicSourceData : public PAvgDynamicSourceData<Scalar>
37{
38public:
42 using GlobalToLocal = std::function<int(const std::size_t)>;
43 template<class T> using SourceDataSpan = typename PAvgDynamicSourceData<Scalar>::template SourceDataSpan<T>;
44
54 using Evaluator = std::function<void(int, SourceDataSpan<Scalar>)>;
55
69 const std::vector<std::size_t>& sourceLocations,
70 GlobalToLocal localCellIdx);
71
76 void setToZero();
77
91 void reconstruct(const std::vector<std::size_t>& sourceLocations,
92 GlobalToLocal localCellIdx);
93
99
103
104private:
106 struct LocalLocation
107 {
109 std::size_t ix{};
110
112 int cell{};
113 };
114
116 std::reference_wrapper<const Parallel::Communication> comm_;
117
119 std::vector<LocalLocation> locations_{};
120
122 std::vector<Scalar> localSrc_{};
123
126 std::vector<typename std::vector<Scalar>::size_type> storageIndex_{};
127
129 std::vector<int> allSizes_{}; // Type int to meet API requirements.
130
132 std::vector<int> startPointers_{}; // Type int to meet API requirements.
133
141 [[nodiscard]] typename std::vector<Scalar>::size_type
142 storageIndex(typename std::vector<Scalar>::size_type elemIndex) const override;
143
156 void finaliseConstruction(const std::vector<std::size_t>& sourceLocations,
157 GlobalToLocal localCellIdx);
158
164 [[nodiscard]] SourceDataSpan<Scalar>
165 localSourceTerm(const std::size_t localIx);
166
170 void defineCommunication();
171};
172
173} // namespace Opm
174
175#endif // PARALLEL_PAVG_DYNAMIC_SOURCE_DATA_HPP
Definition: ParallelPAvgDynamicSourceData.hpp:37
std::function< void(int, SourceDataSpan< Scalar >)> Evaluator
Definition: ParallelPAvgDynamicSourceData.hpp:54
typename PAvgDynamicSourceData< Scalar >::template SourceDataSpan< T > SourceDataSpan
Definition: ParallelPAvgDynamicSourceData.hpp:43
std::function< int(const std::size_t)> GlobalToLocal
Definition: ParallelPAvgDynamicSourceData.hpp:42
void collectLocalSources(Evaluator eval)
void reconstruct(const std::vector< std::size_t > &sourceLocations, GlobalToLocal localCellIdx)
ParallelPAvgDynamicSourceData(const Parallel::Communication &comm, const std::vector< std::size_t > &sourceLocations, GlobalToLocal localCellIdx)
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:37