diff --git a/opm/simulators/wells/WellGroupHelpers.cpp b/opm/simulators/wells/WellGroupHelpers.cpp index eec227c76..46b7a56d7 100644 --- a/opm/simulators/wells/WellGroupHelpers.cpp +++ b/opm/simulators/wells/WellGroupHelpers.cpp @@ -21,19 +21,29 @@ #include #include +#include #include #include +#include +#include + +#include + #include #include +#include + +#include +#include #include #include #include -#include #include #include #include #include +#include namespace { Opm::GuideRate::RateVector @@ -655,6 +665,86 @@ namespace WellGroupHelpers } + template + void updateGpMaintTargetForGroups(const Group& group, + const Schedule& schedule, + const RegionalValues& regional_values, + const int reportStepIdx, + const double dt, + const WellState& well_state, + GroupState& group_state) + { + for (const std::string& groupName : group.groups()) { + const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); + updateGpMaintTargetForGroups(groupTmp, schedule, regional_values, reportStepIdx, dt, well_state, group_state); + } + const auto& gpm = group.gpmaint(); + if (!gpm) + return; + + const auto [name, number] = *gpm->region(); + const double error = gpm->pressure_target() - regional_values.pressure(number); + double current_rate = 0.0; + const auto& pu = well_state.phaseUsage(); + double sign = 1.0; + switch (gpm->flow_target()) { + case GPMaint::FlowTarget::RESV_PROD: + { + current_rate = -group_state.injection_vrep_rate(group.name()); + sign = -1.0; + break; + } + case GPMaint::FlowTarget::RESV_OINJ: + { + if (pu.phase_used[BlackoilPhases::Liquid]) + current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]]; + + break; + } + case GPMaint::FlowTarget::RESV_WINJ: + { + if (pu.phase_used[BlackoilPhases::Aqua]) + current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]]; + + break; + } + case GPMaint::FlowTarget::RESV_GINJ: + { + if (pu.phase_used[BlackoilPhases::Vapour]) + current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]]; + break; + } + case GPMaint::FlowTarget::SURF_OINJ: + { + if (pu.phase_used[BlackoilPhases::Liquid]) + current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]]; + + break; + } + case GPMaint::FlowTarget::SURF_WINJ: + { + if (pu.phase_used[BlackoilPhases::Aqua]) + current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]]; + + break; + } + case GPMaint::FlowTarget::SURF_GINJ: + { + if (pu.phase_used[BlackoilPhases::Vapour]) + current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]]; + + break; + } + default: + throw std::invalid_argument("Invalid Flow target type in GPMAINT"); + } + + auto& gpmaint_state = group_state.gpmaint(group.name()); + double rate = gpm->rate(gpmaint_state, current_rate, error, dt); + group_state.update_gpmaint_target(group.name(), std::max(0.0, sign * rate)); + } + + std::map @@ -1585,45 +1675,47 @@ namespace WellGroupHelpers } } - #define INSTANCE_WELLGROUP_HELPERS(...) \ - template \ - void updateGuideRateForProductionGroups>(const Group& group,\ - const Schedule& schedule, \ - const PhaseUsage& pu, \ - const int reportStepIdx, \ - const double& simTime, \ - WellState& wellState, \ - const GroupState& group_state, \ - const Dune::CollectiveCommunication<__VA_ARGS__>& comm, \ - GuideRate* guideRate, \ - std::vector& pot); \ - template \ - void updateGuideRatesForWells>(const Schedule& schedule, \ - const PhaseUsage& pu, \ - const int reportStepIdx, \ - const double& simTime, \ - const WellState& wellState, \ - const Dune::CollectiveCommunication<__VA_ARGS__>& comm, \ - GuideRate* guideRate); \ - template \ - void updateGuideRates>(const Group& group, \ - const Schedule& schedule, \ - const SummaryState& summary_state, \ - const PhaseUsage& pu, \ - const int report_step, \ - const double sim_time, \ - WellState& well_state, \ - const GroupState& group_state, \ - const Dune::CollectiveCommunication<__VA_ARGS__>& comm,\ - GuideRate* guide_rate, \ - std::vector& pot,\ - Opm::DeferredLogger& deferred_logger); + using AvgP = RegionAverageCalculator::AverageRegionalPressure,std::vector>; + template void WellGroupHelpers::updateGpMaintTargetForGroups(const Group&, + const Schedule&, + const AvgP&, + int, + double, + const WellState&, + GroupState&); -#if HAVE_MPI - INSTANCE_WELLGROUP_HELPERS(MPI_Comm) -#else - INSTANCE_WELLGROUP_HELPERS(Dune::No_Comm) -#endif +template +void updateGuideRateForProductionGroups(const Group& group, + const Schedule& schedule, + const PhaseUsage& pu, + const int reportStepIdx, + const double& simTime, + WellState& wellState, + const GroupState& group_state, + const Parallel::Communication& comm, + GuideRate* guideRate, + std::vector& pot); +template +void updateGuideRatesForWells(const Schedule& schedule, + const PhaseUsage& pu, + const int reportStepIdx, + const double& simTime, + const WellState& wellState, + const Parallel::Communication& comm, + GuideRate* guideRate); +template +void updateGuideRates(const Group& group, + const Schedule& schedule, + const SummaryState& summary_state, + const PhaseUsage& pu, + const int report_step, + const double sim_time, + WellState& well_state, + const GroupState& group_state, + const Parallel::Communication& comm, + GuideRate* guide_rate, + std::vector& pot, + DeferredLogger&); } // namespace WellGroupHelpers diff --git a/opm/simulators/wells/WellGroupHelpers.hpp b/opm/simulators/wells/WellGroupHelpers.hpp index 509299db0..dcaea6301 100644 --- a/opm/simulators/wells/WellGroupHelpers.hpp +++ b/opm/simulators/wells/WellGroupHelpers.hpp @@ -22,11 +22,6 @@ #define OPM_WELLGROUPHELPERS_HEADER_INCLUDED #include -#include -#include -#include -#include -#include #include #include @@ -44,9 +39,6 @@ class Schedule; class VFPProdProperties; class WellState; -template -class WellContainer; - namespace Network { class ExtNetwork; } namespace WellGroupHelpers @@ -194,77 +186,8 @@ namespace WellGroupHelpers const int reportStepIdx, const double dt, const WellState& well_state, - GroupState& group_state) - { - for (const std::string& groupName : group.groups()) { - const Group& groupTmp = schedule.getGroup(groupName, reportStepIdx); - updateGpMaintTargetForGroups(groupTmp, schedule, regional_values, reportStepIdx, dt, well_state, group_state); - } - const auto& gpm = group.gpmaint(); - if(!gpm) - return; + GroupState& group_state); - const auto [name, number] = *gpm->region(); - const double error = gpm->pressure_target() - regional_values.pressure(number); - double current_rate = 0.0; - const auto& pu = well_state.phaseUsage(); - double sign = 1.0; - switch (gpm->flow_target()) { - case Opm::GPMaint::FlowTarget::RESV_PROD: - { - current_rate = -group_state.injection_vrep_rate(group.name()); - sign = -1.0; - break; - } - case Opm::GPMaint::FlowTarget::RESV_OINJ: - { - if (pu.phase_used[BlackoilPhases::Liquid]) - current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]]; - - break; - } - case Opm::GPMaint::FlowTarget::RESV_WINJ: - { - if (pu.phase_used[BlackoilPhases::Aqua]) - current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]]; - - break; - } - case Opm::GPMaint::FlowTarget::RESV_GINJ: - { - if (pu.phase_used[BlackoilPhases::Vapour]) - current_rate = group_state.injection_reservoir_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]]; - break; - } - case Opm::GPMaint::FlowTarget::SURF_OINJ: - { - if (pu.phase_used[BlackoilPhases::Liquid]) - current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Liquid]]; - - break; - } - case Opm::GPMaint::FlowTarget::SURF_WINJ: - { - if (pu.phase_used[BlackoilPhases::Aqua]) - current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Aqua]]; - - break; - } - case Opm::GPMaint::FlowTarget::SURF_GINJ: - { - if (pu.phase_used[BlackoilPhases::Vapour]) - current_rate = group_state.injection_surface_rates(group.name())[pu.phase_pos[BlackoilPhases::Vapour]]; - - break; - } - default: - throw std::invalid_argument("Invalid Flow target type in GPMAINT"); - } - - auto& gpmaint_state = group_state.gpmaint(group.name()); - double rate = gpm->rate(gpmaint_state, current_rate, error, dt); - group_state.update_gpmaint_target(group.name(), std::max(0.0, sign * rate)); - } std::map computeNetworkPressures(const Opm::Network::ExtNetwork& network, const WellState& well_state,