Merge pull request #4147 from akva2/tracer_begin_optimize

Optimize EclTracerModel::updateStorageCache
This commit is contained in:
Bård Skaflestad
2022-10-13 10:47:51 +02:00
committed by GitHub

View File

@@ -51,8 +51,6 @@ namespace Opm {
* \ingroup EclBlackOilSimulator * \ingroup EclBlackOilSimulator
* *
* \brief A class which handles tracers as specified in by ECL * \brief A class which handles tracers as specified in by ECL
*
* TODO: MPI parallelism.
*/ */
template <class TypeTag> template <class TypeTag>
class EclTracerModel : public EclGenericTracerModel<GetPropType<TypeTag, Properties::Grid>, class EclTracerModel : public EclGenericTracerModel<GetPropType<TypeTag, Properties::Grid>,
@@ -94,9 +92,10 @@ public:
simulator.model().dofMapper(), simulator.model().dofMapper(),
simulator.vanguard().cellCentroids()) simulator.vanguard().cellCentroids())
, simulator_(simulator) , simulator_(simulator)
, wat_(TracerBatch<TracerVector>(waterPhaseIdx)) , tbatch({waterPhaseIdx, oilPhaseIdx, gasPhaseIdx})
, oil_(TracerBatch<TracerVector>(oilPhaseIdx)) , wat_(tbatch[0])
, gas_(TracerBatch<TracerVector>(gasPhaseIdx)) , oil_(tbatch[1])
, gas_(tbatch[2])
{ } { }
@@ -162,9 +161,7 @@ public:
if (this->numTracers()==0) if (this->numTracers()==0)
return; return;
updateStorageCache(wat_); updateStorageCache();
updateStorageCache(oil_);
updateStorageCache(gas_);
} }
/*! /*!
@@ -385,24 +382,26 @@ protected:
Dune::ForwardCommunication); Dune::ForwardCommunication);
} }
template <class TrRe> void updateStorageCache()
void updateStorageCache(TrRe & tr)
{ {
if (tr.numTracer() == 0) for (auto& tr : tbatch) {
return; if (tr.numTracer() != 0)
tr.concentrationInitial_ = tr.concentration_;
tr.concentrationInitial_ = tr.concentration_; }
ElementContext elemCtx(simulator_); ElementContext elemCtx(simulator_);
auto elemIt = simulator_.gridView().template begin</*codim=*/0>(); for (const auto& elem : elements(simulator_.gridView())) {
auto elemEndIt = simulator_.gridView().template end</*codim=*/0>(); elemCtx.updatePrimaryStencil(elem);
for (; elemIt != elemEndIt; ++ elemIt) { elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
elemCtx.updateAll(*elemIt); int globalDofIdx = elemCtx.globalSpaceIndex(0, /*timeIdx=*/0);
int globalDofIdx = elemCtx.globalSpaceIndex(0, /*timIdx=*/0); for (auto& tr : tbatch) {
Scalar fVolume; if (tr.numTracer() == 0)
computeVolume_(fVolume, tr.phaseIdx_, elemCtx, 0, /*timIdx=*/0); continue;
for (int tIdx =0; tIdx < tr.numTracer(); ++tIdx) { Scalar fVolume;
tr.storageOfTimeIndex1_[tIdx][globalDofIdx] = fVolume*tr.concentrationInitial_[tIdx][globalDofIdx]; computeVolume_(fVolume, tr.phaseIdx_, elemCtx, 0, /*timeIdx=*/0);
for (int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
tr.storageOfTimeIndex1_[tIdx][globalDofIdx] = fVolume*tr.concentrationInitial_[tIdx][globalDofIdx];
}
} }
} }
} }
@@ -479,7 +478,7 @@ protected:
Simulator& simulator_; Simulator& simulator_;
// This struct collects tracers of the same type (i.e, transported in same phase). // This struct collects tracers of the same type (i.e, transported in same phase).
// The idea beeing that, under the assumption of linearity, tracers of same type can // The idea being that, under the assumption of linearity, tracers of same type can
// be solved in concert, having a common system matrix but separate right-hand-sides. // be solved in concert, having a common system matrix but separate right-hand-sides.
// Since oil or gas tracers appears in dual compositions when VAPOIL respectively DISGAS // Since oil or gas tracers appears in dual compositions when VAPOIL respectively DISGAS
@@ -510,9 +509,10 @@ protected:
} }
}; };
TracerBatch<TracerVector> wat_; std::array<TracerBatch<TracerVector>,3> tbatch;
TracerBatch<TracerVector> oil_; TracerBatch<TracerVector>& wat_;
TracerBatch<TracerVector> gas_; TracerBatch<TracerVector>& oil_;
TracerBatch<TracerVector>& gas_;
}; };
} // namespace Opm } // namespace Opm