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
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> {
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
97
98public:
104 static constexpr int dimensionworld = Grid::dimensionworld;
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
221 {
222#if HAVE_MPI
223 if (const auto& extPFile = this->externalPartitionFile();
224 !extPFile.empty() && (extPFile != "none"))
225 {
227 }
228
229 this->doLoadBalance_(this->edgeWeightsMethod(), this->ownersFirst(),
230 this->partitionMethod(), this->serialPartitioning(),
231 this->enableDistributedWells(), this->imbalanceTol(),
232 this->gridView(), this->schedule(),
233 this->eclState(), this->parallelWells_,
234 this->numJacobiBlocks());
235#endif
236
237 this->updateGridView_();
239 this->updateCellDepths_();
240 this->updateCellThickness_();
241
242#if HAVE_MPI
243 this->distributeFieldProps_(this->eclState());
244#endif
245 }
246
247 unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
248 return elemIndex;
249 }
250
251 unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
252 return elemIndex;
253 }
261 std::function<std::array<double,dimensionworld>(int)>
263 {
264 return this->cellCentroids_(this->cartesianIndexMapper(), true);
265 }
266
267 const std::vector<int>& globalCell()
268 {
269 return this->grid().globalCell();
270 }
271
272protected:
274 {
275 this->doCreateGrids_(this->eclState());
276 }
277
278 void allocTrans() override
279 {
280 OPM_TIMEBLOCK(allocateTrans);
282 this->gridView(),
283 this->cartesianIndexMapper(),
284 this->grid(),
285 this->cellCentroids(),
286 getPropValue<TypeTag, Properties::EnableEnergy>(),
287 getPropValue<TypeTag, Properties::EnableDiffusion>(),
288 getPropValue<TypeTag, Properties::EnableDispersion>()));
290 }
291
292 double getTransmissibility(unsigned I, unsigned J) const override
293 {
294 return globalTrans_->transmissibility(I,J);
295 }
296
297#if HAVE_MPI
298 const std::string& zoltanParams() const override
299 {
300 return this->zoltanParams_;
301 }
302 const std::string& metisParams() const override
303 {
304 return this->metisParams_;
305 }
306#endif
307
308 // removing some connection located in inactive grid cells
310 {
311 this->doFilterConnections_(this->schedule());
312 }
313
314 // \Note: this globalTrans_ is used for domain decomposition and INIT file output.
315 // It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
316 // diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
317 // during parallel running.
318 std::unique_ptr<TransmissibilityType> globalTrans_;
319};
320
321} // namespace Opm
322
323#endif // OPM_CPGRID_VANGUARD_HPP
This file ensures that flow can be compiled in the presence of dune-fem.
Declares the properties required by the black oil model.
Definition: CollectDataOnIORank.hpp:49
void updateGridView_()
Definition: basevanguard.hh:120
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition: basevanguard.hh:69
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:298
void filterConnections_()
Definition: CpGridVanguard.hpp:309
const TransmissibilityType & globalTransmissibility() const
Definition: CpGridVanguard.hpp:209
void allocTrans() override
Definition: CpGridVanguard.hpp:278
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:273
unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const
Definition: CpGridVanguard.hpp:251
GetPropType< TypeTag, Properties::EquilGrid > EquilGrid
Definition: CpGridVanguard.hpp:101
static constexpr bool gasEnabled
Definition: CpGridVanguard.hpp:107
void checkConsistency()
Definition: CpGridVanguard.hpp:123
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const
Definition: CpGridVanguard.hpp:247
const std::string & metisParams() const override
Definition: CpGridVanguard.hpp:302
std::function< std::array< double, dimensionworld >(int)> cellCentroids() const
Get function to query cell centroids for a distributed grid.
Definition: CpGridVanguard.hpp:262
std::unique_ptr< TransmissibilityType > globalTrans_
Definition: CpGridVanguard.hpp:318
static constexpr bool oilEnabled
Definition: CpGridVanguard.hpp:108
void loadBalance()
Distribute the simulation grid over multiple processes.
Definition: CpGridVanguard.hpp:220
Transmissibility< Grid, GridView, ElementMapper, CartesianIndexMapper, Scalar > TransmissibilityType
Definition: CpGridVanguard.hpp:103
const std::vector< int > & globalCell()
Definition: CpGridVanguard.hpp:267
double getTransmissibility(unsigned I, unsigned J) const override
Definition: CpGridVanguard.hpp:292
Helper class for grid instantiation of ECL file-format using problems.
Definition: FlowBaseVanguard.hpp:83
void updateCartesianToCompressedMapping_()
Definition: FlowBaseVanguard.hpp:350
void updateCellThickness_()
Definition: FlowBaseVanguard.hpp:395
void updateCellDepths_()
Definition: FlowBaseVanguard.hpp:372
void callImplementationInit()
Definition: FlowBaseVanguard.hpp:338
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:318
int numJacobiBlocks() const
Number of blocks in the Block-Jacobi preconditioner.
Definition: FlowGenericVanguard.hpp:239
const Schedule & schedule() const
Return a reference to the object that managages the ECL schedule.
Definition: FlowGenericVanguard.hpp:168
std::string zoltanParams_
Definition: FlowGenericVanguard.hpp:356
bool serialPartitioning() const
Parameter that decides if partitioning for parallel runs should be performed on a single process only...
Definition: FlowGenericVanguard.hpp:264
ParallelWellStruct parallelWells_
Information about wells in parallel.
Definition: FlowGenericVanguard.hpp:391
bool enableDistributedWells() const
Whether perforations of a well might be distributed.
Definition: FlowGenericVanguard.hpp:289
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition: FlowGenericVanguard.hpp:159
double imbalanceTol() const
Parameter that sets the imbalance tolarance, depending on the chosen partition method.
Definition: FlowGenericVanguard.hpp:270
const std::string & externalPartitionFile() const
Definition: FlowGenericVanguard.hpp:280
bool ownersFirst() const
Parameter that decide if cells owned by rank are ordered before ghost cells.
Definition: FlowGenericVanguard.hpp:251
Dune::EdgeWeightMethod edgeWeightsMethod() const
Parameter deciding the edge-weight strategy of the load balancer.
Definition: FlowGenericVanguard.hpp:233
Dune::PartitionMethod partitionMethod() const
Parameter deciding which partition method to use.
Definition: FlowGenericVanguard.hpp:258
std::string metisParams_
Definition: FlowGenericVanguard.hpp:358
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 Dune::PartitionMethod partitionMethod, const bool serialPartitioning, const bool enableDistributedWells, const double imbalanceTol, 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
Defines the common properties required by the porous medium multi-phase models.
Definition: blackoilmodel.hh:72
Definition: blackoilboundaryratevector.hh:37
typename Properties::Detail::GetPropImpl< TypeTag, Property >::type::type GetPropType
get the type alias defined in the property (equivalent to old macro GET_PROP_TYPE(....
Definition: propertysystem.hh:235
GetPropType< TypeTag, Properties::Grid > type
Definition: CpGridVanguard.hpp:71
Definition: FlowBaseVanguard.hpp:69
Dune::CpGrid type
Definition: CpGridVanguard.hpp:67
The type of the DUNE grid.
Definition: basicproperties.hh:100
Definition: CpGridVanguard.hpp:55
std::tuple< FlowBaseVanguard > InheritsFrom
Definition: CpGridVanguard.hpp:56
Property which provides a Vanguard (manages grids)
Definition: basicproperties.hh:96