diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 4c30092ab..c70e45720 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -103,13 +103,13 @@ list (APPEND MAIN_SOURCE_FILES opm/simulators/wells/VFPHelpers.cpp opm/simulators/wells/VFPProdProperties.cpp opm/simulators/wells/VFPInjProperties.cpp + opm/simulators/wells/WellAssemble.cpp opm/simulators/wells/WellBhpThpCalculator.cpp opm/simulators/wells/WellConvergence.cpp opm/simulators/wells/WellGroupConstraints.cpp opm/simulators/wells/WellGroupControls.cpp opm/simulators/wells/WellGroupHelpers.cpp opm/simulators/wells/WellHelpers.cpp - opm/simulators/wells/WellInterfaceEval.cpp opm/simulators/wells/WellInterfaceFluidSystem.cpp opm/simulators/wells/WellInterfaceGeneric.cpp opm/simulators/wells/WellInterfaceIndices.cpp @@ -386,6 +386,7 @@ list (APPEND PUBLIC_HEADER_FILES opm/simulators/wells/VFPInjProperties.hpp opm/simulators/wells/VFPProdProperties.hpp opm/simulators/wells/VFPProperties.hpp + opm/simulators/wells/WellAssemble.hpp opm/simulators/wells/WellBhpThpCalculator.hpp opm/simulators/wells/WellConnectionAuxiliaryModule.hpp opm/simulators/wells/WellConvergence.hpp diff --git a/opm/simulators/wells/MultisegmentWellEval.cpp b/opm/simulators/wells/MultisegmentWellEval.cpp index 588702c02..ae3139dad 100644 --- a/opm/simulators/wells/MultisegmentWellEval.cpp +++ b/opm/simulators/wells/MultisegmentWellEval.cpp @@ -33,9 +33,9 @@ #include #include #include +#include #include #include -#include #include #include @@ -1228,7 +1228,7 @@ assembleControlEq(const WellState& well_state, } const EvalWell injection_rate = getWQTotal() / scaling; // Setup function for evaluation of BHP from THP (used only if needed). - auto bhp_from_thp = [&]() { + std::function bhp_from_thp = [&]() { const auto rates = getRates(); return WellBhpThpCalculator(baseif_).calculateBhpFromThp(well_state, rates, @@ -1238,22 +1238,21 @@ assembleControlEq(const WellState& well_state, deferred_logger); }; // Call generic implementation. - WellInterfaceEval(baseif_). - assembleControlEqInj(well_state, - group_state, - schedule, - summaryState, - inj_controls, - getBhp(), - injection_rate, - bhp_from_thp, - control_eq, - deferred_logger); + WellAssemble(baseif_).assembleControlEqInj(well_state, + group_state, + schedule, + summaryState, + inj_controls, + getBhp(), + injection_rate, + bhp_from_thp, + control_eq, + deferred_logger); } else { // Find rates. const auto rates = getRates(); // Setup function for evaluation of BHP from THP (used only if needed). - auto bhp_from_thp = [&]() { + std::function bhp_from_thp = [&]() { return WellBhpThpCalculator(baseif_).calculateBhpFromThp(well_state, rates, well, @@ -1262,17 +1261,16 @@ assembleControlEq(const WellState& well_state, deferred_logger); }; // Call generic implementation. - WellInterfaceEval(baseif_). - assembleControlEqProd(well_state, - group_state, - schedule, - summaryState, - prod_controls, - getBhp(), - rates, - bhp_from_thp, - control_eq, - deferred_logger); + WellAssemble(baseif_).assembleControlEqProd(well_state, + group_state, + schedule, + summaryState, + prod_controls, + getBhp(), + rates, + bhp_from_thp, + control_eq, + deferred_logger); } // using control_eq to update the matrix and residuals diff --git a/opm/simulators/wells/StandardWellEval.cpp b/opm/simulators/wells/StandardWellEval.cpp index 7cb2b3621..6437be059 100644 --- a/opm/simulators/wells/StandardWellEval.cpp +++ b/opm/simulators/wells/StandardWellEval.cpp @@ -32,9 +32,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -393,7 +393,7 @@ assembleControlEq(const WellState& well_state, // Find injection rate. const EvalWell injection_rate = getWQTotal(); // Setup function for evaluation of BHP from THP (used only if needed). - auto bhp_from_thp = [&]() { + std::function bhp_from_thp = [&]() { const auto rates = getRates(); return WellBhpThpCalculator(baseif_).calculateBhpFromThp(well_state, rates, @@ -404,7 +404,7 @@ assembleControlEq(const WellState& well_state, }; // Call generic implementation. const auto& inj_controls = well.injectionControls(summaryState); - WellInterfaceEval(baseif_). + WellAssemble(baseif_). assembleControlEqInj(well_state, group_state, schedule, @@ -419,7 +419,7 @@ assembleControlEq(const WellState& well_state, // Find rates. const auto rates = getRates(); // Setup function for evaluation of BHP from THP (used only if needed). - auto bhp_from_thp = [&]() { + std::function bhp_from_thp = [&]() { return WellBhpThpCalculator(baseif_).calculateBhpFromThp(well_state, rates, well, @@ -429,7 +429,7 @@ assembleControlEq(const WellState& well_state, }; // Call generic implementation. const auto& prod_controls = well.productionControls(summaryState); - WellInterfaceEval(baseif_). + WellAssemble(baseif_). assembleControlEqProd(well_state, group_state, schedule, diff --git a/opm/simulators/wells/WellInterfaceEval.cpp b/opm/simulators/wells/WellAssemble.cpp similarity index 71% rename from opm/simulators/wells/WellInterfaceEval.cpp rename to opm/simulators/wells/WellAssemble.cpp index 25473ca58..567395ad9 100644 --- a/opm/simulators/wells/WellInterfaceEval.cpp +++ b/opm/simulators/wells/WellAssemble.cpp @@ -20,7 +20,7 @@ */ #include -#include +#include #include #include @@ -44,29 +44,29 @@ namespace Opm { template -WellInterfaceEval:: -WellInterfaceEval(const WellInterfaceFluidSystem& baseif) - : baseif_(baseif) +WellAssemble:: +WellAssemble(const WellInterfaceFluidSystem& well) + : well_(well) {} template template void -WellInterfaceEval:: -assembleControlEqProd_(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::ProductionControls& controls, - const EvalWell& bhp, - const std::vector& rates, // Always 3 canonical rates. - const std::function& bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const +WellAssemble:: +assembleControlEqProd(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::ProductionControls& controls, + const EvalWell& bhp, + const std::vector& rates, // Always 3 canonical rates. + const std::function& bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger) const { - const auto current = well_state.well(baseif_.indexOfWell()).production_cmode; - const auto& pu = baseif_.phaseUsage(); - const double efficiencyFactor = baseif_.wellEcl().getEfficiencyFactor(); + const auto current = well_state.well(well_.indexOfWell()).production_cmode; + const auto& pu = well_.phaseUsage(); + const double efficiencyFactor = well_.wellEcl().getEfficiencyFactor(); switch (current) { case Well::ProducerCMode::ORAT: { @@ -95,13 +95,13 @@ assembleControlEqProd_(const WellState& well_state, break; } case Well::ProducerCMode::CRAT: { - OPM_DEFLOG_THROW(std::runtime_error, "CRAT control not supported " << baseif_.name(), deferred_logger); + OPM_DEFLOG_THROW(std::runtime_error, "CRAT control not supported " << well_.name(), deferred_logger); } case Well::ProducerCMode::RESV: { auto total_rate = rates[0]; // To get the correct type only. total_rate = 0.0; - std::vector convert_coeff(baseif_.numPhases(), 1.0); - baseif_.rateConverter().calcCoeff(/*fipreg*/ 0, baseif_.pvtRegionIdx(), convert_coeff); + std::vector convert_coeff(well_.numPhases(), 1.0); + well_.rateConverter().calcCoeff(/*fipreg*/ 0, well_.pvtRegionIdx(), convert_coeff); for (int phase = 0; phase < 3; ++phase) { if (pu.phase_used[phase]) { const int pos = pu.phase_pos[phase]; @@ -111,7 +111,7 @@ assembleControlEqProd_(const WellState& well_state, if (controls.prediction_mode) { control_eq = total_rate - controls.resv_rate; } else { - std::vector hrates(baseif_.numPhases(), 0.); + std::vector hrates(well_.numPhases(), 0.); if (FluidSystem::phaseIsActive(FluidSystem::waterPhaseIdx)) { hrates[pu.phase_pos[Water]] = controls.water_rate; } @@ -121,8 +121,8 @@ assembleControlEqProd_(const WellState& well_state, if (FluidSystem::phaseIsActive(FluidSystem::gasPhaseIdx)) { hrates[pu.phase_pos[Gas]] = controls.gas_rate; } - std::vector hrates_resv(baseif_.numPhases(), 0.); - baseif_.rateConverter().calcReservoirVoidageRates(/*fipreg*/ 0, baseif_.pvtRegionIdx(), hrates, hrates_resv); + std::vector hrates_resv(well_.numPhases(), 0.); + well_.rateConverter().calcReservoirVoidageRates(/*fipreg*/ 0, well_.pvtRegionIdx(), hrates, hrates_resv); double target = std::accumulate(hrates_resv.begin(), hrates_resv.end(), 0.0); control_eq = total_rate - target; } @@ -137,8 +137,8 @@ assembleControlEqProd_(const WellState& well_state, break; } case Well::ProducerCMode::GRUP: { - assert(baseif_.wellEcl().isAvailableForGroupControl()); - const auto& group = schedule.getGroup(baseif_.wellEcl().groupName(), baseif_.currentStep()); + assert(well_.wellEcl().isAvailableForGroupControl()); + const auto& group = schedule.getGroup(well_.wellEcl().groupName(), well_.currentStep()); // Annoying thing: the rates passed to this function are // always of size 3 and in canonical (for PhaseUsage) // order. This is what is needed for VFP calculations if @@ -153,9 +153,9 @@ assembleControlEqProd_(const WellState& well_state, } auto rCoeff = [this](const RegionId id, const int region, std::vector& coeff) { - baseif_.rateConverter().calcCoeff(id, region, coeff); + well_.rateConverter().calcCoeff(id, region, coeff); }; - WellGroupControls(baseif_).getGroupProductionControl(group, well_state, + WellGroupControls(well_).getGroupProductionControl(group, well_state, group_state, schedule, summaryState, @@ -166,10 +166,10 @@ assembleControlEqProd_(const WellState& well_state, break; } case Well::ProducerCMode::CMODE_UNDEFINED: { - OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + baseif_.name(), deferred_logger); + OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger); } case Well::ProducerCMode::NONE: { - OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + baseif_.name(), deferred_logger); + OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger); } } } @@ -177,22 +177,22 @@ assembleControlEqProd_(const WellState& well_state, template template void -WellInterfaceEval:: -assembleControlEqInj_(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::InjectionControls& controls, - const EvalWell& bhp, - const EvalWell& injection_rate, - const std::function& bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const +WellAssemble:: +assembleControlEqInj(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::InjectionControls& controls, + const EvalWell& bhp, + const EvalWell& injection_rate, + const std::function& bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger) const { - auto current = well_state.well(baseif_.indexOfWell()).injection_cmode; + auto current = well_state.well(well_.indexOfWell()).injection_cmode; const InjectorType injectorType = controls.injector_type; - const auto& pu = baseif_.phaseUsage(); - const double efficiencyFactor = baseif_.wellEcl().getEfficiencyFactor(); + const auto& pu = well_.phaseUsage(); + const double efficiencyFactor = well_.wellEcl().getEfficiencyFactor(); switch (current) { case Well::InjectorCMode::RATE: { @@ -200,8 +200,8 @@ assembleControlEqInj_(const WellState& well_state, break; } case Well::InjectorCMode::RESV: { - std::vector convert_coeff(baseif_.numPhases(), 1.0); - baseif_.rateConverter().calcInjCoeff(/*fipreg*/ 0, baseif_.pvtRegionIdx(), convert_coeff); + std::vector convert_coeff(well_.numPhases(), 1.0); + well_.rateConverter().calcInjCoeff(/*fipreg*/ 0, well_.pvtRegionIdx(), convert_coeff); double coeff = 1.0; @@ -219,7 +219,7 @@ assembleControlEqInj_(const WellState& well_state, break; } default: - throw("Expected WATER, OIL or GAS as type for injectors " + baseif_.wellEcl().name()); + throw("Expected WATER, OIL or GAS as type for injectors " + well_.wellEcl().name()); } control_eq = coeff * injection_rate - controls.reservoir_rate; @@ -234,13 +234,13 @@ assembleControlEqInj_(const WellState& well_state, break; } case Well::InjectorCMode::GRUP: { - assert(baseif_.wellEcl().isAvailableForGroupControl()); - const auto& group = schedule.getGroup(baseif_.wellEcl().groupName(), baseif_.currentStep()); + assert(well_.wellEcl().isAvailableForGroupControl()); + const auto& group = schedule.getGroup(well_.wellEcl().groupName(), well_.currentStep()); auto rCoeff = [this](const RegionId id, const int region, std::vector& coeff) { - baseif_.rateConverter().calcInjCoeff(id, region, coeff); + well_.rateConverter().calcInjCoeff(id, region, coeff); }; - WellGroupControls(baseif_).getGroupInjectionControl(group, + WellGroupControls(well_).getGroupInjectionControl(group, well_state, group_state, schedule, @@ -255,38 +255,38 @@ assembleControlEqInj_(const WellState& well_state, break; } case Well::InjectorCMode::CMODE_UNDEFINED: { - OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + baseif_.name(), deferred_logger); + OPM_DEFLOG_THROW(std::runtime_error, "Well control must be specified for well " + well_.name(), deferred_logger); } } } #define INSTANCE_METHODS(A,...) \ -template void WellInterfaceEval:: \ -assembleControlEqProd_<__VA_ARGS__>(const WellState&, \ - const GroupState&, \ - const Schedule&, \ - const SummaryState&, \ - const Well::ProductionControls&, \ - const __VA_ARGS__&, \ - const std::vector<__VA_ARGS__>&, \ - const std::function<__VA_ARGS__()>&, \ - __VA_ARGS__&, \ - DeferredLogger&) const; \ -template void WellInterfaceEval:: \ -assembleControlEqInj_<__VA_ARGS__>(const WellState&, \ +template void WellAssemble:: \ +assembleControlEqProd<__VA_ARGS__>(const WellState&, \ const GroupState&, \ const Schedule&, \ const SummaryState&, \ - const Well::InjectionControls&, \ - const __VA_ARGS__&, \ + const Well::ProductionControls&, \ const __VA_ARGS__&, \ + const std::vector<__VA_ARGS__>&, \ const std::function<__VA_ARGS__()>&, \ __VA_ARGS__&, \ - DeferredLogger&) const; + DeferredLogger&) const; \ +template void WellAssemble:: \ +assembleControlEqInj<__VA_ARGS__>(const WellState&, \ + const GroupState&, \ + const Schedule&, \ + const SummaryState&, \ + const Well::InjectionControls&, \ + const __VA_ARGS__&, \ + const __VA_ARGS__&, \ + const std::function<__VA_ARGS__()>&, \ + __VA_ARGS__&, \ + DeferredLogger&) const; using FluidSys = BlackOilFluidSystem; -template class WellInterfaceEval; +template class WellAssemble; INSTANCE_METHODS(FluidSys, DenseAd::Evaluation) INSTANCE_METHODS(FluidSys, DenseAd::Evaluation) diff --git a/opm/simulators/wells/WellAssemble.hpp b/opm/simulators/wells/WellAssemble.hpp new file mode 100644 index 000000000..d83393d3b --- /dev/null +++ b/opm/simulators/wells/WellAssemble.hpp @@ -0,0 +1,84 @@ +/* + Copyright 2017 SINTEF Digital, Mathematics and Cybernetics. + Copyright 2017 Statoil ASA. + Copyright 2017 IRIS + Copyright 2019 Norce + + 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 . +*/ + + +#ifndef OPM_WELL_ASSEMBLE_HEADER_INCLUDED +#define OPM_WELL_ASSEMBLE_HEADER_INCLUDED + +#include + +#include +#include + +#include + +namespace Opm +{ + +class DeferredLogger; +class Group; +class GroupState; +class Schedule; +class SummaryState; +template class WellInterfaceFluidSystem; +class WellState; + +template +class WellAssemble { + static constexpr int Water = BlackoilPhases::Aqua; + static constexpr int Oil = BlackoilPhases::Liquid; + static constexpr int Gas = BlackoilPhases::Vapour; + +public: + WellAssemble(const WellInterfaceFluidSystem& well); + + template + void assembleControlEqProd(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::ProductionControls& controls, + const EvalWell& bhp, + const std::vector& rates, // Always 3 canonical rates. + const std::function& bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger) const; + + template + void assembleControlEqInj(const WellState& well_state, + const GroupState& group_state, + const Schedule& schedule, + const SummaryState& summaryState, + const Well::InjectionControls& controls, + const EvalWell& bhp, + const EvalWell& injection_rate, + const std::function& bhp_from_thp, + EvalWell& control_eq, + DeferredLogger& deferred_logger) const; + +private: + const WellInterfaceFluidSystem& well_; +}; + +} + +#endif // OPM_WELL_ASSEMBLE_HEADER_INCLUDED diff --git a/opm/simulators/wells/WellInterfaceEval.hpp b/opm/simulators/wells/WellInterfaceEval.hpp deleted file mode 100644 index c19aadf5d..000000000 --- a/opm/simulators/wells/WellInterfaceEval.hpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - Copyright 2017 SINTEF Digital, Mathematics and Cybernetics. - Copyright 2017 Statoil ASA. - Copyright 2017 IRIS - Copyright 2019 Norce - - 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 . -*/ - - -#ifndef OPM_WELLINTERFACE_EVAL_HEADER_INCLUDED -#define OPM_WELLINTERFACE_EVAL_HEADER_INCLUDED - -#include - -#include -#include - -#include - -namespace Opm -{ - -class DeferredLogger; -class Group; -class GroupState; -class Schedule; -class SummaryState; -template class WellInterfaceFluidSystem; -class WellState; - -template -class WellInterfaceEval { - static constexpr int Water = BlackoilPhases::Aqua; - static constexpr int Oil = BlackoilPhases::Liquid; - static constexpr int Gas = BlackoilPhases::Vapour; - -public: - WellInterfaceEval(const WellInterfaceFluidSystem& baseif); - - template - void assembleControlEqProd(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::ProductionControls& controls, - const EvalWell& bhp, - const std::vector& rates, // Always 3 canonical rates. - BhpFromThpFunc bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const - { - std::function eval = [&bhp_from_thp]() { return bhp_from_thp(); }; - assembleControlEqProd_(well_state, - group_state, - schedule, - summaryState, - controls, - bhp, - rates, - eval, - control_eq, - deferred_logger); - } - - template - void assembleControlEqProd_(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::ProductionControls& controls, - const EvalWell& bhp, - const std::vector& rates, // Always 3 canonical rates. - const std::function& bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const; - - template - void assembleControlEqInj(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::InjectionControls& controls, - const EvalWell& bhp, - const EvalWell& injection_rate, - BhpFromThpFunc bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const - { - std::function eval = [&bhp_from_thp]() { return bhp_from_thp(); }; - assembleControlEqInj_(well_state, - group_state, - schedule, - summaryState, - controls, - bhp, - injection_rate, - eval, - control_eq, - deferred_logger); - } - - template - void assembleControlEqInj_(const WellState& well_state, - const GroupState& group_state, - const Schedule& schedule, - const SummaryState& summaryState, - const Well::InjectionControls& controls, - const EvalWell& bhp, - const EvalWell& injection_rate, - const std::function& bhp_from_thp, - EvalWell& control_eq, - DeferredLogger& deferred_logger) const; - -protected: - const WellInterfaceFluidSystem& baseif_; -}; - -} - -#endif // OPM_WELLINTERFACE_EVAL_HEADER_INCLUDED