Replaced SimulatorState -> SimulationDatacontainer

Have removed the SimulatorState base class, and instead replaced with
the SimulationDatacontainer class from opm-common. The SimulatorState
objects were typcially created with a default constructor, and then
explicitly initialized with a SimulatorState::init() method. For the
SimulationDataContainer RAII is employed; the init( ) has been removed -
and there is no default constructor.
This commit is contained in:
Joakim Hove 2016-02-25 21:47:47 +01:00
parent 301653de83
commit a256dc0e5d
11 changed files with 120 additions and 156 deletions

View File

@ -96,7 +96,8 @@ try
warnIfUnusedParams(param);
// Initialisation.
BlackoilState state;
//initBlackoilSurfvolUsingRSorRV(UgGridHelpers::numCells(grid), props, state);
BlackoilState state( UgGridHelpers::numCells(grid) , UgGridHelpers::numFaces(grid), 3);
initStateEquil(grid, props, deck, eclipseState, grav, state);
// Output.

View File

@ -18,8 +18,10 @@
*/
#include "config.h"
#include <opm/core/pressure/IncompTpfa.hpp>
#include <opm/common/data/SimulationDataContainer.hpp>
#include <opm/core/pressure/IncompTpfa.hpp>
#include <opm/core/props/IncompPropertiesInterface.hpp>
#include <opm/core/props/rock/RockCompressibility.hpp>
#include <opm/core/pressure/tpfa/ifs_tpfa.h>
@ -28,7 +30,6 @@
#include <opm/core/pressure/flow_bc.h>
#include <opm/core/linalg/LinearSolverInterface.hpp>
#include <opm/core/linalg/sparse_sys.h>
#include <opm/core/simulator/SimulatorState.hpp>
#include <opm/core/simulator/WellState.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/core/utility/miscUtilities.hpp>
@ -155,7 +156,7 @@ namespace Opm
/// May throw an exception if the number of iterations
/// exceed maxiter (set in constructor).
void IncompTpfa::solve(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state)
{
if (rock_comp_props_ != 0 && rock_comp_props_->isActive()) {
@ -169,7 +170,7 @@ namespace Opm
// Solve with no rock compressibility (linear eqn).
void IncompTpfa::solveIncomp(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state)
{
// Set up properties.
@ -207,7 +208,7 @@ namespace Opm
// Solve with rock compressibility (nonlinear eqn).
void IncompTpfa::solveRockComp(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state)
{
// This function is identical to CompressibleTpfa::solve().
@ -321,7 +322,7 @@ namespace Opm
/// Compute per-solve dynamic properties.
void IncompTpfa::computePerSolveDynamicData(const double /*dt*/,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& /*well_state*/)
{
// Computed here:
@ -369,7 +370,7 @@ namespace Opm
/// Compute per-iteration dynamic properties.
void IncompTpfa::computePerIterationDynamicData(const double /*dt*/,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& well_state)
{
// These are the variables that get computed by this function:
@ -396,7 +397,7 @@ namespace Opm
/// Compute the residual in h_->b and Jacobian in h_->A.
void IncompTpfa::assemble(const double dt,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& /*well_state*/)
{
const double* pressures = wells_ ? &pressures_[0] : &state.pressure()[0];
@ -462,7 +463,7 @@ namespace Opm
/// Compute the output.
void IncompTpfa::computeResults(SimulatorState& state,
void IncompTpfa::computeResults(SimulationDataContainer& state,
WellState& well_state) const
{
// Make sure h_ contains the direct-solution matrix

View File

@ -20,8 +20,6 @@
#ifndef OPM_INCOMPTPFA_HEADER_INCLUDED
#define OPM_INCOMPTPFA_HEADER_INCLUDED
#include <opm/core/simulator/SimulatorState.hpp>
#include <opm/core/pressure/tpfa/ifs_tpfa.h>
#include <vector>
@ -36,7 +34,7 @@ namespace Opm
class RockCompressibility;
class LinearSolverInterface;
class WellState;
class SimulatoreState;
class SimulationDataContainer;
/// Encapsulating a tpfa pressure solver for the incompressible-fluid case.
@ -114,7 +112,7 @@ namespace Opm
/// May throw an exception if the number of iterations
/// exceed maxiter (set in constructor).
void solve(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state);
@ -124,28 +122,28 @@ namespace Opm
protected:
// Solve with no rock compressibility (linear eqn).
void solveIncomp(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state);
// Solve with rock compressibility (nonlinear eqn).
void solveRockComp(const double dt,
SimulatorState& state,
SimulationDataContainer& state,
WellState& well_state);
private:
// Helper functions.
void computeStaticData();
virtual void computePerSolveDynamicData(const double dt,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& well_state);
void computePerIterationDynamicData(const double dt,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& well_state);
void assemble(const double dt,
const SimulatorState& state,
const SimulationDataContainer& state,
const WellState& well_state);
void solveIncrement();
double residualNorm() const;
double incrementNorm() const;
void computeResults(SimulatorState& state,
void computeResults(SimulationDataContainer& state,
WellState& well_state) const;
protected:

View File

@ -5,44 +5,16 @@
using namespace Opm;
void
BlackoilState::init(int number_of_cells, int number_of_phases, int num_phases)
const std::string BlackoilState::GASOILRATIO = "GASOILRATIO";
const std::string BlackoilState::RV = "RV";
const std::string BlackoilState::SURFACEVOL = "SURFACEVOL";
BlackoilState::BlackoilState( size_t num_cells , size_t num_faces , size_t num_phases)
: SimulationDataContainer( num_cells , num_faces , num_phases)
{
SimulatorState::init(number_of_cells, number_of_phases, num_phases);
// register cell data in base class
gorId_ = SimulatorState::registerCellData( "GASOILRATIO", 1 );
rvId_ = SimulatorState::registerCellData( "RV", 1 );
// surfvolumes intentionally empty, left to initBlackoilSurfvol
surfaceVolId_ = SimulatorState::registerCellData( "SURFACEVOL", 0 );
}
void
BlackoilState::init(const UnstructuredGrid& g, int num_phases)
{
init(g.number_of_cells, g.number_of_faces, num_phases);
}
bool
BlackoilState::equals(const SimulatorState& other,
double epsilon) const {
const BlackoilState* that = dynamic_cast <const BlackoilState*> (&other);
bool equal = that != 0;
equal = equal && SimulatorState::equals (other, epsilon);
equal = equal && cmp::vector_equal(this->surfacevol(),
that->surfacevol(),
cmp::default_abs_epsilon,
epsilon);
equal = equal && cmp::vector_equal(this->gasoilratio(),
that->gasoilratio(),
cmp::default_abs_epsilon,
epsilon);
equal = equal && cmp::vector_equal(this->rv(),
that->rv(),
cmp::default_abs_epsilon,
epsilon);
return equal;
registerCellData( GASOILRATIO , 1 );
registerCellData( RV, 1 );
registerCellData( SURFACEVOL, num_phases );
}

View File

@ -21,43 +21,34 @@
#ifndef OPM_BLACKOILSTATE_HEADER_INCLUDED
#define OPM_BLACKOILSTATE_HEADER_INCLUDED
#include <opm/common/data/SimulationDataContainer.hpp>
#include <opm/core/grid.h>
#include <opm/core/props/BlackoilPropertiesInterface.hpp>
#include <opm/core/simulator/SimulatorState.hpp>
#include <vector>
namespace Opm
{
/// Simulator state for a blackoil simulator.
class BlackoilState : public SimulatorState
class BlackoilState : public SimulationDataContainer
{
public:
using SimulatorState :: cellData ;
static const std::string GASOILRATIO;
static const std::string RV;
static const std::string SURFACEVOL;
virtual void init(const UnstructuredGrid& grid, int num_phases);
BlackoilState(size_t num_cells , size_t num_faces, size_t num_phases);
virtual void init(int number_of_cells, int number_of_faces, int num_phases);
virtual bool equals(const SimulatorState& other,
double epsilon = 1e-8) const;
std::vector<double>& surfacevol () { return getCellData("SURFACEVOL"); }
std::vector<double>& gasoilratio () { return getCellData(GASOILRATIO); }
std::vector<double>& rv () { return getCellData(RV); }
std::vector<double>& surfacevol () { return cellData()[ surfaceVolId_ ]; }
std::vector<double>& gasoilratio () { return cellData()[ gorId_ ] ; }
std::vector<double>& rv () {return cellData()[ rvId_ ] ; }
const std::vector<double>& surfacevol () const { return getCellData("SURFACEVOL"); }
const std::vector<double>& gasoilratio () const { return getCellData("GASOILRATIO"); }
const std::vector<double>& rv () const { return getCellData(RV); }
const std::vector<double>& surfacevol () const { return cellData()[ surfaceVolId_ ]; }
const std::vector<double>& gasoilratio () const { return cellData()[ gorId_ ] ; }
const std::vector<double>& rv () const { return cellData()[ rvId_ ] ; }
private:
int gorId_ ; // no entries = no cells (gas oil ratio id)
int rvId_ ; // no entries = no cells ( rv id )
int surfaceVolId_ ; // no entries = no cells * no phases (surfaceVol id )
//std::vector<double> surfvol_; // no entries = no cells * no phases
//std::vector<double> gor_ ; // no entries = no cells
//std::vector<double> rv_ ; // no entries = no cells
};
} // namespace Opm

View File

@ -0,0 +1,33 @@
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
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/>.
*/
#include <opm/core/simulator/TwophaseState.hpp>
namespace Opm
{
TwophaseState::TwophaseState(size_t num_cells , size_t num_faces) :
SimulationDataContainer( num_cells , num_faces , 2 )
{
}
}

View File

@ -20,22 +20,16 @@
#ifndef OPM_TWOPHASESTATE_HEADER_INCLUDED
#define OPM_TWOPHASESTATE_HEADER_INCLUDED
#include <opm/core/props/IncompPropertiesInterface.hpp>
#include <opm/core/simulator/SimulatorState.hpp>
#include <opm/common/data/SimulationDataContainer.hpp>
namespace Opm
{
/// Simulator state for a two-phase simulator.
class TwophaseState : public SimulatorState
class TwophaseState : public SimulationDataContainer
{
public:
virtual bool equals (const SimulatorState& other,
double epsilon = 1e-8) const;
TwophaseState(size_t num_cells , size_t num_faces);
};
} // namespace Opm
}
#include "TwophaseState_impl.hpp"
#endif // OPM_TWOPHASESTATE_HEADER_INCLUDED
#endif

View File

@ -22,7 +22,7 @@
#include <opm/parser/eclipse/Deck/Deck.hpp>
#include <opm/core/simulator/SimulatorState.hpp>
struct UnstructuredGrid;
namespace Opm
@ -31,6 +31,7 @@ namespace Opm
namespace parameter { class ParameterGroup; }
class IncompPropertiesInterface;
class BlackoilPropertiesInterface;
class SimulationDataContainer;
/// \file
///
@ -45,7 +46,7 @@ namespace Opm
enum ExtremalSat { MinSat, MaxSat };
template <class Props>
static void initSaturation(const std::vector<int>& cells , const Props& props , SimulatorState& state , ExtremalSat satType);
static void initSaturation(const std::vector<int>& cells , const Props& props , SimulationDataContainer& state , ExtremalSat satType);
/// Initialize a two-phase state from parameters.

View File

@ -20,11 +20,12 @@
#ifndef OPM_INITSTATE_IMPL_HEADER_INCLUDED
#define OPM_INITSTATE_IMPL_HEADER_INCLUDED
#include <opm/common/data/SimulationDataContainer.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/core/utility/parameters/ParameterGroup.hpp>
#include <opm/core/grid.h>
#include <opm/core/grid/GridHelpers.hpp>
#include <opm/common/ErrorMacros.hpp>
#include <opm/core/utility/MonotCubicInterpolator.hpp>
#include <opm/core/utility/Units.hpp>
#include <opm/core/props/IncompPropertiesInterface.hpp>
@ -42,7 +43,7 @@ namespace Opm
template <class Props>
static void initSaturation(const std::vector<int>& cells , const Props& props , SimulatorState& state , ExtremalSat satType) {
static void initSaturation(const std::vector<int>& cells , const Props& props , SimulationDataContainer& state , ExtremalSat satType) {
const int num_phases = state.numPhases();
std::vector<double> min_sat(num_phases * cells.size());
std::vector<double> max_sat(num_phases * cells.size());
@ -438,7 +439,6 @@ namespace Opm
if (num_phases != 2) {
OPM_THROW(std::runtime_error, "initStateTwophaseBasic(): currently handling only two-phase scenarios.");
}
state.init(number_of_cells, number_of_faces, num_phases);
const int num_cells = props.numCells();
// By default: initialise water saturation to minimum everywhere.
std::vector<int> all_cells(num_cells);
@ -563,7 +563,6 @@ namespace Opm
if (num_phases != 2) {
OPM_THROW(std::runtime_error, "initStateTwophaseBasic(): currently handling only two-phase scenarios.");
}
state.init(number_of_cells, number_of_faces, num_phases);
const int num_cells = props.numCells();
// By default: initialise water saturation to minimum everywhere.
std::vector<int> all_cells(num_cells);
@ -651,7 +650,6 @@ namespace Opm
OPM_THROW(std::runtime_error, "initStateFromDeck(): user specified property object with " << num_phases << " phases, "
"found " << pu.num_phases << " phases in deck.");
}
state.init(number_of_cells, number_of_faces, num_phases);
if (deck->hasKeyword("EQUIL") && deck->hasKeyword("PRESSURE")) {
OPM_THROW(std::runtime_error, "initStateFromDeck(): The deck must either specify the initial "
"condition using the PRESSURE _or_ the EQUIL keyword (currently it has both)");

View File

@ -1,6 +1,7 @@
#include <config.h>
#include <opm/core/grid/GridManager.hpp>
#include <opm/core/grid/GridHelpers.hpp>
#include <opm/core/props/BlackoilPhases.hpp>
#include <opm/parser/eclipse/Parser/Parser.hpp>
@ -38,41 +39,18 @@ BOOST_AUTO_TEST_CASE(EqualsDifferentDeckReturnFalse) {
Opm::DeckConstPtr deck2(parser->parseFile(filename2, parseContext));
GridManager gridManager1(deck1);
const UnstructuredGrid* grid1 = gridManager1.c_grid();
const UnstructuredGrid& grid1 = *gridManager1.c_grid();
GridManager gridManager2(deck2);
const UnstructuredGrid* grid2 = gridManager2.c_grid();
BlackoilState state1;
state1.init(*grid1, 3);
BlackoilState state2;
state2.init(*grid2, 3);
const UnstructuredGrid& grid2 = *gridManager2.c_grid();
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BlackoilState state1( UgGridHelpers::numCells( grid1 ) , UgGridHelpers::numFaces( grid1 ) , 3);
BlackoilState state2( UgGridHelpers::numCells( grid2 ) , UgGridHelpers::numFaces( grid2 ) , 3);
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
}
BOOST_AUTO_TEST_CASE(EqualsDifferentNumPhasesReturnFalse) {
const string filename = "testBlackoilState1.DATA";
Opm::ParseContext parseContext;
Opm::ParserPtr parser(new Opm::Parser());
Opm::DeckConstPtr deck(parser->parseFile(filename, parseContext));
GridManager gridManager(deck);
const UnstructuredGrid* grid = gridManager.c_grid();
BlackoilState state1;
state1.init(*grid, 3);
BlackoilState state2;
state2.init(*grid, 2);
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
}
BOOST_AUTO_TEST_CASE(EqualsNumericalDifferenceReturnFalse) {
@ -82,41 +60,39 @@ BOOST_AUTO_TEST_CASE(EqualsNumericalDifferenceReturnFalse) {
Opm::DeckConstPtr deck(parser->parseFile(filename , parseContext));
GridManager gridManager(deck);
const UnstructuredGrid* grid = gridManager.c_grid();
BlackoilState state1;
state1.init(*grid, 3);
BlackoilState state2;
state2.init(*grid, 3);
const UnstructuredGrid& grid = *gridManager.c_grid();
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BlackoilState state1( UgGridHelpers::numCells( grid ) , UgGridHelpers::numFaces( grid ) , 3);
BlackoilState state2( UgGridHelpers::numCells( grid ) , UgGridHelpers::numFaces( grid ) , 3);
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
{
std::vector<double>& p1 = state1.pressure();
std::vector<double>& p2 = state2.pressure();
p1[0] = p1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
p1[0] = p2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
{
std::vector<double>& gor1 = state1.gasoilratio();
std::vector<double>& gor2 = state2.gasoilratio();
gor1[0] = gor1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
gor1[0] = gor2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
{
std::vector<double>& p1 = state1.facepressure();
std::vector<double>& p2 = state2.facepressure();
p1[0] = p1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
p1[0] = p2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
{
@ -124,10 +100,10 @@ BOOST_AUTO_TEST_CASE(EqualsNumericalDifferenceReturnFalse) {
std::vector<double>& f2 = state2.faceflux();
if (f1.size() > 0 ) {
f1[0] = f1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
f1[0] = f2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
}
{
@ -135,19 +111,19 @@ BOOST_AUTO_TEST_CASE(EqualsNumericalDifferenceReturnFalse) {
std::vector<double>& sv2 = state2.surfacevol();
if (sv1.size() > 0) {
sv1[0] = sv1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
sv1[0] = sv2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
}
{
std::vector<double>& sat1 = state1.saturation();
std::vector<double>& sat2 = state2.saturation();
sat1[0] = sat1[0] * 2 + 1;
BOOST_CHECK_EQUAL( false , state1.equals(state2) );
BOOST_CHECK_EQUAL( false , state1.equal(state2) );
sat1[0] = sat2[0];
BOOST_CHECK_EQUAL( true , state1.equals(state2) );
BOOST_CHECK_EQUAL( true , state1.equal(state2) );
}
}

View File

@ -54,8 +54,7 @@ BOOST_AUTO_TEST_CASE(TestStoppedWells)
double target_surfacerate_prod;
const std::vector<double> pressure = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
BlackoilState state;
state.init(pressure.size(), 0, 3);
BlackoilState state( pressure.size() , 0 , 3);
state.pressure() = pressure;
// Both wells are open in the first schedule step