27#ifndef OPM_FLOW_BASE_VANGUARD_HPP
28#define OPM_FLOW_BASE_VANGUARD_HPP
30#include <opm/grid/common/GridEnums.hpp>
31#include <opm/grid/common/CartesianIndexMapper.hpp>
32#include <opm/grid/LookUpCellCentroid.hh>
34#include <opm/input/eclipse/EclipseState/Aquifer/NumericalAquifer/NumericalAquiferCell.hpp>
35#include <opm/input/eclipse/EclipseState/EclipseState.hpp>
37#include <opm/models/discretization/common/fvbaseproperties.hh>
38#include <opm/models/io/basevanguard.hh>
39#include <opm/models/utils/parametersystem.hh>
40#include <opm/models/utils/propertysystem.hh>
47#include <unordered_map>
51template <
class TypeTag>
52class FlowBaseVanguard;
63template<
class TypeTag,
class MyTypeTag>
65 using type = UndefinedProperty;
67template<
class TypeTag,
class MyTypeTag>
69 using type = UndefinedProperty;
71template<
class TypeTag,
class MyTypeTag>
73 using type = UndefinedProperty;
75template<
class TypeTag,
class MyTypeTag>
77 using type = UndefinedProperty;
79template<
class TypeTag,
class MyTypeTag>
81 using type = UndefinedProperty;
83template<
class TypeTag,
class MyTypeTag>
85 using type = UndefinedProperty;
87template<
class TypeTag,
class MyTypeTag>
89 using type = UndefinedProperty;
92#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
93template<
class TypeTag,
class MyTypeTag>
94struct NumJacobiBlocks {
95 using type = UndefinedProperty;
99template<
class TypeTag,
class MyTypeTag>
101 using type = UndefinedProperty;
104template<
class TypeTag,
class MyTypeTag>
106 using type = UndefinedProperty;
109template<
class TypeTag,
class MyTypeTag>
111 using type = UndefinedProperty;
114template<
class TypeTag,
class MyTypeTag>
116 using type = UndefinedProperty;
119template <
class TypeTag,
class MyTypeTag>
122 using type = UndefinedProperty;
125template<
class TypeTag,
class MyTypeTag>
127 using type = UndefinedProperty;
130template<
class TypeTag>
132 static constexpr auto value =
"";
134template<
class TypeTag>
136 static constexpr auto value =
"";
138template<
class TypeTag>
140 static constexpr int value = -1;
142template<
class TypeTag>
144 static constexpr bool value =
false;
146template<
class TypeTag>
148 static constexpr auto value =
"normal";
150template<
class TypeTag>
152 static constexpr bool value =
false;
154template<
class TypeTag>
156 static constexpr int value = 1;
159#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
160template<
class TypeTag>
162 static constexpr int value = 0;
166template<
class TypeTag>
168 static constexpr bool value =
true;
170template<
class TypeTag>
172 static constexpr bool value =
false;
175template<
class TypeTag>
177 static constexpr double value = 1.1;
180template<
class TypeTag>
182 static constexpr auto value =
"graph";
185template <
class TypeTag>
188 static constexpr auto* value =
"";
191template<
class TypeTag>
193 static constexpr bool value =
false;
196template<
class T1,
class T2>
200template<
class TypeTag>
202 static constexpr bool value =
true;
213template <
class TypeTag>
217 using ParentType = BaseVanguard<TypeTag>;
218 using Implementation = GetPropType<TypeTag, Properties::Vanguard>;
219 using Scalar = GetPropType<TypeTag, Properties::Scalar>;
220 using Simulator = GetPropType<TypeTag, Properties::Simulator>;
221 using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
223 enum { enableExperiments = getPropValue<TypeTag, Properties::EnableExperiments>() };
226 using Grid = GetPropType<TypeTag, Properties::Grid>;
227 using GridView = GetPropType<TypeTag, Properties::GridView>;
232 using Element =
typename GridView::template Codim<0>::Entity;
241 Parameters::registerParam<TypeTag, Properties::EclDeckFileName>
242 (
"The name of the file which contains the ECL deck to be simulated");
243 Parameters::registerParam<TypeTag, Properties::EclOutputInterval>
244 (
"The number of report steps that ought to be skipped between two writes of ECL results");
245 Parameters::registerParam<TypeTag, Properties::EnableOpmRstFile>
246 (
"Include OPM-specific keywords in the ECL restart file to "
247 "enable restart of OPM simulators from these files");
248 Parameters::registerParam<TypeTag, Properties::IgnoreKeywords>
249 (
"List of Eclipse keywords which should be ignored. As a ':' separated string.");
250 Parameters::registerParam<TypeTag, Properties::ParsingStrictness>
251 (
"Set strictness of parsing process. Available options are "
252 "normal (stop for critical errors), "
253 "high (stop for all errors) and "
254 "low (as normal, except do not stop due to unsupported "
255 "keywords even if marked critical");
256 Parameters::registerParam<TypeTag, Properties::SchedRestart>
257 (
"When restarting: should we try to initialize wells and "
258 "groups from historical SCHEDULE section.");
259 Parameters::registerParam<TypeTag, Properties::EdgeWeightsMethod>
260 (
"Choose edge-weighing strategy: 0=uniform, 1=trans, 2=log(trans).");
262#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
263 Parameters::registerParam<TypeTag, Properties::NumJacobiBlocks>
264 (
"Number of blocks to be created for the Block-Jacobi preconditioner.");
267 Parameters::registerParam<TypeTag, Properties::OwnerCellsFirst>
268 (
"Order cells owned by rank before ghost/overlap cells.");
270 Parameters::registerParam<TypeTag, Properties::SerialPartitioning>
271 (
"Perform partitioning for parallel runs on a single process.");
272 Parameters::registerParam<TypeTag, Properties::ZoltanImbalanceTol>
273 (
"Tolerable imbalance of the loadbalancing provided by Zoltan (default: 1.1).");
274 Parameters::registerParam<TypeTag, Properties::ZoltanParams>
275 (
"Configuration of Zoltan partitioner. "
276 "Valid options are: graph, hypergraph or scotch. "
277 "Alternatively, you can request a configuration to be read "
278 "from a JSON file by giving the filename here, ending with '.json.' "
279 "See https://sandialabs.github.io/Zoltan/ug_html/ug.html "
280 "for available Zoltan options.");
281 Parameters::hideParam<TypeTag, Properties::ZoltanParams>();
282 Parameters::registerParam<TypeTag, Properties::ExternalPartition>
283 (
"Name of file from which to load an externally generated "
284 "partitioning of the model's active cells for MPI "
285 "distribution purposes. If empty, the built-in partitioning "
286 "method will be employed.");
287 Parameters::hideParam<TypeTag, Properties::ExternalPartition>();
289 Parameters::registerParam<TypeTag, Properties::AllowDistributedWells>
290 (
"Allow the perforations of a well to be distributed to interior of multiple processes");
292 Parameters::registerParam<TypeTag, Properties::UseMultisegmentWell>
293 (
"Use the well model for multi-segment wells instead of the one for single-segment wells");
303 : ParentType(simulator)
305 fileName_ = Parameters::get<TypeTag, Properties::EclDeckFileName>();
306 edgeWeightsMethod_ = Dune::EdgeWeightMethod(Parameters::get<TypeTag, Properties::EdgeWeightsMethod>());
308#if HAVE_OPENCL || HAVE_ROCSPARSE || HAVE_CUDA
309 numJacobiBlocks_ = Parameters::get<TypeTag, Properties::NumJacobiBlocks>();
312 ownersFirst_ = Parameters::get<TypeTag, Properties::OwnerCellsFirst>();
316 zoltanParams_ = Parameters::get<TypeTag, Properties::ZoltanParams>();
321 int output_param = Parameters::get<TypeTag, Properties::EclOutputInterval>();
322 if (output_param >= 0)
331 {
return asImp_().cartesianIndexMapper(); }
337 {
return asImp_().cartesianIndexMapper().cartesianDimensions(); }
343 {
return asImp_().cartesianIndexMapper().cartesianSize(); }
349 {
return asImp_().equilCartesianIndexMapper().cartesianSize(); }
355 {
return asImp_().cartesianIndexMapper().cartesianIndex(compressedCellIdx); }
362 unsigned cartIndex = coords[0];
364 for (
unsigned i = 1; i <
dimension; ++i) {
365 cartIndex += coords[i]*factor;
382 return index_pair->second;
403 return index_pair->second;
413 {
return asImp_().cartesianIndexMapper().cartesianCoordinate(cellIdx, ijk); }
419 {
return asImp_().equilCartesianIndexMapper().cartesianIndex(compressedEquilCellIdx); }
428 {
return asImp_().equilCartesianIndexMapper().cartesianCoordinate(cellIdx, ijk); }
467 const auto& grid = asImp_().grid();
468 if (grid.comm().size() == 1)
470 return grid.leafGridView().size(0);
472 const auto& gridView = grid.leafGridView();
473 constexpr int codim = 0;
474 constexpr auto Part = Dune::Interior_Partition;
475 auto local_cells = std::distance(gridView.template begin<codim, Part>(),
476 gridView.template end<codim, Part>());
477 return grid.comm().sum(local_cells);
494 template<
class CartMapper>
495 std::function<std::array<double,dimensionworld>(
int)>
498 return [
this, cartMapper, isCpGrid](
int elemIdx) {
499 std::array<double,dimensionworld> centroid;
500 const auto rank = this->gridView().comm().rank();
501 const auto maxLevel = this->gridView().grid().maxLevel();
502 bool useEclipse = !isCpGrid || (isCpGrid && (rank == 0) && (maxLevel == 0));
505 centroid = this->
eclState().getInputGrid().getCellCenter(cartMapper.cartesianIndex(elemIdx));
510 centroid = lookUpCellCentroid(elemIdx);
518 asImp_().createGrids_();
519 asImp_().filterConnections_();
520 std::string outputDir = Parameters::get<TypeTag, Properties::OutputDir>();
521 bool enableEclCompatFile = !Parameters::get<TypeTag, Properties::EnableOpmRstFile>();
522 asImp_().updateOutputDir_(outputDir, enableEclCompatFile);
523 asImp_().finalizeInit_();
528 std::size_t num_cells = asImp_().grid().leafGridView().size(0);
531 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
532 for (
const auto& element : elements(this->gridView()))
534 const auto elemIdx = elemMapper.index(element);
537 if (element.partitionType() == Dune::InteriorEntity)
550 int numCells = this->gridView().size(0);
553 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
557 for(
const auto& element : elements(this->gridView())) {
558 const unsigned int elemIdx = elemMapper.index(element);
561 if (!num_aqu_cells.empty()) {
563 const auto search = num_aqu_cells.find(global_index);
564 if (search != num_aqu_cells.end()) {
576 ElementMapper elemMapper(this->gridView(), Dune::mcmgElementLayout());
578 int numElements = this->gridView().size(0);
581 for (
const auto& elem : elements(this->gridView())) {
582 const unsigned int elemIdx = elemMapper.index(elem);
591 typedef typename Element::Geometry Geometry;
592 static constexpr int zCoord = Element::dimension - 1;
595 const Geometry& geometry = element.geometry();
596 const int corners = geometry.corners();
597 for (
int i=0; i < corners; ++i)
598 zz += geometry.corner(i)[zCoord];
600 return zz/Scalar(corners);
603 Scalar computeCellThickness(
const typename GridView::template Codim<0>::Entity& element)
const
605 typedef typename Element::Geometry Geometry;
606 static constexpr int zCoord = Element::dimension - 1;
610 const Geometry& geometry = element.geometry();
616 assert(geometry.corners() == 8);
617 for (
int i=0; i < 4; ++i){
618 zz1 += geometry.corner(i)[zCoord];
619 zz2 += geometry.corner(i+4)[zCoord];
626 Implementation& asImp_()
627 {
return *
static_cast<Implementation*
>(
this); }
629 const Implementation& asImp_()
const
630 {
return *
static_cast<const Implementation*
>(
this); }
Definition: CollectDataOnIORank.hpp:49
Helper class for grid instantiation of ECL file-format using problems.
Definition: FlowBaseVanguard.hpp:216
unsigned cartesianIndex(const std::array< int, dimension > &coords) const
Return the index of the cells in the logical Cartesian grid.
Definition: FlowBaseVanguard.hpp:360
void updateCartesianToCompressedMapping_()
Definition: FlowBaseVanguard.hpp:526
int cartesianSize() const
Returns the overall number of cells of the logically Cartesian grid.
Definition: FlowBaseVanguard.hpp:342
int compressedIndex(int cartesianCellIdx) const
Return compressed index from cartesian index.
Definition: FlowBaseVanguard.hpp:378
void updateCellThickness_()
Definition: FlowBaseVanguard.hpp:571
std::vector< Scalar > cellCenterDepth_
Cell center depths.
Definition: FlowBaseVanguard.hpp:640
const std::array< int, dimension > & cartesianDimensions() const
Returns the number of logically Cartesian cells in each direction.
Definition: FlowBaseVanguard.hpp:336
unsigned equilCartesianIndex(unsigned compressedEquilCellIdx) const
Returns the Cartesian cell id given an element index for the grid used for equilibration.
Definition: FlowBaseVanguard.hpp:418
FlowBaseVanguard(Simulator &simulator)
Create the grid for problem data files which use the ECL file format.
Definition: FlowBaseVanguard.hpp:302
int compressedIndexForInterior(int cartesianCellIdx) const
Return compressed index from cartesian index only in interior.
Definition: FlowBaseVanguard.hpp:393
const std::vector< Scalar > & cellCenterDepths() const
Definition: FlowBaseVanguard.hpp:442
unsigned cartesianIndex(unsigned compressedCellIdx) const
Returns the Cartesian cell id for identifaction with ECL data.
Definition: FlowBaseVanguard.hpp:354
static const int dimension
Definition: FlowBaseVanguard.hpp:230
std::vector< int > is_interior_
Whether a cells is in the interior.
Definition: FlowBaseVanguard.hpp:648
void updateCellDepths_()
Definition: FlowBaseVanguard.hpp:548
void callImplementationInit()
Definition: FlowBaseVanguard.hpp:516
const CartesianIndexMapper & cartesianMapper() const
Definition: FlowBaseVanguard.hpp:330
static const int dimensionworld
Definition: FlowBaseVanguard.hpp:231
void cartesianCoordinate(unsigned cellIdx, std::array< int, 3 > &ijk) const
Extract Cartesian index triplet (i,j,k) of an active cell.
Definition: FlowBaseVanguard.hpp:412
std::unordered_map< int, int > cartesianToCompressed_
Mapping between cartesian and compressed cells. It is initialized the first time it is called.
Definition: FlowBaseVanguard.hpp:636
std::vector< Scalar > cellThickness_
Cell thickness.
Definition: FlowBaseVanguard.hpp:644
GetPropType< TypeTag, Properties::GridView > GridView
Definition: FlowBaseVanguard.hpp:227
GetPropType< TypeTag, Properties::Grid > Grid
Definition: FlowBaseVanguard.hpp:226
Scalar cellCenterDepth(unsigned globalSpaceIdx) const
Returns the depth of a degree of freedom [m].
Definition: FlowBaseVanguard.hpp:437
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:465
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:427
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
Scalar cellThickness(unsigned globalSpaceIdx) const
Returns the thickness of a degree of freedom [m].
Definition: FlowBaseVanguard.hpp:454
typename GridView::template Codim< 0 >::Entity Element
Definition: FlowBaseVanguard.hpp:232
static void registerParameters()
Register the common run-time parameters for all ECL simulator vanguards.
Definition: FlowBaseVanguard.hpp:239
int equilCartesianSize() const
Returns the overall number of cells of the logically EquilCartesian grid.
Definition: FlowBaseVanguard.hpp:348
void setupCartesianToCompressed_()
Definition: FlowBaseVanguard.hpp:480
Definition: FlowGenericVanguard.hpp:60
bool enableDistributedWells_
Definition: FlowGenericVanguard.hpp:299
bool useMultisegmentWell_
Definition: FlowGenericVanguard.hpp:302
bool ownersFirst_
Definition: FlowGenericVanguard.hpp:292
std::string zoltanParams_
Definition: FlowGenericVanguard.hpp:296
std::unordered_map< std::size_t, const NumericalAquiferCell * > allAquiferCells() const
std::string ignoredKeywords_
Definition: FlowGenericVanguard.hpp:300
bool enableExperiments_
Definition: FlowGenericVanguard.hpp:303
bool serialPartitioning_
Definition: FlowGenericVanguard.hpp:294
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition: FlowGenericVanguard.hpp:120
bool drsdtconEnabled() const
Dune::EdgeWeightMethod edgeWeightsMethod_
Definition: FlowGenericVanguard.hpp:286
double zoltanImbalanceTol_
Definition: FlowGenericVanguard.hpp:295
std::string externalPartitionFile_
Definition: FlowGenericVanguard.hpp:297
std::optional< int > outputInterval_
Definition: FlowGenericVanguard.hpp:301
std::string fileName_
Definition: FlowGenericVanguard.hpp:285
Definition: AluGridVanguard.hpp:57
Definition: BlackoilPhases.hpp:27
Definition: FlowBaseVanguard.hpp:53
Definition: FlowBaseVanguard.hpp:126
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:127
Definition: BlackoilModelParameters.hpp:41
Definition: FlowBaseVanguard.hpp:80
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:81
Definition: FlowBaseVanguard.hpp:88
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:89
Definition: FlowBaseVanguard.hpp:68
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:69
Definition: FlowBaseVanguard.hpp:64
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:65
Definition: FlowBaseVanguard.hpp:121
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:122
Definition: FlowBaseVanguard.hpp:84
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:85
Definition: FlowBaseVanguard.hpp:100
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:101
Definition: FlowBaseVanguard.hpp:72
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:73
Definition: FlowBaseVanguard.hpp:76
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:77
Definition: FlowBaseVanguard.hpp:105
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:106
Definition: FlowBaseVanguard.hpp:59
Definition: BlackoilModelParameters.hpp:89
Definition: FlowBaseVanguard.hpp:110
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:111
Definition: FlowBaseVanguard.hpp:115
UndefinedProperty type
Definition: FlowBaseVanguard.hpp:116