From 9b997aea8c024ffaeb7cbb0a6167711d016214be Mon Sep 17 00:00:00 2001 From: Markus Blatt Date: Thu, 17 Sep 2020 12:12:14 +0200 Subject: [PATCH] Use FieldData in ParallelEclipseState. We will need the values_status for the TranCalculator in parallel. --- opm/simulators/utils/ParallelEclipseState.cpp | 22 +++++---- opm/simulators/utils/ParallelEclipseState.hpp | 4 +- .../utils/PropsCentroidsDataHandle.hpp | 46 +++++++++++++++---- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/opm/simulators/utils/ParallelEclipseState.cpp b/opm/simulators/utils/ParallelEclipseState.cpp index d11a57235..d82255d38 100644 --- a/opm/simulators/utils/ParallelEclipseState.cpp +++ b/opm/simulators/utils/ParallelEclipseState.cpp @@ -68,17 +68,18 @@ const std::vector& ParallelFieldPropsManager::get_int(const std::string& ke // Some of the keywords might be defaulted. // We will let rank 0 create them and distribute them using get_global_int auto data = get_global_int(keyword); - auto& local_data = const_cast>&>(m_intProps)[keyword]; - local_data.resize(m_activeSize()); + auto& local_data = const_cast>&>(m_intProps)[keyword]; + local_data.data.resize(m_activeSize()); + local_data.value_status.resize(m_activeSize()); for (int i = 0; i < m_activeSize(); ++i) { - local_data[i] = data[m_local2Global(i)]; + local_data.data[i] = data[m_local2Global(i)]; } - return local_data; + return local_data.data; } - return it->second; + return it->second.data; } std::vector ParallelFieldPropsManager::get_global_int(const std::string& keyword) const @@ -121,16 +122,17 @@ const std::vector& ParallelFieldPropsManager::get_double(const std::stri // Some of the keywords might be defaulted. // We will let rank 0 create them and distribute them using get_global_int auto data = get_global_double(keyword); - auto& local_data = const_cast>&>(m_doubleProps)[keyword]; - local_data.resize(m_activeSize()); + auto& local_data = const_cast>&>(m_doubleProps)[keyword]; + local_data.data.resize(m_activeSize()); + local_data.value_status.resize(m_activeSize()); for (int i = 0; i < m_activeSize(); ++i) { - local_data[i] = data[m_local2Global(i)]; + local_data.data[i] = data[m_local2Global(i)]; } - return local_data; + return local_data.data; } - return it->second; + return it->second.data; } diff --git a/opm/simulators/utils/ParallelEclipseState.hpp b/opm/simulators/utils/ParallelEclipseState.hpp index 60a189ce1..07f494b4f 100644 --- a/opm/simulators/utils/ParallelEclipseState.hpp +++ b/opm/simulators/utils/ParallelEclipseState.hpp @@ -96,8 +96,8 @@ public: std::placeholders::_1); } protected: - std::map> m_intProps; //!< Map of integer properties in process-local compressed indices. - std::map> m_doubleProps; //!< Map of double properties in process-local compressed indices. + std::map> m_intProps; //!< Map of integer properties in process-local compressed indices. + std::map> m_doubleProps; //!< Map of double properties in process-local compressed indices. FieldPropsManager& m_manager; //!< Underlying field property manager (only used on root process). Dune::CollectiveCommunication m_comm; //!< Collective communication handler. std::function m_activeSize; //!< active size function of the grid diff --git a/opm/simulators/utils/PropsCentroidsDataHandle.hpp b/opm/simulators/utils/PropsCentroidsDataHandle.hpp index cb31b916a..3ae6aac6d 100644 --- a/opm/simulators/utils/PropsCentroidsDataHandle.hpp +++ b/opm/simulators/utils/PropsCentroidsDataHandle.hpp @@ -50,7 +50,7 @@ class PropsCentroidsDataHandle { public: //! \brief the data type we send (ints are converted to double) - using DataType = double; + using DataType = std::pair; //! \brief Constructor //! \param grid The grid where the loadbalancing is happening. @@ -106,15 +106,23 @@ public: data.reserve(m_no_data); for (const auto& intKey : m_intKeys) - data.push_back(globalProps.get_int(intKey)[index]); + { + const auto& fieldData = globalProps.get_int_field_data(intKey); + data.push_back(std::make_pair(fieldData.data[index], + static_cast(fieldData.value_status[index]))); + } for (const auto& doubleKey : m_doubleKeys) - data.push_back(globalProps.get_double(doubleKey)[index]); + { + const auto& fieldData = globalProps.get_double_field_data(doubleKey); + data.push_back(std::make_pair(fieldData.data[index], + static_cast(fieldData.value_status[index]))); + } auto cartIndex = cartMapper.cartesianIndex(index); const auto& center = eclGridOnRoot->getCellCenter(cartIndex); for (int dim = 0; dim < Grid::dimensionworld; ++dim) - data.push_back(center[dim]); + data.push_back(std::make_pair(center[dim], '1')); // write garbage for value_status } } else @@ -136,10 +144,16 @@ public: { // distributed grid is now correctly set up. for(const auto& intKey : m_intKeys) - m_distributed_fieldProps.m_intProps[intKey].resize(m_grid.size(0)); + { + m_distributed_fieldProps.m_intProps[intKey].data.resize(m_grid.size(0)); + m_distributed_fieldProps.m_intProps[intKey].value_status.resize(m_grid.size(0)); + } for(const auto& doubleKey : m_doubleKeys) - m_distributed_fieldProps.m_doubleProps[doubleKey].resize(m_grid.size(0)); + { + m_distributed_fieldProps.m_doubleProps[doubleKey].data.resize(m_grid.size(0)); + m_distributed_fieldProps.m_doubleProps[doubleKey].value_status.resize(m_grid.size(0)); + } m_centroids.resize(m_grid.size(0) * Grid::dimensionworld); @@ -159,15 +173,23 @@ public: assert(data != elementData_.end()); for(const auto& intKey : m_intKeys) - m_distributed_fieldProps.m_intProps[intKey][index] = static_cast(data->second[counter++]); + { + const auto& pair = data->second[counter++]; + m_distributed_fieldProps.m_intProps[intKey].data[index] = static_cast(pair.first); + m_distributed_fieldProps.m_intProps[intKey].value_status[index] = static_cast(pair.second); + } for(const auto& doubleKey : m_doubleKeys) - m_distributed_fieldProps.m_doubleProps[doubleKey][index] = data->second[counter++]; + { + const auto& pair = data->second[counter++]; + m_distributed_fieldProps.m_doubleProps[doubleKey].data[index] = pair.first; + m_distributed_fieldProps.m_doubleProps[doubleKey].value_status[index] = static_cast(pair.second); + } auto centroidIter = m_centroids.begin() + Grid::dimensionworld * index; auto centroidIterEnd = centroidIter + Grid::dimensionworld; for ( ; centroidIter != centroidIterEnd; ++centroidIter ) - *centroidIter = data->second[counter++]; + *centroidIter = data->second[counter++].first; // value_status discarded } } @@ -197,7 +219,9 @@ public: auto iter = elementData_.find(m_grid.localIdSet().id(e)); assert(iter != elementData_.end()); for(const auto& data : iter->second) + { buffer.write(data); + } } template @@ -222,7 +246,9 @@ private: //! \brief The names of the keys of the double fields. std::vector m_doubleKeys; /// \brief The data per element as a vector mapped from the local id. - std::unordered_map > elementData_; + /// + /// each entry is a pair of data and value_status. + std::unordered_map > > elementData_; /// \brief The cell centroids of the distributed grid. std::vector& m_centroids; /// \brief The amount of data to send for each element