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 <tuple>
57 #include <unordered_map>
58 #include <utility>
59 #include <vector>
60 
61 namespace Opm::Parameters {
62 
63 struct ForceDisableFluidInPlaceOutput { static constexpr bool value = false; };
64 struct ForceDisableResvFluidInPlaceOutput { static constexpr bool value = false; };
65 
66 } // namespace Opm::Parameters
67 
68 namespace Opm {
69 
70 namespace data { class Solution; }
71 class EclHysteresisConfig;
72 class EclipseGrid;
73 class EclipseState;
74 class Schedule;
75 class SummaryConfig;
76 class SummaryConfigNode;
77 class SummaryState;
78 
79 template<class FluidSystem>
81 public:
82  using Scalar = typename FluidSystem::Scalar;
83 
84  // Virtual destructor for safer inheritance.
85  virtual ~GenericOutputBlackoilModule();
86 
90  static void registerParameters();
91 
92  void outputTimeStamp(const std::string& lbl,
93  double elapsed,
94  int rstep,
95  boost::posix_time::ptime currentDate);
96 
100 
104 
105  // write cumulative production and injection reports to output
106  void outputCumLog(std::size_t reportStepNum,
107  const bool connData);
108 
109  // write production report to output
110  void outputProdLog(std::size_t reportStepNum,
111  const bool connData);
112 
113  // write injection report to output
114  void outputInjLog(std::size_t reportStepNum,
115  const bool connData);
116 
117  // write msw report to output
118  void outputMSWLog(std::size_t reportStepNum);
119 
120  // calculate Initial Fluid In Place
121  void calc_initial_inplace(const Parallel::Communication& comm);
122 
123  // calculate Fluid In Place
124  Inplace calc_inplace(std::map<std::string, double>& miscSummaryData,
125  std::map<std::string, std::vector<double>>& regionData,
126  const Parallel::Communication& comm);
127 
148  void outputWellspecReport(const std::vector<std::string>& changedWells,
149  const bool changedWellLists,
150  const std::size_t reportStepNum,
151  const double elapsed,
152  boost::posix_time::ptime currentDate) const;
153 
154  void outputErrorLog(const Parallel::Communication& comm) const;
155 
156  void addRftDataToWells(data::Wells& wellDatas,
157  std::size_t reportStepNum,
158  const Parallel::Communication& comm)
159  { this->rftC_.addToWells(wellDatas, reportStepNum, comm); }
160 
164  void assignToSolution(data::Solution& sol);
165 
166  void setRestart(const data::Solution& sol,
167  unsigned elemIdx,
168  unsigned globalDofIndex);
169 
170  Scalar getSolventSaturation(unsigned elemIdx) const
171  {
172  if (sSol_.size() > elemIdx)
173  return sSol_[elemIdx];
174 
175  return 0;
176  }
177 
178  Scalar getSolventRsw(unsigned elemIdx) const
179  {
180  if (rswSol_.size() > elemIdx)
181  return rswSol_[elemIdx];
182 
183  return 0;
184  }
185 
186  Scalar getPolymerConcentration(unsigned elemIdx) const
187  {
188  if (cPolymer_.size() > elemIdx)
189  return cPolymer_[elemIdx];
190 
191  return 0;
192  }
193 
194  Scalar getFoamConcentration(unsigned elemIdx) const
195  {
196  if (cFoam_.size() > elemIdx)
197  return cFoam_[elemIdx];
198 
199  return 0;
200  }
201 
202  Scalar getSaltConcentration(unsigned elemIdx) const
203  {
204  if (cSalt_.size() > elemIdx)
205  return cSalt_[elemIdx];
206 
207  return 0;
208  }
209 
210  Scalar getSaltSaturation(unsigned elemIdx) const
211  {
212  if (pSalt_.size() > elemIdx)
213  return pSalt_[elemIdx];
214 
215  return 0;
216  }
217 
218  Scalar getPermFactor(unsigned elemIdx) const
219  {
220  if (permFact_.size() > elemIdx)
221  return permFact_[elemIdx];
222 
223  return 0;
224  }
225 
226  const std::vector<Scalar>& getFluidPressure() const
227  { return fluidPressure_; }
228 
229  const BioeffectsContainer<Scalar>& getBioeffects() const
230  { return this->bioeffectsC_; }
231 
232  const CO2H2Container<Scalar>& getCO2H2() const
233  { return this->CO2H2C_; }
234 
235  const FlowsContainer<FluidSystem>& getFlows() const
236  { return this->flowsC_; }
237 
238  bool needInterfaceFluxes([[maybe_unused]] const bool isSubStep) const
239  {
240  return this->interRegionFlows_.wantInterRegflowSummary();
241  }
242 
243  const std::map<std::pair<std::string, int>, double>& getBlockData()
244  {
245  return blockData_;
246  }
247 
248  std::map<std::pair<std::string, int>, double>& getExtraBlockData()
249  {
250  return extraBlockData_;
251  }
252 
253  // Per-LGR-cell block-summary results. Cell identity is the
254  // (keyword, grid level, level-local linearised Cartesian cell index)
255  // tuple — the same identity data::Connection carries as
256  // (lgr_grid, index) for LC* connection vectors. Empty for runs
257  // without LB* summary requests.
258  const std::map<std::tuple<std::string, int, int>, double>& getLgrBlockData() const
259  {
260  return lgrBlockData_;
261  }
262 
263  const Inplace* initialInplace() const
264  {
265  return this->initialInplace_.has_value()
266  ? &*this->initialInplace_
267  : nullptr;
268  }
269 
270  bool localDataValid() const{
271  return local_data_valid_;
272  }
273 
274  void invalidateLocalData(){
275  local_data_valid_ = false;
276  }
277 
278  void validateLocalData(){
279  local_data_valid_ = true;
280  }
281 
282  template<class Serializer>
283  void serializeOp(Serializer& serializer)
284  {
285  serializer(initialInplace_);
286  }
287 
288  RSTConv& getConv()
289  { return this->rst_conv_; }
290 
291  const RSTConv& getConv() const
292  { return this->rst_conv_; }
293 
298  void assignGlobalFieldsToSolution(data::Solution& sol);
299 
300 protected:
301  using ScalarBuffer = std::vector<Scalar>;
302  using StringBuffer = std::vector<std::string>;
303  enum { numPhases = FluidSystem::numPhases };
304  enum { numComponents = FluidSystem::numComponents };
305  static constexpr int gasPhaseIdx = FluidSystem::gasPhaseIdx;
306  static constexpr int oilPhaseIdx = FluidSystem::oilPhaseIdx;
307  static constexpr int waterPhaseIdx = FluidSystem::waterPhaseIdx;
308  enum { gasCompIdx = FluidSystem::gasCompIdx };
309  enum { oilCompIdx = FluidSystem::oilCompIdx };
310  enum { waterCompIdx = FluidSystem::waterCompIdx };
311  using Dir = FaceDir::DirEnum;
312 
313  GenericOutputBlackoilModule(const EclipseState& eclState,
314  const Schedule& schedule,
315  const SummaryConfig& summaryConfig,
316  const SummaryState& summaryState,
317  const std::string& moduleVersionName,
318  RSTConv::LocalToGlobalCellFunc globalCell,
319  std::function<bool(const unsigned)> isInterior,
320  const Parallel::Communication& comm,
321  bool enableEnergy,
322  bool constantTemperature,
323  bool enableMech,
324  bool enableSolvent,
325  bool enablePolymer,
326  bool enableFoam,
327  bool enableBrine,
328  bool enableSaltPrecipitation,
329  bool enableExtbo,
330  bool enableBioeffects,
331  bool enableGeochemistry);
332 
333  void doAllocBuffers(unsigned bufferSize,
334  unsigned reportStepNum,
335  const bool substep,
336  const bool log,
337  const bool isRestart,
338  const EclHysteresisConfig* hysteresisConfig,
339  unsigned numOutputNnc = 0,
340  std::map<std::string, int> rstKeywords = {});
341 
342  void makeRegionSum(Inplace& inplace,
343  const std::string& region_name,
344  const Parallel::Communication& comm) const;
345 
346  Inplace accumulateRegionSums(const Parallel::Communication& comm);
347 
348  void updateSummaryRegionValues(const Inplace& inplace,
349  std::map<std::string, double>& miscSummaryData,
350  std::map<std::string, std::vector<double>>& regionData) const;
351 
352  static bool isOutputCreationDirective_(const std::string& keyword);
353 
354  // Sum Fip values over regions.
355  static ScalarBuffer regionSum(const ScalarBuffer& property,
356  const std::vector<int>& regionId,
357  const std::size_t maxNumberOfRegions,
358  const Parallel::Communication& comm);
359 
360  static int regionMax(const std::vector<int>& region,
361  const Parallel::Communication& comm);
362 
363  static void update(Inplace& inplace,
364  const std::string& region_name,
365  const Inplace::Phase phase,
366  const std::size_t ntFip,
367  const ScalarBuffer& values);
368 
369  static Scalar sum(const ScalarBuffer& v);
370 
371  void setupBlockData(std::function<bool(int)> isCartIdxOnThisRank);
372  void setupExtraBlockData(const std::size_t reportStepNum,
373  std::function<bool(int)> isCartIdxOnThisRank);
374 
375  // Allocate lgrBlockData_ slots for every Block-category summary node
376  // that names an LGR cell. The level component of the key is resolved
377  // through EclipseGrid::get_lgr_cell_index (the same call data::Connection
378  // uses for lgr_grid on LC* connection vectors); the level-local
379  // linearised Cartesian index is recovered from node.number - 1.
380  //
381  // No rank check here — ownership for LGR leaf cells is decided in the
382  // walk via Dune::InteriorEntity on the leaf entity; the existing
383  // isCartIdxOnThisRank predicate operates in the global Cartesian space,
384  // which LGR cells do not inhabit.
385  //
386  // Caller-supplied via parameter rather than read from a member to keep
387  // this module decoupled from EclipseState ownership (matching how the
388  // existing block path receives its rank predicate as an argument).
389  void setupLgrBlockData(const std::map<std::string, int>& lgrNameToLevel,
390  const std::function<bool(int, int)>& isLgrCellOnThisRank);
391 
392  virtual bool isDefunctParallelWell(const std::string& wname) const = 0;
393  virtual bool isOwnedByCurrentRank(const std::string& wname) const = 0;
394  virtual bool isOnCurrentRank(const std::string& wname) const = 0;
395 
396  const EclipseState& eclState_;
397  const Schedule& schedule_;
398  const SummaryState& summaryState_;
399 
400  SummaryConfig summaryConfig_;
401 
402  InterRegFlowMap interRegionFlows_;
403  LogOutputHelper<Scalar> logOutput_;
404 
405  bool enableEnergy_{false};
406  bool constantTemperature_{false};
407  bool enableMech_{false};
408 
409  bool enableSolvent_{false};
410  bool enablePolymer_{false};
411  bool enableFoam_{false};
412  bool enableBrine_{false};
413  bool enableSaltPrecipitation_{false};
414  bool enableExtbo_{false};
415  bool enableBioeffects_{false};
416  bool enableGeochemistry_{false};
417 
418  bool forceDisableFipOutput_{false};
419  bool forceDisableFipresvOutput_{false};
420  bool computeFip_{false};
421 
423  std::unordered_map<std::string, std::vector<int>> regions_;
424  std::unordered_map<Inplace::Phase, std::vector<SummaryConfigNode>> regionNodes_;
425 
426  std::vector<SummaryConfigNode> RPRNodes_;
427  std::vector<SummaryConfigNode> RPRPNodes_;
428 
429  std::vector<int> failedCellsPb_;
430  std::vector<int> failedCellsPd_;
431 
432  ScalarBuffer gasFormationVolumeFactor_;
433  ScalarBuffer hydrocarbonPoreVolume_;
434  ScalarBuffer pressureTimesPoreVolume_;
435  ScalarBuffer pressureTimesHydrocarbonVolume_;
436  ScalarBuffer rPorV_;
437  ScalarBuffer fluidPressure_;
438  ScalarBuffer temperature_;
439  ScalarBuffer rs_;
440  ScalarBuffer rsw_;
441  ScalarBuffer rv_;
442  ScalarBuffer rvw_;
443  ScalarBuffer overburdenPressure_;
444  ScalarBuffer oilSaturationPressure_;
445  ScalarBuffer drsdtcon_;
446  ScalarBuffer sSol_;
447  ScalarBuffer rswSol_;
448  ScalarBuffer cPolymer_;
449  ScalarBuffer cFoam_;
450  ScalarBuffer cSalt_;
451  ScalarBuffer pSalt_;
452  ScalarBuffer permFact_;
453  ExtboContainer<Scalar> extboC_;
454  ScalarBuffer soMax_;
455  ScalarBuffer swMax_;
456  ScalarBuffer sgmax_;
457  ScalarBuffer shmax_;
458  ScalarBuffer somin_;
459  ScalarBuffer swmin_;
460  ScalarBuffer ppcw_;
461  ScalarBuffer gasDissolutionFactor_;
462  ScalarBuffer oilVaporizationFactor_;
463  ScalarBuffer gasDissolutionFactorInWater_;
464  ScalarBuffer waterVaporizationFactor_;
465  ScalarBuffer bubblePointPressure_;
466  ScalarBuffer dewPointPressure_;
467  ScalarBuffer rockCompPorvMultiplier_;
468  ScalarBuffer minimumOilPressure_;
469  ScalarBuffer saturatedOilFormationVolumeFactor_;
470  ScalarBuffer rockCompTransMultiplier_;
471  BioeffectsContainer<Scalar> bioeffectsC_;
472  CO2H2Container<Scalar> CO2H2C_;
473  ScalarBuffer pcgw_;
474  ScalarBuffer pcow_;
475  ScalarBuffer pcog_;
476 
477  // buffers for mechanical output
478  MechContainer<Scalar> mech_;
479 
480  std::array<ScalarBuffer, numPhases> saturation_;
481  std::array<ScalarBuffer, numPhases> invB_;
482  std::array<ScalarBuffer, numPhases> density_;
483  std::array<ScalarBuffer, numPhases> viscosity_;
484  std::array<ScalarBuffer, numPhases> relativePermeability_;
485 
487 
489 
490  std::array<ScalarBuffer, numPhases> residual_;
491 
493 
496 
497  std::map<std::pair<std::string, int>, double> blockData_;
498  // Extra block data required for non-summary output reasons
499  // Example is the block pressures for RPTSCHED WELLS=2
500  std::map<std::pair<std::string, int>, double> extraBlockData_;
501 
502  // Per-LGR-cell block-summary results. Keyed by (keyword, grid level,
503  // level-local linearised Cartesian cell index). The map type matches
504  // Summary::DynamicSimulatorState::LgrBlockValues so the writer can hand
505  // a pointer to this member directly to the summary engine. Empty for
506  // runs that request no LB* summary vectors (zero non-LGR cost).
507  std::map<std::tuple<std::string, int, int>, double> lgrBlockData_;
508 
509  std::optional<Inplace> initialInplace_;
510  bool local_data_valid_{false};
511 
512  std::optional<RegionPhasePoreVolAverage> regionAvgDensity_;
513 };
514 
515 } // namespace Opm
516 
517 #endif // OPM_GENERIC_OUTPUT_BLACK_OIL_MODULE_HPP
Definition: GenericOutputBlackoilModule.hpp:64
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
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Definition: GenericOutputBlackoilModule.hpp:63
Definition: blackoilnewtonmethodparams.hpp:31
Definition: GenericOutputBlackoilModule.hpp:80
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:1236
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:495
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