20#ifndef OPM_GRID_CPGRID_LGROUTPUTHELPERS_HEADER_INCLUDED
21#define OPM_GRID_CPGRID_LGROUTPUTHELPERS_HEADER_INCLUDED
26#include <opm/input/eclipse/Units/UnitSystem.hpp>
27#include <opm/output/data/Cells.hpp>
28#include <opm/output/data/Solution.hpp>
29#include <opm/output/eclipse/RestartValue.hpp>
37template<
class ScalarType>
41 const std::vector<std::vector<ScalarType>>& levelVectors)
43 min = std::min(
min, levelVectors[ level ][ levelIdx ]);
54template<
class ScalarType>
58 const std::vector<std::vector<ScalarType>>& levelVectors)
60 max = std::max(
max, levelVectors[ level ][ levelIdx ]);
71template<
class ScalarType>
75 const std::vector<std::vector<ScalarType>>& levelVectors)
77 partialSum+= levelVectors[ level ][ levelIdx ];
116template <
typename Container>
118 const std::vector<int>& toOutput);
129template <
typename ScalarType>
145template <
typename ScalarType>
148 const std::vector<ScalarType>& leafVector,
149 const std::vector<std::vector<int>>& toOutput_refinedLevels,
150 std::vector<std::vector<ScalarType>>& levelVectors);
173 const std::vector<std::vector<int>>& toOutput_refinedLevels,
174 const Opm::data::Solution& leafSolution,
175 std::vector<Opm::data::Solution>&);
188template <
typename Gr
id>
190 const Opm::RestartValue& leafRestartValue,
191 std::vector<Opm::RestartValue>& restartValue_levels);
196template <
typename Container>
198 const std::vector<int>& toOutput)
201 Container outputContainer;
202 outputContainer.resize(toOutput.size());
203 for (std::size_t i = 0; i < toOutput.size(); ++i) {
204 outputContainer[i] = simulatorContainer[toOutput[i]];
206 return outputContainer;
209template <
typename ScalarType>
214 const auto& [level, level_indices] = grid.
currentData()[element.
level()]->getChildrenLevelAndIndexList(element.
index());
222 auto childrenDataFunc = [](){
223 if constexpr (std::is_same_v<ScalarType, double>)
229 for (
const auto& levelIdx : level_indices) {
230 childrenDataFunc(level, levelIdx, levelVectors);
232 return childrenDataFunc.getValue();
235template <
typename ScalarType>
238 const std::vector<ScalarType>& leafVector,
239 const std::vector<std::vector<int>>& toOutput_refinedLevels,
240 std::vector<std::vector<ScalarType>>& levelVectors)
242 for (
int level = 0; level <= maxLevel; ++level) {
243 levelVectors[level].resize(grid.levelGridView(level).
size(0));
247 for (
const auto& element : Dune::elements(grid.leafGridView())) {
248 levelVectors[element.level()][element.getLevelElem().index()] = leafVector[element.index()];
253 for (
int level = maxLevel-1; level >= 0; --level) {
254 for (
const auto& element : Dune::elements(grid.levelGridView(level))) {
255 if (!element.isLeaf()) {
264 for (
int level = 1; level<=maxLevel; ++level) {
269template <
typename Gr
id>
271 const Opm::RestartValue& leafRestartValue,
272 std::vector<Opm::RestartValue>& restartValue_levels)
274 if constexpr (std::is_same_v<Grid, Dune::CpGrid>) {
276 int maxLevel = grid.maxLevel();
277 restartValue_levels.resize(maxLevel+1);
281 std::vector<std::vector<int>> toOutput_refinedLevels{};
282 toOutput_refinedLevels.resize(maxLevel);
285 for (
int level = 1; level <= maxLevel; ++level) {
289 std::vector<Opm::data::Solution> dataSolutionLevels{};
291 toOutput_refinedLevels,
292 leafRestartValue.solution,
297 for (
int level = 0; level <= maxLevel; ++level) {
298 restartValue_levels[level] = Opm::RestartValue(std::move(dataSolutionLevels[level]),
299 leafRestartValue.wells,
300 leafRestartValue.grp_nwrk,
301 leafRestartValue.aquifer,
305 for (
const auto& [rst_key, leafVector] : leafRestartValue.extra) {
307 std::vector<std::vector<double>> levelVectors{};
308 levelVectors.resize(maxLevel+1);
310 Opm::Lgr::populateDataVectorLevelGrids<double>(grid,
313 toOutput_refinedLevels,
316 for (
int level = 0; level <= maxLevel; ++level) {
317 restartValue_levels[level].addExtra(rst_key.key, rst_key.dim, std::move(levelVectors[level]));
[ provides Dune::Grid ]
Definition: CpGrid.hpp:203
const std::vector< std::shared_ptr< Dune::cpgrid::CpGridData > > & currentData() const
Returns either data_ or distributed_data_(if non empty).
int size(int level, int codim) const
Number of grid entities per level and codim.
int level() const
Return the level of the entity in the grid hierarchy. Level = 0 represents the coarsest grid.
Definition: Entity.hpp:442
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:126
Definition: cpgrid/LevelCartesianIndexMapper.hpp:53
void extractSolutionLevelGrids(const Dune::CpGrid &grid, const std::vector< std::vector< int > > &toOutput_refinedLevels, const Opm::data::Solution &leafSolution, std::vector< Opm::data::Solution > &)
Extracts and organizes solution data for all grid refinement levels.
void populateDataVectorLevelGrids(const Dune::CpGrid &grid, int maxLevel, const std::vector< ScalarType > &leafVector, const std::vector< std::vector< int > > &toOutput_refinedLevels, std::vector< std::vector< ScalarType > > &levelVectors)
Populate level data vectors based on leaf vector, for a specific named data field.
Definition: LgrOutputHelpers.hpp:236
void extractRestartValueLevelGrids(const Grid &grid, const Opm::RestartValue &leafRestartValue, std::vector< Opm::RestartValue > &restartValue_levels)
Constructs restart-value containers for all grid refinement levels.
Definition: LgrOutputHelpers.hpp:270
ScalarType processChildrenData(const std::vector< std::vector< ScalarType > > &levelVectors, const Dune::cpgrid::Entity< 0 > &element, const Dune::CpGrid &grid)
Definition: LgrOutputHelpers.hpp:210
Container reorderForOutput(const Container &simulatorContainer, const std::vector< int > &toOutput)
Reorder data from a simulation container into the order assumed by output for refined level grids.
Definition: LgrOutputHelpers.hpp:197
std::vector< int > mapLevelIndicesToCartesianOutputOrder(const Dune::CpGrid &grid, const Opm::LevelCartesianIndexMapper< Dune::CpGrid > &levelCartMapp, int level)
Builds a mapping from level element indices to the Cartesian ordering required by output files.
Holds the implementation of the CpGrid as a pimple.
Definition: CellQuadrature.hpp:26
Definition: LgrOutputHelpers.hpp:72
ScalarType partialSum
Definition: LgrOutputHelpers.hpp:87
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:81
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:73
std::size_t count
Definition: LgrOutputHelpers.hpp:86
Definition: LgrOutputHelpers.hpp:55
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:63
ScalarType max
Definition: LgrOutputHelpers.hpp:68
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:56
Definition: LgrOutputHelpers.hpp:38
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:39
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:46
ScalarType min
Definition: LgrOutputHelpers.hpp:51