Loading...
Searching...
No Matches
CpGridVanguard.hpp
Go to the documentation of this file.
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
// vi: set et ts=4 sw=4 sts=4:
/*
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
Consult the COPYING file in the top-level source directory of this
module for the precise wording of the license and the list of
copyright holders.
*/
#ifndef OPM_CPGRID_VANGUARD_HPP
#define OPM_CPGRID_VANGUARD_HPP
#include <opm/common/TimingMacros.hpp>
#include <opm/models/common/multiphasebaseproperties.hh>
#include <opm/models/blackoil/blackoilproperties.hh>
#include <opm/simulators/flow/FemCpGridCompat.hpp>
#include <opm/simulators/flow/FlowBaseVanguard.hpp>
#include <opm/simulators/flow/GenericCpGridVanguard.hpp>
#include <opm/simulators/flow/Transmissibility.hpp>
#include <array>
#include <functional>
#include <memory>
#include <stdexcept>
#include <tuple>
#include <vector>
namespace Opm {
template <class TypeTag>
class CpGridVanguard;
}
namespace Opm::Properties {
namespace TTag {
struct CpGridVanguard {
using InheritsFrom = std::tuple<FlowBaseVanguard>;
};
}
// declare the properties
template<class TypeTag>
struct Vanguard<TypeTag, TTag::CpGridVanguard> {
using type = CpGridVanguard<TypeTag>;
};
template<class TypeTag>
struct Grid<TypeTag, TTag::CpGridVanguard> {
using type = Dune::CpGrid;
};
template<class TypeTag>
struct EquilGrid<TypeTag, TTag::CpGridVanguard> {
using type = GetPropType<TypeTag, Properties::Grid>;
};
} // namespace Opm::Properties
namespace Opm {
template <class TypeTag>
class CpGridVanguard : public FlowBaseVanguard<TypeTag>
, public GenericCpGridVanguard<GetPropType<TypeTag, Properties::ElementMapper>,
GetPropType<TypeTag, Properties::GridView>,
GetPropType<TypeTag, Properties::Scalar>>
{
friend class FlowBaseVanguard<TypeTag>;
using ParentType = FlowBaseVanguard<TypeTag>;
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
public:
using Grid = GetPropType<TypeTag, Properties::Grid>;
using CartesianIndexMapper = Dune::CartesianIndexMapper<Grid>;
using EquilGrid = GetPropType<TypeTag, Properties::EquilGrid>;
using GridView = GetPropType<TypeTag, Properties::GridView>;
using TransmissibilityType = Transmissibility<Grid, GridView, ElementMapper, CartesianIndexMapper, Scalar>;
static constexpr int dimensionworld = Grid::dimensionworld;
using Indices = GetPropType<TypeTag, Properties::Indices>;
static constexpr bool waterEnabled = Indices::waterEnabled;
static constexpr bool gasEnabled = Indices::gasEnabled;
static constexpr bool oilEnabled = Indices::oilEnabled;
private:
using Element = typename GridView::template Codim<0>::Entity;
public:
explicit CpGridVanguard(Simulator& simulator)
: FlowBaseVanguard<TypeTag>(simulator)
{
this->checkConsistency();
this->callImplementationInit();
}
int compressedIndexForInteriorLGR(const std::string& lgr_tag, const Connection& conn) const override
{
const std::array<int,3> lgr_ijk = {conn.getI(), conn.getJ(), conn.getK()};
const auto& lgr_level = this->grid().getLgrNameToLevel().at(lgr_tag);
if (ParentType::lgrMappers_.has_value() == false) {
ParentType::lgrMappers_.emplace(this->grid().mapLocalCartesianIndexSetsToLeafIndexSet());
}
const auto& lgr_dim = this->grid().currentData()[lgr_level]->logicalCartesianSize();
const auto lgr_cartesian_index = (lgr_ijk[2]*lgr_dim[0]*lgr_dim[1]) + (lgr_ijk[1]*lgr_dim[0]) + (lgr_ijk[0]);
return ParentType::lgrMappers_.value()[lgr_level].at(lgr_cartesian_index);
}
void checkConsistency()
{
const auto& runspec = this->eclState().runspec();
const auto& config = this->eclState().getSimulationConfig();
const auto& phases = runspec.phases();
// check for correct module setup
if (config.isThermal()) {
if (getPropValue<TypeTag, Properties::EnableEnergy>() == false) {
throw std::runtime_error("Input specifies energy while simulator has disabled it, try xxx_energy");
}
} else {
if (getPropValue<TypeTag, Properties::EnableEnergy>() == true) {
throw std::runtime_error("Input specifies no energy while simulator has energy, try run without _energy");
}
}
if (config.isDiffusive()) {
if (getPropValue<TypeTag, Properties::EnableDiffusion>() == false) {
throw std::runtime_error("Input specifies diffusion while simulator has disabled it, try xxx_diffusion");
}
}
if (runspec.micp()) {
if (getPropValue<TypeTag, Properties::EnableBioeffects>() == false) {
throw std::runtime_error("Input specifies MICP while simulator has it disabled");
}
}
if (runspec.biof()) {
if (getPropValue<TypeTag, Properties::EnableBioeffects>() == false) {
throw std::runtime_error("Input specifies Biofilm while simulator has it disabled");
}
}
if (phases.active(Phase::BRINE)) {
if (getPropValue<TypeTag, Properties::EnableBrine>() == false) {
throw std::runtime_error("Input specifies Brine while simulator has it disabled");
}
}
if (phases.active(Phase::POLYMER)) {
if (getPropValue<TypeTag, Properties::EnablePolymer>() == false) {
throw std::runtime_error("Input specifies Polymer while simulator has it disabled");
}
}
// checking for correct phases is more difficult TODO!
if (phases.active(Phase::ZFRACTION)) {
if (getPropValue<TypeTag, Properties::EnableExtbo>() == false) {
throw std::runtime_error("Input specifies ExBo while simulator has it disabled");
}
}
if (phases.active(Phase::FOAM)) {
if (getPropValue<TypeTag, Properties::EnableFoam>() == false) {
throw std::runtime_error("Input specifies Foam while simulator has it disabled");
}
}
if (phases.active(Phase::SOLVENT)) {
if (getPropValue<TypeTag, Properties::EnableSolvent>() == false) {
throw std::runtime_error("Input specifies Solvent while simulator has it disabled");
}
}
if(phases.active(Phase::WATER)){
if(waterEnabled == false){
throw std::runtime_error("Input specifies water while simulator has it disabled");
}
}
if(phases.active(Phase::GAS)){
if(gasEnabled == false){
throw std::runtime_error("Input specifies gas while simulator has it disabled");
}
}
if(phases.active(Phase::OIL)){
if(oilEnabled == false){
throw std::runtime_error("Input specifies oil while simulator has it disabled");
}
}
}
void releaseGlobalTransmissibilities()
{
globalTrans_.reset();
}
const TransmissibilityType& globalTransmissibility() const
{
assert( globalTrans_ != nullptr );
return *globalTrans_;
}
void loadBalance()
{
#if HAVE_MPI
if (const auto& extPFile = this->externalPartitionFile();
!extPFile.empty() && (extPFile != "none"))
{
this->setExternalLoadBalancer(details::MPIPartitionFromFile { extPFile });
}
this->doLoadBalance_(this->edgeWeightsMethod(), this->ownersFirst(),
this->addCorners(), this->numOverlap(),
this->partitionMethod(), this->serialPartitioning(),
this->enableDistributedWells(),
this->allow_splitting_inactive_wells_,
this->imbalanceTol(),
this->gridView(), this->schedule(),
this->eclState(), this->parallelWells_,
this->numJacobiBlocks(), this->enableEclOutput());
#endif
this->updateGridView_();
this->updateCartesianToCompressedMapping_();
this->updateCellDepths_();
this->updateCellThickness_();
#if HAVE_MPI
this->distributeFieldProps_(this->eclState());
#endif
}
void addLgrs()
{
// Check if input file contains Lgrs. Add them, if any.
// In a parallel run, this adds the LGRs on the distributed simulation grid.
if (const auto& lgrs = this->eclState().getLgrs(); lgrs.size() > 0) {
OpmLog::info("\nAdding LGRs to the grid and updating its leaf grid view");
this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_);
this->updateGridView_();
this->updateCellDepths_();
this->updateCellThickness_();
if (this->grid_->comm().size()>1) {
// Add LGRs and update the leaf grid view in the global (undistributed) simulation grid.
// Purpose: To enable synchronization of cell ids in 'serial mode',
// we rely on the "parent-to-children" cell id mapping.
OpmLog::info("\nAdding LGRs to the global view and updating its leaf grid view");
this->grid_->switchToGlobalView();
this->addLgrsUpdateLeafView(lgrs, lgrs.size(), *this->grid_);
this->grid_->switchToDistributedView();
this->grid_->syncDistributedGlobalCellIds();
}
}
}
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
return elemIndex;
}
unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
return elemIndex;
}
std::function<std::array<double,dimensionworld>(int)>
cellCentroids() const
{
return this->cellCentroids_(this->cartesianIndexMapper(), true);
}
const std::vector<int>& globalCell()
{
return this->grid().globalCell();
}
protected:
void createGrids_()
{
this->doCreateGrids_(this->edgeConformal(), this->eclState());
}
void allocTrans() override
{
OPM_TIMEBLOCK(allocateTrans);
globalTrans_.reset(new TransmissibilityType(this->eclState(),
this->gridView(),
this->cartesianIndexMapper(),
this->grid(),
this->cellCentroids(),
getPropValue<TypeTag, Properties::EnableEnergy>(),
getPropValue<TypeTag, Properties::EnableDiffusion>(),
getPropValue<TypeTag, Properties::EnableDispersion>()));
globalTrans_->update(false, TransmissibilityType::TransUpdateQuantities::Trans);
}
double getTransmissibility(unsigned I, unsigned J) const override
{
return globalTrans_->transmissibility(I,J);
}
#if HAVE_MPI
const std::string& zoltanParams() const override
{
return this->zoltanParams_;
}
double zoltanPhgEdgeSizeThreshold() const override
{
return this->zoltanPhgEdgeSizeThreshold_;
}
const std::string& metisParams() const override
{
return this->metisParams_;
}
#endif
// removing some connection located in inactive grid cells
void filterConnections_()
{
this->doFilterConnections_(this->schedule());
}
// \Note: this globalTrans_ is used for domain decomposition and INIT file output.
// It only contains trans_ due to permeability and does not contain thermalHalfTrans_,
// diffusivity_ abd dispersivity_. The main reason is to reduce the memory usage for rank 0
// during parallel running.
std::unique_ptr<TransmissibilityType> globalTrans_;
};
} // namespace Opm
#endif // OPM_CPGRID_VANGUARD_HPP
FemCpGridCompat.hpp
This file ensures that flow can be compiled in the presence of dune-fem.
FlowBaseVanguard.hpp
Helper class for grid instantiation of ECL file-format using problems.
GenericCpGridVanguard.hpp
Helper class for grid instantiation of ECL file-format using problems.
Transmissibility.hpp
blackoilproperties.hh
Declares the properties required by the black oil model.
Dune::CartesianIndexMapper
Definition CollectDataOnIORank.hpp:49
Opm::BaseVanguard::gridView
const GridView & gridView() const
Returns a reference to the grid view to be used.
Definition basevanguard.hh:70
Opm::CpGridVanguard
Helper class for grid instantiation of ECL file-format using problems.
Definition CpGridVanguard.hpp:90
Opm::CpGridVanguard::releaseGlobalTransmissibilities
void releaseGlobalTransmissibilities()
Free the memory occupied by the global transmissibility object.
Definition CpGridVanguard.hpp:221
Opm::CpGridVanguard::addLgrs
void addLgrs()
Add LGRs and update Leaf Grid View in the simulation grid.
Definition CpGridVanguard.hpp:270
Opm::CpGridVanguard::checkConsistency
void checkConsistency()
Checking consistency of simulator.
Definition CpGridVanguard.hpp:134
Opm::CpGridVanguard::cellCentroids
std::function< std::array< double, dimensionworld >(int)> cellCentroids() const
Get function to query cell centroids for a distributed grid.
Definition CpGridVanguard.hpp:310
Opm::CpGridVanguard::loadBalance
void loadBalance()
Distribute the simulation grid over multiple processes.
Definition CpGridVanguard.hpp:237
Opm::FlowBaseVanguard::FlowBaseVanguard
FlowBaseVanguard(Simulator &simulator)
Create the grid for problem data files which use the ECL file format.
Definition FlowBaseVanguard.hpp:118
Opm::FlowBaseVanguard::lgrMappers_
std::optional< std::vector< std::unordered_map< std::size_t, std::size_t > > > lgrMappers_
Mapping between LGR cartesian and compressed cells.
Definition FlowBaseVanguard.hpp:448
Opm::FlowBaseVanguard::cellCentroids_
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:302
Opm::FlowGenericVanguard::numJacobiBlocks
int numJacobiBlocks() const
Number of blocks in the Block-Jacobi preconditioner.
Definition FlowGenericVanguard.hpp:248
Opm::FlowGenericVanguard::schedule
const Schedule & schedule() const
Return a reference to the object that managages the ECL schedule.
Definition FlowGenericVanguard.hpp:177
Opm::FlowGenericVanguard::parallelWells_
ParallelWellStruct parallelWells_
Information about wells in parallel.
Definition FlowGenericVanguard.hpp:431
Opm::FlowGenericVanguard::enableDistributedWells
bool enableDistributedWells() const
Whether perforations of a well might be distributed.
Definition FlowGenericVanguard.hpp:311
Opm::FlowGenericVanguard::eclState
const EclipseState & eclState() const
Return a reference to the internalized ECL deck.
Definition FlowGenericVanguard.hpp:168
Opm::FlowGenericVanguard::enableEclOutput
bool enableEclOutput() const
Whether or not to emit result files that are compatible with a commercial reservoir simulator.
Definition FlowGenericVanguard.hpp:318
Opm::FlowGenericVanguard::ownersFirst
bool ownersFirst() const
Parameter that decide if cells owned by rank are ordered before ghost cells.
Definition FlowGenericVanguard.hpp:260
Opm::FlowGenericVanguard::edgeWeightsMethod
Dune::EdgeWeightMethod edgeWeightsMethod() const
Parameter deciding the edge-weight strategy of the load balancer.
Definition FlowGenericVanguard.hpp:242
Opm::GenericCpGridVanguard< GetPropType< TypeTag, Properties::ElementMapper >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::Scalar > >::cartesianIndexMapper
const CartesianIndexMapper & cartesianIndexMapper() const
Definition GenericCpGridVanguard.cpp:644
Opm::GenericCpGridVanguard< GetPropType< TypeTag, Properties::ElementMapper >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::Scalar > >::setExternalLoadBalancer
static void setExternalLoadBalancer(const std::function< std::vector< int >(const Dune::CpGrid &)> &loadBalancer)
Definition GenericCpGridVanguard.hpp:125
Opm::GenericCpGridVanguard< GetPropType< TypeTag, Properties::ElementMapper >, GetPropType< TypeTag, Properties::GridView >, GetPropType< TypeTag, Properties::Scalar > >::grid
Dune::CpGrid & grid()
Definition GenericCpGridVanguard.hpp:93
Opm::Transmissibility
Definition Transmissibility.hpp:54
multiphasebaseproperties.hh
Defines the common properties required by the porous medium multi-phase models.
Opm::Properties::TTag
The generic type tag for problems using the immiscible multi-phase model.
Definition blackoilmodel.hh:81
Opm
This file contains a set of helper functions used by VFPProd / VFPInj.
Definition blackoilbioeffectsmodules.hh:43
Opm::GetPropType
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:233
Opm::getPropValue
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
Opm::Properties::EquilGrid
Definition FlowBaseVanguard.hpp:70
Opm::Properties::Grid
The type of the DUNE grid.
Definition basicproperties.hh:100
Opm::Properties::TTag::CpGridVanguard
Definition CpGridVanguard.hpp:55
Opm::Properties::Vanguard
Property which provides a Vanguard (manages grids).
Definition basicproperties.hh:96