fix regression: unconditional dereferences

equilGrid and equilCartesianMapper can only
be dereferenced on rank 0.
This commit is contained in:
Arne Morten Kvarving 2021-05-11 14:48:50 +02:00
parent dc8bbc9e5a
commit c7c29483e7
4 changed files with 15 additions and 13 deletions

View File

@ -667,10 +667,10 @@ private:
template <class Grid, class EquilGrid, class GridView>
CollectDataToIORank<Grid,EquilGrid,GridView>::
CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid,
CollectDataToIORank(const Grid& grid, const EquilGrid* equilGrid,
const GridView& localGridView,
const Dune::CartesianIndexMapper<Grid>& cartMapper,
const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapper)
const Dune::CartesianIndexMapper<EquilGrid>* equilCartMapper)
: toIORankComm_()
{
// index maps only have to be build when reordering is needed
@ -701,9 +701,9 @@ CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid,
// We need a mapping from local to global grid, here we
// use equilGrid which represents a view on the global grid
// reserve memory
const size_t globalSize = equilGrid.leafGridView().size(0);
const size_t globalSize = equilGrid->leafGridView().size(0);
globalCartesianIndex_.resize(globalSize, -1);
const EquilGridView equilGridView = equilGrid.leafGridView();
const EquilGridView equilGridView = equilGrid->leafGridView();
using EquilElementMapper = Dune::MultipleCodimMultipleGeomTypeMapper<EquilGridView>;
EquilElementMapper equilElemMapper(equilGridView, Dune::mcmgElementLayout());
@ -713,11 +713,11 @@ CollectDataToIORank(const Grid& grid, const EquilGrid& equilGrid,
grid.scatterData(handle);
// loop over all elements (global grid) and store Cartesian index
auto elemIt = equilGrid.leafGridView().template begin<0>();
const auto& elemEndIt = equilGrid.leafGridView().template end<0>();
auto elemIt = equilGrid->leafGridView().template begin<0>();
const auto& elemEndIt = equilGrid->leafGridView().template end<0>();
for (; elemIt != elemEndIt; ++elemIt) {
int elemIdx = equilElemMapper.index(*elemIt);
int cartElemIdx = equilCartMapper.cartesianIndex(elemIdx);
int cartElemIdx = equilCartMapper->cartesianIndex(elemIdx);
globalCartesianIndex_[elemIdx] = cartElemIdx;
}

View File

@ -58,10 +58,10 @@ public:
!std::is_same<Grid, EquilGrid>::value;
CollectDataToIORank(const Grid& grid,
const EquilGrid& equilGrid,
const EquilGrid* equilGrid,
const GridView& gridView,
const Dune::CartesianIndexMapper<Grid>& cartMapper,
const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapper);
const Dune::CartesianIndexMapper<EquilGrid>* equilCartMapper);
// gather solution to rank 0 for EclipseWriter
void collect(const Opm::data::Solution& localCellData,

View File

@ -191,10 +191,12 @@ public:
EclWriter(Simulator& simulator)
: simulator_(simulator)
, collectToIORank_(simulator_.vanguard().grid(),
simulator_.vanguard().equilGrid(),
simulator_.vanguard().grid().comm().rank() == 0 ?
&simulator_.vanguard().equilGrid() : nullptr,
simulator_.vanguard().gridView(),
simulator_.vanguard().cartesianIndexMapper(),
simulator_.vanguard().equilCartesianIndexMapper())
simulator_.vanguard().grid().comm().rank() == 0 ?
&simulator_.vanguard().equilCartesianIndexMapper() : nullptr)
{
std::vector<std::size_t> wbp_index_list;

View File

@ -151,10 +151,10 @@ BOOST_AUTO_TEST_CASE(Summary)
using GridView = Opm::GetPropType<TypeTag, Opm::Properties::GridView>;
using CollectDataToIORankType = Opm::CollectDataToIORank<Grid,EquilGrid,GridView>;
CollectDataToIORankType collectToIORank(simulator->vanguard().grid(),
simulator->vanguard().equilGrid(),
&simulator->vanguard().equilGrid(),
simulator->vanguard().gridView(),
simulator->vanguard().cartesianIndexMapper(),
simulator->vanguard().equilCartesianIndexMapper());
&simulator->vanguard().equilCartesianIndexMapper());
Opm::EclOutputBlackOilModule<TypeTag> eclOutputModule(*simulator, {}, collectToIORank);
typedef Opm::EclWriter<TypeTag> EclWriterType;