Merge pull request #1016 from jokva/refactor-output-restart

Breaking opm-core dependency in opm-output; new summary implementation
This commit is contained in:
Joakim Hove 2016-06-10 13:15:34 +02:00 committed by GitHub
commit d3aa0926c8
7 changed files with 233 additions and 8 deletions

View File

@ -25,6 +25,7 @@ install:
- git clone https://github.com/OPM/opm-common.git
- git clone https://github.com/OPM/opm-parser.git
- git clone https://github.com/OPM/opm-material.git
- git clone https://github.com/OPM/opm-output.git
- git clone https://github.com/OPM/opm-data.git
- opm-parser/travis/clone-and-build-ert.sh
@ -34,6 +35,7 @@ install:
- opm-common/travis/build-opm-common.sh
- opm-parser/travis/build-opm-parser.sh
- opm-parser/travis/build-opm-output.sh
- opm-material/travis/build-opm-material.sh
script: opm-core/travis/build-and-test-opm-core.sh

View File

@ -372,6 +372,7 @@ list (APPEND PUBLIC_HEADER_FILES
opm/core/transport/reorder/reordersequence.h
opm/core/transport/reorder/tarjan.h
opm/core/utility/Average.hpp
opm/core/utility/Compat.hpp
opm/core/utility/CompressedPropertyAccess.hpp
opm/core/utility/DataMap.hpp
opm/core/utility/Event.hpp

View File

@ -66,16 +66,16 @@ namespace Opm {
\param well_state additional well state object
\param outputWriter writer object to write sub steps
*/
template <class Solver, class State, class WellState>
template <class Solver, class State, class WellState, class Output>
void step( const SimulatorTimer& timer,
Solver& solver, State& state, WellState& well_state,
OutputWriter& outputWriter );
Output& outputWriter );
protected:
template <class Solver, class State, class WellState>
template <class Solver, class State, class WellState, class Output>
void stepImpl( const SimulatorTimer& timer,
Solver& solver, State& state, WellState& well_state,
OutputWriter* outputWriter);
Output* outputWriter);
typedef std::unique_ptr< TimeStepControlInterface > TimeStepControlType;

View File

@ -110,20 +110,20 @@ namespace Opm {
stepImpl( simulatorTimer, solver, state, well_state );
}
template <class Solver, class State, class WellState>
template <class Solver, class State, class WellState, class Output>
void AdaptiveTimeStepping::
step( const SimulatorTimer& simulatorTimer, Solver& solver, State& state, WellState& well_state,
OutputWriter& outputWriter )
Output& outputWriter )
{
stepImpl( simulatorTimer, solver, state, well_state, &outputWriter );
}
// implementation of the step method
template <class Solver, class State, class WState>
template <class Solver, class State, class WState, class Output >
void AdaptiveTimeStepping::
stepImpl( const SimulatorTimer& simulatorTimer,
Solver& solver, State& state, WState& well_state,
OutputWriter* outputWriter )
Output* outputWriter )
{
const double timestep = simulatorTimer.currentStepLength();

View File

@ -1,6 +1,8 @@
#include "BlackoilState.hpp"
#include <opm/common/util/numeric/cmp.hpp>
#include <opm/core/props/BlackoilPropertiesInterface.hpp>
#include <opm/core/simulator/WellState.hpp>
#include <opm/output/Wells.hpp>
using namespace Opm;

View File

@ -22,8 +22,11 @@
#include <opm/core/wells.h>
#include <opm/core/well_controls.h>
#include <opm/output/Wells.hpp>
#include <array>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include <cassert>
@ -49,6 +52,7 @@ namespace Opm
{
// clear old name mapping
wellMap_.clear();
wells_.reset( clone_wells( wells ) );
if (wells) {
const int nw = wells->number_of_wells;
@ -208,6 +212,43 @@ namespace Opm
return wellRates().size() / numWells();
}
virtual data::Wells report() const
{
return { { /* WellState offers no completion data, so that has to be added later */ },
this->bhp(),
this->temperature(),
this->wellRates(),
this->perfPress(),
this->perfRates() };
}
virtual ~WellState() {}
WellState() = default;
WellState( const WellState& rhs ) :
bhp_( rhs.bhp_ ),
thp_( rhs.thp_ ),
temperature_( rhs.temperature_ ),
wellrates_( rhs.wellrates_ ),
perfrates_( rhs.perfrates_ ),
perfpress_( rhs.perfpress_ ),
wellMap_( rhs.wellMap_ ),
wells_( clone_wells( rhs.wells_.get() ) )
{}
WellState& operator=( const WellState& rhs ) {
this->bhp_ = rhs.bhp_;
this->thp_ = rhs.thp_;
this->temperature_ = rhs.temperature_;
this->wellrates_ = rhs.wellrates_;
this->perfrates_ = rhs.perfrates_;
this->perfpress_ = rhs.perfpress_;
this->wellMap_ = rhs.wellMap_;
this->wells_.reset( clone_wells( rhs.wells_.get() ) );
return *this;
}
private:
std::vector<double> bhp_;
std::vector<double> thp_;
@ -217,6 +258,12 @@ namespace Opm
std::vector<double> perfpress_;
WellMapType wellMap_;
protected:
struct wdel {
void operator()( Wells* w ) { destroy_wells( w ); }
};
std::unique_ptr< Wells, wdel > wells_;
};
} // namespace Opm

