20#ifndef OPM_GRID_CPGRID_LGROUTPUTHELPERS_HEADER_INCLUDED
21#define OPM_GRID_CPGRID_LGROUTPUTHELPERS_HEADER_INCLUDED
27#include <opm/input/eclipse/Units/UnitSystem.hpp>
28#include <opm/output/data/Cells.hpp>
29#include <opm/output/data/Solution.hpp>
30#include <opm/output/eclipse/RestartValue.hpp>
39template<
class ScalarType>
43 const std::vector<std::vector<ScalarType>>& levelVectors)
45 min = std::min(
min, levelVectors[ level ][ levelIdx ]);
56template<
class ScalarType>
60 const std::vector<std::vector<ScalarType>>& levelVectors)
62 max = std::max(
max, levelVectors[ level ][ levelIdx ]);
73template<
class ScalarType>
77 const std::vector<std::vector<ScalarType>>& levelVectors)
79 partialSum+= levelVectors[ level ][ levelIdx ];
118template <
typename Container>
120 const std::vector<int>& toOutput);
128std::vector<std::unordered_map<int,int>>
141template <
typename ScalarType>
157template <
typename ScalarType>
160 const std::vector<ScalarType>& leafVector,
161 const std::vector<std::vector<int>>& toOutput_refinedLevels,
162 std::vector<std::vector<ScalarType>>& levelVectors);
186 const std::vector<std::vector<int>>& toOutput_refinedLevels,
187 const Opm::data::Solution& leafSolution,
188 std::vector<Opm::data::Solution>&);
201template <
typename Gr
id>
202void extractRestartValueLevelGrids(
const Grid& grid,
203 const Opm::RestartValue& leafRestartValue,
204 std::vector<Opm::RestartValue>& restartValue_levels);
210template <
typename Container>
212 const std::vector<int>& toOutput)
215 Container outputContainer;
216 outputContainer.resize(toOutput.size());
217 for (std::size_t i = 0; i < toOutput.size(); ++i) {
218 outputContainer[i] = simulatorContainer[toOutput[i]];
220 return outputContainer;
223template <
typename ScalarType>
228 const auto& [level, level_indices] = grid.
currentData()[element.
level()]->getChildrenLevelAndIndexList(element.
index());
236 auto childrenDataFunc = [](){
237 if constexpr (std::is_same_v<ScalarType, double>)
243 for (
const auto& levelIdx : level_indices) {
244 childrenDataFunc(level, levelIdx, levelVectors);
246 return childrenDataFunc.getValue();
249template <
typename ScalarType>
252 const std::vector<ScalarType>& leafVector,
253 const std::vector<std::vector<int>>& toOutput_refinedLevels,
254 std::vector<std::vector<ScalarType>>& levelVectors)
256 for (
int level = 0; level <= maxLevel; ++level) {
257 levelVectors[level].resize(grid.levelGridView(level).
size(0));
261 for (
const auto& element : Dune::elements(grid.leafGridView())) {
262 levelVectors[element.level()][element.getLevelElem().index()] = leafVector[element.index()];
267 for (
int level = maxLevel-1; level >= 0; --level) {
268 for (
const auto& element : Dune::elements(grid.levelGridView(level))) {
269 if (!element.isLeaf()) {
278 for (
int level = 1; level<=maxLevel; ++level) {
284template <
typename Gr
id>
285void Opm::Lgr::extractRestartValueLevelGrids(
const Grid& grid,
286 const Opm::RestartValue& leafRestartValue,
287 std::vector<Opm::RestartValue>& restartValue_levels)
289 if constexpr (std::is_same_v<Grid, Dune::CpGrid>) {
291 int maxLevel = grid.maxLevel();
292 restartValue_levels.resize(maxLevel+1);
296 std::vector<std::vector<int>> toOutput_refinedLevels{};
297 toOutput_refinedLevels.resize(maxLevel);
300 for (
int level = 1; level <= maxLevel; ++level) {
304 std::vector<Opm::data::Solution> dataSolutionLevels{};
305 extractSolutionLevelGrids(grid,
306 toOutput_refinedLevels,
307 leafRestartValue.solution,
312 for (
int level = 0; level <= maxLevel; ++level) {
313 restartValue_levels[level] = Opm::RestartValue(std::move(dataSolutionLevels[level]),
314 leafRestartValue.wells,
315 leafRestartValue.grp_nwrk,
316 leafRestartValue.aquifer,
320 for (
const auto& [rst_key, leafVector] : leafRestartValue.extra) {
322 std::vector<std::vector<double>> levelVectors{};
323 levelVectors.resize(maxLevel+1);
325 if (rst_key.key ==
"OPMEXTRA") {
330 Opm::Lgr::populateDataVectorLevelGrids<double>(grid,
333 toOutput_refinedLevels,
335 for (
int level = 0; level <= maxLevel; ++level) {
336 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:473
int index() const
The (positive) index of an entity. Not a Dune interface method.
Definition: EntityRep.hpp:125
Definition: cpgrid/LevelCartesianIndexMapper.hpp:53
std::vector< std::unordered_map< int, int > > levelCartesianToLevelCompressedMaps(const Dune::CpGrid &grid, const Opm::LevelCartesianIndexMapper< Dune::CpGrid > &levelCartMapp)
Map level Cartesian index to level compressed index (active cell)
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:250
ScalarType processChildrenData(const std::vector< std::vector< ScalarType > > &levelVectors, const Dune::cpgrid::Entity< 0 > &element, const Dune::CpGrid &grid)
Definition: LgrOutputHelpers.hpp:224
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:211
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:74
ScalarType partialSum
Definition: LgrOutputHelpers.hpp:89
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:83
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:75
std::size_t count
Definition: LgrOutputHelpers.hpp:88
Definition: LgrOutputHelpers.hpp:57
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:65
ScalarType max
Definition: LgrOutputHelpers.hpp:70
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:58
Definition: LgrOutputHelpers.hpp:40
void operator()(int level, int levelIdx, const std::vector< std::vector< ScalarType > > &levelVectors)
Definition: LgrOutputHelpers.hpp:41
ScalarType getValue()
Definition: LgrOutputHelpers.hpp:48
ScalarType min
Definition: LgrOutputHelpers.hpp:53