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
42template<class Scalar>
44{
45 Scalar temperature{};
47
48 template<class Serializer>
49 void serializeOp(Serializer& serializer)
50 {
51 serializer(temperature);
52 serializer(saltConcentration);
53 }
54};
55
58template<class Scalar>
60{
61public:
62 enum Attribute {
65 // there is a bug in older versions of DUNE that will skip
66 // entries with matching attributes in RemoteIndices that are local
67 // therefore we add one more version for above.
69 overlapAbove = 4
70 };
71 using LocalIndex = Dune::ParallelLocalIndex<Attribute>;
72 using IndexSet = Dune::ParallelIndexSet<int,LocalIndex,50>;
73#if HAVE_MPI
74 using RI = Dune::RemoteIndices<IndexSet>;
75#endif
76
86 void pushBackEclIndex(int above, int current, bool owner = true);
87
89 void clear();
90
93 void beginReset();
94
100 int endReset();
101
107 std::vector<Scalar> communicateAbove(Scalar first_value,
108 const Scalar* current,
109 std::size_t size);
110
116 std::vector<Scalar> communicateBelow(Scalar first_value,
117 const Scalar* current,
118 std::size_t size);
119
127 template<class RAIterator>
128 void partialSumPerfValues(RAIterator begin, RAIterator end) const;
129
131 const IndexSet& getIndexSet() const;
132
133 int numLocalPerfs() const;
134
135private:
138 IndexSet current_indices_;
139#if HAVE_MPI
141 IndexSet above_indices_;
142 RI remote_indices_;
143 Dune::Interface interface_;
144 Dune::BufferedCommunicator communicator_;
145#endif
146 std::size_t num_local_perfs_{};
147};
148
155template<class Scalar>
157{
158public:
161 using GlobalIndex = typename IndexSet::IndexPair::GlobalIndex;
162
168 const Parallel::Communication comm,
169 int num_local_perfs);
170
176 std::vector<Scalar> createGlobal(const std::vector<Scalar>& local_perf_container,
177 std::size_t num_quantities) const;
178
183 void copyGlobalToLocal(const std::vector<Scalar>& global, std::vector<Scalar>& local,
184 std::size_t num_quantities) const;
185
186 int numGlobalPerfs() const;
187 int globalToLocal(const int globalIndex) const;
188 int localToGlobal(std::size_t localIndex) const;
189
190private:
191 void buildLocalToGlobalMap() const;
192 void buildGlobalToLocalMap() const;
193 mutable std::unordered_map<std::size_t, int> local_to_global_map_; // Cache for L2G mapping
194 mutable std::unordered_map<int, std::size_t> global_to_local_map_; // Cache for G2L mapping
195 mutable bool l2g_map_built_ = false;
196 mutable bool g2l_map_built_ = false;
197 const IndexSet& local_indices_;
199 int num_global_perfs_;
201 std::vector<int> sizes_;
203 std::vector<int> displ_;
205 std::vector<int> map_received_;
209 std::vector<int> perf_ecl_index_;
210};
211
215template<class Scalar>
217{
218public:
219 static constexpr int INVALID_ECL_INDEX = -1;
220
222 explicit ParallelWellInfo(const std::string& name = {""},
223 bool hasLocalCells = true);
224
231 ParallelWellInfo(const std::pair<std::string,bool>& well_info,
233
235 {
236 return *comm_;
237 }
238
240 void communicateFirstPerforation(bool hasFirst);
241
242 // \brief Set the activePerfToLocalPerf-Map for multisegment wells, to be called from WellState::initWellStateMSWell
243 void setActivePerfToLocalPerfMap(const std::unordered_map<int,int>& active_to_local_map) const;
244 // \brief Convert a global active perforation index to a local active perforation index
245 int activePerfToLocalPerf(const int activeIndex) const;
246 // \brief Convert a local active perforation index to a global active perforation index
247 int localPerfToActivePerf(std::size_t localIndex) const;
248 // \brief Convert a global perforation index to a local perforation index
249 int globalPerfToLocalPerf(const int globalIndex) const;
250 // \brief Convert a local perforation index to a global perforation index
251 int localPerfToGlobalPerf(std::size_t localIndex) const;
252
256 template<class T>
258
264 std::vector<Scalar> communicateAboveValues(Scalar first_value,
265 const Scalar* current,
266 std::size_t size) const;
267
271 std::vector<Scalar> communicateAboveValues(Scalar first_value,
272 const std::vector<Scalar>& current) const;
273
279 std::vector<Scalar> communicateBelowValues(Scalar last_value,
280 const Scalar* current,
281 std::size_t size) const;
282
286 std::vector<Scalar> communicateBelowValues(Scalar last_value,
287 const std::vector<Scalar>& current) const;
288
296 void pushBackEclIndex(int above, int current);
297
299 const std::string& name() const
300 {
301 return name_;
302 }
303
305 bool hasLocalCells() const
306 {
307 return hasLocalCells_;
308 }
309 bool isOwner() const
310 {
311 return isOwner_;
312 }
313
318
320 void endReset();
321
323 template<typename It>
324 typename It::value_type sumPerfValues(It begin, It end) const;
325
333 template<class RAIterator>
334 void partialSumPerfValues(RAIterator begin, RAIterator end) const
335 {
336 commAboveBelow_->partialSumPerfValues(begin, end);
337 }
338
340 void clear();
341
348
349private:
350
352 struct DestroyComm
353 {
354 void operator()(Parallel::Communication* comm);
355 };
356
357
359 std::string name_;
361 bool hasLocalCells_;
363 bool isOwner_;
365 int rankWithFirstPerf_;
369 std::unique_ptr<Parallel::Communication, DestroyComm> comm_;
370
372 std::unique_ptr<CommunicateAboveBelow<Scalar>> commAboveBelow_;
373
374 std::unique_ptr<GlobalPerfContainerFactory<Scalar>> globalPerfCont_;
375
376 mutable std::unordered_map<int,int> active_to_local_map_; // Cache for active perforation index to local perforation index mapping
377 mutable std::unordered_map<int,int> local_to_active_map_; // Cache for local perforation index to active perforation index mapping
378};
379
383template<class Scalar>
385{
386public:
388 const ParallelWellInfo<Scalar>& info);
389
394 void connectionFound(std::size_t index);
395
397
398private:
399 std::vector<std::size_t> foundConnections_;
400 const Well& well_;
401 const ParallelWellInfo<Scalar>& pwinfo_;
402};
403
404template<class Scalar>
406
407template<class Scalar>
409
410template<class Scalar>
412
413template<class Scalar>
414bool operator<(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
415
416template<class Scalar>
417bool operator<( const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
418
419template<class Scalar>
420bool operator==(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
421
422template<class Scalar>
423bool operator==(const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
424
425template<class Scalar>
426bool operator!=(const std::pair<std::string, bool>& pair, const ParallelWellInfo<Scalar>& well);
427
428template<class Scalar>
429bool operator!=(const ParallelWellInfo<Scalar>& well, const std::pair<std::string, bool>& pair);
430
431} // end namespace Opm
432
433#endif // OPM_PARALLELWELLINFO_HEADER_INCLUDED
Class checking that all connections are on active cells.
Definition: ParallelWellInfo.hpp:385
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:60
Dune::RemoteIndices< IndexSet > RI
Definition: ParallelWellInfo.hpp:74
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:71
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:72
Attribute
Definition: ParallelWellInfo.hpp:62
@ ownerAbove
Definition: ParallelWellInfo.hpp:68
@ overlap
Definition: ParallelWellInfo.hpp:64
@ overlapAbove
Definition: ParallelWellInfo.hpp:69
@ owner
Definition: ParallelWellInfo.hpp:63
A factory for creating a global data representation for distributed wells.
Definition: ParallelWellInfo.hpp:157
GlobalPerfContainerFactory(const IndexSet &local_indices, const Parallel::Communication comm, int num_local_perfs)
Constructor.
int globalToLocal(const int globalIndex) const
void copyGlobalToLocal(const std::vector< Scalar > &global, std::vector< Scalar > &local, std::size_t num_quantities) const
Copies the values of the global perforation to the local representation.
typename CommunicateAboveBelow< Scalar >::Attribute Attribute
Definition: ParallelWellInfo.hpp:160
std::vector< Scalar > createGlobal(const std::vector< Scalar > &local_perf_container, std::size_t num_quantities) const
Creates a container that holds values for all perforations.
typename IndexSet::IndexPair::GlobalIndex GlobalIndex
Definition: ParallelWellInfo.hpp:161
int localToGlobal(std::size_t localIndex) const
typename CommunicateAboveBelow< Scalar >::IndexSet IndexSet
Definition: ParallelWellInfo.hpp:159
Class encapsulating some information about parallel wells.
Definition: ParallelWellInfo.hpp:217
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.
void setActivePerfToLocalPerfMap(const std::unordered_map< int, int > &active_to_local_map) const
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:299
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:309
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:305
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:334
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 communicateFirstPerforation(bool hasFirst)
Collectively decide which rank has first perforation.
static constexpr int INVALID_ECL_INDEX
Definition: ParallelWellInfo.hpp:219
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:234
Dune::Communication< MPIComm > Communication
Definition: ParallelCommunication.hpp:30
Definition: blackoilbioeffectsmodules.hh:45
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
Reservoir temperature and salt concentration of the first perforated cell.
Definition: ParallelWellInfo.hpp:44
void serializeOp(Serializer &serializer)
Definition: ParallelWellInfo.hpp:49
Scalar saltConcentration
Definition: ParallelWellInfo.hpp:46
Scalar temperature
Definition: ParallelWellInfo.hpp:45