FlowBaseVanguard.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_FLOW_BASE_VANGUARD_HPP
28#define OPM_FLOW_BASE_VANGUARD_HPP
29
30#include <dune/grid/common/partitionset.hh>
31
32#include <opm/grid/common/GridEnums.hpp>
33#include <opm/grid/common/CartesianIndexMapper.hpp>
34#include <opm/grid/LookUpCellCentroid.hh>
35
36#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquiferCell.hpp>
37#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
38
44
47
48#include <array>
49#include <cstddef>
50#include <unordered_map>
51#include <vector>
52
53namespace Opm {
54template <class TypeTag>
55class FlowBaseVanguard;
56template<typename Grid, typename GridView> struct LookUpCellCentroid;
57}
58
59namespace Opm::Properties {
60
61namespace TTag {
62
64
65}
66
67// declare the properties required by the for the ecl simulator vanguard
68template<class TypeTag, class MyTypeTag>
69struct EquilGrid { using type = UndefinedProperty; };
70
71} // namespace Opm::Properties
72
73namespace Opm {
74
80template <class TypeTag>
81class FlowBaseVanguard : public BaseVanguard<TypeTag>,
83{
85 using Implementation = GetPropType<TypeTag, Properties::Vanguard>;
89
90 enum { enableExperiments = getPropValue<TypeTag, Properties::EnableExperiments>() };
91
92public:
95
96protected:
97 static const int dimension = Grid::dimension;
98 static const int dimensionworld = Grid::dimensionworld;
99 using Element = typename GridView::template Codim<0>::Entity;
101
102public:
106 static void registerParameters()
107 {
108 FlowGenericVanguard::registerParameters_<Scalar>();
109 }
110
117 FlowBaseVanguard(Simulator& simulator)
118 : ParentType(simulator)
119 {
120 fileName_ = Parameters::Get<Parameters::EclDeckFileName>();
121 edgeWeightsMethod_ = Dune::EdgeWeightMethod(Parameters::Get<Parameters::EdgeWeightsMethod>());
122
123#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
124 numJacobiBlocks_ = Parameters::Get<Parameters::NumJacobiBlocks>();
125#endif
126
127 ownersFirst_ = Parameters::Get<Parameters::OwnerCellsFirst>();
128#if HAVE_MPI
129 partitionMethod_ = Dune::PartitionMethod(Parameters::Get<Parameters::PartitionMethod>());
130 serialPartitioning_ = Parameters::Get<Parameters::SerialPartitioning>();
131 imbalanceTol_ = Parameters::Get<Parameters::ImbalanceTol<Scalar>>();
132
133 zoltanImbalanceTolSet_ = Parameters::IsSet<Parameters::ZoltanImbalanceTol<Scalar>>();
134 zoltanImbalanceTol_ = Parameters::Get<Parameters::ZoltanImbalanceTol<Scalar>>();
135 zoltanParams_ = Parameters::Get<Parameters::ZoltanParams>();
136
137 metisParams_ = Parameters::Get<Parameters::MetisParams>();
138
139 externalPartitionFile_ = Parameters::Get<Parameters::ExternalPartition>();
140#endif
141 enableDistributedWells_ = Parameters::Get<Parameters::AllowDistributedWells>();
142 ignoredKeywords_ = Parameters::Get<Parameters::IgnoreKeywords>();
143 int output_param = Parameters::Get<Parameters::EclOutputInterval>();
144 if (output_param >= 0)
145 outputInterval_ = output_param;
146 useMultisegmentWell_ = Parameters::Get<Parameters::UseMultisegmentWell>();
147 enableExperiments_ = enableExperiments;
148
149 init();
150 }
151
153 { return asImp_().cartesianIndexMapper(); }
154
158 const std::array<int, dimension>& cartesianDimensions() const
159 { return asImp_().cartesianIndexMapper().cartesianDimensions(); }
160
164 int cartesianSize() const
165 { return asImp_().cartesianIndexMapper().cartesianSize(); }
166
171 { return asImp_().equilCartesianIndexMapper().cartesianSize(); }
172
176 unsigned cartesianIndex(unsigned compressedCellIdx) const
177 { return asImp_().cartesianIndexMapper().cartesianIndex(compressedCellIdx); }
178
182 unsigned cartesianIndex(const std::array<int,dimension>& coords) const
183 {
184 unsigned cartIndex = coords[0];
185 int factor = cartesianDimensions()[0];
186 for (unsigned i = 1; i < dimension; ++i) {
187 cartIndex += coords[i]*factor;
188 factor *= cartesianDimensions()[i];
189 }
190
191 return cartIndex;
192 }
193
200 int compressedIndex(int cartesianCellIdx) const
201 {
202 auto index_pair = cartesianToCompressed_.find(cartesianCellIdx);
203 if (index_pair!=cartesianToCompressed_.end())
204 return index_pair->second;
205 else
206 return -1;
207 }
208
215 int compressedIndexForInterior(int cartesianCellIdx) const
216 {
217 auto index_pair = cartesianToCompressed_.find(cartesianCellIdx);
218 if (index_pair == cartesianToCompressed_.end() ||
219 !is_interior_[index_pair->second])
220 {
221 return -1;
222 }
223 else
224 {
225 return index_pair->second;
226 }
227 }
234 void cartesianCoordinate(unsigned cellIdx, std::array<int,3>& ijk) const
235 { return asImp_().cartesianIndexMapper().cartesianCoordinate(cellIdx, ijk); }
236
240 unsigned equilCartesianIndex(unsigned compressedEquilCellIdx) const
241 { return asImp_().equilCartesianIndexMapper().cartesianIndex(compressedEquilCellIdx); }
242
249 void equilCartesianCoordinate(unsigned cellIdx, std::array<int,3>& ijk) const
250 { return asImp_().equilCartesianIndexMapper().cartesianCoordinate(cellIdx, ijk); }
251
252
259 Scalar cellCenterDepth(unsigned globalSpaceIdx) const
260 {
261 return cellCenterDepth_[globalSpaceIdx];
262 }
263
264 const std::vector<Scalar>& cellCenterDepths() const
265 {
266 return cellCenterDepth_;
267 }
268
276 Scalar cellThickness(unsigned globalSpaceIdx) const
277 {
278 assert(!cellThickness_.empty());
279 return cellThickness_[globalSpaceIdx];
280 }
281
287 std::size_t globalNumCells() const
288 {
289 const auto& grid = asImp_().grid();
290 if (grid.comm().size() == 1)
291 {
292 return grid.leafGridView().size(0);
293 }
294 const auto& gridView = grid.leafGridView();
295 constexpr int codim = 0;
296 constexpr auto Part = Dune::Interior_Partition;
297 auto local_cells = std::distance(gridView.template begin<codim, Part>(),
298 gridView.template end<codim, Part>());
299 return grid.comm().sum(local_cells);
300 }
301
304 }
305
306protected:
316 template<class CartMapper>
317 std::function<std::array<double,dimensionworld>(int)>
318 cellCentroids_(const CartMapper& cartMapper, const bool& isCpGrid) const
319 {
320 return [this, cartMapper, isCpGrid](int elemIdx) {
321 std::array<double,dimensionworld> centroid;
322 const auto rank = this->gridView().comm().rank();
323 const auto maxLevel = this->gridView().grid().maxLevel();
324 bool useEclipse = !isCpGrid || (isCpGrid && (rank == 0) && (maxLevel == 0));
325 if (useEclipse)
326 {
327 centroid = this->eclState().getInputGrid().getCellCenter(cartMapper.cartesianIndex(elemIdx));
328 }
329 else
330 {
331 LookUpCellCentroid<Grid,GridView> lookUpCellCentroid(this->gridView(), cartMapper, nullptr);
332 centroid = lookUpCellCentroid(elemIdx);
333 }
334 return centroid;
335 };
336 }
337
339 {
340 asImp_().createGrids_();
341 asImp_().filterConnections_();
342 std::string outputDir = Parameters::Get<Parameters::OutputDir>();
343 bool enableEclCompatFile = !Parameters::Get<Parameters::EnableOpmRstFile>();
344 asImp_().updateOutputDir_(outputDir, enableEclCompatFile);
345 const std::string& dryRunString = Parameters::Get<Parameters::EnableDryRun>();
346 asImp_().updateNOSIM_(dryRunString);
347 asImp_().finalizeInit_();
348 }
349
351 {
352 std::size_t num_cells = asImp_().grid().leafGridView().size(0);
353 is_interior_.resize(num_cells);
354
355 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
356 for (const auto& element : elements(this->gridView()))
357 {
358 const auto elemIdx = elemMapper.index(element);
359 unsigned cartesianCellIdx = cartesianIndex(elemIdx);
360 cartesianToCompressed_[cartesianCellIdx] = elemIdx;
361 if (element.partitionType() == Dune::InteriorEntity)
362 {
363 is_interior_[elemIdx] = 1;
364 }
365 else
366 {
367 is_interior_[elemIdx] = 0;
368 }
369 }
370 }
371
373 {
374 int numCells = this->gridView().size(/*codim=*/0);
375 cellCenterDepth_.resize(numCells);
376
377 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
378
379 const auto num_aqu_cells = this->allAquiferCells();
380
381 for(const auto& element : elements(this->gridView())) {
382 const unsigned int elemIdx = elemMapper.index(element);
383 cellCenterDepth_[elemIdx] = cellCenterDepth(element);
384
385 if (!num_aqu_cells.empty()) {
386 const unsigned int global_index = cartesianIndex(elemIdx);
387 const auto search = num_aqu_cells.find(global_index);
388 if (search != num_aqu_cells.end()) {
389 // updating the cell depth using aquifer cell depth
390 cellCenterDepth_[elemIdx] = search->second->depth;
391 }
392 }
393 }
394 }
396 {
397 if (!this->drsdtconEnabled())
398 return;
399
400 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
401
402 int numElements = this->gridView().size(/*codim=*/0);
403 cellThickness_.resize(numElements);
404
405 for (const auto& elem : elements(this->gridView())) {
406 const unsigned int elemIdx = elemMapper.index(elem);
407 cellThickness_[elemIdx] = computeCellThickness(elem);
408 }
409 }
410
411private:
412 // computed from averaging cell corner depths
413 Scalar cellCenterDepth(const Element& element) const
414 {
415 typedef typename Element::Geometry Geometry;
416 static constexpr int zCoord = Element::dimension - 1;
417 Scalar zz = 0.0;
418
419 const Geometry& geometry = element.geometry();
420 const int corners = geometry.corners();
421 for (int i=0; i < corners; ++i)
422 zz += geometry.corner(i)[zCoord];
423
424 return zz/Scalar(corners);
425 }
426
427 Scalar computeCellThickness(const typename GridView::template Codim<0>::Entity& element) const
428 {
429 typedef typename Element::Geometry Geometry;
430 static constexpr int zCoord = Element::dimension - 1;
431 Scalar zz1 = 0.0;
432 Scalar zz2 = 0.0;
433
434 const Geometry& geometry = element.geometry();
435 // This code only works with CP-grid where the
436 // number of corners are 8 and
437 // also assumes that the first
438 // 4 corners are the top surface and
439 // the 4 next are the bottomn.
440 assert(geometry.corners() == 8);
441 for (int i=0; i < 4; ++i){
442 zz1 += geometry.corner(i)[zCoord];
443 zz2 += geometry.corner(i+4)[zCoord];
444 }
445 zz1 /=4;
446 zz2 /=4;
447 return zz2-zz1;
448 }
449
450 Implementation& asImp_()
451 { return *static_cast<Implementation*>(this); }
452
453 const Implementation& asImp_() const
454 { return *static_cast<const Implementation*>(this); }
455
456protected:
460 std::unordered_map<int,int> cartesianToCompressed_;
461
464 std::vector<Scalar> cellCenterDepth_;
465
468 std::vector<Scalar> cellThickness_;
469
472 std::vector<int> is_interior_;
473};
474
475} // namespace Opm
476
477#endif // OPM_FLOW_BASE_VANGUARD_HPP
Definition: CollectDataOnIORank.hpp:49
Provides the base class for most (all?) simulator vanguards.
Definition: basevanguard.hh:49
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: FlowBaseVanguard.hpp:83
unsigned cartesianIndex(const std::array< int, dimension > &coords) const
Return the index of the cells in the logical Cartesian grid.
Definition: FlowBaseVanguard.hpp:182
void updateCartesianToCompressedMapping_()
Definition: FlowBaseVanguard.hpp:350
int cartesianSize() const
Returns the overall number of cells of the logically Cartesian grid.
Definition: FlowBaseVanguard.hpp:164
int compressedIndex(int cartesianCellIdx) const
Return compressed index from cartesian index.
Definition: FlowBaseVanguard.hpp:200
void updateCellThickness_()
Definition: FlowBaseVanguard.hpp:395
std::vector< Scalar > cellCenterDepth_
Cell center depths.
Definition: FlowBaseVanguard.hpp:464
const std::array< int, dimension > & cartesianDimensions() const
Returns the number of logically Cartesian cells in each direction.
Definition: FlowBaseVanguard.hpp:158
unsigned equilCartesianIndex(unsigned compressedEquilCellIdx) const
Returns the Cartesian cell id given an element index for the grid used for equilibration.
Definition: FlowBaseVanguard.hpp:240
FlowBaseVanguard(Simulator &simulator)
Create the grid for problem data files which use the ECL file format.
Definition: FlowBaseVanguard.hpp:117
int compressedIndexForInterior(int cartesianCellIdx) const
Return compressed index from cartesian index only in interior.
Definition: FlowBaseVanguard.hpp:215
const std::vector< Scalar > & cellCenterDepths() const
Definition: FlowBaseVanguard.hpp:264
unsigned cartesianIndex(unsigned compressedCellIdx) const
Returns the Cartesian cell id for identifaction with ECL data.
Definition: FlowBaseVanguard.hpp:176
static const int dimension
Definition: FlowBaseVanguard.hpp:97
std::vector< int > is_interior_
Whether a cells is in the interior.
Definition: FlowBaseVanguard.hpp:472
void updateCellDepths_()
Definition: FlowBaseVanguard.hpp:372
void callImplementationInit()
Definition: FlowBaseVanguard.hpp:338
const CartesianIndexMapper & cartesianMapper() const
Definition: FlowBaseVanguard.hpp:152
static const int dimensionworld
Definition: FlowBaseVanguard.hpp:98
void cartesianCoordinate(unsigned cellIdx, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
Definition: FlowBaseVanguard.hpp:234
std::unordered_map< int, int > cartesianToCompressed_
Mapping between cartesian and compressed cells. It is initialized the first time it is called.
Definition: FlowBaseVanguard.hpp:460
std::vector< Scalar > cellThickness_
Cell thickness.
Definition: FlowBaseVanguard.hpp:468
Scalar cellCenterDepth(unsigned globalSpaceIdx) const
Returns the depth of a degree of freedom [m].
Definition: FlowBaseVanguard.hpp:259
std::size_t globalNumCells() const
Get the number of cells in the global leaf grid view. \warn This is a collective operation that needs...
Definition: FlowBaseVanguard.hpp:287
void equilCartesianCoordinate(unsigned cellIdx, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell of the grid used for EQUIL.
Definition: FlowBaseVanguard.hpp:249
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
Scalar cellThickness(unsigned globalSpaceIdx) const
Returns the thickness of a degree of freedom [m].
Definition: FlowBaseVanguard.hpp:276
typename GridView::template Codim< 0 >::Entity Element
Definition: FlowBaseVanguard.hpp:99
static void registerParameters()
Register the common run-time parameters for all ECL simulator vanguards.
Definition: FlowBaseVanguard.hpp:106
int equilCartesianSize() const
Returns the overall number of cells of the logically EquilCartesian grid.
Definition: FlowBaseVanguard.hpp:170
void setupCartesianToCompressed_()
Definition: FlowBaseVanguard.hpp:302
Definition: FlowGenericVanguard.hpp:99
bool enableDistributedWells_
Definition: FlowGenericVanguard.hpp:362
bool useMultisegmentWell_
Definition: FlowGenericVanguard.hpp:365
bool ownersFirst_
Definition: FlowGenericVanguard.hpp:348
std::string zoltanParams_
Definition: FlowGenericVanguard.hpp:356
std::unordered_map< std::size_t, const NumericalAquiferCell * > allAquiferCells() const
std::string ignoredKeywords_
Definition: FlowGenericVanguard.hpp:363
Dune::PartitionMethod partitionMethod_
Definition: FlowGenericVanguard.hpp:350
bool zoltanImbalanceTolSet_
Definition: FlowGenericVanguard.hpp:354
bool enableExperiments_
Definition: FlowGenericVanguard.hpp:366
bool serialPartitioning_
Definition: FlowGenericVanguard.hpp:351
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition: FlowGenericVanguard.hpp:159
bool drsdtconEnabled() const
Dune::EdgeWeightMethod edgeWeightsMethod_
Definition: FlowGenericVanguard.hpp:342
double zoltanImbalanceTol_
Definition: FlowGenericVanguard.hpp:355
double imbalanceTol_
Definition: FlowGenericVanguard.hpp:352
std::string externalPartitionFile_
Definition: FlowGenericVanguard.hpp:360
std::optional< int > outputInterval_
Definition: FlowGenericVanguard.hpp:364
std::string fileName_
Definition: FlowGenericVanguard.hpp:341
std::string metisParams_
Definition: FlowGenericVanguard.hpp:358
Declare the properties used by the infrastructure code of the finite volume discretizations.
Declare the properties used by the infrastructure code of the finite volume discretizations.
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
This file provides the infrastructure to retrieve run-time parameters.
The Opm property system, traits with inheritance.
Definition: FlowBaseVanguard.hpp:56
Definition: FlowBaseVanguard.hpp:69
Definition: FlowBaseVanguard.hpp:63
a tag to mark properties as undefined
Definition: propertysystem.hh:40