From 833f5d053f8c817d288281e1f95b1783246b9c7c Mon Sep 17 00:00:00 2001 From: Joakim Hove Date: Wed, 6 Jan 2016 14:52:33 +0100 Subject: [PATCH] Avoid using Deck. Removed incorrect use of Deck for polymer and solvent properties. --- examples/sim_poly2p_comp_reorder.cpp | 2 +- examples/sim_poly2p_incomp_reorder.cpp | 2 +- ...latorFullyImplicitBlackoilSolvent_impl.hpp | 51 +++++------- opm/polymer/PolymerInflow.cpp | 83 +++---------------- opm/polymer/PolymerInflow.hpp | 14 +--- ...latorFullyImplicitBlackoilPolymer_impl.hpp | 2 +- ...rFullyImplicitCompressiblePolymer_impl.hpp | 2 +- 7 files changed, 35 insertions(+), 121 deletions(-) diff --git a/examples/sim_poly2p_comp_reorder.cpp b/examples/sim_poly2p_comp_reorder.cpp index f19359d6f..72b84f827 100644 --- a/examples/sim_poly2p_comp_reorder.cpp +++ b/examples/sim_poly2p_comp_reorder.cpp @@ -273,7 +273,7 @@ try if (wells.c_wells() == 0) { OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells."); } - polymer_inflow.reset(new PolymerInflowFromDeck(deck, eclipseState, *wells.c_wells(), props->numCells(), simtimer.currentStepNum())); + polymer_inflow.reset(new PolymerInflowFromDeck(eclipseState, *wells.c_wells(), props->numCells(), simtimer.currentStepNum())); } else { polymer_inflow.reset(new PolymerInflowBasic(param.getDefault("poly_start_days", 300.0)*Opm::unit::day, param.getDefault("poly_end_days", 800.0)*Opm::unit::day, diff --git a/examples/sim_poly2p_incomp_reorder.cpp b/examples/sim_poly2p_incomp_reorder.cpp index da8cebd45..5ab15aa9b 100644 --- a/examples/sim_poly2p_incomp_reorder.cpp +++ b/examples/sim_poly2p_incomp_reorder.cpp @@ -310,7 +310,7 @@ try if (wells.c_wells() == 0) { OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells."); } - polymer_inflow.reset(new PolymerInflowFromDeck(deck, eclipseState, *wells.c_wells(), props->numCells(), simtimer.currentStepNum())); + polymer_inflow.reset(new PolymerInflowFromDeck(eclipseState, *wells.c_wells(), props->numCells(), simtimer.currentStepNum())); } else { polymer_inflow.reset(new PolymerInflowBasic(param.getDefault("poly_start_days", 300.0)*Opm::unit::day, param.getDefault("poly_end_days", 800.0)*Opm::unit::day, diff --git a/opm/autodiff/SimulatorFullyImplicitBlackoilSolvent_impl.hpp b/opm/autodiff/SimulatorFullyImplicitBlackoilSolvent_impl.hpp index 052198fd3..3a3622acc 100644 --- a/opm/autodiff/SimulatorFullyImplicitBlackoilSolvent_impl.hpp +++ b/opm/autodiff/SimulatorFullyImplicitBlackoilSolvent_impl.hpp @@ -100,41 +100,28 @@ namespace Opm const int nw = wells->number_of_wells; std::vector perfcells_fraction(wells->well_connpos[nw], 0.0); - if (deck_->hasKeyword("WSOLVENT")) { + size_t currentStep = timer.currentStepNum(); + ScheduleConstPtr schedule = BaseType::eclipse_state_->getSchedule(); - size_t currentStep = timer.currentStepNum(); - ScheduleConstPtr schedule = BaseType::eclipse_state_->getSchedule(); - Opm::DeckKeywordConstPtr keyword = deck_->getKeyword("WSOLVENT"); - const int num_keywords = keyword->size(); - - for (int recordNr = 0; recordNr < num_keywords; ++recordNr) { - DeckRecordConstPtr record = keyword->getRecord(recordNr); - const std::string& wellNamesPattern = record->getItem("WELL")->getTrimmedString(0); - std::vector wells_solvent = schedule->getWells(wellNamesPattern); - for (auto wellIter = wells_solvent.begin(); wellIter != wells_solvent.end(); ++wellIter) { - WellPtr well_solvent = *wellIter; - WellInjectionProperties injection = well_solvent->getInjectionProperties(currentStep); - if (injection.injectorType == WellInjector::GAS) { - double solventFraction = well_solvent->getSolventFraction(currentStep); - // Find the solvent well in the well list and add properties to it - int wix = 0; - for (; wix < nw; ++wix) { - if (wellNamesPattern == wells->name[wix]) { - break; - } - } - if (wix == wells->number_of_wells) { - OPM_THROW(std::runtime_error, "Could not find a match for well " - << wellNamesPattern - << " from WSOLVENT."); - } - for (int j = wells->well_connpos[wix]; j < wells->well_connpos[wix+1]; ++j) { - perfcells_fraction[j] = solventFraction; - } - } else { - OPM_THROW(std::logic_error, "For solvent injector you must have a gas injector"); + for (const auto& well_solvent : schedule->getWells( currentStep )) { + WellInjectionProperties injection = well_solvent->getInjectionProperties(currentStep); + if (injection.injectorType == WellInjector::GAS) { + double solventFraction = well_solvent->getSolventFraction(currentStep); + // Find the solvent well in the well list and add properties to it + int wix = 0; + for (; wix < nw; ++wix) { + if (well_solvent->name() == wells->name[wix]) { + break; } } + if (wix == wells->number_of_wells) { + OPM_THROW(std::runtime_error, "Could not find a match for well " + << well_solvent->name() + << " from WSOLVENT."); + } + for (int j = wells->well_connpos[wix]; j < wells->well_connpos[wix+1]; ++j) { + perfcells_fraction[j] = solventFraction; + } } } well_state.solventFraction() = perfcells_fraction; diff --git a/opm/polymer/PolymerInflow.cpp b/opm/polymer/PolymerInflow.cpp index 2c78926ef..2c9f103c4 100644 --- a/opm/polymer/PolymerInflow.cpp +++ b/opm/polymer/PolymerInflow.cpp @@ -66,94 +66,31 @@ namespace Opm // ---------- Methods of PolymerInflowFromDeck ---------- - - /// Constructor. - /// @param[in] deck Input deck expected to contain WPOLYMER. - PolymerInflowFromDeck::PolymerInflowFromDeck(Opm::DeckConstPtr deck, - const Wells& wells, - const int num_cells) - : sparse_inflow_(num_cells) - { - if (!deck->hasKeyword("WPOLYMER")) { - OPM_MESSAGE("PolymerInflowFromDeck initialized without WPOLYMER in current epoch."); - return; - } - - // Extract concentrations and put into cell->concentration map. - Opm::DeckKeywordConstPtr wpolymerKeyword = deck->getKeyword("WPOLYMER"); - const int num_wpl = wpolymerKeyword->size(); - std::map perfcell_conc; - for (int i = 0; i < num_wpl; ++i) { - // Only use well name and polymer concentration. - // That is, we ignore salt concentration and group - // names. - int wix = 0; - for (; wix < wells.number_of_wells; ++wix) { - if (wpolymerKeyword->getRecord(i)->getItem("WELL")->getString(0) == wells.name[wix]) { - break; - } - } - if (wix == wells.number_of_wells) { - OPM_THROW(std::runtime_error, "Could not find a match for well " - << wpolymerKeyword->getRecord(i)->getItem("WELL")->getString(0) - << " from WPOLYMER."); - } - for (int j = wells.well_connpos[wix]; j < wells.well_connpos[wix+1]; ++j) { - const int perf_cell = wells.well_cells[j]; - perfcell_conc[perf_cell] = - wpolymerKeyword->getRecord(i)->getItem("POLYMER_CONCENTRATION")->getSIDouble(0); - } - } - - // Build sparse vector from map. - std::map::const_iterator it = perfcell_conc.begin(); - for (; it != perfcell_conc.end(); ++it) { - sparse_inflow_.addElement(it->second, it->first); - } - } - void - PolymerInflowFromDeck::setInflowValues(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, + PolymerInflowFromDeck::setInflowValues(Opm::EclipseStateConstPtr eclipseState, size_t currentStep) { - Opm::DeckKeywordConstPtr keyword = deck->getKeyword("WPOLYMER"); - - // Schedule schedule(deck); ScheduleConstPtr schedule = eclipseState->getSchedule(); - for (size_t recordNr = 0; recordNr < keyword->size(); recordNr++) { - DeckRecordConstPtr record = keyword->getRecord(recordNr); - - const std::string& wellNamesPattern = record->getItem("WELL")->getTrimmedString(0); - std::string wellName = record->getItem("WELL")->getTrimmedString(0); - std::vector wells = schedule->getWells(wellNamesPattern); - for (auto wellIter = wells.begin(); wellIter != wells.end(); ++wellIter) { - WellPtr well = *wellIter; - WellInjectionProperties injection = well->getInjectionProperties(currentStep); - if (injection.injectorType == WellInjector::WATER) { - WellPolymerProperties polymer = well->getPolymerProperties(currentStep); - wellPolymerRate_.insert(std::make_pair(wellName, polymer.m_polymerConcentration)); - } else { - OPM_THROW(std::logic_error, "For polymer injector you must have a water injector"); - } + for (const auto& well : schedule->getWells(currentStep)) { + WellInjectionProperties injection = well->getInjectionProperties(currentStep); + if (injection.injectorType == WellInjector::WATER) { + WellPolymerProperties polymer = well->getPolymerProperties(currentStep); + wellPolymerRate_.insert(std::make_pair(well->name(), polymer.m_polymerConcentration)); + } else { + OPM_THROW(std::logic_error, "For polymer injector you must have a water injector"); } } } /// Constructor. /// @param[in] deck Input deck expected to contain WPOLYMER. - PolymerInflowFromDeck::PolymerInflowFromDeck(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, + PolymerInflowFromDeck::PolymerInflowFromDeck(Opm::EclipseStateConstPtr eclipseState, const Wells& wells, const int num_cells, size_t currentStep) : sparse_inflow_(num_cells) { - if (!deck->hasKeyword("WPOLYMER")) { - OPM_MESSAGE("PolymerInflowFromDeck initialized without WPOLYMER in current epoch."); - return; - } - setInflowValues(deck, eclipseState, currentStep); + setInflowValues(eclipseState, currentStep); std::unordered_map::const_iterator map_it; // Extract concentrations and put into cell->concentration map. diff --git a/opm/polymer/PolymerInflow.hpp b/opm/polymer/PolymerInflow.hpp index 878bef9d6..b49899da8 100644 --- a/opm/polymer/PolymerInflow.hpp +++ b/opm/polymer/PolymerInflow.hpp @@ -88,21 +88,12 @@ namespace Opm class PolymerInflowFromDeck : public PolymerInflowInterface { public: - /// Constructor. - /// \param[in] deck Input deck expected to contain WPOLYMER. - /// \param[in] wells Wells structure. - /// \param[in] num_cells Number of cells in grid. - PolymerInflowFromDeck(Opm::DeckConstPtr deck, - const Wells& wells, - const int num_cells); - /// Constructor. /// \param[in] deck Input deck expected to contain WPOLYMER. /// \param[in] wells Wells structure. /// \param[in] num_cells Number of cells in grid. /// \param[in] currentStep Number of current simulation step. - PolymerInflowFromDeck(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, + PolymerInflowFromDeck(Opm::EclipseStateConstPtr eclipseState, const Wells& wells, const int num_cells, size_t currentStep); @@ -119,8 +110,7 @@ namespace Opm SparseVector sparse_inflow_; std::unordered_map wellPolymerRate_; - void setInflowValues(Opm::DeckConstPtr deck, - Opm::EclipseStateConstPtr eclipseState, + void setInflowValues(Opm::EclipseStateConstPtr eclipseState, size_t currentStep); }; diff --git a/opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer_impl.hpp b/opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer_impl.hpp index 050d79e38..17eb1b8ad 100644 --- a/opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer_impl.hpp +++ b/opm/polymer/fullyimplicit/SimulatorFullyImplicitBlackoilPolymer_impl.hpp @@ -110,7 +110,7 @@ namespace Opm if (wells_manager.c_wells() == 0) { OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells."); } - polymer_inflow_ptr.reset(new PolymerInflowFromDeck(deck_, BaseType::eclipse_state_, *wells, Opm::UgGridHelpers::numCells(BaseType::grid_), timer.currentStepNum())); + polymer_inflow_ptr.reset(new PolymerInflowFromDeck(BaseType::eclipse_state_, *wells, Opm::UgGridHelpers::numCells(BaseType::grid_), timer.currentStepNum())); } else { OPM_MESSAGE("Warning: simulating with no WPOLYMER in deck (no polymer will be injected)."); polymer_inflow_ptr.reset(new PolymerInflowBasic(0.0*Opm::unit::day, diff --git a/opm/polymer/fullyimplicit/SimulatorFullyImplicitCompressiblePolymer_impl.hpp b/opm/polymer/fullyimplicit/SimulatorFullyImplicitCompressiblePolymer_impl.hpp index ab722f1fa..28dc06e6c 100644 --- a/opm/polymer/fullyimplicit/SimulatorFullyImplicitCompressiblePolymer_impl.hpp +++ b/opm/polymer/fullyimplicit/SimulatorFullyImplicitCompressiblePolymer_impl.hpp @@ -82,7 +82,7 @@ handleAdditionalWellInflow(SimulatorTimer& timer, if (wells_manager.c_wells() == 0) { OPM_THROW(std::runtime_error, "Cannot control polymer injection via WPOLYMER without wells."); } - polymer_inflow_ptr.reset(new PolymerInflowFromDeck(deck_, BaseType::eclipse_state_, *wells, Opm::UgGridHelpers::numCells(BaseType::grid_), timer.currentStepNum())); + polymer_inflow_ptr.reset(new PolymerInflowFromDeck( BaseType::eclipse_state_, *wells, Opm::UgGridHelpers::numCells(BaseType::grid_), timer.currentStepNum())); } else { polymer_inflow_ptr.reset(new PolymerInflowBasic(0.0*Opm::unit::day, 1.0*Opm::unit::day,