Skip to content

Commit d246b98

Browse files
authored
Merge pull request #6330 from aritorto/useLevelCartIdxMapp
(Partial) Support for parallel runs with CpGrid with LGRs
2 parents c51f507 + a77baf0 commit d246b98

7 files changed

Lines changed: 47 additions & 14 deletions

compareECLFiles.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ add_test_runSimulator(CASENAME spe1case1_carfin
408408
DIR lgr
409409
TEST_ARGS --parsing-strictness=low --enable-ecl-output=false --enable-vtk-output=true)
410410

411+
add_test_runSimulator(CASENAME spe1case1_carfin_parallel
412+
FILENAME SPE1CASE1_CARFIN
413+
SIMULATOR flow
414+
DIR lgr
415+
PROCS 4
416+
TEST_ARGS --parsing-strictness=low --enable-ecl-output=false --enable-vtk-output=true)
417+
411418
# Tests that are run based on simulator results, but not necessarily direct comparison to reference results
412419
add_test_runSimulator(CASENAME tuning_xxxmbe
413420
FILENAME 01_TUNING_XXXMBE

opm/simulators/flow/CollectDataOnIORank_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ CollectDataOnIORank(const Grid& grid, const EquilGrid* equilGrid,
851851
: toIORankComm_(grid.comm())
852852
, globalInterRegFlows_(InterRegFlowMap::createMapFromNames(toVector(fipRegionsInterregFlow)))
853853
{
854-
// index maps only have to be build when reordering is needed
855-
if (!needsReordering && !isParallel())
854+
// Build index maps only when reordering is needed; skip in parallel runs for CpGrid with LGRs
855+
if ((!needsReordering && !isParallel()) || (isParallel() && (grid.maxLevel()>0)))
856856
return;
857857

858858
const CollectiveCommunication& comm = grid.comm();

opm/simulators/flow/CpGridVanguard.hpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,26 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag>
263263
*/
264264
void addLgrs()
265265
{
266-
// Check if input file contains Lgrs.
267-
//
268-
// If there are lgrs, create the grid with them, and update the leaf grid view.
269-
if (const auto& lgrs = this->eclState().getLgrs(); (lgrs.size() > 0) && (this->grid_->comm().size() == 1)) {
266+
// Check if input file contains Lgrs. Add them, if any.
267+
// In a parallel run, this adds the LGRs on the distributed simulation grid.
268+
if (const auto& lgrs = this->eclState().getLgrs(); lgrs.size() > 0) {
270269
OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view");
271270
this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_);
272271

273272
this->updateGridView_();
274273
this->updateCellDepths_();
275274
this->updateCellThickness_();
276-
}
277-
else if (this->grid_->comm().size() > 1) {
278-
OpmLog::warning("Adding LGRs in parallel run is not supported yet.\n");
275+
276+
if (this->grid_->comm().size()>1) {
277+
// Add LGRs and update the leaf grid view in the global (undistributed) simulation grid.
278+
// Purpose: To enable synchronization of cell ids in 'serial mode',
279+
// we rely on the "parent-to-children" cell id mapping.
280+
OpmLog::info("\nAdding LGRs to the global view and updating its leaf grid view");
281+
this->grid_->switchToGlobalView();
282+
this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_);
283+
this->grid_->switchToDistributedView();
284+
this->grid_->syncDistributedGlobalCellIds();
285+
}
279286
}
280287
}
281288

opm/simulators/flow/GenericCpGridVanguard.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <opm/common/utility/ActiveGridCells.hpp>
3434

3535
#include <opm/grid/cpgrid/GridHelpers.hpp>
36+
#include <opm/grid/cpgrid/LevelCartesianIndexMapper.hpp>
3637

3738
#include <opm/input/eclipse/Schedule/Schedule.hpp>
3839
#include <opm/input/eclipse/Schedule/Well/Well.hpp>
@@ -306,7 +307,13 @@ distributeFieldProps_(EclipseState& eclState1)
306307
{
307308
// Reset Cartesian index mapper for automatic creation of field
308309
// properties
309-
parallelEclState->resetCartesianMapper(this->cartesianIndexMapper_.get());
310+
// Note: the previous cartesianIndexMapper_ has been replaces by levelCartesianIndexMapper_
311+
// to support also the case of a distributed level zero grid in a CpGrid with LGRs.
312+
// This change allows access to the Cartesian indices of the distributed level zero grid,
313+
// where the field properties are given - for now.
314+
// In case of supporting LGR field properties, this need to be adapted, to access instead
315+
// each local/level Cartesian index set.
316+
parallelEclState->resetCartesianMapper(this->levelCartesianIndexMapper_.get());
310317
parallelEclState->switchToDistributedProps();
311318
}
312319
else {
@@ -500,6 +507,7 @@ void GenericCpGridVanguard<ElementMapper,GridView,Scalar>::doCreateGrids_(Eclips
500507
}
501508

502509
cartesianIndexMapper_ = std::make_unique<CartesianIndexMapper>(*grid_);
510+
levelCartesianIndexMapper_ = std::make_unique<LevelCartesianIndexMapper>(*grid_);
503511

504512
#if HAVE_MPI
505513
if (this->grid_->comm().size() > 1) {
@@ -640,7 +648,7 @@ template<class ElementMapper, class GridView, class Scalar>
640648
const LevelCartesianIndexMapper<Dune::CpGrid>
641649
GenericCpGridVanguard<ElementMapper,GridView,Scalar>::levelCartesianIndexMapper() const
642650
{
643-
return LevelCartesianIndexMapper(*grid_);
651+
return *levelCartesianIndexMapper_;
644652
}
645653

646654
template<class ElementMapper, class GridView, class Scalar>

opm/simulators/flow/GenericCpGridVanguard.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class GenericCpGridVanguard {
233233
std::unique_ptr<Dune::CpGrid> equilGrid_;
234234
std::unique_ptr<CartesianIndexMapper> cartesianIndexMapper_;
235235
std::unique_ptr<CartesianIndexMapper> equilCartesianIndexMapper_;
236+
std::unique_ptr<LevelCartesianIndexMapper> levelCartesianIndexMapper_;
236237

237238
int mpiRank;
238239
std::vector<int> cell_part_{};

opm/simulators/flow/OutputBlackoilModule.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,11 @@ class OutputBlackOilModule : public GenericOutputBlackoilModule<GetPropType<Type
673673

674674
void createLocalRegion_(std::vector<int>& region)
675675
{
676+
// For CpGrid with LGRs, where level zero grid has been distributed,
677+
// resize region is needed, since in this case the total amount of
678+
// element - per process - in level zero grid and leaf grid do not
679+
// coincide, in general.
680+
region.resize(simulator_.gridView().size(0));
676681
std::size_t elemIdx = 0;
677682
for (const auto& elem : elements(simulator_.gridView())) {
678683
if (elem.partitionType() != Dune::InteriorEntity) {

opm/simulators/utils/ParallelEclipseState.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,14 @@ class ParallelFieldPropsManager : public FieldPropsManager {
102102
template<class T>
103103
void resetCartesianMapper(const T* mapper)
104104
{
105-
m_activeSize = std::bind(&T::compressedSize, mapper);
106-
m_local2Global = std::bind(&T::cartesianIndex, mapper,
107-
std::placeholders::_1);
105+
// Note: mapper would usually be a CartesianIndexMapper. However, to support also
106+
// the case of a distributed level zero grid in a CpGrid with LGRs, mapper will be
107+
// Opm::LevelCartesianIndexMapper. This change allows access to the Cartesian indices
108+
// of the distributed level zero grid, where the field properties are given - for now.
109+
// In case of supporting LGR field properties, this need to be adapted, to access instead
110+
// each local/level Cartesian index set.
111+
m_activeSize = [mapper]() { return mapper->compressedSize(/*level = */ 0); };
112+
m_local2Global = [mapper](int localIdx) { return mapper->cartesianIndex(localIdx, /* level = */ 0); };
108113
}
109114

110115
bool tran_active(const std::string& keyword) const override;

0 commit comments

Comments
 (0)