opm-simulators
BlackoilWellModelNetworkGeneric.hpp
1 /*
2  Copyright 2016 SINTEF ICT, Applied Mathematics.
3  Copyright 2016 - 2017 Statoil ASA.
4  Copyright 2017 Dr. Blatt - HPC-Simulation-Software & Services
5  Copyright 2016 - 2018 IRIS AS
6 
7  This file is part of the Open Porous Media project (OPM).
8 
9  OPM is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  OPM is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with OPM. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef OPM_BLACKOILWELLMODEL_NETWORK_GENERIC_HEADER_INCLUDED
24 #define OPM_BLACKOILWELLMODEL_NETWORK_GENERIC_HEADER_INCLUDED
25 
26 #include <opm/input/eclipse/Schedule/Network/ExtNetwork.hpp>
27 
28 #include <opm/output/data/Groups.hpp>
29 
30 #include <opm/simulators/flow/NewtonIterationContext.hpp>
31 #include <opm/simulators/utils/ParallelCommunication.hpp>
32 
33 #include <map>
34 #include <optional>
35 #include <string>
36 
37 namespace Opm {
38  class Schedule;
39  class UnitSystem;
40  template<class Scalar, class IndexTraits> class BlackoilWellModelGeneric;
41  template<typename Scalar, typename IndexTraits> class WellInterfaceGeneric;
42  template<typename Scalar> class VFPProdProperties;
43 }
44 
45 namespace Opm {
46 
48 template<typename Scalar, typename IndexTraits>
50 {
51 public:
53 
54  virtual ~BlackoilWellModelNetworkGeneric() = default;
55 
57  bool active() const
58  { return active_; }
59 
60  const std::map<std::string, Scalar>&
61  nodePressures() const { return node_pressures_; }
62 
63  // do not use, only needed for serialization testing
64  void setNodePressures(const std::map<std::string, Scalar>& values)
65  { node_pressures_ = values; }
66 
67  void setFromRestart(const std::optional<std::map<std::string, double>>& restart_pressures);
68 
70  void initialize(const int report_step);
71 
73  void initializeWell(WellInterfaceGeneric<Scalar,IndexTraits>& well);
74 
76  void updateActiveState(const int report_step);
77 
81  bool needPreStepRebalance(const int report_step) const;
82 
85  bool shouldBalance(const int reportStepIndex) const;
87  bool willBalanceOnNextIteration(const int reportStepIndex) const;
88 
89  Scalar updatePressures(const int reportStepIdx,
90  const Scalar damping_factor,
91  const Scalar update_upper_bound);
92 
93  void assignNodeAndBranchValues(std::map<std::string, data::NodeData>& nodevalues,
94  std::map<std::string, data::BranchData>& branchvalues,
95  std::map<std::string, data::BranchData>& converged_branchvalues,
96  const int reportStepIdx) const;
97 
98  void commitState()
99  {
100  this->last_valid_node_pressures_ = this->node_pressures_;
101  this->last_valid_branch_data_ = this->branch_data_;
102  }
103 
104  void resetState()
105  {
106  this->node_pressures_ = this->last_valid_node_pressures_;
107  this->branch_data_ = this->last_valid_branch_data_;
108  }
109 
110  template<class Serializer>
111  void serializeOp(Serializer& serializer)
112  {
113  serializer(node_pressures_);
114  serializer(last_valid_node_pressures_);
115  serializer(branch_data_);
116  serializer(last_valid_branch_data_);
117  }
118 
119  bool operator==(const BlackoilWellModelNetworkGeneric<Scalar,IndexTraits>& rhs) const;
120 
121 protected:
122  std::pair<std::map<std::string, Scalar>, std::map<std::string, data::BranchData>>
123  computePressures(const Network::ExtNetwork& network,
124  const VFPProdProperties<Scalar>& vfp_prod_props,
125  const UnitSystem& unit_system,
126  const int reportStepIdx,
127  const Parallel::Communication& comm) const;
128 
129 
130  bool active_{false};
131  BlackoilWellModelGeneric<Scalar,IndexTraits>& well_model_;
132 
133  // Network pressures for output and initialization
134  std::map<std::string, Scalar> node_pressures_;
135  // Network branch pressure drops and flow rates for output (outlet branch for production network, inlet branch for injection network)
136  std::map<std::string, data::BranchData> branch_data_;
137  // Valid network pressures for output and initialization for safe restart after failed iterations
138  std::map<std::string, Scalar> last_valid_node_pressures_;
139  // Valid network branch pressure drops and flow rates for output (outlet branch for production network, inlet branch for injection network) for safe restart after failed iterations
140  std::map<std::string, data::BranchData> last_valid_branch_data_;
141 };
142 
143 } // namespace Opm
144 
145 #endif
Class which linearly interpolates BHP as a function of rate, tubing head pressure, water fraction, gas fraction, and artificial lift for production VFP tables, and similarly the BHP as a function of the rate and tubing head pressure.
Definition: BlackoilWellModelNetworkGeneric.hpp:42
bool active() const
return true if network is active (at least one network well in prediction mode)
Definition: BlackoilWellModelNetworkGeneric.hpp:57
void initializeWell(WellInterfaceGeneric< Scalar, IndexTraits > &well)
Initialize a single well according to network configuration.
Definition: BlackoilWellModelNetworkGeneric.cpp:331
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
bool willBalanceOnNextIteration(const int reportStepIndex) const
Checks if we will perform a network re-balance on the next Newton iteration.
Definition: BlackoilWellModelNetworkGeneric.cpp:162
Class for handling the blackoil well network model.
Definition: BlackoilWellModelGeneric.hpp:65
bool needPreStepRebalance(const int report_step) const
Checks if there are reasons to perform a pre-step network re-balance.
Definition: BlackoilWellModelNetworkGeneric.cpp:117
bool shouldBalance(const int reportStepIndex) const
Checks if we shall perform a network re-balance.
Definition: BlackoilWellModelNetworkGeneric.cpp:136
void initialize(const int report_step)
Initialize wells according to network configuration.
Definition: BlackoilWellModelNetworkGeneric.cpp:319
void updateActiveState(const int report_step)
Checks if network is active (at least one network well on prediction).
Definition: BlackoilWellModelNetworkGeneric.cpp:67