28#ifndef OPM_TRACER_MODEL_HPP
29#define OPM_TRACER_MODEL_HPP
31#include <opm/common/OpmLog/OpmLog.hpp>
32#include <opm/common/TimingMacros.hpp>
34#include <opm/input/eclipse/EclipseState/Aquifer/AquiferConfig.hpp>
35#include <opm/input/eclipse/Schedule/BCState.hpp>
36#include <opm/input/eclipse/Schedule/Schedule.hpp>
37#include <opm/input/eclipse/Schedule/Well/Well.hpp>
38#include <opm/input/eclipse/Schedule/Well/WellConnections.hpp>
40#include <opm/grid/utility/ElementChunks.hpp>
60#include <unordered_map>
64#include <fmt/format.h>
68template<
class TypeTag,
class MyTypeTag>
82template <
class TypeTag>
84 GetPropType<TypeTag, Properties::GridView>,
85 GetPropType<TypeTag, Properties::DofMapper>,
86 GetPropType<TypeTag, Properties::Stencil>,
87 GetPropType<TypeTag, Properties::FluidSystem>,
88 GetPropType<TypeTag, Properties::Scalar>>
106 using TracerEvaluation = DenseAd::Evaluation<Scalar,1>;
112 enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
113 enum { numPhases = FluidSystem::numPhases };
114 enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
115 enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
116 enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
117 enum { enableDiffusion = getPropValue<TypeTag, Properties::EnableDiffusion>() };
118 enum { enableDispersion = getPropValue<TypeTag, Properties::EnableDispersion>() };
122 :
BaseType(simulator.vanguard().gridView(),
123 simulator.vanguard().eclState(),
124 simulator.vanguard().cartesianIndexMapper(),
125 simulator.model().dofMapper(),
126 simulator.vanguard().cellCentroids())
128 ,
dispersionActive_(simulator.vanguard().eclState().getSimulationConfig().rock_config().dispersion())
154 gasPhaseIdx, oilPhaseIdx, waterPhaseIdx);
156 const std::string solver = Parameters::Get<Parameters::TracerSolver>();
157 if (solver !=
"istl" && solver !=
"reorder") {
158 throw std::invalid_argument(
"Unknown tracer solver '" + solver +
159 "', use 'istl' or 'reorder'");
165 bool hasDispersion =
false;
166 if constexpr (enableDispersion) {
169 bool hasDiffusion =
false;
170 if constexpr (enableDiffusion) {
171 for (std::size_t tracerIdx = 0; tracerIdx < this->
tracerPhaseIdx_.size();
173 const auto& tracerConfig = this->
eclState_.tracer()[tracerIdx];
174 hasDiffusion = hasDiffusion || tracerConfig.free_diffusion_coefficient != 0.0 ||
176 tracerConfig.solution_diffusion_coefficient != 0.0);
179 if (hasDiffusion || hasDispersion) {
180 const std::string unsupported = hasDiffusion && hasDispersion
181 ?
"diffusion (TRDIF) and dispersion (DISPERC)"
182 : (hasDiffusion ?
"diffusion (TRDIF)" :
"dispersion (DISPERC)");
183 throw std::invalid_argument(
"The reorder tracer solver does not support " +
184 unsupported +
", use --tracer-solver=istl");
190 throw std::invalid_argument(
"The number of tracer reorder retry steps must not be "
202 for (std::size_t tracerIdx = 0; tracerIdx < this->
tracerPhaseIdx_.size(); ++tracerIdx) {
204 if (phaseIdx == FluidSystem::waterPhaseIdx) {
205 if (! FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)){
206 throw std::runtime_error(
"Water tracer specified for non-water fluid system: " +
207 this->
name(tracerIdx));
210 else if (phaseIdx == FluidSystem::oilPhaseIdx) {
211 if (! FluidSystem::phaseIsActive(FluidSystem::oilPhaseIdx)){
212 throw std::runtime_error(
"Oil tracer specified for non-oil fluid system: " +
213 this->
name(tracerIdx));
216 else if (phaseIdx == FluidSystem::gasPhaseIdx) {
217 if (! FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)){
218 throw std::runtime_error(
"Gas tracer specified for non-gas fluid system: " +
219 this->
name(tracerIdx));
225 const auto& tracerConfig = this->
eclState_.tracer()[tracerIdx];
226 const Scalar freeD = tracerConfig.free_diffusion_coefficient;
227 const Scalar solutionD =
hasSolutionPart_(phaseIdx) ? tracerConfig.solution_diffusion_coefficient
229 if (freeD != 0.0 || solutionD != 0.0) {
232 const std::string diffKeyword =
"TRDIF" + this->
name(tracerIdx);
233 if constexpr (!enableDiffusion) {
234 throw std::runtime_error(diffKeyword +
" is given for tracer " + this->
name(tracerIdx) +
235 ", but this simulator was built without diffusion");
237 if (!this->
eclState_.getSimulationConfig().isDiffusive()) {
238 throw std::runtime_error(diffKeyword +
" is given for tracer " + this->
name(tracerIdx) +
239 ", which requires the DIFFUSE keyword");
242 auto batch = std::ranges::find_if(this->
tbatch,
243 [phaseIdx, freeD, solutionD](
const auto& tr)
245 return tr.phaseIdx_ == phaseIdx &&
246 tr.freeDiffusionCoefficient_ == freeD &&
247 tr.solutionDiffusionCoefficient_ == solutionD;
249 if (batch == this->
tbatch.end()) {
250 this->
tbatch.emplace_back(phaseIdx);
251 batch = std::prev(this->
tbatch.end());
252 batch->freeDiffusionCoefficient_ = freeD;
253 batch->solutionDiffusionCoefficient_ = solutionD;
264 for (
auto& tr : this->
tbatch) {
265 if (tr.numTracer() != 0) {
270 tr.mat = std::make_unique<TracerMatrix>(*base);
278 const auto& comm =
simulator_.vanguard().grid().comm();
280 if (comm.rank() == 0) {
281 global_logger.logMessages();
291 OPM_TIMEBLOCK(tracerUpdateCache);
304 OPM_TIMEBLOCK(tracerAdvance);
312 template <
class Restarter>
322 template <
class Restarter>
326 template<
class Serializer>
329 serializer(
static_cast<BaseType&
>(*
this));
339 template<TracerTypeIdx Index>
341 const unsigned globalDofIdx,
342 const unsigned timeIdx)
const
344 const auto& intQuants =
simulator_.model().intensiveQuantities(globalDofIdx, timeIdx);
345 const auto& fs = intQuants.fluidState();
346 constexpr Scalar min_volume = 1e-10;
349 return std::max(decay<Scalar>(fs.saturation(tracerPhaseIdx)) *
350 decay<Scalar>(fs.invB(tracerPhaseIdx)) *
351 decay<Scalar>(intQuants.porosity()),
355 if (tracerPhaseIdx == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) {
356 return std::max(decay<Scalar>(fs.saturation(FluidSystem::gasPhaseIdx)) *
357 decay<Scalar>(fs.invB(FluidSystem::gasPhaseIdx)) *
358 decay<Scalar>(fs.Rv()) *
359 decay<Scalar>(intQuants.porosity()),
364 else if (tracerPhaseIdx == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas()) {
365 return std::max(decay<Scalar>(fs.saturation(FluidSystem::oilPhaseIdx)) *
366 decay<Scalar>(fs.invB(FluidSystem::oilPhaseIdx)) *
367 decay<Scalar>(fs.Rs()) *
368 decay<Scalar>(intQuants.porosity()),
376 template<TracerTypeIdx Index>
377 std::pair<TracerEvaluation, bool>
379 const ElementContext& elemCtx,
380 const unsigned scvfIdx,
381 const unsigned timeIdx)
const
383 const auto& stencil = elemCtx.stencil(timeIdx);
384 const auto& scvf = stencil.interiorFace(scvfIdx);
386 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
387 const unsigned inIdx = extQuants.interiorIndex();
393 upIdx = extQuants.upstreamIndex(tracerPhaseIdx);
394 const auto& intQuants = elemCtx.intensiveQuantities(upIdx, timeIdx);
395 const auto& inFs = intQuants.fluidState();
397 v = decay<Scalar>(extQuants.volumeFlux(tracerPhaseIdx)) *
398 decay<Scalar>(inFs.invB(tracerPhaseIdx));
402 if (tracerPhaseIdx == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) {
403 upIdx = extQuants.upstreamIndex(FluidSystem::gasPhaseIdx);
405 const auto& intQuants = elemCtx.intensiveQuantities(upIdx, timeIdx);
406 const auto& fs = intQuants.fluidState();
407 v = decay<Scalar>(fs.invB(FluidSystem::gasPhaseIdx)) *
408 decay<Scalar>(extQuants.volumeFlux(FluidSystem::gasPhaseIdx)) *
409 decay<Scalar>(fs.Rv());
412 else if (tracerPhaseIdx == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas()) {
413 upIdx = extQuants.upstreamIndex(FluidSystem::oilPhaseIdx);
415 const auto& intQuants = elemCtx.intensiveQuantities(upIdx, timeIdx);
416 const auto& fs = intQuants.fluidState();
417 v = decay<Scalar>(fs.invB(FluidSystem::oilPhaseIdx)) *
418 decay<Scalar>(extQuants.volumeFlux(FluidSystem::oilPhaseIdx)) *
419 decay<Scalar>(fs.Rs());
427 const Scalar A = scvf.area();
428 return inIdx == upIdx
429 ? std::pair{A * v * variable<TracerEvaluation>(1.0, 0),
true}
430 : std::pair{A * v,
false};
438 template<TracerTypeIdx Index>
442 return tracerPhaseIdx;
445 return tracerPhaseIdx == FluidSystem::oilPhaseIdx ? FluidSystem::gasPhaseIdx
446 : FluidSystem::oilPhaseIdx;
455 return (tracerPhaseIdx == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) ||
456 (tracerPhaseIdx == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas());
464 template<TracerTypeIdx Index,
class Flu
idState>
466 const FluidState& fs,
467 const bool saturationWeighted)
469 const int phaseIdx = carrierPhaseIdx_<Index>(tracerPhaseIdx);
470 Scalar w = decay<Scalar>(fs.invB(phaseIdx));
472 w *= tracerPhaseIdx == FluidSystem::oilPhaseIdx ? decay<Scalar>(fs.Rv())
473 : decay<Scalar>(fs.Rs());
475 if (saturationWeighted) {
476 w *= decay<Scalar>(fs.saturation(phaseIdx));
487 template<TracerTypeIdx Index,
class Flu
idState>
490 return carrierSurfaceVolume_<Index>(tracerPhaseIdx, fs,
true) > 0.0;
501 template<TracerTypeIdx Index>
504 const ElementContext& elemCtx,
505 const unsigned scvfIdx,
506 const unsigned timeIdx)
const
508 const auto& scvf = elemCtx.stencil(timeIdx).interiorFace(scvfIdx);
511 if constexpr (enableDiffusion) {
512 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
513 const auto& inFs = elemCtx.intensiveQuantities(extQuants.interiorIndex(), timeIdx).fluidState();
514 const auto& outFs = elemCtx.intensiveQuantities(extQuants.exteriorIndex(), timeIdx).fluidState();
515 if (carrierPresent_<Index>(tracerPhaseIdx, inFs) && carrierPresent_<Index>(tracerPhaseIdx, outFs)) {
516 v = decay<Scalar>(extQuants.diffusivity()) *
517 0.5 * (carrierSurfaceVolume_<Index>(tracerPhaseIdx, inFs,
true) +
518 carrierSurfaceVolume_<Index>(tracerPhaseIdx, outFs,
true));
522 return scvf.area() * v * variable<TracerEvaluation>(1.0, 0);
534 template<TracerTypeIdx Index>
537 const ElementContext& elemCtx,
538 const unsigned scvfIdx,
539 const unsigned timeIdx)
const
542 if constexpr (enableDispersion) {
544 const int phaseIdx = carrierPhaseIdx_<Index>(tracerPhaseIdx);
545 const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
546 const unsigned inIdx = extQuants.interiorIndex();
547 const unsigned outIdx = extQuants.exteriorIndex();
548 const auto& inIq = elemCtx.intensiveQuantities(inIdx, timeIdx);
549 const auto& outIq = elemCtx.intensiveQuantities(outIdx, timeIdx);
551 if (carrierPresent_<Index>(tracerPhaseIdx, inIq.fluidState()) &&
552 carrierPresent_<Index>(tracerPhaseIdx, outIq.fluidState())) {
553 const Scalar normVelocityAvg = 0.5 * (inIq.normVelocityCell(phaseIdx) +
554 outIq.normVelocityCell(phaseIdx));
555 const Scalar weight =
556 0.5 * (carrierSurfaceVolume_<Index>(tracerPhaseIdx, inIq.fluidState(),
false) +
557 carrierSurfaceVolume_<Index>(tracerPhaseIdx, outIq.fluidState(),
false));
558 const Scalar dispersivity =
559 simulator_.problem().dispersivity(elemCtx.globalSpaceIndex(inIdx, timeIdx),
560 elemCtx.globalSpaceIndex(outIdx, timeIdx));
561 flux = weight * normVelocityAvg * dispersivity;
566 return flux * variable<TracerEvaluation>(1.0, 0);
569 template<TracerTypeIdx Index,
class TrRe>
577 return tr.storageOfTimeIndex1_[tIdx][I][
Index];
579 return computeVolume_<Index>(tr.phaseIdx_, I1, 1) *
580 tr.concentration_[tIdx][I1][
Index];
586 const ElementContext& elemCtx,
587 const Scalar scvVolume,
593 if (tr.numTracer() == 0) {
597 const TracerEvaluation fVol = computeVolume_<Free>(tr.phaseIdx_, I, 0) * variable<TracerEvaluation>(1.0, 0);
598 const TracerEvaluation sVol = computeVolume_<Solution>(tr.phaseIdx_, I, 0) * variable<TracerEvaluation>(1.0, 0);
599 tr.dVol_[
Solution][I] += sVol.value() * scvVolume -
vol1_[1][tr.phaseIdx_][I];
600 tr.dVol_[
Free][I] += fVol.value() * scvVolume -
vol1_[0][tr.phaseIdx_][I];
601 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
603 const Scalar fStorageOfTimeIndex0 = fVol.value() * tr.concentration_[tIdx][I][
Free];
604 const Scalar fLocalStorage = (fStorageOfTimeIndex0 - storage1_<Free>(tr, tIdx, I, I1,
605 elemCtx.enableStorageCache())) * scvVolume / dt;
606 tr.residual_[tIdx][I][
Free] += fLocalStorage;
609 const Scalar sStorageOfTimeIndex0 = sVol.value() * tr.concentration_[tIdx][I][
Solution];
610 const Scalar sLocalStorage = (sStorageOfTimeIndex0 - storage1_<Solution>(tr, tIdx, I, I1,
611 elemCtx.enableStorageCache())) * scvVolume / dt;
612 tr.residual_[tIdx][I][
Solution] += sLocalStorage;
616 (*tr.mat)[I][I][
Free][
Free] += fVol.derivative(0) * scvVolume/dt;
622 const ElementContext& elemCtx,
628 if (tr.numTracer() == 0) {
632 const auto& [fFlux, isUpF] = computeFlux_<Free>(tr.phaseIdx_, elemCtx, scvfIdx, 0);
633 const auto& [sFlux, isUpS] = computeFlux_<Solution>(tr.phaseIdx_, elemCtx, scvfIdx, 0);
641 const bool hasDiffusionFree = enableDiffusion && tr.freeDiffusionCoefficient_ != 0.0;
642 const bool hasDiffusionSolution = enableDiffusion && hasSolutionPart &&
643 tr.solutionDiffusionCoefficient_ != 0.0;
644 const bool hasFickianFree = hasDiffusionFree || hasDispersion;
645 const bool hasFickianSolution = hasDiffusionSolution || (hasDispersion && hasSolutionPart);
646 TracerEvaluation fickianFree = 0.0;
647 TracerEvaluation fickianSolution = 0.0;
648 if (hasDiffusionFree) {
649 fickianFree += computeDiffusivity_<Free>(tr.phaseIdx_, elemCtx, scvfIdx, 0) *
650 tr.freeDiffusionCoefficient_;
652 if (hasDiffusionSolution) {
653 fickianSolution += computeDiffusivity_<Solution>(tr.phaseIdx_, elemCtx, scvfIdx, 0) *
654 tr.solutionDiffusionCoefficient_;
657 fickianFree += computeDispersivity_<Free>(tr.phaseIdx_, elemCtx, scvfIdx, 0);
658 if (hasSolutionPart) {
659 fickianSolution += computeDispersivity_<Solution>(tr.phaseIdx_, elemCtx, scvfIdx, 0);
663 tr.dVol_[
Solution][I] += sFlux.value() * dt;
664 tr.dVol_[
Free][I] += fFlux.value() * dt;
665 const int fGlobalUpIdx = isUpF ? I : J;
666 const int sGlobalUpIdx = isUpS ? I : J;
667 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
669 tr.residual_[tIdx][I][
Free] += fFlux.value()*tr.concentration_[tIdx][fGlobalUpIdx][
Free];
670 tr.residual_[tIdx][I][
Solution] += sFlux.value()*tr.concentration_[tIdx][sGlobalUpIdx][
Solution];
673 if (hasFickianFree) {
674 const Scalar gradientFree = tr.concentration_[tIdx][J][
Free] - tr.concentration_[tIdx][I][
Free];
675 tr.residual_[tIdx][I][
Free] -= fickianFree.value() * gradientFree;
677 if (hasFickianSolution) {
678 const Scalar gradientSolution = tr.concentration_[tIdx][J][
Solution] - tr.concentration_[tIdx][I][
Solution];
679 tr.residual_[tIdx][I][
Solution] -= fickianSolution.value() * gradientSolution;
691 (*tr.mat)[I][I][
Free][
Free] += fFlux.derivative(0);
692 (*tr.mat)[J][I][
Free][
Free] -= fFlux.derivative(0);
701 if (hasFickianFree) {
702 (*tr.mat)[I][I][
Free][
Free] += fickianFree.derivative(0);
703 (*tr.mat)[J][I][
Free][
Free] -= fickianFree.derivative(0);
705 if (hasFickianSolution) {
711 template<
class TrRe,
class Well>
715 if (tr.numTracer() == 0) {
719 const auto& eclWell = well.wellEcl();
725 auto* mswTracerRate = eclWell.isMultiSegment()
728 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
729 tracerRate[tr.idx_[tIdx]] = {this->
name(tr.idx_[tIdx]), 0.0};
730 freeTracerRate[tr.idx_[tIdx]] = {this->
wellfname(tr.idx_[tIdx]), 0.0};
731 solTracerRate[tr.idx_[tIdx]] = {this->
wellsname(tr.idx_[tIdx]), 0.0};
732 if (eclWell.isMultiSegment()) {
733 auto& wtr = mswTracerRate->at(tr.idx_[tIdx]) = {this->
name(tr.idx_[tIdx])};;
734 wtr.rate.reserve(eclWell.getConnections().size());
735 for (std::size_t i = 0; i < eclWell.getConnections().size(); ++i) {
736 wtr.rate.emplace(eclWell.getConnections().get(i).segment(), 0.0);
741 std::vector<Scalar> wtracer(tr.numTracer());
742 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
744 simulator_.problem().wellModel().summaryState());
748 const auto& ws =
simulator_.problem().wellModel().wellState().well(well.name());
749 const auto well_eff = well.wellEfficiencyFactor();
750 for (std::size_t i = 0; i < ws.perf_data.size(); ++i) {
751 const auto I = ws.perf_data.cell_index[i];
752 const Scalar rate = well.volumetricSurfaceRateForConnection(I, tr.phaseIdx_);
755 if (tr.phaseIdx_ == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) {
756 rate_s = ws.perf_data.phase_mixing_rates[i][ws.vaporized_oil] * well_eff;
758 else if (tr.phaseIdx_ == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas()) {
759 rate_s = ws.perf_data.phase_mixing_rates[i][ws.dissolved_gas] * well_eff;
765 const Scalar rate_f = rate - rate_s;
767 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
768 const Scalar delta = rate_f * wtracer[tIdx];
770 tr.residual_[tIdx][I][
Free] -= delta;
774 tracerRate[tr.idx_[tIdx]].rate += delta;
775 freeTracerRate[tr.idx_[tIdx]].rate += delta;
776 if (eclWell.isMultiSegment()) {
777 (*mswTracerRate)[tr.idx_[tIdx]].rate[eclWell.getConnections().get(i).segment()] += delta;
780 tr.dVol_[
Free][I] -= rate_f * dt;
782 else if (rate_f < 0) {
783 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
784 const Scalar delta = rate_f * wtracer[tIdx];
787 tracerRate[tr.idx_[tIdx]].rate += delta;
788 freeTracerRate[tr.idx_[tIdx]].rate += delta;
791 tr.residual_[tIdx][I][
Free] -= rate_f * tr.concentration_[tIdx][I][
Free];
793 tr.dVol_[
Free][I] -= rate_f * dt;
796 (*tr.mat)[I][I][
Free][
Free] -= rate_f * variable<TracerEvaluation>(1.0, 0).derivative(0);
799 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
801 tr.residual_[tIdx][I][
Solution] -= rate_s * tr.concentration_[tIdx][I][
Solution];
803 tr.dVol_[
Solution][I] -= rate_s * dt;
806 (*tr.mat)[I][I][
Solution][
Solution] -= rate_s * variable<TracerEvaluation>(1.0, 0).derivative(0);
827 const ElementContext& elemCtx,
831 if (tr.numTracer() == 0) {
836 if (!problem.nonTrivialBoundaryConditions()) {
840 if (!elemCtx.onBoundary()) {
848 BoundaryContext boundaryCtx(elemCtx);
849 if (boundaryCtx.intersection(0).neighbor()) {
851 boundaryCtx.increment();
854 const auto& stencil = elemCtx.stencil(0);
855 const auto& bcstate =
simulator_.vanguard().schedule()[problem.episodeIndex()].bcstate;
856 const unsigned numBoundaryFaces = boundaryCtx.numBoundaryFaces(0);
857 for (
unsigned bfIdx = 0; bfIdx < numBoundaryFaces; ++bfIdx, boundaryCtx.increment()) {
858 const auto& bf = stencil.boundaryFace(bfIdx);
859 const int dirId = bf.dirId();
864 const int bcIndex = problem.boundaryConditionIndex(I, dirId);
869 const BCType type = problem.boundaryCondition(I, dirId).first;
870 if (type != BCType::RATE && type != BCType::FREE && type != BCType::DIRICHLET) {
874 BoundaryRateVector bdyFlux;
875 problem.boundary(bdyFlux, boundaryCtx, bfIdx, 0);
876 const unsigned pvtRegionIdx = problem.pvtRegionIndex(I);
877 const Scalar boundaryArea = bf.area() * decay<Scalar>(elemCtx.intensiveQuantities(0, 0).extrusionFactor());
883 const auto phaseFlux = [&](
const int phaseIdx)
885 const int compIdx = phaseIdx == FluidSystem::waterPhaseIdx ? FluidSystem::waterCompIdx
886 : phaseIdx == FluidSystem::oilPhaseIdx ? FluidSystem::oilCompIdx
887 : FluidSystem::gasCompIdx;
888 Scalar flux = decay<Scalar>(bdyFlux[FluidSystem::canonicalToActiveCompIdx(compIdx)]) * boundaryArea;
889 if constexpr (!getPropValue<TypeTag, Properties::BlackoilConserveSurfaceVolume>()) {
890 flux /= FluidSystem::referenceDensity(phaseIdx, pvtRegionIdx);
894 const Scalar rateOut = phaseFlux(tr.phaseIdx_);
895 if (rateOut == Scalar{0}) {
903 Scalar rateFree = rateOut;
904 Scalar rateSol = 0.0;
905 const bool oilSolution = tr.phaseIdx_ == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil();
906 const bool gasSolution = tr.phaseIdx_ == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas();
907 if (rateOut > 0 && (oilSolution || gasSolution)) {
909 const auto& intQuants =
simulator_.model().intensiveQuantities(I, 0);
910 const auto& fs = intQuants.fluidState();
911 const Scalar Rs = FluidSystem::enableDissolvedGas() ? decay<Scalar>(fs.Rs()) : Scalar{0};
912 const Scalar Rv = FluidSystem::enableVaporizedOil() ? decay<Scalar>(fs.Rv()) : Scalar{0};
913 const Scalar Qo = phaseFlux(FluidSystem::oilPhaseIdx);
914 const Scalar Qg = phaseFlux(FluidSystem::gasPhaseIdx);
915 const Scalar det = 1.0 - Rs * Rv;
916 const Scalar Fo = (Qo - Rv * Qg) / det;
917 const Scalar Fg = (Qg - Rs * Qo) / det;
928 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
931 const auto bcConc = bcstate.tracerConcentration(bcIndex,
932 this->
name(tr.idx_[tIdx]));
933 tr.residual_[tIdx][I][
Free] += rateOut * bcConc.value_or(0.0);
937 tr.residual_[tIdx][I][
Free] += rateFree * tr.concentration_[tIdx][I][
Free];
938 tr.residual_[tIdx][I][
Solution] += rateSol * tr.concentration_[tIdx][I][
Solution];
941 tr.dVol_[
Free][I] += rateFree * dt;
942 tr.dVol_[
Solution][I] += rateSol * dt;
946 (*tr.mat)[I][I][
Free][
Free] += rateFree * variable<TracerEvaluation>(1.0, 0).derivative(0);
947 (*tr.mat)[I][I][
Solution][
Solution] += rateSol * variable<TracerEvaluation>(1.0, 0).derivative(0);
957 if (tr.numTracer() == 0) {
962 if (tr.phaseIdx_ == FluidSystem::waterPhaseIdx ||
963 (tr.phaseIdx_ == FluidSystem::gasPhaseIdx && !FluidSystem::enableDissolvedGas()) ||
964 (tr.phaseIdx_ == FluidSystem::oilPhaseIdx && !FluidSystem::enableVaporizedOil()))
969 const Scalar& dsVol = tr.dVol_[
Solution][I];
970 const Scalar& dfVol = tr.dVol_[
Free][I];
973 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
975 const auto delta = (dfVol / dt) * tr.concentration_[tIdx][I][
Free];
976 tr.residual_[tIdx][I][
Free] -= delta;
977 tr.residual_[tIdx][I][
Solution] += delta;
980 const auto delta = (dsVol / dt) * tr.concentration_[tIdx][I][
Solution];
981 tr.residual_[tIdx][I][
Free] += delta;
982 tr.residual_[tIdx][I][
Solution] -= delta;
988 const auto delta = (dfVol / dt) * variable<TracerEvaluation>(1.0, 0).derivative(0);
989 (*tr.mat)[I][I][
Free][
Free] -= delta;
993 const auto delta = (dsVol / dt) * variable<TracerEvaluation>(1.0, 0).derivative(0);
1010 OPM_TIMEBLOCK(tracerAssemble);
1011 for (
auto& tr :
tbatch) {
1012 if (tr.numTracer() != 0) {
1014 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1015 tr.residual_[tIdx] = 0.0;
1029 const auto& wellPtrs =
simulator_.problem().wellModel().localNonshutWells();
1034 for (
const auto& wellPtr : wellPtrs) {
1036 const auto& eclWell = wellPtr->wellEcl();
1040 auto* mswTracerRate = eclWell.isMultiSegment()
1043 if (mswTracerRate) {
1046 for (
auto& tr :
tbatch) {
1051 for (
auto& tr :
tbatch) {
1057 #pragma omp parallel for
1062 const Scalar dt = elemCtx.simulator().timeStepSize();
1064 for (
const auto& elem : chunk) {
1065 elemCtx.updateStencil(elem);
1066 const std::size_t I = elemCtx.globalSpaceIndex( 0, 0);
1068 if (elem.partitionType() != Dune::InteriorEntity) {
1072 for (
const auto& tr :
tbatch) {
1073 if (tr.numTracer() != 0) {
1074 (*tr.mat)[I][I][0][0] = 1.;
1075 (*tr.mat)[I][I][1][1] = 1.;
1080 elemCtx.updateAllIntensiveQuantities();
1081 elemCtx.updateAllExtensiveQuantities();
1083 const Scalar extrusionFactor =
1084 elemCtx.intensiveQuantities( 0, 0).extrusionFactor();
1085 Valgrind::CheckDefined(extrusionFactor);
1086 assert(isfinite(extrusionFactor));
1087 assert(extrusionFactor > 0.0);
1088 const Scalar scvVolume =
1089 elemCtx.stencil(0).subControlVolume( 0).volume() * extrusionFactor;
1090 const std::size_t I1 = elemCtx.globalSpaceIndex( 0, 1);
1094 for (
auto& tr :
tbatch) {
1095 if (tr.numTracer() == 0) {
1101 const std::size_t numInteriorFaces = elemCtx.numInteriorFaces(0);
1102 for (
unsigned scvfIdx = 0; scvfIdx < numInteriorFaces; scvfIdx++) {
1103 const auto& face = elemCtx.stencil(0).interiorFace(scvfIdx);
1104 const unsigned j = face.exteriorIndex();
1105 const unsigned J = elemCtx.globalSpaceIndex( j, 0);
1106 for (
auto& tr :
tbatch) {
1107 if (tr.numTracer() == 0) {
1115 for (
auto& tr :
tbatch) {
1120 for (
auto& tr :
tbatch) {
1121 if (tr.numTracer() == 0) {
1130 "assembleTracerEquations() failed: ",
1134 for (
auto& tr :
tbatch) {
1135 if (tr.numTracer() == 0) {
1140 simulator_.gridView().communicate(handle, Dune::InteriorBorder_All_Interface,
1141 Dune::ForwardCommunication);
1145 template<TracerTypeIdx Index,
class TrRe>
1147 const Scalar scvVolume,
1148 const unsigned globalDofIdx)
1150 const Scalar vol1 = computeVolume_<Index>(tr.phaseIdx_, globalDofIdx, 0);
1151 vol1_[
Index][tr.phaseIdx_][globalDofIdx] = vol1 * scvVolume;
1152 tr.dVol_[
Index][globalDofIdx] = 0.0;
1153 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1154 tr.storageOfTimeIndex1_[tIdx][globalDofIdx][
Index] =
1155 vol1 * tr.concentrationInitial_[tIdx][globalDofIdx][
Index];
1161 for (
auto& tr :
tbatch) {
1162 if (tr.numTracer() != 0) {
1163 tr.concentrationInitial_ = tr.concentration_;
1169 #pragma omp parallel for
1175 for (
const auto& elem : chunk) {
1176 elemCtx.updatePrimaryStencil(elem);
1177 elemCtx.updatePrimaryIntensiveQuantities(0);
1178 const Scalar extrusionFactor = elemCtx.intensiveQuantities( 0, 0).extrusionFactor();
1179 const Scalar scvVolume = elemCtx.stencil(0).subControlVolume( 0).volume() * extrusionFactor;
1180 const unsigned globalDofIdx = elemCtx.globalSpaceIndex(0, 0);
1182 for (
auto& tr :
tbatch) {
1183 if (tr.numTracer() == 0) {
1188 updateElem<Free>(tr, scvVolume, globalDofIdx);
1189 updateElem<Solution>(tr, scvVolume, globalDofIdx);
1195 template<TracerTypeIdx Index,
class TrRe>
1197 const std::vector<TracerVector>& dx,
1199 const unsigned tIdx,
1200 const unsigned globalDofIdx,
1201 std::vector<TracerVectorSingle>& sc)
1203 constexpr Scalar tol_gas_sat = 1e-6;
1204 tr.concentration_[tIdx][globalDofIdx][
Index] -= dx[tIdx][globalDofIdx][
Index];
1205 if (tr.concentration_[tIdx][globalDofIdx][
Index] < 0.0 || S < tol_gas_sat) {
1206 tr.concentration_[tIdx][globalDofIdx][
Index] = 0.0;
1208 sc[tr.idx_[tIdx]][globalDofIdx] = tr.concentration_[tIdx][globalDofIdx][
Index];
1211 template<TracerTypeIdx Index,
class TrRe>
1213 const Well& eclWell,
1214 const std::size_t i,
1215 const std::size_t I,
1222 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1224 const Scalar delta = rate * tr.concentration_[tIdx][I][
Index];
1225 tracerRate[tr.idx_[tIdx]].rate += delta;
1226 splitRate[tr.idx_[tIdx]].rate += delta;
1227 if (eclWell.isMultiSegment()) {
1228 (*mswTracerRate)[tr.idx_[tIdx]].rate[eclWell.getConnections().get(i).segment()] += delta;
1235 const auto& wellPtrs =
simulator_.problem().wellModel().localNonshutWells();
1236 for (
const auto& wellPtr : wellPtrs) {
1237 const auto& eclWell = wellPtr->wellEcl();
1238 const auto well_seq_index = eclWell.seqIndex();
1239 const auto inv_well_eff_factor = 1.0 / std::max(Scalar{1.0e-10}, wellPtr->wellEfficiencyFactor());
1242 wtr.
rate *= inv_well_eff_factor;
1245 wtr.
rate *= inv_well_eff_factor;
1248 wtr.
rate *= inv_well_eff_factor;
1250 if (eclWell.isMultiSegment()) {
1252 std::ranges::for_each(wtr.
rate, [&](
auto& item) {
1253 item.second *= inv_well_eff_factor;
1274 std::unordered_map<std::string, int> tracer_name_to_idx;
1275 for (
int tracerIdx = 0; tracerIdx < this->
numTracers(); ++tracerIdx) {
1276 tracer_name_to_idx.emplace(this->
name(tracerIdx), tracerIdx);
1279 const bool logging =
simulator_.vanguard().grid().comm().rank() == 0;
1280 const auto& schedule =
simulator_.vanguard().schedule();
1281 std::set<std::pair<int, std::string>> warned;
1282 std::set<int> flowIndices;
1283 std::set<int> tracerIndices;
1284 for (std::size_t step = 0; step < schedule.size(); ++step) {
1285 for (
const auto& face : schedule[step].bcstate) {
1286 if (face.bctype == BCType::RATE || face.bctype == BCType::FREE ||
1287 face.bctype == BCType::DIRICHLET) {
1288 flowIndices.insert(face.index);
1291 for (
const auto& tracerbc : face.tracerbcvalues) {
1292 tracerIndices.insert(face.index);
1293 const auto pos = tracer_name_to_idx.find(tracerbc.tracer);
1294 if (pos == tracer_name_to_idx.end()) {
1295 throw std::runtime_error(fmt::format(
"BCTRACER: tracer {} (INDEX {}) is not declared in TRACER",
1296 tracerbc.tracer, face.index));
1300 const bool samePhase =
1301 (face.component == BCComponent::WATER && phaseIdx == FluidSystem::waterPhaseIdx) ||
1302 (face.component == BCComponent::OIL && phaseIdx == FluidSystem::oilPhaseIdx) ||
1303 (face.component == BCComponent::GAS && phaseIdx == FluidSystem::gasPhaseIdx);
1305 const bool isPhaseComponent = face.component == BCComponent::WATER ||
1306 face.component == BCComponent::OIL ||
1307 face.component == BCComponent::GAS;
1308 if (isPhaseComponent && !samePhase &&
1309 warned.emplace(face.index, tracerbc.tracer).second && logging)
1311 deferredLogger.
warning(fmt::format(
"BCTRACER: the BCPROP component of INDEX {} is not the phase "
1312 "of tracer {}, so the tracer will not enter through this "
1313 "boundary", face.index, tracerbc.tracer));
1319 for (
const int index : tracerIndices) {
1320 if (!flowIndices.contains(index) && logging) {
1321 deferredLogger.
warning(fmt::format(
"BCTRACER: INDEX {} has no BCPROP of type RATE, FREE or DIRICHLET. "
1322 "BCTRACER is only used for boundaries with a flow and is ignored.",
1332 const auto& aquifer_cfg = this->
eclState_.aquifer();
1333 if (!aquifer_cfg.active()) {
1337 const auto& specs = aquifer_cfg.aquiferTracers();
1338 if (specs.empty()) {
1342 std::unordered_map<std::string, int> tracer_name_to_idx;
1343 for (
int tracerIdx = 0; tracerIdx < this->
numTracers(); ++tracerIdx) {
1344 tracer_name_to_idx.emplace(this->
name(tracerIdx), tracerIdx);
1347 const auto& vanguard =
simulator_.vanguard();
1348 for (
const auto& spec : specs) {
1349 if (!aquifer_cfg.hasAnalyticalAquifer(spec.aquifer_id)) {
1353 const auto tracer_pos = tracer_name_to_idx.find(spec.tracer_name);
1354 if (tracer_pos == tracer_name_to_idx.end()) {
1355 if (
simulator_.vanguard().grid().comm().rank() == 0) {
1356 deferredLogger.
warning(fmt::format(
"AQANTRC tracer '{}' is not declared in TRACER",
1362 if (!aquifer_cfg.connections().hasAquiferConnections(spec.aquifer_id)) {
1366 const int tracerIdx = tracer_pos->second;
1369 for (
const auto& conn : aquifer_cfg.connections().getConnections(spec.aquifer_id)) {
1370 const int cellIdx = vanguard.compressedIndex(conn.global_index);
1381 template<
class TrRe>
1388 const auto& aquiferModel =
simulator_.problem().aquiferModel();
1394 const Scalar rate = aquiferModel.cachedConnectionInfluxRate(cellIdx);
1395 if (rate == Scalar{0}) {
1399 const unsigned I = cellIdx;
1400 const Scalar rate_f = rate;
1402 for (
const auto& spec : specs) {
1403 if (spec.phaseIdx != tr.phaseIdx_) {
1408 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1409 if (tr.idx_[tIdx] == spec.tracerIdx) {
1414 if (localTIdx < 0) {
1419 const Scalar delta = rate_f * spec.concentration;
1420 tr.residual_[localTIdx][I][
Free] -= delta;
1421 tr.dVol_[
Free][I] -= rate_f * dt;
1423 else if (rate_f < 0) {
1424 tr.residual_[localTIdx][I][
Free] -= rate_f * tr.concentration_[localTIdx][I][
Free];
1425 tr.dVol_[
Free][I] -= rate_f * dt;
1426 (*tr.mat)[I][I][
Free][
Free] -= rate_f * variable<TracerEvaluation>(1.0, 0).derivative(0);
1432 template<
class TrRe>
1441 if (tr.reorderSkipSteps_ > 0) {
1442 --tr.reorderSkipSteps_;
1443 if (tr.reorderSkipSteps_ == 0) {
1444 OpmLog::info(fmt::format(
"Tracer model: retrying the reorder solver for the {} "
1445 "tracers in the next time step",
1446 FluidSystem::phaseName(tr.phaseIdx_)));
1459 OpmLog::warning(fmt::format(
"Tracer model: the reorder solver failed for the {} tracers. "
1460 "Using the ISTL solver for this and the next {} time steps.",
1469 for (
auto& tr :
tbatch) {
1470 if (tr.numTracer() == 0) {
1476 std::vector<TracerVector> dx(tr.concentration_);
1477 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1483 OpmLog::warning(
"### Tracer model: Linear solver did not converge. ###");
1486 OPM_TIMEBLOCK(tracerPost);
1488 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1489 for (std::size_t globalDofIdx = 0; globalDofIdx < tr.concentration_[tIdx].size(); ++globalDofIdx) {
1492 const auto& intQuants =
simulator_.model().intensiveQuantities(globalDofIdx, 0);
1493 const auto& fs = intQuants.fluidState();
1494 const Scalar Sf = decay<Scalar>(fs.saturation(tr.phaseIdx_));
1497 if (tr.phaseIdx_ == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas()) {
1498 Ss = decay<Scalar>(fs.saturation(FluidSystem::oilPhaseIdx));
1500 else if (tr.phaseIdx_ == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) {
1501 Ss = decay<Scalar>(fs.saturation(FluidSystem::gasPhaseIdx));
1510 const auto& wellPtrs =
simulator_.problem().wellModel().localNonshutWells();
1511 for (
const auto& wellPtr : wellPtrs) {
1512 const auto& eclWell = wellPtr->wellEcl();
1515 if (!eclWell.isProducer()) {
1519 Scalar rateWellPos = 0.0;
1520 Scalar rateWellNeg = 0.0;
1521 const std::size_t well_index =
simulator_.problem().wellModel().wellState().index(eclWell.name()).value();
1522 const auto& ws =
simulator_.problem().wellModel().wellState().well(well_index);
1526 auto* mswTracerRate = eclWell.isMultiSegment() ? &this->
mSwTracerRate_[eclWell.seqIndex()] :
nullptr;
1527 const auto well_eff = wellPtr->wellEfficiencyFactor();
1528 for (std::size_t i = 0; i < ws.perf_data.size(); ++i) {
1529 const auto I = ws.perf_data.cell_index[i];
1530 const Scalar rate = wellPtr->volumetricSurfaceRateForConnection(I, tr.phaseIdx_);
1533 if (tr.phaseIdx_ == FluidSystem::oilPhaseIdx && FluidSystem::enableVaporizedOil()) {
1534 rate_s = ws.perf_data.phase_mixing_rates[i][ws.vaporized_oil]*well_eff;
1536 else if (tr.phaseIdx_ == FluidSystem::gasPhaseIdx && FluidSystem::enableDissolvedGas()) {
1537 rate_s = ws.perf_data.phase_mixing_rates[i][ws.dissolved_gas]*well_eff;
1543 const Scalar rate_f = rate - rate_s;
1544 assignRates<Free>(tr, eclWell, i, I, rate_f,
1545 tracerRate, mswTracerRate, freeTracerRate);
1546 assignRates<Solution>(tr, eclWell, i, I, rate_s,
1547 tracerRate, mswTracerRate, solTracerRate);
1550 rateWellNeg += rate;
1553 rateWellPos += rate;
1562 const Scalar official_well_rate_total =
1563 simulator_.problem().wellModel().wellState().well(well_index).surface_rates[tr.phaseIdx_];
1565 const Scalar rateWellTotal = official_well_rate_total;
1567 if (rateWellTotal > rateWellNeg) {
1568 constexpr Scalar bucketPrDay = 10.0 / (1000. * 3600. * 24.);
1569 const Scalar factor = (rateWellTotal < -bucketPrDay) ? rateWellTotal / rateWellNeg : 0.0;
1570 for (
int tIdx = 0; tIdx < tr.numTracer(); ++tIdx) {
1571 tracerRate[tr.idx_[tIdx]].rate *= factor;
1592 template <
typename TV>
1601 std::unique_ptr<TracerMatrix>
mat;
1608 std::array<std::vector<Scalar>, 2>
dVol_;
1619 result.
idx_ = {1,2,3};
1628 template<
class Serializer>
1638 {
return idx_.size(); }
1642 const int numGridDof = concentration.size();
1643 idx_.emplace_back(idx);
1648 for (
auto& dVol :
dVol_) {
1649 dVol.resize(numGridDof);
1654 std::vector<TracerBatch<TracerVector>>
tbatch;
1655 std::array<std::array<std::vector<Scalar>,numPhases>,2>
vol1_;
#define OPM_END_PARALLEL_TRY_CATCH_LOG(obptc_logger, obptc_prefix, obptc_output, comm)
Catch exception, log, and throw in a parallel try-catch clause.
Definition: DeferredLoggingErrorHelpers.hpp:207
#define OPM_BEGIN_PARALLEL_TRY_CATCH()
Macro to setup the try of a parallel try-catch.
Definition: DeferredLoggingErrorHelpers.hpp:160
A datahandle sending data located in multiple vectors.
Definition: DeferredLogger.hpp:57
void warning(const std::string &tag, const std::string &message)
Definition: GenericTracerModel.hpp:56
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::TracerVector Opm::BlockVector< Dune::FieldVector< GetPropType< TypeTag, Properties::Scalar >, 2 > > TracerVector
Definition: GenericTracerModel.hpp:60
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::numTracers int numTracers() const
Return the number of tracers considered by the tracerModel.
Definition: GenericTracerModel_impl.hpp:164
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::useReorderSolver_ bool useReorderSolver_
Definition: GenericTracerModel.hpp:167
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::doInit void doInit(bool rst, std::size_t numGridDof, std::size_t gasPhaseIdx, std::size_t oilPhaseIdx, std::size_t waterPhaseIdx)
Initialize all internal data structures needed by the tracer module.
Definition: GenericTracerModel_impl.hpp:229
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::tracerConcentration_ std::vector< TracerVector > tracerConcentration_
Definition: GenericTracerModel.hpp:165
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::tracerPhaseIdx_ std::vector< int > tracerPhaseIdx_
Definition: GenericTracerModel.hpp:163
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::wellFreeTracerRate_ std::unordered_map< int, std::vector< WellTracerRate< GetPropType< TypeTag, Properties::Scalar > > > > wellFreeTracerRate_
Definition: GenericTracerModel.hpp:173
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::wellTracerRate_ std::unordered_map< int, std::vector< WellTracerRate< GetPropType< TypeTag, Properties::Scalar > > > > wellTracerRate_
Definition: GenericTracerModel.hpp:172
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::mSwTracerRate_ std::unordered_map< int, std::vector< MSWellTracerRate< GetPropType< TypeTag, Properties::Scalar > > > > mSwTracerRate_
Definition: GenericTracerModel.hpp:176
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::eclState_ const EclipseState & eclState_
Definition: GenericTracerModel.hpp:159
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::wellfname std::string wellfname(int tracerIdx) const
Definition: GenericTracerModel_impl.hpp:185
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::name const std::string & name(int tracerIdx) const
Return the tracer name.
Definition: GenericTracerModel_impl.hpp:222
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::wellsname std::string wellsname(int tracerIdx) const
Definition: GenericTracerModel_impl.hpp:192
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::freeTracerConcentration_ std::vector< TracerVectorSingle > freeTracerConcentration_
Definition: GenericTracerModel.hpp:168
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::linearSolveReorder_ bool linearSolveReorder_(const TracerMatrix &M, std::vector< TracerVector > &x, std::vector< TracerVector > &b)
Solve the tracer equations cell by cell in the order of the flow.
Definition: GenericTracerModel_impl.hpp:510
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::TracerMatrix Opm::BCRSMatrix< Opm::MatrixBlock< GetPropType< TypeTag, Properties::Scalar >, 2, 2 > > TracerMatrix
Definition: GenericTracerModel.hpp:59
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::TracerTypeIdx TracerTypeIdx
Tracer type index.
Definition: GenericTracerModel.hpp:153
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::Free @ Free
Definition: GenericTracerModel.hpp:154
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::Solution @ Solution
Definition: GenericTracerModel.hpp:155
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::linearSolveBatchwise_ bool linearSolveBatchwise_(const TracerMatrix &M, std::vector< TracerVector > &x, std::vector< TracerVector > &b)
Definition: GenericTracerModel_impl.hpp:446
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::solTracerConcentration_ std::vector< TracerVectorSingle > solTracerConcentration_
Definition: GenericTracerModel.hpp:169
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::currentConcentration_ GetPropType< TypeTag, Properties::Scalar > currentConcentration_(const Well &eclWell, const std::string &trName, const SummaryState &summaryState) const
Definition: GenericTracerModel_impl.hpp:213
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::tracerMatrix_ std::unique_ptr< TracerMatrix > tracerMatrix_
Definition: GenericTracerModel.hpp:166
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::wellSolTracerRate_ std::unordered_map< int, std::vector< WellTracerRate< GetPropType< TypeTag, Properties::Scalar > > > > wellSolTracerRate_
Definition: GenericTracerModel.hpp:174
Opm::GenericTracerModel< GetPropType< TypeTag, Properties::Grid >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::DofMapper >, GetPropType< TypeTag, Properties::Stencil >, GetPropType< TypeTag, Properties::FluidSystem >, GetPropType< TypeTag, Properties::Scalar > >::TracerVectorSingle Opm::BlockVector< Dune::FieldVector< GetPropType< TypeTag, Properties::Scalar >, 1 > > TracerVectorSingle
Definition: GenericTracerModel.hpp:58
Simplifies multi-threaded capabilities.
Definition: threadmanager.hpp:36
A class which handles tracers as specified in by ECL.
Definition: TracerModel.hpp:89
static Scalar carrierSurfaceVolume_(const int tracerPhaseIdx, const FluidState &fs, const bool saturationWeighted)
Surface volume of the tracer carrier per unit pore volume of a cell: the inverse formation volume fac...
Definition: TracerModel.hpp:465
void updateStorageCache()
Definition: TracerModel.hpp:1159
std::array< std::array< std::vector< Scalar >, numPhases >, 2 > vol1_
Definition: TracerModel.hpp:1655
void convertEffectiveRatesToRawRates()
Definition: TracerModel.hpp:1234
static bool carrierPresent_(const int tracerPhaseIdx, const FluidState &fs)
Whether the carrier of the tracer is present in a cell, i.e. there is carrier phase (and,...
Definition: TracerModel.hpp:488
void assembleTracerEquationBoundary(TrRe &tr, const ElementContext &elemCtx, const unsigned I, const Scalar dt)
Boundary conditions for the tracer equations.
Definition: TracerModel.hpp:826
void advanceTracerFields()
Definition: TracerModel.hpp:1465
void init(bool rst)
Definition: TracerModel.hpp:151
TracerEvaluation computeDispersivity_(const int tracerPhaseIdx, const ElementContext &elemCtx, const unsigned scvfIdx, const unsigned timeIdx) const
Dispersive coefficient of a face for the Fickian flux J = -(w * |u| * disp) * (c_J - c_I),...
Definition: TracerModel.hpp:536
void checkBoundaryTracers_(DeferredLogger &deferredLogger) const
Cross-reference the boundary conditions of the schedule with the tracers.
Definition: TracerModel.hpp:1272
std::vector< TracerBatch< TracerVector > > tbatch
Definition: TracerModel.hpp:1654
void assembleTracerEquationSource(TrRe &tr, const Scalar dt, unsigned I)
Definition: TracerModel.hpp:953
TracerModel(Simulator &simulator)
Definition: TracerModel.hpp:121
void assignRates(const TrRe &tr, const Well &eclWell, const std::size_t i, const std::size_t I, const Scalar rate, std::vector< WellTracerRate< Scalar > > &tracerRate, std::vector< MSWellTracerRate< Scalar > > *mswTracerRate, std::vector< WellTracerRate< Scalar > > &splitRate)
Definition: TracerModel.hpp:1212
void copyForOutput(TrRe &tr, const std::vector< TracerVector > &dx, const Scalar S, const unsigned tIdx, const unsigned globalDofIdx, std::vector< TracerVectorSingle > &sc)
Definition: TracerModel.hpp:1196
void assembleTracerEquationFlux(TrRe &tr, const ElementContext &elemCtx, unsigned scvfIdx, unsigned I, unsigned J, const Scalar dt)
Definition: TracerModel.hpp:621
bool solveBatch_(TrRe &tr, std::vector< TracerVector > &dx)
Definition: TracerModel.hpp:1433
void assembleTracerEquationWell(TrRe &tr, const Well &well)
Definition: TracerModel.hpp:712
void updateElem(TrRe &tr, const Scalar scvVolume, const unsigned globalDofIdx)
Definition: TracerModel.hpp:1146
Scalar computeVolume_(const int tracerPhaseIdx, const unsigned globalDofIdx, const unsigned timeIdx) const
Definition: TracerModel.hpp:340
void assembleTracerEquationAquifer_(TrRe &tr)
Definition: TracerModel.hpp:1382
typename BaseType::TracerTypeIdx TracerTypeIdx
Definition: TracerModel.hpp:334
void assembleTracerEquationVolume(TrRe &tr, const ElementContext &elemCtx, const Scalar scvVolume, const Scalar dt, unsigned I, unsigned I1)
Definition: TracerModel.hpp:585
Scalar storage1_(const TrRe &tr, const unsigned tIdx, const unsigned I, const unsigned I1, const bool cache)
Definition: TracerModel.hpp:570
void serialize(Restarter &)
This method writes the complete state of all tracer to the hard disk.
Definition: TracerModel.hpp:313
void assembleTracerEquations_()
Definition: TracerModel.hpp:999
static bool hasSolutionPart_(const int tracerPhaseIdx)
Whether the tracers of the phase have a solution part (vaporized oil, dissolved gas)
Definition: TracerModel.hpp:453
void buildAquiferTracerConnections_(DeferredLogger &deferredLogger)
Definition: TracerModel.hpp:1328
bool dispersionActive_
Definition: TracerModel.hpp:1582
std::pair< TracerEvaluation, bool > computeFlux_(const int tracerPhaseIdx, const ElementContext &elemCtx, const unsigned scvfIdx, const unsigned timeIdx) const
Definition: TracerModel.hpp:378
void beginTimeStep()
Definition: TracerModel.hpp:285
TracerEvaluation computeDiffusivity_(const int tracerPhaseIdx, const ElementContext &elemCtx, const unsigned scvfIdx, const unsigned timeIdx) const
Diffusive coefficient of a face for the Fickian flux J = -D_mol * A * diffusivity * w * (c_J - c_I)....
Definition: TracerModel.hpp:503
void serializeOp(Serializer &serializer)
Definition: TracerModel.hpp:327
int reorderRetrySteps_
Definition: TracerModel.hpp:1666
void prepareTracerBatches()
Definition: TracerModel.hpp:195
std::unordered_map< unsigned, std::vector< AquiferTracerCellSpec > > aquifer_tracer_cells_
Definition: TracerModel.hpp:1664
ElementChunks< GridView, Dune::Partitions::All > element_chunks_
Definition: TracerModel.hpp:1656
void endTimeStep()
Informs the tracer model that a time step has just been finished.
Definition: TracerModel.hpp:298
Simulator & simulator_
Definition: TracerModel.hpp:1579
static int carrierPhaseIdx_(const int tracerPhaseIdx)
Phase that carries the tracer of the given type: the phase of the tracer for the free tracer,...
Definition: TracerModel.hpp:439
void deserialize(Restarter &)
This method restores the complete state of the tracer from disk.
Definition: TracerModel.hpp:323
A data handle sending multiple data store in vectors attached to cells.
Definition: VectorVectorDataHandle.hpp:52
Definition: fvbaseprimaryvariables.hh:161
int Index
The type of an index of a degree of freedom.
Definition: overlaptypes.hh:44
Definition: blackoilmodel.hh:74
Definition: blackoilbioeffectsmodules.hh:45
Opm::DeferredLogger gatherDeferredLogger(const Opm::DeferredLogger &local_deferredlogger, Parallel::Communication communicator)
Create a global log combining local logs.
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:233
std::string to_string(const ConvergenceReport::ReservoirFailure::Type t)
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Definition: WellTracerRate.hpp:60
std::unordered_map< int, Scalar > rate
Definition: WellTracerRate.hpp:62
Definition: TracerModel.hpp:69
a tag to mark properties as undefined
Definition: propertysystem.hh:38
Definition: TracerModel.hpp:1658
int phaseIdx
Definition: TracerModel.hpp:1660
Scalar concentration
Definition: TracerModel.hpp:1661
int tracerIdx
Definition: TracerModel.hpp:1659
Definition: TracerModel.hpp:1594
const int phaseIdx_
Definition: TracerModel.hpp:1596
void addTracer(const int idx, const TV &concentration)
Definition: TracerModel.hpp:1640
int reorderSkipSteps_
Definition: TracerModel.hpp:1602
bool operator==(const TracerBatch &rhs) const
Definition: TracerModel.hpp:1610
static TracerBatch serializationTestObject()
Definition: TracerModel.hpp:1616
std::vector< TV > concentrationInitial_
Definition: TracerModel.hpp:1597
void serializeOp(Serializer &serializer)
Definition: TracerModel.hpp:1629
TracerBatch(int phaseIdx=0)
Definition: TracerModel.hpp:1635
Scalar solutionDiffusionCoefficient_
Definition: TracerModel.hpp:1606
int numTracer() const
Definition: TracerModel.hpp:1637
std::vector< int > idx_
Definition: TracerModel.hpp:1595
std::unique_ptr< TracerMatrix > mat
Definition: TracerModel.hpp:1601
std::vector< TV > storageOfTimeIndex1_
Definition: TracerModel.hpp:1599
std::vector< TV > residual_
Definition: TracerModel.hpp:1600
Scalar freeDiffusionCoefficient_
Definition: TracerModel.hpp:1605
std::vector< TV > concentration_
Definition: TracerModel.hpp:1598
std::array< std::vector< Scalar >, 2 > dVol_
Definition: TracerModel.hpp:1608
Definition: WellTracerRate.hpp:33
Scalar rate
Definition: WellTracerRate.hpp:35