diff --git a/opm/autodiff/SimulatorBase.hpp b/opm/autodiff/SimulatorBase.hpp index e9826120c..70e9f6647 100644 --- a/opm/autodiff/SimulatorBase.hpp +++ b/opm/autodiff/SimulatorBase.hpp @@ -74,13 +74,22 @@ namespace Opm { + template + struct SimulatorTraits; + /// Class collecting all necessary components for a two-phase simulation. - template + template class SimulatorBase { + typedef SimulatorTraits Traits; + public: - /// \brief The type of the grid that we use. - typedef GridT Grid; + typedef typename Traits::ReservoirState ReservoirState; + typedef typename Traits::WellState WellState; + typedef typename Traits::OutputWriter OutputWriter; + typedef typename Traits::Grid Grid; + typedef typename Traits::Model Model; + /// Initialise from parameters and objects to observe. /// \param[in] param parameters, this class accepts the following: /// parameter (default) effect @@ -118,7 +127,7 @@ namespace Opm const bool disgas, const bool vapoil, std::shared_ptr eclipse_state, - BlackoilOutputWriter& output_writer, + OutputWriter& output_writer, const std::vector& threshold_pressures_by_face); /// Run the simulation. @@ -129,17 +138,39 @@ namespace Opm /// \param[in,out] well_state state of wells: bhp, perforation rates /// \return simulation report, with timing data SimulatorReport run(SimulatorTimer& timer, - BlackoilState& state); + ReservoirState& state); protected: Implementation& asImp_() { return *static_cast(this); } const Implementation& asImp_() const { return *static_cast(this); } + void handleAdditionalWellInflow(SimulatorTimer& timer, + WellsManager& wells_manager, + WellState& well_state, + const Wells* wells) + {}; + + std::shared_ptr createModel(const typename Model::ModelParameters &modelParams, + const Wells* wells) + + { + return std::make_shared(modelParams, + grid_, + props_, + geo_, + rock_comp_props_, + wells, + solver_, + has_disgas_, + has_vapoil_, + terminal_output_); + } + void computeRESV(const std::size_t step, const Wells* wells, const BlackoilState& x, - WellStateFullyImplicitBlackoil& xw); + WellState& xw); // Data. typedef RateConverter:: @@ -164,7 +195,7 @@ namespace Opm // eclipse_state std::shared_ptr eclipse_state_; // output_writer - BlackoilOutputWriter& output_writer_; + OutputWriter& output_writer_; RateConverterType rateConverter_; // Threshold pressures. std::vector threshold_pressures_by_face_; diff --git a/opm/autodiff/SimulatorBase_impl.hpp b/opm/autodiff/SimulatorBase_impl.hpp index 07e611c03..08593400b 100644 --- a/opm/autodiff/SimulatorBase_impl.hpp +++ b/opm/autodiff/SimulatorBase_impl.hpp @@ -20,20 +20,19 @@ namespace Opm { - template - SimulatorBase::SimulatorBase(const parameter::ParameterGroup& param, - const Grid& grid, - const DerivedGeology& geo, - BlackoilPropsAdInterface& props, - const RockCompressibility* rock_comp_props, - NewtonIterationBlackoilInterface& linsolver, - const double* gravity, - const bool has_disgas, - const bool has_vapoil, - std::shared_ptr eclipse_state, - BlackoilOutputWriter& output_writer, - const std::vector& threshold_pressures_by_face) - + template + SimulatorBase::SimulatorBase(const parameter::ParameterGroup& param, + const Grid& grid, + const DerivedGeology& geo, + BlackoilPropsAdInterface& props, + const RockCompressibility* rock_comp_props, + NewtonIterationBlackoilInterface& linsolver, + const double* gravity, + const bool has_disgas, + const bool has_vapoil, + std::shared_ptr eclipse_state, + OutputWriter& output_writer, + const std::vector& threshold_pressures_by_face) : param_(param), grid_(grid), props_(props), @@ -69,11 +68,11 @@ namespace Opm #endif } - template - SimulatorReport SimulatorBase::run(SimulatorTimer& timer, - BlackoilState& state) + template + SimulatorReport SimulatorBase::run(SimulatorTimer& timer, + ReservoirState& state) { - WellStateFullyImplicitBlackoil prev_well_state; + WellState prev_well_state; // Create timers and file for writing timing info. Opm::time::StopWatch solver_timer; @@ -84,8 +83,6 @@ namespace Opm std::string tstep_filename = output_writer_.outputDirectory() + "/step_timing.txt"; std::ofstream tstep_os(tstep_filename.c_str()); - typedef GridT Grid; - typedef BlackoilModel Model; typedef typename Model::ModelParameters ModelParams; ModelParams modelParams( param_ ); typedef NewtonSolver Solver; @@ -134,9 +131,12 @@ namespace Opm props_.permeability(), is_parallel_run_); const Wells* wells = wells_manager.c_wells(); - WellStateFullyImplicitBlackoil well_state; + WellState well_state; well_state.init(wells, state, prev_well_state); + // give the polymer and surfactant simulators the chance to do their stuff + asImp_().handleAdditionalWellInflow(timer, wells_manager, well_state, wells); + // write simulation state at the report stage output_writer_.writeTimeStep( timer, state, well_state ); @@ -145,16 +145,16 @@ namespace Opm props_.updateSatHyst(state.saturation(), allcells_); // Compute reservoir volumes for RESV controls. - computeRESV(timer.currentStepNum(), wells, state, well_state); + asImp_().computeRESV(timer.currentStepNum(), wells, state, well_state); // Run a multiple steps of the solver depending on the time step control. solver_timer.start(); - Model model(modelParams, grid_, props_, geo_, rock_comp_props_, wells, solver_, has_disgas_, has_vapoil_, terminal_output_); + auto model = asImp_().createModel(modelParams, wells); if (!threshold_pressures_by_face_.empty()) { - model.setThresholdPressures(threshold_pressures_by_face_); + model->setThresholdPressures(threshold_pressures_by_face_); } - Solver solver(solverParams, model); + Solver solver(solverParams, *model); // If sub stepping is enabled allow the solver to sub cycle // in case the report steps are to large for the solver to converge @@ -327,11 +327,11 @@ namespace Opm } } // namespace SimFIBODetails - template - void SimulatorBase::computeRESV(const std::size_t step, - const Wells* wells, - const BlackoilState& x, - WellStateFullyImplicitBlackoil& xw) + template + void SimulatorBase::computeRESV(const std::size_t step, + const Wells* wells, + const BlackoilState& x, + WellState& xw) { typedef SimFIBODetails::WellMap WellMap; diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoil.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoil.hpp index bb11ab759..6ae7e91a4 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoil.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoil.hpp @@ -23,13 +23,25 @@ #include "SimulatorBase.hpp" namespace Opm { +template +class SimulatorFullyImplicitBlackoil; + +template +struct SimulatorTraits > +{ + typedef WellStateFullyImplicitBlackoil WellState; + typedef BlackoilState ReservoirState; + typedef BlackoilOutputWriter OutputWriter; + typedef GridT Grid; + typedef BlackoilModel Model; +}; /// a simulator for the blackoil model template class SimulatorFullyImplicitBlackoil - : public SimulatorBase > + : public SimulatorBase > { - typedef SimulatorBase > Base; + typedef SimulatorBase > Base; public: // forward the constructor to the base class SimulatorFullyImplicitBlackoil(const parameter::ParameterGroup& param,