Merge pull request #2446 from blattms/use-compressed-in-initstateequil.hh

Autocreate parallel fieldprops and use compressed ones in initstateequil.hh
This commit is contained in:
Arne Morten Kvarving
2020-03-11 08:14:21 +01:00
committed by GitHub
4 changed files with 134 additions and 38 deletions

View File

@@ -40,6 +40,8 @@
#include <dune/common/version.hh>
#include <sstream>
namespace Opm {
template <class TypeTag>
class EclCpGridVanguard;
@@ -189,17 +191,29 @@ public:
//distribute the grid and switch to the distributed view.
{
const auto wells = this->schedule().getWellsatEnd();
auto& eclState = static_cast<ParallelEclipseState&>(this->eclState());
const EclipseGrid* eclGrid = nullptr;
if (grid_->comm().rank() == 0)
try
{
eclGrid = &this->eclState().getInputGrid();
}
auto& eclState = dynamic_cast<ParallelEclipseState&>(this->eclState());
const EclipseGrid* eclGrid = nullptr;
PropsCentroidsDataHandle<Dune::CpGrid> handle(*grid_, eclState, eclGrid, this->centroids_,
cartesianIndexMapper());
defunctWellNames_ = std::get<1>(grid_->loadBalance(handle, edgeWeightsMethod, &wells, faceTrans.data()));
if (grid_->comm().rank() == 0)
{
eclGrid = &this->eclState().getInputGrid();
}
PropsCentroidsDataHandle<Dune::CpGrid> handle(*grid_, eclState, eclGrid, this->centroids_,
cartesianIndexMapper());
defunctWellNames_ = std::get<1>(grid_->loadBalance(handle, edgeWeightsMethod, &wells, faceTrans.data()));
}
catch(const std::bad_cast& e)
{
std::ostringstream message;
message << "Parallel simulator setup is incorrect as it does not use ParallelEclipseState ("
<< e.what() <<")"<<std::flush;
OpmLog::error(message.str());
std::rethrow_exception(std::current_exception());
}
}
grid_->switchToDistributedView();
@@ -221,7 +235,21 @@ public:
this->updateGridView_();
#if HAVE_MPI
if (mpiSize > 1) {
static_cast<ParallelEclipseState&>(this->eclState()).switchToDistributedProps();
try
{
auto& parallelEclState = dynamic_cast<ParallelEclipseState&>(this->eclState());
// reset cartesian index mapper for auto creation of field properties
parallelEclState.resetCartesianMapper(cartesianIndexMapper_.get());
parallelEclState.switchToDistributedProps();
}
catch(const std::bad_cast& e)
{
std::ostringstream message;
message << "Parallel simulator setup is incorrect as it does not use ParallelEclipseState ("
<< e.what() <<")"<<std::flush;
OpmLog::error(message.str());
std::rethrow_exception(std::current_exception());
}
}
#endif
}

View File

@@ -906,12 +906,8 @@ equilnum(const Opm::EclipseState& eclipseState,
const int nc = grid.size(/*codim=*/0);
eqlnum.resize(nc);
const auto& e = eclipseState.fieldProps().get_global_int("EQLNUM");
const int* gc = Opm::UgGridHelpers::globalCell(grid);
for (int cell = 0; cell < nc; ++cell) {
const int deckPos = (gc == NULL) ? cell : gc[cell];
eqlnum[cell] = e[deckPos] - 1;
}
const auto& e = eclipseState.fieldProps().get_int("EQLNUM");
std::transform(e.begin(), e.end(), eqlnum.begin(), [](int n){ return n - 1;});
}
return eqlnum;
}
@@ -940,16 +936,8 @@ public:
{
//Check for presence of kw SWATINIT
if (applySwatInit) {
const int nc = grid.size(/*codim=*/0);
if (eclipseState.fieldProps().has_double("SWATINIT")) {
const std::vector<double>& swatInitEcl = eclipseState.fieldProps().get_global_double("SWATINIT");
const int* gc = Opm::UgGridHelpers::globalCell(grid);
swatInit_.resize(nc);
for (int c = 0; c < nc; ++c) {
const int deckPos = (gc == NULL) ? c : gc[c];
swatInit_[c] = swatInitEcl[deckPos];
}
swatInit_ = eclipseState.fieldProps().get_double("SWATINIT");
}
}
@@ -1101,25 +1089,20 @@ private:
void setRegionPvtIdx(const Grid& grid, const Opm::EclipseState& eclState, const RMap& reg)
{
size_t numCompressed = grid.size(/*codim=*/0);
const auto* globalCell = Opm::UgGridHelpers::globalCell(grid);
std::vector<int> cellPvtRegionIdx(numCompressed);
//Get the PVTNUM data
const auto pvtnumData = eclState.fieldProps().get_global_int("PVTNUM");
// Convert PVTNUM data into an array of indices for compressed cells. Remember
const auto& pvtnumData = eclState.fieldProps().get_int("PVTNUM");
// Save pvt indices of regions. Remember
// that Eclipse uses Fortran-style indices which start at 1 instead of 0, so we
// need to subtract 1.
for (size_t cellIdx = 0; cellIdx < numCompressed; ++ cellIdx) {
size_t cartesianCellIdx = globalCell[cellIdx];
assert(cartesianCellIdx < pvtnumData.size());
size_t pvtRegionIdx = pvtnumData[cartesianCellIdx] - 1;
cellPvtRegionIdx[cellIdx] = pvtRegionIdx;
}
std::transform(pvtnumData.begin(), pvtnumData.end(),
cellPvtRegionIdx.begin(), [](int n){ return n - 1;});
for (const auto& r : reg.activeRegions()) {
const auto& cells = reg.cells(r);
const int cell = *(cells.begin());
regionPvtIdx_[r] = cellPvtRegionIdx[cell];
regionPvtIdx_[r] = pvtnumData[cell] - 1;
}
}