opm-simulators
GenericOutputBlackoilModule.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  Consult the COPYING file in the top-level source directory of this
19  module for the precise wording of the license and the list of
20  copyright holders.
21 */
26 #ifndef OPM_GENERIC_OUTPUT_BLACK_OIL_MODULE_HPP
27 #define OPM_GENERIC_OUTPUT_BLACK_OIL_MODULE_HPP
28 
29 #include <opm/input/eclipse/EclipseState/Grid/FaceDir.hpp>
30 #include <opm/input/eclipse/EclipseState/SummaryConfig/SummaryConfig.hpp>
31 
32 #include <opm/output/data/Wells.hpp>
33 #include <opm/output/eclipse/Inplace.hpp>
34 
39 #include <opm/simulators/flow/FlowsContainer.hpp>
43 #include <opm/simulators/flow/RegionPhasePVAverage.hpp>
45 #include <opm/simulators/flow/RSTConv.hpp>
46 #include <opm/simulators/flow/GeochemistryContainer.hpp>
48 
49 #include <opm/simulators/utils/ParallelCommunication.hpp>
50 
51 #include <array>
52 #include <cstddef>
53 #include <functional>
54 #include <map>
55 #include <optional>
56 #include <unordered_map>
57 #include <utility>
58 #include <vector>
59 
60 namespace Opm::Parameters {
61 
62 struct ForceDisableFluidInPlaceOutput { static constexpr bool value = false; };
63 struct ForceDisableResvFluidInPlaceOutput { static constexpr bool value = false; };
64 
65 } // namespace Opm::Parameters
66 
67 namespace Opm {
68 
69 namespace data { class Solution; }
70 class EclHysteresisConfig;
71 class EclipseState;
72 class Schedule;
73 class SummaryConfig;
74 class SummaryConfigNode;
75 class SummaryState;
76 
77 template<class FluidSystem>
79 public:
80  using Scalar = typename FluidSystem::Scalar;
81 
82  // Virtual destructor for safer inheritance.
83  virtual ~GenericOutputBlackoilModule();
84 
88  static void registerParameters();
89 
90  void outputTimeStamp(const std::string& lbl,
91  double elapsed,
92  int rstep,
93  boost::posix_time::ptime currentDate);
94 
98 
102 
103  // write cumulative production and injection reports to output
104  void outputCumLog(std::size_t reportStepNum,
105  const bool connData);
106 
107  // write production report to output
108  void outputProdLog(std::size_t reportStepNum,
109  const bool connData);
110 
111  // write injection report to output
112  void outputInjLog(std::size_t reportStepNum,
113  const bool connData);
114 
115  // write msw report to output
116  void outputMSWLog(std::size_t reportStepNum);
117 
118  // calculate Initial Fluid In Place
119  void calc_initial_inplace(const Parallel::Communication& comm);
120 
121  // calculate Fluid In Place
122  Inplace calc_inplace(std::map<std::string, double>& miscSummaryData,
123  std::map<std::string, std::vector<double>>& regionData,
124  const Parallel::Communication& comm);
125 
146  void outputWellspecReport(const std::vector<std::string>& changedWells,
147  const bool changedWellLists,
148  const std::size_t reportStepNum,
149  const double elapsed,
150  boost::posix_time::ptime currentDate) const;
151 
152  void outputErrorLog(const Parallel::Communication& comm) const;
153 
154  void addRftDataToWells(data::Wells& wellDatas,
155  std::size_t reportStepNum,
156  const Parallel::Communication& comm)
157  { this->rftC_.addToWells(wellDatas, reportStepNum, comm); }
158 
162  void assignToSolution(data::Solution& sol);
163 
164  void setRestart(const data::Solution& sol,
165  unsigned elemIdx,
166  unsigned globalDofIndex);
167 
168  Scalar getSolventSaturation(unsigned elemIdx) const
169  {
170  if (sSol_.size() > elemIdx)
171  return sSol_[elemIdx];
172 
173  return 0;
174  }
175 
176  Scalar getSolventRsw(unsigned elemIdx) const
177  {
178  if (rswSol_.size() > elemIdx)
179  return rswSol_[elemIdx];
180 
181  return 0;
182  }
183 
184  Scalar getPolymerConcentration(unsigned elemIdx) const
185  {
186  if (cPolymer_.size() > elemIdx)
187  return cPolymer_[elemIdx];
188 
189  return 0;
190  }
191 
192  Scalar getFoamConcentration(unsigned elemIdx) const
193  {
194  if (cFoam_.size() > elemIdx)
195  return cFoam_[elemIdx];
196 
197  return 0;
198  }
199 
200  Scalar getSaltConcentration(unsigned elemIdx) const
201  {
202  if (cSalt_.size() > elemIdx)
203  return cSalt_[elemIdx];
204 
205  return 0;
206  }
207 
208  Scalar getSaltSaturation(unsigned elemIdx) const
209  {
210  if (pSalt_.size() > elemIdx)
211  return pSalt_[elemIdx];
212 
213  return 0;
214  }
215 
216  Scalar getPermFactor(unsigned elemIdx) const
217  {
218  if (permFact_.size() > elemIdx)
219  return permFact_[elemIdx];
220 
221  return 0;
222  }
223 
224  const std::vector<Scalar>& getFluidPressure() const
225  { return fluidPressure_; }
226 
227  const BioeffectsContainer<Scalar>& getBioeffects() const
228  { return this->bioeffectsC_; }
229 
230  const CO2H2Container<Scalar>& getCO2H2() const
231  { return this->CO2H2C_; }
232 
233  const FlowsContainer<FluidSystem>& getFlows() const
234  { return this->flowsC_; }
235 
236  bool needInterfaceFluxes([[maybe_unused]] const bool isSubStep) const
237  {
238  return this->interRegionFlows_.wantInterRegflowSummary();
239  }
240 
241  const std::map<std::pair<std::string, int>, double>& getBlockData()
242  {
243  return blockData_;
244  }
245 
246  std::map<std::pair<std::string, int>, double>& getExtraBlockData()
247  {
248  return extraBlockData_;
249  }
250 
251  const Inplace* initialInplace() const
252  {
253  return this->initialInplace_.has_value()
254  ? &*this->initialInplace_
255  : nullptr;
256  }
257 
258  bool localDataValid() const{
259  return local_data_valid_;
260  }
261 
262  void invalidateLocalData(){
263  local_data_valid_ = false;
264  }
265 
266  void validateLocalData(){
267  local_data_valid_ = true;
268  }
269 
270  template<class Serializer>
271  void serializeOp(Serializer& serializer)
272  {
273  serializer(initialInplace_);
274  }
275 
276  RSTConv& getConv()
277  { return this->rst_conv_; }
278 
279  const RSTConv& getConv() const
280  { return this->rst_conv_; }
281 
286  void assignGlobalFieldsToSolution(data::Solution& sol);
287 
288 protected:
289  using ScalarBuffer = std::vector<Scalar>;
290  using StringBuffer = std::vector<std::string>;
291  enum { numPhases = FluidSystem::numPhases };
292  enum { numComponents = FluidSystem::numComponents };
293  static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
294  static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
295  static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
296  enum { gasCompIdx = FluidSystem::gasCompIdx };
297  enum { oilCompIdx = FluidSystem::oilCompIdx };
298  enum { waterCompIdx = FluidSystem::waterCompIdx };
299  using Dir = FaceDir::DirEnum;
300 
301  GenericOutputBlackoilModule(const EclipseState& eclState,
302  const Schedule& schedule,
303  const SummaryConfig& summaryConfig,
304  const SummaryState& summaryState,
305  const std::string& moduleVersionName,
306  RSTConv::LocalToGlobalCellFunc globalCell,
307  std::function<bool(const unsigned)> isInterior,
308  const Parallel::Communication& comm,
309  bool enableEnergy,
310  bool constantTemperature,
311  bool enableMech,
312  bool enableSolvent,
313  bool enablePolymer,
314  bool enableFoam,
315  bool enableBrine,
316  bool enableSaltPrecipitation,
317  bool enableExtbo,
318  bool enableBioeffects,
319  bool enableGeochemistry);
320 
321  void doAllocBuffers(unsigned bufferSize,
322  unsigned reportStepNum,
323  const bool substep,
324  const bool log,
325  const bool isRestart,
326  const EclHysteresisConfig* hysteresisConfig,
327  unsigned numOutputNnc = 0,
328  std::map<std::string, int> rstKeywords = {});
329 
330  void makeRegionSum(Inplace& inplace,
331  const std::string& region_name,
332  const Parallel::Communication& comm) const;
333 
334  Inplace accumulateRegionSums(const Parallel::Communication& comm);
335 
336  void updateSummaryRegionValues(const Inplace& inplace,
337  std::map<std::string, double>& miscSummaryData,
338  std::map<std::string, std::vector<double>>& regionData) const;
339 
340  static bool isOutputCreationDirective_(const std::string& keyword);
341 
342  // Sum Fip values over regions.
343  static ScalarBuffer regionSum(const ScalarBuffer& property,
344  const std::vector<int>& regionId,
345  const std::size_t maxNumberOfRegions,
346  const Parallel::Communication& comm);
347 
348  static int regionMax(const std::vector<int>& region,
349  const Parallel::Communication& comm);
350 
351  static void update(Inplace& inplace,
352  const std::string& region_name,
353  const Inplace::Phase phase,
354  const std::size_t ntFip,
355  const ScalarBuffer& values);
356 
357  static Scalar sum(const ScalarBuffer& v);
358 
359  void setupBlockData(std::function<bool(int)> isCartIdxOnThisRank);
360  void setupExtraBlockData(const std::size_t reportStepNum,
361  std::function<bool(int)> isCartIdxOnThisRank);
362 
363  virtual bool isDefunctParallelWell(const std::string& wname) const = 0;
364  virtual bool isOwnedByCurrentRank(const std::string& wname) const = 0;
365  virtual bool isOnCurrentRank(const std::string& wname) const = 0;
366 
367  const EclipseState& eclState_;
368  const Schedule& schedule_;
369  const SummaryState& summaryState_;
370 
371  SummaryConfig summaryConfig_;
372 
373  InterRegFlowMap interRegionFlows_;
374  LogOutputHelper<Scalar> logOutput_;
375 
376  bool enableEnergy_{false};
377  bool constantTemperature_{false};
378  bool enableMech_{false};
379 
380  bool enableSolvent_{false};
381  bool enablePolymer_{false};
382  bool enableFoam_{false};
383  bool enableBrine_{false};
384  bool enableSaltPrecipitation_{false};
385  bool enableExtbo_{false};
386  bool enableBioeffects_{false};
387  bool enableGeochemistry_{false};
388 
389  bool forceDisableFipOutput_{false};
390  bool forceDisableFipresvOutput_{false};
391  bool computeFip_{false};
392 
394  std::unordered_map<std::string, std::vector<int>> regions_;
395  std::unordered_map<Inplace::Phase, std::vector<SummaryConfigNode>> regionNodes_;
396 
397  std::vector<SummaryConfigNode> RPRNodes_;
398  std::vector<SummaryConfigNode> RPRPNodes_;
399 
400  std::vector<int> failedCellsPb_;
401  std::vector<int> failedCellsPd_;
402 
403  ScalarBuffer gasFormationVolumeFactor_;
404  ScalarBuffer hydrocarbonPoreVolume_;
405  ScalarBuffer pressureTimesPoreVolume_;
406  ScalarBuffer pressureTimesHydrocarbonVolume_;
407  ScalarBuffer dynamicPoreVolume_;
408  ScalarBuffer rPorV_;
409  ScalarBuffer fluidPressure_;
410  ScalarBuffer temperature_;
411  ScalarBuffer rs_;
412  ScalarBuffer rsw_;
413  ScalarBuffer rv_;
414  ScalarBuffer rvw_;
415  ScalarBuffer overburdenPressure_;
416  ScalarBuffer oilSaturationPressure_;
417  ScalarBuffer drsdtcon_;
418  ScalarBuffer sSol_;
419  ScalarBuffer rswSol_;
420  ScalarBuffer cPolymer_;
421  ScalarBuffer cFoam_;
422  ScalarBuffer cSalt_;
423  ScalarBuffer pSalt_;
424  ScalarBuffer permFact_;
425  ExtboContainer<Scalar> extboC_;
426  ScalarBuffer soMax_;
427  ScalarBuffer swMax_;
428  ScalarBuffer sgmax_;
429  ScalarBuffer shmax_;
430  ScalarBuffer somin_;
431  ScalarBuffer swmin_;
432  ScalarBuffer ppcw_;
433  ScalarBuffer gasDissolutionFactor_;
434  ScalarBuffer oilVaporizationFactor_;
435  ScalarBuffer gasDissolutionFactorInWater_;
436  ScalarBuffer waterVaporizationFactor_;
437  ScalarBuffer bubblePointPressure_;
438  ScalarBuffer dewPointPressure_;
439  ScalarBuffer rockCompPorvMultiplier_;
440  ScalarBuffer minimumOilPressure_;
441  ScalarBuffer saturatedOilFormationVolumeFactor_;
442  ScalarBuffer rockCompTransMultiplier_;
443  BioeffectsContainer<Scalar> bioeffectsC_;
444  CO2H2Container<Scalar> CO2H2C_;
445  ScalarBuffer pcgw_;
446  ScalarBuffer pcow_;
447  ScalarBuffer pcog_;
448 
449  // buffers for mechanical output
450  MechContainer<Scalar> mech_;
451 
452  std::array<ScalarBuffer, numPhases> saturation_;
453  std::array<ScalarBuffer, numPhases> invB_;
454  std::array<ScalarBuffer, numPhases> density_;
455  std::array<ScalarBuffer, numPhases> viscosity_;
456  std::array<ScalarBuffer, numPhases> relativePermeability_;
457 
459 
461 
462  std::array<ScalarBuffer, numPhases> residual_;
463 
465 
468 
469  std::map<std::pair<std::string, int>, double> blockData_;
470  // Extra block data required for non-summary output reasons
471  // Example is the block pressures for RPTSCHED WELLS=2
472  std::map<std::pair<std::string, int>, double> extraBlockData_;
473 
474  std::optional<Inplace> initialInplace_;
475  bool local_data_valid_{false};
476 
477  std::optional<RegionPhasePoreVolAverage> regionAvgDensity_;
478 };
479 
480 } // namespace Opm
481 
482 #endif // OPM_GENERIC_OUTPUT_BLACK_OIL_MODULE_HPP
Definition: GenericOutputBlackoilModule.hpp:63
Definition: TracerContainer.hpp:38
Output module for the results black oil model writing in ECL binary format.
Output module for the results black oil model writing in ECL binary format.
Definition: FlowsContainer.hpp:43
Definition: GeochemistryContainer.hpp:35
static void registerParameters()
Register all run-time parameters for the Vtk output module.
Definition: GenericOutputBlackoilModule.cpp:194
void outputWellspecReport(const std::vector< std::string > &changedWells, const bool changedWellLists, const std::size_t reportStepNum, const double elapsed, boost::posix_time::ptime currentDate) const
Emit well specification report.
Definition: GenericOutputBlackoilModule.cpp:299
std::string moduleVersionName()
Return the version name of the module, for example "2015.10" (for a release branch) or "2016...
Definition: moduleVersion.cpp:34
Output module for the results black oil model writing in ECL binary format.
Output module for the results black oil model writing in ECL binary format.
Output module for the results black oil model writing in ECL binary format.
Definition: BioeffectsContainer.hpp:37
Definition: FIPContainer.hpp:47
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
Definition: GenericOutputBlackoilModule.hpp:62
Definition: blackoilnewtonmethodparams.hpp:31
Definition: GenericOutputBlackoilModule.hpp:78
Inter-region flow accumulation maps for all region definition arrays.
Definition: InterRegFlows.hpp:178
Class computing RPTRST CONV output.
Definition: RSTConv.hpp:35
Definition: ExtboContainer.hpp:36
void accumulateDensityParallel()
Run cross-rank parallel accumulation of per-region phase density running sums (average values)...
Definition: GenericOutputBlackoilModule.cpp:225
void assignGlobalFieldsToSolution(data::Solution &sol)
Assign fields that are in global numbering to the solution.
Definition: GenericOutputBlackoilModule.cpp:1191
Collection of cell-level RFT data–i.e., pressures and saturations–in cells intersected by wells...
Definition: RFTContainer.hpp:51
MPI-aware facility for converting collection of tuples of region ID pairs and associate flow rates in...
Definition: LogOutputHelper.hpp:45
void assignToSolution(data::Solution &sol)
Move all buffers to data::Solution.
Definition: GenericOutputBlackoilModule.cpp:316
Output module for the results black oil model writing in ECL binary format.
Output module for the results black oil model writing in ECL binary format.
RSTConv rst_conv_
Helper class for RPTRST CONV.
Definition: GenericOutputBlackoilModule.hpp:467
void prepareDensityAccumulation()
Clear internal arrays for parallel accumulation of per-region phase density averages.
Definition: GenericOutputBlackoilModule.cpp:216
Definition: MechContainer.hpp:44
Definition: CO2H2Container.hpp:37