Transmissibility: add a cache for centroids and use this in update()

The loops repeatedly calls distanceVector which recalculates
the centroid for a cell. This is not a trivial calculation
This commit is contained in:
Arne Morten Kvarving 2025-01-16 11:53:09 +01:00
parent 635d7d77dd
commit 9a97bf41c5
2 changed files with 12 additions and 1 deletions

View File

@ -284,6 +284,7 @@ protected:
const CartesianIndexMapper& cartMapper_;
const Grid& grid_;
std::function<std::array<double,dimWorld>(int)> centroids_;
std::vector<std::array<double,dimWorld>> centroids_cache_;
Scalar transmissibilityThreshold_;
std::map<std::pair<unsigned, unsigned>, Scalar> transBoundary_;
std::map<std::pair<unsigned, unsigned>, Scalar> thermalHalfTransBoundary_;

View File

@ -236,6 +236,13 @@ update(bool global, const TransUpdateQuantities update_quantities,
comm.broadcast(&pinchActive, 1, 0);
}
// fill the centroids cache to avoid repeated calculations in loops below
centroids_cache_.resize(gridView_.size(0));
for (const auto& elem : elements(gridView_)) {
const unsigned elemIdx = elemMapper.index(elem);
centroids_cache_[elemIdx] = centroids_(elemIdx);
}
// compute the transmissibilities for all intersections
for (const auto& elem : elements(gridView_)) {
unsigned elemIdx = elemMapper.index(elem);
@ -529,6 +536,8 @@ update(bool global, const TransUpdateQuantities update_quantities,
}
}
centroids_cache_.clear();
// Potentially overwrite and/or modify transmissibilities based on input from deck
this->updateFromEclState_(global);
@ -1321,7 +1330,8 @@ Transmissibility<Grid,GridView,ElementMapper,CartesianIndexMapper,Scalar>::
distanceVector_(const DimVector& faceCenter,
const unsigned& cellIdx) const
{
const auto& cellCenter = centroids_(cellIdx);
const auto& cellCenter = centroids_cache_.empty() ? centroids_(cellIdx)
: centroids_cache_[cellIdx];
DimVector x = faceCenter;
for (unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
x[dimIdx] -= cellCenter[dimIdx];