173
opm/core/utility/Compat.hpp Normal file
View File

@ -0,0 +1,173 @@
/*
Copyright 2016 Statoil ASA
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_CORE_COMPAT_HPP
#define OPM_CORE_COMPAT_HPP
#include <opm/common/data/SimulationDataContainer.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <opm/core/simulator/BlackoilState.hpp>
#include <opm/core/simulator/WellState.hpp>
#include <opm/output/Cells.hpp>
#include <opm/output/Wells.hpp>
namespace Opm {
inline std::vector< double > destripe( const std::vector< double >& v,
size_t stride,
size_t offset ) {
std::vector< double > dst( v.size() / stride );
size_t di = 0;
for( size_t i = offset; i < v.size(); i += stride ) {
dst[ di++ ] = v[ i ];
}
return dst;
}
inline std::vector< double >& stripe( const std::vector< double >& v,
size_t stride,
size_t offset,
std::vector< double >& dst ) {
/* does little range checking etc; for future revisions */
size_t vi = 0;
for( size_t i = offset; i < dst.size(); i += stride ) {
dst[ i ] = v[ vi++ ];
}
return dst;
}
inline data::Solution simToSolution( const SimulationDataContainer& reservoir,
PhaseUsage phases ) {
using ds = data::Solution::key;
data::Solution sol;
sol.insert( ds::PRESSURE, reservoir.pressure() );
sol.insert( ds::TEMP, reservoir.temperature() );
const auto ph = reservoir.numPhases();
const auto& sat = reservoir.saturation();
const auto aqua = BlackoilPhases::Aqua;
const auto vapour = BlackoilPhases::Vapour;
if( phases.phase_used[ aqua ] ) {
sol.insert( ds::SWAT, destripe( sat, ph, phases.phase_pos[ aqua ] ) );
}
if( phases.phase_used[ vapour ] ) {
sol.insert( ds::SGAS, destripe( sat, ph, phases.phase_pos[ vapour ] ) );
}
if( reservoir.hasCellData( BlackoilState::GASOILRATIO ) ) {
sol.insert( ds::RS, reservoir.getCellData( BlackoilState::GASOILRATIO ) );
}
if( reservoir.hasCellData( BlackoilState::RV ) ) {
sol.insert( ds::RV, reservoir.getCellData( BlackoilState::RV ) );
}
sol.sdc = &reservoir;
return sol;
}
inline void solutionToSim( const data::Solution& sol,
PhaseUsage phases,
SimulationDataContainer& state ) {
using ds = data::Solution::key;
const auto stride = phases.num_phases;
if( sol.has( ds::SWAT ) ) {
stripe( sol[ ds::SWAT ],
stride,
phases.phase_pos[ BlackoilPhases::Aqua ],
state.saturation() );
}
if( sol.has( ds::SGAS ) ) {
stripe( sol[ ds::SGAS ],
stride,
phases.phase_pos[ BlackoilPhases::Vapour ],
state.saturation() );
}
if( sol.has( ds::PRESSURE ) ) {
state.pressure() = sol[ ds::PRESSURE ];
}
if( sol.has( ds::TEMP ) ) {
state.temperature() = sol[ ds::TEMP ];
}
if( sol.has( ds::RS ) ) {
state.getCellData( "GASOILRATIO" ) = sol[ ds::RS ];
}
if( sol.has( ds::RV ) ) {
state.getCellData( "RV" ) = sol[ ds::RV ];
}
}
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;
}
}
#endif //OPM_CORE_COMPAT_HPP