Only output interior cells

This commit is contained in:
Tor Harald Sandve 2023-12-06 10:33:46 +01:00
parent 78e8ceccba
commit 6eeb5b4187
4 changed files with 33 additions and 21 deletions

View File

@ -31,6 +31,8 @@
#include <dune/common/version.hh> #include <dune/common/version.hh>
#include <dune/grid/common/gridenums.hh> #include <dune/grid/common/gridenums.hh>
#include <dune/grid/common/mcmgmapper.hh> #include <dune/grid/common/mcmgmapper.hh>
#include <dune/grid/common/partitionset.hh>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>
@ -865,7 +867,7 @@ CollectDataToIORank(const Grid& grid, const EquilGrid* equilGrid,
ElementMapper elemMapper(localGridView, Dune::mcmgElementLayout()); ElementMapper elemMapper(localGridView, Dune::mcmgElementLayout());
sortedCartesianIdx_.reserve(localGridView.size(0)); sortedCartesianIdx_.reserve(localGridView.size(0));
for (const auto& elem : elements(localGridView)) for (const auto& elem : elements(localGridView, Dune::Partitions::interior))
{ {
auto idx = elemMapper.index(elem); auto idx = elemMapper.index(elem);
sortedCartesianIdx_.push_back(cartMapper.cartesianIndex(idx)); sortedCartesianIdx_.push_back(cartMapper.cartesianIndex(idx));
@ -934,12 +936,12 @@ CollectDataToIORank(const Grid& grid, const EquilGrid* equilGrid,
distributedCartesianIndex.resize(gridSize, -1); distributedCartesianIndex.resize(gridSize, -1);
// A mapping for the whole grid (including the ghosts) is needed for restarts // A mapping for the whole grid (including the ghosts) is needed for restarts
for (const auto& elem : elements(localGridView)) { for (const auto& elem : elements(localGridView, Dune::Partitions::interior)) {
int elemIdx = elemMapper.index(elem); int elemIdx = elemMapper.index(elem);
distributedCartesianIndex[elemIdx] = cartMapper.cartesianIndex(elemIdx); distributedCartesianIndex[elemIdx] = cartMapper.cartesianIndex(elemIdx);
// only store interior element for collection // only store interior element for collection
//assert(element.partitionType() == Dune::InteriorEntity); assert(elem.partitionType() == Dune::InteriorEntity);
localIndexMap_.push_back(elemIdx); localIndexMap_.push_back(elemIdx);
} }

View File

@ -516,17 +516,18 @@ private:
} }
const auto& gridView = simulator_.vanguard().gridView(); const auto& gridView = simulator_.vanguard().gridView();
const int numElements = gridView.size(/*codim=*/0); const int num_interior = Opm::detail::
countLocalInteriorCellsGridView(gridView);
const bool log = this->collectToIORank_.isIORank(); const bool log = this->collectToIORank_.isIORank();
damarisOutputModule_->allocBuffers(numElements, reportStepNum, damarisOutputModule_->allocBuffers(num_interior, reportStepNum,
isSubStep, log, /*isRestart*/ false); isSubStep, log, /*isRestart*/ false);
ElementContext elemCtx(simulator_); ElementContext elemCtx(simulator_);
OPM_BEGIN_PARALLEL_TRY_CATCH(); OPM_BEGIN_PARALLEL_TRY_CATCH();
{ {
OPM_TIMEBLOCK(prepareCellBasedData); OPM_TIMEBLOCK(prepareCellBasedData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
@ -535,7 +536,7 @@ private:
} }
if(!simulator_.model().linearizer().getFlowsInfo().empty()){ if(!simulator_.model().linearizer().getFlowsInfo().empty()){
OPM_TIMEBLOCK(prepareFlowsData); OPM_TIMEBLOCK(prepareFlowsData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
damarisOutputModule_->processElementFlows(elemCtx); damarisOutputModule_->processElementFlows(elemCtx);
@ -543,7 +544,7 @@ private:
} }
{ {
OPM_TIMEBLOCK(prepareBlockData); OPM_TIMEBLOCK(prepareBlockData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
damarisOutputModule_->processElementBlockData(elemCtx); damarisOutputModule_->processElementBlockData(elemCtx);
@ -554,7 +555,7 @@ private:
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (int dofIdx=0; dofIdx < numElements; ++dofIdx){ for (int dofIdx=0; dofIdx < num_interior; ++dofIdx){
const auto& intQuants = *(simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0)); const auto& intQuants = *(simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0));
const auto totVolume = simulator_.model().dofTotalVolume(dofIdx); const auto totVolume = simulator_.model().dofTotalVolume(dofIdx);
damarisOutputModule_->updateFluidInPlace(dofIdx, intQuants, totVolume); damarisOutputModule_->updateFluidInPlace(dofIdx, intQuants, totVolume);

View File

@ -707,8 +707,13 @@ regionSum(const ScalarBuffer& property,
if (property.empty()) if (property.empty())
return totals; return totals;
assert(regionId.size() == property.size()); // the regionId contains the ghost cells
for (std::size_t j = 0; j < regionId.size(); ++j) { // the property does not contain the ghostcells
// This code assumes that that the ghostcells are
// added after the interior cells
// Is this a valid assumption?
assert(regionId.size() >= property.size());
for (std::size_t j = 0; j < property.size(); ++j) {
const int regionIdx = regionId[j] - 1; const int regionIdx = regionId[j] - 1;
// the cell is not attributed to any region. ignore it! // the cell is not attributed to any region. ignore it!
if (regionIdx < 0) if (regionIdx < 0)

View File

@ -41,6 +41,8 @@
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp> #include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
#include <opm/simulators/utils/ParallelRestart.hpp> #include <opm/simulators/utils/ParallelRestart.hpp>
#include <opm/simulators/flow/countGlobalCells.hpp>
#include <opm/common/OpmLog/OpmLog.hpp> #include <opm/common/OpmLog/OpmLog.hpp>
@ -329,15 +331,16 @@ public:
} }
const auto& gridView = simulator_.vanguard().gridView(); const auto& gridView = simulator_.vanguard().gridView();
const int numElements = gridView.size(/*codim=*/0); const int num_interior = Opm::detail::
countLocalInteriorCellsGridView(gridView);
this->eclOutputModule_-> this->eclOutputModule_->
allocBuffers(numElements, 0, false, false, /*isRestart*/ false); allocBuffers(num_interior, 0, false, false, /*isRestart*/ false);
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (int dofIdx = 0; dofIdx < numElements; ++dofIdx) { for (int dofIdx = 0; dofIdx < num_interior; ++dofIdx) {
const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0); const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0);
const auto totVolume = simulator_.model().dofTotalVolume(dofIdx); const auto totVolume = simulator_.model().dofTotalVolume(dofIdx);
@ -557,11 +560,12 @@ private:
} }
const auto& gridView = simulator_.vanguard().gridView(); const auto& gridView = simulator_.vanguard().gridView();
const int numElements = gridView.size(/*codim=*/0);
const bool log = this->collectToIORank_.isIORank(); const bool log = this->collectToIORank_.isIORank();
const int num_interior = Opm::detail::
countLocalInteriorCellsGridView(gridView);
this->eclOutputModule_-> this->eclOutputModule_->
allocBuffers(numElements, reportStepNum, allocBuffers(num_interior, reportStepNum,
isSubStep, log, /*isRestart*/ false); isSubStep, log, /*isRestart*/ false);
ElementContext elemCtx(simulator_); ElementContext elemCtx(simulator_);
@ -570,7 +574,7 @@ private:
{ {
OPM_TIMEBLOCK(prepareCellBasedData); OPM_TIMEBLOCK(prepareCellBasedData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
@ -581,7 +585,7 @@ private:
if constexpr (enableMech) { if constexpr (enableMech) {
if (simulator_.vanguard().eclState().runspec().mech()) { if (simulator_.vanguard().eclState().runspec().mech()) {
OPM_TIMEBLOCK(prepareMechData); OPM_TIMEBLOCK(prepareMechData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
eclOutputModule_->processElementMech(elemCtx); eclOutputModule_->processElementMech(elemCtx);
@ -591,7 +595,7 @@ private:
if (! this->simulator_.model().linearizer().getFlowsInfo().empty()) { if (! this->simulator_.model().linearizer().getFlowsInfo().empty()) {
OPM_TIMEBLOCK(prepareFlowsData); OPM_TIMEBLOCK(prepareFlowsData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
@ -601,7 +605,7 @@ private:
{ {
OPM_TIMEBLOCK(prepareBlockData); OPM_TIMEBLOCK(prepareBlockData);
for (const auto& elem : elements(gridView)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
elemCtx.updatePrimaryStencil(elem); elemCtx.updatePrimaryStencil(elem);
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0); elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
@ -615,7 +619,7 @@ private:
#ifdef _OPENMP #ifdef _OPENMP
#pragma omp parallel for #pragma omp parallel for
#endif #endif
for (int dofIdx = 0; dofIdx < numElements; ++dofIdx) { for (int dofIdx = 0; dofIdx < num_interior; ++dofIdx) {
const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0); const auto& intQuants = *simulator_.model().cachedIntensiveQuantities(dofIdx, /*timeIdx=*/0);
const auto totVolume = simulator_.model().dofTotalVolume(dofIdx); const auto totVolume = simulator_.model().dofTotalVolume(dofIdx);