mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Add globalToLocal and localToGlobal functions to the ParallelWellInfo class
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
|
||||
#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <cassert>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
@@ -119,6 +120,50 @@ GlobalPerfContainerFactory(const IndexSet& local_indices,
|
||||
}
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
void GlobalPerfContainerFactory<Scalar>::buildLocalToGlobalMap() const {
|
||||
local_to_global_map_.clear();
|
||||
for (const auto& index : local_indices_) {
|
||||
local_to_global_map_[index.local()] = index.global();
|
||||
}
|
||||
l2g_map_built_ = true;
|
||||
}
|
||||
|
||||
|
||||
template<class Scalar>
|
||||
int GlobalPerfContainerFactory<Scalar>::localToGlobal(std::size_t localIndex) const {
|
||||
if (local_indices_.size() == 0)
|
||||
return localIndex;
|
||||
if (!l2g_map_built_)
|
||||
buildLocalToGlobalMap();
|
||||
auto it = local_to_global_map_.find(localIndex);
|
||||
if (it == local_to_global_map_.end())
|
||||
OPM_THROW(std::logic_error, fmt::format("There is no global index for the localIndex {}.", localIndex));
|
||||
return it->second;
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
void GlobalPerfContainerFactory<Scalar>::buildGlobalToLocalMap() const {
|
||||
global_to_local_map_.clear();
|
||||
for (const auto& index : local_indices_) {
|
||||
global_to_local_map_[index.global()] = index.local().local();
|
||||
}
|
||||
g2l_map_built_ = true;
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
int GlobalPerfContainerFactory<Scalar>::globalToLocal(const int globalIndex) const {
|
||||
if (local_indices_.size() == 0)
|
||||
return globalIndex;
|
||||
if (!g2l_map_built_) {
|
||||
buildGlobalToLocalMap();
|
||||
}
|
||||
auto it = global_to_local_map_.find(globalIndex);
|
||||
if (it == global_to_local_map_.end())
|
||||
return -1; // Global index not found
|
||||
return it->second;
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
std::vector<Scalar> GlobalPerfContainerFactory<Scalar>::
|
||||
createGlobal(const std::vector<Scalar>& local_perf_container,
|
||||
@@ -477,6 +522,22 @@ ParallelWellInfo<Scalar>::ParallelWellInfo(const std::pair<std::string, bool>& w
|
||||
isOwner_ = (comm_->rank() == 0);
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
int ParallelWellInfo<Scalar>::localToGlobal(std::size_t localIndex) const {
|
||||
if(globalPerfCont_)
|
||||
return globalPerfCont_->localToGlobal(localIndex);
|
||||
else // If globalPerfCont_ is not set up, then this is a sequential run and local and global indices are the same.
|
||||
return localIndex;
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
int ParallelWellInfo<Scalar>::globalToLocal(const int globalIndex) const {
|
||||
if(globalPerfCont_)
|
||||
return globalPerfCont_->globalToLocal(globalIndex);
|
||||
else // If globalPerfCont_ is not set up, then this is a sequential run and local and global indices are the same.
|
||||
return globalIndex;
|
||||
}
|
||||
|
||||
template<class Scalar>
|
||||
void ParallelWellInfo<Scalar>::communicateFirstPerforation(bool hasFirst)
|
||||
{
|
||||
|
||||
@@ -161,8 +161,16 @@ public:
|
||||
std::size_t num_components) const;
|
||||
|
||||
int numGlobalPerfs() const;
|
||||
int globalToLocal(const int globalIndex) const;
|
||||
int localToGlobal(std::size_t localIndex) const;
|
||||
|
||||
private:
|
||||
void buildLocalToGlobalMap() const;
|
||||
void buildGlobalToLocalMap() const;
|
||||
mutable std::unordered_map<std::size_t, int> local_to_global_map_; // Cache for L2G mapping
|
||||
mutable std::unordered_map<int, std::size_t> global_to_local_map_; // Cache for G2L mapping
|
||||
mutable bool l2g_map_built_ = false;
|
||||
mutable bool g2l_map_built_ = false;
|
||||
const IndexSet& local_indices_;
|
||||
Parallel::Communication comm_;
|
||||
int num_global_perfs_;
|
||||
@@ -208,6 +216,8 @@ public:
|
||||
/// \brief Collectively decide which rank has first perforation.
|
||||
void communicateFirstPerforation(bool hasFirst);
|
||||
|
||||
int globalToLocal(const int globalIndex) const;
|
||||
int localToGlobal(std::size_t localIndex) const;
|
||||
|
||||
/// If the well does not have any open connections the member rankWithFirstPerf
|
||||
/// is not initialized, and no broadcast is performed. In this case the argument
|
||||
|
||||
Reference in New Issue
Block a user