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