instantiate the ebos Simulator object in SimulatorFullyImplicitBlackoilEbos

this gets rid of some ugly hacks with static variables...
This commit is contained in:
Andreas Lauser 2016-08-08 14:31:32 +02:00
parent 3027e1f39d
commit 77f103fca5
2 changed files with 45 additions and 46 deletions

View File

@ -138,7 +138,8 @@ namespace Opm {
/// \param[in] has_disgas turn on dissolved gas
/// \param[in] has_vapoil turn on vaporized oil feature
/// \param[in] terminal_output request output to cout/cerr
BlackoilModelEbos(const ModelParameters& param,
BlackoilModelEbos(Simulator& ebosSimulator,
const ModelParameters& param,
const Grid& grid ,
const BlackoilPropsAdInterface& fluid,
const DerivedGeology& geo ,
@ -149,7 +150,8 @@ namespace Opm {
const bool has_disgas,
const bool has_vapoil,
const bool terminal_output)
: grid_ (grid)
: ebosSimulator_(ebosSimulator)
, grid_ (grid)
, fluid_ (fluid)
, geo_ (geo)
, rock_comp_props_(rock_comp_props)
@ -178,7 +180,6 @@ namespace Opm {
false } )
, terminal_output_ (terminal_output)
, current_relaxation_(1.0)
, ebosSimulator_( 0 )
{
const double gravity = detail::getGravity(geo_.gravity(), UgGridHelpers::dimensions(grid_));
const V depth = Opm::AutoDiffGrid::cellCentroidsZToEigen(grid_);
@ -187,22 +188,6 @@ namespace Opm {
wellModel().setWellsActive( localWellsActive() );
global_nc_ = Opm::AutoDiffGrid::numCells(grid_);
static Simulator* ebosPtr = 0;
if( ! ebosPtr )
{
std::string progName("./ebos");
std::string deckFile("--ecl-deck-file-name=");
deckFile += param.deck_file_name_;
char* ptr[2];
ptr[ 0 ] = const_cast< char * > (progName.c_str());
ptr[ 1 ] = const_cast< char * > (deckFile.c_str());
Simulator::registerParameters();
Ewoms::setupParameters_< TypeTag > ( 2, ptr );
ebosPtr = new Simulator();
ebosPtr->model().applyInitialSolution();
}
ebosSimulator_ = ebosPtr;
}
/// Called once before each time step.
@ -891,6 +876,7 @@ namespace Opm {
// --------- Data members ---------
Simulator& ebosSimulator_;
const Grid& grid_;
const BlackoilPropsAdInterface& fluid_;
const DerivedGeology& geo_;
@ -931,8 +917,6 @@ namespace Opm {
double current_relaxation_;
V dx_old_;
Simulator* ebosSimulator_;
// --------- Protected methods ---------
public:
@ -1328,7 +1312,7 @@ namespace Opm {
///////
for( int cellIdx = 0; cellIdx < numCells; ++cellIdx )
{
const auto& intQuants = *(ebosSimulator_->model().cachedIntensiveQuantities(cellIdx, /*timeIdx=*/0));
const auto& intQuants = *(ebosSimulator_.model().cachedIntensiveQuantities(cellIdx, /*timeIdx=*/0));
const auto& fs = intQuants.fluidState();
poVal[cellIdx] = fs.pressure(FluidSystem::oilPhaseIdx).value;
@ -1460,15 +1444,13 @@ namespace Opm {
const ReservoirState& reservoirState,
SolutionState& state)
{
assert( ebosSimulator_ );
convertInput( iterationIdx, reservoirState, ebosSimulator_ );
convertInput( iterationIdx, reservoirState, *ebosSimulator_ );
ebosSimulator_->startNextEpisode( timer.currentStepLength() );
ebosSimulator_->setEpisodeIndex( timer.reportStepNum() );
ebosSimulator_->setTimeStepIndex( timer.reportStepNum() );
ebosSimulator_->model().invalidateIntensiveQuantitiesCache(/*timeIdx=*/0);
ebosSimulator_->model().newtonMethod().setIterationIndex(iterationIdx);
ebosSimulator_.startNextEpisode( timer.currentStepLength() );
ebosSimulator_.setEpisodeIndex( timer.reportStepNum() );
ebosSimulator_.setTimeStepIndex( timer.reportStepNum() );
ebosSimulator_.model().invalidateIntensiveQuantitiesCache(/*timeIdx=*/0);
ebosSimulator_.model().newtonMethod().setIterationIndex(iterationIdx);
static int prevEpisodeIdx = 10000;
@ -1477,24 +1459,24 @@ namespace Opm {
// doing the notifactions here is conceptually wrong and also causes the
// endTimeStep() and endEpisode() methods to be not called for the
// simulation's last time step and episode.
if (ebosSimulator_->model().newtonMethod().numIterations() == 0 && prevEpisodeIdx >= 0)
ebosSimulator_->problem().endTimeStep();
if (ebosSimulator_->episodeIndex() != prevEpisodeIdx && prevEpisodeIdx >= 0)
ebosSimulator_->problem().endEpisode();
if (ebosSimulator_.model().newtonMethod().numIterations() == 0 && prevEpisodeIdx >= 0)
ebosSimulator_.problem().endTimeStep();
if (ebosSimulator_.episodeIndex() != prevEpisodeIdx && prevEpisodeIdx >= 0)
ebosSimulator_.problem().endEpisode();
if (ebosSimulator_->episodeIndex() != prevEpisodeIdx)
ebosSimulator_->problem().beginEpisode();
ebosSimulator_->setTimeStepSize( timer.currentStepLength() );
if (ebosSimulator_->model().newtonMethod().numIterations() == 0)
ebosSimulator_->problem().beginTimeStep();
ebosSimulator_->problem().beginIteration();
if (ebosSimulator_.episodeIndex() != prevEpisodeIdx)
ebosSimulator_.problem().beginEpisode();
ebosSimulator_.setTimeStepSize( timer.currentStepLength() );
if (ebosSimulator_.model().newtonMethod().numIterations() == 0)
ebosSimulator_.problem().beginTimeStep();
ebosSimulator_.problem().beginIteration();
ebosSimulator_->model().linearizer().linearize();
ebosSimulator_.model().linearizer().linearize();
ebosSimulator_->problem().endIteration();
prevEpisodeIdx = ebosSimulator_->episodeIndex();
convertResults(*ebosSimulator_, /*sparsityPattern=*/state.saturation[0]);
updateLegacyState(*ebosSimulator_, state);
ebosSimulator_.problem().endIteration();
prevEpisodeIdx = ebosSimulator_.episodeIndex();
convertResults(ebosSimulator_, /*sparsityPattern=*/state.saturation[0]);
updateLegacyState(ebosSimulator_, state);
if (param_.update_equations_scaling_) {
updateEquationsScaling();

View File

@ -37,6 +37,8 @@ template <class GridT>
class SimulatorFullyImplicitBlackoilEbos
{
public:
typedef typename TTAG(EclFlowProblem) TypeTag;
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator ;
typedef WellStateFullyImplicitBlackoil WellState;
typedef BlackoilState ReservoirState;
typedef BlackoilOutputWriter OutputWriter;
@ -110,6 +112,18 @@ public:
for (int cell = 0; cell < num_cells; ++cell) {
allcells_[cell] = cell;
}
std::string progName("flow_ebos");
std::string deckFile("--ecl-deck-file-name=");
deckFile += model_param_.deck_file_name_;
char* ptr[2];
ptr[ 0 ] = const_cast< char * > (progName.c_str());
ptr[ 1 ] = const_cast< char * > (deckFile.c_str());
Simulator::registerParameters();
Ewoms::setupParameters_< TypeTag > ( 2, ptr );
ebosSimulator_ = new Simulator();
ebosSimulator_->model().applyInitialSolution();
#if HAVE_MPI
if ( solver_.parallelInformation().type() == typeid(ParallelISTLInformation) )
{
@ -338,7 +352,8 @@ protected:
std::unique_ptr<Solver> createSolver(const WellModel& well_model)
{
auto model = std::unique_ptr<Model>(new Model(model_param_,
auto model = std::unique_ptr<Model>(new Model(*ebosSimulator_,
model_param_,
grid_,
props_,
geo_,
@ -551,6 +566,8 @@ protected:
// Data.
Simulator* ebosSimulator_;
typedef RateConverter::
SurfaceToReservoirVoidage< BlackoilPropsAdInterface,
std::vector<int> > RateConverterType;