opm-simulators
BlackoilWellModelNldd.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 #ifndef OPM_BLACKOILWELLMODEL_NLDD_HEADER_INCLUDED
23 #define OPM_BLACKOILWELLMODEL_NLDD_HEADER_INCLUDED
24 
25 #include <opm/grid/utility/SparseTable.hpp>
26 
27 #include <opm/simulators/timestepping/ConvergenceReport.hpp>
28 
29 #include <opm/simulators/utils/DeferredLogger.hpp>
30 
31 #include <opm/simulators/wells/BlackoilWellModel.hpp>
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
37 namespace Opm {
38 
39 template<typename Scalar, typename IndexTraits>
41 {
42 public:
43  std::vector<Scalar> getPrimaryVarsDomain(const int domainIdx) const;
44  void setPrimaryVarsDomain(const int domainIdx, const std::vector<Scalar>& vars);
45 
46  const SparseTable<int>& well_local_cells() const
47  { return well_local_cells_; }
48 
49  const std::map<std::string, int>& well_domain() const
50  { return well_domain_; }
51 
52 protected:
54  : genWellModel_(model)
55  {}
56 
57  void calcDomains(const std::vector<const SubDomainIndices*>& domains);
58 
59 private:
60  void logDomains() const;
61 
62  void findWellDomains(const std::vector<const SubDomainIndices*>& domains);
63 
64  void calcLocalIndices(const std::vector<const SubDomainIndices*>& domains);
65 
67 
68  // Keep track of the domain of each well
69  std::map<std::string, int> well_domain_{};
70 
71  // Store the local index of the wells perforated cells in the domain
72  SparseTable<int> well_local_cells_{};
73 };
74 
76 template<typename TypeTag>
78  public BlackoilWellModelNlddGeneric<GetPropType<TypeTag, Properties::Scalar>,
79  typename GetPropType<TypeTag, Properties::FluidSystem>::IndexTraitsType>
80 {
81 public:
82  // --------- Types ---------
85  using PressureMatrix = typename BlackoilWellModel<TypeTag>::PressureMatrix;
86  using BVector = typename BlackoilWellModel<TypeTag>::BVector;
88  using IndexTraits = typename FluidSystem::IndexTraitsType;
90 
91  using Domain = SubDomain<Grid>;
92 
94  : BlackoilWellModelNlddGeneric<Scalar, IndexTraits>(model)
95  , wellModel_(model)
96  {}
97 
98  void addWellPressureEquations(PressureMatrix& jacobian,
99  const BVector& weights,
100  const bool use_well_weights,
101  const int domainIndex) const;
102 
103  // prototype for assemble function for ASPIN solveLocal()
104  // will try to merge back to assemble() when done prototyping
105  void assemble(const double dt,
106  const Domain& domain);
107 
108  void updateWellControls(const Domain& domain);
109 
110  void setupDomains(const std::vector<Domain>& domains);
111 
112  // Check if well equations are converged locally.
113  ConvergenceReport getWellConvergence(const Domain& domain,
114  const std::vector<Scalar>& B_avg,
115  DeferredLogger& local_deferredLogger) const;
116 
117  // using the solution x to recover the solution xw for wells and applying
118  // xw to update Well State
119  void recoverWellSolutionAndUpdateWellState(const BVector& x,
120  const int domainIdx);
121 
122  // Get number of wells on this rank
123  int numLocalWells() const
124  {
125  return wellModel_.numLocalWells();
126  }
127 
128  // Get number of wells on this rank
129  int numLocalWellsEnd() const
130  {
131  return wellModel_.numLocalWellsEnd();
132  }
133 
134 private:
135  BlackoilWellModel<TypeTag>& wellModel_;
136 
137  void assembleWellEq(const double dt,
138  const Domain& domain);
139 
140  // These members are used to avoid reallocation in specific functions
141  // instead of using local variables.
142  // Their state is not relevant between function calls, so they can
143  // (and must) be mutable, as the functions using them are const.
144  mutable BVector x_local_;
145 
146 };
147 
148 } // namespace Opm
149 
150 #include "BlackoilWellModelNldd_impl.hpp"
151 
152 #endif
Class for handling the blackoil well model.
Definition: ActionHandler.hpp:39
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(...))
Definition: propertysystem.hh:233
Representing a part of a grid, in a way suitable for performing local solves.
Definition: SubDomain.hpp:84
Class for handling the blackoil well model.
Definition: BlackoilModelProperties.hpp:32
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Class for handling the blackoil well model in a NLDD solver.
Definition: BlackoilWellModel.hpp:86
Definition: BlackoilWellModelNldd.hpp:40