void RegressionTest::deviationsForCell(double val1, double val2, const std::string& keyword, int occurrence1, int occurrence2, size_t cell, bool allowNegativeValues) {
    double absTolerance = getAbsTolerance();
    double relTolerance = getRelTolerance();
    if (!allowNegativeValues) {
        if (val1 < 0) {
            if (std::abs(val1) > absTolerance) {
                printValuesForCell(keyword, occurrence1, occurrence2, cell, val1, val2);
                OPM_THROW(std::runtime_error, "Negative value in first file, "
                        << "which in absolute value exceeds the absolute tolerance of " << absTolerance << ".");
            }
            val1 = 0;
        }
        if (val2 < 0) {
            if (std::abs(val2) > absTolerance) {
                printValuesForCell(keyword, occurrence1, occurrence2, cell, val1, val2);
                OPM_THROW(std::runtime_error, "Negative value in second file, "
                        << "which in absolute value exceeds the absolute tolerance of " << absTolerance << ".");
            }
            val2 = 0;
        }
    }
    Deviation dev = calculateDeviations(val1, val2);
    if (dev.abs > absTolerance && dev.rel > relTolerance) {
        printValuesForCell(keyword, occurrence1, occurrence2, cell, val1, val2);
        OPM_THROW(std::runtime_error, "Deviations exceed tolerances."
                << "\nThe absolute deviation is " << dev.abs << ", and the tolerance limit is " << absTolerance << "."
                << "\nThe relative deviation is " << dev.rel << ", and the tolerance limit is " << relTolerance << ".");
    }
    if (dev.abs != -1) {
        absDeviation.push_back(dev.abs);
    }
    if (dev.rel != -1) {
        relDeviation.push_back(dev.rel);
    }
}
void ECLFilesComparator::deviationsForCell(double val1, double val2, const std::string& keyword, int occurence, int cell, bool allowNegativeValues) {
    int i, j, k;
    ecl_grid_get_ijk1(ecl_grid1, cell, &i, &j, &k);
    // Coordinates from this function are zero-based, hence incrementing
    i++, j++, k++;

    if (showValues) {
        std::cout << "Occurence        = "  << occurence << std::endl;
        std::cout << "Grid coordinate  = (" << i << ", " << j << ", " << k << ")\n";
        std::cout << "(value1, value2) = (" << val1 << ", " << val2 << ")\n\n";
    }
    if (!allowNegativeValues) {
        if (val1 < 0) {
            if (std::abs(val1) > absTolerance) {
                std::cout << "For keyword " << keyword << " (which is listed for positive values only), occurence " << occurence
                    << ", and grid coordinate (" << i << ", " << j << ", " << k << "):\n"
                    << "the vector has a value of " << val1 << ", which exceeds the absolute tolerance of " << absTolerance << ".\n";
                OPM_THROW(std::runtime_error, "Negative value in first file.");
            }
            val1 = 0;
        }
        if (val2 < 0) {
            if (std::abs(val2) > absTolerance) {
                std::cout << "For keyword " << keyword << " (which is listed for positive values only), occurence " << occurence
                    << ", and grid coordinate (" << i << ", " << j << ", " << k << "):\n"
                    << "the vector has a value of " << val2 << ", which exceeds the absolute tolerance of " << absTolerance << ".\n";
                OPM_THROW(std::runtime_error, "Negative value in second file.");
            }
            val2 = 0;
        }
    }
    Deviation dev = calculateDeviations(val1, val2);
    if (dev.abs > absTolerance && dev.rel > relTolerance) {
        std::cout << "For keyword " << keyword << ", occurence " << occurence
            << ", and grid coordinate (" << i << ", " << j << ", " << k << "):\n"
            << "(first value, second value) = (" << val1 << ", " << val2 << ")\n";
        std::cout << "The absolute deviation is " << dev.abs << ", and the tolerance limit is " << absTolerance << ".\n";
        std::cout << "The relative deviation is " << dev.rel << ", and the tolerance limit is " << relTolerance << ".\n";
        OPM_THROW(std::runtime_error, "Absolute deviation exceeds tolerance.");
    }
    if (dev.abs != -1) {
        absDeviation.push_back(dev.abs);
    }
    if (dev.rel != -1) {
        relDeviation.push_back(dev.rel);
    }
}
void IntegrationTest::setCellVolumes() {
    double absTolerance = getAbsTolerance();
    double relTolerance = getRelTolerance();
    const unsigned int globalGridCount1 = ecl_grid_get_global_size(ecl_grid1);
    const unsigned int activeGridCount1 = ecl_grid_get_active_size(ecl_grid1);
    const unsigned int globalGridCount2 = ecl_grid_get_global_size(ecl_grid2);
    const unsigned int activeGridCount2 = ecl_grid_get_active_size(ecl_grid2);
    if (globalGridCount1 != globalGridCount2) {
        OPM_THROW(std::runtime_error, "In grid file:"
                << "\nCells in first file: "  << globalGridCount1
                << "\nCells in second file: " << globalGridCount2
                << "\nThe number of global cells differ.");
    }
    if (activeGridCount1 != activeGridCount2) {
        OPM_THROW(std::runtime_error, "In grid file:"
                << "\nCells in first file: "  << activeGridCount1
                << "\nCells in second file: " << activeGridCount2
                << "\nThe number of active cells differ.");
    }
    for (unsigned int cell = 0; cell < globalGridCount1; ++cell) {
        const double cellVolume1 = ecl_grid_get_cell_volume1(ecl_grid1, cell);
        const double cellVolume2 = ecl_grid_get_cell_volume1(ecl_grid2, cell);
        Deviation dev = calculateDeviations(cellVolume1, cellVolume2);
        if (dev.abs > absTolerance && dev.rel > relTolerance) {
            int i, j, k;
            ecl_grid_get_ijk1(ecl_grid1, cell, &i, &j, &k);
            // Coordinates from this function are zero-based, hence incrementing
            i++, j++, k++;
            OPM_THROW(std::runtime_error, "In grid file: Deviations of cell volume exceed tolerances. "
                    << "\nFor cell with coordinate (" << i << ", " << j << ", " << k << "):"
                    << "\nCell volume in first file: "  << cellVolume1
                    << "\nCell volume in second file: " << cellVolume2
                    << "\nThe absolute deviation is " << dev.abs << ", and the tolerance limit is " << absTolerance << "."
                    << "\nThe relative deviation is " << dev.rel << ", and the tolerance limit is " << relTolerance << ".");
        } // The second input case is used as reference.
        cellVolumes.push_back(cellVolume2);
    }
}