opm-simulators
CompWellModel.hpp
1 /*
2  Copyright 2024, SINTEF Digital
3 
4  This file is part of the Open Porous Media project (OPM).
5 
6  OPM is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  OPM is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with OPM. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef OPM_COMPOSITIONAL_WELL_MODEL_HPP
21 #define OPM_COMPOSITIONAL_WELL_MODEL_HPP
22 
23 #include <opm/output/data/Wells.hpp>
24 
26 #include <opm/input/eclipse/Schedule/Events.hpp>
27 #include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
28 #include <opm/input/eclipse/Schedule/Schedule.hpp>
29 
30 #include <flowexperimental/comp/wells/CompWell.hpp>
31 #include <flowexperimental/comp/wells/CompWellState.hpp>
32 
33 #include <opm/simulators/utils/ParallelCommunication.hpp>
34 
35 #include <opm/simulators/wells/WellConnectionAuxiliaryModule.hpp>
36 
37 #include <opm/simulators/wells/PerforationData.hpp>
38 
39 #include <opm/simulators/timestepping/SimulatorReport.hpp>
40 
41 
42 #include <map>
43 #include <vector>
44 
45 namespace Opm {
46 
47 class Schedule;
48 struct NewtonIterationContext;
49 
50 template<typename TypeTag>
51 class CompWellModel : public WellConnectionAuxiliaryModule<TypeTag, CompWellModel<TypeTag>>
52 {
61 
62  // using NeighborSet = typename BaseAuxiliaryModule<TypeTag>::NeighborSet;
63 
64 public:
66 
68 
70  static const int numEq = Indices::numEq;
71  using VectorBlockType = Dune::FieldVector<Scalar, numEq>;
72  typedef Dune::BlockVector<VectorBlockType> BVector;
73 
74 
75  // TODO: Scalar will probably to be TypeTag later
76  using CompWellPtr = std::shared_ptr<CompWell<TypeTag> >;
77  CompWellModel(Simulator& /*simulator*/, const NewtonIterationContext& /*iter_ctx*/);
78 
79  // No extra dofs are inserted for wells. (we use a Schur complement.)
80  [[nodiscard]] unsigned numDofs() const override
81  { return 0; }
82 
83 // void addNeighbors(std::vector<NeighborSet>& /* neighbors */) const override
84 // {}
85 
86  void applyInitial() override {}
87 
88  // void linearize(SparseMatrixAdapter& /*matrix*/, GlobalEqVector& /*residual*/) override;
89 
90  template <class Restarter>
91  void serialize(Restarter& /*res*/)
92  {}
93 
94  template <class Restarter>
95  void deserialize(Restarter& /*res*/)
96  {}
97 
98  // OPMRST restart of compositional wells is not supported yet
99  template<class Serializer>
100  void serializeOp(Serializer& /*serializer*/)
101  {}
102 
103 
104  void beginEpisode() { beginReportStep(simulator_.episodeIndex()); }
105  void beginReportStep(unsigned report_step);
106  void beginTimeStep();
107  void beginIteration();
108  void restoreLastValidState();
109 
110  void init();
111  void endIteration() const {}
112  void endTimeStep();
113  void endEpisode() {}
114 
115  void computeTotalRatesForDof(RateVector& /*rate*/, unsigned /*globalIdx*/) const;
116  //
117  [[nodiscard]] data::Wells wellData() const;
118 
119  [[nodiscard]] data::WellBlockAveragePressures wellBlockAveragePressures() const {
120  return data::WellBlockAveragePressures{};
121  }
122  [[nodiscard]] data::GroupAndNetworkValues groupAndNetworkData(const int&) const {
123  return data::GroupAndNetworkValues{};
124  }
125  [[nodiscard]] WellTestState wellTestState() const {
126  return WellTestState{};
127  }
128 
129  // using the solution x to recover the solution xw for wells and applying
130  // xw to update Well State
131  void recoverWellSolutionAndUpdateWellState(const BVector& x);
132 
133  // some functions to compile
134  bool addMatrixContributions() const { return false; }
135  const Schedule& schedule() const { return schedule_; }
136  auto begin() const { return well_container_.begin(); }
137  auto end() const { return well_container_.end(); }
138 
139  const SimulatorReportSingle& lastReport() const { return last_report_; }
140  void prepareDeserialize(const int) {}
141  const std::map<std::string, double>& wellOpenTimes() const { return well_open_times_; }
142  const std::map<std::string, double>& wellCloseTimes() const { return well_close_times_; }
143  const WellGroupEvents& reportStepStartEvents() const { return report_step_start_events_; }
144  bool forceShutWellByName(const std::string& well_name, double simulation_time, bool dont_shut_grup_wells);
145 
146  template <class ReservoirCouplingSlave>
147  void setReservoirCouplingSlave(ReservoirCouplingSlave*) {}
148 
149  template <class ReservoirCouplingMaster>
150  void setReservoirCouplingMaster(ReservoirCouplingMaster*) {}
151 
152  bool getWellConvergence() const;
153 
154  // the following functions are not used while added to avoid modifying WellConnectionAuxiliaryModule.hpp
155  std::size_t compressedIndexForInterior(std::size_t cartesian_cell_idx) const;
156 
157  std::vector<int> getCellsForConnections(const Well& well) const;
158 
159 private:
160  Simulator& simulator_;
161  const Schedule& schedule_;
162  const SummaryState& summary_state_;
163  const EclipseState& ecl_state_;
164  const Parallel::Communication& comm_;
165 
166  // we might need something lighter
167  const CompositionalConfig& comp_config_;
168 
169  // we will need two to handle the changes between time stepping
170  CompWellState<FluidSystem> comp_well_states_;
171 
172  // saved state at beginning of report step, used to restore on failed timestep
173  CompWellState<FluidSystem> last_valid_comp_well_states_;
174 
175  // this is needed for parallel running, not all the wells will be in the same process
176  std::vector<Well> wells_ecl_;
177  std::vector<std::vector<CompConnectionData> > well_connection_data_;
178  // const Schedule& schedule_;
179  std::vector<CompWellPtr> well_container_;
180 
181  mutable BVector x_local_;
182 
183  std::size_t local_num_cells_{0};
184  SimulatorReportSingle last_report_{};
185  std::map<std::string, double> well_open_times_;
186  std::map<std::string, double> well_close_times_;
187  WellGroupEvents report_step_start_events_{};
188 
189  void createWellContainer();
190  void initWellContainer();
191 
192  void initWellConnectionData();
193  void initWellState();
194 
195  void assemble(const double dt);
196 
197  void calculateExplicitQuantities();
198 };
199 
200 } // end of namespace Opm
201 
202 #include "CompWellModel_impl.hpp"
203 
204 #endif // OPM_COMPOSITIONAL_WELL_MODEL_HPP
Context for iteration-dependent decisions in the Newton solver.
Definition: NewtonIterationContext.hpp:43
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
Base class for specifying auxiliary equations.
unsigned numDofs() const override
Returns the number of additional degrees of freedom required for the auxiliary module.
Definition: CompWellModel.hpp:80
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Static data associated with a well perforation.
Definition: BlackoilWellModelRestart.hpp:41
void applyInitial() override
Set the initial condition of the auxiliary module in the solution vector.
Definition: CompWellModel.hpp:86
Definition: WellConnectionAuxiliaryModule.hpp:38
Definition: CompWellModel.hpp:51