Skip to content

Commit

Permalink
Extract addLgrs and call it after initial conditions computation - at…
Browse files Browse the repository at this point in the history
…tempt
  • Loading branch information
aritorto committed Jan 28, 2025
1 parent 6bfb60d commit c959447
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 15 deletions.
7 changes: 7 additions & 0 deletions opm/models/discretization/ecfv/ecfvstencil.hh
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ public:
, elementMapper_(mapper)
{
// try to ensure that the mapper passed indeed maps elements
// gridView.grid().switchToGlobalView(); // I would like to switch here (only relevant for CpGrid with LGRs)
// What we actually want is data_[0]
// which can be done with:
// gridView.grid().switchToGlobalView();
// gridView.grid().currentData().front(); This works only for CpGrid ...
std::cout<< "gridView size: " << gridView.size(/*codim=*/0) << " vs elemMapper_ size: " <<
elementMapper_.size()<< std::endl;
assert(int(gridView.size(/*codim=*/0)) == int(elementMapper_.size()));
}

Expand Down
11 changes: 11 additions & 0 deletions opm/models/io/basevanguard.hh
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ public:
updateGridView_();
}

/*!
* \brief Add LGRs to the grid, if any. Only supported for CpGrid - for now.
*/
void addLgrs()
{
if(&asImp_() != this) {
asImp_().addLgrs();
//updateGridView_();
}
}

protected:
// this method should be called after the grid has been allocated
void finalizeInit_()
Expand Down
4 changes: 4 additions & 0 deletions opm/models/utils/simulator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public:
checkParallelException("Could not initialize the problem: ",
exceptionThrown, what);

// Only relevant for CpGrid
std::cout << "Adding LGRs, if any\n" << std::flush;
vanguard_->addLgrs();

setupTimer_.stop();

if (verbose_)
Expand Down
7 changes: 6 additions & 1 deletion opm/simulators/flow/AluGridVanguard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ class AluGridVanguard : public FlowBaseVanguard<TypeTag>
globalTrans_->update(false, TransmissibilityType::TransUpdateQuantities::Trans,
[&](unsigned int i) { return gridEquilIdxToGridIdx(i);});
}


}

void addLgrs()
{
// do nothing: AluGrid with LGRs not supported yet!
}

template<class DataHandle>
Expand Down
20 changes: 18 additions & 2 deletions opm/simulators/flow/CpGridVanguard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,25 @@ class CpGridVanguard : public FlowBaseVanguard<TypeTag>
#endif
}

/*!
* \brief Add LGRs in the simulation grid.
*/
void addLgrs()
{
// Check if input file contains Lgrs.
const auto& lgrs = this-> eclState().getLgrs();
const auto& lgrsSize = lgrs.size();
// If there are lgrs, create the grid with them, and update the leaf grid view.
if (lgrsSize)
{
OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view");
this->addLgrsUpdateLeafView(lgrs, lgrsSize, *(this->grid_));
}
}

unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
return elemIndex;
}
return elemIndex;
}

unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
return elemIndex;
Expand Down
14 changes: 2 additions & 12 deletions opm/simulators/flow/GenericCpGridVanguard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,6 @@ void GenericCpGridVanguard<ElementMapper,GridView,Scalar>::doCreateGrids_(Eclips

cartesianIndexMapper_ = std::make_unique<CartesianIndexMapper>(*grid_);

// --- Add LGRs and update Leaf Grid View ---
// Check if input file contains Lgrs.
const auto& lgrs = eclState.getLgrs();
const auto lgrsSize = lgrs.size();
// If there are lgrs, create the grid with them, and update the leaf grid view.
if (lgrsSize)
{
OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view");
this->addLgrsUpdateLeafView(lgrs, lgrsSize, *(this->grid_));
}

#if HAVE_MPI
{
const bool has_numerical_aquifer = eclState.aquifer().hasNumericalAquifer();
Expand Down Expand Up @@ -509,7 +498,7 @@ void GenericCpGridVanguard<ElementMapper,GridView,Scalar>::doCreateGrids_(Eclips
}
#endif

// --- Copy grid with LGRs to equilGrid_ ---
// --- Copy grid to equilGrid_ ---
// We use separate grid objects: one for the calculation of the initial
// condition via EQUIL and one for the actual simulation. The reason is
// that the EQUIL code is allergic to distributed grids and the
Expand Down Expand Up @@ -569,6 +558,7 @@ void GenericCpGridVanguard<ElementMapper,GridView,Scalar>::addLgrsUpdateLeafView
grid.addLgrsUpdateLeafView(cells_per_dim_vec, startIJK_vec, endIJK_vec, lgrName_vec);
};


template<class ElementMapper, class GridView, class Scalar>
void GenericCpGridVanguard<ElementMapper,GridView,Scalar>::
doFilterConnections_(Schedule& schedule)
Expand Down
4 changes: 4 additions & 0 deletions opm/simulators/flow/PolyhedralGridVanguard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ class PolyhedralGridVanguard : public FlowBaseVanguard<TypeTag>
{ /* do nothing: PolyhedralGrid is not parallel! */
}

void addLgrs()
{ /* do nothing: PolyhedralGrid with LGRs not supported yet! */
}

/*!
* \brief Returns the object which maps a global element index of the simulation grid
* to the corresponding element index of the logically Cartesian index.
Expand Down

0 comments on commit c959447

Please sign in to comment.