mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-16 17:54:47 -06:00
Save space for cartesianToCompressed mapping.
For 10 Million cell problems my compute server (with 128 GB Ram) starts to swap, when I use debugging tools in parallel runs. I assume that this might get an issue for others, too. Now we consistently use unordered_map for the mapping.
This commit is contained in:
parent
2f86231b8d
commit
33645cb4f6
@ -297,8 +297,11 @@ public:
|
||||
*/
|
||||
int compressedIndex(int cartesianCellIdx) const
|
||||
{
|
||||
int index = cartesianToCompressed_[cartesianCellIdx];
|
||||
return index;
|
||||
auto index_pair = cartesianToCompressed_.find(cartesianCellIdx);
|
||||
if (index_pair!=cartesianToCompressed_.end())
|
||||
return index_pair->second;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -399,7 +402,6 @@ protected:
|
||||
void updateCartesianToCompressedMapping_()
|
||||
{
|
||||
size_t num_cells = asImp_().grid().leafGridView().size(0);
|
||||
cartesianToCompressed_.resize(cartesianSize(), -1);
|
||||
for (unsigned i = 0; i < num_cells; ++i) {
|
||||
unsigned cartesianCellIdx = cartesianIndex(i);
|
||||
cartesianToCompressed_[cartesianCellIdx] = i;
|
||||
@ -482,7 +484,7 @@ protected:
|
||||
/*! \brief Mapping between cartesian and compressed cells.
|
||||
* It is initialized the first time it is called
|
||||
*/
|
||||
std::vector<int> cartesianToCompressed_;
|
||||
std::unordered_map<int,int> cartesianToCompressed_;
|
||||
|
||||
/*! \brief Cell center depths
|
||||
*/
|
||||
|
@ -472,9 +472,7 @@ update(bool global)
|
||||
updateFromEclState_(global);
|
||||
|
||||
// Create mapping from global to local index
|
||||
const size_t cartesianSize = cartMapper_.cartesianSize();
|
||||
// reserve memory
|
||||
std::vector<int> globalToLocal(cartesianSize, -1);
|
||||
std::unordered_map<std::size_t,int> globalToLocal;
|
||||
|
||||
// loop over all elements (global grid) and store Cartesian index
|
||||
elemIt = grid_.leafGridView().template begin<0>();
|
||||
@ -813,7 +811,7 @@ computeFaceProperties(const Intersection& intersection,
|
||||
template<class Grid, class GridView, class ElementMapper, class Scalar>
|
||||
std::tuple<std::vector<NNCdata>, std::vector<NNCdata>>
|
||||
EclTransmissibility<Grid,GridView,ElementMapper,Scalar>::
|
||||
applyNncToGridTrans_(const std::vector<int>& cartesianToCompressed)
|
||||
applyNncToGridTrans_(const std::unordered_map<std::size_t,int>& cartesianToCompressed)
|
||||
{
|
||||
// First scale NNCs with EDITNNC.
|
||||
std::vector<NNCdata> unprocessedNnc;
|
||||
@ -825,8 +823,10 @@ applyNncToGridTrans_(const std::vector<int>& cartesianToCompressed)
|
||||
for (const auto& nncEntry : nnc_input) {
|
||||
auto c1 = nncEntry.cell1;
|
||||
auto c2 = nncEntry.cell2;
|
||||
auto low = cartesianToCompressed[c1];
|
||||
auto high = cartesianToCompressed[c2];
|
||||
auto lowIt = cartesianToCompressed.find(c1);
|
||||
auto highIt = cartesianToCompressed.find(c2);
|
||||
int low = (lowIt == cartesianToCompressed.end())? -1 : lowIt->second;
|
||||
int high = (highIt == cartesianToCompressed.end())? -1 : highIt->second;
|
||||
|
||||
if (low > high)
|
||||
std::swap(low, high);
|
||||
@ -863,7 +863,7 @@ applyNncToGridTrans_(const std::vector<int>& cartesianToCompressed)
|
||||
|
||||
template<class Grid, class GridView, class ElementMapper, class Scalar>
|
||||
void EclTransmissibility<Grid,GridView,ElementMapper,Scalar>::
|
||||
applyEditNncToGridTrans_(const std::vector<int>& globalToLocal)
|
||||
applyEditNncToGridTrans_(const std::unordered_map<std::size_t,int>& globalToLocal)
|
||||
{
|
||||
const auto& nnc_input = eclState_.getInputNNC();
|
||||
const auto& editNnc = nnc_input.edit();
|
||||
@ -879,11 +879,13 @@ applyEditNncToGridTrans_(const std::vector<int>& globalToLocal)
|
||||
return fmt::format("({},{},{})", i + 1,j + 1,k + 1);
|
||||
};
|
||||
|
||||
auto make_warning = [&format_ijk] (const KeywordLocation& location, const NNCdata& nnc) -> std::string {
|
||||
return fmt::format("Problem with EDITNNC keyword\n"
|
||||
"In {} line {} \n"
|
||||
"No NNC defined for connection {} -> {}", location.filename, location.lineno, format_ijk(nnc.cell1), format_ijk(nnc.cell2));
|
||||
|
||||
auto print_warning = [&format_ijk, &nnc_input] (const NNCdata& nnc) {
|
||||
const auto& location = nnc_input.edit_location( nnc );
|
||||
auto warning = fmt::format("Problem with EDITNNC keyword\n"
|
||||
"In {} line {} \n"
|
||||
"No NNC defined for connection {} -> {}", location.filename,
|
||||
location.lineno, format_ijk(nnc.cell1), format_ijk(nnc.cell2));
|
||||
OpmLog::warning("EDITNNC", warning);
|
||||
};
|
||||
|
||||
// editNnc is supposed to only reference non-neighboring connections and not
|
||||
@ -895,16 +897,24 @@ applyEditNncToGridTrans_(const std::vector<int>& globalToLocal)
|
||||
while (nnc != end) {
|
||||
auto c1 = nnc->cell1;
|
||||
auto c2 = nnc->cell2;
|
||||
auto low = globalToLocal[c1];
|
||||
auto high = globalToLocal[c2];
|
||||
auto lowIt = globalToLocal.find(c1);
|
||||
auto highIt = globalToLocal.find(c2);
|
||||
|
||||
if (lowIt == globalToLocal.end() || highIt == globalToLocal.end()) {
|
||||
print_warning(*nnc);
|
||||
++nnc;
|
||||
warning_count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
auto low = lowIt->second, high = highIt->second;
|
||||
|
||||
if (low > high)
|
||||
std::swap(low, high);
|
||||
|
||||
auto candidate = trans_.find(isId(low, high));
|
||||
if (candidate == trans_.end()) {
|
||||
const auto& location = nnc_input.edit_location( *nnc );
|
||||
auto warning = make_warning(location, *nnc);
|
||||
OpmLog::warning("EDITNNC", warning);
|
||||
print_warning(*nnc);
|
||||
++nnc;
|
||||
warning_count++;
|
||||
}
|
||||
|
@ -194,10 +194,10 @@ protected:
|
||||
* inactive cells are omitted in these vectors.
|
||||
*/
|
||||
std::tuple<std::vector<NNCdata>, std::vector<NNCdata>>
|
||||
applyNncToGridTrans_(const std::vector<int>& cartesianToCompressed);
|
||||
applyNncToGridTrans_(const std::unordered_map<std::size_t,int>& cartesianToCompressed);
|
||||
|
||||
/// \brief Multiplies the grid transmissibilities according to EDITNNC.
|
||||
void applyEditNncToGridTrans_(const std::vector<int>& globalToLocal);
|
||||
void applyEditNncToGridTrans_(const std::unordered_map<std::size_t,int>& globalToLocal);
|
||||
|
||||
void extractPermeability_();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user