Rename ebos_simulator members/parameters to simulator

This commit is contained in:
Arne Morten Kvarving 2024-02-06 11:55:07 +01:00
parent 339cc29f47
commit 3475da7d8c
20 changed files with 559 additions and 544 deletions

View File

@ -88,8 +88,8 @@ public:
// Constructor
AquiferAnalytical(const int aqID,
const std::vector<Aquancon::AquancCell>& connections,
const Simulator& ebosSimulator)
: AquiferInterface<TypeTag>(aqID, ebosSimulator)
const Simulator& simulator)
: AquiferInterface<TypeTag>(aqID, simulator)
, connections_(connections)
{
this->initializeConnectionMappings();
@ -148,10 +148,10 @@ public:
void beginTimeStep() override
{
ElementContext elemCtx(this->ebos_simulator_);
ElementContext elemCtx(this->simulator_);
OPM_BEGIN_PARALLEL_TRY_CATCH();
for (const auto& elem : elements(this->ebos_simulator_.gridView())) {
for (const auto& elem : elements(this->simulator_.gridView())) {
elemCtx.updatePrimaryStencil(elem);
const int cellIdx = elemCtx.globalSpaceIndex(0, 0);
@ -165,14 +165,14 @@ public:
}
OPM_END_PARALLEL_TRY_CATCH("AquiferAnalytical::beginTimeStep() failed: ",
this->ebos_simulator_.vanguard().grid().comm());
this->simulator_.vanguard().grid().comm());
}
void addToSource(RateVector& rates,
const unsigned cellIdx,
const unsigned timeIdx) override
{
const auto& model = this->ebos_simulator_.model();
const auto& model = this->simulator_.model();
const int idx = this->cellToConnectionIdx_[cellIdx];
if (idx < 0)
@ -182,7 +182,7 @@ public:
// This is the pressure at td + dt
this->updateCellPressure(this->pressure_current_, idx, intQuants);
this->calculateInflowRate(idx, this->ebos_simulator_);
this->calculateInflowRate(idx, this->simulator_);
rates[BlackoilIndices::conti0EqIdx + compIdx_()]
+= this->Qai_[idx] / model.dofTotalVolume(cellIdx);
@ -196,7 +196,7 @@ public:
typename FluidSystem::template ParameterCache<FsScalar> paramCache;
const unsigned pvtRegionIdx = intQuants.pvtRegionIndex();
paramCache.setRegionIndex(pvtRegionIdx);
paramCache.setMaxOilSat(this->ebos_simulator_.problem().maxOilSaturation(cellIdx));
paramCache.setMaxOilSat(this->simulator_.problem().maxOilSaturation(cellIdx));
paramCache.updatePhase(fs, this->phaseIdx_());
const auto& h = FluidSystem::enthalpy(fs, paramCache, this->phaseIdx_());
fs.setEnthalpy(this->phaseIdx_(), h);
@ -240,7 +240,7 @@ protected:
Scalar gravity_() const
{
return this->ebos_simulator_.problem().gravity()[2];
return this->simulator_.problem().gravity()[2];
}
int compIdx_() const
@ -290,11 +290,11 @@ protected:
// total_face_area_ is the sum of the areas connected to an aquifer
this->total_face_area_ = Scalar{0};
this->cellToConnectionIdx_.resize(this->ebos_simulator_.gridView().size(/*codim=*/0), -1);
const auto& gridView = this->ebos_simulator_.vanguard().gridView();
this->cellToConnectionIdx_.resize(this->simulator_.gridView().size(/*codim=*/0), -1);
const auto& gridView = this->simulator_.vanguard().gridView();
for (std::size_t idx = 0; idx < this->size(); ++idx) {
const auto global_index = this->connections_[idx].global_index;
const int cell_index = this->ebos_simulator_.vanguard().compressedIndex(global_index);
const int cell_index = this->simulator_.vanguard().compressedIndex(global_index);
if (cell_index < 0) {
continue;
}
@ -314,7 +314,7 @@ protected:
FaceDir::DirEnum faceDirection;
// Get areas for all connections
const auto& elemMapper = this->ebos_simulator_.model().dofMapper();
const auto& elemMapper = this->simulator_.model().dofMapper();
for (const auto& elem : elements(gridView)) {
const unsigned cell_index = elemMapper.index(elem);
const int idx = this->cellToConnectionIdx_[cell_index];
@ -368,9 +368,9 @@ protected:
{
this->cell_depth_.resize(this->size(), this->aquiferDepth());
const auto& gridView = this->ebos_simulator_.vanguard().gridView();
const auto& gridView = this->simulator_.vanguard().gridView();
for (std::size_t idx = 0; idx < this->size(); ++idx) {
const int cell_index = this->ebos_simulator_.vanguard()
const int cell_index = this->simulator_.vanguard()
.compressedIndex(this->connections_[idx].global_index);
if (cell_index < 0) {
continue;
@ -384,7 +384,7 @@ protected:
continue;
}
this->cell_depth_.at(idx) = this->ebos_simulator_.vanguard().cellCenterDepth(cell_index);
this->cell_depth_.at(idx) = this->simulator_.vanguard().cellCenterDepth(cell_index);
}
}
@ -395,8 +395,8 @@ protected:
std::vector<Scalar> pw_aquifer;
Scalar water_pressure_reservoir;
ElementContext elemCtx(this->ebos_simulator_);
const auto& gridView = this->ebos_simulator_.gridView();
ElementContext elemCtx(this->simulator_);
const auto& gridView = this->simulator_.gridView();
for (const auto& elem : elements(gridView)) {
elemCtx.updatePrimaryStencil(elem);
@ -420,7 +420,7 @@ protected:
}
// We take the average of the calculated equilibrium pressures.
const auto& comm = this->ebos_simulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
Scalar vals[2];
vals[0] = std::accumulate(this->alphai_.begin(), this->alphai_.end(), Scalar{0});

View File

@ -55,15 +55,15 @@ public:
using typename Base::ElementMapper;
AquiferCarterTracy(const std::vector<Aquancon::AquancCell>& connections,
const Simulator& ebosSimulator,
const Simulator& simulator,
const AquiferCT::AQUCT_data& aquct_data)
: Base(aquct_data.aquiferID, connections, ebosSimulator)
: Base(aquct_data.aquiferID, connections, simulator)
, aquct_data_(aquct_data)
{}
static AquiferCarterTracy serializationTestObject(const Simulator& ebosSimulator)
static AquiferCarterTracy serializationTestObject(const Simulator& simulator)
{
AquiferCarterTracy result({}, ebosSimulator, {});
AquiferCarterTracy result({}, simulator, {});
result.pressure_previous_ = {1.0, 2.0, 3.0};
result.pressure_current_ = {4.0, 5.0};
@ -80,10 +80,10 @@ public:
void endTimeStep() override
{
for (const auto& q : this->Qai_) {
this->W_flux_ += q * this->ebos_simulator_.timeStepSize();
this->W_flux_ += q * this->simulator_.timeStepSize();
}
this->fluxValue_ = this->W_flux_.value();
const auto& comm = this->ebos_simulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
comm.sum(&this->fluxValue_, 1);
}
@ -236,7 +236,7 @@ protected:
this->aquct_data_.initial_pressure =
this->calculateReservoirEquilibrium();
const auto& tables = this->ebos_simulator_.vanguard()
const auto& tables = this->simulator_.vanguard()
.eclState().getTableManager();
this->aquct_data_.finishInitialisation(tables);

View File

@ -48,9 +48,9 @@ public:
using Eval = DenseAd::Evaluation<double, /*size=*/numEq>;
AquiferConstantFlux(const std::vector<Aquancon::AquancCell>& connections,
const Simulator& ebos_simulator,
const Simulator& simulator,
const SingleAquiferFlux& aquifer)
: AquiferInterface<TypeTag>(aquifer.id, ebos_simulator)
: AquiferInterface<TypeTag>(aquifer.id, simulator)
, connections_ (connections)
, aquifer_data_ (aquifer)
, connection_flux_ (connections_.size(), Eval{0})
@ -58,9 +58,9 @@ public:
this->total_face_area_ = this->initializeConnections();
}
static AquiferConstantFlux serializationTestObject(const Simulator& ebos_simulator)
static AquiferConstantFlux serializationTestObject(const Simulator& simulator)
{
AquiferConstantFlux<TypeTag> result({}, ebos_simulator, {});
AquiferConstantFlux<TypeTag> result({}, simulator, {});
result.cumulative_flux_ = 1.0;
return result;
@ -106,7 +106,7 @@ public:
{
this->flux_rate_ = this->totalFluxRate();
this->cumulative_flux_ +=
this->flux_rate_ * this->ebos_simulator_.timeStepSize();
this->flux_rate_ * this->simulator_.timeStepSize();
}
data::AquiferData aquiferData() const override
@ -136,7 +136,7 @@ public:
return;
}
const auto& model = this->ebos_simulator_.model();
const auto& model = this->simulator_.model();
const auto fw = this->aquifer_data_.flux;
@ -173,11 +173,11 @@ private:
auto connected_face_area = 0.0;
this->cellToConnectionIdx_
.resize(this->ebos_simulator_.gridView().size(/*codim=*/0), -1);
.resize(this->simulator_.gridView().size(/*codim=*/0), -1);
for (std::size_t idx = 0; idx < this->connections_.size(); ++idx) {
const auto global_index = this->connections_[idx].global_index;
const int cell_index = this->ebos_simulator_.vanguard()
const int cell_index = this->simulator_.vanguard()
.compressedIndexForInterior(global_index);
if (cell_index < 0) {
@ -198,7 +198,7 @@ private:
double computeFaceAreaFraction(const double connected_face_area) const
{
const auto tot_face_area = this->ebos_simulator_.vanguard()
const auto tot_face_area = this->simulator_.vanguard()
.grid().comm().sum(connected_face_area);
return (tot_face_area > 0.0)

View File

@ -52,16 +52,16 @@ public:
using typename Base::ElementMapper;
AquiferFetkovich(const std::vector<Aquancon::AquancCell>& connections,
const Simulator& ebosSimulator,
const Simulator& simulator,
const Aquifetp::AQUFETP_data& aqufetp_data)
: Base(aqufetp_data.aquiferID, connections, ebosSimulator)
: Base(aqufetp_data.aquiferID, connections, simulator)
, aqufetp_data_(aqufetp_data)
{
}
static AquiferFetkovich serializationTestObject(const Simulator& ebosSimulator)
static AquiferFetkovich serializationTestObject(const Simulator& simulator)
{
AquiferFetkovich result({}, ebosSimulator, {});
AquiferFetkovich result({}, simulator, {});
result.pressure_previous_ = {1.0, 2.0, 3.0};
result.pressure_current_ = {4.0, 5.0};
@ -76,7 +76,7 @@ public:
void endTimeStep() override
{
for (const auto& q : this->Qai_) {
this->W_flux_ += q * this->ebos_simulator_.timeStepSize();
this->W_flux_ += q * this->simulator_.timeStepSize();
}
aquifer_pressure_ = aquiferPressure();
}
@ -149,7 +149,7 @@ protected:
{
Scalar Flux = this->W_flux_.value();
const auto& comm = this->ebos_simulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
comm.sum(&Flux, 1);
const auto denom =
@ -183,7 +183,7 @@ protected:
this->aqufetp_data_.initial_pressure =
this->calculateReservoirEquilibrium();
const auto& tables = this->ebos_simulator_.vanguard()
const auto& tables = this->simulator_.vanguard()
.eclState().getTableManager();
this->aqufetp_data_.finishInitialisation(tables);

View File

@ -40,9 +40,9 @@ public:
// Constructor
AquiferInterface(int aqID,
const Simulator& ebosSimulator)
const Simulator& simulator)
: aquiferID_(aqID)
, ebos_simulator_(ebosSimulator)
, simulator_(simulator)
{
}
@ -80,7 +80,7 @@ public:
protected:
bool co2store_or_h2store_() const
{
const auto& rspec = ebos_simulator_.vanguard().eclState().runspec();
const auto& rspec = simulator_.vanguard().eclState().runspec();
return rspec.co2Storage() || rspec.h2Storage();
}
@ -94,7 +94,7 @@ protected:
}
const int aquiferID_{};
const Simulator& ebos_simulator_;
const Simulator& simulator_;
};
} // namespace Opm

View File

@ -62,20 +62,20 @@ public:
// Constructor
AquiferNumerical(const SingleNumericalAquifer& aquifer,
const Simulator& ebos_simulator)
: AquiferInterface<TypeTag>(aquifer.id(), ebos_simulator)
const Simulator& simulator)
: AquiferInterface<TypeTag>(aquifer.id(), simulator)
, flux_rate_ (0.0)
, cumulative_flux_(0.0)
, init_pressure_ (aquifer.numCells(), 0.0)
{
this->cell_to_aquifer_cell_idx_.resize(this->ebos_simulator_.gridView().size(/*codim=*/0), -1);
this->cell_to_aquifer_cell_idx_.resize(this->simulator_.gridView().size(/*codim=*/0), -1);
auto aquifer_on_process = false;
for (std::size_t idx = 0; idx < aquifer.numCells(); ++idx) {
const auto* cell = aquifer.getCellPrt(idx);
// Due to parallelisation, the cell might not exist in the current process
const int compressed_idx = ebos_simulator.vanguard().compressedIndexForInterior(cell->global_index);
const int compressed_idx = simulator.vanguard().compressedIndexForInterior(cell->global_index);
if (compressed_idx >= 0) {
this->cell_to_aquifer_cell_idx_[compressed_idx] = idx;
aquifer_on_process = true;
@ -87,9 +87,9 @@ public:
}
}
static AquiferNumerical serializationTestObject(const Simulator& ebos_simulator)
static AquiferNumerical serializationTestObject(const Simulator& simulator)
{
AquiferNumerical result({}, ebos_simulator);
AquiferNumerical result({}, simulator);
result.flux_rate_ = 1.0;
result.cumulative_flux_ = 2.0;
result.init_pressure_ = {3.0, 4.0};
@ -124,7 +124,7 @@ public:
{
this->pressure_ = this->calculateAquiferPressure();
this->flux_rate_ = this->calculateAquiferFluxRate();
this->cumulative_flux_ += this->flux_rate_ * this->ebos_simulator_.timeStepSize();
this->cumulative_flux_ += this->flux_rate_ * this->simulator_.timeStepSize();
}
data::AquiferData aquiferData() const override
@ -185,9 +185,9 @@ public:
private:
void checkConnectsToReservoir()
{
ElementContext elem_ctx(this->ebos_simulator_);
auto elemIt = std::find_if(this->ebos_simulator_.gridView().template begin</*codim=*/0>(),
this->ebos_simulator_.gridView().template end</*codim=*/0>(),
ElementContext elem_ctx(this->simulator_);
auto elemIt = std::find_if(this->simulator_.gridView().template begin</*codim=*/0>(),
this->simulator_.gridView().template end</*codim=*/0>(),
[&elem_ctx, this](const auto& elem) -> bool
{
elem_ctx.updateStencil(elem);
@ -198,7 +198,7 @@ private:
return this->cell_to_aquifer_cell_idx_[cell_index] == 0;
});
assert ((elemIt != this->ebos_simulator_.gridView().template end</*codim=*/0>())
assert ((elemIt != this->simulator_.gridView().template end</*codim=*/0>())
&& "Internal error locating numerical aquifer's connecting cell");
this->connects_to_reservoir_ =
@ -216,8 +216,8 @@ private:
double sum_pressure_watervolume = 0.;
double sum_watervolume = 0.;
ElementContext elem_ctx(this->ebos_simulator_);
const auto& gridView = this->ebos_simulator_.gridView();
ElementContext elem_ctx(this->simulator_);
const auto& gridView = this->simulator_.gridView();
OPM_BEGIN_PARALLEL_TRY_CATCH();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
@ -247,8 +247,9 @@ private:
cell_pressure[idx] = water_pressure_reservoir;
}
OPM_END_PARALLEL_TRY_CATCH("AquiferNumerical::calculateAquiferPressure() failed: ", this->ebos_simulator_.vanguard().grid().comm());
const auto& comm = this->ebos_simulator_.vanguard().grid().comm();
OPM_END_PARALLEL_TRY_CATCH("AquiferNumerical::calculateAquiferPressure() failed: ",
this->simulator_.vanguard().grid().comm());
const auto& comm = this->simulator_.vanguard().grid().comm();
comm.sum(&sum_pressure_watervolume, 1);
comm.sum(&sum_watervolume, 1);
@ -274,8 +275,8 @@ private:
return aquifer_flux;
}
ElementContext elem_ctx(this->ebos_simulator_);
const auto& gridView = this->ebos_simulator_.gridView();
ElementContext elem_ctx(this->simulator_);
const auto& gridView = this->simulator_.gridView();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
// elem_ctx.updatePrimaryStencil(elem);
elem_ctx.updateStencil(elem);

View File

@ -184,11 +184,11 @@ public:
/// \param[in] eclipse_state the object which represents an internalized ECL deck
/// \param[in] output_writer
/// \param[in] threshold_pressures_by_face if nonempty, threshold pressures that inhibit flow
SimulatorFullyImplicitBlackoil(Simulator& ebosSimulator)
: ebosSimulator_(ebosSimulator)
SimulatorFullyImplicitBlackoil(Simulator& simulator)
: simulator_(simulator)
, serializer_(*this,
EclGenericVanguard::comm(),
ebosSimulator_.vanguard().eclState().getIOConfig(),
simulator_.vanguard().eclState().getIOConfig(),
EWOMS_GET_PARAM(TypeTag, std::string, SaveStep),
EWOMS_GET_PARAM(TypeTag, int, LoadStep),
EWOMS_GET_PARAM(TypeTag, std::string, SaveFile),
@ -263,7 +263,7 @@ public:
{
init(timer);
// Make cache up to date. No need for updating it in elementCtx.
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
simulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
// Main simulation loop.
while (!timer.done()) {
bool continue_looping = runStep(timer);
@ -274,7 +274,7 @@ public:
void init(SimulatorTimer &timer)
{
ebosSimulator_.setEpisodeIndex(-1);
simulator_.setEpisodeIndex(-1);
// Create timers and file for writing timing info.
solverTimer_ = std::make_unique<time::StopWatch>();
@ -285,7 +285,7 @@ public:
bool enableAdaptive = EWOMS_GET_PARAM(TypeTag, bool, EnableAdaptiveTimeStepping);
bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning);
if (enableAdaptive) {
const UnitSystem& unitSystem = this->ebosSimulator_.vanguard().eclState().getUnits();
const UnitSystem& unitSystem = this->simulator_.vanguard().eclState().getUnits();
const auto& sched_state = schedule()[timer.currentStepNum()];
auto max_next_tstep = sched_state.max_next_tstep(enableTUNING);
if (enableTUNING) {
@ -298,9 +298,9 @@ public:
}
if (isRestart()) {
// For restarts the ebosSimulator may have gotten some information
// For restarts the simulator may have gotten some information
// about the next timestep size from the OPMEXTRA field
adaptiveTimeStepping_->setSuggestedNextStep(ebosSimulator_.timeStepSize());
adaptiveTimeStepping_->setSuggestedNextStep(simulator_.timeStepSize());
}
}
}
@ -343,11 +343,11 @@ public:
Dune::Timer perfTimer;
perfTimer.start();
ebosSimulator_.setEpisodeIndex(-1);
ebosSimulator_.setEpisodeLength(0.0);
ebosSimulator_.setTimeStepSize(0.0);
simulator_.setEpisodeIndex(-1);
simulator_.setEpisodeLength(0.0);
simulator_.setTimeStepSize(0.0);
wellModel_().beginReportStep(timer.currentStepNum());
ebosSimulator_.problem().writeOutput(timer);
simulator_.problem().writeOutput(timer);
report_.success.output_write_time += perfTimer.stop();
}
@ -359,15 +359,15 @@ public:
solver_ = createSolver(wellModel_());
}
ebosSimulator_.startNextEpisode(
ebosSimulator_.startTime()
simulator_.startNextEpisode(
simulator_.startTime()
+ schedule().seconds(timer.currentStepNum()),
timer.currentStepLength());
ebosSimulator_.setEpisodeIndex(timer.currentStepNum());
simulator_.setEpisodeIndex(timer.currentStepNum());
if (serializer_.shouldLoad()) {
wellModel_().prepareDeserialize(serializer_.loadStep() - 1);
serializer_.loadState();
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
simulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
}
solver_->model().beginReportStep();
bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning);
@ -380,7 +380,7 @@ public:
if (adaptiveTimeStepping_) {
auto tuningUpdater = [enableTUNING, this, reportStep = timer.currentStepNum()]()
{
auto& schedule = this->ebosSimulator_.vanguard().schedule();
auto& schedule = this->simulator_.vanguard().schedule();
auto& events = this->schedule()[reportStep].events();
if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) {
@ -414,7 +414,7 @@ public:
auto stepReport = adaptiveTimeStepping_->step(timer, *solver_, event, nullptr, tuningUpdater);
report_ += stepReport;
//Pass simulation report to eclwriter for summary output
ebosSimulator_.problem().setSimulationReport(report_);
simulator_.problem().setSimulationReport(report_);
} else {
// solve for complete report step
auto stepReport = solver_->step(timer);
@ -430,8 +430,8 @@ public:
Dune::Timer perfTimer;
perfTimer.start();
const double nextstep = adaptiveTimeStepping_ ? adaptiveTimeStepping_->suggestedNextStep() : -1.0;
ebosSimulator_.problem().setNextTimeStepSize(nextstep);
ebosSimulator_.problem().writeOutput(timer);
simulator_.problem().setNextTimeStepSize(nextstep);
simulator_.problem().writeOutput(timer);
report_.success.output_write_time += perfTimer.stop();
solver_->model().endReportStep();
@ -471,7 +471,7 @@ public:
Dune::Timer finalOutputTimer;
finalOutputTimer.start();
ebosSimulator_.problem().finalizeOutput();
simulator_.problem().finalizeOutput();
report_.success.output_write_time += finalOutputTimer.stop();
}
@ -484,12 +484,12 @@ public:
}
const Grid& grid() const
{ return ebosSimulator_.vanguard().grid(); }
{ return simulator_.vanguard().grid(); }
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(ebosSimulator_);
serializer(simulator_);
serializer(report_);
serializer(adaptiveTimeStepping_);
}
@ -524,20 +524,20 @@ protected:
return {"OPM Flow",
moduleVersion(),
compileTimestamp(),
ebosSimulator_.vanguard().caseName(),
simulator_.vanguard().caseName(),
str.str()};
}
//! \brief Returns local-to-global cell mapping.
const std::vector<int>& getCellMapping() const override
{
return ebosSimulator_.vanguard().globalCell();
return simulator_.vanguard().globalCell();
}
std::unique_ptr<Solver> createSolver(WellModel& wellModel)
{
auto model = std::make_unique<Model>(ebosSimulator_,
auto model = std::make_unique<Model>(simulator_,
modelParam_,
wellModel,
terminalOutput_);
@ -564,11 +564,11 @@ protected:
}
const EclipseState& eclState() const
{ return ebosSimulator_.vanguard().eclState(); }
{ return simulator_.vanguard().eclState(); }
const Schedule& schedule() const
{ return ebosSimulator_.vanguard().schedule(); }
{ return simulator_.vanguard().schedule(); }
bool isRestart() const
{
@ -577,10 +577,10 @@ protected:
}
WellModel& wellModel_()
{ return ebosSimulator_.problem().wellModel(); }
{ return simulator_.problem().wellModel(); }
const WellModel& wellModel_() const
{ return ebosSimulator_.problem().wellModel(); }
{ return simulator_.problem().wellModel(); }
void startConvergenceOutputThread(std::string_view convOutputOptions,
std::string_view optionName)
@ -642,7 +642,7 @@ protected:
}
// Data.
Simulator& ebosSimulator_;
Simulator& simulator_;
ModelParameters modelParam_;
SolverParameters solverParam_;

View File

@ -80,8 +80,8 @@ private:
// MPI at the correct time (ie after the other objects).
std::unique_ptr<Opm::Main> main_;
std::unique_ptr<Opm::FlowMain<TypeTag>> main_ebos_;
Simulator *ebos_simulator_;
std::unique_ptr<Opm::FlowMain<TypeTag>> flow_main_;
Simulator* simulator_;
std::unique_ptr<PyFluidState<TypeTag>> fluid_state_;
std::unique_ptr<PyMaterialState<TypeTag>> material_state_;
std::shared_ptr<Opm::Deck> deck_;

View File

@ -20,36 +20,35 @@
#ifndef OPM_PY_MATERIAL_STATE_HEADER_INCLUDED
#define OPM_PY_MATERIAL_STATE_HEADER_INCLUDED
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/discretization/common/fvbaseproperties.hh>
#include <opm/models/utils/basicproperties.hh>
#include <opm/models/utils/propertysystem.hh>
#include <exception>
#include <iostream>
#include <map>
#include <cstddef>
#include <memory>
#include <string>
#include <vector>
namespace Opm::Pybind
{
template <class TypeTag>
class PyMaterialState {
using Simulator = GetPropType<TypeTag, Opm::Properties::Simulator>;
using Problem = GetPropType<TypeTag, Opm::Properties::Problem>;
using Model = GetPropType<TypeTag, Opm::Properties::Model>;
using ElementContext = GetPropType<TypeTag, Opm::Properties::ElementContext>;
using FluidSystem = GetPropType<TypeTag, Opm::Properties::FluidSystem>;
using Indices = GetPropType<TypeTag, Opm::Properties::Indices>;
using GridView = GetPropType<TypeTag, Opm::Properties::GridView>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using Problem = GetPropType<TypeTag, Properties::Problem>;
using Model = GetPropType<TypeTag, Properties::Model>;
using ElementContext = GetPropType<TypeTag, Properties::ElementContext>;
using FluidSystem = GetPropType<TypeTag, Properties::FluidSystem>;
using Indices = GetPropType<TypeTag, Properties::Indices>;
using GridView = GetPropType<TypeTag, Properties::GridView>;
public:
PyMaterialState(Simulator *ebos_simulator)
: ebos_simulator_(ebos_simulator) { }
PyMaterialState(Simulator* simulator)
: simulator_(simulator) { }
std::vector<double> getCellVolumes();
std::vector<double> getPorosity();
void setPorosity(const double *poro, std::size_t size);
private:
Simulator *ebos_simulator_;
Simulator* simulator_;
};
}

View File

@ -26,7 +26,7 @@ std::vector<double>
PyMaterialState<TypeTag>::
getCellVolumes()
{
Model &model = this->ebos_simulator_->model();
Model &model = this->simulator_->model();
auto size = model.numGridDof();
std::vector<double> array(size);
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
@ -40,8 +40,8 @@ std::vector<double>
PyMaterialState<TypeTag>::
getPorosity()
{
Problem &problem = this->ebos_simulator_->problem();
Model &model = this->ebos_simulator_->model();
Problem &problem = this->simulator_->problem();
Model &model = this->simulator_->model();
auto size = model.numGridDof();
std::vector<double> array(size);
for (unsigned dof_idx = 0; dof_idx < size; ++dof_idx) {
@ -53,10 +53,10 @@ getPorosity()
template <class TypeTag>
void
PyMaterialState<TypeTag>::
setPorosity(const double *poro, std::size_t size)
setPorosity(const double* poro, std::size_t size)
{
Problem &problem = this->ebos_simulator_->problem();
Model &model = this->ebos_simulator_->model();
Problem& problem = this->simulator_->problem();
Model& model = this->simulator_->model();
auto model_size = model.numGridDof();
if (model_size != size) {
const std::string msg = fmt::format(

View File

@ -143,7 +143,7 @@ namespace Opm {
using Domain = SubDomain<Grid>;
BlackoilWellModel(Simulator& ebosSimulator);
BlackoilWellModel(Simulator& simulator);
void init();
void initWellContainer(const int reportStepIdx) override;
@ -196,7 +196,7 @@ namespace Opm {
void beginEpisode()
{
OPM_TIMEBLOCK(beginEpsiode);
beginReportStep(ebosSimulator_.episodeIndex());
beginReportStep(simulator_.episodeIndex());
}
void beginTimeStep();
@ -204,8 +204,8 @@ namespace Opm {
void beginIteration()
{
OPM_TIMEBLOCK(beginIteration);
assemble(ebosSimulator_.model().newtonMethod().numIterations(),
ebosSimulator_.timeStepSize());
assemble(simulator_.model().newtonMethod().numIterations(),
simulator_.timeStepSize());
}
void endIteration()
@ -214,7 +214,7 @@ namespace Opm {
void endTimeStep()
{
OPM_TIMEBLOCK(endTimeStep);
timeStepSucceeded(ebosSimulator_.time(), ebosSimulator_.timeStepSize());
timeStepSucceeded(simulator_.time(), simulator_.timeStepSize());
}
void endEpisode()
@ -238,7 +238,7 @@ namespace Opm {
void initFromRestartFile(const RestartValue& restartValues)
{
initFromRestartFile(restartValues,
this->ebosSimulator_.vanguard().transferWTestState(),
this->simulator_.vanguard().transferWTestState(),
grid().size(0),
param_.use_multisegment_well_);
}
@ -253,13 +253,13 @@ namespace Opm {
data::Wells wellData() const
{
auto wsrpt = this->wellState()
.report(ebosSimulator_.vanguard().globalCell().data(),
.report(simulator_.vanguard().globalCell().data(),
[this](const int well_index) -> bool
{
return this->wasDynamicallyShutThisTimeStep(well_index);
});
const auto& tracerRates = ebosSimulator_.problem().tracerModel().getWellTracerRates();
const auto& tracerRates = simulator_.problem().tracerModel().getWellTracerRates();
this->assignWellTracerRates(wsrpt, tracerRates);
@ -360,7 +360,7 @@ namespace Opm {
void setupDomains(const std::vector<Domain>& domains);
protected:
Simulator& ebosSimulator_;
Simulator& simulator_;
// a vector of all the wells.
std::vector<WellInterfacePtr> well_container_{};
@ -417,13 +417,13 @@ namespace Opm {
std::map<std::string, int> well_domain_;
const Grid& grid() const
{ return ebosSimulator_.vanguard().grid(); }
{ return simulator_.vanguard().grid(); }
const EquilGrid& equilGrid() const
{ return ebosSimulator_.vanguard().equilGrid(); }
{ return simulator_.vanguard().equilGrid(); }
const EclipseState& eclState() const
{ return ebosSimulator_.vanguard().eclState(); }
{ return simulator_.vanguard().eclState(); }
// compute the well fluxes and assemble them in to the reservoir equations as source terms
// and in the well equations.
@ -548,11 +548,11 @@ namespace Opm {
void computeWellTemperature();
int compressedIndexForInterior(int cartesian_cell_idx) const override {
return ebosSimulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
return simulator_.vanguard().compressedIndexForInterior(cartesian_cell_idx);
}
private:
BlackoilWellModel(Simulator& ebosSimulator, const PhaseUsage& pu);
BlackoilWellModel(Simulator& simulator, const PhaseUsage& pu);
};

View File

@ -49,24 +49,24 @@
namespace Opm {
template<typename TypeTag>
BlackoilWellModel<TypeTag>::
BlackoilWellModel(Simulator& ebosSimulator, const PhaseUsage& phase_usage)
: BlackoilWellModelGeneric(ebosSimulator.vanguard().schedule(),
ebosSimulator.vanguard().summaryState(),
ebosSimulator.vanguard().eclState(),
BlackoilWellModel(Simulator& simulator, const PhaseUsage& phase_usage)
: BlackoilWellModelGeneric(simulator.vanguard().schedule(),
simulator.vanguard().summaryState(),
simulator.vanguard().eclState(),
phase_usage,
ebosSimulator.gridView().comm())
, ebosSimulator_(ebosSimulator)
simulator.gridView().comm())
, simulator_(simulator)
{
terminal_output_ = ((ebosSimulator.gridView().comm().rank() == 0) &&
terminal_output_ = ((simulator.gridView().comm().rank() == 0) &&
EWOMS_GET_PARAM(TypeTag, bool, EnableTerminalOutput));
local_num_cells_ = ebosSimulator_.gridView().size(0);
local_num_cells_ = simulator_.gridView().size(0);
// Number of cells the global grid view
global_num_cells_ = ebosSimulator_.vanguard().globalNumCells();
global_num_cells_ = simulator_.vanguard().globalNumCells();
{
auto& parallel_wells = ebosSimulator.vanguard().parallelWells();
auto& parallel_wells = simulator.vanguard().parallelWells();
this->parallel_well_info_.reserve(parallel_wells.size());
for( const auto& name_bool : parallel_wells) {
@ -85,12 +85,12 @@ namespace Opm {
{
using Item = PAvgDynamicSourceData::SourceDataSpan<double>::Item;
const auto* intQuants = this->ebosSimulator_.model()
const auto* intQuants = this->simulator_.model()
.cachedIntensiveQuantities(localCell, /*timeIndex = */0);
const auto& fs = intQuants->fluidState();
sourceTerms.set(Item::PoreVol, intQuants->porosity().value() *
this->ebosSimulator_.model().dofTotalVolume(localCell));
this->simulator_.model().dofTotalVolume(localCell));
constexpr auto io = FluidSystem::oilPhaseIdx;
constexpr auto ig = FluidSystem::gasPhaseIdx;
@ -122,8 +122,8 @@ namespace Opm {
template<typename TypeTag>
BlackoilWellModel<TypeTag>::
BlackoilWellModel(Simulator& ebosSimulator) :
BlackoilWellModel(ebosSimulator, phaseUsageFromDeck(ebosSimulator.vanguard().eclState()))
BlackoilWellModel(Simulator& simulator) :
BlackoilWellModel(simulator, phaseUsageFromDeck(simulator.vanguard().eclState()))
{}
@ -135,12 +135,12 @@ namespace Opm {
extractLegacyCellPvtRegionIndex_();
extractLegacyDepth_();
gravity_ = ebosSimulator_.problem().gravity()[2];
gravity_ = simulator_.problem().gravity()[2];
initial_step_ = true;
// add the eWoms auxiliary module for the wells to the list
ebosSimulator_.model().addAuxiliaryModule(this);
simulator_.model().addAuxiliaryModule(this);
is_cell_perforated_.resize(local_num_cells_, false);
}
@ -203,7 +203,7 @@ namespace Opm {
well->apply(res);
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::linearize failed: ",
ebosSimulator_.gridView().comm());
simulator_.gridView().comm());
}
@ -247,7 +247,7 @@ namespace Opm {
this->initializeGroupStructure(timeStepIdx);
const auto& comm = this->ebosSimulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
OPM_BEGIN_PARALLEL_TRY_CATCH()
{
@ -255,7 +255,7 @@ namespace Opm {
// purpose of RESV controls.
this->rateConverter_ = std::make_unique<RateConverterType>
(this->phase_usage_, std::vector<int>(this->local_num_cells_, 0));
this->rateConverter_->template defineState<ElementContext>(this->ebosSimulator_);
this->rateConverter_->template defineState<ElementContext>(this->simulator_);
// Update VFP properties.
{
@ -288,7 +288,7 @@ namespace Opm {
{
DeferredLogger local_deferredLogger{};
const auto& comm = this->ebosSimulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
// Wells_ecl_ holds this rank's wells, both open and stopped/shut.
this->wells_ecl_ = this->getLocalWells(reportStepIdx);
@ -332,7 +332,7 @@ namespace Opm {
{
DeferredLogger local_deferredLogger{};
const auto& comm = this->ebosSimulator_.vanguard().grid().comm();
const auto& comm = this->simulator_.vanguard().grid().comm();
OPM_BEGIN_PARALLEL_TRY_CATCH()
{
@ -387,7 +387,7 @@ namespace Opm {
// Reconstruct the local wells to account for the new well
// structure.
const auto reportStepIdx =
this->ebosSimulator_.episodeIndex();
this->simulator_.episodeIndex();
// Disable WELPI scaling when well structure is updated in the
// middle of a report step.
@ -407,14 +407,14 @@ namespace Opm {
this->resetWGState();
const int reportStepIdx = ebosSimulator_.episodeIndex();
const int reportStepIdx = simulator_.episodeIndex();
updateAndCommunicateGroupData(reportStepIdx,
ebosSimulator_.model().newtonMethod().numIterations());
simulator_.model().newtonMethod().numIterations());
this->wellState().updateWellsDefaultALQ(this->wells_ecl_, this->summaryState());
this->wellState().gliftTimeStepInit();
const double simulationTime = ebosSimulator_.time();
const double simulationTime = simulator_.time();
OPM_BEGIN_PARALLEL_TRY_CATCH();
{
// test wells
@ -424,7 +424,7 @@ namespace Opm {
createWellContainer(reportStepIdx);
// Wells are active if they are active wells on at least one process.
const Grid& grid = ebosSimulator_.vanguard().grid();
const Grid& grid = simulator_.vanguard().grid();
wells_active_ = !this->well_container_.empty();
wells_active_ = grid.comm().max(wells_active_);
@ -451,7 +451,7 @@ namespace Opm {
}
OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger, "beginTimeStep() failed: ",
terminal_output_, ebosSimulator_.vanguard().grid().comm());
terminal_output_, simulator_.vanguard().grid().comm());
for (auto& well : well_container_) {
well->setVFPProperties(vfp_properties_.get());
@ -468,7 +468,7 @@ namespace Opm {
// we need the inj_multiplier from the previous time step
this->initInjMult();
const auto& summaryState = ebosSimulator_.vanguard().summaryState();
const auto& summaryState = simulator_.vanguard().summaryState();
if (alternative_well_rate_init_) {
// Update the well rates of well_state_, if only single-phase rates, to
// have proper multi-phase rates proportional to rates at bhp zero.
@ -477,7 +477,7 @@ namespace Opm {
for (auto& well : well_container_) {
const bool zero_target = well->stopppedOrZeroRateTarget(summaryState, this->wellState());
if (well->isProducer() && !zero_target) {
well->updateWellStateRates(ebosSimulator_, this->wellState(), local_deferredLogger);
well->updateWellStateRates(simulator_, this->wellState(), local_deferredLogger);
}
}
}
@ -492,7 +492,7 @@ namespace Opm {
try {
updateWellPotentials(reportStepIdx,
/*onlyAfterEvent*/true,
ebosSimulator_.vanguard().summaryConfig(),
simulator_.vanguard().summaryConfig(),
local_deferredLogger);
} catch ( std::runtime_error& e ) {
const std::string msg = "A zero well potential is returned for output purposes. ";
@ -500,7 +500,7 @@ namespace Opm {
}
//update guide rates
const auto& comm = ebosSimulator_.vanguard().grid().comm();
const auto& comm = simulator_.vanguard().grid().comm();
std::vector<double> pot(numPhases(), 0.0);
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx);
WellGroupHelpers::updateGuideRates(fieldGroup, schedule(), summaryState, this->phase_usage_, reportStepIdx, simulationTime,
@ -510,9 +510,9 @@ namespace Opm {
// update gpmaint targets
if (schedule_[reportStepIdx].has_gpmaint()) {
for (auto& calculator : regionalAveragePressureCalculator_) {
calculator.second->template defineState<ElementContext>(ebosSimulator_);
calculator.second->template defineState<ElementContext>(simulator_);
}
const double dt = ebosSimulator_.timeStepSize();
const double dt = simulator_.timeStepSize();
WellGroupHelpers::updateGpMaintTargetForGroups(fieldGroup,
schedule_, regionalAveragePressureCalculator_, reportStepIdx, dt, this->wellState(), this->groupState());
}
@ -531,9 +531,9 @@ namespace Opm {
if (event || dyn_status_change) {
try {
well->updateWellStateWithTarget(ebosSimulator_, this->groupState(), this->wellState(), local_deferredLogger);
well->calculateExplicitQuantities(ebosSimulator_, this->wellState(), local_deferredLogger);
well->solveWellEquation(ebosSimulator_, this->wellState(), this->groupState(), local_deferredLogger);
well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), local_deferredLogger);
well->calculateExplicitQuantities(simulator_, this->wellState(), local_deferredLogger);
well->solveWellEquation(simulator_, this->wellState(), this->groupState(), local_deferredLogger);
} catch (const std::exception& e) {
const std::string msg = "Compute initial well solution for new well " + well->name() + " failed. Continue with zero initial rates";
local_deferredLogger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
@ -579,14 +579,14 @@ namespace Opm {
// initialize rates/previous rates to prevent zero fractions in vfp-interpolation
if (well->isProducer()) {
well->updateWellStateRates(ebosSimulator_, this->wellState(), deferred_logger);
well->updateWellStateRates(simulator_, this->wellState(), deferred_logger);
}
if (well->isVFPActive(deferred_logger)) {
well->setPrevSurfaceRates(this->wellState(), this->prevWellState());
}
try {
well->wellTesting(ebosSimulator_, simulationTime, this->wellState(), this->groupState(), wellTestState(), deferred_logger);
well->wellTesting(simulator_, simulationTime, this->wellState(), this->groupState(), wellTestState(), deferred_logger);
} catch (const std::exception& e) {
const std::string msg = fmt::format("Exception during testing of well: {}. The well will not open.\n Exception message: {}", wellEcl.name(), e.what());
deferred_logger.warning("WELL_TESTING_FAILED", msg);
@ -635,7 +635,7 @@ namespace Opm {
// time step is finished and we are not any more at the beginning of an report step
report_step_starts_ = false;
const int reportStepIdx = ebosSimulator_.episodeIndex();
const int reportStepIdx = simulator_.episodeIndex();
DeferredLogger local_deferredLogger;
for (const auto& well : well_container_) {
@ -645,8 +645,8 @@ namespace Opm {
}
// update connection transmissibility factor and d factor (if applicable) in the wellstate
for (const auto& well : well_container_) {
well->updateConnectionTransmissibilityFactor(ebosSimulator_, this->wellState().well(well->indexOfWell()));
well->updateConnectionDFactor(ebosSimulator_, this->wellState().well(well->indexOfWell()));
well->updateConnectionTransmissibilityFactor(simulator_, this->wellState().well(well->indexOfWell()));
well->updateConnectionDFactor(simulator_, this->wellState().well(well->indexOfWell()));
}
if (Indices::waterEnabled) {
@ -691,13 +691,13 @@ namespace Opm {
}
// update the rate converter with current averages pressures etc in
rateConverter_->template defineState<ElementContext>(ebosSimulator_);
rateConverter_->template defineState<ElementContext>(simulator_);
// calculate the well potentials
try {
updateWellPotentials(reportStepIdx,
/*onlyAfterEvent*/false,
ebosSimulator_.vanguard().summaryConfig(),
simulator_.vanguard().summaryConfig(),
local_deferredLogger);
} catch ( std::runtime_error& e ) {
const std::string msg = "A zero well potential is returned for output purposes. ";
@ -709,9 +709,9 @@ namespace Opm {
// check group sales limits at the end of the timestep
const Group& fieldGroup = schedule_.getGroup("FIELD", reportStepIdx);
checkGEconLimits(
fieldGroup, simulationTime, ebosSimulator_.episodeIndex(), local_deferredLogger);
fieldGroup, simulationTime, simulator_.episodeIndex(), local_deferredLogger);
checkGconsaleLimits(fieldGroup, this->wellState(),
ebosSimulator_.episodeIndex(), local_deferredLogger);
simulator_.episodeIndex(), local_deferredLogger);
this->calculateProductivityIndexValues(local_deferredLogger);
@ -771,9 +771,9 @@ namespace Opm {
initializeWellState(const int timeStepIdx)
{
std::vector<double> cellPressures(this->local_num_cells_, 0.0);
ElementContext elemCtx(ebosSimulator_);
ElementContext elemCtx(simulator_);
const auto& gridView = ebosSimulator_.vanguard().gridView();
const auto& gridView = simulator_.vanguard().gridView();
OPM_BEGIN_PARALLEL_TRY_CATCH();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
@ -791,7 +791,7 @@ namespace Opm {
perf_pressure = fs.pressure(FluidSystem::gasPhaseIdx).value();
}
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::initializeWellState() failed: ", ebosSimulator_.vanguard().grid().comm());
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::initializeWellState() failed: ", simulator_.vanguard().grid().comm());
this->wellState().init(cellPressures, schedule(), wells_ecl_, local_parallel_well_info_, timeStepIdx,
&this->prevWellState(), well_perf_data_,
@ -846,7 +846,7 @@ namespace Opm {
// a timestep without the well in question, after it caused
// repeated timestep cuts. It should therefore not be opened,
// even if it was new or received new targets this report step.
const bool closed_this_step = (wellTestState().lastTestTime(well_name) == ebosSimulator_.time());
const bool closed_this_step = (wellTestState().lastTestTime(well_name) == simulator_.time());
// TODO: more checking here, to make sure this standard more specific and complete
// maybe there is some WCON keywords will not open the well
auto& events = this->wellState().well(w).events;
@ -1025,7 +1025,7 @@ namespace Opm {
void
BlackoilWellModel<TypeTag>::
doPreStepNetworkRebalance(DeferredLogger& deferred_logger) {
const double dt = this->ebosSimulator_.timeStepSize();
const double dt = this->simulator_.timeStepSize();
// TODO: should we also have the group and network backed-up here in case the solution did not get converged?
auto& well_state = this->wellState();
const std::size_t max_iter = param_.network_max_iterations_;
@ -1041,7 +1041,7 @@ namespace Opm {
}
++iter;
for (auto& well : this->well_container_) {
const auto& summary_state = this->ebosSimulator_.vanguard().summaryState();
const auto& summary_state = this->simulator_.vanguard().summaryState();
well->solveEqAndUpdateWellState(summary_state, well_state, deferred_logger);
}
this->initPrimaryVariablesEvaluation();
@ -1078,7 +1078,7 @@ namespace Opm {
perfTimer.start();
{
const int episodeIdx = ebosSimulator_.episodeIndex();
const int episodeIdx = simulator_.episodeIndex();
const auto& network = schedule()[episodeIdx].network();
if ( !wellsActive() && !network.active() ) {
return;
@ -1180,12 +1180,12 @@ namespace Opm {
terminal_output_, grid().comm());
//update guide rates
const int reportStepIdx = ebosSimulator_.episodeIndex();
const int reportStepIdx = simulator_.episodeIndex();
if (alq_updated || BlackoilWellModelGuideRates(*this).
guideRateUpdateIsNeeded(reportStepIdx)) {
const double simulationTime = ebosSimulator_.time();
const auto& comm = ebosSimulator_.vanguard().grid().comm();
const auto& summaryState = ebosSimulator_.vanguard().summaryState();
const double simulationTime = simulator_.time();
const auto& comm = simulator_.vanguard().grid().comm();
const auto& summaryState = simulator_.vanguard().summaryState();
std::vector<double> pot(numPhases(), 0.0);
const Group& fieldGroup = schedule().getGroup("FIELD", reportStepIdx);
WellGroupHelpers::updateGuideRates(fieldGroup, schedule(), summaryState, this->phase_usage_, reportStepIdx, simulationTime,
@ -1210,7 +1210,7 @@ namespace Opm {
perfTimer.start();
{
const int episodeIdx = ebosSimulator_.episodeIndex();
const int episodeIdx = simulator_.episodeIndex();
const auto& network = schedule()[episodeIdx].network();
if ( !wellsActive() && !network.active() ) {
return;
@ -1245,8 +1245,8 @@ namespace Opm {
{
bool do_glift_optimization = false;
int num_wells_changed = 0;
const double simulation_time = ebosSimulator_.time();
const double min_wait = ebosSimulator_.vanguard().schedule().glo(ebosSimulator_.episodeIndex()).min_wait();
const double simulation_time = simulator_.time();
const double min_wait = simulator_.vanguard().schedule().glo(simulator_.episodeIndex()).min_wait();
// We only optimize if a min_wait time has past.
// If all_newton is true we still want to optimize several times pr timestep
// i.e. we also optimize if check simulation_time == last_glift_opt_time_
@ -1271,15 +1271,15 @@ namespace Opm {
initGliftEclWellMap(ecl_well_map);
GasLiftGroupInfo group_info {
ecl_well_map,
ebosSimulator_.vanguard().schedule(),
ebosSimulator_.vanguard().summaryState(),
ebosSimulator_.episodeIndex(),
ebosSimulator_.model().newtonMethod().numIterations(),
simulator_.vanguard().schedule(),
simulator_.vanguard().summaryState(),
simulator_.episodeIndex(),
simulator_.model().newtonMethod().numIterations(),
phase_usage_,
deferred_logger,
this->wellState(),
this->groupState(),
ebosSimulator_.vanguard().grid().comm(),
simulator_.vanguard().grid().comm(),
this->glift_debug
};
group_info.initialize();
@ -1287,7 +1287,7 @@ namespace Opm {
deferred_logger, prod_wells, glift_wells, group_info, state_map);
gasLiftOptimizationStage2(
deferred_logger, prod_wells, glift_wells, group_info, state_map,
ebosSimulator_.episodeIndex());
simulator_.episodeIndex());
if (this->glift_debug) gliftDebugShowALQ(deferred_logger);
num_wells_changed = glift_wells.size();
}
@ -1302,7 +1302,7 @@ namespace Opm {
GLiftProdWells &prod_wells, GLiftOptWells &glift_wells,
GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map)
{
auto comm = ebosSimulator_.vanguard().grid().comm();
auto comm = simulator_.vanguard().grid().comm();
int num_procs = comm.size();
// NOTE: Gas lift optimization stage 1 seems to be difficult
// to do in parallel since the wells are optimized on different
@ -1410,14 +1410,14 @@ namespace Opm {
GasLiftGroupInfo &group_info, GLiftWellStateMap &state_map,
GLiftSyncGroups& sync_groups)
{
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
const auto& summary_state = simulator_.vanguard().summaryState();
std::unique_ptr<GasLiftSingleWell> glift
= std::make_unique<GasLiftSingleWell>(
*well, ebosSimulator_, summary_state,
*well, simulator_, summary_state,
deferred_logger, this->wellState(), this->groupState(),
group_info, sync_groups, this->comm_, this->glift_debug);
auto state = glift->runOptimize(
ebosSimulator_.model().newtonMethod().numIterations());
simulator_.model().newtonMethod().numIterations());
if (state) {
state_map.insert({well->name(), std::move(state)});
glift_wells.insert({well->name(), std::move(glift)});
@ -1445,7 +1445,7 @@ namespace Opm {
assembleWellEq(const double dt, DeferredLogger& deferred_logger)
{
for (auto& well : well_container_) {
well->assembleWellEq(ebosSimulator_, dt, this->wellState(), this->groupState(), deferred_logger);
well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
}
}
@ -1457,7 +1457,7 @@ namespace Opm {
{
for (auto& well : well_container_) {
if (well_domain_.at(well->name()) == domain.index) {
well->assembleWellEq(ebosSimulator_, dt, this->wellState(), this->groupState(), deferred_logger);
well->assembleWellEq(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
}
}
}
@ -1469,7 +1469,7 @@ namespace Opm {
prepareWellsBeforeAssembling(const double dt, DeferredLogger& deferred_logger)
{
for (auto& well : well_container_) {
well->prepareWellBeforeAssembling(ebosSimulator_, dt, this->wellState(), this->groupState(), deferred_logger);
well->prepareWellBeforeAssembling(simulator_, dt, this->wellState(), this->groupState(), deferred_logger);
}
}
@ -1484,7 +1484,7 @@ namespace Opm {
OPM_BEGIN_PARALLEL_TRY_CATCH();
for (auto& well: well_container_) {
well->assembleWellEqWithoutIteration(ebosSimulator_, dt, this->wellState(), this->groupState(),
well->assembleWellEqWithoutIteration(simulator_, dt, this->wellState(), this->groupState(),
deferred_logger);
}
OPM_END_PARALLEL_TRY_CATCH_LOG(deferred_logger, "BlackoilWellModel::assembleWellEqWithoutIteration failed: ",
@ -1620,7 +1620,7 @@ namespace Opm {
VectorBlockType res(0.0);
using MatrixBlockType = typename SparseMatrixAdapter::MatrixBlock;
MatrixBlockType bMat(0.0);
ebosSimulator_.model().linearizer().setResAndJacobi(res, bMat, rate);
simulator_.model().linearizer().setResAndJacobi(res, bMat, rate);
residual[cellIdx] += res;
*diagMatAddress[cellIdx] += bMat;
}
@ -1659,14 +1659,14 @@ namespace Opm {
DeferredLogger local_deferredLogger;
OPM_BEGIN_PARALLEL_TRY_CATCH();
{
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
const auto& summary_state = simulator_.vanguard().summaryState();
for (auto& well : well_container_) {
well->recoverWellSolutionAndUpdateWellState(summary_state, x, this->wellState(), local_deferredLogger);
}
}
OPM_END_PARALLEL_TRY_CATCH_LOG(local_deferredLogger,
"recoverWellSolutionAndUpdateWellState() failed: ",
terminal_output_, ebosSimulator_.vanguard().grid().comm());
terminal_output_, simulator_.vanguard().grid().comm());
}
@ -1679,7 +1679,7 @@ namespace Opm {
// try/catch here, as this function is not called in
// parallel but for each individual domain of each rank.
DeferredLogger local_deferredLogger;
const auto& summary_state = this->ebosSimulator_.vanguard().summaryState();
const auto& summary_state = this->simulator_.vanguard().summaryState();
for (auto& well : well_container_) {
if (well_domain_.at(well->name()) == domain.index) {
well->recoverWellSolutionAndUpdateWellState(summary_state, x,
@ -1730,8 +1730,8 @@ namespace Opm {
const std::vector<Scalar>& B_avg,
DeferredLogger& local_deferredLogger) const
{
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
const int iterationIdx = ebosSimulator_.model().newtonMethod().numIterations();
const auto& summary_state = simulator_.vanguard().summaryState();
const int iterationIdx = simulator_.model().newtonMethod().numIterations();
const bool relax_tolerance = iterationIdx > param_.strict_outer_iter_wells_;
ConvergenceReport report;
@ -1778,10 +1778,10 @@ namespace Opm {
DeferredLogger local_deferredLogger;
// Get global (from all processes) convergence report.
ConvergenceReport local_report;
const int iterationIdx = ebosSimulator_.model().newtonMethod().numIterations();
const int iterationIdx = simulator_.model().newtonMethod().numIterations();
for (const auto& well : well_container_) {
if (well->isOperableAndSolvable() || well->wellIsStopped()) {
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
const auto& summary_state = simulator_.vanguard().summaryState();
local_report += well->getWellConvergence(
summary_state, this->wellState(), B_avg, local_deferredLogger,
iterationIdx > param_.strict_outer_iter_wells_);
@ -1829,7 +1829,7 @@ namespace Opm {
{
// TODO: checking isOperableAndSolvable() ?
for (auto& well : well_container_) {
well->calculateExplicitQuantities(ebosSimulator_, this->wellState(), deferred_logger);
well->calculateExplicitQuantities(simulator_, this->wellState(), deferred_logger);
}
}
@ -1842,14 +1842,14 @@ namespace Opm {
BlackoilWellModel<TypeTag>::
updateWellControls(const bool mandatory_network_balance, DeferredLogger& deferred_logger, const bool relax_network_tolerance)
{
const int episodeIdx = ebosSimulator_.episodeIndex();
const int episodeIdx = simulator_.episodeIndex();
const auto& network = schedule()[episodeIdx].network();
if (!wellsActive() && !network.active()) {
return {false, false};
}
const int iterationIdx = ebosSimulator_.model().newtonMethod().numIterations();
const auto& comm = ebosSimulator_.vanguard().grid().comm();
const int iterationIdx = simulator_.model().newtonMethod().numIterations();
const auto& comm = simulator_.vanguard().grid().comm();
updateAndCommunicateGroupData(episodeIdx, iterationIdx);
// network related
@ -1880,13 +1880,13 @@ namespace Opm {
OPM_BEGIN_PARALLEL_TRY_CATCH()
for (const auto& well : well_container_) {
const auto mode = WellInterface<TypeTag>::IndividualOrGroup::Group;
const bool changed_well = well->updateWellControl(ebosSimulator_, mode, this->wellState(), this->groupState(), deferred_logger);
const bool changed_well = well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
if (changed_well) {
changed_well_to_group = changed_well || changed_well_to_group;
}
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel: updating well controls failed: ",
ebosSimulator_.gridView().comm());
simulator_.gridView().comm());
}
changed_well_to_group = comm.sum(static_cast<int>(changed_well_to_group));
@ -1903,13 +1903,13 @@ namespace Opm {
OPM_BEGIN_PARALLEL_TRY_CATCH()
for (const auto& well : well_container_) {
const auto mode = WellInterface<TypeTag>::IndividualOrGroup::Individual;
const bool changed_well = well->updateWellControl(ebosSimulator_, mode, this->wellState(), this->groupState(), deferred_logger);
const bool changed_well = well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
if (changed_well) {
changed_well_individual = changed_well || changed_well_individual;
}
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel: updating well controls failed: ",
ebosSimulator_.gridView().comm());
simulator_.gridView().comm());
}
changed_well_individual = comm.sum(static_cast<int>(changed_well_individual));
@ -1939,7 +1939,7 @@ namespace Opm {
for (const auto& well : well_container_) {
if (well_domain_.at(well->name()) == domain.index) {
const auto mode = WellInterface<TypeTag>::IndividualOrGroup::Individual;
well->updateWellControl(ebosSimulator_, mode, this->wellState(), this->groupState(), deferred_logger);
well->updateWellControl(simulator_, mode, this->wellState(), this->groupState(), deferred_logger);
}
}
}
@ -2108,10 +2108,10 @@ namespace Opm {
OPM_BEGIN_PARALLEL_TRY_CATCH()
// if a well or group change control it affects all wells that are under the same group
for (const auto& well : well_container_) {
well->updateWellStateWithTarget(ebosSimulator_, this->groupState(), this->wellState(), deferred_logger);
well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger);
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::updateAndCommunicate failed: ",
ebosSimulator_.gridView().comm())
simulator_.gridView().comm())
updateAndCommunicateGroupData(reportStepIdx, iterationIdx);
}
@ -2159,7 +2159,7 @@ namespace Opm {
for (const auto& well : well_container_) {
const auto& wname = well->name();
const auto wasClosed = wellTestState.well_is_closed(wname);
well->checkWellOperability(ebosSimulator_, this->wellState(), local_deferredLogger);
well->checkWellOperability(simulator_, this->wellState(), local_deferredLogger);
well->updateWellTestState(this->wellState().well(wname), simulationTime, /*writeMessageToOPMLog=*/ true, wellTestState, local_deferredLogger);
if (!wasClosed && wellTestState.well_is_closed(wname)) {
@ -2189,7 +2189,7 @@ namespace Opm {
std::string cur_exc_msg;
auto cur_exc_type = ExceptionType::NONE;
try {
well->computeWellPotentials(ebosSimulator_, well_state_copy, potentials, deferred_logger);
well->computeWellPotentials(simulator_, well_state_copy, potentials, deferred_logger);
}
// catch all possible exception and store type and message.
OPM_PARALLEL_CATCH_CLAUSE(cur_exc_type, cur_exc_msg);
@ -2260,7 +2260,7 @@ namespace Opm {
calculateProductivityIndexValues(const WellInterface<TypeTag>* wellPtr,
DeferredLogger& deferred_logger)
{
wellPtr->updateProductivityIndex(this->ebosSimulator_,
wellPtr->updateProductivityIndex(this->simulator_,
this->prod_index_calc_[wellPtr->indexOfWell()],
this->wellState(),
deferred_logger);
@ -2274,7 +2274,7 @@ namespace Opm {
prepareTimeStep(DeferredLogger& deferred_logger)
{
// Check if there is a network with active prediction wells at this time step.
const auto episodeIdx = ebosSimulator_.episodeIndex();
const auto episodeIdx = simulator_.episodeIndex();
this->updateNetworkActiveState(episodeIdx);
// Rebalance the network initially if any wells in the network have status changes
@ -2284,8 +2284,8 @@ namespace Opm {
for (const auto& well : well_container_) {
auto& events = this->wellState().well(well->indexOfWell()).events;
if (events.hasEvent(WellState::event_mask)) {
well->updateWellStateWithTarget(ebosSimulator_, this->groupState(), this->wellState(), deferred_logger);
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
well->updateWellStateWithTarget(simulator_, this->groupState(), this->wellState(), deferred_logger);
const auto& summary_state = simulator_.vanguard().summaryState();
well->updatePrimaryVariables(summary_state, this->wellState(), deferred_logger);
well->initPrimaryVariablesEvaluation();
// There is no new well control change input within a report step,
@ -2299,7 +2299,7 @@ namespace Opm {
// solve the well equation initially to improve the initial solution of the well model
if (param_.solve_welleq_initially_ && well->isOperableAndSolvable()) {
try {
well->solveWellEquation(ebosSimulator_, this->wellState(), this->groupState(), deferred_logger);
well->solveWellEquation(simulator_, this->wellState(), this->groupState(), deferred_logger);
} catch (const std::exception& e) {
const std::string msg = "Compute initial well solution for " + well->name() + " initially failed. Continue with the previous rates";
deferred_logger.warning("WELL_INITIAL_SOLVE_FAILED", msg);
@ -2321,9 +2321,9 @@ namespace Opm {
updateAverageFormationFactor()
{
std::vector< Scalar > B_avg(numComponents(), Scalar() );
const auto& grid = ebosSimulator_.vanguard().grid();
const auto& grid = simulator_.vanguard().grid();
const auto& gridView = grid.leafGridView();
ElementContext elemCtx(ebosSimulator_);
ElementContext elemCtx(simulator_);
OPM_BEGIN_PARALLEL_TRY_CATCH();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
@ -2370,7 +2370,7 @@ namespace Opm {
updatePrimaryVariables(DeferredLogger& deferred_logger)
{
for (const auto& well : well_container_) {
const auto& summary_state = ebosSimulator_.vanguard().summaryState();
const auto& summary_state = simulator_.vanguard().summaryState();
well->updatePrimaryVariables(summary_state, this->wellState(), deferred_logger);
}
}
@ -2379,8 +2379,8 @@ namespace Opm {
void
BlackoilWellModel<TypeTag>::extractLegacyCellPvtRegionIndex_()
{
const auto& grid = ebosSimulator_.vanguard().grid();
const auto& eclProblem = ebosSimulator_.problem();
const auto& grid = simulator_.vanguard().grid();
const auto& eclProblem = simulator_.problem();
const unsigned numCells = grid.size(/*codim=*/0);
pvt_region_idx_.resize(numCells);
@ -2412,7 +2412,7 @@ namespace Opm {
void
BlackoilWellModel<TypeTag>::extractLegacyDepth_()
{
const auto& eclProblem = ebosSimulator_.problem();
const auto& eclProblem = simulator_.problem();
depth_.resize(local_num_cells_);
for (unsigned cellIdx = 0; cellIdx < local_num_cells_; ++cellIdx) {
depth_[cellIdx] = eclProblem.dofCenterDepth(cellIdx);
@ -2456,7 +2456,7 @@ namespace Opm {
BlackoilWellModel<TypeTag>::
reportStepIndex() const
{
return std::max(this->ebosSimulator_.episodeIndex(), 0);
return std::max(this->simulator_.episodeIndex(), 0);
}
@ -2515,7 +2515,7 @@ namespace Opm {
using int_type = decltype(well_perf_data_[wellID].size());
for (int_type perf = 0, end_perf = well_perf_data_[wellID].size(); perf < end_perf; ++perf) {
const int cell_idx = well_perf_data_[wellID][perf].cell_index;
const auto& intQuants = ebosSimulator_.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& intQuants = simulator_.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
// we on only have one temperature pr cell any phaseIdx will do
@ -2631,7 +2631,7 @@ namespace Opm {
}
}
OPM_END_PARALLEL_TRY_CATCH("BlackoilWellModel::setupDomains(): well found on multiple domains.",
ebosSimulator_.gridView().comm());
simulator_.gridView().comm());
// Write well/domain info to the DBG file.
const Opm::Parallel::Communication& comm = grid().comm();

View File

@ -42,7 +42,7 @@ namespace Opm
public:
GasLiftSingleWell(
const WellInterface<TypeTag> &well,
const Simulator &ebos_simulator,
const Simulator& simulator,
const SummaryState &summary_state,
DeferredLogger &deferred_logger,
WellState &well_state,
@ -63,7 +63,7 @@ namespace Opm
bool checkThpControl_() const override;
const Simulator &ebos_simulator_;
const Simulator& simulator_;
const WellInterface<TypeTag> &well_;
};

View File

@ -25,7 +25,7 @@ namespace Opm {
template<typename TypeTag>
GasLiftSingleWell<TypeTag>::
GasLiftSingleWell(const WellInterface<TypeTag> &well,
const Simulator &ebos_simulator,
const Simulator& simulator,
const SummaryState &summary_state,
DeferredLogger &deferred_logger,
WellState &well_state,
@ -45,13 +45,13 @@ GasLiftSingleWell(const WellInterface<TypeTag> &well,
summary_state,
group_info,
well.phaseUsage(),
ebos_simulator.vanguard().schedule(),
ebos_simulator.episodeIndex(),
simulator.vanguard().schedule(),
simulator.episodeIndex(),
sync_groups,
comm,
glift_debug
)
, ebos_simulator_{ebos_simulator}
, simulator_{simulator}
, well_{well}
{
const auto& gl_well = *gl_well_;
@ -106,7 +106,7 @@ computeWellRates_( double bhp, bool bhp_is_limited, bool debug_output ) const
{
std::vector<double> potentials(NUM_PHASES, 0.0);
this->well_.computeWellRatesWithBhp(
this->ebos_simulator_, bhp, potentials, this->deferred_logger_);
this->simulator_, bhp, potentials, this->deferred_logger_);
if (debug_output) {
const std::string msg = fmt::format("computed well potentials given bhp {}, "
"oil: {}, gas: {}, water: {}", bhp,
@ -131,7 +131,7 @@ GasLiftSingleWell<TypeTag>::
computeBhpAtThpLimit_(double alq, bool debug_output) const
{
auto bhp_at_thp_limit = this->well_.computeBhpAtThpLimitProdWithAlq(
this->ebos_simulator_,
this->simulator_,
this->summary_state_,
alq,
this->deferred_logger_);

View File

@ -64,7 +64,7 @@ GasLiftStage2::GasLiftStage2(
, glo_{schedule_.glo(report_step_idx_)}
{
// this->time_step_idx_
// = this->ebos_simulator_.model().newtonMethod().currentTimeStep();
// = this->simulator_.model().newtonMethod().currentTimeStep();
}
/********************************************

View File

@ -90,7 +90,7 @@ namespace Opm
void initPrimaryVariablesEvaluation() override;
/// updating the well state based the current control mode
virtual void updateWellStateWithTarget(const Simulator& ebos_simulator,
virtual void updateWellStateWithTarget(const Simulator& simulator,
const GroupState& group_state,
WellState& well_state,
DeferredLogger& deferred_logger) const override;
@ -115,7 +115,7 @@ namespace Opm
DeferredLogger& deferred_logger) override;
/// computing the well potentials for group control
virtual void computeWellPotentials(const Simulator& ebosSimulator,
virtual void computeWellPotentials(const Simulator& simulator,
const WellState& well_state,
std::vector<double>& well_potentials,
DeferredLogger& deferred_logger) override;
@ -128,15 +128,15 @@ namespace Opm
WellState& well_state,
DeferredLogger& deferred_logger) override; // const?
virtual void calculateExplicitQuantities(const Simulator& ebosSimulator,
virtual void calculateExplicitQuantities(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger) override; // should be const?
void updateIPRImplicit(const Simulator& ebos_simulator,
void updateIPRImplicit(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) override;
virtual void updateProductivityIndex(const Simulator& ebosSimulator,
virtual void updateProductivityIndex(const Simulator& simulator,
const WellProdIndexCalculator& wellPICalc,
WellState& well_state,
DeferredLogger& deferred_logger) const override;
@ -152,11 +152,11 @@ namespace Opm
const bool use_well_weights,
const WellState& well_state) const override;
virtual std::vector<double> computeCurrentWellRates(const Simulator& ebosSimulator,
DeferredLogger& deferred_logger) const override;
std::vector<double> computeCurrentWellRates(const Simulator& simulator,
DeferredLogger& deferred_logger) const override;
std::optional<double>
computeBhpAtThpLimitProdWithAlq(const Simulator& ebos_simulator,
computeBhpAtThpLimitProdWithAlq(const Simulator& simulator,
const SummaryState& summary_state,
const double alq_value,
DeferredLogger& deferred_logger) const override;
@ -184,10 +184,10 @@ namespace Opm
// computing the accumulation term for later use in well mass equations
void computeInitialSegmentFluids(const Simulator& ebos_simulator);
void computeInitialSegmentFluids(const Simulator& simulator);
// compute the pressure difference between the perforation and cell center
void computePerfCellPressDiffs(const Simulator& ebosSimulator);
void computePerfCellPressDiffs(const Simulator& simulator);
template<class Value>
void computePerfRate(const IntensiveQuantities& int_quants,
@ -221,42 +221,42 @@ namespace Opm
// compute the fluid properties, such as densities, viscosities, and so on, in the segments
// They will be treated implicitly, so they need to be of Evaluation type
void computeSegmentFluidProperties(const Simulator& ebosSimulator,
void computeSegmentFluidProperties(const Simulator& simulator,
DeferredLogger& deferred_logger);
// get the mobility for specific perforation
template<class Value>
void getMobility(const Simulator& ebosSimulator,
void getMobility(const Simulator& simulator,
const int perf,
std::vector<Value>& mob,
DeferredLogger& deferred_logger) const;
void computeWellRatesAtBhpLimit(const Simulator& ebosSimulator,
void computeWellRatesAtBhpLimit(const Simulator& simulator,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const;
void computeWellRatesWithBhp(const Simulator& ebosSimulator,
void computeWellRatesWithBhp(const Simulator& simulator,
const double& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const override;
void computeWellRatesWithBhpIterations(const Simulator& ebosSimulator,
void computeWellRatesWithBhpIterations(const Simulator& simulator,
const Scalar& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const override;
std::vector<double> computeWellPotentialWithTHP(
const WellState& well_state,
const Simulator& ebos_simulator,
const Simulator& simulator,
DeferredLogger& deferred_logger) const;
bool computeWellPotentialsImplicit(const Simulator& ebos_simulator,
bool computeWellPotentialsImplicit(const Simulator& simulator,
std::vector<double>& well_potentials,
DeferredLogger& deferred_logger) const;
virtual double getRefDensity() const override;
virtual bool iterateWellEqWithControl(const Simulator& ebosSimulator,
virtual bool iterateWellEqWithControl(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -264,7 +264,7 @@ namespace Opm
const GroupState& group_state,
DeferredLogger& deferred_logger) override;
virtual bool iterateWellEqWithSwitching(const Simulator& ebosSimulator,
virtual bool iterateWellEqWithSwitching(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -274,7 +274,7 @@ namespace Opm
const bool fixed_control = false,
const bool fixed_status = false) override;
virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
virtual void assembleWellEqWithoutIteration(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -284,41 +284,46 @@ namespace Opm
virtual void updateWaterThroughput(const double dt, WellState& well_state) const override;
EvalWell getSegmentSurfaceVolume(const Simulator& ebos_simulator, const int seg_idx) const;
EvalWell getSegmentSurfaceVolume(const Simulator& simulator, const int seg_idx) const;
// turn on crossflow to avoid singular well equations
// when the well is banned from cross-flow and the BHP is not properly initialized,
// we turn on crossflow to avoid singular well equations. It can result in wrong-signed
// well rates, it can cause problem for THP calculation
// TODO: looking for better alternative to avoid wrong-signed well rates
bool openCrossFlowAvoidSingularity(const Simulator& ebos_simulator) const;
bool openCrossFlowAvoidSingularity(const Simulator& simulator) const;
// for a well, when all drawdown are in the wrong direction, then this well will not
// be able to produce/inject .
bool allDrawDownWrongDirection(const Simulator& ebos_simulator) const;
bool allDrawDownWrongDirection(const Simulator& simulator) const;
std::optional<double> computeBhpAtThpLimitProd(
const WellState& well_state,
const Simulator& ebos_simulator,
const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger) const;
std::optional<double> computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
std::optional<double> computeBhpAtThpLimitInj(const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger) const;
double maxPerfPress(const Simulator& ebos_simulator) const;
double maxPerfPress(const Simulator& simulator) const;
// check whether the well is operable under BHP limit with current reservoir condition
virtual void checkOperabilityUnderBHPLimit(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) override;
void checkOperabilityUnderBHPLimit(const WellState& well_state,
const Simulator& simulator,
DeferredLogger& deferred_logger) override;
// check whether the well is operable under THP limit with current reservoir condition
virtual void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) override;
void checkOperabilityUnderTHPLimit(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger) override;
// updating the inflow based on the current reservoir condition
virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const override;
void updateIPR(const Simulator& simulator,
DeferredLogger& deferred_logger) const override;
};
}

View File

@ -171,12 +171,12 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
updateWellStateWithTarget(const Simulator& ebos_simulator,
updateWellStateWithTarget(const Simulator& simulator,
const GroupState& group_state,
WellState& well_state,
DeferredLogger& deferred_logger) const
{
Base::updateWellStateWithTarget(ebos_simulator, group_state, well_state, deferred_logger);
Base::updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
// scale segment rates based on the wellRates
// and segment pressure based on bhp
this->scaleSegmentRatesWithWellRates(this->segments_.inlets(),
@ -274,7 +274,7 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeWellPotentials(const Simulator& ebosSimulator,
computeWellPotentials(const Simulator& simulator,
const WellState& well_state,
std::vector<double>& well_potentials,
DeferredLogger& deferred_logger)
@ -289,7 +289,7 @@ namespace Opm
debug_cost_counter_ = 0;
bool converged_implicit = false;
if (this->param_.local_well_solver_control_switching_) {
converged_implicit = computeWellPotentialsImplicit(ebosSimulator, well_potentials, deferred_logger);
converged_implicit = computeWellPotentialsImplicit(simulator, well_potentials, deferred_logger);
if (!converged_implicit) {
deferred_logger.debug("Implicit potential calculations failed for well "
+ this->name() + ", reverting to original aproach.");
@ -297,12 +297,12 @@ namespace Opm
}
if (!converged_implicit) {
// does the well have a THP related constraint?
const auto& summaryState = ebosSimulator.vanguard().summaryState();
const auto& summaryState = simulator.vanguard().summaryState();
if (!Base::wellHasTHPConstraints(summaryState) || bhp_controlled_well) {
computeWellRatesAtBhpLimit(ebosSimulator, well_potentials, deferred_logger);
computeWellRatesAtBhpLimit(simulator, well_potentials, deferred_logger);
} else {
well_potentials = computeWellPotentialWithTHP(
well_state, ebosSimulator, deferred_logger);
well_state, simulator, deferred_logger);
}
}
deferred_logger.debug("Cost in iterations of finding well potential for well "
@ -319,23 +319,23 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeWellRatesAtBhpLimit(const Simulator& ebosSimulator,
computeWellRatesAtBhpLimit(const Simulator& simulator,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const
{
if (this->well_ecl_.isInjector()) {
const auto controls = this->well_ecl_.injectionControls(ebosSimulator.vanguard().summaryState());
computeWellRatesWithBhpIterations(ebosSimulator, controls.bhp_limit, well_flux, deferred_logger);
const auto controls = this->well_ecl_.injectionControls(simulator.vanguard().summaryState());
computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, well_flux, deferred_logger);
} else {
const auto controls = this->well_ecl_.productionControls(ebosSimulator.vanguard().summaryState());
computeWellRatesWithBhpIterations(ebosSimulator, controls.bhp_limit, well_flux, deferred_logger);
const auto controls = this->well_ecl_.productionControls(simulator.vanguard().summaryState());
computeWellRatesWithBhpIterations(simulator, controls.bhp_limit, well_flux, deferred_logger);
}
}
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeWellRatesWithBhp(const Simulator& ebosSimulator,
computeWellRatesWithBhp(const Simulator& simulator,
const double& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const
@ -346,7 +346,7 @@ namespace Opm
well_flux.resize(np, 0.0);
const bool allow_cf = this->getAllowCrossFlow();
const int nseg = this->numberOfSegments();
const WellState& well_state = ebosSimulator.problem().wellModel().wellState();
const WellState& well_state = simulator.problem().wellModel().wellState();
const auto& ws = well_state.well(this->indexOfWell());
auto segments_copy = ws.segments;
segments_copy.scale_pressure(bhp);
@ -354,12 +354,12 @@ namespace Opm
for (int seg = 0; seg < nseg; ++seg) {
for (const int perf : this->segments_.perforations()[seg]) {
const int cell_idx = this->well_cells_[perf];
const auto& intQuants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
// flux for each perforation
std::vector<Scalar> mob(this->num_components_, 0.);
getMobility(ebosSimulator, perf, mob, deferred_logger);
const double trans_mult = ebosSimulator.problem().template wellTransMultiplier<double>(intQuants, cell_idx);
const auto& wellstate_nupcol = ebosSimulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
getMobility(simulator, perf, mob, deferred_logger);
const double trans_mult = simulator.problem().template wellTransMultiplier<double>(intQuants, cell_idx);
const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
const std::vector<Scalar> Tw = this->wellIndex(perf, intQuants, trans_mult, wellstate_nupcol);
const Scalar seg_pressure = segment_pressure[seg];
std::vector<Scalar> cq_s(this->num_components_, 0.);
@ -380,7 +380,7 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeWellRatesWithBhpIterations(const Simulator& ebosSimulator,
computeWellRatesWithBhpIterations(const Simulator& simulator,
const Scalar& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const
@ -391,12 +391,12 @@ namespace Opm
well_copy.debug_cost_counter_ = 0;
// store a copy of the well state, we don't want to update the real well state
WellState well_state_copy = ebosSimulator.problem().wellModel().wellState();
const auto& group_state = ebosSimulator.problem().wellModel().groupState();
WellState well_state_copy = simulator.problem().wellModel().wellState();
const auto& group_state = simulator.problem().wellModel().groupState();
auto& ws = well_state_copy.well(this->index_of_well_);
// Get the current controls.
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
auto inj_controls = well_copy.well_ecl_.isInjector()
? well_copy.well_ecl_.injectionControls(summary_state)
: Well::InjectionControls(0);
@ -431,10 +431,10 @@ namespace Opm
this->segments_.perforations(),
well_state_copy);
well_copy.calculateExplicitQuantities(ebosSimulator, well_state_copy, deferred_logger);
const double dt = ebosSimulator.timeStepSize();
well_copy.calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
const double dt = simulator.timeStepSize();
// iterate to get a solution at the given bhp.
well_copy.iterateWellEqWithControl(ebosSimulator, dt, inj_controls, prod_controls, well_state_copy, group_state,
well_copy.iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, well_state_copy, group_state,
deferred_logger);
// compute the potential and store in the flux vector.
@ -454,19 +454,19 @@ namespace Opm
MultisegmentWell<TypeTag>::
computeWellPotentialWithTHP(
const WellState& well_state,
const Simulator& ebos_simulator,
const Simulator& simulator,
DeferredLogger& deferred_logger) const
{
std::vector<double> potentials(this->number_of_phases_, 0.0);
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
const auto& well = this->well_ecl_;
if (well.isInjector()){
auto bhp_at_thp_limit = computeBhpAtThpLimitInj(ebos_simulator, summary_state, deferred_logger);
auto bhp_at_thp_limit = computeBhpAtThpLimitInj(simulator, summary_state, deferred_logger);
if (bhp_at_thp_limit) {
const auto& controls = well.injectionControls(summary_state);
const double bhp = std::min(*bhp_at_thp_limit, controls.bhp_limit);
computeWellRatesWithBhpIterations(ebos_simulator, bhp, potentials, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, potentials, deferred_logger);
deferred_logger.debug("Converged thp based potential calculation for well "
+ this->name() + ", at bhp = " + std::to_string(bhp));
} else {
@ -475,15 +475,15 @@ namespace Opm
+ this->name() + ". Instead the bhp based value is used");
const auto& controls = well.injectionControls(summary_state);
const double bhp = controls.bhp_limit;
computeWellRatesWithBhpIterations(ebos_simulator, bhp, potentials, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, potentials, deferred_logger);
}
} else {
auto bhp_at_thp_limit = computeBhpAtThpLimitProd(
well_state, ebos_simulator, summary_state, deferred_logger);
well_state, simulator, summary_state, deferred_logger);
if (bhp_at_thp_limit) {
const auto& controls = well.productionControls(summary_state);
const double bhp = std::max(*bhp_at_thp_limit, controls.bhp_limit);
computeWellRatesWithBhpIterations(ebos_simulator, bhp, potentials, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, potentials, deferred_logger);
deferred_logger.debug("Converged thp based potential calculation for well "
+ this->name() + ", at bhp = " + std::to_string(bhp));
} else {
@ -492,7 +492,7 @@ namespace Opm
+ this->name() + ". Instead the bhp based value is used");
const auto& controls = well.productionControls(summary_state);
const double bhp = controls.bhp_limit;
computeWellRatesWithBhpIterations(ebos_simulator, bhp, potentials, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, potentials, deferred_logger);
}
}
@ -502,7 +502,7 @@ namespace Opm
template<typename TypeTag>
bool
MultisegmentWell<TypeTag>::
computeWellPotentialsImplicit(const Simulator& ebos_simulator,
computeWellPotentialsImplicit(const Simulator& simulator,
std::vector<double>& well_potentials,
DeferredLogger& deferred_logger) const
{
@ -513,12 +513,12 @@ namespace Opm
well_copy.debug_cost_counter_ = 0;
// store a copy of the well state, we don't want to update the real well state
WellState well_state_copy = ebos_simulator.problem().wellModel().wellState();
const auto& group_state = ebos_simulator.problem().wellModel().groupState();
WellState well_state_copy = simulator.problem().wellModel().wellState();
const auto& group_state = simulator.problem().wellModel().groupState();
auto& ws = well_state_copy.well(this->index_of_well_);
// get current controls
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
auto inj_controls = well_copy.well_ecl_.isInjector()
? well_copy.well_ecl_.injectionControls(summary_state)
: Well::InjectionControls(0);
@ -547,14 +547,14 @@ namespace Opm
this->segments_.perforations(),
well_state_copy);
well_copy.calculateExplicitQuantities(ebos_simulator, well_state_copy, deferred_logger);
const double dt = ebos_simulator.timeStepSize();
well_copy.calculateExplicitQuantities(simulator, well_state_copy, deferred_logger);
const double dt = simulator.timeStepSize();
// solve equations
bool converged = false;
if (this->well_ecl_.isProducer() && this->wellHasTHPConstraints(summary_state)) {
converged = well_copy.solveWellWithTHPConstraint(ebos_simulator, dt, inj_controls, prod_controls, well_state_copy, group_state, deferred_logger);
converged = well_copy.solveWellWithTHPConstraint(simulator, dt, inj_controls, prod_controls, well_state_copy, group_state, deferred_logger);
} else {
converged = well_copy.iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state_copy, group_state, deferred_logger);
converged = well_copy.iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state_copy, group_state, deferred_logger);
}
// fetch potentials (sign is updated on the outside).
@ -601,7 +601,7 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
computePerfCellPressDiffs(const Simulator& ebosSimulator)
computePerfCellPressDiffs(const Simulator& simulator)
{
for (int perf = 0; perf < this->number_of_perforations_; ++perf) {
@ -609,7 +609,7 @@ namespace Opm
std::vector<double> density(this->number_of_phases_, 0.0);
const int cell_idx = this->well_cells_[perf];
const auto& intQuants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& fs = intQuants.fluidState();
double sum_kr = 0.;
@ -656,11 +656,11 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeInitialSegmentFluids(const Simulator& ebos_simulator)
computeInitialSegmentFluids(const Simulator& simulator)
{
for (int seg = 0; seg < this->numberOfSegments(); ++seg) {
// TODO: trying to reduce the times for the surfaceVolumeFraction calculation
const double surface_volume = getSegmentSurfaceVolume(ebos_simulator, seg).value();
const double surface_volume = getSegmentSurfaceVolume(simulator, seg).value();
for (int comp_idx = 0; comp_idx < this->num_components_; ++comp_idx) {
segment_fluid_initial_[seg][comp_idx] = surface_volume * this->primary_variables_.surfaceVolumeFraction(seg, comp_idx).value();
}
@ -709,15 +709,15 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
calculateExplicitQuantities(const Simulator& ebosSimulator,
calculateExplicitQuantities(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger)
{
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
updatePrimaryVariables(summary_state, well_state, deferred_logger);
initPrimaryVariablesEvaluation();
computePerfCellPressDiffs(ebosSimulator);
computeInitialSegmentFluids(ebosSimulator);
computePerfCellPressDiffs(simulator);
computeInitialSegmentFluids(simulator);
}
@ -727,15 +727,15 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
updateProductivityIndex(const Simulator& ebosSimulator,
updateProductivityIndex(const Simulator& simulator,
const WellProdIndexCalculator& wellPICalc,
WellState& well_state,
DeferredLogger& deferred_logger) const
{
auto fluidState = [&ebosSimulator, this](const int perf)
auto fluidState = [&simulator, this](const int perf)
{
const auto cell_idx = this->well_cells_[perf];
return ebosSimulator.model()
return simulator.model()
.intensiveQuantities(cell_idx, /*timeIdx=*/ 0).fluidState();
};
@ -769,7 +769,7 @@ namespace Opm
};
std::vector<Scalar> mob(this->num_components_, 0.0);
getMobility(ebosSimulator, static_cast<int>(subsetPerfID), mob, deferred_logger);
getMobility(simulator, static_cast<int>(subsetPerfID), mob, deferred_logger);
const auto& fs = fluidState(subsetPerfID);
setToZero(connPI);
@ -1064,7 +1064,7 @@ namespace Opm
template <typename TypeTag>
void
MultisegmentWell<TypeTag>::
computeSegmentFluidProperties(const Simulator& ebosSimulator, DeferredLogger& deferred_logger)
computeSegmentFluidProperties(const Simulator& simulator, DeferredLogger& deferred_logger)
{
// TODO: the concept of phases and components are rather confusing in this function.
// needs to be addressed sooner or later.
@ -1084,7 +1084,7 @@ namespace Opm
{
// using the first perforated cell
const int cell_idx = this->well_cells_[0];
const auto& intQuants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
temperature.setValue(fs.temperature(FluidSystem::oilPhaseIdx).value());
saltConcentration = this->extendEval(fs.saltConcentration());
@ -1102,7 +1102,7 @@ namespace Opm
template<class Value>
void
MultisegmentWell<TypeTag>::
getMobility(const Simulator& ebosSimulator,
getMobility(const Simulator& simulator,
const int perf,
std::vector<Value>& mob,
DeferredLogger& deferred_logger) const
@ -1117,7 +1117,7 @@ namespace Opm
}
};
WellInterface<TypeTag>::getMobility(ebosSimulator, perf, mob, obtain, deferred_logger);
WellInterface<TypeTag>::getMobility(simulator, perf, mob, obtain, deferred_logger);
if (this->isInjector() && this->well_ecl_.getInjMultMode() != Well::InjMultMode::NONE) {
const auto perf_ecl_index = this->perforationData()[perf].ecl_index;
@ -1150,9 +1150,9 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
checkOperabilityUnderBHPLimit(const WellState& /*well_state*/, const Simulator& ebos_simulator, DeferredLogger& deferred_logger)
checkOperabilityUnderBHPLimit(const WellState& /*well_state*/, const Simulator& simulator, DeferredLogger& deferred_logger)
{
const auto& summaryState = ebos_simulator.vanguard().summaryState();
const auto& summaryState = simulator.vanguard().summaryState();
const double bhp_limit = WellBhpThpCalculator(*this).mostStrictBhpFromBhpLimits(summaryState);
// Crude but works: default is one atmosphere.
// TODO: a better way to detect whether the BHP is defaulted or not
@ -1183,7 +1183,7 @@ namespace Opm
// option 2: stick with the above IPR curve
// we use IPR here
std::vector<double> well_rates_bhp_limit;
computeWellRatesWithBhp(ebos_simulator, bhp_limit, well_rates_bhp_limit, deferred_logger);
computeWellRatesWithBhp(simulator, bhp_limit, well_rates_bhp_limit, deferred_logger);
const double thp_limit = this->getTHPConstraint(summaryState);
const double thp = WellBhpThpCalculator(*this).calculateThpFromBhp(well_rates_bhp_limit,
@ -1214,7 +1214,7 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const
updateIPR(const Simulator& simulator, DeferredLogger& deferred_logger) const
{
// TODO: not handling solvent related here for now
@ -1234,10 +1234,10 @@ namespace Opm
std::vector<Scalar> mob(this->num_components_, 0.0);
// TODO: maybe we should store the mobility somewhere, so that we only need to calculate it one per iteration
getMobility(ebos_simulator, perf, mob, deferred_logger);
getMobility(simulator, perf, mob, deferred_logger);
const int cell_idx = this->well_cells_[perf];
const auto& int_quantities = ebos_simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& int_quantities = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& fs = int_quantities.fluidState();
// pressure difference between the segment and the perforation
const double perf_seg_press_diff = this->segments_.getPressureDiffSegPerf(seg, perf);
@ -1266,8 +1266,8 @@ namespace Opm
}
// the well index associated with the connection
const double trans_mult = ebos_simulator.problem().template wellTransMultiplier<double>(int_quantities, cell_idx);
const auto& wellstate_nupcol = ebos_simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
const double trans_mult = simulator.problem().template wellTransMultiplier<double>(int_quantities, cell_idx);
const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
const std::vector<Scalar> tw_perf = this->wellIndex(perf, int_quantities, trans_mult, wellstate_nupcol);
std::vector<double> ipr_a_perf(this->ipr_a_.size());
std::vector<double> ipr_b_perf(this->ipr_b_.size());
@ -1308,7 +1308,7 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
updateIPRImplicit(const Simulator& ebos_simulator, WellState& well_state, DeferredLogger& deferred_logger)
updateIPRImplicit(const Simulator& simulator, WellState& well_state, DeferredLogger& deferred_logger)
{
// Compute IPR based on *converged* well-equation:
// For a component rate r the derivative dr/dbhp is obtained by
@ -1328,16 +1328,16 @@ namespace Opm
deferred_logger.debug(msg);
/*
// could revert to standard approach here:
updateIPR(ebos_simulator, deferred_logger);
updateIPR(simulator, deferred_logger);
for (int comp_idx = 0; comp_idx < this->num_components_; ++comp_idx){
const int idx = this->ebosCompIdxToFlowCompIdx(comp_idx);
const int idx = this->modelCompIdxToFlowCompIdx(comp_idx);
ws.implicit_ipr_a[idx] = this->ipr_a_[comp_idx];
ws.implicit_ipr_b[idx] = this->ipr_b_[comp_idx];
}
return;
*/
}
const auto& group_state = ebos_simulator.problem().wellModel().groupState();
const auto& group_state = simulator.problem().wellModel().groupState();
std::fill(ws.implicit_ipr_a.begin(), ws.implicit_ipr_a.end(), 0.);
std::fill(ws.implicit_ipr_b.begin(), ws.implicit_ipr_b.end(), 0.);
@ -1350,8 +1350,8 @@ namespace Opm
// Set current control to bhp, and bhp value in state, modify bhp limit in control object.
const auto cmode = ws.production_cmode;
ws.production_cmode = Well::ProducerCMode::BHP;
const double dt = ebos_simulator.timeStepSize();
assembleWellEqWithoutIteration(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
const double dt = simulator.timeStepSize();
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
BVectorWell rhs(this->numberOfSegments());
rhs = 0.0;
@ -1376,15 +1376,15 @@ namespace Opm
void
MultisegmentWell<TypeTag>::
checkOperabilityUnderTHPLimit(
const Simulator& ebos_simulator,
const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger)
{
const auto& summaryState = ebos_simulator.vanguard().summaryState();
const auto& summaryState = simulator.vanguard().summaryState();
const auto obtain_bhp = this->isProducer()
? computeBhpAtThpLimitProd(
well_state, ebos_simulator, summaryState, deferred_logger)
: computeBhpAtThpLimitInj(ebos_simulator, summaryState, deferred_logger);
well_state, simulator, summaryState, deferred_logger)
: computeBhpAtThpLimitInj(simulator, summaryState, deferred_logger);
if (obtain_bhp) {
this->operability_status_.can_obtain_bhp_with_thp_limit = true;
@ -1428,7 +1428,7 @@ namespace Opm
template<typename TypeTag>
bool
MultisegmentWell<TypeTag>::
iterateWellEqWithControl(const Simulator& ebosSimulator,
iterateWellEqWithControl(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -1459,7 +1459,7 @@ namespace Opm
this->regularize_ = false;
for (; it < max_iter_number; ++it, ++debug_cost_counter_) {
assembleWellEqWithoutIteration(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
BVectorWell dx_well;
try{
@ -1479,7 +1479,7 @@ namespace Opm
this->regularize_ = true;
}
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
const auto report = getWellConvergence(summary_state, well_state, Base::B_avg_, deferred_logger, relax_convergence);
if (report.converged()) {
converged = true;
@ -1580,7 +1580,7 @@ namespace Opm
template<typename TypeTag>
bool
MultisegmentWell<TypeTag>::
iterateWellEqWithSwitching(const Simulator& ebosSimulator,
iterateWellEqWithSwitching(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -1609,7 +1609,7 @@ namespace Opm
[[maybe_unused]] int stagnate_count = 0;
bool relax_convergence = false;
this->regularize_ = false;
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
// Always take a few (more than one) iterations after a switch before allowing a new switch
// The optimal number here is subject to further investigation, but it has been observerved
@ -1637,7 +1637,7 @@ namespace Opm
its_since_last_switch++;
if (allow_switching && its_since_last_switch >= min_its_after_switch){
const double wqTotal = this->primary_variables_.getWQTotal().value();
changed = this->updateWellControlAndStatusLocalIteration(ebosSimulator, well_state, group_state, inj_controls, prod_controls, wqTotal, deferred_logger, fixed_control, fixed_status);
changed = this->updateWellControlAndStatusLocalIteration(simulator, well_state, group_state, inj_controls, prod_controls, wqTotal, deferred_logger, fixed_control, fixed_status);
if (changed){
its_since_last_switch = 0;
switch_count++;
@ -1652,7 +1652,7 @@ namespace Opm
}
}
assembleWellEqWithoutIteration(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
const BVectorWell dx_well = this->linSys_.solve();
@ -1771,7 +1771,7 @@ namespace Opm
template<typename TypeTag>
void
MultisegmentWell<TypeTag>::
assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
assembleWellEqWithoutIteration(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -1785,7 +1785,7 @@ namespace Opm
this->segments_.updateUpwindingSegments(this->primary_variables_);
// calculate the fluid properties needed.
computeSegmentFluidProperties(ebosSimulator, deferred_logger);
computeSegmentFluidProperties(simulator, deferred_logger);
// clear all entries
this->linSys_.clear();
@ -1798,7 +1798,7 @@ namespace Opm
//
// but for the top segment, the pressure equation will be the well control equation, and the other three will be the same.
const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(ebosSimulator);
const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
const int nseg = this->numberOfSegments();
@ -1806,7 +1806,7 @@ namespace Opm
// calculating the accumulation term
// TODO: without considering the efficiency factor for now
{
const EvalWell segment_surface_volume = getSegmentSurfaceVolume(ebosSimulator, seg);
const EvalWell segment_surface_volume = getSegmentSurfaceVolume(simulator, seg);
// Add a regularization_factor to increase the accumulation term
// This will make the system less stiff and help convergence for
@ -1857,11 +1857,11 @@ namespace Opm
auto& perf_press_state = perf_data.pressure;
for (const int perf : this->segments_.perforations()[seg]) {
const int cell_idx = this->well_cells_[perf];
const auto& int_quants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
std::vector<EvalWell> mob(this->num_components_, 0.0);
getMobility(ebosSimulator, perf, mob, deferred_logger);
const double trans_mult = ebosSimulator.problem().template wellTransMultiplier<double>(int_quants, cell_idx);
const auto& wellstate_nupcol = ebosSimulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
getMobility(simulator, perf, mob, deferred_logger);
const double trans_mult = simulator.problem().template wellTransMultiplier<double>(int_quants, cell_idx);
const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
const std::vector<Scalar> Tw = this->wellIndex(perf, int_quants, trans_mult, wellstate_nupcol);
std::vector<EvalWell> cq_s(this->num_components_, 0.0);
EvalWell perf_press;
@ -1896,8 +1896,8 @@ namespace Opm
// the fourth dequation, the pressure drop equation
if (seg == 0) { // top segment, pressure equation is the control equation
const auto& summaryState = ebosSimulator.vanguard().summaryState();
const Schedule& schedule = ebosSimulator.vanguard().schedule();
const auto& summaryState = simulator.vanguard().summaryState();
const Schedule& schedule = simulator.vanguard().schedule();
MultisegmentWellAssemble(*this).
assembleControlEq(well_state,
group_state,
@ -1910,8 +1910,8 @@ namespace Opm
this->linSys_,
deferred_logger);
} else {
const UnitSystem& unit_system = ebosSimulator.vanguard().eclState().getDeckUnitSystem();
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const UnitSystem& unit_system = simulator.vanguard().eclState().getDeckUnitSystem();
const auto& summary_state = simulator.vanguard().summaryState();
this->assemblePressureEq(seg, unit_system, well_state, summary_state, this->param_.use_average_density_ms_wells_, deferred_logger);
}
}
@ -1925,16 +1925,16 @@ namespace Opm
template<typename TypeTag>
bool
MultisegmentWell<TypeTag>::
openCrossFlowAvoidSingularity(const Simulator& ebos_simulator) const
openCrossFlowAvoidSingularity(const Simulator& simulator) const
{
return !this->getAllowCrossFlow() && allDrawDownWrongDirection(ebos_simulator);
return !this->getAllowCrossFlow() && allDrawDownWrongDirection(simulator);
}
template<typename TypeTag>
bool
MultisegmentWell<TypeTag>::
allDrawDownWrongDirection(const Simulator& ebos_simulator) const
allDrawDownWrongDirection(const Simulator& simulator) const
{
bool all_drawdown_wrong_direction = true;
const int nseg = this->numberOfSegments();
@ -1944,7 +1944,7 @@ namespace Opm
for (const int perf : this->segments_.perforations()[seg]) {
const int cell_idx = this->well_cells_[perf];
const auto& intQuants = ebos_simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& fs = intQuants.fluidState();
// pressure difference between the segment and the perforation
@ -1989,7 +1989,7 @@ namespace Opm
template<typename TypeTag>
typename MultisegmentWell<TypeTag>::EvalWell
MultisegmentWell<TypeTag>::
getSegmentSurfaceVolume(const Simulator& ebos_simulator, const int seg_idx) const
getSegmentSurfaceVolume(const Simulator& simulator, const int seg_idx) const
{
EvalWell temperature;
EvalWell saltConcentration;
@ -1998,7 +1998,7 @@ namespace Opm
// using the pvt region of first perforated cell
// TODO: it should be a member of the WellInterface, initialized properly
const int cell_idx = this->well_cells_[0];
const auto& intQuants = ebos_simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
temperature.setValue(fs.temperature(FluidSystem::oilPhaseIdx).value());
saltConcentration = this->extendEval(fs.saltConcentration());
@ -2017,12 +2017,12 @@ namespace Opm
std::optional<double>
MultisegmentWell<TypeTag>::
computeBhpAtThpLimitProd(const WellState& well_state,
const Simulator& ebos_simulator,
const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger) const
{
return this->MultisegmentWell<TypeTag>::computeBhpAtThpLimitProdWithAlq(
ebos_simulator,
simulator,
summary_state,
this->getALQ(well_state),
deferred_logger);
@ -2033,27 +2033,27 @@ namespace Opm
template<typename TypeTag>
std::optional<double>
MultisegmentWell<TypeTag>::
computeBhpAtThpLimitProdWithAlq(const Simulator& ebos_simulator,
computeBhpAtThpLimitProdWithAlq(const Simulator& simulator,
const SummaryState& summary_state,
const double alq_value,
DeferredLogger& deferred_logger) const
{
// Make the frates() function.
auto frates = [this, &ebos_simulator, &deferred_logger](const double bhp) {
auto frates = [this, &simulator, &deferred_logger](const double bhp) {
// Not solving the well equations here, which means we are
// calculating at the current Fg/Fw values of the
// well. This does not matter unless the well is
// crossflowing, and then it is likely still a good
// approximation.
std::vector<double> rates(3);
computeWellRatesWithBhp(ebos_simulator, bhp, rates, deferred_logger);
computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
return rates;
};
auto bhpAtLimit = WellBhpThpCalculator(*this).
computeBhpAtThpLimitProd(frates,
summary_state,
this->maxPerfPress(ebos_simulator),
this->maxPerfPress(simulator),
this->getRefDensity(),
alq_value,
this->getTHPConstraint(summary_state),
@ -2062,19 +2062,19 @@ namespace Opm
if (bhpAtLimit)
return bhpAtLimit;
auto fratesIter = [this, &ebos_simulator, &deferred_logger](const double bhp) {
auto fratesIter = [this, &simulator, &deferred_logger](const double bhp) {
// Solver the well iterations to see if we are
// able to get a solution with an update
// solution
std::vector<double> rates(3);
computeWellRatesWithBhpIterations(ebos_simulator, bhp, rates, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, rates, deferred_logger);
return rates;
};
return WellBhpThpCalculator(*this).
computeBhpAtThpLimitProd(fratesIter,
summary_state,
this->maxPerfPress(ebos_simulator),
this->maxPerfPress(simulator),
this->getRefDensity(),
alq_value,
this->getTHPConstraint(summary_state),
@ -2084,19 +2084,19 @@ namespace Opm
template<typename TypeTag>
std::optional<double>
MultisegmentWell<TypeTag>::
computeBhpAtThpLimitInj(const Simulator& ebos_simulator,
computeBhpAtThpLimitInj(const Simulator& simulator,
const SummaryState& summary_state,
DeferredLogger& deferred_logger) const
{
// Make the frates() function.
auto frates = [this, &ebos_simulator, &deferred_logger](const double bhp) {
auto frates = [this, &simulator, &deferred_logger](const double bhp) {
// Not solving the well equations here, which means we are
// calculating at the current Fg/Fw values of the
// well. This does not matter unless the well is
// crossflowing, and then it is likely still a good
// approximation.
std::vector<double> rates(3);
computeWellRatesWithBhp(ebos_simulator, bhp, rates, deferred_logger);
computeWellRatesWithBhp(simulator, bhp, rates, deferred_logger);
return rates;
};
@ -2112,12 +2112,12 @@ namespace Opm
if (bhpAtLimit)
return bhpAtLimit;
auto fratesIter = [this, &ebos_simulator, &deferred_logger](const double bhp) {
auto fratesIter = [this, &simulator, &deferred_logger](const double bhp) {
// Solver the well iterations to see if we are
// able to get a solution with an update
// solution
std::vector<double> rates(3);
computeWellRatesWithBhpIterations(ebos_simulator, bhp, rates, deferred_logger);
computeWellRatesWithBhpIterations(simulator, bhp, rates, deferred_logger);
return rates;
};
@ -2138,14 +2138,14 @@ namespace Opm
template<typename TypeTag>
double
MultisegmentWell<TypeTag>::
maxPerfPress(const Simulator& ebos_simulator) const
maxPerfPress(const Simulator& simulator) const
{
double max_pressure = 0.0;
const int nseg = this->numberOfSegments();
for (int seg = 0; seg < nseg; ++seg) {
for (const int perf : this->segments_.perforations()[seg]) {
const int cell_idx = this->well_cells_[perf];
const auto& int_quants = ebos_simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& fs = int_quants.fluidState();
double pressure_cell = this->getPerfCellPressure(fs).value();
max_pressure = std::max(max_pressure, pressure_cell);
@ -2161,23 +2161,23 @@ namespace Opm
template<typename TypeTag>
std::vector<double>
MultisegmentWell<TypeTag>::
computeCurrentWellRates(const Simulator& ebosSimulator,
computeCurrentWellRates(const Simulator& simulator,
DeferredLogger& deferred_logger) const
{
// Calculate the rates that follow from the current primary variables.
std::vector<Scalar> well_q_s(this->num_components_, 0.0);
const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(ebosSimulator);
const bool allow_cf = this->getAllowCrossFlow() || openCrossFlowAvoidSingularity(simulator);
const int nseg = this->numberOfSegments();
for (int seg = 0; seg < nseg; ++seg) {
// calculating the perforation rate for each perforation that belongs to this segment
const Scalar seg_pressure = getValue(this->primary_variables_.getSegmentPressure(seg));
for (const int perf : this->segments_.perforations()[seg]) {
const int cell_idx = this->well_cells_[perf];
const auto& int_quants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
const auto& int_quants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/ 0);
std::vector<Scalar> mob(this->num_components_, 0.0);
getMobility(ebosSimulator, perf, mob, deferred_logger);
const double trans_mult = ebosSimulator.problem().template wellTransMultiplier<double>(int_quants, cell_idx);
const auto& wellstate_nupcol = ebosSimulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
getMobility(simulator, perf, mob, deferred_logger);
const double trans_mult = simulator.problem().template wellTransMultiplier<double>(int_quants, cell_idx);
const auto& wellstate_nupcol = simulator.problem().wellModel().nupcolWellState().well(this->index_of_well_);
const std::vector<Scalar> Tw = this->wellIndex(perf, int_quants, trans_mult, wellstate_nupcol);
std::vector<Scalar> cq_s(this->num_components_, 0.0);
Scalar perf_press = 0.0;

View File

@ -169,20 +169,20 @@ public:
WellState& well_state,
DeferredLogger& deferred_logger) = 0;
void assembleWellEq(const Simulator& ebosSimulator,
void assembleWellEq(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger);
void assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
void assembleWellEqWithoutIteration(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger);
// TODO: better name or further refactoring the function to make it more clear
void prepareWellBeforeAssembling(const Simulator& ebosSimulator,
void prepareWellBeforeAssembling(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
@ -190,14 +190,14 @@ public:
virtual void computeWellRatesWithBhp(
const Simulator& ebosSimulator,
const Simulator& simulator,
const double& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger
) const = 0;
virtual std::optional<double> computeBhpAtThpLimitProdWithAlq(
const Simulator& ebos_simulator,
const Simulator& simulator,
const SummaryState& summary_state,
const double alq_value,
DeferredLogger& deferred_logger
@ -217,33 +217,33 @@ public:
virtual void apply(BVector& r) const = 0;
// TODO: before we decide to put more information under mutable, this function is not const
virtual void computeWellPotentials(const Simulator& ebosSimulator,
virtual void computeWellPotentials(const Simulator& simulator,
const WellState& well_state,
std::vector<double>& well_potentials,
DeferredLogger& deferred_logger) = 0;
virtual void updateWellStateWithTarget(const Simulator& ebos_simulator,
virtual void updateWellStateWithTarget(const Simulator& simulator,
const GroupState& group_state,
WellState& well_state,
DeferredLogger& deferred_logger) const;
virtual void computeWellRatesWithBhpIterations(const Simulator& ebosSimulator,
virtual void computeWellRatesWithBhpIterations(const Simulator& simulator,
const Scalar& bhp,
std::vector<double>& well_flux,
DeferredLogger& deferred_logger) const = 0;
bool updateWellStateWithTHPTargetProd(const Simulator& ebos_simulator,
bool updateWellStateWithTHPTargetProd(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) const;
enum class IndividualOrGroup { Individual, Group, Both };
bool updateWellControl(const Simulator& ebos_simulator,
bool updateWellControl(const Simulator& simulator,
const IndividualOrGroup iog,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger) /* const */;
bool updateWellControlAndStatusLocalIteration(const Simulator& ebos_simulator,
bool updateWellControlAndStatusLocalIteration(const Simulator& simulator,
WellState& well_state,
const GroupState& group_state,
const Well::InjectionControls& inj_controls,
@ -257,11 +257,11 @@ public:
const WellState& well_state,
DeferredLogger& deferred_logger) = 0;
virtual void calculateExplicitQuantities(const Simulator& ebosSimulator,
virtual void calculateExplicitQuantities(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger) = 0; // should be const?
virtual void updateProductivityIndex(const Simulator& ebosSimulator,
virtual void updateProductivityIndex(const Simulator& simulator,
const WellProdIndexCalculator& wellPICalc,
WellState& well_state,
DeferredLogger& deferred_logger) const = 0;
@ -295,26 +295,28 @@ public:
/* const */ WellState& well_state, const GroupState& group_state, WellTestState& welltest_state,
DeferredLogger& deferred_logger);
void checkWellOperability(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger);
void checkWellOperability(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger);
bool gliftBeginTimeStepWellTestIterateWellEquations(
const Simulator& ebos_simulator,
const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState &group_state,
DeferredLogger& deferred_logger);
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator& ebos_simulator,
void gliftBeginTimeStepWellTestUpdateALQ(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger);
// check whether the well is operable under the current reservoir condition
// mostly related to BHP limit and THP limit
void updateWellOperability(const Simulator& ebos_simulator,
void updateWellOperability(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger);
bool updateWellOperabilityFromWellEq(const Simulator& ebos_simulator,
bool updateWellOperabilityFromWellEq(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger);
@ -323,17 +325,17 @@ public:
/// Compute well rates based on current reservoir conditions and well variables.
/// Used in updateWellStateRates().
virtual std::vector<double> computeCurrentWellRates(const Simulator& ebosSimulator,
virtual std::vector<double> computeCurrentWellRates(const Simulator& simulator,
DeferredLogger& deferred_logger) const = 0;
/// Modify the well_state's rates if there is only one nonzero rate.
/// If so, that rate is kept as is, but the others are set proportionally
/// to the rates returned by computeCurrentWellRates().
void updateWellStateRates(const Simulator& ebosSimulator,
void updateWellStateRates(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) const;
void solveWellEquation(const Simulator& ebosSimulator,
void solveWellEquation(const Simulator& simulator,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger);
@ -385,17 +387,23 @@ protected:
// Component fractions for each phase for the well
const std::vector<double>& compFrac() const;
std::vector<double> initialWellRateFractions(const Simulator& ebosSimulator, const WellState& well_state) const;
std::vector<double> initialWellRateFractions(const Simulator& simulator,
const WellState& well_state) const;
// check whether the well is operable under BHP limit with current reservoir condition
virtual void checkOperabilityUnderBHPLimit(const WellState& well_state, const Simulator& ebos_simulator, DeferredLogger& deferred_logger) =0;
virtual void checkOperabilityUnderBHPLimit(const WellState& well_state,
const Simulator& simulator,
DeferredLogger& deferred_logger) = 0;
// check whether the well is operable under THP limit with current reservoir condition
virtual void checkOperabilityUnderTHPLimit(const Simulator& ebos_simulator, const WellState& well_state, DeferredLogger& deferred_logger) =0;
virtual void checkOperabilityUnderTHPLimit(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger) = 0;
virtual void updateIPR(const Simulator& ebos_simulator, DeferredLogger& deferred_logger) const=0;
virtual void updateIPR(const Simulator& simulator,
DeferredLogger& deferred_logger) const=0;
virtual void assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
virtual void assembleWellEqWithoutIteration(const Simulator& simulator,
const double dt,
const WellInjectionControls& inj_controls,
const WellProductionControls& prod_controls,
@ -404,7 +412,7 @@ protected:
DeferredLogger& deferred_logger) = 0;
// iterate well equations with the specified control until converged
virtual bool iterateWellEqWithControl(const Simulator& ebosSimulator,
virtual bool iterateWellEqWithControl(const Simulator& simulator,
const double dt,
const WellInjectionControls& inj_controls,
const WellProductionControls& prod_controls,
@ -412,7 +420,7 @@ protected:
const GroupState& group_state,
DeferredLogger& deferred_logger) = 0;
virtual bool iterateWellEqWithSwitching(const Simulator& ebosSimulator,
virtual bool iterateWellEqWithSwitching(const Simulator& simulator,
const double dt,
const WellInjectionControls& inj_controls,
const WellProductionControls& prod_controls,
@ -422,17 +430,17 @@ protected:
const bool fixed_control = false,
const bool fixed_status = false) = 0;
virtual void updateIPRImplicit(const Simulator& ebosSimulator,
virtual void updateIPRImplicit(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) = 0;
bool iterateWellEquations(const Simulator& ebosSimulator,
bool iterateWellEquations(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger);
bool solveWellWithTHPConstraint(const Simulator& ebos_simulator,
bool solveWellWithTHPConstraint(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -440,31 +448,33 @@ protected:
const GroupState& group_state,
DeferredLogger& deferred_logger);
std::optional<double> estimateOperableBhp(const Simulator& ebos_simulator,
std::optional<double> estimateOperableBhp(const Simulator& simulator,
const double dt,
WellState& well_state,
const SummaryState& summary_state,
DeferredLogger& deferred_logger);
bool solveWellWithBhp(const Simulator& ebos_simulator,
bool solveWellWithBhp(const Simulator& simulator,
const double dt,
const double bhp,
WellState& well_state,
DeferredLogger& deferred_logger);
bool solveWellWithZeroRate(const Simulator& ebos_simulator,
bool solveWellWithZeroRate(const Simulator& simulator,
const double dt,
WellState& well_state,
DeferredLogger& deferred_logger);
bool solveWellForTesting(const Simulator& ebosSimulator, WellState& well_state, const GroupState& group_state,
bool solveWellForTesting(const Simulator& simulator,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger);
Eval getPerfCellPressure(const FluidState& fs) const;
// get the mobility for specific perforation
template<class Value, class Callback>
void getMobility(const Simulator& ebosSimulator,
void getMobility(const Simulator& simulator,
const int perf,
std::vector<Value>& mob,
Callback& extendEval,

View File

@ -184,19 +184,19 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
updateWellControl(const Simulator& ebos_simulator,
updateWellControl(const Simulator& simulator,
const IndividualOrGroup iog,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger) /* const */
{
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
if (this->stopppedOrZeroRateTarget(summary_state, well_state)) {
return false;
}
const auto& summaryState = ebos_simulator.vanguard().summaryState();
const auto& schedule = ebos_simulator.vanguard().schedule();
const auto& summaryState = simulator.vanguard().summaryState();
const auto& schedule = simulator.vanguard().schedule();
const auto& well = this->well_ecl_;
auto& ws = well_state.well(this->index_of_well_);
std::string from;
@ -232,7 +232,7 @@ namespace Opm
assert(iog == IndividualOrGroup::Both);
changed = this->checkConstraints(well_state, group_state, schedule, summaryState, deferred_logger);
}
Parallel::Communication cc = ebos_simulator.vanguard().grid().comm();
Parallel::Communication cc = simulator.vanguard().grid().comm();
// checking whether control changed
if (changed) {
std::string to;
@ -251,7 +251,7 @@ namespace Opm
deferred_logger.debug(ss.str());
this->well_control_log_.push_back(from);
updateWellStateWithTarget(ebos_simulator, group_state, well_state, deferred_logger);
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
updatePrimaryVariables(summaryState, well_state, deferred_logger);
}
@ -261,7 +261,7 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
updateWellControlAndStatusLocalIteration(const Simulator& ebos_simulator,
updateWellControlAndStatusLocalIteration(const Simulator& simulator,
WellState& well_state,
const GroupState& group_state,
const Well::InjectionControls& inj_controls,
@ -271,8 +271,8 @@ namespace Opm
const bool fixed_control,
const bool fixed_status)
{
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& schedule = ebos_simulator.vanguard().schedule();
const auto& summary_state = simulator.vanguard().summaryState();
const auto& schedule = simulator.vanguard().schedule();
if (this->wellUnderZeroRateTarget(summary_state, well_state) || !(this->well_ecl_.getStatus() == WellStatus::OPEN)) {
return false;
@ -300,7 +300,7 @@ namespace Opm
ws.production_cmode == Well::ProducerCMode::THP;
if (!thp_controlled){
// don't call for thp since this might trigger additional local solve
updateWellStateWithTarget(ebos_simulator, group_state, well_state, deferred_logger);
updateWellStateWithTarget(simulator, group_state, well_state, deferred_logger);
} else {
ws.thp = this->getTHPConstraint(summary_state);
}
@ -443,25 +443,25 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
iterateWellEquations(const Simulator& ebosSimulator,
iterateWellEquations(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger)
{
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
bool converged = false;
try {
// TODO: the following two functions will be refactored to be one to reduce the code duplication
if (!this->param_.local_well_solver_control_switching_){
converged = this->iterateWellEqWithControl(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = this->iterateWellEqWithControl(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
} else {
if (this->param_.use_implicit_ipr_ && this->well_ecl_.isProducer() && this->wellHasTHPConstraints(summary_state) && (this->well_ecl_.getStatus() == WellStatus::OPEN)) {
converged = solveWellWithTHPConstraint(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = solveWellWithTHPConstraint(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
} else {
converged = this->iterateWellEqWithSwitching(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
}
}
@ -476,7 +476,7 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
solveWellWithTHPConstraint(const Simulator& ebos_simulator,
solveWellWithTHPConstraint(const Simulator& simulator,
const double dt,
const Well::InjectionControls& inj_controls,
const Well::ProductionControls& prod_controls,
@ -484,32 +484,32 @@ namespace Opm
const GroupState& group_state,
DeferredLogger& deferred_logger)
{
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
bool is_operable = true;
bool converged = true;
auto& ws = well_state.well(this->index_of_well_);
// if well is stopped, check if we can reopen
if (this->wellIsStopped()) {
this->openWell();
auto bhp_target = estimateOperableBhp(ebos_simulator, dt, well_state, summary_state, deferred_logger);
auto bhp_target = estimateOperableBhp(simulator, dt, well_state, summary_state, deferred_logger);
if (!bhp_target.has_value()) {
// no intersection with ipr
const auto msg = fmt::format("estimateOperableBhp: Did not find operable BHP for well {}", this->name());
deferred_logger.debug(msg);
is_operable = false;
// solve with zero rates
solveWellWithZeroRate(ebos_simulator, dt, well_state, deferred_logger);
solveWellWithZeroRate(simulator, dt, well_state, deferred_logger);
this->stopWell();
} else {
// solve well with the estimated target bhp (or limit)
ws.thp = this->getTHPConstraint(summary_state);
const double bhp = std::max(bhp_target.value(), prod_controls.bhp_limit);
solveWellWithBhp(ebos_simulator, dt, bhp, well_state, deferred_logger);
solveWellWithBhp(simulator, dt, bhp, well_state, deferred_logger);
}
}
// solve well-equation
if (is_operable) {
converged = this->iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
}
const bool isThp = ws.production_cmode == Well::ProducerCMode::THP;
@ -517,7 +517,7 @@ namespace Opm
if (converged && !this->stopppedOrZeroRateTarget(summary_state, well_state) && isThp) {
auto rates = well_state.well(this->index_of_well_).surface_rates;
this->adaptRatesForVFP(rates);
this->updateIPRImplicit(ebos_simulator, well_state, deferred_logger);
this->updateIPRImplicit(simulator, well_state, deferred_logger);
bool is_stable = WellBhpThpCalculator(*this).isStableSolution(well_state, this->well_ecl_, rates, summary_state);
if (!is_stable) {
// solution converged to an unstable point!
@ -529,10 +529,10 @@ namespace Opm
if (bhp_stable.has_value() && cur_bhp - bhp_stable.value() > cur_bhp*reltol){
const auto msg = fmt::format("Well {} converged to an unstable solution, re-solving", this->name());
deferred_logger.debug(msg);
solveWellWithBhp(ebos_simulator, dt, bhp_stable.value(), well_state, deferred_logger);
solveWellWithBhp(simulator, dt, bhp_stable.value(), well_state, deferred_logger);
// re-solve with hopefully good initial guess
ws.thp = this->getTHPConstraint(summary_state);
converged = this->iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
}
}
}
@ -541,19 +541,19 @@ namespace Opm
// Well did not converge, switch to explicit fractions
this->operability_status_.use_vfpexplicit = true;
this->openWell();
auto bhp_target = estimateOperableBhp(ebos_simulator, dt, well_state, summary_state, deferred_logger);
auto bhp_target = estimateOperableBhp(simulator, dt, well_state, summary_state, deferred_logger);
if (!bhp_target.has_value()) {
// well can't operate using explicit fractions
is_operable = false;
// solve with zero rate
converged = solveWellWithZeroRate(ebos_simulator, dt, well_state, deferred_logger);
converged = solveWellWithZeroRate(simulator, dt, well_state, deferred_logger);
this->stopWell();
} else {
// solve well with the estimated target bhp (or limit)
const double bhp = std::max(bhp_target.value(), prod_controls.bhp_limit);
solveWellWithBhp(ebos_simulator, dt, bhp, well_state, deferred_logger);
solveWellWithBhp(simulator, dt, bhp, well_state, deferred_logger);
ws.thp = this->getTHPConstraint(summary_state);
converged = this->iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
}
}
// update operability
@ -566,7 +566,7 @@ namespace Opm
template<typename TypeTag>
std::optional<double>
WellInterface<TypeTag>::
estimateOperableBhp(const Simulator& ebos_simulator,
estimateOperableBhp(const Simulator& simulator,
const double dt,
WellState& well_state,
const SummaryState& summary_state,
@ -576,11 +576,11 @@ namespace Opm
// Get minimal bhp from vfp-curve
double bhp_min = WellBhpThpCalculator(*this).calculateMinimumBhpFromThp(well_state, this->well_ecl_, summary_state, this->getRefDensity());
// Solve
const bool converged = solveWellWithBhp(ebos_simulator, dt, bhp_min, well_state, deferred_logger);
const bool converged = solveWellWithBhp(simulator, dt, bhp_min, well_state, deferred_logger);
if (!converged || this->wellIsStopped()) {
return std::nullopt;
}
this->updateIPRImplicit(ebos_simulator, well_state, deferred_logger);
this->updateIPRImplicit(simulator, well_state, deferred_logger);
auto rates = well_state.well(this->index_of_well_).surface_rates;
this->adaptRatesForVFP(rates);
return WellBhpThpCalculator(*this).estimateStableBhp(well_state, this->well_ecl_, rates, this->getRefDensity(), summary_state);
@ -589,7 +589,7 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
solveWellWithBhp(const Simulator& ebos_simulator,
solveWellWithBhp(const Simulator& simulator,
const double dt,
const double bhp,
WellState& well_state,
@ -616,7 +616,7 @@ namespace Opm
// update well-state
ws.bhp = bhp;
// solve
const bool converged = this->iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger, /*fixed_control*/true);
const bool converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger, /*fixed_control*/true);
ws.injection_cmode = cmode_inj;
ws.production_cmode = cmode_prod;
return converged;
@ -625,7 +625,7 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
solveWellWithZeroRate(const Simulator& ebos_simulator,
solveWellWithZeroRate(const Simulator& simulator,
const double dt,
WellState& well_state,
DeferredLogger& deferred_logger)
@ -637,7 +637,7 @@ namespace Opm
auto group_state = GroupState(); // empty group
auto inj_controls = Well::InjectionControls(0);
auto prod_controls = Well::ProductionControls(0);
const bool converged = this->iterateWellEqWithSwitching(ebos_simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger, /*fixed_control*/true, /*fixed_status*/ true);
const bool converged = this->iterateWellEqWithSwitching(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger, /*fixed_control*/true, /*fixed_status*/ true);
this->wellStatus_ = well_status_orig;
return converged;
}
@ -645,23 +645,23 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
solveWellForTesting(const Simulator& ebosSimulator, WellState& well_state, const GroupState& group_state,
solveWellForTesting(const Simulator& simulator, WellState& well_state, const GroupState& group_state,
DeferredLogger& deferred_logger)
{
// keep a copy of the original well state
const WellState well_state0 = well_state;
const double dt = ebosSimulator.timeStepSize();
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const double dt = simulator.timeStepSize();
const auto& summary_state = simulator.vanguard().summaryState();
const bool has_thp_limit = this->wellHasTHPConstraints(summary_state);
bool converged;
if (has_thp_limit) {
well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::THP;
converged = gliftBeginTimeStepWellTestIterateWellEquations(
ebosSimulator, dt, well_state, group_state, deferred_logger);
simulator, dt, well_state, group_state, deferred_logger);
}
else {
well_state.well(this->indexOfWell()).production_cmode = Well::ProducerCMode::BHP;
converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
}
if (converged) {
deferred_logger.debug("WellTest: Well equation for well " + this->name() + " converged");
@ -678,7 +678,7 @@ namespace Opm
template<typename TypeTag>
void
WellInterface<TypeTag>::
solveWellEquation(const Simulator& ebosSimulator,
solveWellEquation(const Simulator& simulator,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger)
@ -688,8 +688,8 @@ namespace Opm
// keep a copy of the original well state
const WellState well_state0 = well_state;
const double dt = ebosSimulator.timeStepSize();
bool converged = iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
const double dt = simulator.timeStepSize();
bool converged = iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
// Newly opened wells with THP control sometimes struggles to
// converge due to bad initial guess. Or due to the simple fact
@ -718,7 +718,7 @@ namespace Opm
const std::string msg = std::string("The newly opened well ") + this->name()
+ std::string(" with THP control did not converge during inner iterations, we try again with bhp control");
deferred_logger.debug(msg);
converged = this->iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
converged = this->iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
}
}
@ -735,16 +735,16 @@ namespace Opm
template <typename TypeTag>
void
WellInterface<TypeTag>::
assembleWellEq(const Simulator& ebosSimulator,
assembleWellEq(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger)
{
prepareWellBeforeAssembling(ebosSimulator, dt, well_state, group_state, deferred_logger);
prepareWellBeforeAssembling(simulator, dt, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(ebosSimulator, dt, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(simulator, dt, well_state, group_state, deferred_logger);
}
@ -752,18 +752,18 @@ namespace Opm
template <typename TypeTag>
void
WellInterface<TypeTag>::
assembleWellEqWithoutIteration(const Simulator& ebosSimulator,
assembleWellEqWithoutIteration(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
DeferredLogger& deferred_logger)
{
const auto& summary_state = ebosSimulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
const auto inj_controls = this->well_ecl_.isInjector() ? this->well_ecl_.injectionControls(summary_state) : Well::InjectionControls(0);
const auto prod_controls = this->well_ecl_.isProducer() ? this->well_ecl_.productionControls(summary_state) : Well::ProductionControls(0);
// TODO: the reason to have inj_controls and prod_controls in the arguments, is that we want to change the control used for the well functions
// TODO: maybe we can use std::optional or pointers to simplify here
assembleWellEqWithoutIteration(ebosSimulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
assembleWellEqWithoutIteration(simulator, dt, inj_controls, prod_controls, well_state, group_state, deferred_logger);
}
@ -771,7 +771,7 @@ namespace Opm
template<typename TypeTag>
void
WellInterface<TypeTag>::
prepareWellBeforeAssembling(const Simulator& ebosSimulator,
prepareWellBeforeAssembling(const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState& group_state,
@ -780,13 +780,13 @@ namespace Opm
const bool old_well_operable = this->operability_status_.isOperableAndSolvable();
if (param_.check_well_operability_iter_)
checkWellOperability(ebosSimulator, well_state, deferred_logger);
checkWellOperability(simulator, well_state, deferred_logger);
// only use inner well iterations for the first newton iterations.
const int iteration_idx = ebosSimulator.model().newtonMethod().numIterations();
const int iteration_idx = simulator.model().newtonMethod().numIterations();
if (iteration_idx < param_.max_niter_inner_well_iter_ || this->well_ecl_.isMultiSegment()) {
this->operability_status_.solvable = true;
bool converged = this->iterateWellEquations(ebosSimulator, dt, well_state, group_state, deferred_logger);
bool converged = this->iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
// unsolvable wells are treated as not operable and will not be solved for in this iteration.
if (!converged) {
@ -798,7 +798,7 @@ namespace Opm
auto well_state_copy = well_state;
std::vector<double> potentials;
try {
computeWellPotentials(ebosSimulator, well_state_copy, potentials, deferred_logger);
computeWellPotentials(simulator, well_state_copy, potentials, deferred_logger);
} catch (const std::exception& e) {
const std::string msg = std::string("well ") + this->name() + std::string(": computeWellPotentials() failed during attempt to recompute potentials for well : ") + e.what();
deferred_logger.info(msg);
@ -862,7 +862,7 @@ namespace Opm
template<typename TypeTag>
void
WellInterface<TypeTag>::
checkWellOperability(const Simulator& ebos_simulator,
checkWellOperability(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger)
{
@ -875,12 +875,12 @@ namespace Opm
return;
}
updateWellOperability(ebos_simulator, well_state, deferred_logger);
updateWellOperability(simulator, well_state, deferred_logger);
if (!this->operability_status_.isOperableAndSolvable()) {
this->operability_status_.use_vfpexplicit = true;
deferred_logger.debug("EXPLICIT_LOOKUP_VFP",
"well not operable, trying with explicit vfp lookup: " + this->name());
updateWellOperability(ebos_simulator, well_state, deferred_logger);
updateWellOperability(simulator, well_state, deferred_logger);
}
}
@ -888,16 +888,16 @@ namespace Opm
bool
WellInterface<TypeTag>::
gliftBeginTimeStepWellTestIterateWellEquations(
const Simulator& ebos_simulator,
const Simulator& simulator,
const double dt,
WellState& well_state,
const GroupState &group_state,
DeferredLogger& deferred_logger)
{
const auto& well_name = this->name();
assert(this->wellHasTHPConstraints(ebos_simulator.vanguard().summaryState()));
const auto& schedule = ebos_simulator.vanguard().schedule();
auto report_step_idx = ebos_simulator.episodeIndex();
assert(this->wellHasTHPConstraints(simulator.vanguard().summaryState()));
const auto& schedule = simulator.vanguard().schedule();
auto report_step_idx = simulator.episodeIndex();
const auto& glo = schedule.glo(report_step_idx);
if(glo.active() && glo.has_well(well_name)) {
const auto increment = glo.gaslift_increment();
@ -906,7 +906,7 @@ namespace Opm
while (alq > 0) {
well_state.setALQ(well_name, alq);
if ((converged =
iterateWellEquations(ebos_simulator, dt, well_state, group_state, deferred_logger)))
iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger)))
{
return converged;
}
@ -915,26 +915,26 @@ namespace Opm
return false;
}
else {
return iterateWellEquations(ebos_simulator, dt, well_state, group_state, deferred_logger);
return iterateWellEquations(simulator, dt, well_state, group_state, deferred_logger);
}
}
template<typename TypeTag>
void
WellInterface<TypeTag>::
gliftBeginTimeStepWellTestUpdateALQ(const Simulator& ebos_simulator,
gliftBeginTimeStepWellTestUpdateALQ(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger)
{
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
const auto& well_name = this->name();
if (!this->wellHasTHPConstraints(summary_state)) {
const std::string msg = fmt::format("GLIFT WTEST: Well {} does not have THP constraints", well_name);
deferred_logger.info(msg);
return;
}
const auto& schedule = ebos_simulator.vanguard().schedule();
const auto report_step_idx = ebos_simulator.episodeIndex();
const auto& schedule = simulator.vanguard().schedule();
const auto report_step_idx = simulator.episodeIndex();
const auto& glo = schedule.glo(report_step_idx);
if (!glo.has_well(well_name)) {
const std::string msg = fmt::format(
@ -966,12 +966,12 @@ namespace Opm
template<typename TypeTag>
void
WellInterface<TypeTag>::
updateWellOperability(const Simulator& ebos_simulator,
updateWellOperability(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger)
{
if (this->param_.local_well_solver_control_switching_) {
const bool success = updateWellOperabilityFromWellEq(ebos_simulator, well_state, deferred_logger);
const bool success = updateWellOperabilityFromWellEq(simulator, well_state, deferred_logger);
if (success) {
return;
} else {
@ -990,19 +990,19 @@ namespace Opm
// Only check wells under BHP and THP control
bool check_thp = thp_controlled || this->operability_status_.thp_limit_violated_but_not_switched;
if (check_thp || bhp_controlled) {
updateIPR(ebos_simulator, deferred_logger);
checkOperabilityUnderBHPLimit(well_state, ebos_simulator, deferred_logger);
updateIPR(simulator, deferred_logger);
checkOperabilityUnderBHPLimit(well_state, simulator, deferred_logger);
}
// we do some extra checking for wells under THP control.
if (check_thp) {
checkOperabilityUnderTHPLimit(ebos_simulator, well_state, deferred_logger);
checkOperabilityUnderTHPLimit(simulator, well_state, deferred_logger);
}
}
template<typename TypeTag>
bool
WellInterface<TypeTag>::
updateWellOperabilityFromWellEq(const Simulator& ebos_simulator,
updateWellOperabilityFromWellEq(const Simulator& simulator,
const WellState& well_state,
DeferredLogger& deferred_logger)
{
@ -1010,17 +1010,17 @@ namespace Opm
assert(this->param_.local_well_solver_control_switching_);
this->operability_status_.resetOperability();
WellState well_state_copy = well_state;
const auto& group_state = ebos_simulator.problem().wellModel().groupState();
const double dt = ebos_simulator.timeStepSize();
const auto& group_state = simulator.problem().wellModel().groupState();
const double dt = simulator.timeStepSize();
// equations should be converged at this stage, so only one it is needed
bool converged = iterateWellEquations(ebos_simulator, dt, well_state_copy, group_state, deferred_logger);
bool converged = iterateWellEquations(simulator, dt, well_state_copy, group_state, deferred_logger);
return converged;
}
template<typename TypeTag>
void
WellInterface<TypeTag>::
updateWellStateWithTarget(const Simulator& ebos_simulator,
updateWellStateWithTarget(const Simulator& simulator,
const GroupState& group_state,
WellState& well_state,
DeferredLogger& deferred_logger) const
@ -1032,8 +1032,8 @@ namespace Opm
auto& ws = well_state.well(well_index);
const auto& pu = this->phaseUsage();
const int np = well_state.numPhases();
const auto& summaryState = ebos_simulator.vanguard().summaryState();
const auto& schedule = ebos_simulator.vanguard().schedule();
const auto& summaryState = simulator.vanguard().summaryState();
const auto& schedule = simulator.vanguard().schedule();
if (this->wellIsStopped()) {
for (int p = 0; p<np; ++p) {
@ -1184,7 +1184,7 @@ namespace Opm
ws.surface_rates[p] *= controls.oil_rate/current_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
double control_fraction = fractions[pu.phase_pos[Oil]];
if (control_fraction != 0.0) {
for (int p = 0; p<np; ++p) {
@ -1204,7 +1204,7 @@ namespace Opm
ws.surface_rates[p] *= controls.water_rate/current_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
double control_fraction = fractions[pu.phase_pos[Water]];
if (control_fraction != 0.0) {
for (int p = 0; p<np; ++p) {
@ -1224,7 +1224,7 @@ namespace Opm
ws.surface_rates[p] *= controls.gas_rate/current_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
double control_fraction = fractions[pu.phase_pos[Gas]];
if (control_fraction != 0.0) {
for (int p = 0; p<np; ++p) {
@ -1247,7 +1247,7 @@ namespace Opm
ws.surface_rates[p] *= controls.liquid_rate/current_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
double control_fraction = fractions[pu.phase_pos[Water]] + fractions[pu.phase_pos[Oil]];
if (control_fraction != 0.0) {
for (int p = 0; p<np; ++p) {
@ -1279,7 +1279,7 @@ namespace Opm
ws.surface_rates[p] *= controls.resv_rate/total_res_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] = - fractions[p] * controls.resv_rate / convert_coeff[p];
}
@ -1305,7 +1305,7 @@ namespace Opm
ws.surface_rates[p] *= target/total_res_rate;
}
} else {
const std::vector<double> fractions = initialWellRateFractions(ebos_simulator, well_state);
const std::vector<double> fractions = initialWellRateFractions(simulator, well_state);
for (int p = 0; p<np; ++p) {
ws.surface_rates[p] = - fractions[p] * target / convert_coeff[p];
}
@ -1333,7 +1333,7 @@ namespace Opm
}
case Well::ProducerCMode::THP:
{
const bool update_success = updateWellStateWithTHPTargetProd(ebos_simulator, well_state, deferred_logger);
const bool update_success = updateWellStateWithTHPTargetProd(simulator, well_state, deferred_logger);
if (!update_success) {
// the following is the original way of initializing well state with THP constraint
@ -1399,7 +1399,7 @@ namespace Opm
template<typename TypeTag>
std::vector<double>
WellInterface<TypeTag>::
initialWellRateFractions(const Simulator& ebosSimulator, const WellState& well_state) const
initialWellRateFractions(const Simulator& simulator, const WellState& well_state) const
{
const int np = this->number_of_phases_;
std::vector<double> scaling_factor(np);
@ -1424,7 +1424,7 @@ namespace Opm
}
for (int perf = 0; perf < nperf; ++perf) {
const int cell_idx = this->well_cells_[perf];
const auto& intQuants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& fs = intQuants.fluidState();
const double well_tw_fraction = this->well_index_[perf] / total_tw;
double total_mobility = 0.0;
@ -1445,7 +1445,7 @@ namespace Opm
template <typename TypeTag>
void
WellInterface<TypeTag>::
updateWellStateRates(const Simulator& ebosSimulator,
updateWellStateRates(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) const
{
@ -1466,7 +1466,7 @@ namespace Opm
}
// Calculate the rates that follow from the current primary variables.
std::vector<double> well_q_s = computeCurrentWellRates(ebosSimulator, deferred_logger);
std::vector<double> well_q_s = computeCurrentWellRates(simulator, deferred_logger);
if (nonzero_rate_index == -1) {
// No nonzero rates.
@ -1676,7 +1676,7 @@ namespace Opm
template<class Value, class Callback>
void
WellInterface<TypeTag>::
getMobility(const Simulator& ebosSimulator,
getMobility(const Simulator& simulator,
const int perf,
std::vector<Value>& mob,
Callback& extendEval,
@ -1692,8 +1692,8 @@ namespace Opm
};
const int cell_idx = this->well_cells_[perf];
assert (int(mob.size()) == this->num_components_);
const auto& intQuants = ebosSimulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& materialLawManager = ebosSimulator.problem().materialLawManager();
const auto& intQuants = simulator.model().intensiveQuantities(cell_idx, /*timeIdx=*/0);
const auto& materialLawManager = simulator.problem().materialLawManager();
// either use mobility of the perforation cell or calculate its own
// based on passing the saturation table index
@ -1751,21 +1751,21 @@ namespace Opm
template<typename TypeTag>
bool
WellInterface<TypeTag>::
updateWellStateWithTHPTargetProd(const Simulator& ebos_simulator,
updateWellStateWithTHPTargetProd(const Simulator& simulator,
WellState& well_state,
DeferredLogger& deferred_logger) const
{
const auto& summary_state = ebos_simulator.vanguard().summaryState();
const auto& summary_state = simulator.vanguard().summaryState();
auto bhp_at_thp_limit = computeBhpAtThpLimitProdWithAlq(
ebos_simulator, summary_state, this->getALQ(well_state), deferred_logger);
simulator, summary_state, this->getALQ(well_state), deferred_logger);
if (bhp_at_thp_limit) {
std::vector<double> rates(this->number_of_phases_, 0.0);
if (thp_update_iterations) {
computeWellRatesWithBhpIterations(ebos_simulator, *bhp_at_thp_limit,
computeWellRatesWithBhpIterations(simulator, *bhp_at_thp_limit,
rates, deferred_logger);
} else {
computeWellRatesWithBhp(ebos_simulator, *bhp_at_thp_limit,
computeWellRatesWithBhp(simulator, *bhp_at_thp_limit,
rates, deferred_logger);
}
auto& ws = well_state.well(this->name());

View File

@ -91,9 +91,9 @@ bool PyBlackOilSimulator::checkSimulationFinished()
int PyBlackOilSimulator::currentStep()
{
return getFlowMain().getSimTimer()->currentStepNum();
// NOTE: this->ebos_simulator_->episodeIndex() would also return the current
// NOTE: this->simulator_->episodeIndex() would also return the current
// report step number, but this number is always delayed by 1 step relative
// to this->main_ebos_->getSimTimer()->currentStepNum()
// to this->flow_main_->getSimTimer()->currentStepNum()
// See details in runStep() in file SimulatorFullyImplicitBlackoilEbos.hpp
}
@ -218,13 +218,13 @@ int PyBlackOilSimulator::stepInit()
this->main_ = std::make_unique<Opm::Main>( this->deck_filename_ );
}
int exit_code = EXIT_SUCCESS;
this->main_ebos_ = this->main_->initFlowBlackoil(exit_code);
if (this->main_ebos_) {
int result = this->main_ebos_->executeInitStep();
this->flow_main_ = this->main_->initFlowBlackoil(exit_code);
if (this->flow_main_) {
int result = this->flow_main_->executeInitStep();
this->has_run_init_ = true;
this->ebos_simulator_ = this->main_ebos_->getSimulatorPtr();
this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->ebos_simulator_);
this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->ebos_simulator_);
this->simulator_ = this->flow_main_->getSimulatorPtr();
this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->simulator_);
this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->simulator_);
return result;
}
else {
@ -238,8 +238,8 @@ int PyBlackOilSimulator::stepInit()
Opm::FlowMain<typename Opm::Pybind::PyBlackOilSimulator::TypeTag>&
PyBlackOilSimulator::getFlowMain() const
{
if (this->main_ebos_) {
return *this->main_ebos_;
if (this->flow_main_) {
return *this->flow_main_;
}
else {
throw std::runtime_error("BlackOilSimulator not initialized: "