opm-simulators
ParallelEclipseState.hpp
1 /*
2  Copyright 2019 Equinor AS.
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 3 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 #ifndef PARALLEL_ECLIPSE_STATE_HPP
20 #define PARALLEL_ECLIPSE_STATE_HPP
21 
22 #include <dune/common/version.hh>
23 #include <opm/input/eclipse/EclipseState/EclipseState.hpp>
24 #include <opm/input/eclipse/EclipseState/Grid/TranCalculator.hpp>
25 #include <dune/common/parallel/mpihelper.hh>
26 
27 #include <opm/simulators/utils/ParallelCommunication.hpp>
28 
29 #include <functional>
30 
31 namespace Opm {
32 
33 
42 class ParallelFieldPropsManager : public FieldPropsManager {
43 public:
44  friend class ParallelEclipseState;
45  template<class Grid>
47  friend class PropsDataHandle;
48 
51  explicit ParallelFieldPropsManager(FieldPropsManager& manager);
52 
56  ParallelFieldPropsManager(FieldPropsManager& manager, Parallel::Communication comm);
57 
60  std::vector<int> actnum() const override;
61 
64  void reset_actnum(const std::vector<int>& actnum) override;
65 
67  std::vector<double> porv(bool global = false) const override;
68 
71  const std::vector<int>& get_int(const std::string& keyword) const override;
72 
75  const std::vector<double>& get_double(const std::string& keyword) const override;
76 
80  std::vector<int> get_global_int(const std::string& keyword) const override;
81 
85  std::vector<double> get_global_double(const std::string& keyword) const override;
86 
89  bool has_int(const std::string& keyword) const override;
90 
93  bool has_double(const std::string& keyword) const override;
94 
96  std::vector<std::string> fip_regions() const override;
97 
103  template<class T>
104  void resetCartesianMapper(const T* mapper)
105  {
106  // Note: mapper would usually be a CartesianIndexMapper. However, to support also
107  // the case of a distributed level zero grid in a CpGrid with LGRs, mapper will be
108  // Opm::LevelCartesianIndexMapper. This change allows access to the Cartesian indices
109  // of the distributed level zero grid, where the field properties are given - for now.
110  // In case of supporting LGR field properties, this need to be adapted, to access instead
111  // each local/level Cartesian index set.
112  m_activeSize = [mapper]() { return mapper->compressedSize(/*level = */ 0); };
113  m_local2Global = [mapper](int localIdx) { return mapper->cartesianIndex(localIdx, /* level = */ 0); };
114  }
115 
116  bool tran_active(const std::string& keyword) const override;
117 
118  void apply_tran(const std::string& keyword, std::vector<double>& trans) const override;
119 
120  void copyTran(const FieldPropsManager& from)
121  {
122  m_tran = from.getTran();
123  }
124 
125  template<class Serializer>
126  void serializeOp(Serializer& serializer)
127  {
128  serializer(m_tran);
129  }
130 
131 protected:
132  std::map<std::string, Fieldprops::FieldData<int>> m_intProps;
133  std::map<std::string, Fieldprops::FieldData<double>> m_doubleProps;
134  FieldPropsManager& m_manager;
135  Parallel::Communication m_comm;
136  std::function<int(void)> m_activeSize;
137  std::function<int(const int)> m_local2Global;
138  std::unordered_map<std::string, Fieldprops::TranCalculator> m_tran;
139 };
140 
141 
153 class ParallelEclipseState : public EclipseState {
155  template<class Grid>
156  friend class PropsDataHandle;
157 public:
159  ParallelEclipseState(Parallel::Communication comm);
160 
164  ParallelEclipseState(const Deck& deck);
165 
171  ParallelEclipseState(const Deck& deck, Parallel::Communication comm);
172 
175  void switchToGlobalProps();
176 
181 
183  const FieldPropsManager& fieldProps() const override;
184 
187  const FieldPropsManager& globalFieldProps() const override;
188 
193  void computeFipRegionStatistics() override;
194 
197  const EclipseGrid& getInputGrid() const override;
198 
204  template<class T>
205  void resetCartesianMapper(const T* mapper)
206  {
207  m_fieldProps.resetCartesianMapper(mapper);
208  }
209 private:
210  bool m_parProps = false;
211  ParallelFieldPropsManager m_fieldProps;
212  Parallel::Communication m_comm;
213 };
214 
215 
216 } // end namespace Opm
217 #endif // PARALLEL_ECLIPSE_STATE_HPP
friend class PropsDataHandle
Friend to set up props.
Definition: ParallelEclipseState.hpp:47
std::vector< int > actnum() const override
Returns actnum vector.
Definition: ParallelEclipseState.cpp:60
std::unordered_map< std::string, Fieldprops::TranCalculator > m_tran
calculators map
Definition: ParallelEclipseState.hpp:138
void switchToDistributedProps()
Switch to distributed field properies.
Definition: ParallelEclipseState.cpp:316
void switchToGlobalProps()
Switch to global field properties.
Definition: ParallelEclipseState.cpp:310
bool has_int(const std::string &keyword) const override
Check if an integer property is available.
Definition: ParallelEclipseState.cpp:222
Parallel::Communication m_comm
Collective communication handler.
Definition: ParallelEclipseState.hpp:135
std::vector< int > get_global_int(const std::string &keyword) const override
Returns an int property using global cartesian indices.
Definition: ParallelEclipseState.cpp:121
std::vector< double > porv(bool global=false) const override
Returns the pore volume vector.
Definition: ParallelEclipseState.cpp:77
std::vector< std::string > fip_regions() const override
Returns a list of registered FIP regions.
Definition: ParallelEclipseState.cpp:234
const FieldPropsManager & globalFieldProps() const override
Returns a const ref to global field properties.
Definition: ParallelEclipseState.cpp:280
std::vector< double > get_global_double(const std::string &keyword) const override
Returns a double property using global cartesian indices.
Definition: ParallelEclipseState.cpp:179
Parallel frontend to the EclipseState.
Definition: ParallelEclipseState.hpp:153
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition: blackoilbioeffectsmodules.hh:45
const std::vector< double > & get_double(const std::string &keyword) const override
Returns a double property using compressed indices.
Definition: ParallelEclipseState.cpp:157
friend class PropsDataHandle
Friend to set up props.
Definition: ParallelEclipseState.hpp:156
void resetCartesianMapper(const T *mapper)
Resets the underlying cartesian mapper This has to be the cartesian mapper of the distributed grid...
Definition: ParallelEclipseState.hpp:104
std::map< std::string, Fieldprops::FieldData< double > > m_doubleProps
Map of double properties in process-local compressed indices.
Definition: ParallelEclipseState.hpp:133
Parallel frontend to the field properties.
Definition: ParallelEclipseState.hpp:42
const FieldPropsManager & fieldProps() const override
Returns a const ref to current field properties.
Definition: ParallelEclipseState.cpp:268
std::function< int(const int)> m_local2Global
mapping from local to global cartesian indices
Definition: ParallelEclipseState.hpp:137
const EclipseGrid & getInputGrid() const override
Returns a const ref to the eclipse grid.
Definition: ParallelEclipseState.cpp:302
void resetCartesianMapper(const T *mapper)
Resets the underlying cartesian mapper This has to be the cartesian mapper of the distributed grid...
Definition: ParallelEclipseState.hpp:205
FieldPropsManager & m_manager
Underlying field property manager (only used on root process).
Definition: ParallelEclipseState.hpp:134
ParallelFieldPropsManager(FieldPropsManager &manager)
Constructor.
Definition: ParallelEclipseState.cpp:46
ParallelEclipseState(Parallel::Communication comm)
Default constructor.
Definition: ParallelEclipseState.cpp:248
void computeFipRegionStatistics() override
Compute basic descriptive statistics about all FIP region sets.
Definition: ParallelEclipseState.cpp:288
void reset_actnum(const std::vector< int > &actnum) override
Reset the actnum vector.
Definition: ParallelEclipseState.cpp:69
bool has_double(const std::string &keyword) const override
Check if a double property is available.
Definition: ParallelEclipseState.cpp:228
std::function< int(void)> m_activeSize
active size function of the grid
Definition: ParallelEclipseState.hpp:136
std::map< std::string, Fieldprops::FieldData< int > > m_intProps
Map of integer properties in process-local compressed indices.
Definition: ParallelEclipseState.hpp:132
const std::vector< int > & get_int(const std::string &keyword) const override
Returns an int property using compressed indices.
Definition: ParallelEclipseState.cpp:99