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/>.
|
|
|
|
*/
|
|
|
|
|
2022-08-11 02:17:53 -05:00
|
|
|
#ifndef OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
|
|
|
#define OPM_AQUIFERANALYTICAL_HEADER_INCLUDED
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
#include <opm/common/utility/numeric/linearInterpolation.hpp>
|
2019-11-28 10:26:58 -06:00
|
|
|
|
2023-02-02 03:27:48 -06:00
|
|
|
#include <opm/input/eclipse/EclipseState/Aquifer/Aquancon.hpp>
|
2021-09-20 04:12:27 -05:00
|
|
|
|
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>
|
|
|
|
|
2023-02-02 03:27:48 -06:00
|
|
|
#include <opm/models/blackoil/blackoilproperties.hh>
|
|
|
|
#include <opm/models/utils/basicproperties.hh>
|
|
|
|
|
|
|
|
#include <opm/output/data/Aquifer.hpp>
|
|
|
|
|
|
|
|
#include <opm/simulators/aquifers/AquiferInterface.hpp>
|
|
|
|
#include <opm/simulators/utils/DeferredLoggingErrorHelpers.hpp>
|
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
#include <algorithm>
|
2021-06-22 08:39:03 -05:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <limits>
|
|
|
|
#include <numeric>
|
2023-02-02 03:27:48 -06:00
|
|
|
#include <optional>
|
2019-10-19 13:53:35 -05:00
|
|
|
#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>
|
2022-08-11 02:54:15 -05:00
|
|
|
class AquiferAnalytical : public AquiferInterface<TypeTag>
|
2019-12-20 07:30:13 -06:00
|
|
|
{
|
|
|
|
public:
|
2020-08-26 03:49:52 -05:00
|
|
|
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
|
|
|
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
|
|
|
|
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
|
|
|
|
using BlackoilIndices = GetPropType<TypeTag, Properties::Indices>;
|
|
|
|
using RateVector = GetPropType<TypeTag, Properties::RateVector>;
|
|
|
|
using IntensiveQuantities = GetPropType<TypeTag, Properties::IntensiveQuantities>;
|
2020-11-24 07:58:15 -06:00
|
|
|
using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2020-08-27 02:13:30 -05:00
|
|
|
enum { enableTemperature = getPropValue<TypeTag, Properties::EnableTemperature>() };
|
|
|
|
enum { enableEnergy = getPropValue<TypeTag, Properties::EnableEnergy>() };
|
|
|
|
enum { enableBrine = getPropValue<TypeTag, Properties::EnableBrine>() };
|
2021-11-29 09:27:55 -06:00
|
|
|
enum { enableEvaporation = getPropValue<TypeTag, Properties::EnableEvaporation>() };
|
2022-11-24 07:32:41 -06:00
|
|
|
enum { has_disgas_in_water = getPropValue<TypeTag, Properties::EnableDisgasInWater>() };
|
|
|
|
|
2021-11-29 09:27:55 -06:00
|
|
|
enum { enableSaltPrecipitation = getPropValue<TypeTag, Properties::EnableSaltPrecipitation>() };
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2022-08-10 07:27:34 -05:00
|
|
|
static constexpr int numEq = BlackoilIndices::numEq;
|
|
|
|
using Scalar = double;
|
|
|
|
|
|
|
|
using Eval = DenseAd::Evaluation<double, /*size=*/numEq>;
|
|
|
|
|
|
|
|
using FluidState = BlackOilFluidState<Eval,
|
|
|
|
FluidSystem,
|
|
|
|
enableTemperature,
|
|
|
|
enableEnergy,
|
|
|
|
BlackoilIndices::gasEnabled,
|
|
|
|
enableEvaporation,
|
|
|
|
enableBrine,
|
|
|
|
enableSaltPrecipitation,
|
2022-11-24 07:32:41 -06:00
|
|
|
has_disgas_in_water,
|
2022-08-10 07:27:34 -05:00
|
|
|
BlackoilIndices::numPhases>;
|
2019-10-19 13:53:35 -05:00
|
|
|
|
|
|
|
// Constructor
|
2023-03-31 04:47:58 -05:00
|
|
|
AquiferAnalytical(const int aqID,
|
|
|
|
const std::vector<Aquancon::AquancCell>& connections,
|
|
|
|
const Simulator& ebosSimulator)
|
2022-08-11 02:54:15 -05:00
|
|
|
: AquiferInterface<TypeTag>(aqID, ebosSimulator)
|
2020-02-10 10:39:04 -06:00
|
|
|
, connections_(connections)
|
2019-12-20 07:30:13 -06:00
|
|
|
{
|
2023-03-31 04:47:58 -05:00
|
|
|
this->initializeConnectionMappings();
|
2019-12-20 07:30:13 -06:00
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2021-05-12 05:16:20 -05:00
|
|
|
// Destructor
|
2022-08-11 02:17:53 -05:00
|
|
|
virtual ~AquiferAnalytical()
|
2023-03-31 04:47:58 -05:00
|
|
|
{}
|
|
|
|
|
|
|
|
void computeFaceAreaFraction(const std::vector<double>& total_face_area) override
|
|
|
|
{
|
|
|
|
assert (total_face_area.size() >= static_cast<std::vector<double>::size_type>(this->aquiferID()));
|
|
|
|
|
|
|
|
const auto tfa = total_face_area[this->aquiferID() - 1];
|
|
|
|
const auto eps_sqrt = std::sqrt(std::numeric_limits<double>::epsilon());
|
|
|
|
|
|
|
|
if (tfa < eps_sqrt) {
|
|
|
|
this->alphai_.assign(this->size(), Scalar{0});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
std::transform(this->faceArea_connected_.begin(),
|
|
|
|
this->faceArea_connected_.end(),
|
|
|
|
this->alphai_.begin(),
|
|
|
|
[tfa](const Scalar area)
|
|
|
|
{
|
|
|
|
return area / tfa;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
this->area_fraction_ = this->totalFaceArea() / tfa;
|
|
|
|
}
|
|
|
|
|
|
|
|
double totalFaceArea() const override
|
2019-12-20 07:30:13 -06:00
|
|
|
{
|
2023-03-31 04:47:58 -05:00
|
|
|
return this->total_face_area_;
|
2019-12-20 07:30:13 -06:00
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
void initFromRestart(const data::Aquifers& aquiferSoln) override
|
2019-11-28 10:26:58 -06:00
|
|
|
{
|
2021-05-12 10:12:03 -05:00
|
|
|
auto xaqPos = aquiferSoln.find(this->aquiferID());
|
2020-02-10 10:39:04 -06:00
|
|
|
if (xaqPos == aquiferSoln.end())
|
2019-12-20 07:30:13 -06:00
|
|
|
return;
|
|
|
|
|
2021-05-12 10:12:03 -05:00
|
|
|
this->assignRestartData(xaqPos->second);
|
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
this->W_flux_ = xaqPos->second.volume * this->area_fraction_;
|
2021-05-12 10:12:03 -05:00
|
|
|
this->pa0_ = xaqPos->second.initPressure;
|
2023-03-31 04:47:58 -05:00
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
this->solution_set_from_restart_ = true;
|
2019-11-28 10:26:58 -06:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
void initialSolutionApplied() override
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2020-02-09 00:43:43 -06:00
|
|
|
initQuantities();
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
void beginTimeStep() override
|
2019-10-19 13:53:35 -05:00
|
|
|
{
|
2022-08-11 02:54:15 -05:00
|
|
|
ElementContext elemCtx(this->ebos_simulator_);
|
2021-09-20 04:12:27 -05:00
|
|
|
OPM_BEGIN_PARALLEL_TRY_CATCH();
|
|
|
|
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(this->ebos_simulator_.gridView())) {
|
2019-12-20 07:30:13 -06:00
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
|
|
|
|
2021-05-12 05:16:20 -05:00
|
|
|
const int cellIdx = elemCtx.globalSpaceIndex(0, 0);
|
|
|
|
const int idx = cellToConnectionIdx_[cellIdx];
|
2019-12-20 07:30:13 -06:00
|
|
|
if (idx < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
elemCtx.updateIntensiveQuantities(0);
|
|
|
|
const auto& iq = elemCtx.intensiveQuantities(0, 0);
|
2022-08-11 02:54:15 -05:00
|
|
|
pressure_previous_[idx] = getValue(iq.fluidState().pressure(this->phaseIdx_()));
|
2019-12-20 07:30:13 -06:00
|
|
|
}
|
2021-05-25 05:57:11 -05:00
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
OPM_END_PARALLEL_TRY_CATCH("AquiferAnalytical::beginTimeStep() failed: ",
|
|
|
|
this->ebos_simulator_.vanguard().grid().comm());
|
2022-07-01 08:36:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void addToSource(RateVector& rates,
|
|
|
|
const unsigned cellIdx,
|
2022-08-11 02:54:15 -05:00
|
|
|
const unsigned timeIdx) override
|
2022-07-01 08:36:32 -05:00
|
|
|
{
|
2022-08-11 02:54:15 -05:00
|
|
|
const auto& model = this->ebos_simulator_.model();
|
2019-12-20 07:30:13 -06:00
|
|
|
|
2021-05-12 05:16:20 -05:00
|
|
|
const int idx = this->cellToConnectionIdx_[cellIdx];
|
2019-12-20 07:30:13 -06:00
|
|
|
if (idx < 0)
|
|
|
|
return;
|
|
|
|
|
2023-03-28 02:37:00 -05:00
|
|
|
const auto& intQuants = model.intensiveQuantities(cellIdx, timeIdx);
|
2021-05-12 05:16:20 -05:00
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
// This is the pressure at td + dt
|
2023-03-28 02:37:00 -05:00
|
|
|
this->updateCellPressure(this->pressure_current_, idx, intQuants);
|
2022-08-11 02:54:15 -05:00
|
|
|
this->calculateInflowRate(idx, this->ebos_simulator_);
|
2021-05-12 05:16:20 -05:00
|
|
|
|
2021-09-17 08:26:46 -05:00
|
|
|
rates[BlackoilIndices::conti0EqIdx + compIdx_()]
|
2022-07-01 08:36:32 -05:00
|
|
|
+= this->Qai_[idx] / model.dofTotalVolume(cellIdx);
|
2022-08-29 03:59:20 -05:00
|
|
|
|
|
|
|
if constexpr (enableEnergy) {
|
2023-03-28 02:37:00 -05:00
|
|
|
auto fs = intQuants.fluidState();
|
2022-08-29 03:59:20 -05:00
|
|
|
if (this->Ta0_.has_value() && this->Qai_[idx] > 0)
|
|
|
|
{
|
|
|
|
fs.setTemperature(this->Ta0_.value());
|
|
|
|
typedef typename std::decay<decltype(fs)>::type::Scalar FsScalar;
|
|
|
|
typename FluidSystem::template ParameterCache<FsScalar> paramCache;
|
2023-03-28 02:37:00 -05:00
|
|
|
const unsigned pvtRegionIdx = intQuants.pvtRegionIndex();
|
2022-08-29 03:59:20 -05:00
|
|
|
paramCache.setRegionIndex(pvtRegionIdx);
|
|
|
|
paramCache.setMaxOilSat(this->ebos_simulator_.problem().maxOilSaturation(cellIdx));
|
|
|
|
paramCache.updatePhase(fs, this->phaseIdx_());
|
|
|
|
const auto& h = FluidSystem::enthalpy(fs, paramCache, this->phaseIdx_());
|
|
|
|
fs.setEnthalpy(this->phaseIdx_(), h);
|
|
|
|
}
|
|
|
|
rates[BlackoilIndices::contiEnergyEqIdx]
|
2023-03-28 02:37:00 -05:00
|
|
|
+= this->Qai_[idx] *fs.enthalpy(this->phaseIdx_()) * FluidSystem::referenceDensity( this->phaseIdx_(), intQuants.pvtRegionIndex()) / model.dofTotalVolume(cellIdx);
|
2022-08-29 03:59:20 -05:00
|
|
|
|
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
2022-08-11 02:54:15 -05:00
|
|
|
|
|
|
|
std::size_t size() const
|
|
|
|
{
|
2020-02-10 10:39:04 -06:00
|
|
|
return this->connections_.size();
|
|
|
|
}
|
|
|
|
|
2023-02-02 03:27:48 -06:00
|
|
|
template<class Serializer>
|
|
|
|
void serializeOp(Serializer& serializer)
|
|
|
|
{
|
|
|
|
serializer(pressure_previous_);
|
|
|
|
serializer(pressure_current_);
|
|
|
|
serializer(Qai_);
|
|
|
|
serializer(rhow_);
|
|
|
|
serializer(W_flux_);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const AquiferAnalytical& rhs) const
|
|
|
|
{
|
|
|
|
return this->pressure_previous_ == rhs.pressure_previous_ &&
|
|
|
|
this->pressure_current_ == rhs.pressure_current_ &&
|
|
|
|
this->Qai_ == rhs.Qai_ &&
|
|
|
|
this->rhow_ == rhs.rhow_ &&
|
|
|
|
this->W_flux_ == rhs.W_flux_;
|
|
|
|
}
|
|
|
|
|
2019-12-20 07:30:13 -06:00
|
|
|
protected:
|
2022-08-11 02:54:15 -05:00
|
|
|
virtual void assignRestartData(const data::AquiferData& xaq) = 0;
|
|
|
|
virtual void calculateInflowRate(int idx, const Simulator& simulator) = 0;
|
|
|
|
virtual void calculateAquiferCondition() = 0;
|
|
|
|
virtual void calculateAquiferConstants() = 0;
|
|
|
|
virtual Scalar aquiferDepth() const = 0;
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
Scalar gravity_() const
|
2021-09-17 08:26:46 -05:00
|
|
|
{
|
2022-08-11 02:54:15 -05:00
|
|
|
return this->ebos_simulator_.problem().gravity()[2];
|
2021-09-17 08:26:46 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
int compIdx_() const
|
2021-09-17 08:26:46 -05:00
|
|
|
{
|
2022-08-11 02:54:15 -05:00
|
|
|
if (this->co2store_())
|
2021-09-17 08:26:46 -05:00
|
|
|
return FluidSystem::oilCompIdx;
|
|
|
|
|
|
|
|
return FluidSystem::waterCompIdx;
|
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
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
|
2023-03-31 04:47:58 -05:00
|
|
|
if (! this->solution_set_from_restart_) {
|
2021-06-22 08:39:03 -05:00
|
|
|
W_flux_ = Scalar{0};
|
2019-12-20 07:30:13 -06:00
|
|
|
}
|
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
this->initializeConnectionDepths();
|
|
|
|
this->calculateAquiferCondition();
|
|
|
|
this->calculateAquiferConstants();
|
2019-12-20 07:30:13 -06:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
this->pressure_previous_.resize(this->size(), Scalar{0});
|
|
|
|
this->pressure_current_.resize(this->size(), Scalar{0});
|
|
|
|
this->Qai_.resize(this->size(), Scalar{0});
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
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();
|
2022-08-11 02:54:15 -05:00
|
|
|
pressure_water.at(idx) = fs.pressure(this->phaseIdx_());
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
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();
|
2022-08-11 02:54:15 -05:00
|
|
|
pressure_water.at(idx) = fs.pressure(this->phaseIdx_()).value();
|
2019-10-19 13:53:35 -05:00
|
|
|
}
|
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
void initializeConnectionMappings()
|
2020-12-15 02:43:43 -06:00
|
|
|
{
|
|
|
|
this->alphai_.resize(this->size(), 1.0);
|
2021-06-22 08:39:03 -05:00
|
|
|
this->faceArea_connected_.resize(this->size(), Scalar{0});
|
2020-12-15 02:43:43 -06:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
// total_face_area_ is the sum of the areas connected to an aquifer
|
|
|
|
this->total_face_area_ = Scalar{0};
|
2020-12-15 02:43:43 -06:00
|
|
|
this->cellToConnectionIdx_.resize(this->ebos_simulator_.gridView().size(/*codim=*/0), -1);
|
2020-12-17 06:19:18 -06:00
|
|
|
const auto& gridView = this->ebos_simulator_.vanguard().gridView();
|
2021-06-22 08:39:03 -05:00
|
|
|
for (std::size_t idx = 0; idx < this->size(); ++idx) {
|
2020-12-15 02:43:43 -06:00
|
|
|
const auto global_index = this->connections_[idx].global_index;
|
|
|
|
const int cell_index = this->ebos_simulator_.vanguard().compressedIndex(global_index);
|
2023-03-31 04:47:58 -05:00
|
|
|
if (cell_index < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-12-17 06:19:18 -06:00
|
|
|
auto elemIt = gridView.template begin</*codim=*/ 0>();
|
2023-03-31 04:47:58 -05:00
|
|
|
std::advance(elemIt, cell_index);
|
2020-12-17 06:19:18 -06:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
// The global_index is not part of this grid
|
|
|
|
if (elemIt->partitionType() != Dune::InteriorEntity) {
|
2020-12-15 02:43:43 -06:00
|
|
|
continue;
|
2023-03-31 04:47:58 -05:00
|
|
|
}
|
2021-06-22 08:39:03 -05:00
|
|
|
|
2020-12-15 02:43:43 -06:00
|
|
|
this->cellToConnectionIdx_[cell_index] = idx;
|
|
|
|
}
|
2023-03-31 04:47:58 -05:00
|
|
|
|
|
|
|
// Translate the C face tag into the enum used by opm-parser's TransMult class
|
|
|
|
FaceDir::DirEnum faceDirection;
|
|
|
|
|
|
|
|
// Get areas for all connections
|
|
|
|
const auto& elemMapper = this->ebos_simulator_.model().dofMapper();
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(gridView)) {
|
2023-03-31 04:47:58 -05:00
|
|
|
const unsigned cell_index = elemMapper.index(elem);
|
|
|
|
const int idx = this->cellToConnectionIdx_[cell_index];
|
2020-12-15 02:43:43 -06:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
// Only deal with connections given by the aquifer
|
|
|
|
if (idx < 0) {
|
2020-12-15 02:43:43 -06:00
|
|
|
continue;
|
2023-03-31 04:47:58 -05:00
|
|
|
}
|
2020-12-15 02:43:43 -06:00
|
|
|
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& intersection : intersections(gridView, elem)) {
|
2023-03-31 04:47:58 -05:00
|
|
|
// Only deal with grid boundaries
|
|
|
|
if (! intersection.boundary()) {
|
2020-12-15 02:43:43 -06:00
|
|
|
continue;
|
2023-03-31 04:47:58 -05:00
|
|
|
}
|
2020-12-15 02:43:43 -06:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
switch (intersection.indexInInside()) {
|
2020-12-15 02:43:43 -06:00
|
|
|
case 0:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::XMinus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
case 1:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::XPlus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
case 2:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::YMinus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
case 3:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::YPlus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
case 4:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::ZMinus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
case 5:
|
2021-05-05 04:22:44 -05:00
|
|
|
faceDirection = FaceDir::ZPlus;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
OPM_THROW(std::logic_error,
|
2023-03-31 04:47:58 -05:00
|
|
|
"Internal error in initialization of aquifer.");
|
2020-12-15 02:43:43 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if (faceDirection == this->connections_[idx].face_dir) {
|
2021-02-14 13:47:22 -06:00
|
|
|
this->faceArea_connected_[idx] = this->connections_[idx].influx_coeff;
|
2020-12-15 02:43:43 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-06-22 08:39:03 -05:00
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
this->total_face_area_ += this->faceArea_connected_.at(idx);
|
2021-06-22 08:39:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
void initializeConnectionDepths()
|
2021-06-22 08:39:03 -05:00
|
|
|
{
|
2023-03-31 04:47:58 -05:00
|
|
|
this->cell_depth_.resize(this->size(), this->aquiferDepth());
|
|
|
|
|
|
|
|
const auto& gridView = this->ebos_simulator_.vanguard().gridView();
|
|
|
|
for (std::size_t idx = 0; idx < this->size(); ++idx) {
|
|
|
|
const int cell_index = this->ebos_simulator_.vanguard()
|
|
|
|
.compressedIndex(this->connections_[idx].global_index);
|
|
|
|
if (cell_index < 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto elemIt = gridView.template begin</*codim=*/ 0>();
|
|
|
|
std::advance(elemIt, cell_index);
|
|
|
|
|
|
|
|
// The global_index is not part of this grid
|
|
|
|
if (elemIt->partitionType() != Dune::InteriorEntity) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->cell_depth_.at(idx) = this->ebos_simulator_.vanguard().cellCenterDepth(cell_index);
|
|
|
|
}
|
2020-12-15 02:43:43 -06:00
|
|
|
}
|
2019-10-19 13:53:35 -05:00
|
|
|
|
2020-09-24 09:09:56 -05:00
|
|
|
// This function is for calculating the aquifer properties from equilibrium state with the reservoir
|
2022-08-11 02:54:15 -05:00
|
|
|
Scalar calculateReservoirEquilibrium()
|
2020-09-24 09:09:56 -05:00
|
|
|
{
|
|
|
|
// Since the global_indices are the reservoir index, we just need to extract the fluidstate at those indices
|
|
|
|
std::vector<Scalar> pw_aquifer;
|
|
|
|
Scalar water_pressure_reservoir;
|
|
|
|
|
|
|
|
ElementContext elemCtx(this->ebos_simulator_);
|
|
|
|
const auto& gridView = this->ebos_simulator_.gridView();
|
2022-10-12 07:27:20 -05:00
|
|
|
for (const auto& elem : elements(gridView)) {
|
2020-09-24 09:09:56 -05:00
|
|
|
elemCtx.updatePrimaryStencil(elem);
|
|
|
|
|
2021-05-12 05:16:20 -05:00
|
|
|
const auto cellIdx = elemCtx.globalSpaceIndex(/*spaceIdx=*/0, /*timeIdx=*/0);
|
|
|
|
const auto idx = this->cellToConnectionIdx_[cellIdx];
|
2020-09-24 09:09:56 -05:00
|
|
|
if (idx < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
|
|
|
|
const auto& iq0 = elemCtx.intensiveQuantities(/*spaceIdx=*/0, /*timeIdx=*/0);
|
|
|
|
const auto& fs = iq0.fluidState();
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
water_pressure_reservoir = fs.pressure(this->phaseIdx_()).value();
|
|
|
|
const auto water_density = fs.density(this->phaseIdx_());
|
2021-05-12 17:37:10 -05:00
|
|
|
|
|
|
|
const auto gdz =
|
|
|
|
this->gravity_() * (this->cell_depth_[idx] - this->aquiferDepth());
|
|
|
|
|
|
|
|
pw_aquifer.push_back(this->alphai_[idx] *
|
|
|
|
(water_pressure_reservoir - water_density.value()*gdz));
|
2020-09-24 09:09:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// We take the average of the calculated equilibrium pressures.
|
2022-08-11 02:54:15 -05:00
|
|
|
const auto& comm = this->ebos_simulator_.vanguard().grid().comm();
|
2021-05-12 05:16:20 -05:00
|
|
|
|
2020-12-15 02:01:03 -06:00
|
|
|
Scalar vals[2];
|
2021-06-22 08:39:03 -05:00
|
|
|
vals[0] = std::accumulate(this->alphai_.begin(), this->alphai_.end(), Scalar{0});
|
|
|
|
vals[1] = std::accumulate(pw_aquifer.begin(), pw_aquifer.end(), Scalar{0});
|
2021-05-12 05:16:20 -05:00
|
|
|
|
2020-12-15 02:01:03 -06:00
|
|
|
comm.sum(vals, 2);
|
2021-05-12 05:16:20 -05:00
|
|
|
|
2020-12-15 02:01:03 -06:00
|
|
|
return vals[1] / vals[0];
|
2020-09-24 09:09:56 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
const std::vector<Aquancon::AquancCell> connections_;
|
|
|
|
|
|
|
|
// 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<Scalar> alphai_;
|
|
|
|
|
|
|
|
Scalar Tc_{}; // Time constant
|
|
|
|
Scalar pa0_{}; // initial aquifer pressure
|
2022-08-29 03:59:20 -05:00
|
|
|
std::optional<Scalar> Ta0_{}; // initial aquifer temperature
|
2022-08-11 02:54:15 -05:00
|
|
|
Scalar rhow_{};
|
|
|
|
|
2023-03-31 04:47:58 -05:00
|
|
|
Scalar total_face_area_{};
|
|
|
|
Scalar area_fraction_{Scalar{1}};
|
|
|
|
|
2022-08-11 02:54:15 -05:00
|
|
|
Eval W_flux_;
|
|
|
|
|
|
|
|
bool solution_set_from_restart_ {false};
|
2023-03-31 04:47:58 -05:00
|
|
|
bool has_active_connection_on_proc_{false};
|
2019-12-20 07:30:13 -06:00
|
|
|
};
|
2022-08-11 02:17:53 -05:00
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
} // namespace Opm
|
2022-08-11 02:17:53 -05:00
|
|
|
|
2019-10-19 13:53:35 -05:00
|
|
|
#endif
|