Merge pull request #3020 from joakim-hove/vfp-refactor

Vfp refactor
This commit is contained in:
Joakim Hove 2021-01-15 07:39:43 +01:00 committed by GitHub
commit 553c16774c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 53 additions and 109 deletions

View File

@ -36,12 +36,11 @@ using namespace Opm;
struct Setup struct Setup
{ {
using VFP = VFPProperties<VFPInjProperties, VFPProdProperties>;
std::unique_ptr<const EclipseState> ecl_state; std::unique_ptr<const EclipseState> ecl_state;
std::shared_ptr<Python> python; std::shared_ptr<Python> python;
std::unique_ptr<const Schedule> schedule; std::unique_ptr<const Schedule> schedule;
std::unique_ptr<SummaryState> summary_state; std::unique_ptr<SummaryState> summary_state;
std::unique_ptr<VFP> vfp_properties; std::unique_ptr<VFPProperties> vfp_properties;
Setup(const std::string& file) Setup(const std::string& file)
{ {
@ -56,7 +55,8 @@ struct Setup
summary_state.reset( new SummaryState(std::chrono::system_clock::from_time_t(schedule->getStartTime()))); summary_state.reset( new SummaryState(std::chrono::system_clock::from_time_t(schedule->getStartTime())));
} }
const int step = 0; const int step = 0;
vfp_properties = std::make_unique<VFP>(schedule->getVFPInjTables(step), schedule->getVFPProdTables(step)); const auto& sched_state = schedule->operator[](step);
vfp_properties = std::make_unique<VFPProperties>(sched_state.vfpinj(), sched_state.vfpprod());
}; };
}; };

View File

@ -333,7 +333,7 @@ namespace Opm {
std::optional<int> last_run_wellpi_{}; std::optional<int> last_run_wellpi_{};
std::unique_ptr<RateConverterType> rateConverter_; std::unique_ptr<RateConverterType> rateConverter_;
std::unique_ptr<VFPProperties<VFPInjProperties,VFPProdProperties>> vfp_properties_; std::unique_ptr<VFPProperties> vfp_properties_;
SimulatorReportSingle last_report_; SimulatorReportSingle last_report_;

View File

@ -302,15 +302,15 @@ namespace Opm {
std::vector<int>(local_num_cells_, 0))); std::vector<int>(local_num_cells_, 0)));
rateConverter_->template defineState<ElementContext>(ebosSimulator_); rateConverter_->template defineState<ElementContext>(ebosSimulator_);
{
const auto& sched_state = this->schedule()[timeStepIdx];
// update VFP properties // update VFP properties
vfp_properties_.reset (new VFPProperties<VFPInjProperties,VFPProdProperties> ( vfp_properties_.reset(new VFPProperties( sched_state.vfpinj(), sched_state.vfpprod()) );
schedule().getVFPInjTables(timeStepIdx),
schedule().getVFPProdTables(timeStepIdx)) );
this->initializeWellProdIndCalculators(); this->initializeWellProdIndCalculators();
if (this->schedule()[timeStepIdx].events().hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX)) { if (sched_state.events().hasEvent(ScheduleEvents::Events::WELL_PRODUCTIVITY_INDEX)) {
this->runWellPIScaling(timeStepIdx, local_deferredLogger); this->runWellPIScaling(timeStepIdx, local_deferredLogger);
} }
}
// update the previous well state. This is used to restart failed steps. // update the previous well state. This is used to restart failed steps.
previous_well_state_ = well_state_; previous_well_state_ = well_state_;

View File

