mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Add guard against invalid satnum, pvtnum, imbnum, eqlnum
This commit is contained in:
parent
a363ad6028
commit
40bd07a3b5
@ -364,7 +364,7 @@ rockFraction(unsigned elementIdx, unsigned timeIdx) const
|
|||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
template<class T>
|
template<class T>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updateNum(const std::string& name, std::vector<T>& numbers)
|
updateNum(const std::string& name, std::vector<T>& numbers, size_t num_regions)
|
||||||
{
|
{
|
||||||
if (!eclState_.fieldProps().has_int(name))
|
if (!eclState_.fieldProps().has_int(name))
|
||||||
return;
|
return;
|
||||||
@ -374,7 +374,13 @@ updateNum(const std::string& name, std::vector<T>& numbers)
|
|||||||
unsigned numElems = gridView_.size(/*codim=*/0);
|
unsigned numElems = gridView_.size(/*codim=*/0);
|
||||||
numbers.resize(numElems);
|
numbers.resize(numElems);
|
||||||
for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx) {
|
for (unsigned elemIdx = 0; elemIdx < numElems; ++elemIdx) {
|
||||||
numbers[elemIdx] = static_cast<T>(numData[elemIdx]) - 1;
|
if (numData[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[elemIdx] > 0) {
|
||||||
|
numbers[elemIdx] = static_cast<T>(numData[elemIdx]) - 1;
|
||||||
|
} else {
|
||||||
|
throw std::runtime_error("zero or negative values provided for region array: " + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -382,46 +388,52 @@ template<class GridView, class FluidSystem, class Scalar>
|
|||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updatePvtnum_()
|
updatePvtnum_()
|
||||||
{
|
{
|
||||||
updateNum("PVTNUM", pvtnum_);
|
const auto num_regions = eclState_.getTableManager().getTabdims().getNumPVTTables();
|
||||||
|
updateNum("PVTNUM", pvtnum_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updateSatnum_()
|
updateSatnum_()
|
||||||
{
|
{
|
||||||
updateNum("SATNUM", satnum_);
|
const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
|
||||||
|
updateNum("SATNUM", satnum_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updateMiscnum_()
|
updateMiscnum_()
|
||||||
{
|
{
|
||||||
updateNum("MISCNUM", miscnum_);
|
const auto num_regions = 1; // we only support single region
|
||||||
|
updateNum("MISCNUM", miscnum_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updatePlmixnum_()
|
updatePlmixnum_()
|
||||||
{
|
{
|
||||||
updateNum("PLMIXNUM", plmixnum_);
|
const auto num_regions = 1; // we only support single region
|
||||||
|
updateNum("PLMIXNUM", plmixnum_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updateKrnum_()
|
updateKrnum_()
|
||||||
{
|
{
|
||||||
updateNum("KRNUMX", krnumx_);
|
const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
|
||||||
updateNum("KRNUMY", krnumy_);
|
updateNum("KRNUMX", krnumx_, num_regions);
|
||||||
updateNum("KRNUMZ", krnumz_);
|
updateNum("KRNUMY", krnumy_, num_regions);
|
||||||
|
updateNum("KRNUMZ", krnumz_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
void EclGenericProblem<GridView,FluidSystem,Scalar>::
|
||||||
updateImbnum_()
|
updateImbnum_()
|
||||||
{
|
{
|
||||||
updateNum("IMBNUMX", imbnumx_);
|
const auto num_regions = eclState_.getTableManager().getTabdims().getNumSatTables();
|
||||||
updateNum("IMBNUMY", imbnumy_);
|
updateNum("IMBNUMX", imbnumx_, num_regions);
|
||||||
updateNum("IMBNUMZ", imbnumz_);
|
updateNum("IMBNUMY", imbnumy_, num_regions);
|
||||||
|
updateNum("IMBNUMZ", imbnumz_, num_regions);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class GridView, class FluidSystem, class Scalar>
|
template<class GridView, class FluidSystem, class Scalar>
|
||||||
|
@ -407,7 +407,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
template<class T>
|
template<class T>
|
||||||
void updateNum(const std::string& name, std::vector<T>& numbers);
|
void updateNum(const std::string& name, std::vector<T>& numbers, size_t num_regions);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Opm
|
} // namespace Opm
|
||||||
|
@ -2334,6 +2334,7 @@ protected:
|
|||||||
const auto& eclState = vanguard.eclState();
|
const auto& eclState = vanguard.eclState();
|
||||||
|
|
||||||
// the PVT and saturation region numbers
|
// the PVT and saturation region numbers
|
||||||
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
||||||
this->updatePvtnum_();
|
this->updatePvtnum_();
|
||||||
this->updateSatnum_();
|
this->updateSatnum_();
|
||||||
|
|
||||||
@ -2344,6 +2345,7 @@ protected:
|
|||||||
|
|
||||||
// directional relative permeabilities
|
// directional relative permeabilities
|
||||||
this->updateKrnum_();
|
this->updateKrnum_();
|
||||||
|
OPM_END_PARALLEL_TRY_CATCH("Invalid region numbers: ", vanguard.gridView().comm());
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// porosity
|
// porosity
|
||||||
updateReferencePorosity_();
|
updateReferencePorosity_();
|
||||||
|
@ -44,6 +44,7 @@
|
|||||||
#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
|
#include <opm/material/fluidmatrixinteractions/EclMaterialLawManager.hpp>
|
||||||
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
|
#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>
|
||||||
|
|
||||||
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
||||||
#include <dune/grid/common/mcmgmapper.hh>
|
#include <dune/grid/common/mcmgmapper.hh>
|
||||||
|
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
@ -1278,6 +1279,15 @@ equilnum(const EclipseState& eclipseState,
|
|||||||
const auto& e = eclipseState.fieldProps().get_int("EQLNUM");
|
const auto& e = eclipseState.fieldProps().get_int("EQLNUM");
|
||||||
std::transform(e.begin(), e.end(), eqlnum.begin(), [](int n){ return n - 1;});
|
std::transform(e.begin(), e.end(), eqlnum.begin(), [](int n){ return n - 1;});
|
||||||
}
|
}
|
||||||
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
||||||
|
const int num_regions = eclipseState.getTableManager().getEqldims().getNumEquilRegions();
|
||||||
|
if ( std::any_of(eqlnum.begin(), eqlnum.end(), [num_regions](int n){return n >= num_regions;}) ) {
|
||||||
|
throw std::runtime_error("Values larger than maximum Equil regions " + std::to_string(num_regions) + " provided in EQLNUM");
|
||||||
|
}
|
||||||
|
if ( std::any_of(eqlnum.begin(), eqlnum.end(), [](int n){return n < 0;}) ) {
|
||||||
|
throw std::runtime_error("zero or negative values provided in EQLNUM");
|
||||||
|
}
|
||||||
|
OPM_END_PARALLEL_TRY_CATCH("Invalied EQLNUM numbers: ", gridview.comm());
|
||||||
|
|
||||||
return eqlnum;
|
return eqlnum;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user