From 26f1a69903abe4e15481cde6904e05b0253ec8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Kvalsvik?= Date: Fri, 30 Sep 2016 09:52:45 +0200 Subject: [PATCH] wellToState reads new opm-output data exchange --- opm/autodiff/Compat.hpp | 60 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/opm/autodiff/Compat.hpp b/opm/autodiff/Compat.hpp index d93d71192..23705c04e 100644 --- a/opm/autodiff/Compat.hpp +++ b/opm/autodiff/Compat.hpp @@ -21,6 +21,9 @@ #ifndef OPM_SIMULATORS_COMPAT_HPP #define OPM_SIMULATORS_COMPAT_HPP +#include +#include + #include #include #include @@ -167,14 +170,59 @@ inline void solutionToSim( const data::Solution& sol, +inline void wellsToState( const data::Wells& wells, + PhaseUsage phases, + WellState& state ) { + using rt = data::Rates::opt; -inline void wellsToState( const data::Wells& wells, WellState& state ) { - state.bhp() = wells.bhp; - state.temperature() = wells.temperature; - state.wellRates() = wells.well_rate; - state.perfPress() = wells.perf_pressure; - state.perfRates() = wells.perf_rate; + const auto np = phases.num_phases; + + std::vector< rt > phs( np ); + if( phases.phase_used[BlackoilPhases::Aqua] ) { + phs.at( phases.phase_pos[BlackoilPhases::Aqua] ) = rt::wat; + } + + if( phases.phase_used[BlackoilPhases::Liquid] ) { + phs.at( phases.phase_pos[BlackoilPhases::Liquid] ) = rt::oil; + } + + if( phases.phase_used[BlackoilPhases::Vapour] ) { + phs.at( phases.phase_pos[BlackoilPhases::Vapour] ) = rt::gas; + } + + for( const auto& wm : state.wellMap() ) { + const auto well_index = wm.second[ 0 ]; + const auto& well = wells.at( wm.first ); + + state.bhp()[ well_index ] = well.bhp; + state.temperature()[ well_index ] = well.temperature; + + const auto wellrate_index = well_index * np; + for( size_t i = 0; i < phs.size(); ++i ) { + assert( well.rates.has( phs[ i ] ) ); + state.wellRates()[ wellrate_index + i ] = well.rates.get( phs[ i ] ); + } + + using PerfPairTypeAlias = decltype( *well.completions.begin() ); + const auto perforation_pressure = []( const PerfPairTypeAlias& p ) { + return p.second.pressure; + }; + + const auto perforation_reservoir_rate = []( const PerfPairTypeAlias& p ) { + return p.second.reservoir_rate; + }; + + std::transform( well.completions.begin(), + well.completions.end(), + state.perfPress().begin() + wm.second[ 1 ], + perforation_pressure ); + + std::transform( well.completions.begin(), + well.completions.end(), + state.perfRates().begin() + wm.second[ 1 ], + perforation_reservoir_rate ); + } } }