CpGridVanguard.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*/
27#ifndef OPM_CPGRID_VANGUARD_HPP
28#define OPM_CPGRID_VANGUARD_HPP
29
30#include <opm/common/TimingMacros.hpp>
31
32#include <opm/models/common/multiphasebaseproperties.hh>
33#include <opm/models/blackoil/blackoilproperties.hh>
34
39
40#include <array>
41#include <functional>
42#include <memory>
43#include <stdexcept>
44#include <tuple>
45#include <vector>
46
47namespace Opm {
48template <class TypeTag>
49class CpGridVanguard;
50}
51
52namespace Opm::Properties {
53
54namespace TTag {
56 using InheritsFrom = std::tuple<FlowBaseVanguard>;
57};
58}
59
60// declare the properties
61template<class TypeTag>
62struct Vanguard<TypeTag, TTag::CpGridVanguard> {
64};
65template<class TypeTag>
66struct Grid<TypeTag, TTag::CpGridVanguard> {
67 using type = Dune::CpGrid;
68};
69template<class TypeTag>
70struct EquilGrid<TypeTag, TTag::CpGridVanguard> {
71 using type = GetPropType<TypeTag, Properties::Grid>;
72};
73
74} // namespace Opm::Properties
75
76namespace Opm {
77
85template <class TypeTag>
86class CpGridVanguard : public FlowBaseVanguard<TypeTag>
87 , public GenericCpGridVanguard<GetPropType<TypeTag, Properties::ElementMapper>,
88 GetPropType<TypeTag, Properties::GridView>,
89 GetPropType<TypeTag, Properties::Scalar>>
90{
91 friend class FlowBaseVanguard<TypeTag>;
93
94 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
95 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
96 using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
97
98public:
99 using Grid = GetPropType<TypeTag, Properties::Grid>;
101 using EquilGrid = GetPropType<TypeTag, Properties::EquilGrid>;
102 using GridView = GetPropType<TypeTag, Properties::GridView>;
104 static constexpr int dimensionworld = Grid::dimensionworld;
105 using Indices = GetPropType<TypeTag, Properties::Indices>;
106 static constexpr bool waterEnabled = Indices::waterEnabled;
107 static constexpr bool gasEnabled = Indices::gasEnabled;
108 static constexpr bool oilEnabled = Indices::oilEnabled;
109private:
110 using Element = typename GridView::template Codim<0>::Entity;
111
112public:
113 CpGridVanguard(Simulator& simulator)
114 : FlowBaseVanguard<TypeTag>(simulator)
115 {
116 this->checkConsistency();
118 }
119
124 {
125 const auto& runspec = this->eclState().runspec();
126 const auto& config = this->eclState().getSimulationConfig();
127 const auto& phases = runspec.phases();
128
129 // check for correct module setup
130 if (config.isThermal()) {
131 if (getPropValue<TypeTag, Properties::EnableEnergy>() == false) {
132 throw std::runtime_error("Input specifies energy while simulator has disabled it, try xxx_energy");
133 }
134 } else {
135 if (getPropValue<TypeTag, Properties::EnableEnergy>() == true) {
136 throw std::runtime_error("Input specifies no energy while simulator has energy, try run without _energy");
137 }
138 }
139
140 if (config.isDiffusive()) {
141 if (getPropValue<TypeTag, Properties::EnableDiffusion>() == false) {
142 throw std::runtime_error("Input specifies diffusion while simulator has disabled it, try xxx_diffusion");
143 }
144 }
145
146 if (runspec.micp()) {
147 if (getPropValue<TypeTag, Properties::EnableMICP>() == false) {
148 throw std::runtime_error("Input specifies MICP while simulator has it disabled");
149 }
150 }
151
152 if (phases.active(Phase::BRINE)) {
153 if (getPropValue<TypeTag, Properties::EnableBrine>() == false) {
154 throw std::runtime_error("Input specifies Brine while simulator has it disabled");
155 }
156 }
157
158 if (phases.active(Phase::POLYMER)) {
159 if (getPropValue<TypeTag, Properties::EnablePolymer>() == false) {
160 throw std::runtime_error("Input specifies Polymer while simulator has it disabled");
161 }
162 }
163
164 // checking for correct phases is more difficult TODO!
165 if (phases.active(Phase::ZFRACTION)) {
166 if (getPropValue<TypeTag, Properties::EnableExtbo>() == false) {
167 throw std::runtime_error("Input specifies ExBo while simulator has it disabled");
168 }
169 }
170 if (phases.active(Phase::FOAM)) {
171 if (getPropValue<TypeTag, Properties::EnableFoam>() == false) {
172 throw std::runtime_error("Input specifies Foam while simulator has it disabled");
173 }
174 }
175
176 if (phases.active(Phase::SOLVENT)) {
177 if (getPropValue<TypeTag, Properties::EnableSolvent>() == false) {
178 throw std::runtime_error("Input specifies Solvent while simulator has it disabled");
179 }
180 }
181 if(phases.active(Phase::WATER)){
182 if(waterEnabled == false){
183 throw std::runtime_error("Input specifies water while simulator has it disabled");
184 }
185 }
186 if(phases.active(Phase::GAS)){
187 if(gasEnabled == false){
188 throw std::runtime_error("Input specifies gas while simulator has it disabled");
189 }
190 }
191 if(phases.active(Phase::OIL)){
192 if(oilEnabled == false){
193 throw std::runtime_error("Input specifies oil while simulator has it disabled");
194 }
195 }
196
197 }
198
205 {
206 globalTrans_.reset();
207 }
208
210 {
211 assert( globalTrans_ != nullptr );
212 return *globalTrans_;
213 }
214
216 {
217 globalTrans_.reset();
218 }
219
226 {
227#if HAVE_MPI
228 if (const auto& extPFile = this->externalPartitionFile();
229 !extPFile.empty() && (extPFile != "none"))
230 {
232 }
233
234 this->doLoadBalance_(this->edgeWeightsMethod(), this->ownersFirst(),
236 this->zoltanImbalanceTol(), this->gridView(),
237 this->schedule(), this->eclState(),
238 this->parallelWells_, this->numJacobiBlocks());
239#endif
240
241 this->updateGridView_();
243 this->updateCellDepths_();
244 this->updateCellThickness_();
245
246#if HAVE_MPI
247 this->distributeFieldProps_(this->eclState());
248#endif
249 }
250
251 unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
252 return elemIndex;
253 }
254
255 unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
256 return elemIndex;
257 }
265 std::function<std::array<double,dimensionworld>(int)>
267 {
268 return this->cellCentroids_(this->cartesianIndexMapper(), true);
269 }
270
271 const std::vector<int>& globalCell()
272 {
273 return this->grid().globalCell();
274 }
275
276protected:
278 {
279 this->doCreateGrids_(this->eclState());
280 }
281
282 void allocTrans() override
283 {
284 OPM_TIMEBLOCK(allocateTrans);
286 this->gridView(),
287 this->cartesianIndexMapper(),
288 this->grid(),
289 this->cellCentroids(),
290 getPropValue<TypeTag, Properties::EnableEnergy>(),
291 getPropValue<TypeTag, Properties::EnableDiffusion>(),
292 getPropValue<TypeTag, Properties::EnableDispersion>()));
293 globalTrans_->update(false);
294 }
295
296 double getTransmissibility(unsigned I, unsigned J) const override
297 {
298 return globalTrans_->transmissibility(I,J);
299 }
300
301#if HAVE_MPI
302 const std::string& zoltanParams() const override
303 {
304 return this->zoltanParams_;
305 }
306#endif
307
308 // removing some connection located in inactive grid cells
310 {
311 this->doFilterConnections_(this->schedule());
312 }
313
314 std::unique_ptr<TransmissibilityType> globalTrans_;
315};
316
317} // namespace Opm
318
319#endif // OPM_CPGRID_VANGUARD_HPP
This file ensures that flow can be compiled in the presence of dune-fem.
Definition: CollectDataOnIORank.hpp:49
Helper class for grid instantiation of ECL file-format using problems.
Definition: CpGridVanguard.hpp:90
GetPropType< TypeTag, Properties::Indices > Indices
Definition: CpGridVanguard.hpp:105
void releaseGlobalTransmissibilities()
Free the memory occupied by the global transmissibility object.
Definition: CpGridVanguard.hpp:204
const std::string & zoltanParams() const override
Definition: CpGridVanguard.hpp:302
void filterConnections_()
Definition: CpGridVanguard.hpp:309
const TransmissibilityType & globalTransmissibility() const
Definition: CpGridVanguard.hpp:209
GetPropType< TypeTag, Properties::Grid > Grid
Definition: CpGridVanguard.hpp:99
void allocTrans() override
Definition: CpGridVanguard.hpp:282
static constexpr int dimensionworld
Definition: CpGridVanguard.hpp:104
static constexpr bool waterEnabled
Definition: CpGridVanguard.hpp:106
CpGridVanguard(Simulator &simulator)
Definition: CpGridVanguard.hpp:113
void createGrids_()
Definition: CpGridVanguard.hpp:277
unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const
Definition: CpGridVanguard.hpp:255
GetPropType< TypeTag, Properties::EquilGrid > EquilGrid
Definition: CpGridVanguard.hpp:101
static constexpr bool gasEnabled
Definition: CpGridVanguard.hpp:107
GetPropType< TypeTag, Properties::GridView > GridView
Definition: CpGridVanguard.hpp:102
void releaseGlobalTransmissibility()
Definition: CpGridVanguard.hpp:215
void checkConsistency()
Definition: CpGridVanguard.hpp:123
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const
Definition: CpGridVanguard.hpp:251
std::function< std::array< double, dimensionworld >(int)> cellCentroids() const
Get function to query cell centroids for a distributed grid.
Definition: CpGridVanguard.hpp:266
std::unique_ptr< TransmissibilityType > globalTrans_
Definition: CpGridVanguard.hpp:314
static constexpr bool oilEnabled
Definition: CpGridVanguard.hpp:108
void loadBalance()
Distribute the simulation grid over multiple processes.
Definition: CpGridVanguard.hpp:225
Transmissibility< Grid, GridView, ElementMapper, CartesianIndexMapper, Scalar > TransmissibilityType
Definition: CpGridVanguard.hpp:103
const std::vector< int > & globalCell()
Definition: CpGridVanguard.hpp:271
double getTransmissibility(unsigned I, unsigned J) const override
Definition: CpGridVanguard.hpp:296
Helper class for grid instantiation of ECL file-format using problems.
Definition: FlowBaseVanguard.hpp:216
void updateCartesianToCompressedMapping_()
Definition: FlowBaseVanguard.hpp:526
void updateCellThickness_()
Definition: FlowBaseVanguard.hpp:571
void updateCellDepths_()
Definition: FlowBaseVanguard.hpp:548
void callImplementationInit()
Definition: FlowBaseVanguard.hpp:516
std::function< std::array< double, dimensionworld >(int)> cellCentroids_(const CartMapper &cartMapper, const bool &isCpGrid) const
Get function to query cell centroids for a distributed grid.
Definition: FlowBaseVanguard.hpp:496
int numJacobiBlocks() const
Number of blocks in the Block-Jacobi preconditioner.
Definition: FlowGenericVanguard.hpp:200
const Schedule & schedule() const
Return a reference to the object that managages the ECL schedule.
Definition: FlowGenericVanguard.hpp:129
std::string zoltanParams_
Definition: FlowGenericVanguard.hpp:296
bool serialPartitioning() const
Parameter that decides if partitioning for parallel runs should be performed on a single process only...
Definition: FlowGenericVanguard.hpp:220
ParallelWellStruct parallelWells_
Information about wells in parallel.
Definition: FlowGenericVanguard.hpp:328
bool enableDistributedWells() const
Whether perforations of a well might be distributed.
Definition: FlowGenericVanguard.hpp:238
double zoltanImbalanceTol() const
Parameter that sets the zoltan imbalance tolarance.
Definition: FlowGenericVanguard.hpp:226
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition: FlowGenericVanguard.hpp:120
const std::string & externalPartitionFile() const
Definition: FlowGenericVanguard.hpp:229
bool ownersFirst() const
Parameter that decide if cells owned by rank are ordered before ghost cells.
Definition: FlowGenericVanguard.hpp:212
Dune::EdgeWeightMethod edgeWeightsMethod() const
Parameter deciding the edge-weight strategy of the load balancer.
Definition: FlowGenericVanguard.hpp:194
Definition: GenericCpGridVanguard.hpp:78
const CartesianIndexMapper & cartesianIndexMapper() const
Returns the object which maps a global element index of the simulation grid to the corresponding elem...
void doLoadBalance_(const Dune::EdgeWeightMethod edgeWeightsMethod, const bool ownersFirst, const bool serialPartitioning, const bool enableDistributedWells, const double zoltanImbalanceTol, const GetPropType< TypeTag, Properties::GridView > &gridView, const Schedule &schedule, EclipseState &eclState, FlowGenericVanguard::ParallelWellStruct &parallelWells, const int numJacobiBlocks)
Distribute the simulation grid over multiple processes.
static void setExternalLoadBalancer(const std::function< std::vector< int >(const Dune::CpGrid &)> &loadBalancer)
Sets a function that returns external load balancing information when passed the grid.
Definition: GenericCpGridVanguard.hpp:123
Definition: Transmissibility.hpp:54
Definition: GenericCpGridVanguard.hpp:56
Definition: AluGridVanguard.hpp:57
Definition: BlackoilPhases.hpp:27
GetPropType< TypeTag, Properties::Grid > type
Definition: CpGridVanguard.hpp:71
Definition: FlowBaseVanguard.hpp:64
Dune::CpGrid type
Definition: CpGridVanguard.hpp:67
Definition: CpGridVanguard.hpp:55
std::tuple< FlowBaseVanguard > InheritsFrom
Definition: CpGridVanguard.hpp:56