Skip to content

Commit

Permalink
Fix solution tracers and well output.
Browse files Browse the repository at this point in the history
-Only output or restart solution tracers for gas/oil tracers with DISGAS/VAPOIL enabled (no solution tracers in water phase!).
-Initial tracers (free/solution) will be set to zero initially if TBLK/TVDP is not given.
- Do not calculate mass transfer between free and solution tracers if it is not necessary.
-Calculate well rates using updated tracer concentrations
  • Loading branch information
svenn-t committed Jun 10, 2024
1 parent 61cfcfa commit 84cdef1
Show file tree
Hide file tree
Showing 10 changed files with 243 additions and 104 deletions.
26 changes: 22 additions & 4 deletions opm/simulators/flow/EclWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,10 @@ class EclWriter : public EclGenericWriter<GetPropType<TypeTag, Properties::Grid>
{
const auto& tracers = simulator_.vanguard().eclState().tracer();
for (const auto& tracer : tracers) {
bool enableSolTracer = (tracer.phase == Phase::GAS && FluidSystem::enableDissolvedGas()) ||
(tracer.phase == Phase::OIL && FluidSystem::enableVaporizedOil());
solutionKeys.emplace_back(tracer.fname(), UnitSystem::measure::identity, true);
solutionKeys.emplace_back(tracer.sname(), UnitSystem::measure::identity, true);
solutionKeys.emplace_back(tracer.sname(), UnitSystem::measure::identity, enableSolTracer);
}
}

Expand All @@ -529,14 +531,30 @@ class EclWriter : public EclGenericWriter<GetPropType<TypeTag, Properties::Grid>

