opm-simulators
FlowGenericVanguard.hpp
Go to the documentation of this file.
1 // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 // vi: set et ts=4 sw=4 sts=4:
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 2 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  Consult the COPYING file in the top-level source directory of this
20  module for the precise wording of the license and the list of
21  copyright holders.
22 */
27 #ifndef OPM_FLOW_GENERIC_VANGUARD_HPP
28 #define OPM_FLOW_GENERIC_VANGUARD_HPP
29 
30 #include <dune/common/parallel/communication.hh>
31 
32 #include <opm/common/OpmLog/OpmLog.hpp>
33 
34 #include <opm/grid/common/GridEnums.hpp>
35 
36 #include <opm/input/eclipse/Schedule/Well/WellTestState.hpp>
37 
38 #include <opm/simulators/utils/ParallelCommunication.hpp>
39 
40 #include <cassert>
41 #include <memory>
42 #include <optional>
43 #include <string>
44 #include <unordered_map>
45 #include <utility>
46 #include <vector>
47 
48 namespace Opm::Parameters {
49 
50 struct AllowDistributedWells { static constexpr bool value = false; };
51 struct AllowSplittingInactiveWells { static constexpr bool value = true; };
52 
53 struct EclOutputInterval { static constexpr int value = -1; };
54 struct EdgeWeightsMethod { static constexpr auto value = "transmissibility"; };
55 struct EnableDryRun { static constexpr auto value = "auto"; };
56 struct EnableEclOutput { static constexpr auto value = true; };
57 struct EnableOpmRstFile { static constexpr bool value = false; };
58 struct ExternalPartition { static constexpr auto* value = ""; };
59 
60 template<class Scalar>
61 struct ImbalanceTol { static constexpr Scalar value = 1.1; };
62 
63 struct IgnoreKeywords { static constexpr auto value = ""; };
64 struct InputSkipMode { static constexpr auto value = "100"; };
65 struct MetisParams { static constexpr auto value = "default"; };
66 
67 #if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
68 struct NumJacobiBlocks { static constexpr int value = 0; };
69 #endif // HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
70 
71 struct OwnerCellsFirst { static constexpr bool value = true; };
72 struct ParsingStrictness { static constexpr auto value = "normal"; };
73 struct ActionParsingStrictness { static constexpr auto value = "normal"; };
74 
77 struct PartitionMethod { static constexpr auto value = "zoltanwell"; };
78 struct AddCorners { static constexpr bool value = false; };
79 struct NumOverlap { static constexpr int value = 1; };
80 struct EdgeConformal { static constexpr bool value = false; };
81 
82 struct SchedRestart{ static constexpr bool value = false; };
83 struct SerialPartitioning{ static constexpr bool value = false; };
84 
85 template<class Scalar>
86 struct ZoltanImbalanceTol { static constexpr Scalar value = 1.1; };
87 
88 struct ZoltanPhgEdgeSizeThreshold { static constexpr auto value = 0.35; };
89 
90 struct ZoltanParams { static constexpr auto value = "graph"; };
91 
92 } // namespace Opm::Parameters
93 
94 namespace Opm {
95 
96 namespace Action { class State; }
97 class Deck;
98 class EclipseState;
99 struct NumericalAquiferCell;
100 class ParseContext;
101 class Schedule;
102 class Python;
103 class SummaryConfig;
104 class SummaryState;
105 class UDQState;
106 class WellTestState;
107 
109 public:
110  using ParallelWellStruct = std::vector<std::pair<std::string,bool>>;
111 
113  double setupTime_;
114  std::unique_ptr<UDQState> udqState_;
115  std::unique_ptr<Action::State> actionState_;
116  std::unique_ptr<SummaryState> summaryState_;
117  std::unique_ptr<WellTestState> wtestState_;
118  std::shared_ptr<EclipseState> eclState_;
119  std::shared_ptr<Schedule> eclSchedule_;
120  std::shared_ptr<SummaryConfig> eclSummaryConfig_;
121  };
122 
123  static SimulationModelParams modelParams_;
124 
130  explicit FlowGenericVanguard(SimulationModelParams&& params);
131 
137 
138  static SimulationModelParams serializationTestParams();
139 
146  static std::string canonicalDeckPath(const std::string& caseName);
147 
151  double setupTime()
152  { return setupTime_; }
153 
158  static void readDeck(const std::string& filename);
159 
163  void defineSimulationModel(SimulationModelParams&& params);
164 
168  const EclipseState& eclState() const
169  { return *eclState_; }
170 
171  EclipseState& eclState()
172  { return *eclState_; }
173 
177  const Schedule& schedule() const
178  { return *eclSchedule_; }
179 
180  Schedule& schedule()
181  { return *eclSchedule_; }
182 
187  const SummaryConfig& summaryConfig() const
188  { return *eclSummaryConfig_; }
189 
197  SummaryState& summaryState()
198  { return *summaryState_; }
199 
200  const SummaryState& summaryState() const
201  { return *summaryState_; }
202 
208  Action::State& actionState()
209  { return *actionState_; }
210 
211  const Action::State& actionState() const
212  { return *actionState_; }
213 
219  UDQState& udqState()
220  { return *udqState_; }
221 
222  const UDQState& udqState() const
223  { return *udqState_; }
224 
225  std::unique_ptr<WellTestState> transferWTestState() {
226  return std::move(this->wtestState_);
227  }
228 
229 
236  const std::string& caseName() const
237  { return caseName_; }
238 
242  Dune::EdgeWeightMethod edgeWeightsMethod() const
243  { return edgeWeightsMethod_; }
244 
248  int numJacobiBlocks() const
249  {
250 #if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
251  return numJacobiBlocks_;
252 #else
253  return 0;
254 #endif // HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
255  }
256 
260  bool ownersFirst() const
261  { return ownersFirst_; }
262 
263  bool edgeConformal() const
264  { return edgeConformal_; }
265 
266 #if HAVE_MPI
267  bool addCorners() const
268  { return addCorners_; }
269 
270  int numOverlap() const
271  { return numOverlap_; }
272 
276  Dune::PartitionMethod partitionMethod() const
277  { return partitionMethod_; }
278 
283  bool serialPartitioning() const
284  { return serialPartitioning_; }
285 
290  double imbalanceTol() const
291  {
292  if (zoltanImbalanceTolSet_) {
293  OpmLog::info("The parameter --zoltan-imbalance-tol is deprecated "
294  "and has been renamed to --imbalance-tol, please "
295  "adjust your calls and scripts!");
296  return zoltanImbalanceTol_;
297  } else {
298  return imbalanceTol_;
299  }
300  }
301 
302  const std::string& externalPartitionFile() const
303  {
304  return this->externalPartitionFile_;
305  }
306 #endif // HAVE_MPI
307 
312  { return enableDistributedWells_; }
313 
318  bool enableEclOutput() const
319  { return enableEclOutput_; }
320 
328  const ParallelWellStruct& parallelWells() const
329  { return parallelWells_; }
330 
332  static void setCommunication(std::unique_ptr<Opm::Parallel::Communication> comm)
333  { comm_ = std::move(comm); }
334 
336  static Parallel::Communication& comm()
337  {
338  assert(comm_ != nullptr);
339  return *comm_;
340  }
341 
342  // Private to avoid pulling schedule in header.
343  // Static state is not serialized, only use for restart.
344  template<class Serializer>
345  void serializeOp(Serializer& serializer);
346 
347  // Only compares dynamic state.
348  bool operator==(const FlowGenericVanguard& rhs) const;
349 
350 protected:
351  void updateOutputDir_(std::string outputDir,
352  bool enableEclCompatFile);
353 
354  void updateNOSIM_(std::string_view enableDryRun);
355 
356  bool drsdtconEnabled() const;
357 
358  std::unordered_map<std::size_t, const NumericalAquiferCell*> allAquiferCells() const;
359 
360  void init();
361 
362  template<class Scalar>
363  static void registerParameters_();
364 
365  double setupTime_;
366 
367  // These variables may be owned by both Python and the simulator
368  static std::unique_ptr<Parallel::Communication> comm_;
369 
370  std::string caseName_;
371  std::string fileName_;
372  Dune::EdgeWeightMethod edgeWeightsMethod_;
373 
374 #if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
375  int numJacobiBlocks_{0};
376 #endif // HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
377 
378  bool ownersFirst_;
379  bool edgeConformal_;
380 
381 #if HAVE_MPI
382  bool addCorners_;
383  int numOverlap_;
384 
385  Dune::PartitionMethod partitionMethod_;
386  bool serialPartitioning_;
387  double imbalanceTol_;
388 
389  bool zoltanImbalanceTolSet_;
390  double zoltanImbalanceTol_;
391  double zoltanPhgEdgeSizeThreshold_;
392  std::string zoltanParams_;
393 
394  std::string metisParams_;
395 
396  std::string externalPartitionFile_{};
397 #endif // HAVE_MPI
398 
399  bool enableDistributedWells_;
400  bool enableEclOutput_;
401  bool allow_splitting_inactive_wells_;
402 
403  std::string ignoredKeywords_;
404  std::optional<int> outputInterval_;
405  bool useMultisegmentWell_;
406  bool enableExperiments_;
407 
408  std::unique_ptr<SummaryState> summaryState_;
409  std::unique_ptr<UDQState> udqState_;
410  std::unique_ptr<Action::State> actionState_;
411 
412  // Observe that this instance is handled differently from the other state
413  // variables, it will only be initialized for a restart run. While
414  // initializing a restarted run this instance is transferred to the WGState
415  // member in the well model.
416  std::unique_ptr<WellTestState> wtestState_;
417 
418  // these attributes point either to the internal or to the external version of the
419  // parser objects.
420  std::shared_ptr<Python> python;
421  // These variables may be owned by both Python and the simulator
422  std::shared_ptr<EclipseState> eclState_;
423  std::shared_ptr<Schedule> eclSchedule_;
424  std::shared_ptr<SummaryConfig> eclSummaryConfig_;
425 
431  ParallelWellStruct parallelWells_;
432 };
433 
434 } // namespace Opm
435 
436 #endif // OPM_FLOW_GENERIC_VANGUARD_HPP
const Schedule & schedule() const
Return a reference to the object that managages the ECL schedule.
Definition: FlowGenericVanguard.hpp:177
UDQState & udqState()
Returns the udq state.
Definition: FlowGenericVanguard.hpp:219
const std::string & caseName() const
Returns the name of the case.
Definition: FlowGenericVanguard.hpp:236
Definition: FlowGenericVanguard.hpp:78
Dune::EdgeWeightMethod edgeWeightsMethod() const
Parameter deciding the edge-weight strategy of the load balancer.
Definition: FlowGenericVanguard.hpp:242
int numJacobiBlocks() const
Number of blocks in the Block-Jacobi preconditioner.
Definition: FlowGenericVanguard.hpp:248
Definition: FlowGenericVanguard.hpp:90
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition: FlowGenericVanguard.hpp:168
Definition: FlowGenericVanguard.hpp:58
double setupTime()
Returns the wall time required to set up the simulator before it was born.
Definition: FlowGenericVanguard.hpp:151
0: simple, 1: Zoltan, 2: METIS, 3: Zoltan with a all cells of a well represented by one vertex in the...
Definition: FlowGenericVanguard.hpp:77
Definition: FlowGenericVanguard.hpp:57
static void readDeck(const std::string &filename)
Read a deck.
Definition: FlowGenericVanguard.cpp:210
bool ownersFirst() const
Parameter that decide if cells owned by rank are ordered before ghost cells.
Definition: FlowGenericVanguard.hpp:260
Definition: FlowGenericVanguard.hpp:53
static void setCommunication(std::unique_ptr< Opm::Parallel::Communication > comm)
Set global communication.
Definition: FlowGenericVanguard.hpp:332
Definition: FlowGenericVanguard.hpp:63
Definition: FlowGenericVanguard.hpp:83
bool enableDistributedWells() const
Whether perforations of a well might be distributed.
Definition: FlowGenericVanguard.hpp:311
bool enableEclOutput() const
Whether or not to emit result files that are compatible with a commercial reservoir simulator...
Definition: FlowGenericVanguard.hpp:318
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: FlowGenericVanguard.hpp:56
static std::string canonicalDeckPath(const std::string &caseName)
Returns the canonical path to a deck file.
Definition: FlowGenericVanguard.cpp:227
Definition: FlowGenericVanguard.hpp:50
~FlowGenericVanguard()
Destructor.
Definition: blackoilnewtonmethodparams.hpp:31
Definition: FlowGenericVanguard.hpp:54
static Parallel::Communication & comm()
Obtain global communicator.
Definition: FlowGenericVanguard.hpp:336
Definition: FlowGenericVanguard.hpp:71
Definition: FlowGenericVanguard.hpp:82
Action::State & actionState()
Returns the action state.
Definition: FlowGenericVanguard.hpp:208
SummaryState & summaryState()
Returns the summary state.
Definition: FlowGenericVanguard.hpp:197
Definition: FlowGenericVanguard.hpp:80
Definition: FlowGenericVanguard.hpp:64
void defineSimulationModel(SimulationModelParams &&params)
Set the simulation configuration objects.
Definition: FlowGenericVanguard.cpp:198
Definition: FlowGenericVanguard.hpp:108
Definition: FlowGenericVanguard.hpp:73
Definition: FlowGenericVanguard.hpp:55
Definition: FlowGenericVanguard.hpp:61
FlowGenericVanguard()
Constructor.
Definition: FlowGenericVanguard.cpp:108
Definition: FlowGenericVanguard.hpp:88
Definition: FlowGenericVanguard.hpp:51
ParallelWellStruct parallelWells_
Information about wells in parallel.
Definition: FlowGenericVanguard.hpp:431
Definition: FlowGenericVanguard.hpp:112
const SummaryConfig & summaryConfig() const
Return a reference to the object that determines which quantities ought to be put into the ECL summar...
Definition: FlowGenericVanguard.hpp:187
Definition: FlowGenericVanguard.hpp:72
const ParallelWellStruct & parallelWells() const
Retrieve collection (a vector of pairs) of well names and whether or not the corresponding well objec...
Definition: FlowGenericVanguard.hpp:328
Definition: FlowGenericVanguard.hpp:65
Definition: FlowGenericVanguard.hpp:86
Definition: FlowGenericVanguard.hpp:79