From a17ae448d7c4875b83fdb14347410fc927452114 Mon Sep 17 00:00:00 2001 From: Antonella Ritorto Date: Thu, 26 Oct 2023 14:01:15 +0200 Subject: [PATCH] Hide Field Properties lookup --- ebos/eclgenericproblem_impl.hh | 56 ++++++++++++------------ ebos/eclgenericthresholdpressure_impl.hh | 12 ++--- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/ebos/eclgenericproblem_impl.hh b/ebos/eclgenericproblem_impl.hh index 5e6b54fb5..4ee8b6ad6 100644 --- a/ebos/eclgenericproblem_impl.hh +++ b/ebos/eclgenericproblem_impl.hh @@ -166,31 +166,33 @@ readRockParameters_(const std::vector& cellCenterDepths, unsigned numElem = gridView_.size(0); if (eclState_.fieldProps().has_int(rock_config.rocknum_property())) { - rockTableIdx_.resize(numElem); - const auto& num = eclState_.fieldProps().get_int(rock_config.rocknum_property()); - for (std::size_t elemIdx = 0; elemIdx < numElem; ++ elemIdx) { - auto coarseElemIdx = this->getLookUpData(elemIdx); - rockTableIdx_[elemIdx] = num[coarseElemIdx] - 1; - auto fmtError = - [&num,coarseElemIdx,&ijkIndex,&rock_config](const char* type, std::size_t size) - { - return fmt::format("{} table index {} for elem {} read from {}" - " is is out of bounds for number of tables {}", - type, num[coarseElemIdx], - ijkIndex(coarseElemIdx), - rock_config.rocknum_property(), size); - }; + // Auxiliary function to check rockTableIdx_ values belong to the right range. Otherwise, throws. + std::function valueCheck = [&ijkIndex,&rock_config,this](int fieldPropValue, int coarseElemIdx) + { + auto fmtError = [fieldPropValue, coarseElemIdx,&ijkIndex,&rock_config](const char* type, std::size_t size) + { + return fmt::format("{} table index {} for elem {} read from {}" + " is out of bounds for number of tables {}", + type, fieldPropValue, + ijkIndex(coarseElemIdx), + rock_config.rocknum_property(), size); + }; if (!rockCompPoroMult_.empty() && - rockTableIdx_[elemIdx] >= rockCompPoroMult_.size()) { + fieldPropValue > static_cast(rockCompPoroMult_.size())) { throw std::runtime_error(fmtError("Rock compaction", rockCompPoroMult_.size())); } if (!rockCompPoroMultWc_.empty() && - rockTableIdx_[elemIdx] >= rockCompPoroMultWc_.size()) { + fieldPropValue > static_cast(rockCompPoroMultWc_.size())) { throw std::runtime_error(fmtError("Rock water compaction", rockCompPoroMultWc_.size())); } - } + }; + + rockTableIdx_ = this->lookUpData_.template assignFieldPropsIntOnLeaf(eclState_.fieldProps(), + rock_config.rocknum_property(), + numElem, true /*needsTranslation*/, + valueCheck); } // Store overburden pressure pr element @@ -367,19 +369,19 @@ updateNum(const std::string& name, std::vector& numbers, std::size_t num_regi if (!eclState_.fieldProps().has_int(name)) return; - const auto& numData = eclState_.fieldProps().get_int(name); - unsigned numElems = gridView_.size(/*codim=*/0); - numbers.resize(numElems); - for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx) { - if (numData[this->getLookUpData(elemIdx)] > (int)num_regions) { - throw std::runtime_error("Values larger than maximum number of regions " + std::to_string(num_regions) + " provided in " + name); - } else if (numData[this->getLookUpData(elemIdx)] > 0) { - numbers[elemIdx] = static_cast(numData[this->getLookUpData(elemIdx)]) - 1; - } else { + std::function valueCheck = [num_regions,name](T fieldPropValue, [[maybe_unused]] int fieldPropIdx) { + if ( fieldPropValue > (int)num_regions) { + throw std::runtime_error("Values larger than maximum number of regions " + + std::to_string(num_regions) + " provided in " + name); + } + if ( fieldPropValue <= 0) { throw std::runtime_error("zero or negative values provided for region array: " + name); } - } + }; + + numbers = this->lookUpData_.template assignFieldPropsIntOnLeaf(eclState_.fieldProps(), name, numElems, + true /*needsTranslation*/, valueCheck); } template diff --git a/ebos/eclgenericthresholdpressure_impl.hh b/ebos/eclgenericthresholdpressure_impl.hh index 33d5d6d6f..f1a24b7a7 100644 --- a/ebos/eclgenericthresholdpressure_impl.hh +++ b/ebos/eclgenericthresholdpressure_impl.hh @@ -132,12 +132,8 @@ finishInit() } // internalize the data specified using the EQLNUM keyword - const auto& fp = eclState_.fieldProps(); - const auto& equilRegionData = fp.get_int("EQLNUM"); - elemEquilRegion_.resize(numElements, 0); - for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) { - elemEquilRegion_[elemIdx] = equilRegionData[elemIdx] - 1; - } + elemEquilRegion_ = lookUpData_.template assignFieldPropsIntOnLeaf(eclState_.fieldProps(), + "EQLNUM", numElements, true); /* If this is a restart run the ThresholdPressure object will be active, @@ -171,8 +167,8 @@ applyExplicitThresholdPressures_() const auto& inside = intersection.inside(); const auto& outside = intersection.outside(); - auto equilRegionInside = lookUpData_(inside, elemEquilRegion_); - auto equilRegionOutside = lookUpData_(outside, elemEquilRegion_); + auto equilRegionInside = elemEquilRegion_[elementMapper_.index(inside)]; + auto equilRegionOutside = elemEquilRegion_[elementMapper_.index(outside)]; if (thpres.hasRegionBarrier(equilRegionInside + 1, equilRegionOutside + 1)) { Scalar pth = 0.0;