2015-06-18 06:43:59 -05:00
|
|
|
// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
// vi: set et ts=4 sw=4 sts=4:
|
2014-12-27 08:19:15 -06:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Andreas Lauser
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
/*!
|
|
|
|
* \file
|
|
|
|
*
|
|
|
|
* \copydoc Ewoms::EclTransmissibility
|
|
|
|
*/
|
|
|
|
#ifndef EWOMS_ECL_TRANSMISSIBILITY_HH
|
|
|
|
#define EWOMS_ECL_TRANSMISSIBILITY_HH
|
|
|
|
|
2016-01-17 14:15:27 -06:00
|
|
|
#include <ewoms/common/propertysystem.hh>
|
|
|
|
|
|
|
|
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
2016-01-21 06:24:24 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/GridProperties.hpp>
|
2016-01-29 12:21:32 -06:00
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/FaceDir.hpp>
|
|
|
|
#include <opm/parser/eclipse/EclipseState/Grid/TransMult.hpp>
|
2016-01-17 14:15:27 -06:00
|
|
|
|
2014-12-27 08:19:15 -06:00
|
|
|
#include <dune/common/version.hh>
|
|
|
|
#include <dune/common/fvector.hh>
|
|
|
|
#include <dune/common/fmatrix.hh>
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <vector>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
namespace Ewoms {
|
2016-01-17 14:15:27 -06:00
|
|
|
namespace Properties {
|
|
|
|
NEW_PROP_TAG(GridView);
|
|
|
|
NEW_PROP_TAG(Scalar);
|
|
|
|
NEW_PROP_TAG(Simulator);
|
|
|
|
}
|
|
|
|
|
2014-12-27 08:19:15 -06:00
|
|
|
/*!
|
|
|
|
* \ingroup EclBlackOilSimulator
|
|
|
|
*
|
|
|
|
* \brief This class calculates the transmissibilites for grid faces according to the
|
|
|
|
* Eclipse Technical Description.
|
|
|
|
*/
|
|
|
|
template <class TypeTag>
|
|
|
|
class EclTransmissibility
|
|
|
|
{
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, GridView) GridView;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
|
|
|
|
typedef typename GET_PROP_TYPE(TypeTag, Simulator) Simulator;
|
|
|
|
typedef typename GridView::Intersection Intersection;
|
|
|
|
|
|
|
|
// Grid and world dimension
|
|
|
|
enum { dimWorld = GridView::dimensionworld };
|
|
|
|
|
|
|
|
typedef Dune::FieldMatrix<Scalar, dimWorld, dimWorld> DimMatrix;
|
|
|
|
typedef Dune::FieldVector<Scalar, dimWorld> DimVector;
|
|
|
|
|
|
|
|
public:
|
|
|
|
EclTransmissibility(const Simulator& simulator)
|
|
|
|
: simulator_(simulator)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief Actually compute the transmissibilty over a face as a pre-compute step.
|
|
|
|
*
|
|
|
|
* This code actually uses the direction specific "centroids" of
|
|
|
|
* each element. These "centroids" are _not_ the identical
|
|
|
|
* barycenter of the element, but the middle of the centers of the
|
|
|
|
* faces of the logical Cartesian cells, i.e., the centers of the
|
|
|
|
* faces of the reference elements. We do things this way because
|
|
|
|
* the barycenter of the element can be located outside of the
|
|
|
|
* element for sufficiently "ugly" (i.e., thin and "non-flat")
|
|
|
|
* elements which in turn leads to quite wrong
|
|
|
|
* permeabilities. This approach is probably not always correct
|
|
|
|
* either but at least it seems to be much better.
|
|
|
|
*/
|
|
|
|
void finishInit()
|
|
|
|
{
|
|
|
|
const auto& elementMapper = simulator_.model().elementMapper();
|
|
|
|
const auto& gridView = simulator_.gridView();
|
|
|
|
const auto& problem = simulator_.problem();
|
|
|
|
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned numElements = elementMapper.size();
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
// this code assumes that the DOFs are the elements. (i.e., an
|
|
|
|
// ECFV spatial discretization with TPFA). if you try to use
|
|
|
|
// it with something else, you're currently out of luck,
|
|
|
|
// sorry!
|
2015-11-18 04:54:35 -06:00
|
|
|
assert(simulator_.model().numGridDof() == numElements);
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
// calculate the axis specific centroids of all elements
|
|
|
|
std::array<std::vector<DimVector>, dimWorld> axisCentroids;
|
|
|
|
|
2015-11-18 04:54:35 -06:00
|
|
|
for (unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx)
|
2014-12-27 08:19:15 -06:00
|
|
|
axisCentroids[dimIdx].resize(numElements);
|
|
|
|
|
|
|
|
auto elemIt = gridView.template begin</*codim=*/ 0>();
|
|
|
|
const auto& elemEndIt = gridView.template end</*codim=*/ 0>();
|
|
|
|
for (; elemIt != elemEndIt; ++elemIt) {
|
2015-01-21 08:15:40 -06:00
|
|
|
const auto& elem = *elemIt;
|
2014-12-27 08:19:15 -06:00
|
|
|
#if DUNE_VERSION_NEWER(DUNE_COMMON, 2,4)
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned elemIdx = elementMapper.index(elem);
|
2014-12-27 08:19:15 -06:00
|
|
|
#else
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned elemIdx = elementMapper.map(elem);
|
2014-12-27 08:19:15 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// get the geometry of the current element
|
2015-01-21 08:15:40 -06:00
|
|
|
const auto& geom = elem.geometry();
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
// compute the axis specific "centroids" used for the
|
|
|
|
// transmissibilities
|
2015-11-18 04:54:35 -06:00
|
|
|
for (unsigned dimIdx = 0; dimIdx < dimWorld; ++dimIdx) {
|
2014-12-27 08:19:15 -06:00
|
|
|
DimVector x0Local(0.5);
|
|
|
|
DimVector x1Local(0.5);
|
|
|
|
|
|
|
|
x0Local[dimIdx] = 0.0;
|
|
|
|
x1Local[dimIdx] = 1.0;
|
|
|
|
|
|
|
|
DimVector x = geom.global(x0Local);
|
|
|
|
x += geom.global(x1Local);
|
|
|
|
x /= 2;
|
|
|
|
|
|
|
|
axisCentroids[dimIdx][elemIdx] = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 06:17:01 -06:00
|
|
|
const auto& gridManager = simulator_.gridManager();
|
|
|
|
Opm::EclipseStateConstPtr eclState = gridManager.eclState();
|
2016-02-25 04:19:55 -06:00
|
|
|
std::shared_ptr<const Opm::TransMult> transMult = eclState->getTransMult();
|
2014-12-27 08:19:15 -06:00
|
|
|
const std::vector<double>& ntg =
|
|
|
|
eclState->getDoubleGridProperty("NTG")->getData();
|
|
|
|
|
2015-01-06 05:40:30 -06:00
|
|
|
// reserving some space in the hashmap upfront saves quite a bit of time because
|
|
|
|
// resizes are costly for hashmaps and there would be quite a few of them if we
|
|
|
|
// would not have a rough idea of how large the final map will be (the rough idea
|
|
|
|
// is a conforming Cartesian grid). unfortunately, this method is not available
|
|
|
|
// in GCC 4.4. (but I cannot say for sure when it became available so I play safe
|
|
|
|
// and limit it to GCC >= 4.8)
|
|
|
|
#if defined __clang__ || (__GNUC__ > 4 && __GNUC_MINOR__ >= 8)
|
2014-12-27 08:19:15 -06:00
|
|
|
trans_.reserve(numElements*3*1.05);
|
2015-01-06 05:40:30 -06:00
|
|
|
#endif
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
// compute the transmissibilities for all intersections
|
|
|
|
elemIt = gridView.template begin</*codim=*/ 0>();
|
|
|
|
for (; elemIt != elemEndIt; ++elemIt) {
|
2015-01-21 08:15:40 -06:00
|
|
|
const auto& elem = *elemIt;
|
|
|
|
auto isIt = gridView.ibegin(elem);
|
|
|
|
const auto& isEndIt = gridView.iend(elem);
|
2014-12-27 08:19:15 -06:00
|
|
|
for (; isIt != isEndIt; ++ isIt) {
|
2015-01-19 09:22:34 -06:00
|
|
|
// store intersection, this might be costly
|
|
|
|
const auto& intersection = *isIt;
|
|
|
|
|
2014-12-27 08:19:15 -06:00
|
|
|
// ignore boundary intersections for now (TODO?)
|
2015-01-19 09:22:34 -06:00
|
|
|
if (intersection.boundary())
|
2014-12-27 08:19:15 -06:00
|
|
|
continue;
|
|
|
|
|
2015-01-21 08:48:01 -06:00
|
|
|
const auto& inside = intersection.inside();
|
2015-01-19 09:22:34 -06:00
|
|
|
const auto& outside = intersection.outside();
|
2014-12-27 08:19:15 -06:00
|
|
|
#if DUNE_VERSION_NEWER(DUNE_COMMON, 2,4)
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned insideElemIdx = elementMapper.index(inside);
|
|
|
|
unsigned outsideElemIdx = elementMapper.index(outside);
|
2014-12-27 08:19:15 -06:00
|
|
|
#else
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned insideElemIdx = elementMapper.map(*inside);
|
|
|
|
unsigned outsideElemIdx = elementMapper.map(*outside);
|
2014-12-27 08:19:15 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// we only need to calculate a face's transmissibility
|
|
|
|
// once...
|
|
|
|
if (insideElemIdx > outsideElemIdx)
|
|
|
|
continue;
|
|
|
|
|
2016-02-24 08:27:54 -06:00
|
|
|
unsigned insideCartElemIdx = gridManager.cartesianIndex(insideElemIdx);
|
|
|
|
unsigned outsideCartElemIdx = gridManager.cartesianIndex(outsideElemIdx);
|
2015-01-27 06:17:01 -06:00
|
|
|
|
2014-12-27 08:19:15 -06:00
|
|
|
// local indices of the faces of the inside and
|
|
|
|
// outside elements which contain the intersection
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned insideFaceIdx = intersection.indexInInside();
|
|
|
|
unsigned outsideFaceIdx = intersection.indexInOutside();
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
Scalar halfTrans1;
|
|
|
|
Scalar halfTrans2;
|
|
|
|
|
|
|
|
computeHalfTrans_(halfTrans1,
|
2015-01-19 09:22:34 -06:00
|
|
|
intersection,
|
2014-12-27 08:19:15 -06:00
|
|
|
insideFaceIdx,
|
2015-01-19 09:22:34 -06:00
|
|
|
distanceVector_(intersection,
|
|
|
|
intersection.indexInInside(),
|
2014-12-27 08:19:15 -06:00
|
|
|
insideElemIdx,
|
|
|
|
axisCentroids),
|
|
|
|
problem.intrinsicPermeability(insideElemIdx));
|
|
|
|
computeHalfTrans_(halfTrans2,
|
2015-01-19 09:22:34 -06:00
|
|
|
intersection,
|
2014-12-27 08:19:15 -06:00
|
|
|
outsideFaceIdx,
|
2015-01-19 09:22:34 -06:00
|
|
|
distanceVector_(intersection,
|
|
|
|
intersection.indexInOutside(),
|
2014-12-27 08:19:15 -06:00
|
|
|
outsideElemIdx,
|
|
|
|
axisCentroids),
|
|
|
|
problem.intrinsicPermeability(outsideElemIdx));
|
|
|
|
|
2016-02-24 08:27:54 -06:00
|
|
|
applyNtg_(halfTrans1, insideFaceIdx, insideCartElemIdx, ntg);
|
|
|
|
applyNtg_(halfTrans2, outsideFaceIdx, outsideCartElemIdx, ntg);
|
2014-12-27 08:19:15 -06:00
|
|
|
|
|
|
|
// convert half transmissibilities to full face
|
|
|
|
// transmissibilities using the harmonic mean
|
|
|
|
Scalar trans = 1.0 / (1.0/halfTrans1 + 1.0/halfTrans2);
|
|
|
|
|
|
|
|
// apply the full face transmissibility multipliers
|
|
|
|
// for the inside ...
|
2016-02-25 04:19:55 -06:00
|
|
|
applyMultipliers_(trans, insideFaceIdx, insideCartElemIdx, *transMult);
|
2014-12-27 08:19:15 -06:00
|
|
|
// ... and outside elements
|
2016-02-25 04:19:55 -06:00
|
|
|
applyMultipliers_(trans, outsideFaceIdx, outsideCartElemIdx, *transMult);
|
2014-12-27 08:19:15 -06:00
|
|
|
|
2015-01-27 06:17:01 -06:00
|
|
|
// apply the region multipliers (cf. the MULTREGT keyword)
|
|
|
|
Opm::FaceDir::DirEnum faceDir;
|
|
|
|
switch (insideFaceIdx) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
faceDir = Opm::FaceDir::XPlus;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
faceDir = Opm::FaceDir::YPlus;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
faceDir = Opm::FaceDir::ZPlus;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
OPM_THROW(std::logic_error, "Could not determine a face direction");
|
|
|
|
}
|
|
|
|
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult->getRegionMultiplier(insideCartElemIdx,
|
|
|
|
outsideCartElemIdx,
|
|
|
|
faceDir);
|
2015-01-27 06:17:01 -06:00
|
|
|
|
2014-12-27 08:19:15 -06:00
|
|
|
trans_[isId_(insideElemIdx, outsideElemIdx)] = trans;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 04:54:35 -06:00
|
|
|
Scalar transmissibility(unsigned elemIdx1, unsigned elemIdx2) const
|
2014-12-27 08:19:15 -06:00
|
|
|
{ return trans_.at(isId_(elemIdx1, elemIdx2)); }
|
|
|
|
|
|
|
|
private:
|
2015-11-18 04:54:35 -06:00
|
|
|
std::uint64_t isId_(unsigned elemIdx1, unsigned elemIdx2) const
|
2014-12-27 08:19:15 -06:00
|
|
|
{
|
2015-11-18 04:54:35 -06:00
|
|
|
static const unsigned elemIdxShift = 32; // bits
|
2014-12-27 08:19:15 -06:00
|
|
|
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned elemAIdx = std::min(elemIdx1, elemIdx2);
|
2014-12-27 08:19:15 -06:00
|
|
|
std::uint64_t elemBIdx = std::max(elemIdx1, elemIdx2);
|
|
|
|
|
|
|
|
return (elemBIdx<<elemIdxShift) + elemAIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
void computeHalfTrans_(Scalar& halfTrans,
|
|
|
|
const Intersection& is,
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned faceIdx, // in the reference element that contains the intersection
|
2014-12-27 08:19:15 -06:00
|
|
|
const DimVector& distance,
|
|
|
|
const DimMatrix& perm) const
|
|
|
|
{
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned dimIdx = faceIdx/2;
|
2014-12-27 08:19:15 -06:00
|
|
|
assert(dimIdx < dimWorld);
|
|
|
|
halfTrans = perm[dimIdx][dimIdx];
|
|
|
|
halfTrans *= is.geometry().volume();
|
2015-05-21 09:18:45 -05:00
|
|
|
|
|
|
|
const auto &normal = is.centerUnitOuterNormal();
|
|
|
|
Scalar val = 0;
|
|
|
|
for (unsigned i = 0; i < normal.size(); ++i)
|
|
|
|
val += is.centerUnitOuterNormal()[i]*distance[i];
|
|
|
|
|
|
|
|
halfTrans *= std::abs<Scalar>(val);
|
2014-12-27 08:19:15 -06:00
|
|
|
halfTrans /= distance*distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
DimVector distanceVector_(const Intersection& is,
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned faceIdx, // in the reference element that contains the intersection
|
|
|
|
unsigned elemIdx,
|
2014-12-27 08:19:15 -06:00
|
|
|
const std::array<std::vector<DimVector>, dimWorld>& axisCentroids) const
|
|
|
|
{
|
2015-11-18 04:54:35 -06:00
|
|
|
unsigned dimIdx = faceIdx/2;
|
2014-12-27 08:19:15 -06:00
|
|
|
assert(dimIdx < dimWorld);
|
|
|
|
DimVector x = is.geometry().center();
|
|
|
|
x -= axisCentroids[dimIdx][elemIdx];
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2016-02-24 08:27:54 -06:00
|
|
|
void applyMultipliers_(Scalar &trans, unsigned faceIdx, unsigned cartElemIdx,
|
2016-02-25 04:19:55 -06:00
|
|
|
const Opm::TransMult& transMult) const
|
2014-12-27 08:19:15 -06:00
|
|
|
{
|
|
|
|
// apply multiplyer for the transmissibility of the face. (the
|
|
|
|
// face index is the index of the reference-element face which
|
|
|
|
// contains the intersection of interest.)
|
|
|
|
switch (faceIdx) {
|
|
|
|
case 0: // left
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::XMinus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
case 1: // right
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::XPlus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // front
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::YMinus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
case 3: // back
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::YPlus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: // bottom
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::ZMinus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
case 5: // top
|
2016-02-25 04:19:55 -06:00
|
|
|
trans *= transMult.getMultiplier(cartElemIdx, Opm::FaceDir::ZPlus);
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-24 08:27:54 -06:00
|
|
|
void applyNtg_(Scalar &trans, unsigned faceIdx, unsigned cartElemIdx,
|
2016-02-25 04:19:55 -06:00
|
|
|
const std::vector<double>& ntg) const
|
2014-12-27 08:19:15 -06:00
|
|
|
{
|
|
|
|
// apply multiplyer for the transmissibility of the face. (the
|
|
|
|
// face index is the index of the reference-element face which
|
|
|
|
// contains the intersection of interest.)
|
|
|
|
switch (faceIdx) {
|
|
|
|
case 0: // left
|
2016-02-24 08:27:54 -06:00
|
|
|
trans *= ntg[cartElemIdx];
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
case 1: // right
|
2016-02-24 08:27:54 -06:00
|
|
|
trans *= ntg[cartElemIdx];
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: // front
|
2016-02-24 08:27:54 -06:00
|
|
|
trans *= ntg[cartElemIdx];
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
case 3: // back
|
2016-02-24 08:27:54 -06:00
|
|
|
trans *= ntg[cartElemIdx];
|
2014-12-27 08:19:15 -06:00
|
|
|
break;
|
|
|
|
|
|
|
|
// NTG does not apply to top and bottom faces
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Simulator& simulator_;
|
|
|
|
std::unordered_map<std::uint64_t, Scalar> trans_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Ewoms
|
|
|
|
|
|
|
|
#endif
|