From 5c9fb9d32ad6e4ccd63f0bef435eb3a407072b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atgeirr=20Fl=C3=B8=20Rasmussen?= Date: Thu, 23 Feb 2017 09:51:00 +0100 Subject: [PATCH] Refactor setting of new members into own functions. --- .../WellStateFullyImplicitBlackoilDense.hpp | 90 +++++++++++-------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/opm/autodiff/WellStateFullyImplicitBlackoilDense.hpp b/opm/autodiff/WellStateFullyImplicitBlackoilDense.hpp index 6f041f6b6..e715874a6 100644 --- a/opm/autodiff/WellStateFullyImplicitBlackoilDense.hpp +++ b/opm/autodiff/WellStateFullyImplicitBlackoilDense.hpp @@ -67,14 +67,63 @@ namespace Opm // call init on base class BaseType :: init(wells, state, prevState); - // if there are no well, do nothing in init + setWellSolutions(wells, pu); + setWellSolutionsFromPrevState(wells, prevState); + } + + + template + void setWellSolutionsFromPrevState(const Wells* wells, const PrevState& prevState) + { + // Set nw and np, or return if no wells. if (wells == 0) { return; } - const int nw = wells->number_of_wells; - if( nw == 0 ) return ; + if (nw == 0) { + return; + } + const int np = wells->number_of_phases; + // intialize wells that have been there before + // order may change so the mapping is based on the well name + // if there are no well, do nothing in init + if( ! prevState.wellMap().empty() ) + { + typedef typename WellMapType :: const_iterator const_iterator; + const_iterator end = prevState.wellMap().end(); + int nw_old = prevState.bhp().size(); + for (int w = 0; w < nw; ++w) { + std::string name( wells->name[ w ] ); + const_iterator it = prevState.wellMap().find( name ); + if( it != end ) + { + const int oldIndex = (*it).second[ 0 ]; + const int newIndex = w; + + // wellSolutions + for( int i = 0; i < np; ++i) + { + wellSolutions()[ i*nw + newIndex ] = prevState.wellSolutions()[i * nw_old + oldIndex ]; + } + + } + } + } + } + + + /// Set wellSolutions() based on the base class members. + void setWellSolutions(const Wells* wells, const PhaseUsage& pu) + { + // Set nw and np, or return if no wells. + if (wells == 0) { + return; + } + const int nw = wells->number_of_wells; + if (nw == 0) { + return; + } const int np = wells->number_of_phases; well_solutions_.clear(); @@ -93,7 +142,6 @@ namespace Opm switch (well_controls_iget_type(wc, current)) { case THP: // Intentional fall-through case BHP: - { if (well_type == INJECTOR) { for (int p = 0; p < np; ++p) { well_solutions_[w] += wellRates()[np*w + p] * wells->comp_frac[np*w + p]; @@ -103,16 +151,10 @@ namespace Opm well_solutions_[w] += g[p] * wellRates()[np*w + p]; } } - } break; - - case RESERVOIR_RATE: // Intentional fall-through case SURFACE_RATE: - { wellSolutions()[w] = bhp()[w]; - - } break; } @@ -142,34 +184,9 @@ namespace Opm } } } - - - // intialize wells that have been there before - // order may change so the mapping is based on the well name - if( ! prevState.wellMap().empty() ) - { - typedef typename WellMapType :: const_iterator const_iterator; - const_iterator end = prevState.wellMap().end(); - int nw_old = prevState.bhp().size(); - for (int w = 0; w < nw; ++w) { - std::string name( wells->name[ w ] ); - const_iterator it = prevState.wellMap().find( name ); - if( it != end ) - { - const int oldIndex = (*it).second[ 0 ]; - const int newIndex = w; - - // wellSolutions - for( int i = 0; i < np; ++i) - { - wellSolutions()[ i*nw + newIndex ] = prevState.wellSolutions()[i * nw_old + oldIndex ]; - } - - } - } - } } + template void resize(const Wells* wells, const State& state, const PhaseUsage& pu ) { const WellStateFullyImplicitBlackoilDense dummy_state{}; // Init with an empty previous state only resizes @@ -186,6 +203,7 @@ namespace Opm return res; } + private: std::vector well_solutions_; };