@ -32,21 +32,6 @@
namespace Opm { namespace Opm {
VFPInjProperties::VFPInjProperties() {
}
VFPInjProperties::VFPInjProperties(const VFPInjTable* table){
m_tables[table->getTableNum()] = table;
}
VFPInjProperties::VFPInjProperties(const VFPInjProperties::InjTable& tables) {
for (const auto& table : tables) {
m_tables[table.first] = table.second.get();
}
}
double VFPInjProperties::bhp(int table_id, double VFPInjProperties::bhp(int table_id,
@ -98,4 +83,9 @@ bool VFPInjProperties::hasTable(const int table_id) const {
return detail::hasTable(m_tables, table_id); return detail::hasTable(m_tables, table_id);
} }
void VFPInjProperties::addTable(const VFPInjTable * new_table) {
this->m_tables.emplace( new_table->getTableNum(), new_table );
}
} //Namespace Opm } //Namespace Opm

View File

@ -34,25 +34,11 @@ namespace Opm {
class VFPInjProperties { class VFPInjProperties {
public: public:
VFPInjProperties() = default;
/** /**
* Empty constructor
*/
VFPInjProperties();
/**
* Constructor
* Takes *no* ownership of data. * Takes *no* ownership of data.
* @param inj_table A *single* VFPINJ table
*/ */
explicit VFPInjProperties(const VFPInjTable* inj_table); void addTable(const VFPInjTable * new_table);
/**
* Constructor
* Takes *no* ownership of data.
* @param inj_tables A map of different VFPINJ tables.
*/
using InjTable = std::map<int, std::shared_ptr<const VFPInjTable> >;
explicit VFPInjProperties(const InjTable& inj_tables);
/** /**
* Linear interpolation of bhp as a function of the input parameters given as * Linear interpolation of bhp as a function of the input parameters given as

View File

@ -33,23 +33,6 @@ namespace Opm {
VFPProdProperties::VFPProdProperties() {
}
VFPProdProperties::VFPProdProperties(const VFPProdTable* table){
m_tables[table->getTableNum()] = table;
}
VFPProdProperties::VFPProdProperties(const VFPProdProperties::ProdTable& tables) {
for (const auto& table : tables) {
m_tables[table.first] = table.second.get();
}
}
double VFPProdProperties::thp(int table_id, double VFPProdProperties::thp(int table_id,
const double& aqua, const double& aqua,
const double& liquid, const double& liquid,
@ -261,5 +244,8 @@ calculateBhpWithTHPTarget(const std::vector<double>& ipr_a,
} }
} }
void VFPProdProperties::addTable(const VFPProdTable * new_table) {
this->m_tables.emplace( new_table->getTableNum(), new_table );
}
} }

View File

@ -38,25 +38,11 @@ namespace Opm {
*/ */
class VFPProdProperties { class VFPProdProperties {
public: public:
VFPProdProperties() = default;
/** /**
* Empty constructor
*/
VFPProdProperties();
/**
* Constructor
* Takes *no* ownership of data. * Takes *no* ownership of data.
* @param prod_table A *single* VFPPROD table
*/ */
explicit VFPProdProperties(const VFPProdTable* prod_table); void addTable(const VFPProdTable * new_table);
/**
* Constructor
* Takes *no* ownership of data.
* @param prod_tables A map of different VFPPROD tables.
*/
using ProdTable = std::map<int, std::shared_ptr<const VFPProdTable> >;
explicit VFPProdProperties(const ProdTable& prod_tables);
/** /**
* Linear interpolation of bhp as a function of the input parameters given as * Linear interpolation of bhp as a function of the input parameters given as

View File

@ -23,6 +23,9 @@
#include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/VFPInjTable.hpp>
#include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp> #include <opm/parser/eclipse/EclipseState/Schedule/VFPProdTable.hpp>
#include <opm/simulators/wells/VFPInjProperties.hpp>
#include <opm/simulators/wells/VFPProdProperties.hpp>
#include <map> #include <map>
namespace Opm { namespace Opm {
@ -31,26 +34,10 @@ namespace Opm {
* A thin wrapper class that holds one VFPProdProperties and one * A thin wrapper class that holds one VFPProdProperties and one
* VFPInjProperties object. * VFPInjProperties object.
*/ */
template<typename VFPInjProp, typename VFPProdProp>
class VFPProperties { class VFPProperties {
public: public:
VFPProperties() {} VFPProperties() = default;
/**
* Constructor
* Takes *no* ownership of data.
* @param inj_table A *single* VFPINJ table or NULL (no table)
* @param prod_table A *single* VFPPROD table or NULL (no table)
*/
explicit VFPProperties(const VFPInjTable* inj_table, const VFPProdTable* prod_table)
{
if (inj_table != nullptr) {
m_inj.reset(new VFPInjProp(inj_table));
}
if (prod_table != nullptr) {
m_prod.reset(new VFPProdProp(prod_table));
}
}
/** /**
* Constructor * Constructor
@ -58,27 +45,34 @@ public:
* @param inj_tables A map of different VFPINJ tables. * @param inj_tables A map of different VFPINJ tables.
* @param prod_tables A map of different VFPPROD tables. * @param prod_tables A map of different VFPPROD tables.
*/ */
VFPProperties(const std::map<int, std::shared_ptr<const VFPInjTable> >& inj_tables,
const std::map<int, std::shared_ptr<const VFPProdTable> >& prod_tables) VFPProperties(const std::vector<const VFPInjTable *>& inj_tables,
: m_inj(new VFPInjProp(inj_tables)), m_prod(new VFPProdProp(prod_tables)) {} const std::vector<const VFPProdTable *>& prod_tables)
{
for (const auto& vfpinj_ptr : inj_tables)
this->m_inj.addTable( vfpinj_ptr );
for (const auto& vfpprod_ptr : prod_tables)
this->m_prod.addTable( vfpprod_ptr );
};
/** /**
* Returns the VFP properties for injection wells * Returns the VFP properties for injection wells
*/ */
const VFPInjProp* getInj() const { const VFPInjProperties* getInj() const {
return m_inj.get(); return &m_inj;
} }
/** /**
* Returns the VFP properties for production wells * Returns the VFP properties for production wells
*/ */
const VFPProdProp* getProd() const { const VFPProdProperties* getProd() const {
return m_prod.get(); return &m_prod;
} }
private: private:
std::shared_ptr<VFPInjProp> m_inj; VFPInjProperties m_inj;
std::shared_ptr<VFPProdProp> m_prod; VFPProdProperties m_prod;
}; };

View File

@ -151,7 +151,7 @@ namespace Opm
/// Well cells. /// Well cells.
const std::vector<int>& cells() const {return well_cells_; } const std::vector<int>& cells() const {return well_cells_; }
void setVFPProperties(const VFPProperties<VFPInjProperties,VFPProdProperties>* vfp_properties_arg); void setVFPProperties(const VFPProperties* vfp_properties_arg);
void setGuideRate(const GuideRate* guide_rate_arg); void setGuideRate(const GuideRate* guide_rate_arg);
@ -384,7 +384,7 @@ namespace Opm
bool getAllowCrossFlow() const; bool getAllowCrossFlow() const;
const VFPProperties<VFPInjProperties,VFPProdProperties>* vfp_properties_; const VFPProperties* vfp_properties_;
const GuideRate* guide_rate_; const GuideRate* guide_rate_;

View File

@ -174,7 +174,7 @@ namespace Opm
template<typename TypeTag> template<typename TypeTag>
void void
WellInterface<TypeTag>:: WellInterface<TypeTag>::
setVFPProperties(const VFPProperties<VFPInjProperties,VFPProdProperties>* vfp_properties_arg) setVFPProperties(const VFPProperties* vfp_properties_arg)
{ {
vfp_properties_ = vfp_properties_arg; vfp_properties_ = vfp_properties_arg;
} }

View File

@ -205,7 +205,8 @@ struct TrivialFixture {
alq_axis, alq_axis,
data)); data));
properties.reset(new Opm::VFPProdProperties(table.get())); properties = std::make_shared<Opm::VFPProdProperties>();
properties->addTable( table.get() );
} }
double& operator()(size_t thp_idx, size_t wfr_idx, size_t gfr_idx, size_t alq_idx, size_t flo_idx) { double& operator()(size_t thp_idx, size_t wfr_idx, size_t gfr_idx, size_t alq_idx, size_t flo_idx) {
@ -590,7 +591,8 @@ VFPPROD \n\
Opm::Parser parser; Opm::Parser parser;
auto deck = parser.parseString(table_str); auto deck = parser.parseString(table_str);
Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units); Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units);
Opm::VFPProdProperties properties(&table); Opm::VFPProdProperties properties;
properties.addTable( &table );
const int n = 5; //Number of points to check per axis const int n = 5; //Number of points to check per axis
double bhp_sad = 0.0; //Sum of absolute difference double bhp_sad = 0.0; //Sum of absolute difference
@ -649,8 +651,8 @@ BOOST_AUTO_TEST_CASE(ParseInterpolateRealisticVFPPROD)
BOOST_CHECK_EQUAL(deck.count("VFPPROD"), 1); BOOST_CHECK_EQUAL(deck.count("VFPPROD"), 1);
Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units); Opm::VFPProdTable table(deck.getKeyword("VFPPROD", 0), units);
Opm::VFPProdProperties properties;
Opm::VFPProdProperties properties(&table); properties.addTable(&table);
//Do some rudimentary testing //Do some rudimentary testing
//Get the BHP as a function of rate, thp, wfr, gfr, alq //Get the BHP as a function of rate, thp, wfr, gfr, alq