ParallelWellInfo.hpp
Go to the documentation of this file.
1/*
2 Copyright 2020 OPM-OP AS
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#ifndef OPM_PARALLELWELLINFO_HEADER_INCLUDED
20#define OPM_PARALLELWELLINFO_HEADER_INCLUDED
21
22#include <dune/common/parallel/communicator.hh>
23#include <dune/common/parallel/interface.hh>
24#include <dune/common/parallel/mpihelper.hh>
25#include <dune/common/parallel/plocalindex.hh>
26#include <dune/common/parallel/remoteindices.hh>
27
29
30#include <memory>
31#include <unordered_map>
32
33namespace Opm {
34
35class Well;
36
39template<class Scalar>
41{
42public:
43 enum Attribute {
46 // there is a bug in older versions of DUNE that will skip
47 // entries with matching attributes in RemoteIndices that are local
48 // therefore we add one more version for above.
50 overlapAbove = 4
51 };
52 using LocalIndex = Dune::ParallelLocalIndex<Attribute>;
53 using IndexSet = Dune::ParallelIndexSet<int,LocalIndex,50>;
54#if HAVE_MPI
55 using RI = Dune::RemoteIndices<IndexSet>;
56#endif
57
66 void pushBackEclIndex(int above, int current, bool owner=true);
67
69 void clear();
70
73 void beginReset();
74
80 int endReset();
81
87 std::vector<Scalar> communicateAbove(Scalar first_value,
88 const Scalar* current,
89 std::size_t size);
90
96 std::vector<Scalar> communicateBelow(Scalar first_value,
97 const Scalar* current,
98 std::size_t size);
99
107 template<class RAIterator>
108 void partialSumPerfValues(RAIterator begin, RAIterator end) const;
109
111 const IndexSet& getIndexSet() const;
112
113 int numLocalPerfs() const;
114
115private:
118 IndexSet current_indices_;
119#if HAVE_MPI
121 IndexSet above_indices_;
122 RI remote_indices_;
123 Dune::Interface interface_;
124 Dune::BufferedCommunicator communicator_;
125#endif
126 std::size_t num_local_perfs_{};
127};
128
135template<class Scalar>
137{
138public:
141 using GlobalIndex = typename IndexSet::IndexPair::GlobalIndex;
142
146 const Parallel::Communication comm,
147 int num_local_perfs);
148
154 std::vector<Scalar> createGlobal(const std::vector<Scalar>& local_perf_container,
155 std::size_t num_components) const;
156
161 void copyGlobalToLocal(const std::vector<Scalar>& global, std::vector<Scalar>& local,
162 std::size_t num_components) const;
163
164 int numGlobalPerfs() const;
165 int globalToLocal(const int globalIndex) const;
166 int localToGlobal(std::size_t localIndex) const;
167
168private:
169 void buildLocalToGlobalMap() const;
170 void buildGlobalToLocalMap() const;
171 mutable std::unordered_map<std::size_t, int> local_to_global_map_; // Cache for L2G mapping
172 mutable std::unordered_map<int, std::size_t> global_to_local_map_; // Cache for G2L mapping
173 mutable bool l2g_map_built_ = false;
174 mutable bool g2l_map_built_ = false;
175 const IndexSet& local_indices_;
177 int num_global_perfs_;
179 std::vector<int> sizes_;
181 std::vector<int> displ_;
183 std::vector<int> map_received_;
187 std::vector<int> perf_ecl_index_;
188};
189
193template<class Scalar>
195{
196public:
197 static constexpr int INVALID_ECL_INDEX = -1;
198
200 explicit ParallelWellInfo(const std::string& name = {""},
201 bool hasLocalCells = true);
202
209 ParallelWellInfo(const std::pair<std::string,bool>& well_info,
211
213 {
214 return *comm_;
215 }
216
218 void communicateFirstPerforation(bool hasFirst);
219
220 // \brief Set the activePerfToLocalPerf-Map for multisegment wells, to be called from WellState::initWellStateMSWell
221 void setActivePerfToLocalPerfMap(const std::unordered_map<int,int> active_to_local_map) const;
222 // \brief Convert a global active perforation index to a local active perforation index
223 int activePerfToLocalPerf(const int activeIndex) const;
224 // \brief Convert a local active perforation index to a global active perforation index
225 int localPerfToActivePerf(std::size_t localIndex) const;
226 // \brief Convert a global perforation index to a local perforation index
227 int globalPerfToLocalPerf(const int globalIndex) const;
228 // \brief Convert a local perforation index to a global perforation index
229 int localPerfToGlobalPerf(std::size_t localIndex) const;
230
234 template<class T>
236
242 std::vector<Scalar> communicateAboveValues(Scalar first_value,
243 const Scalar* current,
244 std::size_t size) const;
245
249 std::vector<Scalar> communicateAboveValues(Scalar first_value,
250 const std::vector<Scalar>& current) const;
251
257 std::vector<Scalar> communicateBelowValues(Scalar last_value,
258 const Scalar* current,
259 std::size_t size) const;
260
264 std::vector<Scalar> communicateBelowValues(Scalar last_value,
265 const std::vector<Scalar>& current) const;
266
274 void pushBackEclIndex(int above, int current);
275
277 const std::string& name() const
278 {
279 return name_;
280 }
281
283 bool hasLocalCells() const
284 {
285 return hasLocalCells_;
286 }
287 bool isOwner() const
288 {
289 return isOwner_;
290 }
291
296
298 void endReset();
299
301 template<typename It>
302 typename It::value_type sumPerfValues(It begin, It end) const;
303
311 template<class RAIterator>
312 void partialSumPerfValues(RAIterator begin, RAIterator end) const
313 {
314 commAboveBelow_->partialSumPerfValues(begin, end);
315 }
316
318 void clear();
319
326
327private:
328
330 struct DestroyComm
331 {
332 void operator()(Parallel::Communication* comm);
333 };
334
335
337 std::string name_;
339 bool hasLocalCells_;
341 bool isOwner_;
343 int rankWithFirstPerf_;
347 std::unique_ptr<Parallel::Communication, DestroyComm> comm_;
348
350 std::unique_ptr<CommunicateAboveBelow<Scalar>> commAboveBelow_;
351
352 std::unique_ptr<GlobalPerfContainerFactory<Scalar>> globalPerfCont_;
353
354 mutable std::unordered_map<int,int> active_to_local_map_; // Cache for active perforation index to local perforation index mapping
355 mutable std::unordered_map<int,int> local_to_active_map_; // Cache for local perforation index to active perforation index mapping
356};
357
361template<class Scalar>
363{
364public:
366 const ParallelWellInfo<Scalar>& info);
367
372 void connectionFound(std::size_t index);
373
375
376private:
377 std::vector<std::size_t> foundConnections_;
378 const Well& well_;
379 const ParallelWellInfo<Scalar>& pwinfo_;
380};
381
382template<class Scalar>
384
385template<class Scalar>
387
388template<class Scalar>
390
391template<class Scalar>
392bool operator<(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
393
394template<class Scalar>
395bool operator<( const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
396
397template<class Scalar>
398bool operator==(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
399
400template<class Scalar>
401bool operator==(const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
402
403template<class Scalar>
404bool operator!=(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
405
406template<class Scalar>
407bool operator!=(const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
408
409} // end namespace Opm
410
411#endif // OPM_PARALLELWELLINFO_HEADER_INCLUDED
Class checking that all connections are on active cells.
Definition: ParallelWellInfo.hpp:363
void connectionFound(std::size_t index)
Inidicate that the i-th completion was found.
CheckDistributedWellConnections(const Well &well, const ParallelWellInfo< Scalar > &info)
Class to facilitate getting values associated with the above/below perforation.
Definition: ParallelWellInfo.hpp:41
Dune::RemoteIndices< IndexSet > RI
Definition: ParallelWellInfo.hpp:55
std::vector< Scalar > communicateBelow(Scalar first_value, const Scalar *current, std::size_t size)
Creates an array of values for the perforation below.
CommunicateAboveBelow(const Parallel::Communication &comm)
void clear()
Clear all the parallel information.
void pushBackEclIndex(int above, int current, bool owner=true)
Adds information about original index of the perforations in ECL Schedule.
Dune::ParallelLocalIndex< Attribute > LocalIndex
Definition: ParallelWellInfo.hpp:52
int endReset()
Indicates that the index information is complete.
const IndexSet & getIndexSet() const
Get index set for the local perforations.
std::vector< Scalar > communicateAbove(Scalar first_value, const Scalar *current, std::size_t size)
Creates an array of values for the perforation above.
void beginReset()
Indicates that we will add the index information.
void partialSumPerfValues(RAIterator begin, RAIterator end) const
Do a (in place) partial sum on values attached to all perforations.
Dune::ParallelIndexSet< int, LocalIndex, 50 > IndexSet
Definition: ParallelWellInfo.hpp:53
Attribute
Definition: ParallelWellInfo.hpp:43
@ ownerAbove
Definition: ParallelWellInfo.hpp:49
@ overlap
Definition: ParallelWellInfo.hpp:45
@ overlapAbove
Definition: ParallelWellInfo.hpp:50
@ owner
Definition: ParallelWellInfo.hpp:44
A factory for creating a global data representation for distributed wells.
Definition: ParallelWellInfo.hpp:137
GlobalPerfContainerFactory(const IndexSet &local_indices, const Parallel::Communication comm, int num_local_perfs)
Constructor.
int globalToLocal(const int globalIndex) const
std::vector< Scalar > createGlobal(const std::vector< Scalar > &local_perf_container, std::size_t num_components) const
Creates a container that holds values for all perforations.
void copyGlobalToLocal(const std::vector< Scalar > &global, std::vector< Scalar > &local, std::size_t num_components) const
Copies the values of the global perforation to the local representation.
typename CommunicateAboveBelow< Scalar >::Attribute Attribute
Definition: ParallelWellInfo.hpp:140
typename IndexSet::IndexPair::GlobalIndex GlobalIndex
Definition: ParallelWellInfo.hpp:141
int localToGlobal(std::size_t localIndex) const
typename CommunicateAboveBelow< Scalar >::IndexSet IndexSet
Definition: ParallelWellInfo.hpp:139
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:195
int activePerfToLocalPerf(const int activeIndex) const
std::vector< Scalar > communicateBelowValues(Scalar last_value, const Scalar *current, std::size_t size) const
Creates an array of values for the perforation below.
std::vector< Scalar > communicateBelowValues(Scalar last_value, const std::vector< Scalar > &current) const
Creates an array of values for the perforation above.
ParallelWellInfo(const std::string &name={""}, bool hasLocalCells=true)
Constructs object using MPI_COMM_SELF.
const std::string & name() const
Name of the well.
Definition: ParallelWellInfo.hpp:277
T broadcastFirstPerforationValue(const T &t) const
ParallelWellInfo(const std::pair< std::string, bool > &well_info, Parallel::Communication allComm)
Constructs object with communication between all rank sharing a well.
int localPerfToGlobalPerf(std::size_t localIndex) const
bool isOwner() const
Definition: ParallelWellInfo.hpp:287
std::vector< Scalar > communicateAboveValues(Scalar first_value, const Scalar *current, std::size_t size) const
Creates an array of values for the perforation above.
void beginReset()
Inidicate that we will reset the ecl index information.
void pushBackEclIndex(int above, int current)
Adds information about the ecl indices of the perforations.
bool hasLocalCells() const
Whether local cells are perforated somewhen.
Definition: ParallelWellInfo.hpp:283
It::value_type sumPerfValues(It begin, It end) const
Sum all the values of the perforations.
int localPerfToActivePerf(std::size_t localIndex) const
void partialSumPerfValues(RAIterator begin, RAIterator end) const
Do a (in place) partial sum on values attached to all perforations.
Definition: ParallelWellInfo.hpp:312
void clear()
Free data of communication data structures.
int globalPerfToLocalPerf(const int globalIndex) const
const GlobalPerfContainerFactory< Scalar > & getGlobalPerfContainerFactory() const
Get a factor to create a global representation of peforation data.
void setActivePerfToLocalPerfMap(const std::unordered_map< int, int > active_to_local_map) const
void communicateFirstPerforation(bool hasFirst)
Collectively decide which rank has first perforation.
static constexpr int INVALID_ECL_INDEX
Definition: ParallelWellInfo.hpp:197
std::vector< Scalar > communicateAboveValues(Scalar first_value, const std::vector< Scalar > &current) const
Creates an array of values for the perforation above.
void endReset()
Inidicate completion of reset of the ecl index information.
const Parallel::Communication & communication() const
Definition: ParallelWellInfo.hpp:212
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilboundaryratevector.hh:39
bool operator<(const ParallelWellInfo< Scalar > &well1, const ParallelWellInfo< Scalar > &well2)
bool operator==(const aligned_allocator< T1, Alignment > &, const aligned_allocator< T2, Alignment > &) noexcept
Definition: alignedallocator.hh:200
bool operator!=(const aligned_allocator< T1, Alignment > &, const aligned_allocator< T2, Alignment > &) noexcept
Definition: alignedallocator.hh:208