Merge pull request #1651 from totto82/speed_up_add_cell_rates

Speed up add cell rates
This commit is contained in:
Atgeirr Flø Rasmussen 2018-11-19 10:49:19 +01:00 committed by GitHub
commit c006ea23f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 36 deletions

View File

@ -278,6 +278,8 @@ namespace Opm {
// map from logically cartesian cell indices to compressed ones
std::vector<int> cartesian_to_compressed_;
std::vector<bool> is_cell_perforated_;
// create the well container
std::vector<WellInterfacePtr > createWellContainer(const int time_step);

View File

@ -46,6 +46,8 @@ namespace Opm {
// add the eWoms auxiliary module for the wells to the list
ebosSimulator_.model().addAuxiliaryModule(this);
is_cell_perforated_.resize(number_of_cells_, false);
}
template<typename TypeTag>
@ -228,6 +230,12 @@ namespace Opm {
well->init(&phase_usage_, depth_, gravity_, number_of_cells_);
}
// update the updated cell flag
std::fill(is_cell_perforated_.begin(), is_cell_perforated_.end(), false);
for (auto& well : well_container_) {
well->updatePerforatedCell(is_cell_perforated_);
}
// calculate the efficiency factors for each well
calculateEfficiencyFactors();
@ -342,6 +350,10 @@ namespace Opm {
{
rate = 0;
int elemIdx = context.globalSpaceIndex(spaceIdx, timeIdx);
if (!is_cell_perforated_[elemIdx])
return;
for (const auto& well : well_container_)
well->addCellRates(rate, elemIdx);
}
@ -879,7 +891,7 @@ namespace Opm {
const int np = numPhases();
well_potentials.resize(nw * np, 0.0);
const Opm::SummaryConfig summaryConfig = ebosSimulator_.vanguard().summaryConfig();
const Opm::SummaryConfig& summaryConfig = ebosSimulator_.vanguard().summaryConfig();
for (const auto& well : well_container_) {
// Only compute the well potential when asked for
bool needed_for_output = ((summaryConfig.hasSummaryKey( "WWPI:" + well->name()) ||
@ -1357,7 +1369,13 @@ namespace Opm {
elemIt != elemEndIt;
++elemIt)
{
elemCtx.updatePrimaryStencil(*elemIt);
int elemIdx = elemCtx.globalSpaceIndex(0, 0);
if (!is_cell_perforated_[elemIdx]) {
continue;
}
elemCtx.updatePrimaryIntensiveQuantities(/*timeIdx=*/0);
}
}

View File

@ -33,7 +33,6 @@ namespace Opm
{
public:
typedef WellInterface<TypeTag> Base;
typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
using typename Base::WellState;
using typename Base::Simulator;
@ -152,17 +151,6 @@ namespace Opm
int numberOfPerforations() const;
void addCellRates(RateVector& rates, int cellIdx) const override
{
for (int perfIdx = 0; perfIdx < number_of_perforations_; ++perfIdx) {
if (Base::cells()[perfIdx] == cellIdx) {
for (int i = 0; i < RateVector::dimension; ++i) {
rates[i] += connectionRates_[perfIdx][i];
}
}
}
}
protected:
int number_segments_;
@ -194,6 +182,7 @@ namespace Opm
using Base::well_controls_;
using Base::perf_depth_;
using Base::num_components_;
using Base::connectionRates_;
// protected functions from the Base class
using Base::phaseUsage;
@ -264,8 +253,6 @@ namespace Opm
std::vector<double> segment_depth_diffs_;
std::vector<RateVector> connectionRates_;
void initMatrixAndVectors(const int num_cells) const;
// protected functions

View File

@ -114,8 +114,6 @@ namespace Opm
{
Base::init(phase_usage_arg, depth_arg, gravity_arg, num_cells);
connectionRates_.resize(number_of_perforations_);
// TODO: for StandardWell, we need to update the perf depth here using depth_arg.
// for MultisegmentWell, it is much more complicated.
// It can be specified directly, it can be calculated from the segment depth,

View File

@ -37,7 +37,6 @@ namespace Opm
public:
typedef WellInterface<TypeTag> Base;
typedef typename GET_PROP_TYPE(TypeTag, RateVector) RateVector;
// TODO: some functions working with AD variables handles only with values (double) without
// dealing with derivatives. It can be beneficial to make functions can work with either AD or scalar value.
@ -176,17 +175,6 @@ namespace Opm
return param_.matrix_add_well_contributions_;
}
void addCellRates(RateVector& rates, int cellIdx) const override
{
for (int perfIdx = 0; perfIdx < number_of_perforations_; ++perfIdx) {
if (Base::cells()[perfIdx] == cellIdx) {
for (int i = 0; i < RateVector::dimension; ++i) {
rates[i] += connectionRates_[perfIdx][i];
}
}
}
}
protected:
// protected functions from the Base class
@ -221,6 +209,7 @@ namespace Opm
using Base::well_controls_;
using Base::well_type_;
using Base::num_components_;
using Base::connectionRates_;
using Base::perf_rep_radius_;
using Base::perf_length_;
@ -240,8 +229,6 @@ namespace Opm
// diagonal matrix for the well
DiagMatWell invDuneD_;
std::vector<RateVector> connectionRates_;
// several vector used in the matrix calculation
mutable BVectorWell Bx_;
mutable BVectorWell invDrw_;

View File

@ -60,8 +60,6 @@ namespace Opm
{
Base::init(phase_usage_arg, depth_arg, gravity_arg, num_cells);
connectionRates_.resize(number_of_perforations_);
perf_depth_.resize(number_of_perforations_, 0.);
for (int perf = 0; perf < number_of_perforations_; ++perf) {
const int cell_idx = well_cells_[perf];
@ -442,7 +440,7 @@ namespace Opm
WellState& well_state)
{
const Opm::SummaryConfig summaryConfig = ebosSimulator.vanguard().summaryConfig();
const Opm::SummaryConfig& summaryConfig = ebosSimulator.vanguard().summaryConfig();
const int np = number_of_phases_;

View File

@ -197,8 +197,7 @@ namespace Opm
virtual void addWellContributions(Mat&) const
{}
virtual void addCellRates(RateVector& rates, int cellIdx) const
{}
void addCellRates(RateVector& rates, int cellIdx) const;
template <class EvalWell>
Eval restrictEval(const EvalWell& in) const
@ -222,6 +221,9 @@ namespace Opm
const WellTestConfig::Reason testing_reason, const WellState& well_state,
WellTestState& welltest_state);
void updatePerforatedCell(std::vector<bool>& is_cell_perforated);
protected:
// to indicate a invalid completion
@ -301,6 +303,8 @@ namespace Opm
const int num_components_;
std::vector<RateVector> connectionRates_;
const PhaseUsage& phaseUsage() const;
int flowPhaseToEbosCompIdx( const int phaseIdx ) const;
@ -359,6 +363,7 @@ namespace Opm
void scaleProductivityIndex(const int perfIdx, double& productivity_index) const;
};
}

View File

@ -102,11 +102,23 @@ namespace Opm
wells->sat_table_id + perf_index_end,
saturation_table_number_.begin() );
}
well_efficiency_factor_ = 1.0;
connectionRates_.resize(number_of_perforations_);
}
template<typename TypeTag>
void
WellInterface<TypeTag>::
updatePerforatedCell(std::vector<bool>& is_cell_perforated)
{
for (int perf_idx = 0; perf_idx<number_of_perforations_; ++perf_idx) {
is_cell_perforated[well_cells_[perf_idx]] = true;
}
}
@ -1181,5 +1193,18 @@ namespace Opm
(std::log(well_ecl_->getDrainageRadius(current_step_) / connection.rw()) + connection.skinFactor());
}
template<typename TypeTag>
void
WellInterface<TypeTag>::addCellRates(RateVector& rates, int cellIdx) const
{
for (int perfIdx = 0; perfIdx < number_of_perforations_; ++perfIdx) {
if (cells()[perfIdx] == cellIdx) {
for (int i = 0; i < RateVector::dimension; ++i) {
rates[i] += connectionRates_[perfIdx][i];
}
}
}
}
}