mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#3644 Write unit test for cell volume calculation and fix negative volumes for "flipped" cells.
This commit is contained in:
@@ -78,8 +78,8 @@ double RigCellGeometryTools::calculateCellVolume(const std::array<cvf::Vec3d, 8>
|
|||||||
// 2 flops for summation + 1 for division = 3 flops
|
// 2 flops for summation + 1 for division = 3 flops
|
||||||
double volume = (det1 + det2 + det3) / 12.0;
|
double volume = (det1 + det2 + det3) / 12.0;
|
||||||
|
|
||||||
// Assume 0 in volume for degenerate cells. 1 flop.
|
// In order for this to work in any rotation of the cell, we need the absolute value. 1 flop.
|
||||||
return std::max(0.0, volume); // Altogether 18 + 3*17 + 3 + 1 flops = 73 flops.
|
return std::abs(volume); // Altogether 18 + 3*17 + 3 + 1 flops = 73 flops.
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -21,6 +21,27 @@
|
|||||||
#include "RigCellGeometryTools.h"
|
#include "RigCellGeometryTools.h"
|
||||||
#include "RigMainGrid.h"
|
#include "RigMainGrid.h"
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
TEST(RigCellGeometryTools, calculateCellVolumeTest)
|
||||||
|
{
|
||||||
|
cvf::BoundingBox bbox(cvf::Vec3d(1.0, -2.0, 5.0), cvf::Vec3d(200.0, 3.0, 1500.0));
|
||||||
|
cvf::Vec3d extent = bbox.extent();
|
||||||
|
double bboxVolume = extent.x() * extent.y() * extent.z();
|
||||||
|
|
||||||
|
std::array<cvf::Vec3d, 8> cornerVertices;
|
||||||
|
bbox.cornerVertices(cornerVertices.data());
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(bboxVolume, RigCellGeometryTools::calculateCellVolume(cornerVertices));
|
||||||
|
|
||||||
|
cornerVertices[1].x() += 100.0;
|
||||||
|
cornerVertices[2].x() += 100.0;
|
||||||
|
|
||||||
|
double extraVolume = 0.5 * extent.z() * 100 * extent.y();
|
||||||
|
|
||||||
|
EXPECT_DOUBLE_EQ(bboxVolume + extraVolume, RigCellGeometryTools::calculateCellVolume(cornerVertices));
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user