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

View File

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

View File

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

View File

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

View File

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

View File

@@ -62,20 +62,20 @@ public:
// Constructor // Constructor
AquiferNumerical(const SingleNumericalAquifer& aquifer, AquiferNumerical(const SingleNumericalAquifer& aquifer,
const Simulator& ebos_simulator) const Simulator& simulator)
: AquiferInterface<TypeTag>(aquifer.id(), ebos_simulator) : AquiferInterface<TypeTag>(aquifer.id(), simulator)
, flux_rate_ (0.0) , flux_rate_ (0.0)
, cumulative_flux_(0.0) , cumulative_flux_(0.0)
, init_pressure_ (aquifer.numCells(), 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; auto aquifer_on_process = false;
for (std::size_t idx = 0; idx < aquifer.numCells(); ++idx) { for (std::size_t idx = 0; idx < aquifer.numCells(); ++idx) {
const auto* cell = aquifer.getCellPrt(idx); const auto* cell = aquifer.getCellPrt(idx);
// Due to parallelisation, the cell might not exist in the current process // 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) { if (compressed_idx >= 0) {
this->cell_to_aquifer_cell_idx_[compressed_idx] = idx; this->cell_to_aquifer_cell_idx_[compressed_idx] = idx;
aquifer_on_process = true; 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.flux_rate_ = 1.0;
result.cumulative_flux_ = 2.0; result.cumulative_flux_ = 2.0;
result.init_pressure_ = {3.0, 4.0}; result.init_pressure_ = {3.0, 4.0};
@@ -124,7 +124,7 @@ public:
{ {
this->pressure_ = this->calculateAquiferPressure(); this->pressure_ = this->calculateAquiferPressure();
this->flux_rate_ = this->calculateAquiferFluxRate(); 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 data::AquiferData aquiferData() const override
@@ -185,9 +185,9 @@ public:
private: private:
void checkConnectsToReservoir() void checkConnectsToReservoir()
{ {
ElementContext elem_ctx(this->ebos_simulator_); ElementContext elem_ctx(this->simulator_);
auto elemIt = std::find_if(this->ebos_simulator_.gridView().template begin</*codim=*/0>(), auto elemIt = std::find_if(this->simulator_.gridView().template begin</*codim=*/0>(),
this->ebos_simulator_.gridView().template end</*codim=*/0>(), this->simulator_.gridView().template end</*codim=*/0>(),
[&elem_ctx, this](const auto& elem) -> bool [&elem_ctx, this](const auto& elem) -> bool
{ {
elem_ctx.updateStencil(elem); elem_ctx.updateStencil(elem);
@@ -198,7 +198,7 @@ private:
return this->cell_to_aquifer_cell_idx_[cell_index] == 0; 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"); && "Internal error locating numerical aquifer's connecting cell");
this->connects_to_reservoir_ = this->connects_to_reservoir_ =
@@ -216,8 +216,8 @@ private:
double sum_pressure_watervolume = 0.; double sum_pressure_watervolume = 0.;
double sum_watervolume = 0.; double sum_watervolume = 0.;
ElementContext elem_ctx(this->ebos_simulator_); ElementContext elem_ctx(this->simulator_);
const auto& gridView = this->ebos_simulator_.gridView(); const auto& gridView = this->simulator_.gridView();
OPM_BEGIN_PARALLEL_TRY_CATCH(); OPM_BEGIN_PARALLEL_TRY_CATCH();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
@@ -247,8 +247,9 @@ private:
cell_pressure[idx] = water_pressure_reservoir; cell_pressure[idx] = water_pressure_reservoir;
} }
OPM_END_PARALLEL_TRY_CATCH("AquiferNumerical::calculateAquiferPressure() failed: ", this->ebos_simulator_.vanguard().grid().comm()); OPM_END_PARALLEL_TRY_CATCH("AquiferNumerical::calculateAquiferPressure() failed: ",
const auto& comm = this->ebos_simulator_.vanguard().grid().comm(); this->simulator_.vanguard().grid().comm());
const auto& comm = this->simulator_.vanguard().grid().comm();
comm.sum(&sum_pressure_watervolume, 1); comm.sum(&sum_pressure_watervolume, 1);
comm.sum(&sum_watervolume, 1); comm.sum(&sum_watervolume, 1);
@@ -274,8 +275,8 @@ private:
return aquifer_flux; return aquifer_flux;
} }
ElementContext elem_ctx(this->ebos_simulator_); ElementContext elem_ctx(this->simulator_);
const auto& gridView = this->ebos_simulator_.gridView(); const auto& gridView = this->simulator_.gridView();
for (const auto& elem : elements(gridView, Dune::Partitions::interior)) { for (const auto& elem : elements(gridView, Dune::Partitions::interior)) {
// elem_ctx.updatePrimaryStencil(elem); // elem_ctx.updatePrimaryStencil(elem);
elem_ctx.updateStencil(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] eclipse_state the object which represents an internalized ECL deck
/// \param[in] output_writer /// \param[in] output_writer
/// \param[in] threshold_pressures_by_face if nonempty, threshold pressures that inhibit flow /// \param[in] threshold_pressures_by_face if nonempty, threshold pressures that inhibit flow
SimulatorFullyImplicitBlackoil(Simulator& ebosSimulator) SimulatorFullyImplicitBlackoil(Simulator& simulator)
: ebosSimulator_(ebosSimulator) : simulator_(simulator)
, serializer_(*this, , serializer_(*this,
EclGenericVanguard::comm(), EclGenericVanguard::comm(),
ebosSimulator_.vanguard().eclState().getIOConfig(), simulator_.vanguard().eclState().getIOConfig(),
EWOMS_GET_PARAM(TypeTag, std::string, SaveStep), EWOMS_GET_PARAM(TypeTag, std::string, SaveStep),
EWOMS_GET_PARAM(TypeTag, int, LoadStep), EWOMS_GET_PARAM(TypeTag, int, LoadStep),
EWOMS_GET_PARAM(TypeTag, std::string, SaveFile), EWOMS_GET_PARAM(TypeTag, std::string, SaveFile),
@@ -263,7 +263,7 @@ public:
{ {
init(timer); init(timer);
// Make cache up to date. No need for updating it in elementCtx. // 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. // Main simulation loop.
while (!timer.done()) { while (!timer.done()) {
bool continue_looping = runStep(timer); bool continue_looping = runStep(timer);
@@ -274,7 +274,7 @@ public:
void init(SimulatorTimer &timer) void init(SimulatorTimer &timer)
{ {
ebosSimulator_.setEpisodeIndex(-1); simulator_.setEpisodeIndex(-1);
// Create timers and file for writing timing info. // Create timers and file for writing timing info.
solverTimer_ = std::make_unique<time::StopWatch>(); solverTimer_ = std::make_unique<time::StopWatch>();
@@ -285,7 +285,7 @@ public:
bool enableAdaptive = EWOMS_GET_PARAM(TypeTag, bool, EnableAdaptiveTimeStepping); bool enableAdaptive = EWOMS_GET_PARAM(TypeTag, bool, EnableAdaptiveTimeStepping);
bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning); bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning);
if (enableAdaptive) { 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()]; const auto& sched_state = schedule()[timer.currentStepNum()];
auto max_next_tstep = sched_state.max_next_tstep(enableTUNING); auto max_next_tstep = sched_state.max_next_tstep(enableTUNING);
if (enableTUNING) { if (enableTUNING) {
@@ -298,9 +298,9 @@ public:
} }
if (isRestart()) { 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 // 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; Dune::Timer perfTimer;
perfTimer.start(); perfTimer.start();
ebosSimulator_.setEpisodeIndex(-1); simulator_.setEpisodeIndex(-1);
ebosSimulator_.setEpisodeLength(0.0); simulator_.setEpisodeLength(0.0);
ebosSimulator_.setTimeStepSize(0.0); simulator_.setTimeStepSize(0.0);
wellModel_().beginReportStep(timer.currentStepNum()); wellModel_().beginReportStep(timer.currentStepNum());
ebosSimulator_.problem().writeOutput(timer); simulator_.problem().writeOutput(timer);
report_.success.output_write_time += perfTimer.stop(); report_.success.output_write_time += perfTimer.stop();
} }
@@ -359,15 +359,15 @@ public:
solver_ = createSolver(wellModel_()); solver_ = createSolver(wellModel_());
} }
ebosSimulator_.startNextEpisode( simulator_.startNextEpisode(
ebosSimulator_.startTime() simulator_.startTime()
+ schedule().seconds(timer.currentStepNum()), + schedule().seconds(timer.currentStepNum()),
timer.currentStepLength()); timer.currentStepLength());
ebosSimulator_.setEpisodeIndex(timer.currentStepNum()); simulator_.setEpisodeIndex(timer.currentStepNum());
if (serializer_.shouldLoad()) { if (serializer_.shouldLoad()) {
wellModel_().prepareDeserialize(serializer_.loadStep() - 1); wellModel_().prepareDeserialize(serializer_.loadStep() - 1);
serializer_.loadState(); serializer_.loadState();
ebosSimulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0); simulator_.model().invalidateAndUpdateIntensiveQuantities(/*timeIdx=*/0);
} }
solver_->model().beginReportStep(); solver_->model().beginReportStep();
bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning); bool enableTUNING = EWOMS_GET_PARAM(TypeTag, bool, EnableTuning);
@@ -380,7 +380,7 @@ public:
if (adaptiveTimeStepping_) { if (adaptiveTimeStepping_) {
auto tuningUpdater = [enableTUNING, this, reportStep = timer.currentStepNum()]() 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(); auto& events = this->schedule()[reportStep].events();
if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) { if (events.hasEvent(ScheduleEvents::TUNING_CHANGE)) {
@@ -414,7 +414,7 @@ public:
auto stepReport = adaptiveTimeStepping_->step(timer, *solver_, event, nullptr, tuningUpdater); auto stepReport = adaptiveTimeStepping_->step(timer, *solver_, event, nullptr, tuningUpdater);
report_ += stepReport; report_ += stepReport;
//Pass simulation report to eclwriter for summary output //Pass simulation report to eclwriter for summary output
ebosSimulator_.problem().setSimulationReport(report_); simulator_.problem().setSimulationReport(report_);
} else { } else {
// solve for complete report step // solve for complete report step
auto stepReport = solver_->step(timer); auto stepReport = solver_->step(timer);
@@ -430,8 +430,8 @@ public:
Dune::Timer perfTimer; Dune::Timer perfTimer;
perfTimer.start(); perfTimer.start();
const double nextstep = adaptiveTimeStepping_ ? adaptiveTimeStepping_->suggestedNextStep() : -1.0; const double nextstep = adaptiveTimeStepping_ ? adaptiveTimeStepping_->suggestedNextStep() : -1.0;
ebosSimulator_.problem().setNextTimeStepSize(nextstep); simulator_.problem().setNextTimeStepSize(nextstep);
ebosSimulator_.problem().writeOutput(timer); simulator_.problem().writeOutput(timer);
report_.success.output_write_time += perfTimer.stop(); report_.success.output_write_time += perfTimer.stop();
solver_->model().endReportStep(); solver_->model().endReportStep();
@@ -471,7 +471,7 @@ public:
Dune::Timer finalOutputTimer; Dune::Timer finalOutputTimer;
finalOutputTimer.start(); finalOutputTimer.start();
ebosSimulator_.problem().finalizeOutput(); simulator_.problem().finalizeOutput();
report_.success.output_write_time += finalOutputTimer.stop(); report_.success.output_write_time += finalOutputTimer.stop();
} }
@@ -484,12 +484,12 @@ public:
} }
const Grid& grid() const const Grid& grid() const
{ return ebosSimulator_.vanguard().grid(); } { return simulator_.vanguard().grid(); }
template<class Serializer> template<class Serializer>
void serializeOp(Serializer& serializer) void serializeOp(Serializer& serializer)
{ {
serializer(ebosSimulator_); serializer(simulator_);
serializer(report_); serializer(report_);
serializer(adaptiveTimeStepping_); serializer(adaptiveTimeStepping_);
} }
@@ -524,20 +524,20 @@ protected:
return {"OPM Flow", return {"OPM Flow",
moduleVersion(), moduleVersion(),
compileTimestamp(), compileTimestamp(),
ebosSimulator_.vanguard().caseName(), simulator_.vanguard().caseName(),
str.str()}; str.str()};
} }
//! \brief Returns local-to-global cell mapping. //! \brief Returns local-to-global cell mapping.
const std::vector<int>& getCellMapping() const override const std::vector<int>& getCellMapping() const override
{ {
return ebosSimulator_.vanguard().globalCell(); return simulator_.vanguard().globalCell();
} }
std::unique_ptr<Solver> createSolver(WellModel& wellModel) std::unique_ptr<Solver> createSolver(WellModel& wellModel)
{ {
auto model = std::make_unique<Model>(ebosSimulator_, auto model = std::make_unique<Model>(simulator_,
modelParam_, modelParam_,
wellModel, wellModel,
terminalOutput_); terminalOutput_);
@@ -564,11 +564,11 @@ protected:
} }
const EclipseState& eclState() const const EclipseState& eclState() const
{ return ebosSimulator_.vanguard().eclState(); } { return simulator_.vanguard().eclState(); }
const Schedule& schedule() const const Schedule& schedule() const
{ return ebosSimulator_.vanguard().schedule(); } { return simulator_.vanguard().schedule(); }
bool isRestart() const bool isRestart() const
{ {
@@ -577,10 +577,10 @@ protected:
} }
WellModel& wellModel_() WellModel& wellModel_()
{ return ebosSimulator_.problem().wellModel(); } { return simulator_.problem().wellModel(); }
const WellModel& wellModel_() const const WellModel& wellModel_() const
{ return ebosSimulator_.problem().wellModel(); } { return simulator_.problem().wellModel(); }
void startConvergenceOutputThread(std::string_view convOutputOptions, void startConvergenceOutputThread(std::string_view convOutputOptions,
std::string_view optionName) std::string_view optionName)
@@ -642,7 +642,7 @@ protected:
} }
// Data. // Data.
Simulator& ebosSimulator_; Simulator& simulator_;
ModelParameters modelParam_; ModelParameters modelParam_;
SolverParameters solverParam_; SolverParameters solverParam_;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -91,9 +91,9 @@ bool PyBlackOilSimulator::checkSimulationFinished()
int PyBlackOilSimulator::currentStep() int PyBlackOilSimulator::currentStep()
{ {
return getFlowMain().getSimTimer()->currentStepNum(); 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 // 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 // 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_ ); this->main_ = std::make_unique<Opm::Main>( this->deck_filename_ );
} }
int exit_code = EXIT_SUCCESS; int exit_code = EXIT_SUCCESS;
this->main_ebos_ = this->main_->initFlowBlackoil(exit_code); this->flow_main_ = this->main_->initFlowBlackoil(exit_code);
if (this->main_ebos_) { if (this->flow_main_) {
int result = this->main_ebos_->executeInitStep(); int result = this->flow_main_->executeInitStep();
this->has_run_init_ = true; this->has_run_init_ = true;
this->ebos_simulator_ = this->main_ebos_->getSimulatorPtr(); this->simulator_ = this->flow_main_->getSimulatorPtr();
this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->ebos_simulator_); this->fluid_state_ = std::make_unique<PyFluidState<TypeTag>>(this->simulator_);
this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->ebos_simulator_); this->material_state_ = std::make_unique<PyMaterialState<TypeTag>>(this->simulator_);
return result; return result;
} }
else { else {
@@ -238,8 +238,8 @@ int PyBlackOilSimulator::stepInit()
Opm::FlowMain<typename Opm::Pybind::PyBlackOilSimulator::TypeTag>& Opm::FlowMain<typename Opm::Pybind::PyBlackOilSimulator::TypeTag>&
PyBlackOilSimulator::getFlowMain() const PyBlackOilSimulator::getFlowMain() const
{ {
if (this->main_ebos_) { if (this->flow_main_) {
return *this->main_ebos_; return *this->flow_main_;
} }
else { else {
throw std::runtime_error("BlackOilSimulator not initialized: " throw std::runtime_error("BlackOilSimulator not initialized: "