2016-01-05 12:32:36 -06:00
|
|
|
// -*- 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/>.
|
2016-03-14 07:21:47 -05:00
|
|
|
|
|
|
|
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.
|
2016-01-05 12:32:36 -06:00
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* \file
|
2019-09-05 10:04:39 -05:00
|
|
|
* \copydoc Opm::EclCpGridVanguard
|
2016-01-05 12:32:36 -06:00
|
|
|
*/
|
2018-02-01 09:26:58 -06:00
|
|
|
#ifndef EWOMS_ECL_CP_GRID_VANGUARD_HH
|
|
|
|
#define EWOMS_ECL_CP_GRID_VANGUARD_HH
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <ebos/eclbasevanguard.hh>
|
|
|
|
#include <ebos/eclgenericcpgridvanguard.hh>
|
|
|
|
#include <ebos/ecltransmissibility.hh>
|
|
|
|
#include <ebos/femcpgridcompat.hh>
|
|
|
|
|
2023-06-19 04:42:43 -05:00
|
|
|
#include <opm/common/TimingMacros.hpp>
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
#include <opm/models/common/multiphasebaseproperties.hh>
|
2023-06-30 05:54:18 -05:00
|
|
|
#include <opm/models/blackoil/blackoilproperties.hh>
|
2021-05-05 05:13:25 -05:00
|
|
|
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <array>
|
2023-09-18 03:21:31 -05:00
|
|
|
#include <filesystem>
|
|
|
|
#include <fstream>
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <functional>
|
2023-09-18 03:21:31 -05:00
|
|
|
#include <iterator>
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <memory>
|
2023-09-18 03:21:31 -05:00
|
|
|
#include <stdexcept>
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <tuple>
|
2023-10-23 08:55:51 -05:00
|
|
|
#include <unordered_map>
|
2023-08-02 04:43:39 -05:00
|
|
|
#include <vector>
|
2016-12-05 12:49:58 -06:00
|
|
|
|
2023-09-18 03:21:31 -05:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
|
|
#if HAVE_MPI
|
|
|
|
|
|
|
|
namespace Opm { namespace details {
|
|
|
|
class MPIPartitionFromFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit MPIPartitionFromFile(const std::filesystem::path& partitionFile)
|
|
|
|
: partitionFile_(partitionFile)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::vector<int> operator()(const Dune::CpGrid& grid) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::filesystem::path partitionFile_{};
|
|
|
|
};
|
|
|
|
|
|
|
|
inline std::vector<int>
|
|
|
|
MPIPartitionFromFile::operator()(const Dune::CpGrid& grid) const
|
|
|
|
{
|
|
|
|
std::ifstream pfile { this->partitionFile_ };
|
|
|
|
|
|
|
|
auto partition = std::vector<int> {
|
|
|
|
std::istream_iterator<int> { pfile },
|
|
|
|
std::istream_iterator<int> {}
|
|
|
|
};
|
|
|
|
|
2023-10-23 08:55:51 -05:00
|
|
|
const auto nc =
|
|
|
|
static_cast<std::vector<int>::size_type>(grid.size(0));
|
|
|
|
|
|
|
|
if (partition.size() == nc) {
|
|
|
|
// Input is one process ID for each active cell
|
|
|
|
return partition;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (partition.size() == 3 * nc) {
|
|
|
|
// Partition file is of the form
|
|
|
|
//
|
|
|
|
// Process_ID Cartesian_Idx NLDD_Domain
|
|
|
|
//
|
|
|
|
// with one row for each active cell. Select first column.
|
|
|
|
auto g2l = std::unordered_map<int, int>{};
|
|
|
|
auto locCell = 0;
|
|
|
|
for (const auto& globCell : grid.globalCell()) {
|
|
|
|
g2l.insert_or_assign(globCell, locCell++);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto filtered_partition = std::vector<int>(nc);
|
|
|
|
for (auto c = 0*nc; c < nc; ++c) {
|
|
|
|
auto pos = g2l.find(partition[3*c + 1]);
|
|
|
|
if (pos != g2l.end()) {
|
|
|
|
filtered_partition[pos->second] = partition[3*c + 0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filtered_partition;
|
2023-09-18 03:21:31 -05:00
|
|
|
}
|
|
|
|
|
2023-10-23 08:55:51 -05:00
|
|
|
throw std::invalid_argument {
|
|
|
|
fmt::format("Partition file '{}' with {} values does "
|
|
|
|
"not match CpGrid instance with {} cells",
|
|
|
|
this->partitionFile_.generic_string(),
|
|
|
|
partition.size(), nc)
|
|
|
|
};
|
2023-09-18 03:21:31 -05:00
|
|
|
}
|
|
|
|
}} // namespace Opm::details
|
|
|
|
|
|
|
|
#endif // HAVE_MPI
|
|
|
|
|
2019-09-05 10:04:39 -05:00
|
|
|
namespace Opm {
|
2016-01-05 12:32:36 -06:00
|
|
|
template <class TypeTag>
|
2018-02-01 09:26:58 -06:00
|
|
|
class EclCpGridVanguard;
|
2018-06-14 09:06:05 -05:00
|
|
|
}
|
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
namespace Opm::Properties {
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2020-08-27 03:30:29 -05:00
|
|
|
namespace TTag {
|
|
|
|
struct EclCpGridVanguard {
|
|
|
|
using InheritsFrom = std::tuple<EclBaseVanguard>;
|
|
|
|
};
|
|
|
|
}
|
2016-01-05 12:32:36 -06:00
|
|
|
|
|
|
|
// declare the properties
|
2020-08-27 04:38:38 -05:00
|
|
|
template<class TypeTag>
|
|
|
|
struct Vanguard<TypeTag, TTag::EclCpGridVanguard> {
|
2021-05-15 06:35:21 -05:00
|
|
|
using type = EclCpGridVanguard<TypeTag>;
|
2020-08-27 04:38:38 -05:00
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct Grid<TypeTag, TTag::EclCpGridVanguard> {
|
|
|
|
using type = Dune::CpGrid;
|
|
|
|
};
|
|
|
|
template<class TypeTag>
|
|
|
|
struct EquilGrid<TypeTag, TTag::EclCpGridVanguard> {
|
|
|
|
using type = GetPropType<TypeTag, Properties::Grid>;
|
|
|
|
};
|
2018-06-14 09:06:05 -05:00
|
|
|
|
2020-08-21 06:42:08 -05:00
|
|
|
} // namespace Opm::Properties
|
2018-06-14 09:06:05 -05:00
|
|
|
|
2019-09-05 10:04:39 -05:00
|
|
|
namespace Opm {
|
2016-01-05 12:32:36 -06:00
|
|
|
|
|
|
|
/*!
|
|
|
|
* \ingroup EclBlackOilSimulator
|
|
|
|
*
|
|
|
|
* \brief Helper class for grid instantiation of ECL file-format using problems.
|
|
|
|
*
|
|
|
|
* This class uses Dune::CpGrid as the simulation grid.
|
|
|
|
*/
|
|
|
|
template <class TypeTag>
|
2018-02-01 09:26:58 -06:00
|
|
|
class EclCpGridVanguard : public EclBaseVanguard<TypeTag>
|
2021-05-05 05:13:25 -05:00
|
|
|
, public EclGenericCpGridVanguard<GetPropType<TypeTag, Properties::ElementMapper>,
|
|
|
|
GetPropType<TypeTag, Properties::GridView>,
|
|
|
|
GetPropType<TypeTag, Properties::Scalar>>
|
2016-01-05 12:32:36 -06:00
|
|
|
{
|
2018-02-01 09:26:58 -06:00
|
|
|
friend class EclBaseVanguard<TypeTag>;
|
2022-08-10 05:31:52 -05:00
|
|
|
using ParentType = EclBaseVanguard<TypeTag>;
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2020-08-26 03:49:52 -05:00
|
|
|
using Scalar = GetPropType<TypeTag, Properties::Scalar>;
|
|
|
|
using Simulator = GetPropType<TypeTag, Properties::Simulator>;
|
|
|
|
using ElementMapper = GetPropType<TypeTag, Properties::ElementMapper>;
|
2016-01-05 12:32:36 -06:00
|
|
|
|
|
|
|
public:
|
2020-08-26 03:49:52 -05:00
|
|
|
using Grid = GetPropType<TypeTag, Properties::Grid>;
|
2021-12-01 07:00:21 -06:00
|
|
|
using CartesianIndexMapper = Dune::CartesianIndexMapper<Grid>;
|
2020-08-26 03:49:52 -05:00
|
|
|
using EquilGrid = GetPropType<TypeTag, Properties::EquilGrid>;
|
|
|
|
using GridView = GetPropType<TypeTag, Properties::GridView>;
|
2021-12-01 07:00:21 -06:00
|
|
|
using TransmissibilityType = EclTransmissibility<Grid, GridView, ElementMapper, CartesianIndexMapper, Scalar>;
|
2022-08-10 05:31:52 -05:00
|
|
|
static constexpr int dimensionworld = Grid::dimensionworld;
|
2023-09-29 06:26:31 -05:00
|
|
|
using Indices = GetPropType<TypeTag, Properties::Indices>;
|
|
|
|
static constexpr bool waterEnabled = Indices::waterEnabled;
|
|
|
|
static constexpr bool gasEnabled = Indices::gasEnabled;
|
|
|
|
static constexpr bool oilEnabled = Indices::oilEnabled;
|
2016-01-05 12:32:36 -06:00
|
|
|
private:
|
2020-09-24 14:51:59 -05:00
|
|
|
using Element = typename GridView::template Codim<0>::Entity;
|
2016-01-05 12:32:36 -06:00
|
|
|
|
|
|
|
public:
|
2019-10-01 14:18:17 -05:00
|
|
|
EclCpGridVanguard(Simulator& simulator)
|
2021-05-05 05:13:25 -05:00
|
|
|
: EclBaseVanguard<TypeTag>(simulator)
|
2019-10-01 14:18:17 -05:00
|
|
|
{
|
2023-06-30 05:54:18 -05:00
|
|
|
this->checkConsistency();
|
2019-10-01 14:18:17 -05:00
|
|
|
this->callImplementationInit();
|
|
|
|
}
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2023-06-30 05:54:18 -05:00
|
|
|
/*!
|
|
|
|
* Checking consistency of simulator
|
|
|
|
*/
|
|
|
|
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::EnableMICP>() == false) {
|
|
|
|
throw std::runtime_error("Input specifies MICP 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");
|
|
|
|
}
|
|
|
|
}
|
2023-09-29 06:26:31 -05:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-30 05:54:18 -05:00
|
|
|
}
|
|
|
|
|
2016-01-05 12:32:36 -06:00
|
|
|
/*!
|
2021-05-05 05:13:25 -05:00
|
|
|
* \brief Free the memory occupied by the global transmissibility object.
|
2016-01-05 12:32:36 -06:00
|
|
|
*
|
2021-05-05 05:13:25 -05:00
|
|
|
* After writing the initial solution, this array should not be necessary anymore.
|
2016-01-05 12:32:36 -06:00
|
|
|
*/
|
2021-05-05 05:13:25 -05:00
|
|
|
void releaseGlobalTransmissibilities()
|
2019-09-11 01:05:36 -05:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
globalTrans_.reset();
|
2019-09-11 01:05:36 -05:00
|
|
|
}
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
const TransmissibilityType& globalTransmissibility() const
|
2016-01-05 12:32:36 -06:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
assert( globalTrans_ != nullptr );
|
|
|
|
return *globalTrans_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void releaseGlobalTransmissibility()
|
|
|
|
{
|
|
|
|
globalTrans_.reset();
|
2016-01-05 12:32:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Distribute the simulation grid over multiple processes
|
|
|
|
*
|
|
|
|
* (For parallel simulation runs.)
|
|
|
|
*/
|
|
|
|
void loadBalance()
|
|
|
|
{
|
2021-05-13 15:40:39 -05:00
|
|
|
#if HAVE_MPI
|
2023-09-18 03:21:31 -05:00
|
|
|
if (const auto& extPFile = this->externalPartitionFile();
|
|
|
|
!extPFile.empty() && (extPFile != "none"))
|
|
|
|
{
|
|
|
|
this->setExternalLoadBalancer(details::MPIPartitionFromFile { extPFile });
|
|
|
|
}
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
this->doLoadBalance_(this->edgeWeightsMethod(), this->ownersFirst(),
|
|
|
|
this->serialPartitioning(), this->enableDistributedWells(),
|
2022-06-08 08:33:32 -05:00
|
|
|
this->zoltanImbalanceTol(), this->gridView(),
|
2023-08-01 07:53:39 -05:00
|
|
|
this->schedule(), this->eclState(),
|
|
|
|
this->parallelWells_, this->numJacobiBlocks());
|
2021-05-13 15:40:39 -05:00
|
|
|
#endif
|
2016-12-05 12:49:58 -06:00
|
|
|
|
2017-10-12 10:27:49 -05:00
|
|
|
this->updateGridView_();
|
2020-12-08 09:09:01 -06:00
|
|
|
this->updateCartesianToCompressedMapping_();
|
|
|
|
this->updateCellDepths_();
|
2020-09-24 14:51:59 -05:00
|
|
|
this->updateCellThickness_();
|
2020-12-08 09:09:01 -06:00
|
|
|
|
2021-05-13 15:40:39 -05:00
|
|
|
#if HAVE_MPI
|
2021-05-05 05:13:25 -05:00
|
|
|
this->distributeFieldProps_(this->eclState());
|
2021-05-13 15:40:39 -05:00
|
|
|
#endif
|
2018-07-11 06:59:29 -05:00
|
|
|
}
|
|
|
|
|
2021-12-01 07:00:21 -06:00
|
|
|
unsigned int gridEquilIdxToGridIdx(unsigned int elemIndex) const {
|
|
|
|
return elemIndex;
|
|
|
|
}
|
2023-06-30 05:54:18 -05:00
|
|
|
|
2021-12-01 07:00:21 -06:00
|
|
|
unsigned int gridIdxToEquilGridIdx(unsigned int elemIndex) const {
|
|
|
|
return elemIndex;
|
|
|
|
}
|
2021-09-30 04:50:22 -05:00
|
|
|
/*!
|
|
|
|
* \brief Get function to query cell centroids for a distributed grid.
|
|
|
|
*
|
|
|
|
* Currently this only non-empty for a loadbalanced CpGrid.
|
|
|
|
* It is a function return the centroid for the given element
|
|
|
|
* index.
|
|
|
|
*/
|
|
|
|
std::function<std::array<double,dimensionworld>(int)>
|
|
|
|
cellCentroids() const
|
|
|
|
{
|
2023-09-28 04:12:44 -05:00
|
|
|
return this->cellCentroids_(this->cartesianIndexMapper(), true);
|
2021-09-30 04:50:22 -05:00
|
|
|
}
|
2016-01-05 12:32:36 -06:00
|
|
|
|
2021-12-01 07:00:21 -06:00
|
|
|
const std::vector<int>& globalCell()
|
|
|
|
{
|
|
|
|
return this->grid().globalCell();
|
|
|
|
}
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
protected:
|
|
|
|
void createGrids_()
|
2019-09-11 01:05:36 -05:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
this->doCreateGrids_(this->eclState());
|
2019-09-11 01:05:36 -05:00
|
|
|
}
|
2016-01-17 14:15:18 -06:00
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
void allocTrans() override
|
2019-10-01 06:37:12 -05:00
|
|
|
{
|
2023-06-19 04:42:43 -05:00
|
|
|
OPM_TIMEBLOCK(allocateTrans);
|
2021-05-05 05:13:25 -05:00
|
|
|
globalTrans_.reset(new TransmissibilityType(this->eclState(),
|
|
|
|
this->gridView(),
|
|
|
|
this->cartesianIndexMapper(),
|
|
|
|
this->grid(),
|
2021-05-15 06:35:21 -05:00
|
|
|
this->cellCentroids(),
|
|
|
|
getPropValue<TypeTag, Properties::EnableEnergy>(),
|
2023-10-25 12:46:55 -05:00
|
|
|
getPropValue<TypeTag, Properties::EnableDiffusion>(),
|
|
|
|
getPropValue<TypeTag, Properties::EnableDispersion>()));
|
2021-05-05 05:13:25 -05:00
|
|
|
globalTrans_->update(false);
|
2019-10-01 06:37:12 -05:00
|
|
|
}
|
2017-01-26 08:11:03 -06:00
|
|
|
|
2022-05-31 10:47:46 -05:00
|
|
|
double getTransmissibility(unsigned I, unsigned J) const override
|
2017-01-26 08:11:03 -06:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
return globalTrans_->transmissibility(I,J);
|
2016-01-05 12:32:36 -06:00
|
|
|
}
|
|
|
|
|
2022-09-16 05:38:53 -05:00
|
|
|
#if HAVE_MPI
|
|
|
|
const std::string& zoltanParams() const override
|
|
|
|
{
|
|
|
|
return this->zoltanParams_;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-06-28 08:49:45 -05:00
|
|
|
// removing some connection located in inactive grid cells
|
|
|
|
void filterConnections_()
|
2018-02-07 04:21:57 -06:00
|
|
|
{
|
2021-05-05 05:13:25 -05:00
|
|
|
this->doFilterConnections_(this->schedule());
|
2020-09-24 14:51:59 -05:00
|
|
|
}
|
|
|
|
|
2021-05-05 05:13:25 -05:00
|
|
|
std::unique_ptr<TransmissibilityType> globalTrans_;
|
2016-01-05 12:32:36 -06:00
|
|
|
};
|
|
|
|
|
2019-09-05 10:04:39 -05:00
|
|
|
} // namespace Opm
|
2016-01-05 12:32:36 -06:00
|
|
|
|
|
|
|
#endif
|