From 879f127ae89cdd1a73723e60354164f70dec98a9 Mon Sep 17 00:00:00 2001 From: Kai Bao Date: Thu, 12 May 2016 15:14:20 +0200 Subject: [PATCH] moving variableStateExtractWellsVars() from models to Well Models. --- opm/autodiff/BlackoilModelBase.hpp | 5 --- opm/autodiff/BlackoilModelBase_impl.hpp | 22 +---------- opm/autodiff/BlackoilMultiSegmentModel.hpp | 5 --- .../BlackoilMultiSegmentModel_impl.hpp | 37 ------------------ opm/autodiff/BlackoilSolventModel_impl.hpp | 2 +- opm/autodiff/MultisegmentWells.hpp | 7 ++++ opm/autodiff/MultisegmentWells_impl.hpp | 38 +++++++++++++++++++ opm/autodiff/StandardWells.hpp | 6 ++- opm/autodiff/StandardWells_impl.hpp | 18 +++++++++ 9 files changed, 71 insertions(+), 69 deletions(-) diff --git a/opm/autodiff/BlackoilModelBase.hpp b/opm/autodiff/BlackoilModelBase.hpp index 0cdb53ec3..a1da92407 100644 --- a/opm/autodiff/BlackoilModelBase.hpp +++ b/opm/autodiff/BlackoilModelBase.hpp @@ -365,11 +365,6 @@ namespace Opm { const std::vector& indices, std::vector& vars) const; - void - variableStateExtractWellsVars(const std::vector& indices, - std::vector& vars, - SolutionState& state) const; - void computeAccum(const SolutionState& state, const int aix ); diff --git a/opm/autodiff/BlackoilModelBase_impl.hpp b/opm/autodiff/BlackoilModelBase_impl.hpp index 3952697a2..8352f9e0e 100644 --- a/opm/autodiff/BlackoilModelBase_impl.hpp +++ b/opm/autodiff/BlackoilModelBase_impl.hpp @@ -668,7 +668,7 @@ namespace detail { } } // wells - asImpl().variableStateExtractWellsVars(indices, vars, state); + asImpl().wellModel().variableStateExtractWellsVars(indices, vars, state); return state; } @@ -676,24 +676,6 @@ namespace detail { - template - void - BlackoilModelBase:: - variableStateExtractWellsVars(const std::vector& indices, - std::vector& vars, - SolutionState& state) const - { - // Qs. - state.qs = std::move(vars[indices[Qs]]); - - // Bhp. - state.bhp = std::move(vars[indices[Bhp]]); - } - - - - - template void BlackoilModelBase:: @@ -1024,7 +1006,7 @@ namespace detail { std::vector vars = ADB::variables(vars0); SolutionState wellSolutionState = state0; - asImpl().variableStateExtractWellsVars(indices, vars, wellSolutionState); + asImpl().wellModel().variableStateExtractWellsVars(indices, vars, wellSolutionState); asImpl().wellModel().computeWellFlux(wellSolutionState, mob_perfcells_const, b_perfcells_const, aliveWells, cq_s); asImpl().wellModel().updatePerfPhaseRatesAndPressures(cq_s, wellSolutionState, well_state); asImpl().wellModel().addWellFluxEq(cq_s, wellSolutionState, residual_); diff --git a/opm/autodiff/BlackoilMultiSegmentModel.hpp b/opm/autodiff/BlackoilMultiSegmentModel.hpp index 2071027e1..0fbeb5970 100644 --- a/opm/autodiff/BlackoilMultiSegmentModel.hpp +++ b/opm/autodiff/BlackoilMultiSegmentModel.hpp @@ -173,11 +173,6 @@ namespace Opm { void makeConstantState(SolutionState& state) const; - void - variableStateExtractWellsVars(const std::vector& indices, - std::vector& vars, - SolutionState& state) const; - // TODO: added since the interfaces of the function are different // TODO: for StandardWells and MultisegmentWells void diff --git a/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp b/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp index 85960ff4f..9e1fba145 100644 --- a/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp +++ b/opm/autodiff/BlackoilMultiSegmentModel_impl.hpp @@ -125,43 +125,6 @@ namespace Opm { - template - void - BlackoilMultiSegmentModel::variableStateExtractWellsVars(const std::vector& indices, - std::vector& vars, - SolutionState& state) const - { - // TODO: using the original Qs for the segment rates for now, to be fixed eventually. - // TODO: using the original Bhp for the segment pressures for now, to be fixed eventually. - - // segment phase rates in surface volume - state.segqs = std::move(vars[indices[Qs]]); - - // segment pressures - state.segp = std::move(vars[indices[Bhp]]); - - // The qs and bhp are no longer primary variables, but could - // still be used in computations. They are identical to the - // pressures and flows of the top segments. - const int np = numPhases(); - const int ns = state.segp.size(); - const int nw = wellModel().topWellSegments().size(); - state.qs = ADB::constant(ADB::V::Zero(np*nw)); - for (int phase = 0; phase < np; ++phase) { - // Extract segment fluxes for this phase (ns consecutive elements). - ADB segqs_phase = subset(state.segqs, Span(ns, 1, ns*phase)); - // Extract top segment fluxes (= well fluxes) - ADB wellqs_phase = subset(segqs_phase, wellModel().topWellSegments()); - // Expand to full size of qs (which contains all phases) and add. - state.qs += superset(wellqs_phase, Span(nw, 1, nw*phase), nw*np); - } - state.bhp = subset(state.segp, wellModel().topWellSegments()); - } - - - - - template void BlackoilMultiSegmentModel:: diff --git a/opm/autodiff/BlackoilSolventModel_impl.hpp b/opm/autodiff/BlackoilSolventModel_impl.hpp index 48efb9131..009bda4bf 100644 --- a/opm/autodiff/BlackoilSolventModel_impl.hpp +++ b/opm/autodiff/BlackoilSolventModel_impl.hpp @@ -241,7 +241,7 @@ namespace Opm { } } // wells - Base::variableStateExtractWellsVars(indices, vars, state); + wellModel().variableStateExtractWellsVars(indices, vars, state); return state; } diff --git a/opm/autodiff/MultisegmentWells.hpp b/opm/autodiff/MultisegmentWells.hpp index 7ae2a78a6..240f38c89 100644 --- a/opm/autodiff/MultisegmentWells.hpp +++ b/opm/autodiff/MultisegmentWells.hpp @@ -201,6 +201,13 @@ namespace Opm { void variableStateWellIndices(std::vector& indices, int& next) const; + + template + void + variableStateExtractWellsVars(const std::vector& indices, + std::vector& vars, + SolutionState& state) const; + std::vector variableWellStateIndices() const; diff --git a/opm/autodiff/MultisegmentWells_impl.hpp b/opm/autodiff/MultisegmentWells_impl.hpp index 0dafe02ef..c18be9b14 100644 --- a/opm/autodiff/MultisegmentWells_impl.hpp +++ b/opm/autodiff/MultisegmentWells_impl.hpp @@ -1122,6 +1122,44 @@ namespace Opm + template + void + MultisegmentWells:: + variableStateExtractWellsVars(const std::vector& indices, + std::vector& vars, + SolutionState& state) const + { + // TODO: using the original Qs for the segment rates for now, to be fixed eventually. + // TODO: using the original Bhp for the segment pressures for now, to be fixed eventually. + + // segment phase rates in surface volume + state.segqs = std::move(vars[indices[Qs]]); + + // segment pressures + state.segp = std::move(vars[indices[Bhp]]); + + // The qs and bhp are no longer primary variables, but could + // still be used in computations. They are identical to the + // pressures and flows of the top segments. + const int np = num_phases_; + const int ns = nseg_total_; + const int nw = numWells(); + state.qs = ADB::constant(Vector::Zero(np * nw)); + for (int phase = 0; phase < np; ++phase) { + // Extract segment fluxes for this phase (ns consecutive elements). + ADB segqs_phase = subset(state.segqs, Span(ns, 1, ns*phase)); + // Extract top segment fluxes (= well fluxes) + ADB wellqs_phase = subset(segqs_phase, topWellSegments()); + // Expand to full size of qs (which contains all phases) and add. + state.qs += superset(wellqs_phase, Span(nw, 1, nw * phase), nw * np); + } + state.bhp = subset(state.segp, topWellSegments()); + } + + + + + template void MultisegmentWells:: diff --git a/opm/autodiff/StandardWells.hpp b/opm/autodiff/StandardWells.hpp index 0968d4b2d..27d963664 100644 --- a/opm/autodiff/StandardWells.hpp +++ b/opm/autodiff/StandardWells.hpp @@ -143,12 +143,16 @@ namespace Opm { SolutionState& state0, WellState& well_state); + template + void + variableStateExtractWellsVars(const std::vector& indices, + std::vector& vars, + SolutionState& state) const; void variableStateWellIndices(std::vector& indices, int& next) const; - std::vector variableWellStateIndices() const; diff --git a/opm/autodiff/StandardWells_impl.hpp b/opm/autodiff/StandardWells_impl.hpp index ce0f33f33..cdb1f6f33 100644 --- a/opm/autodiff/StandardWells_impl.hpp +++ b/opm/autodiff/StandardWells_impl.hpp @@ -1137,6 +1137,24 @@ namespace Opm + template + void + StandardWells:: + variableStateExtractWellsVars(const std::vector& indices, + std::vector& vars, + SolutionState& state) const + { + // Qs. + state.qs = std::move(vars[indices[Qs]]); + + // Bhp. + state.bhp = std::move(vars[indices[Bhp]]); + } + + + + + std::vector StandardWells::variableWellStateIndices() const {