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
39
40#include <array>
41#include <map>
42#include <memory>
43#include <optional>
44#include <string>
45#include <utility>
46#include <vector>
47
48namespace Opm {
49
50class EclipseIO;
51class EclipseState;
52class InterRegFlowMap;
53class Inplace;
54template <class Grid> class LevelCartesianIndexMapper;
55struct NNCdata;
56class RegionVariableCollection;
57class Schedule;
58class SummaryConfig;
59class SummaryState;
60class UDQState;
61
62} // namespace Opm
63
64namespace Opm::Action {
65class State;
66} // namespace Opm::Action
67
68namespace Opm::data {
69class RegionVariableMapping;
70} // namespace Opm::data
71
72namespace Opm {
73
74template <class Grid, class EquilGrid, class GridView, class ElementMapper, class Scalar>
76{
81
82public:
83 EclGenericWriter(const Schedule& schedule,
84 const EclipseState& eclState,
85 const SummaryConfig& summaryConfig,
86 const Grid& grid,
87 const EquilGrid* equilGrid,
88 const GridView& gridView,
89 const Dune::CartesianIndexMapper<Grid>& cartMapper,
90 const Dune::CartesianIndexMapper<EquilGrid>* equilCartMapper,
91 bool enableAsyncOutput,
92 bool enableEsmry);
93
94 const EclipseIO& eclIO() const;
95
96 void writeInit();
97
99 {
101 }
102
103 // Parallel LGR INIT output: connection transmissibilities gathered from the
104 // ranks' own (distributed) simulator transmissibilities. When set,
105 // computeTrans_ / exportNncStructure_ take values from these instead of
106 // querying a whole-grid transmissibility object. Complete on the I/O rank only.
107 void setGatheredLgrTrans(std::optional<GatheredLgrOutputTrans> gatheredTrans)
108 {
109 gatheredLgrTrans_ = std::move(gatheredTrans);
110 }
111
113 {
114 sub_step_report_ = report;
115 }
117 {
118 simulation_report_ = report;
119 }
120
121 const std::vector<std::vector<NNCdata>>& getOutputNnc() const
122 {
123 return outputNnc_;
124 }
125
127 {
128 return collectOnIORank_;
129 }
130
131 void extractOutputTransAndNNC(const std::function<unsigned int(unsigned int)>& map);
132
133protected:
134 const TransmissibilityType& globalTrans() const;
135 unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const;
136
137 // Value for `key` from the gathered records, or nullptr when the key is
138 // absent or no gathered records are set. N = 3 selects the same-level
139 // records, N = 4 the level-crossing (NNC) ones -- see GatheredLgrOutputTrans.
140 template <std::size_t N>
141 const double* findGatheredTrans_(const std::array<int,N>& key) const;
142
143 // Output transmissibility value for a connection: from the gathered per-rank
144 // simulator transmissibilities when set (parallel LGR runs; a missing key is
145 // a hard error), otherwise from the whole-grid transmissibility object
146 // (c1, c2). Key shape as in findGatheredTrans_.
147 template <std::size_t N>
148 double gatheredOrGlobalTrans_(const std::array<int,N>& key,
149 unsigned c1,
150 unsigned c2) const;
151
152 void doWriteOutput(const int reportStepNum,
153 const std::optional<int> timeStepNum,
154 const bool isSubStep,
155 const bool forcedSimulationFinished,
156 data::Solution&& localCellData,
157 data::Wells&& localWellData,
158 data::GroupAndNetworkValues&& localGroupAndNetworkData,
159 data::Aquifers&& localAquiferData,
160 WellTestState&& localWTestState,
161 const Action::State& actionState,
162 const UDQState& udqState,
163 const SummaryState& summaryState,
164 const std::vector<Scalar>& thresholdPressure,
165 Scalar curTime,
166 Scalar nextStepSize,
167 bool doublePrecision,
168 bool isFlowsn,
169 std::array<FlowsData<double>,3>&& flowsn,
170 bool isFloresn,
171 std::array<FlowsData<double>, 3>&& floresn);
172
173 void evalSummary(int reportStepNum,
174 Scalar curTime,
175 const data::Wells& localWellData,
176 const data::WellBlockAveragePressures& localWBPData,
177 const data::GroupAndNetworkValues& localGroupAndNetworkData,
178 const std::map<int,data::AquiferData>& localAquiferData,
179 const std::map<std::pair<std::string, int>, double>& blockData,
180 const std::map<std::tuple<std::string, int, int>, double>& lgrBlockData,
181 const std::map<std::string, double>& miscSummaryData,
182 const std::map<std::string, std::vector<double>>& regionData,
183 const data::RegionVariableMapping& regVarMap,
184 const RegionVariableCollection& regVars,
185 const Inplace& inplace,
186 const Inplace* initialInPlace,
187 const InterRegFlowMap& interRegFlows,
188 SummaryState& summaryState,
189 UDQState& udqState,
190 const data::ReservoirCouplingGroupRates* rcGroupRates = nullptr);
191
193 const Grid& grid_;
194 const GridView& gridView_;
195 const Schedule& schedule_;
196 const EclipseState& eclState_;
197 std::unique_ptr<EclipseIO> eclIO_;
198 std::unique_ptr<TaskletRunner> taskletRunner_;
201 std::optional<GatheredLgrOutputTrans> gatheredLgrTrans_;
204 const EquilGrid* equilGrid_;
207
208 // Regular NNCs per grid: internal to a grid.
209 // Both cells belong to the same level grid, either the main grid or a level/local grid.
210 // nnc.cell1 (NNC1 in *.EGRID) Level/Local Cartesian index of cell1
211 // nnc.cell2 (NNC2 in *.EGRID) Level/Local Cartesian index of cell2
212 // Equivalent to TRANNNC in *.INIT
213 mutable std::vector<std::vector<NNCdata>> outputNnc_;
214
215 // NNCs between main (level zero) grid and local grids:
216 // nnc.cell1 (NNCG in *.EGRID) Cartesian index of cell1 in the main grid where the cell belongs to.
217 // nnc.cell2 (NNCL in *.EGRID) Level/Local Cartesian index of cell2 in the refined level grid where the cell belongs to.
218 // Equivalent to TRANGL in *.INIT
219 mutable std::vector<std::vector<NNCdata>> outputNncGlobalLocal_; // here GLOBAL refers to level 0 grid, local to any LGR (refined grid)
220
221 // Amalgamated NNCs: nncs between different LGRs. For example, nested refinement or neighboring LGRs.
222 // The cells belong to different refined level grids.
223 // nnc.cell1 (NNA1 in *.EGRID) Level/Local Cartesian index of cell1 (in its level grid: level1)
224 // nnc.cell2 (NNA2 in *.EGRID) Level/Local Cartesian index of cell2 (in its level grid: level2, with level2 > level1).
225 // Equivalent to TRANLL in *.INIT
226 mutable std::vector<std::vector<std::vector<NNCdata>>> outputAmalgamatedNnc_;
227
228 mutable std::unique_ptr<std::vector<data::Solution>> outputTrans_;
229
230private:
231 template<typename LevelIndicesFunction, typename OriginIndicesFunction>
232 void computeTrans_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
233 const std::function<unsigned int(unsigned int)>& map,
234 const LevelIndicesFunction& computeLevelIndices,
235 const std::function<int(int, int)>& computeLevelCartIdx,
236 const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
237 const OriginIndicesFunction& computeOriginIndices) const;
238
239 template<typename LevelIndicesFunction, typename OriginIndicesFunction>
240 std::vector<std::vector<NNCdata>> exportNncStructure_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
241 const std::function<unsigned int(unsigned int)>& map,
242 const LevelIndicesFunction& computeLevelIndices,
243 const std::function<int(int, int)>& computeLevelCartIdx,
244 const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
245 const OriginIndicesFunction& computeOriginIndices) const;
246
248 bool isCartesianNeighbour_(const std::array<int,3>& levelCartDims,
249 const std::size_t levelCartIdx1,
250 const std::size_t levelCartIdx2) const;
251
252 bool isDirectNeighbours_(const std::unordered_map<int,int>& levelCartesianToActive,
253 const std::array<int,3>& levelCartDims,
254 const std::size_t levelCartIdx1,
255 const std::size_t levelCartIdx2) const;
256
257 auto activeCell_(const std::unordered_map<int,int>& levelCartToLevelCompressed,
258 const std::size_t levelCartIdx) const;
259
260
261
264 bool isNumAquCell_(const std::size_t cartIdx) const;
266 bool isNumAquConn_(const std::size_t cartIdx1, const std::size_t cartIdx2) const;
267
276 template<bool equilGridIsCpGrid>
277 Opm::LevelCartesianIndexMapper<EquilGrid> createLevelCartMapp_() const;
278
286 template<bool equilGridIsCpGrid>
287 std::vector<std::unordered_map<int,int>> createCartesianToActiveMaps_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp) const;
288
294 template<bool equilGridIsCpGrid>
295 std::function<std::array<int,3>(int)> computeLevelCartDimensions_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
296 const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
297
302 template<bool equilGridIsCpGrid>
303 std::function<int(int, int)> computeLevelCartIdx_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
304 const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
305
310 template <bool equilGridIsCpGrid>
311 auto computeLevelIndices_() const;
312
317 template <bool equilGridIsCpGrid>
318 auto computeOriginIndices_() const;
319
322 void allocateLevelTrans_(const std::array<int,3>& levelCartDims,
323 data::Solution& levelTrans) const;
329 void allocateAllNncs_(int maxLevel) const;
330};
331
332} // namespace Opm
333
334#endif // OPM_ECL_GENERIC_WRITER_HPP
Definition: CollectDataOnIORank.hpp:50
Definition: CollectDataOnIORank.hpp:57
Definition: EclGenericWriter.hpp:76
std::vector< std::vector< NNCdata > > outputNnc_
Definition: EclGenericWriter.hpp:213
const Grid & grid_
Definition: EclGenericWriter.hpp:193
const EclipseState & eclState_
Definition: EclGenericWriter.hpp:196
void setSubStepReport(const SimulatorReportSingle &report)
Definition: EclGenericWriter.hpp:112
void setSimulationReport(const SimulatorReport &report)
Definition: EclGenericWriter.hpp:116
double gatheredOrGlobalTrans_(const std::array< int, N > &key, unsigned c1, unsigned c2) const
Definition: EclGenericWriter_impl.hpp:1167
std::vector< std::vector< NNCdata > > outputNncGlobalLocal_
Definition: EclGenericWriter.hpp:219
std::unique_ptr< std::vector< data::Solution > > outputTrans_
Definition: EclGenericWriter.hpp:228
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const
void setGatheredLgrTrans(std::optional< GatheredLgrOutputTrans > gatheredTrans)
Definition: EclGenericWriter.hpp:107
void evalSummary(int reportStepNum, Scalar curTime, const data::Wells &localWellData, const data::WellBlockAveragePressures &localWBPData, const data::GroupAndNetworkValues &localGroupAndNetworkData, const std::map< int, data::AquiferData > &localAquiferData, const std::map< std::pair< std::string, int >, double > &blockData, const std::map< std::tuple< std::string, int, int >, double > &lgrBlockData, const std::map< std::string, double > &miscSummaryData, const std::map< std::string, std::vector< double > > &regionData, const data::RegionVariableMapping &regVarMap, const RegionVariableCollection &regVars, const Inplace &inplace, const Inplace *initialInPlace, const InterRegFlowMap &interRegFlows, SummaryState &summaryState, UDQState &udqState, const data::ReservoirCouplingGroupRates *rcGroupRates=nullptr)
Definition: EclGenericWriter_impl.hpp:1058
CollectDataOnIORankType collectOnIORank_
Definition: EclGenericWriter.hpp:192
const Schedule & schedule_
Definition: EclGenericWriter.hpp:195
SimulatorReport simulation_report_
Definition: EclGenericWriter.hpp:206
void setTransmissibilities(const TransmissibilityType *globalTrans)
Definition: EclGenericWriter.hpp:98
SimulatorReportSingle sub_step_report_
Definition: EclGenericWriter.hpp:205
const EquilGrid * equilGrid_
Definition: EclGenericWriter.hpp:204
void extractOutputTransAndNNC(const std::function< unsigned int(unsigned int)> &map)
Definition: EclGenericWriter_impl.hpp:313
Scalar restartTimeStepSize_
Definition: EclGenericWriter.hpp:199
std::vector< std::vector< std::vector< NNCdata > > > outputAmalgamatedNnc_
Definition: EclGenericWriter.hpp:226
std::unique_ptr< TaskletRunner > taskletRunner_
Definition: EclGenericWriter.hpp:198
void writeInit()
Definition: EclGenericWriter_impl.hpp:281
const double * findGatheredTrans_(const std::array< int, N > &key) const
Definition: EclGenericWriter_impl.hpp:1148
std::optional< GatheredLgrOutputTrans > gatheredLgrTrans_
Definition: EclGenericWriter.hpp:201
const Dune::CartesianIndexMapper< Grid > & cartMapper_
Definition: EclGenericWriter.hpp:202
EclGenericWriter(const Schedule &schedule, const EclipseState &eclState, const SummaryConfig &summaryConfig, const Grid &grid, const EquilGrid *equilGrid, const GridView &gridView, const Dune::CartesianIndexMapper< Grid > &cartMapper, const Dune::CartesianIndexMapper< EquilGrid > *equilCartMapper, bool enableAsyncOutput, bool enableEsmry)
Definition: EclGenericWriter_impl.hpp:227
const EclipseIO & eclIO() const
Definition: EclGenericWriter_impl.hpp:273
const GridView & gridView_
Definition: EclGenericWriter.hpp:194
const std::vector< std::vector< NNCdata > > & getOutputNnc() const
Definition: EclGenericWriter.hpp:121
const CollectDataOnIORankType & collectOnIORank() const
Definition: EclGenericWriter.hpp:126
const TransmissibilityType * globalTrans_
Definition: EclGenericWriter.hpp:200
const TransmissibilityType & globalTrans() const
Definition: EclGenericWriter_impl.hpp:1190
std::unique_ptr< EclipseIO > eclIO_
Definition: EclGenericWriter.hpp:197
const Dune::CartesianIndexMapper< EquilGrid > * equilCartMapper_
Definition: EclGenericWriter.hpp:203
void doWriteOutput(const int reportStepNum, const std::optional< int > timeStepNum, const bool isSubStep, const bool forcedSimulationFinished, data::Solution &&localCellData, data::Wells &&localWellData, data::GroupAndNetworkValues &&localGroupAndNetworkData, data::Aquifers &&localAquiferData, WellTestState &&localWTestState, const Action::State &actionState, const UDQState &udqState, const SummaryState &summaryState, const std::vector< Scalar > &thresholdPressure, Scalar curTime, Scalar nextStepSize, bool doublePrecision, bool isFlowsn, std::array< FlowsData< double >, 3 > &&flowsn, bool isFloresn, std::array< FlowsData< double >, 3 > &&floresn)
Definition: EclGenericWriter_impl.hpp:948
Inter-region flow accumulation maps for all region definition arrays.
Definition: InterRegFlows.hpp:179
Definition: EclGenericWriter.hpp:54
Definition: Transmissibility.hpp:55
Definition: ActionHandler.hpp:34
Definition: BioeffectsContainer.hpp:33
Definition: blackoilbioeffectsmodules.hh:45
Definition: SimulatorReport.hpp:202
A struct for returning timing data from a simulator to its caller.
Definition: SimulatorReport.hpp:34
Provides a mechanism to dispatch work to separate threads.