|
3 | 3 | #include "RiaTestDataDirectory.h" |
4 | 4 | #include "RifEclipseInputFileTools.h" |
5 | 5 | #include "RifEclipseInputPropertyLoader.h" |
| 6 | +#include "RigActiveCellInfo.h" |
6 | 7 | #include "RigCaseCellResultsData.h" |
7 | 8 | #include "RigEclipseCaseData.h" |
8 | 9 | #include "RigEclipseResultAddress.h" |
@@ -664,22 +665,22 @@ TEST( RifEclipseInputFileToolsTest, ExportKeywordsWithRefinement ) |
664 | 665 | RigCaseCellResultsData* cellResultsData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); |
665 | 666 | ASSERT_NE( nullptr, cellResultsData ); |
666 | 667 |
|
667 | | - // Look specifically for PORO property |
| 668 | + // Look specifically for PORO property in the results system |
668 | 669 | std::vector<QString> keywordsToExport; |
669 | 670 | auto allResults = cellResultsData->existingResults(); |
670 | 671 | bool foundPoro = false; |
671 | 672 |
|
672 | 673 | for ( const auto& result : allResults ) |
673 | 674 | { |
674 | | - if ( result.resultName() == "PORO" ) |
| 675 | + if ( result.resultName() == "PORO" && result.resultCatType() == RiaDefines::ResultCatType::INPUT_PROPERTY ) |
675 | 676 | { |
676 | 677 | keywordsToExport.push_back( result.resultName() ); |
677 | 678 | foundPoro = true; |
678 | 679 | break; |
679 | 680 | } |
680 | 681 | } |
681 | 682 |
|
682 | | - ASSERT_TRUE( foundPoro ) << "PORO property not found in test data file"; |
| 683 | + ASSERT_TRUE( foundPoro ) << "PORO property not found as INPUT_PROPERTY in result system"; |
683 | 684 |
|
684 | 685 | QTemporaryDir tempDir; |
685 | 686 | ASSERT_TRUE( tempDir.isValid() ); |
@@ -728,16 +729,102 @@ TEST( RifEclipseInputFileToolsTest, ExportKeywordsWithRefinement ) |
728 | 729 | EXPECT_EQ( originalGrid->cellCountJ() * refinement.y(), refinedGrid->cellCountJ() ) << "Refined J dimension incorrect"; |
729 | 730 | EXPECT_EQ( originalGrid->cellCountK() * refinement.z(), refinedGrid->cellCountK() ) << "Refined K dimension incorrect"; |
730 | 731 |
|
731 | | - // Try to import the exported keywords back into the refined grid case |
732 | | - // This test is expected to FAIL due to a bug in the export function: |
733 | | - // The export outputs values for active cells only, but the refined grid has more total cells |
| 732 | + // Import the exported keywords back into the refined grid case |
734 | 733 | auto propertyMap = RifEclipseInputPropertyLoader::readProperties( exportFileName, refinedEclipseCase.get() ); |
735 | 734 |
|
736 | | - // This test documents the bug: the export should create the same number of values as refined cells |
737 | | - // Currently it exports 25830 values but refined grid has 27048 cells |
738 | | - EXPECT_FALSE( propertyMap.empty() ) << "BUG: Should have imported properties but export doesn't match refined grid cell count"; |
739 | | - EXPECT_TRUE( propertyMap.find( "PORO" ) != propertyMap.end() ) |
740 | | - << "BUG: Should have imported PORO property but cell count mismatch prevents import"; |
| 735 | + // Verify the import was successful |
| 736 | + EXPECT_FALSE( propertyMap.empty() ) << "Should have imported properties successfully"; |
| 737 | + EXPECT_TRUE( propertyMap.find( "PORO" ) != propertyMap.end() ) << "Should have imported PORO property"; |
| 738 | + |
| 739 | + // Get the imported PORO data from both original and refined cases |
| 740 | + RigCaseCellResultsData* originalResultsData = eclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); |
| 741 | + RigCaseCellResultsData* refinedResultsData = refinedEclipseCase->results( RiaDefines::PorosityModelType::MATRIX_MODEL ); |
| 742 | + |
| 743 | + RigEclipseResultAddress poroAddress( RiaDefines::ResultCatType::INPUT_PROPERTY, "PORO" ); |
| 744 | + |
| 745 | + // Ensure both datasets are loaded |
| 746 | + bool originalLoaded = originalResultsData->ensureKnownResultLoaded( poroAddress ); |
| 747 | + bool refinedLoaded = refinedResultsData->ensureKnownResultLoaded( poroAddress ); |
| 748 | + |
| 749 | + ASSERT_TRUE( originalLoaded ) << "Original PORO data should be available after loading properties"; |
| 750 | + ASSERT_TRUE( refinedLoaded ) << "Refined PORO data should be loaded after import"; |
| 751 | + |
| 752 | + auto originalPoroValues = originalResultsData->cellScalarResults( poroAddress ); |
| 753 | + auto refinedPoroValues = refinedResultsData->cellScalarResults( poroAddress ); |
| 754 | + |
| 755 | + ASSERT_FALSE( originalPoroValues.empty() ) << "Original PORO values should not be empty"; |
| 756 | + ASSERT_FALSE( refinedPoroValues.empty() ) << "Refined PORO values should not be empty"; |
| 757 | + ASSERT_FALSE( originalPoroValues[0].empty() ) << "Original PORO values first time step should not be empty"; |
| 758 | + ASSERT_FALSE( refinedPoroValues[0].empty() ) << "Refined PORO values first time step should not be empty"; |
| 759 | + |
| 760 | + const auto& originalData = originalPoroValues[0]; |
| 761 | + const auto& refinedData = refinedPoroValues[0]; |
| 762 | + |
| 763 | + // Verify refined data has the expected size |
| 764 | + EXPECT_EQ( refinedGrid->cellCount(), refinedData.size() ) << "Refined PORO data size should match refined cell count"; |
| 765 | + |
| 766 | + // Find an active cell to test the refinement mapping principle |
| 767 | + auto findActiveCell = []( RigMainGrid* originalGrid, RigCaseCellResultsData* originalResultsData, const std::vector<double>& originalData ) |
| 768 | + { |
| 769 | + // Search for an active cell to test with |
| 770 | + for ( size_t k = 0; k < originalGrid->cellCountK(); ++k ) |
| 771 | + { |
| 772 | + for ( size_t j = 0; j < originalGrid->cellCountJ(); ++j ) |
| 773 | + { |
| 774 | + for ( size_t i = 0; i < originalGrid->cellCountI(); ++i ) |
| 775 | + { |
| 776 | + size_t originalCellIndex = originalGrid->cellIndexFromIJK( i, j, k ); |
| 777 | + size_t originalResultIndex = originalResultsData->activeCellInfo()->cellResultIndex( originalCellIndex ); |
| 778 | + |
| 779 | + if ( originalResultIndex != cvf::UNDEFINED_SIZE_T && originalResultIndex < originalData.size() ) |
| 780 | + { |
| 781 | + return cvf::Vec3st( i, j, k ); |
| 782 | + } |
| 783 | + } |
| 784 | + } |
| 785 | + } |
| 786 | + |
| 787 | + return cvf::Vec3st::UNDEFINED; |
| 788 | + }; |
| 789 | + |
| 790 | + cvf::Vec3st testCell = findActiveCell( originalGrid, originalResultsData, originalData ); |
| 791 | + ASSERT_FALSE( testCell.isUndefined() ) << "Should find at least one active cell with PORO data to test refinement mapping"; |
| 792 | + |
| 793 | + size_t originalCellIndex = originalGrid->cellIndexFromIJK( testCell.x(), testCell.y(), testCell.z() ); |
| 794 | + size_t originalResultIndex = originalResultsData->activeCellInfo()->cellResultIndex( originalCellIndex ); |
| 795 | + double originalPoroValue = originalData[originalResultIndex]; |
| 796 | + |
| 797 | + // Check all 4 refined cells (2x2x1) that correspond to this original cell |
| 798 | + int matchingCells = 0; |
| 799 | + for ( size_t refK = 0; refK < refinement.z(); ++refK ) |
| 800 | + { |
| 801 | + for ( size_t refJ = 0; refJ < refinement.y(); ++refJ ) |
| 802 | + { |
| 803 | + for ( size_t refI = 0; refI < refinement.x(); ++refI ) |
| 804 | + { |
| 805 | + size_t refinedI = testCell.x() * refinement.x() + refI; |
| 806 | + size_t refinedJ = testCell.y() * refinement.y() + refJ; |
| 807 | + size_t refinedK = testCell.z() * refinement.z() + refK; |
| 808 | + |
| 809 | + size_t refinedCellIndex = refinedGrid->cellIndexFromIJK( refinedI, refinedJ, refinedK ); |
| 810 | + if ( refinedCellIndex < refinedData.size() ) |
| 811 | + { |
| 812 | + double refinedPoroValue = refinedData[refinedCellIndex]; |
| 813 | + |
| 814 | + EXPECT_NEAR( originalPoroValue, refinedPoroValue, 1e-6 ) |
| 815 | + << "Refined cell (" << refinedI << "," << refinedJ << "," << refinedK << ") should match original cell (" |
| 816 | + << testCell.x() << "," << testCell.y() << "," << testCell.z() << ") PORO value"; |
| 817 | + |
| 818 | + if ( std::abs( originalPoroValue - refinedPoroValue ) < 1e-6 ) |
| 819 | + { |
| 820 | + matchingCells++; |
| 821 | + } |
| 822 | + } |
| 823 | + } |
| 824 | + } |
| 825 | + } |
| 826 | + |
| 827 | + EXPECT_EQ( 4, matchingCells ) << "All 4 refined cells should match the original cell value for cell"; |
741 | 828 | } |
742 | 829 |
|
743 | 830 | //-------------------------------------------------------------------------------------------------- |
|
0 commit comments