mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3630 Fix volume sum calculation to avoid multiplying by volume twice.
This commit is contained in:
parent
ef4b70d6e5
commit
50a0924f84
@ -7,6 +7,7 @@
|
||||
#include "RigActiveCellInfo.h"
|
||||
#include "RigCaseCellResultsData.h"
|
||||
#include "RigCell.h"
|
||||
#include "RigCellGeometryTools.h"
|
||||
#include "RigEclipseCaseData.h"
|
||||
#include "RigHexIntersectionTools.h"
|
||||
#include "RigMainGrid.h"
|
||||
@ -243,11 +244,23 @@ void Rim2dGridProjection::generateResults()
|
||||
}
|
||||
}
|
||||
|
||||
#pragma omp parallel for
|
||||
for (int index = 0; index < nVertices; ++index)
|
||||
if (m_resultAggregation == RESULTS_SUM && view->cellResult()->resultVariable() == RiaDefines::riCellVolumeResultName())
|
||||
{
|
||||
cvf::Vec2ui ij = ijFromGridIndex(index);
|
||||
m_aggregatedResults[index] = calculateValue(ij.x(), ij.y());
|
||||
#pragma omp parallel for
|
||||
for (int index = 0; index < nVertices; ++index)
|
||||
{
|
||||
cvf::Vec2ui ij = ijFromGridIndex(index);
|
||||
m_aggregatedResults[index] = calculateVolumeSum(ij.x(), ij.y());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#pragma omp parallel for
|
||||
for (int index = 0; index < nVertices; ++index)
|
||||
{
|
||||
cvf::Vec2ui ij = ijFromGridIndex(index);
|
||||
m_aggregatedResults[index] = calculateValue(ij.x(), ij.y());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -470,7 +483,7 @@ double Rim2dGridProjection::calculateValue(uint i, uint j) const
|
||||
for (auto cellIdxAndWeight : matchingCells)
|
||||
{
|
||||
size_t cellIdx = cellIdxAndWeight.first;
|
||||
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
||||
double cellValue = m_resultAccessor->cellScalarGlobIdx(cellIdx);
|
||||
sum += cellValue * cellIdxAndWeight.second;
|
||||
}
|
||||
return sum;
|
||||
@ -495,6 +508,25 @@ double Rim2dGridProjection::calculateValue(uint i, uint j) const
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
double Rim2dGridProjection::calculateVolumeSum(uint i, uint j) const
|
||||
{
|
||||
const std::vector<std::pair<size_t, float>>& matchingCells = cellsAtPos2d(i, j);
|
||||
if (!matchingCells.empty())
|
||||
{
|
||||
double sum = 0.0;
|
||||
for (auto cellIdxAndWeight : matchingCells)
|
||||
{
|
||||
// Sum only the volume intersection, not the result!
|
||||
sum += cellIdxAndWeight.second;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -95,6 +95,7 @@ public:
|
||||
|
||||
protected:
|
||||
double calculateValue(uint i, uint j) const;
|
||||
double calculateVolumeSum(uint i, uint j) const;
|
||||
|
||||
cvf::BoundingBox expandedBoundingBox() const;
|
||||
void generateGridMapping();
|
||||
|
@ -45,8 +45,8 @@
|
||||
/// |/ |/
|
||||
/// 0---------1
|
||||
///
|
||||
/// While in ResInsight, this is the numbering. Thus 2<->3, 6<->7 from the paper.
|
||||
/// Note the negative k!
|
||||
/// While in ResInsight, this is the numbering. Thus we need to swap 2<->3, 6<->7 in the equations.
|
||||
/// Note the negative k! This causes an additional set of 0<->4, 1<->5, etc. index swaps.
|
||||
/// 7---------6
|
||||
/// /| /| |-k
|
||||
/// / | / | | /j
|
||||
@ -77,8 +77,9 @@ double RigCellGeometryTools::calculateCellVolume(const std::array<cvf::Vec3d, 8>
|
||||
|
||||
// 2 flops for summation + 1 for division = 3 flops
|
||||
double volume = (det1 + det2 + det3) / 12.0;
|
||||
CVF_ASSERT(volume > 0.0);
|
||||
return volume;
|
||||
|
||||
// Assume 0 in volume for degenerate cells. 1 flop.
|
||||
return std::max(0.0, volume); // Altogether 18 + 3*17 + 3 + 1 flops = 73 flops.
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user