2019-10-19 13:53:35 -05:00
|
|
|
/*
|
|
|
|
Copyright 2017 SINTEF Digital, Mathematics and Cybernetics.
|
|
|
|
Copyright 2017 Statoil ASA.
|
|
|
|
Copyright 2017 IRIS
|
|
|
|
|
|
|
|
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 3 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
|
|
|
#define OPM_AQUIFERINTERFACE_HEADER_INCLUDED
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
#include <opm/common/utility/numeric/linearInterpolation.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Aquancon.hpp>
|
2019-10-19 13:53:35 -05:00
|
|
|
#include <opm/parser/eclipse/EclipseState/AquiferCT.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Aquifetp.hpp>
|
|
|
|
|
2019-11-28 10:26:58 -06:00
|
|
|
#include <opm/output/data/Aquifer.hpp>
|
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
#include <opm/material/common/MathToolbox.hpp>
|
|
|
|
#include <opm/material/densead/Evaluation.hpp>
|
2019-12-20 07:30:13 -06:00
|
|
|
#include <opm/material/densead/Math.hpp>
|
2019-10-19 13:53:35 -05:00
|
|
|
#include <opm/material/fluidstates/BlackOilFluidState.hpp>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <unordered_map>
|
2019-12-20 07:30:13 -06:00
|
|
|
#include <vector>
|
2019-10-19 13:53:35 -05:00
|
|
|
|
|
|
|
namespace Opm
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
template <typename TypeTag>
|
|
|
|
class AquiferInterface
|
|
|
|
{
|
|
|
|
public:
|
2019-10-19 13:53:35 -05:00
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, ElementContext) ElementContext;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, FluidSystem) FluidSystem;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Indices) BlackoilIndices;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, IntensiveQuantities) IntensiveQuantities;
|
|
|
|
|
|
|
|
enum { enableTemperature = GET_PROP_VALUE(TypeTag, EnableTemperature) };
|
|
|
|
enum { enableEnergy = GET_PROP_VALUE(TypeTag, EnableEnergy) };
|
2020-01-09 08:09:53 -06:00
|
|
|
enum { enableBrine = GET_PROP_VALUE(TypeTag, EnableBrine) };
|
2019-10-19 13:53:35 -05:00
|
|
|
|
|
|
|
static const int numEq = BlackoilIndices::numEq;
|
|
|
|
typedef double Scalar;
|
|
|
|
|
|
|
|
typedef DenseAd::Evaluation<double, /*size=*/numEq> Eval;
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
typedef Opm::BlackOilFluidState<Eval,
|
|
|
|
FluidSystem,
|
|
|
|
enableTemperature,
|
|
|
|
enableEnergy,
|
|
|
|
BlackoilIndices::gasEnabled,
|
2020-01-09 08:09:53 -06:00
|
|
|
enableBrine,
|
2019-12-20 07:30:13 -06:00
|
|
|
BlackoilIndices::numPhases>
|
|
|
|
FluidState;
|
2019-10-19 13:53:35 -05:00
|
|
|
|
|
|
|
static const auto waterCompIdx = FluidSystem::waterCompIdx;
|
|
|
|
static const auto waterPhaseIdx = FluidSystem::waterPhaseIdx;
|
|
|
|
|
|
|
|
// Constructor
|
2020-02-10 10:39:04 -06:00
|
|
|
AquiferInterface(int aqID,
|
|
|
|
const std::vector<Aquancon::AquancCell>& connections,
|
2019-12-20 07:30:13 -06:00
|
|
|
const std::unordered_map<int, int>& cartesian_to_compressed,
|
|
|
|
const Simulator& ebosSimulator)
|
2020-02-10 10:39:04 -06:00
|
|
|
: aquiferID(aqID)
|
|
|
|
, connections_(connections)
|
2019-12-20 07:30:13 -06:00
|
|
|
, ebos_simulator_(ebosSimulator)
|
|
|
|
, cartesian_to_compressed_(cartesian_to_compressed)
|
|
|
|
{
|
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
|
|
|
|
// Deconstructor
|
2019-12-20 07:30:13 -06:00
|
|
|
virtual ~AquiferInterface()
|
|
|
|
{
|
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2019-11-28 10:26:58 -06:00
|
|
|
void initFromRestart(const std::vector<data::AquiferData>& aquiferSoln)
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
auto xaqPos
|
|
|
|
= std::find_if(aquiferSoln.begin(), aquiferSoln.end(), [this](const data::AquiferData& xaq) -> bool {
|
2020-02-10 10:39:04 -06:00
|
|
|
return xaq.aquiferID == this->aquiferID;
|
2019-12-20 07:30:13 -06:00
|
|
|
});
|
|
|
|
|
2020-02-10 10:39:04 -06:00
|
|
|
if (xaqPos == aquiferSoln.end())
|
2019-12-20 07:30:13 -06:00
|
|
|
return;
|
|
|
|
|
|
|
|
this->assignRestartData(*xaqPos);
|
|
|
|
this->W_flux_ = xaqPos->volume;
|
|
|
|
this->pa0_ = xaqPos->initPressure;
|
|
|
|
this->solution_set_from_restart_ = true;
|
2019-11-28 10:26:58 -06:00
|
|
|
}
|
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
void initialSolutionApplied()
|
|
|
|
{
|
2020-02-09 00:43:43 -06:00
|
|
|
initQuantities();
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void beginTimeStep()
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
ElementContext elemCtx(ebos_simulator_);
|
|
|
|
auto elemIt = ebos_simulator_.gridView().template begin<0>();
|
|
|
|
const auto& elemEndIt = ebos_simulator_.gridView().template end<0>();
|
|
|
|
for (; elemIt != elemEndIt; ++elemIt) {
|
|
|
|
const auto& elem = *elemIt;
|
|
|
|
|
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
|
|
|
|
|
|
|
int cellIdx = elemCtx.globalSpaceIndex(0, 0);
|
|
|
|
int idx = cellToConnectionIdx_[cellIdx];
|
|
|
|
if (idx < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
elemCtx.updateIntensiveQuantities(0);
|
|
|
|
const auto& iq = elemCtx.intensiveQuantities(0, 0);
|
|
|
|
pressure_previous_[idx] = Opm::getValue(iq.fluidState().pressure(waterPhaseIdx));
|
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
template <class Context>
|
|
|
|
void addToSource(RateVector& rates, const Context& context, unsigned spaceIdx, unsigned timeIdx)
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
unsigned cellIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
|
|
|
|
|
|
|
|
int idx = cellToConnectionIdx_[cellIdx];
|
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We are dereferencing the value of IntensiveQuantities because cachedIntensiveQuantities return a const
|
|
|
|
// pointer to IntensiveQuantities of that particular cell_id
|
|
|
|
const IntensiveQuantities intQuants = context.intensiveQuantities(spaceIdx, timeIdx);
|
|
|
|
// This is the pressure at td + dt
|
|
|
|
updateCellPressure(pressure_current_, idx, intQuants);
|
|
|
|
updateCellDensity(idx, intQuants);
|
|
|
|
calculateInflowRate(idx, context.simulator());
|
|
|
|
rates[BlackoilIndices::conti0EqIdx + FluidSystem::waterCompIdx]
|
|
|
|
+= Qai_[idx] / context.dofVolume(spaceIdx, timeIdx);
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2020-02-10 10:39:04 -06:00
|
|
|
|
|
|
|
std::size_t size() const {
|
|
|
|
return this->connections_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
protected:
|
2019-10-19 13:53:35 -05:00
|
|
|
inline Scalar gravity_() const
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
return ebos_simulator_.problem().gravity()[2];
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2020-02-09 00:43:43 -06:00
|
|
|
inline void initQuantities()
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
// We reset the cumulative flux at the start of any simulation, so, W_flux = 0
|
|
|
|
if (!this->solution_set_from_restart_) {
|
|
|
|
W_flux_ = 0.;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We next get our connections to the aquifer and initialize these quantities using the initialize_connections
|
|
|
|
// function
|
2020-02-09 00:43:43 -06:00
|
|
|
initializeConnections();
|
2019-12-20 07:30:13 -06:00
|
|
|
calculateAquiferCondition();
|
|
|
|
calculateAquiferConstants();
|
|
|
|
|
2020-02-10 10:39:04 -06:00
|
|
|
pressure_previous_.resize(this->connections_.size(), 0.);
|
|
|
|
pressure_current_.resize(this->connections_.size(), 0.);
|
|
|
|
Qai_.resize(this->connections_.size(), 0.0);
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
inline void
|
|
|
|
updateCellPressure(std::vector<Eval>& pressure_water, const int idx, const IntensiveQuantities& intQuants)
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
pressure_water.at(idx) = fs.pressure(waterPhaseIdx);
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
inline void
|
|
|
|
updateCellPressure(std::vector<Scalar>& pressure_water, const int idx, const IntensiveQuantities& intQuants)
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
pressure_water.at(idx) = fs.pressure(waterPhaseIdx).value();
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void updateCellDensity(const int idx, const IntensiveQuantities& intQuants)
|
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
const auto& fs = intQuants.fluidState();
|
|
|
|
rhow_.at(idx) = fs.density(waterPhaseIdx);
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
template <class faceCellType, class ugridType>
|
|
|
|
inline double getFaceArea(const faceCellType& faceCells,
|
|
|
|
const ugridType& ugrid,
|
|
|
|
const int faceIdx,
|
2020-02-09 00:43:43 -06:00
|
|
|
const int idx) const
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2019-12-20 07:30:13 -06:00
|
|
|
// Check now if the face is outside of the reservoir, or if it adjoins an inactive cell
|
|
|
|
// Do not make the connection if the product of the two cellIdx > 0. This is because the
|
|
|
|
// face is within the reservoir/not connected to boundary. (We still have yet to check for inactive cell
|
|
|
|
// adjoining)
|
|
|
|
double faceArea = 0.;
|
|
|
|
const auto cellNeighbour0 = faceCells(faceIdx, 0);
|
|
|
|
const auto cellNeighbour1 = faceCells(faceIdx, 1);
|
|
|
|
const auto defaultFaceArea = Opm::UgGridHelpers::faceArea(ugrid, faceIdx);
|
|
|
|
const auto calculatedFaceArea
|
2020-02-10 10:39:04 -06:00
|
|
|
= (!this->connections_[idx].influx_coeff.first) ? defaultFaceArea : this->connections_[idx].influx_coeff.second;
|
2019-12-20 07:30:13 -06:00
|
|
|
faceArea = (cellNeighbour0 * cellNeighbour1 > 0) ? 0. : calculatedFaceArea;
|
|
|
|
if (cellNeighbour1 == 0) {
|
|
|
|
faceArea = (cellNeighbour0 < 0) ? faceArea : 0.;
|
|
|
|
} else if (cellNeighbour0 == 0) {
|
|
|
|
faceArea = (cellNeighbour1 < 0) ? faceArea : 0.;
|
|
|
|
}
|
|
|
|
return faceArea;
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void endTimeStep() = 0;
|
|
|
|
|
2020-02-10 10:39:04 -06:00
|
|
|
const int aquiferID;
|
|
|
|
const std::vector<Aquancon::AquancCell> connections_;
|
2019-10-19 13:53:35 -05:00
|
|
|
const Simulator& ebos_simulator_;
|
|
|
|
const std::unordered_map<int, int> cartesian_to_compressed_;
|
|
|
|
|
|
|
|
// Grid variables
|
|
|
|
std::vector<Scalar> faceArea_connected_;
|
|
|
|
std::vector<int> cellToConnectionIdx_;
|
|
|
|
// Quantities at each grid id
|
|
|
|
std::vector<Scalar> cell_depth_;
|
|
|
|
std::vector<Scalar> pressure_previous_;
|
|
|
|
std::vector<Eval> pressure_current_;
|
|
|
|
std::vector<Eval> Qai_;
|
|
|
|
std::vector<Eval> rhow_;
|
|
|
|
std::vector<Scalar> alphai_;
|
|
|
|
|
|
|
|
Scalar Tc_; // Time constant
|
|
|
|
Scalar pa0_; // initial aquifer pressure
|
|
|
|
|
|
|
|
Eval W_flux_;
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
bool solution_set_from_restart_ {false};
|
2019-11-28 10:26:58 -06:00
|
|
|
|
2020-02-09 00:43:43 -06:00
|
|
|
virtual void initializeConnections() = 0;
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2019-11-28 10:26:58 -06:00
|
|
|
virtual void assignRestartData(const data::AquiferData& xaq) = 0;
|
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
virtual void calculateInflowRate(int idx, const Simulator& simulator) = 0;
|
|
|
|
|
|
|
|
virtual void calculateAquiferCondition() = 0;
|
|
|
|
|
|
|
|
virtual void calculateAquiferConstants() = 0;
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
virtual Scalar calculateReservoirEquilibrium() = 0;
|
|
|
|
// This function is used to initialize and calculate the alpha_i for each grid connection to the aquifer
|
|
|
|
};
|
2019-10-19 13:53:35 -05:00
|
|
|
} // namespace Opm
|
|
|
|
#endif
|