2018-11-14 06:10:01 -06:00
|
|
|
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
// vi: set et ts=4 sw=4 sts=4:
|
|
|
|
/*
|
|
|
|
This file is part of the Open Porous Media project (OPM).
|
|
|
|
|
|
|
|
OPM is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
OPM is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Consult the COPYING file in the top-level source directory of this
|
|
|
|
module for the precise wording of the license and the list of
|
|
|
|
copyright holders.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2019-09-05 10:04:39 -05:00
|
|
|
* \copydoc Opm::EclTracerModel
|
2018-11-14 06:10:01 -06:00
|
|
|
*/
|
|
|
|
#ifndef EWOMS_ECL_TRACER_MODEL_HH
|
|
|
|
#define EWOMS_ECL_TRACER_MODEL_HH
|
2019-02-01 10:33:30 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
#include <ebos/eclgenerictracermodel.hh>
|
2019-02-01 10:33:30 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
#include <opm/models/utils/propertysystem.hh>
|
2019-03-26 07:17:54 -05:00
|
|
|
|
2018-11-14 06:10:01 -06:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
namespace Opm::Properties {
|
2018-12-10 04:13:35 -06:00
|
|
|
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag, class MyTypeTag>
|
|
|
|
struct EnableTracerModel {
|
|
|
|
using type = UndefinedProperty;
|
|
|
|
};
|
2018-12-10 04:13:35 -06:00
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
} // namespace Opm::Properties
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2019-09-05 10:04:39 -05:00
|
|
|
namespace Opm {
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \ingroup EclBlackOilSimulator
|
|
|
|
*
|
2019-02-01 10:33:30 -06:00
|
|
|
* \brief A class which handles tracers as specified in by ECL
|
|
|
|
*
|
|
|
|
* TODO: MPI parallelism.
|
2018-11-14 06:10:01 -06:00
|
|
|
*/
|
|
|
|
template <class TypeTag>
|
2021-05-05 05:13:25 -05:00
|
|
|
class EclTracerModel : public EclGenericTracerModel<GetPropType<TypeTag, Properties::Grid>,
|
|
|
|
GetPropType<TypeTag, Properties::GridView>,
|
|
|
|
GetPropType<TypeTag, Properties::DofMapper>,
|
|
|
|
GetPropType<TypeTag, Properties::Stencil>,
|
|
|
|
GetPropType<TypeTag, Properties::Scalar>>
|
2018-11-14 06:10:01 -06:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
using BaseType = EclGenericTracerModel<GetPropType<TypeTag, Properties::Grid>,
|
|
|
|
GetPropType<TypeTag, Properties::GridView>,
|
|
|
|
GetPropType<TypeTag, Properties::DofMapper>,
|
|
|
|
GetPropType<TypeTag, Properties::Stencil>,
|
|
|
|
GetPropType<TypeTag, Properties::Scalar>>;
|
2020-08-26 03:49:52 -05:00
|
|
|
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
|
|
|
using GridView = GetPropType<TypeTag, Properties::GridView>;
|
|
|
|
using Grid = GetPropType<TypeTag, Properties::Grid>;
|
|
|
|
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
|
|
|
|
using Stencil = GetPropType<TypeTag, Properties::Stencil>;
|
|
|
|
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
|
|
|
|
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
|
|
|
|
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
|
|
|
|
using Indices = GetPropType<TypeTag, Properties::Indices>;
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
using TracerEvaluation = DenseAd::Evaluation<Scalar,1>;
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2020-08-27 02:13:30 -05:00
|
|
|
enum { numEq = getPropValue<TypeTag, Properties::NumEq>() };
|
2018-11-14 06:10:01 -06:00
|
|
|
enum { numPhases = FluidSystem::numPhases };
|
|
|
|
enum { waterPhaseIdx = FluidSystem::waterPhaseIdx };
|
|
|
|
enum { oilPhaseIdx = FluidSystem::oilPhaseIdx };
|
|
|
|
enum { gasPhaseIdx = FluidSystem::gasPhaseIdx };
|
|
|
|
|
|
|
|
public:
|
|
|
|
EclTracerModel(Simulator& simulator)
|
2021-05-05 05:13:25 -05:00
|
|
|
: BaseType(simulator.vanguard().gridView(),
|
|
|
|
simulator.vanguard().eclState(),
|
|
|
|
simulator.vanguard().cartesianIndexMapper(),
|
|
|
|
simulator.model().dofMapper())
|
|
|
|
, simulator_(simulator)
|
2018-11-14 06:10:01 -06:00
|
|
|
{ }
|
|
|
|
|
2018-12-10 04:13:35 -06:00
|
|
|
|
2018-11-14 06:10:01 -06:00
|
|
|
/*!
|
|
|
|
* \brief Initialize all internal data structures needed by the tracer module
|
|
|
|
*/
|
|
|
|
void init()
|
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
bool enabled = EWOMS_GET_PARAM(TypeTag, bool, EnableTracerModel);
|
|
|
|
this->doInit(enabled, simulator_.model().numGridDof(),
|
|
|
|
gasPhaseIdx, oilPhaseIdx, waterPhaseIdx);
|
2018-11-14 06:10:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
void beginTimeStep()
|
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
if (this->numTracers()==0)
|
2018-11-14 06:10:01 -06:00
|
|
|
return;
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
this->tracerConcentrationInitial_ = this->tracerConcentration_;
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
// compute storageCache
|
|
|
|
ElementContext elemCtx(simulator_);
|
|
|
|
auto elemIt = simulator_.gridView().template begin</*codim=*/0>();
|
|
|
|
auto elemEndIt = simulator_.gridView().template end</*codim=*/0>();
|
|
|
|
for (; elemIt != elemEndIt; ++ elemIt) {
|
|
|
|
elemCtx.updateAll(*elemIt);
|
|
|
|
int globalDofIdx = elemCtx.globalSpaceIndex(0, 0);
|
2021-05-05 05:13:25 -05:00
|
|
|
for (int tracerIdx = 0; tracerIdx < this->numTracers(); ++ tracerIdx){
|
2018-11-14 06:10:01 -06:00
|
|
|
Scalar storageOfTimeIndex1;
|
|
|
|
computeStorage_(storageOfTimeIndex1, elemCtx, 0, /*timIdx=*/0, tracerIdx);
|
2021-05-05 05:13:25 -05:00
|
|
|
this->storageOfTimeIndex1_[tracerIdx][globalDofIdx] = storageOfTimeIndex1;
|
2018-11-14 06:10:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Informs the tracer model that a time step has just been finished.
|
|
|
|
*/
|
|
|
|
void endTimeStep()
|
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
if (this->numTracers()==0)
|
2018-11-14 06:10:01 -06:00
|
|
|
return;
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
for (int tracerIdx = 0; tracerIdx < this->numTracers(); ++ tracerIdx){
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
typename BaseType::TracerVector dx(this->tracerResidual_.size());
|
2018-11-14 06:10:01 -06:00
|
|
|
// Newton step (currently the system is linear, converge in one iteration)
|
|
|
|
for (int iter = 0; iter < 5; ++ iter){
|
|
|
|
linearize_(tracerIdx);
|
2021-05-05 05:13:25 -05:00
|
|
|
this->linearSolve_(*this->tracerMatrix_, dx, this->tracerResidual_);
|
|
|
|
this->tracerConcentration_[tracerIdx] -= dx;
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
if (dx.two_norm()<1e-2)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief This method writes the complete state of all tracer
|
|
|
|
* to the hard disk.
|
|
|
|
*/
|
|
|
|
template <class Restarter>
|
2021-05-05 05:13:25 -05:00
|
|
|
void serialize(Restarter&)
|
2019-02-01 10:33:30 -06:00
|
|
|
{ /* not implemented */ }
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief This method restores the complete state of the tracer
|
|
|
|
* from disk.
|
|
|
|
*
|
|
|
|
* It is the inverse of the serialize() method.
|
|
|
|
*/
|
|
|
|
template <class Restarter>
|
2021-05-05 05:13:25 -05:00
|
|
|
void deserialize(Restarter&)
|
2019-02-01 10:33:30 -06:00
|
|
|
{ /* not implemented */ }
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// evaluate storage term for all tracers in a single cell
|
|
|
|
template <class LhsEval>
|
|
|
|
void computeStorage_(LhsEval& tracerStorage,
|
|
|
|
const ElementContext& elemCtx,
|
|
|
|
unsigned scvIdx,
|
|
|
|
unsigned timeIdx,
|
|
|
|
const int tracerIdx)
|
|
|
|
{
|
|
|
|
int globalDofIdx = elemCtx.globalSpaceIndex(scvIdx, timeIdx);
|
|
|
|
|
|
|
|
const auto& intQuants = elemCtx.intensiveQuantities(scvIdx, timeIdx);
|
|
|
|
const auto& fs = intQuants.fluidState();
|
2019-02-01 10:33:30 -06:00
|
|
|
Scalar phaseVolume =
|
2021-05-05 05:13:25 -05:00
|
|
|
decay<Scalar>(fs.saturation(this->tracerPhaseIdx_[tracerIdx]))
|
|
|
|
*decay<Scalar>(fs.invB(this->tracerPhaseIdx_[tracerIdx]))
|
2021-05-05 04:22:44 -05:00
|
|
|
*decay<Scalar>(intQuants.porosity());
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
// avoid singular matrix if no water is present.
|
2021-05-05 04:22:44 -05:00
|
|
|
phaseVolume = max(phaseVolume, 1e-10);
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
if (std::is_same<LhsEval, Scalar>::value)
|
2021-05-05 05:13:25 -05:00
|
|
|
tracerStorage = phaseVolume * this->tracerConcentrationInitial_[tracerIdx][globalDofIdx];
|
2018-11-14 06:10:01 -06:00
|
|
|
else
|
|
|
|
tracerStorage =
|
|
|
|
phaseVolume
|
2021-05-05 05:13:25 -05:00
|
|
|
* variable<LhsEval>(this->tracerConcentration_[tracerIdx][globalDofIdx][0], 0);
|
2018-11-14 06:10:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// evaluate the tracerflux over one face
|
|
|
|
void computeFlux_(TracerEvaluation & tracerFlux,
|
|
|
|
const ElementContext& elemCtx,
|
|
|
|
unsigned scvfIdx,
|
|
|
|
unsigned timeIdx,
|
|
|
|
const int tracerIdx)
|
|
|
|
|
|
|
|
{
|
|
|
|
const auto& stencil = elemCtx.stencil(timeIdx);
|
|
|
|
const auto& scvf = stencil.interiorFace(scvfIdx);
|
|
|
|
|
|
|
|
const auto& extQuants = elemCtx.extensiveQuantities(scvfIdx, timeIdx);
|
|
|
|
unsigned inIdx = extQuants.interiorIndex();
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
const int tracerPhaseIdx = this->tracerPhaseIdx_[tracerIdx];
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
unsigned upIdx = extQuants.upstreamIndex(tracerPhaseIdx);
|
|
|
|
int globalUpIdx = elemCtx.globalSpaceIndex(upIdx, timeIdx);
|
|
|
|
|
|
|
|
const auto& intQuants = elemCtx.intensiveQuantities(upIdx, timeIdx);
|
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
|
|
|
|
Scalar A = scvf.area();
|
2021-05-05 04:22:44 -05:00
|
|
|
Scalar v = decay<Scalar>(extQuants.volumeFlux(tracerPhaseIdx));
|
2021-05-05 05:13:25 -05:00
|
|
|
Scalar b = decay<Scalar>(fs.invB(this->tracerPhaseIdx_[tracerIdx]));
|
|
|
|
Scalar c = this->tracerConcentration_[tracerIdx][globalUpIdx];
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
if (inIdx == upIdx)
|
2021-05-05 04:22:44 -05:00
|
|
|
tracerFlux = A*v*b*variable<TracerEvaluation>(c, 0);
|
2018-11-14 06:10:01 -06:00
|
|
|
else
|
|
|
|
tracerFlux = A*v*b*c;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void linearize_(int tracerIdx)
|
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
(*this->tracerMatrix_) = 0.0;
|
|
|
|
this->tracerResidual_ = 0.0;
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2019-02-01 10:33:30 -06:00
|
|
|
size_t numGridDof = simulator_.model().numGridDof();
|
|
|
|
std::vector<double> volumes(numGridDof, 0.0);
|
2018-11-14 06:10:01 -06:00
|
|
|
ElementContext elemCtx(simulator_);
|
|
|
|
auto elemIt = simulator_.gridView().template begin</*codim=*/0>();
|
|
|
|
auto elemEndIt = simulator_.gridView().template end</*codim=*/0>();
|
|
|
|
for (; elemIt != elemEndIt; ++ elemIt) {
|
|
|
|
elemCtx.updateAll(*elemIt);
|
|
|
|
|
|
|
|
Scalar extrusionFactor =
|
|
|
|
elemCtx.intensiveQuantities(/*dofIdx=*/ 0, /*timeIdx=*/0).extrusionFactor();
|
2021-05-05 04:22:44 -05:00
|
|
|
Valgrind::CheckDefined(extrusionFactor);
|
|
|
|
assert(isfinite(extrusionFactor));
|
2018-11-14 06:10:01 -06:00
|
|
|
assert(extrusionFactor > 0.0);
|
|
|
|
Scalar scvVolume =
|
|
|
|
elemCtx.stencil(/*timeIdx=*/0).subControlVolume(/*dofIdx=*/ 0).volume()
|
|
|
|
* extrusionFactor;
|
|
|
|
Scalar dt = elemCtx.simulator().timeStepSize();
|
|
|
|
|
|
|
|
size_t I = elemCtx.globalSpaceIndex(/*dofIdx=*/ 0, /*timIdx=*/0);
|
|
|
|
volumes[I] = scvVolume;
|
|
|
|
TracerEvaluation localStorage;
|
|
|
|
TracerEvaluation storageOfTimeIndex0;
|
|
|
|
Scalar storageOfTimeIndex1;
|
|
|
|
computeStorage_(storageOfTimeIndex0, elemCtx, 0, /*timIdx=*/0, tracerIdx);
|
|
|
|
if (elemCtx.enableStorageCache())
|
2021-05-05 05:13:25 -05:00
|
|
|
storageOfTimeIndex1 = this->storageOfTimeIndex1_[tracerIdx][I];
|
2018-11-14 06:10:01 -06:00
|
|
|
else
|
|
|
|
computeStorage_(storageOfTimeIndex1, elemCtx, 0, /*timIdx=*/1, tracerIdx);
|
|
|
|
|
|
|
|
localStorage = (storageOfTimeIndex0 - storageOfTimeIndex1) * scvVolume/dt;
|
2021-05-05 05:13:25 -05:00
|
|
|
this->tracerResidual_[I][0] += localStorage.value(); //residual + flux
|
|
|
|
(*this->tracerMatrix_)[I][I][0][0] = localStorage.derivative(0);
|
2018-11-14 06:10:01 -06:00
|
|
|
size_t numInteriorFaces = elemCtx.numInteriorFaces(/*timIdx=*/0);
|
|
|
|
for (unsigned scvfIdx = 0; scvfIdx < numInteriorFaces; scvfIdx++) {
|
|
|
|
TracerEvaluation flux;
|
|
|
|
const auto& face = elemCtx.stencil(0).interiorFace(scvfIdx);
|
|
|
|
unsigned j = face.exteriorIndex();
|
|
|
|
unsigned J = elemCtx.globalSpaceIndex(/*dofIdx=*/ j, /*timIdx=*/0);
|
|
|
|
computeFlux_(flux, elemCtx, scvfIdx, 0, tracerIdx);
|
2021-05-05 05:13:25 -05:00
|
|
|
this->tracerResidual_[I][0] += flux.value(); //residual + flux
|
|
|
|
(*this->tracerMatrix_)[J][I][0][0] = -flux.derivative(0);
|
|
|
|
(*this->tracerMatrix_)[I][J][0][0] = flux.derivative(0);
|
2018-11-14 06:10:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-02-01 10:33:30 -06:00
|
|
|
|
2018-11-14 06:10:01 -06:00
|
|
|
// Wells
|
|
|
|
const int episodeIdx = simulator_.episodeIndex();
|
2019-11-13 16:16:11 -06:00
|
|
|
const auto& wells = simulator_.vanguard().schedule().getWells(episodeIdx);
|
2019-05-02 05:51:25 -05:00
|
|
|
for (const auto& well : wells) {
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2021-05-05 04:22:44 -05:00
|
|
|
if (well.getStatus() == Well::Status::SHUT)
|
2018-11-14 06:10:01 -06:00
|
|
|
continue;
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
const double wtracer = well.getTracerProperties().getConcentration(this->tracerNames_[tracerIdx]);
|
2018-11-14 06:10:01 -06:00
|
|
|
std::array<int, 3> cartesianCoordinate;
|
2019-05-02 05:51:25 -05:00
|
|
|
for (auto& connection : well.getConnections()) {
|
2018-11-14 06:10:01 -06:00
|
|
|
|
2021-05-05 04:22:44 -05:00
|
|
|
if (connection.state() == Connection::State::SHUT)
|
2018-11-14 06:10:01 -06:00
|
|
|
continue;
|
|
|
|
|
2019-02-01 10:33:30 -06:00
|
|
|
cartesianCoordinate[0] = connection.getI();
|
|
|
|
cartesianCoordinate[1] = connection.getJ();
|
|
|
|
cartesianCoordinate[2] = connection.getK();
|
|
|
|
const size_t cartIdx = simulator_.vanguard().cartesianIndex(cartesianCoordinate);
|
2021-05-05 05:13:25 -05:00
|
|
|
const int I = this->cartToGlobal_[cartIdx];
|
|
|
|
Scalar rate = simulator_.problem().wellModel().well(well.name())->volumetricSurfaceRateForConnection(I, this->tracerPhaseIdx_[tracerIdx]);
|
2018-11-14 06:10:01 -06:00
|
|
|
if (rate > 0)
|
2021-05-05 05:13:25 -05:00
|
|
|
this->tracerResidual_[I][0] -= rate*wtracer;
|
2018-11-14 06:10:01 -06:00
|
|
|
else if (rate < 0)
|
2021-05-05 05:13:25 -05:00
|
|
|
this->tracerResidual_[I][0] -= rate*this->tracerConcentration_[tracerIdx][I];
|
2018-11-14 06:10:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Simulator& simulator_;
|
|
|
|
};
|
2021-05-05 05:13:25 -05:00
|
|
|
|
2019-09-05 10:04:39 -05:00
|
|
|
} // namespace Opm
|
2018-11-14 06:10:01 -06:00
|
|
|
|
|
|
|
#endif
|