opm-simulators
EclGenericWriter.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 */
28 #ifndef OPM_ECL_GENERIC_WRITER_HPP
29 #define OPM_ECL_GENERIC_WRITER_HPP
30 
32 
33 #include <opm/output/data/Groups.hpp>
34 
35 #include <opm/simulators/flow/CollectDataOnIORank.hpp>
37 #include <opm/simulators/timestepping/SimulatorReport.hpp>
38 
39 #include <map>
40 #include <memory>
41 #include <optional>
42 #include <string>
43 #include <utility>
44 #include <vector>
45 
46 namespace Opm {
47 
48 class EclipseIO;
49 class EclipseState;
50 class InterRegFlowMap;
51 class Inplace;
52 template <class Grid> class LevelCartesianIndexMapper;
53 struct NNCdata;
54 class Schedule;
55 class SummaryConfig;
56 class SummaryState;
57 class UDQState;
58 
59 } // namespace Opm
60 
61 namespace Opm { namespace Action {
62 class State;
63 }} // namespace Opm::Action
64 
65 namespace Opm {
66 
67 template <class Grid, class EquilGrid, class GridView, class ElementMapper, class Scalar>
69 {
74 
75 public:
76  EclGenericWriter(const Schedule& schedule,
77  const EclipseState& eclState,
78  const SummaryConfig& summaryConfig,
79  const Grid& grid,
80  const EquilGrid* equilGrid,
81  const GridView& gridView,
82  const Dune::CartesianIndexMapper<Grid>& cartMapper,
83  const Dune::CartesianIndexMapper<EquilGrid>* equilCartMapper,
84  bool enableAsyncOutput,
85  bool enableEsmry);
86 
87  const EclipseIO& eclIO() const;
88 
89  void writeInit();
90 
91  void setTransmissibilities(const TransmissibilityType* globalTrans)
92  {
93  globalTrans_ = globalTrans;
94  }
95 
96  void setSubStepReport(const SimulatorReportSingle& report)
97  {
98  sub_step_report_ = report;
99  }
100  void setSimulationReport(const SimulatorReport& report)
101  {
102  simulation_report_ = report;
103  }
104 
105  const std::vector<std::vector<NNCdata>>& getOutputNnc() const
106  {
107  return outputNnc_;
108  }
109 
110  const CollectDataOnIORankType& collectOnIORank() const
111  {
112  return collectOnIORank_;
113  }
114 
115  void extractOutputTransAndNNC(const std::function<unsigned int(unsigned int)>& map);
116 
117 protected:
118  const TransmissibilityType& globalTrans() const;
119  unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const;
120 
121  void doWriteOutput(const int reportStepNum,
122  const std::optional<int> timeStepNum,
123  const bool isSubStep,
124  const bool forcedSimulationFinished,
125  data::Solution&& localCellData,
126  data::Wells&& localWellData,
127  data::GroupAndNetworkValues&& localGroupAndNetworkData,
128  data::Aquifers&& localAquiferData,
129  WellTestState&& localWTestState,
130  const Action::State& actionState,
131  const UDQState& udqState,
132  const SummaryState& summaryState,
133  const std::vector<Scalar>& thresholdPressure,
134  Scalar curTime,
135  Scalar nextStepSize,
136  bool doublePrecision,
137  bool isFlowsn,
138  std::array<FlowsData<double>,3>&& flowsn,
139  bool isFloresn,
140  std::array<FlowsData<double>, 3>&& floresn);
141 
142  void evalSummary(int reportStepNum,
143  Scalar curTime,
144  const data::Wells& localWellData,
145  const data::WellBlockAveragePressures& localWBPData,
146  const data::GroupAndNetworkValues& localGroupAndNetworkData,
147  const std::map<int,data::AquiferData>& localAquiferData,
148  const std::map<std::pair<std::string, int>, double>& blockData,
149  const std::map<std::tuple<std::string, int, int>, double>& lgrBlockData,
150  const std::map<std::string, double>& miscSummaryData,
151  const std::map<std::string, std::vector<double>>& regionData,
152  const Inplace& inplace,
153  const Inplace* initialInPlace,
154  const InterRegFlowMap& interRegFlows,
155  SummaryState& summaryState,
156  UDQState& udqState,
157  const data::ReservoirCouplingGroupRates* rcGroupRates = nullptr);
158 
159  CollectDataOnIORankType collectOnIORank_;
160  const Grid& grid_;
161  const GridView& gridView_;
162  const Schedule& schedule_;
163  const EclipseState& eclState_;
164  std::unique_ptr<EclipseIO> eclIO_;
165  std::unique_ptr<TaskletRunner> taskletRunner_;
166  Scalar restartTimeStepSize_;
167  const TransmissibilityType* globalTrans_ = nullptr;
168  const Dune::CartesianIndexMapper<Grid>& cartMapper_;
169  const Dune::CartesianIndexMapper<EquilGrid>* equilCartMapper_;
170  const EquilGrid* equilGrid_;
171  SimulatorReportSingle sub_step_report_;
172  SimulatorReport simulation_report_;
173 
174  // Regular NNCs per grid: internal to a grid.
175  // Both cells belong to the same level grid, either the main grid or a level/local grid.
176  // nnc.cell1 (NNC1 in *.EGRID) Level/Local Cartesian index of cell1
177  // nnc.cell2 (NNC2 in *.EGRID) Level/Local Cartesian index of cell2
178  // Equivalent to TRANNNC in *.INIT
179  mutable std::vector<std::vector<NNCdata>> outputNnc_;
180 
181  // NNCs between main (level zero) grid and local grids:
182  // nnc.cell1 (NNCG in *.EGRID) Cartesian index of cell1 in the main grid where the cell belongs to.
183  // nnc.cell2 (NNCL in *.EGRID) Level/Local Cartesian index of cell2 in the refined level grid where the cell belongs to.
184  // Equivalent to TRANGL in *.INIT
185  mutable std::vector<std::vector<NNCdata>> outputNncGlobalLocal_; // here GLOBAL refers to level 0 grid, local to any LGR (refined grid)
186 
187  // Amalgamated NNCs: nncs between different LGRs. For example, nested refinement or neighboring LGRs.
188  // The cells belong to different refined level grids.
189  // nnc.cell1 (NNA1 in *.EGRID) Level/Local Cartesian index of cell1 (in its level grid: level1)
190  // nnc.cell2 (NNA2 in *.EGRID) Level/Local Cartesian index of cell2 (in its level grid: level2, with level2 > level1).
191  // Equivalent to TRANLL in *.INIT
192  mutable std::vector<std::vector<std::vector<NNCdata>>> outputAmalgamatedNnc_;
193 
194  mutable std::unique_ptr<std::vector<data::Solution>> outputTrans_;
195 
196 private:
197  template<typename LevelIndicesFunction, typename OriginIndicesFunction>
198  void computeTrans_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
199  const std::function<unsigned int(unsigned int)>& map,
200  const LevelIndicesFunction& computeLevelIndices,
201  const std::function<int(int, int)>& computeLevelCartIdx,
202  const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
203  const OriginIndicesFunction& computeOriginIndices) const;
204 
205  template<typename LevelIndicesFunction, typename OriginIndicesFunction>
206  std::vector<std::vector<NNCdata>> exportNncStructure_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
207  const std::function<unsigned int(unsigned int)>& map,
208  const LevelIndicesFunction& computeLevelIndices,
209  const std::function<int(int, int)>& computeLevelCartIdx,
210  const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
211  const OriginIndicesFunction& computeOriginIndices) const;
212 
214  bool isCartesianNeighbour_(const std::array<int,3>& levelCartDims,
215  const std::size_t levelCartIdx1,
216  const std::size_t levelCartIdx2) const;
217 
218  bool isDirectNeighbours_(const std::unordered_map<int,int>& levelCartesianToActive,
219  const std::array<int,3>& levelCartDims,
220  const std::size_t levelCartIdx1,
221  const std::size_t levelCartIdx2) const;
222 
223  auto activeCell_(const std::unordered_map<int,int>& levelCartToLevelCompressed,
224  const std::size_t levelCartIdx) const;
225 
226 
227 
230  bool isNumAquCell_(const std::size_t cartIdx) const;
232  bool isNumAquConn_(const std::size_t cartIdx1, const std::size_t cartIdx2) const;
233 
242  template<bool equilGridIsCpGrid>
243  Opm::LevelCartesianIndexMapper<EquilGrid> createLevelCartMapp_() const;
244 
252  template<bool equilGridIsCpGrid>
253  std::vector<std::unordered_map<int,int>> createCartesianToActiveMaps_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp) const;
254 
260  template<bool equilGridIsCpGrid>
261  std::function<std::array<int,3>(int)> computeLevelCartDimensions_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
262  const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
263 
268  template<bool equilGridIsCpGrid>
269  std::function<int(int, int)> computeLevelCartIdx_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
270  const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
271 
276  template <bool equilGridIsCpGrid>
277  auto computeLevelIndices_() const;
278 
283  template <bool equilGridIsCpGrid>
284  auto computeOriginIndices_() const;
285 
288  void allocateLevelTrans_(const std::array<int,3>& levelCartDims,
289  data::Solution& levelTrans) const;
295  void allocateAllNncs_(int maxLevel) const;
296 };
297 
298 } // namespace Opm
299 
300 #endif // OPM_ECL_GENERIC_WRITER_HPP
Definition: CollectDataOnIORank.hpp:56
Definition: EclGenericWriter.hpp:52
Structs needed for tpfalinearizer and its gpuparams struct extracted to be defined in one place that ...
Definition: blackoilbioeffectsmodules.hh:45
Inter-region flow accumulation maps for all region definition arrays.
Definition: InterRegFlows.hpp:178
Definition: EclGenericWriter.hpp:68
Simple container for FLOWS data.
Definition: FlowsData.hpp:31
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:33
Provides a mechanism to dispatch work to separate threads.
Definition: Transmissibility.hpp:54
Definition: SimulatorReport.hpp:121
Definition: CollectDataOnIORank.hpp:50