auto& tracer_model = simulator_.problem().tracerModel();
for (int tracer_index = 0; tracer_index < tracer_model.numTracers(); tracer_index++) {
// Free tracers
const auto& free_tracer_name = tracer_model.fname(tracer_index);
const auto& free_tracer_solution = restartValues.solution.template data<double>(free_tracer_name);
const auto& sol_tracer_name = tracer_model.sname(tracer_index);
const auto& sol_tracer_solution = restartValues.solution.template data<double>(sol_tracer_name);
for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) {
unsigned globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
tracer_model.setFreeTracerConcentration(tracer_index, globalIdx, free_tracer_solution[globalIdx]);
tracer_model.setSolTracerConcentration(tracer_index, globalIdx, sol_tracer_solution[globalIdx]);
}
// Solution tracer (only if DISGAS/VAPOIL are active for gas/oil tracers)
if ((tracer_model.phase(tracer_index) == Phase::GAS && FluidSystem::enableDissolvedGas()) ||
(tracer_model.phase(tracer_index) == Phase::OIL && FluidSystem::enableVaporizedOil())) {
tracer_model.setEnableSolTracers(tracer_index, true);
const auto& sol_tracer_name = tracer_model.sname(tracer_index);
const auto& sol_tracer_solution = restartValues.solution.template data<double>(sol_tracer_name);
for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) {
unsigned globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
tracer_model.setSolTracerConcentration(tracer_index, globalIdx, sol_tracer_solution[globalIdx]);
}
}
else {
tracer_model.setEnableSolTracers(tracer_index, false);
for (unsigned elemIdx = 0; elemIdx < numElements; ++elemIdx) {
unsigned globalIdx = this->collectOnIORank_.localIdxToGlobalIdx(elemIdx);
tracer_model.setSolTracerConcentration(tracer_index, globalIdx, 0.0);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion opm/simulators/flow/GenericOutputBlackoilModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ assignToSolution(data::Solution& sol)
for (auto tracerIdx = 0*tracers.size();
tracerIdx < tracers.size(); ++tracerIdx)
{
if (solTracerConcentrations_[tracerIdx].empty())
continue;

sol.insert(tracers[tracerIdx].sname(),
UnitSystem::measure::identity,
std::move(solTracerConcentrations_[tracerIdx]),
Expand Down Expand Up @@ -854,6 +857,7 @@ doAllocBuffers(const unsigned bufferSize,
const bool vapparsActive,
const bool enableHysteresis,
const unsigned numTracers,
const std::vector<bool>& enableSolTracers,
const unsigned numOutputNnc)
{
// Output RESTART_OPM_EXTENDED only when explicitly requested by user.
Expand Down Expand Up @@ -1328,7 +1332,8 @@ doAllocBuffers(const unsigned bufferSize,
solTracerConcentrations_.resize(numTracers);
for (unsigned tracerIdx = 0; tracerIdx < numTracers; ++tracerIdx)
{
solTracerConcentrations_[tracerIdx].resize(bufferSize, 0.0);
if (enableSolTracers[tracerIdx])
solTracerConcentrations_[tracerIdx].resize(bufferSize, 0.0);
}
}

Expand Down
1 change: 1 addition & 0 deletions opm/simulators/flow/GenericOutputBlackoilModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class GenericOutputBlackoilModule {
const bool vapparsActive,
const bool enableHysteresis,
unsigned numTracers,
const std::vector<bool>& enableSolTracers,
unsigned numOutputNnc);

void makeRegionSum(Inplace& inplace,
Expand Down
6 changes: 6 additions & 0 deletions opm/simulators/flow/GenericTracerModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

#include <opm/simulators/flow/GenericTracerModel_impl.hpp>

#include <opm/material/fluidsystems/BlackOilFluidSystem.hpp>

#if HAVE_DUNE_FEM
#include <dune/common/version.hh>
#include <dune/fem/gridpart/adaptiveleafgridpart.hh>
Expand All @@ -39,6 +41,7 @@ template class GenericTracerModel<Dune::CpGrid,
Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>,
Dune::MultipleCodimMultipleGeomTypeMapper<Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>>,
Opm::EcfvStencil<double,Dune::GridView<Dune::DefaultLeafGridViewTraits<Dune::CpGrid>>,false,false>,
BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,
double>;

#if HAVE_DUNE_FEM
Expand All @@ -50,12 +53,14 @@ template class GenericTracerModel<Dune::CpGrid,
GV,
Dune::MultipleCodimMultipleGeomTypeMapper<GV>,
EcfvStencil<double, GV, false, false>,
BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,
double>;
#else
template class GenericTracerModel<Dune::CpGrid,
Dune::GridView<Dune::Fem::GridPart2GridViewTraits<Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>>>,
Dune::MultipleCodimMultipleGeomTypeMapper<Dune::GridView<Dune::Fem::GridPart2GridViewTraits<Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>>>>,
EcfvStencil<double,Dune::GridView<Dune::Fem::GridPart2GridViewTraits<Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false>>>,false,false>,
BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,
double>;
template class GenericTracerModel<Dune::CpGrid,
Dune::Fem::GridPart2GridViewImpl<Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, (Dune::PartitionIteratorType)4, false> >,
Expand All @@ -65,6 +70,7 @@ template class GenericTracerModel<Dune::CpGrid,
EcfvStencil<double, Dune::Fem::GridPart2GridViewImpl<
Dune::Fem::AdaptiveLeafGridPart<Dune::CpGrid, Dune::PartitionIteratorType(4), false> >,
false, false>,
BlackOilFluidSystem<double,BlackOilDefaultIndexTraits>,
double>;
#endif
#endif // HAVE_DUNE_FEM
Expand Down
11 changes: 10 additions & 1 deletion opm/simulators/flow/GenericTracerModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include <opm/simulators/linalg/matrixblock.hh>

#include <opm/input/eclipse/EclipseState/Phase.hpp>

#include <array>
#include <cstddef>
#include <functional>
Expand All @@ -49,7 +51,7 @@ namespace Opm {
class EclipseState;
class Well;

template<class Grid, class GridView, class DofMapper, class Stencil, class Scalar>
template<class Grid, class GridView, class DofMapper, class Stencil, class FluidSystem, class Scalar>
class GenericTracerModel {
public:
using TracerVectorSingle = Dune::BlockVector<Dune::FieldVector<Scalar, 1>>;
Expand All @@ -71,6 +73,8 @@ class GenericTracerModel {
std::string wellfname(int tracerIdx) const;
std::string wellsname(int tracerIdx) const;

Phase phase(int tracerIdx) const;
const std::vector<bool>& enableSolTracers() const;

/*!
* \brief Return the tracer concentration for tracer index and global DofIdx
Expand All @@ -79,6 +83,7 @@ class GenericTracerModel {
Scalar solTracerConcentration(int tracerIdx, int globalDofIdx) const;
void setFreeTracerConcentration(int tracerIdx, int globalDofIdx, Scalar value);
void setSolTracerConcentration(int tracerIdx, int globalDofIdx, Scalar value);
void setEnableSolTracers(int tracerIdx, bool enableSolTracer);

/*!
* \brief Return well tracer rates
Expand All @@ -96,9 +101,12 @@ class GenericTracerModel {
void serializeOp(Serializer& serializer)
{
serializer(tracerConcentration_);
serializer(freeTracerConcentration_);
serializer(solTracerConcentration_);
serializer(wellTracerRate_);
serializer(wellFreeTracerRate_);
serializer(wellSolTracerRate_);
serializer(mSwTracerRate_);
}

protected:
Expand Down Expand Up @@ -131,6 +139,7 @@ class GenericTracerModel {
const DofMapper& dofMapper_;

std::vector<int> tracerPhaseIdx_;
std::vector<bool> enableSolTracers_;
std::vector<TracerVector> tracerConcentration_;
std::unique_ptr<TracerMatrix> tracerMatrix_;
std::vector<TracerVectorSingle> freeTracerConcentration_;
Expand Down
Loading

0 comments on commit 84cdef1

Please sign in to comment.