HandlerContext: make target_wellpi private

add a method getWellPI to obtain value for a given well.
protects the potential null pointer
This commit is contained in:
Arne Morten Kvarving 2023-11-24 10:21:09 +01:00
parent 2b56daca05
commit e334f28cc3
3 changed files with 23 additions and 8 deletions

View File

@ -25,6 +25,8 @@
#include "MSW/WelSegsSet.hpp"
#include <stdexcept>
namespace Opm {
void HandlerContext::affected_well(const std::string& well_name)
@ -62,4 +64,18 @@ void HandlerContext::compsegs_handled(const std::string& well_name)
}
}
double HandlerContext::getWellPI(const std::string& well_name) const
{
if (!target_wellpi) {
throw std::logic_error("Lookup of well PI with no map available");
}
auto wellpi_iter = target_wellpi->find(well_name);
if (wellpi_iter == target_wellpi->end()) {
throw std::logic_error("Missing current PI for well " + well_name);
}
return wellpi_iter->second;
}
}

View File

@ -63,9 +63,9 @@ public:
, actionx_mode(actionx_mode_)
, parseContext(parseContext_)
, errors(errors_)
, target_wellpi(target_wellpi_)
, wpimult_global_factor(wpimult_global_factor_)
, grid(grid_)
, target_wellpi(target_wellpi_)
, welsegs_wells(welsegs_wells_)
, compsegs_wells(compsegs_wells_)
, sim_update(sim_update_)
@ -86,6 +86,9 @@ public:
/// \brief Mark that the well occured in a COMPSEGS keyword.
void compsegs_handled(const std::string& well_name);
//! \brief Obtain PI for a well.
double getWellPI(const std::string& well_name) const;
const ScheduleBlock& block;
const DeckKeyword& keyword;
const std::size_t currentStep;
@ -93,11 +96,11 @@ public:
const bool actionx_mode;
const ParseContext& parseContext;
ErrorGuard& errors;
const std::unordered_map<std::string, double>* target_wellpi{nullptr};
std::unordered_map<std::string, double>* wpimult_global_factor{nullptr};
const ScheduleGrid& grid;
private:
const std::unordered_map<std::string, double>* target_wellpi{nullptr};
WelSegsSet* welsegs_wells{nullptr};
std::set<std::string>* compsegs_wells{nullptr};
SimulatorUpdate* sim_update{nullptr};

View File

@ -1773,14 +1773,10 @@ File {} line {}.)", wname, location.keyword, location.filename, location.lineno)
const auto targetPI = record.getItem<PI>().get<double>(0);
std::vector<bool> scalingApplicable;
const auto& current_wellpi = *handlerContext.target_wellpi;
for (const auto& well_name : well_names) {
auto wellpi_iter = current_wellpi.find(well_name);
if (wellpi_iter == current_wellpi.end())
throw std::logic_error(fmt::format("Missing current PI for well {}", well_name));
auto new_well = this->getWell(well_name, report_step);
auto scalingFactor = new_well.convertDeckPI(targetPI) / wellpi_iter->second;
auto scalingFactor = new_well.convertDeckPI(targetPI) /
handlerContext.getWellPI(well_name);
new_well.updateWellProductivityIndex();
new_well.applyWellProdIndexScaling(scalingFactor, scalingApplicable);
this->snapshots.back().wells.update( std::move(new_well) );