Loading...
Searching...
No Matches
RegionPhasePVAverage.hpp
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
Copyright 2024 Equinor AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
#define OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
#include <opm/simulators/utils/ParallelCommunication.hpp>
#include <cstddef>
#include <functional>
#include <string>
#include <string_view>
#include <vector>
namespace Opm {
class RegionPhasePoreVolAverage
{
public:
struct CellValue
{
double value { 0.0 };
double sat { 0.0 };
double porv { 0.0 };
};
struct Phase
{
unsigned int ix;
};
struct Region
{
unsigned int ix;
};
using RegionArrayAccessor = std::function<const std::vector<int>&(const std::string&)>;
explicit RegionPhasePoreVolAverage(const Parallel::Communication& comm,
std::size_t numPhases,
const std::vector<std::string>& regionNames,
RegionArrayAccessor getRegionArray);
double fieldValue(const Phase& p) const;
double value(std::string_view rset, const Phase& p, const Region& r) const;
void prepareAccumulation();
void addCell(std::size_t activeCell, const Phase& p, const CellValue& cv);
void accumulateParallel();
private:
using Ix = std::vector<double>::size_type;
enum AvgType {
SatPV, //< Weighted by phase-filled pore-volume.
PV, //< Weighted by total pore-volume (s=1).
// ---- Must be last enumerator ----
NumTypes, //< Number of averge types.
};
enum Element {
Value, //< Running sum of weighted function values.
Weight, //< Running sum of weights.
// ---- Must be last enumerator ----
NumElem, //< Number of items/elements per average type.
};
std::reference_wrapper<const Parallel::Communication> comm_;
std::size_t np_{};
std::vector<std::string> rsetNames_{};
RegionArrayAccessor getRegionArray_;
std::vector<Ix> rsStart_{};
std::vector<double> x_{};
double averageValueWithFallback(Ix start) const;
double averageValue(Ix start, AvgType type) const;
Ix fieldStartIx(unsigned int phase) const;
Ix rsetStartIx(std::size_t rset, int region, unsigned int phase) const;
Ix startIx(std::size_t offset, unsigned int phase) const;
int regionIndex(std::size_t rset, std::size_t activeCell) const;
void add(Ix start, const CellValue& cv);
void add(Ix start, AvgType type, double x, double w);
double& value(Ix start, AvgType type);
double& weight(Ix start, AvgType type);
double value(Ix start, AvgType type) const;
double weight(Ix start, AvgType type) const;
Ix valueArrayIndex(Ix start, AvgType type, Element element) const;
};
} // namespace Opm
#endif // OPM_REGION_PHASE_POREVOL_AVERAGE_MODULE_HPP
Opm::RegionPhasePoreVolAverage::addCell
void addCell(std::size_t activeCell, const Phase &p, const CellValue &cv)
Incorporate contributions from a single cell.
Definition RegionPhasePVAverage.cpp:117
Opm::RegionPhasePoreVolAverage::accumulateParallel
void accumulateParallel()
Accumulate region-level average values across MPI ranks.
Definition RegionPhasePVAverage.cpp:128
Opm::RegionPhasePoreVolAverage::fieldValue
double fieldValue(const Phase &p) const
Retrieve field-level average function value for specific phase.
Definition RegionPhasePVAverage.cpp:90
Opm::RegionPhasePoreVolAverage::RegionArrayAccessor
std::function< const std::vector< int > &(const std::string &)> RegionArrayAccessor
Call-back function type for accessing region arrays–typically the FIP* arrays.
Definition RegionPhasePVAverage.hpp:72
Opm::RegionPhasePoreVolAverage::RegionPhasePoreVolAverage
RegionPhasePoreVolAverage(const Parallel::Communication &comm, std::size_t numPhases, const std::vector< std::string > &regionNames, RegionArrayAccessor getRegionArray)
Constructor.
Definition RegionPhasePVAverage.cpp:78
Opm::RegionPhasePoreVolAverage::prepareAccumulation
void prepareAccumulation()
Clear internal arrays in preparation of accumulating region-level averages from per-cell contribution...
Definition RegionPhasePVAverage.cpp:111
Opm::RegionPhasePoreVolAverage::value
double value(std::string_view rset, const Phase &p, const Region &r) const
Retrieve region-level average function value for specific phase in specific region of named region se...
Definition RegionPhasePVAverage.cpp:97
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::RegionPhasePoreVolAverage::CellValue
Minimal characteristics of a cell from a simulation grid.
Definition RegionPhasePVAverage.hpp:46
Opm::RegionPhasePoreVolAverage::CellValue::value
double value
Function value.
Definition RegionPhasePVAverage.hpp:48
Opm::RegionPhasePoreVolAverage::CellValue::porv
double porv
Reservoir condition pore-volume.
Definition RegionPhasePVAverage.hpp:54
Opm::RegionPhasePoreVolAverage::CellValue::sat
double sat
Phase saturation.
Definition RegionPhasePVAverage.hpp:51
Opm::RegionPhasePoreVolAverage::Phase
Compile-time disambiguation type for phases.
Definition RegionPhasePVAverage.hpp:59
Opm::RegionPhasePoreVolAverage::Phase::ix
unsigned int ix
Phase index.
Definition RegionPhasePVAverage.hpp:61
Opm::RegionPhasePoreVolAverage::Region
Compile-time disambiguation type for regions.
Definition RegionPhasePVAverage.hpp:66
Opm::RegionPhasePoreVolAverage::Region::ix
unsigned int ix
Region index.
Definition RegionPhasePVAverage.hpp:68