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 Schedule;
55class SummaryConfig;
56class SummaryState;
57class UDQState;
58
59} // namespace Opm
60
61namespace Opm { namespace Action {
62class State;
63}} // namespace Opm::Action
64
65namespace Opm {
66
67template <class Grid, class EquilGrid, class GridView, class ElementMapper, class Scalar>
69{
74
75public:
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
92 {
94 }
95
97 {
98 sub_step_report_ = report;
99 }
101 {
102 simulation_report_ = report;
103 }
104
105 const std::vector<std::vector<NNCdata>>& getOutputNnc() const
106 {
107 return outputNnc_;
108 }
109
111 {
112 return collectOnIORank_;
113 }
114
115 void extractOutputTransAndNNC(const std::function<unsigned int(unsigned int)>& map);
116
117protected:
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 data::Solution&& localCellData,
125 data::Wells&& localWellData,
126 data::GroupAndNetworkValues&& localGroupAndNetworkData,
127 data::Aquifers&& localAquiferData,
128 WellTestState&& localWTestState,
129 const Action::State& actionState,
130 const UDQState& udqState,
131 const SummaryState& summaryState,
132 const std::vector<Scalar>& thresholdPressure,
133 Scalar curTime,
134 Scalar nextStepSize,
135 bool doublePrecision,
136 bool isFlowsn,
137 std::array<FlowsData<double>,3>&& flowsn,
138 bool isFloresn,
139 std::array<FlowsData<double>, 3>&& floresn);
140
141 void evalSummary(int reportStepNum,
142 Scalar curTime,
143 const data::Wells& localWellData,
144 const data::WellBlockAveragePressures& localWBPData,
145 const data::GroupAndNetworkValues& localGroupAndNetworkData,
146 const std::map<int,data::AquiferData>& localAquiferData,
147 const std::map<std::pair<std::string, int>, double>& blockData,
148 const std::map<std::string, double>& miscSummaryData,
149 const std::map<std::string, std::vector<double>>& regionData,
150 const Inplace& inplace,
151 const Inplace* initialInPlace,
152 const InterRegFlowMap& interRegFlows,
153 SummaryState& summaryState,
154 UDQState& udqState,
155 const data::ReservoirCouplingGroupRates* rcGroupRates = nullptr);
156
158 const Grid& grid_;
159 const GridView& gridView_;
160 const Schedule& schedule_;
161 const EclipseState& eclState_;
162 std::unique_ptr<EclipseIO> eclIO_;
163 std::unique_ptr<TaskletRunner> taskletRunner_;
168 const EquilGrid* equilGrid_;
171
172 // Regular NNCs per grid: internal to a grid.
173 // Both cells belong to the same level grid, either the main grid or a level/local grid.
174 // nnc.cell1 (NNC1 in *.EGRID) Level/Local Cartesian index of cell1
175 // nnc.cell2 (NNC2 in *.EGRID) Level/Local Cartesian index of cell2
176 // Equivalent to TRANNNC in *.INIT
177 mutable std::vector<std::vector<NNCdata>> outputNnc_;
178
179 // NNCs between main (level zero) grid and local grids:
180 // nnc.cell1 (NNCG in *.EGRID) Cartesian index of cell1 in the main grid where the cell belongs to.
181 // nnc.cell2 (NNCL in *.EGRID) Level/Local Cartesian index of cell2 in the refined level grid where the cell belongs to.
182 // Equivalent to TRANGL in *.INIT
183 mutable std::vector<std::vector<NNCdata>> outputNncGlobalLocal_; // here GLOBAL refers to level 0 grid, local to any LGR (refined grid)
184
185 // Amalgamated NNCs: nncs between different LGRs. For example, nested refinement or neighboring LGRs.
186 // The cells belong to different refined level grids.
187 // nnc.cell1 (NNA1 in *.EGRID) Level/Local Cartesian index of cell1 (in its level grid: level1)
188 // nnc.cell2 (NNA2 in *.EGRID) Level/Local Cartesian index of cell2 (in its level grid: level2, with level2 > level1).
189 // Equivalent to TRANLL in *.INIT
190 mutable std::vector<std::vector<std::vector<NNCdata>>> outputAmalgamatedNnc_;
191
192 mutable std::unique_ptr<std::vector<data::Solution>> outputTrans_;
193
194private:
195 template<typename LevelIndicesFunction, typename OriginIndicesFunction>
196 void computeTrans_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
197 const std::function<unsigned int(unsigned int)>& map,
198 const LevelIndicesFunction& computeLevelIndices,
199 const std::function<int(int, int)>& computeLevelCartIdx,
200 const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
201 const OriginIndicesFunction& computeOriginIndices) const;
202
203 template<typename LevelIndicesFunction, typename OriginIndicesFunction>
204 std::vector<std::vector<NNCdata>> exportNncStructure_(const std::vector<std::unordered_map<int,int>>& levelCartToLevelCompressed,
205 const std::function<unsigned int(unsigned int)>& map,
206 const LevelIndicesFunction& computeLevelIndices,
207 const std::function<int(int, int)>& computeLevelCartIdx,
208 const std::function<std::array<int,3>(int)>& computeLevelCartDimensions,
209 const OriginIndicesFunction& computeOriginIndices) const;
210
212 bool isCartesianNeighbour_(const std::array<int,3>& levelCartDims,
213 const std::size_t levelCartIdx1,
214 const std::size_t levelCartIdx2) const;
215
216 bool isDirectNeighbours_(const std::unordered_map<int,int>& levelCartesianToActive,
217 const std::array<int,3>& levelCartDims,
218 const std::size_t levelCartIdx1,
219 const std::size_t levelCartIdx2) const;
220
221 auto activeCell_(const std::unordered_map<int,int>& levelCartToLevelCompressed,
222 const std::size_t levelCartIdx) const;
223
224
225
228 bool isNumAquCell_(const std::size_t cartIdx) const;
230 bool isNumAquConn_(const std::size_t cartIdx1, const std::size_t cartIdx2) const;
231
240 template<bool equilGridIsCpGrid>
241 Opm::LevelCartesianIndexMapper<EquilGrid> createLevelCartMapp_() const;
242
250 template<bool equilGridIsCpGrid>
251 std::vector<std::unordered_map<int,int>> createCartesianToActiveMaps_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp) const;
252
258 template<bool equilGridIsCpGrid>
259 std::function<std::array<int,3>(int)> computeLevelCartDimensions_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
260 const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
261
266 template<bool equilGridIsCpGrid>
267 std::function<int(int, int)> computeLevelCartIdx_(const Opm::LevelCartesianIndexMapper<EquilGrid>& levelCartMapp,
268 const Dune::CartesianIndexMapper<EquilGrid>& equilCartMapp) const;
269
274 template <bool equilGridIsCpGrid>
275 auto computeLevelIndices_() const;
276
281 template <bool equilGridIsCpGrid>
282 auto computeOriginIndices_() const;
283
286 void allocateLevelTrans_(const std::array<int,3>& levelCartDims,
287 data::Solution& levelTrans) const;
293 void allocateAllNncs_(int maxLevel) const;
294};
295
296} // namespace Opm
297
298#endif // OPM_ECL_GENERIC_WRITER_HPP
Definition: CollectDataOnIORank.hpp:49
Definition: CollectDataOnIORank.hpp:56
Definition: EclGenericWriter.hpp:69
std::vector< std::vector< NNCdata > > outputNnc_
Definition: EclGenericWriter.hpp:177
const Grid & grid_
Definition: EclGenericWriter.hpp:158
const EclipseState & eclState_
Definition: EclGenericWriter.hpp:161
void setSubStepReport(const SimulatorReportSingle &report)
Definition: EclGenericWriter.hpp:96
void setSimulationReport(const SimulatorReport &report)
Definition: EclGenericWriter.hpp:100
std::vector< std::vector< NNCdata > > outputNncGlobalLocal_
Definition: EclGenericWriter.hpp:183
void doWriteOutput(const int reportStepNum, const std::optional< int > timeStepNum, const bool isSubStep, 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:894
std::unique_ptr< std::vector< data::Solution > > outputTrans_
Definition: EclGenericWriter.hpp:192
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const
CollectDataOnIORankType collectOnIORank_
Definition: EclGenericWriter.hpp:157
const Schedule & schedule_
Definition: EclGenericWriter.hpp:160
SimulatorReport simulation_report_
Definition: EclGenericWriter.hpp:170
void setTransmissibilities(const TransmissibilityType *globalTrans)
Definition: EclGenericWriter.hpp:91
SimulatorReportSingle sub_step_report_
Definition: EclGenericWriter.hpp:169
const EquilGrid * equilGrid_
Definition: EclGenericWriter.hpp:168
void extractOutputTransAndNNC(const std::function< unsigned int(unsigned int)> &map)
Definition: EclGenericWriter_impl.hpp:286
Scalar restartTimeStepSize_
Definition: EclGenericWriter.hpp:164
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::string, double > &miscSummaryData, const std::map< std::string, std::vector< double > > &regionData, const Inplace &inplace, const Inplace *initialInPlace, const InterRegFlowMap &interRegFlows, SummaryState &summaryState, UDQState &udqState, const data::ReservoirCouplingGroupRates *rcGroupRates=nullptr)
Definition: EclGenericWriter_impl.hpp:1002
std::vector< std::vector< std::vector< NNCdata > > > outputAmalgamatedNnc_
Definition: EclGenericWriter.hpp:190
std::unique_ptr< TaskletRunner > taskletRunner_
Definition: EclGenericWriter.hpp:163
void writeInit()
Definition: EclGenericWriter_impl.hpp:268
const Dune::CartesianIndexMapper< Grid > & cartMapper_
Definition: EclGenericWriter.hpp:166
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:214
const EclipseIO & eclIO() const
Definition: EclGenericWriter_impl.hpp:260
const GridView & gridView_
Definition: EclGenericWriter.hpp:159
const std::vector< std::vector< NNCdata > > & getOutputNnc() const
Definition: EclGenericWriter.hpp:105
const CollectDataOnIORankType & collectOnIORank() const
Definition: EclGenericWriter.hpp:110
const TransmissibilityType * globalTrans_
Definition: EclGenericWriter.hpp:165
const TransmissibilityType & globalTrans() const
Definition: EclGenericWriter_impl.hpp:1086
std::unique_ptr< EclipseIO > eclIO_
Definition: EclGenericWriter.hpp:162
const Dune::CartesianIndexMapper< EquilGrid > * equilCartMapper_
Definition: EclGenericWriter.hpp:167
Inter-region flow accumulation maps for all region definition arrays.
Definition: InterRegFlows.hpp:179
Definition: EclGenericWriter.hpp:52
Definition: Transmissibility.hpp:54
Definition: blackoilbioeffectsmodules.hh:45
Definition: SimulatorReport.hpp:122
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.