Add facility for accessing active subset of global data array
This commit introduces a fairly general mechanism for accessing the active subset of a global grid (property) array. Essentially, this takes on the role of translating the active cell index through the "global_cell" mapping when accessing, e.g., the net-to-gross data value. The primary component is class template Opm::GridPropertyAccess::Compressed<DataArray,Tag> which implements a read-only value_type operator[](const int c) that encapsulates and performs the compressed-to-global cell index translation. Template parameter "DataArray" is intended as a policy parameter that for instance wraps access to a "GridProperty<T>" from module opm-parser (with a fall-back default value if the data is not specified on input). The "Tag" parameter is a provision for type safety--e.g., to prevent passing a region ID into a function that requires a porosity value.
This commit is contained in:
parent
7f07964e0c
commit
37dfc4a3b5
@ -148,6 +148,7 @@ list (APPEND MAIN_SOURCE_FILES
|
||||
# find tests -name '*.cpp' -a ! -wholename '*/not-unit/*' -printf '\t%p\n' | sort
|
||||
list (APPEND TEST_SOURCE_FILES
|
||||
tests/test_EclipseWriter.cpp
|
||||
tests/test_compressedpropertyaccess.cpp
|
||||
tests/test_spline.cpp
|
||||
tests/test_propertysystem.cpp
|
||||
tests/test_dgbasis.cpp
|
||||
@ -191,6 +192,7 @@ list (APPEND TEST_DATA_FILES
|
||||
tests/liveoil.DATA
|
||||
tests/capillary.DATA
|
||||
tests/capillary_overlap.DATA
|
||||
tests/compressed_gridproperty.data
|
||||
tests/deadfluids.DATA
|
||||
tests/equil_livegas.DATA
|
||||
tests/equil_liveoil.DATA
|
||||
@ -370,6 +372,7 @@ list (APPEND PUBLIC_HEADER_FILES
|
||||
opm/core/transport/reorder/tarjan.h
|
||||
opm/core/utility/Average.hpp
|
||||
opm/core/utility/ClassName.hpp
|
||||
opm/core/utility/CompressedPropertyAccess.hpp
|
||||
opm/core/utility/DataMap.hpp
|
||||
opm/core/utility/ErrorMacros.hpp
|
||||
opm/core/utility/Event.hpp
|
||||
|
507
opm/core/utility/CompressedPropertyAccess.hpp
Normal file
507
opm/core/utility/CompressedPropertyAccess.hpp
Normal file
@ -0,0 +1,507 @@
|
||||
/*
|
||||
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2014 Statoil ASA.
|
||||
|
||||
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 3 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/>.
|
||||
*/
|
||||
|
||||
#ifndef OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER
|
||||
#define OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* Facility for accessing active subset of data arrays defined for all
|
||||
* global cells. The main component is class template \code
|
||||
* GridPropertyAccess::Compressed<> \endcode which encapsulates and
|
||||
* provides read-only access to a data array and while translating
|
||||
* active cell indices to "global" cell indices. The data array is a
|
||||
* policy parameter for which preexisting implementations "constant"
|
||||
* and "extract from ECLIPSE input" are defined in this module. Data
|
||||
* values in the array must be defined for all global cells.
|
||||
*/
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Grid/GridProperty.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace Opm {
|
||||
/**
|
||||
* Nested name-space that serves no other purpose than to
|
||||
* contextualise \c Compressed class name.
|
||||
*/
|
||||
namespace GridPropertyAccess {
|
||||
/**
|
||||
* Glue code for interacting with ECLIPSE input decks as
|
||||
* defined by module opm-parser.
|
||||
*/
|
||||
namespace Details {
|
||||
/**
|
||||
* Implementation of property query and retrieval from an
|
||||
* ECLIPSE property container.
|
||||
*/
|
||||
namespace EclPropImpl {
|
||||
/**
|
||||
* Property existence predicate.
|
||||
*
|
||||
* Supported for types \c int and \c double.
|
||||
*
|
||||
* \tparam T Property element type.
|
||||
*/
|
||||
template <typename T>
|
||||
struct HasProperty;
|
||||
|
||||
/**
|
||||
* Property value retrieval.
|
||||
*
|
||||
* Supported for types \c int and \c double.
|
||||
*
|
||||
* \tparam T Property element type.
|
||||
*/
|
||||
template <typename T>
|
||||
struct GetProperty;
|
||||
|
||||
/**
|
||||
* Specialization of property existence predicate for
|
||||
* type \c int.
|
||||
*/
|
||||
template <>
|
||||
struct HasProperty<int> {
|
||||
/**
|
||||
* Existence predicate implementation.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type
|
||||
* representing collection of (global) grid
|
||||
* properties. Must implement method \c
|
||||
* hasIntGridProperty.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE property keyword.
|
||||
*
|
||||
* \return Whether or property \c kw exists in the
|
||||
* container \c ecl.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
static bool
|
||||
p(PropertyContainer& ecl,
|
||||
const std::string& kw);
|
||||
};
|
||||
|
||||
template <class PropertyContainer>
|
||||
bool
|
||||
HasProperty<int>::p(PropertyContainer& ecl,
|
||||
const std::string& kw)
|
||||
{
|
||||
return ecl->hasIntGridProperty(kw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialization of property existence predicate for
|
||||
* type \c double.
|
||||
*/
|
||||
template <>
|
||||
struct HasProperty<double> {
|
||||
/**
|
||||
* Existence predicate implementation.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type
|
||||
* representing collection of (global) grid
|
||||
* properties. Must implement method \c
|
||||
* hasDoubleGridProperty.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE property keyword.
|
||||
*
|
||||
* \return Whether or property \c kw exists in the
|
||||
* container \c ecl.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
static bool
|
||||
p(PropertyContainer& ecl,
|
||||
const std::string& kw);
|
||||
};
|
||||
|
||||
template <class PropertyContainer>
|
||||
bool
|
||||
HasProperty<double>::p(PropertyContainer& ecl,
|
||||
const std::string& kw)
|
||||
{
|
||||
return ecl->hasDoubleGridProperty(kw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialization of property value retrieval for type
|
||||
* \c int.
|
||||
*/
|
||||
template <>
|
||||
struct GetProperty<int> {
|
||||
/**
|
||||
* Property value retrieval implementation.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type
|
||||
* representing collection of (global) grid
|
||||
* properties. Must implement method \c
|
||||
* getIntGridProperty.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE property keyword.
|
||||
*
|
||||
* \return Data values for property \c kw.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
static std::shared_ptr< GridProperty<int> >
|
||||
value(PropertyContainer& ecl,
|
||||
const std::string& kw);
|
||||
};
|
||||
|
||||
template <class PropertyContainer>
|
||||
std::shared_ptr< GridProperty<int> >
|
||||
GetProperty<int>::value(PropertyContainer& ecl,
|
||||
const std::string& kw)
|
||||
{
|
||||
assert (HasProperty<int>::p(ecl, kw));
|
||||
|
||||
return ecl->getIntGridProperty(kw);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specialization of property value retrieval for type
|
||||
* \c double.
|
||||
*/
|
||||
template <>
|
||||
struct GetProperty<double> {
|
||||
/**
|
||||
* Property value retrieval implementation.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type
|
||||
* representing collection of (global) grid
|
||||
* properties. Must implement method \c
|
||||
* getDoubleGridProperty.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE property keyword.
|
||||
*
|
||||
* \return Data values for property \c kw.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
static std::shared_ptr< GridProperty<double> >
|
||||
value(PropertyContainer& ecl,
|
||||
const std::string& kw);
|
||||
};
|
||||
|
||||
template <class PropertyContainer>
|
||||
std::shared_ptr< GridProperty<double> >
|
||||
GetProperty<double>::value(PropertyContainer& ecl,
|
||||
const std::string& kw)
|
||||
{
|
||||
assert (HasProperty<double>::p(ecl, kw));
|
||||
|
||||
return ecl->getDoubleGridProperty(kw);
|
||||
}
|
||||
} // namespace EclipsePropertyImpl
|
||||
|
||||
/**
|
||||
* Conditional retrieval of property values from an
|
||||
* ECLIPSE input deck.
|
||||
*
|
||||
* Supported for types \c int and \c double.
|
||||
*
|
||||
* \tparam T Property element type.
|
||||
*/
|
||||
template <typename T>
|
||||
struct EclipsePropertyArray {
|
||||
/**
|
||||
* Retrieve property values if present in container.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type representing
|
||||
* collection of (global) grid properties.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE property keyword.
|
||||
*
|
||||
* \return Data values for property \c kw if present,
|
||||
* an empty \code shared_ptr<> \endcode if not.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
static std::shared_ptr< GridProperty<T> >
|
||||
value(PropertyContainer& ecl,
|
||||
const std::string& kw);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
template <class PropertyContainer>
|
||||
std::shared_ptr< GridProperty<T> >
|
||||
EclipsePropertyArray<T>::value(PropertyContainer& ecl,
|
||||
const std::string& kw)
|
||||
{
|
||||
std::shared_ptr< GridProperty<T> > x;
|
||||
|
||||
if (EclPropImpl::HasProperty<T>::p(ecl, kw)) {
|
||||
x = EclPropImpl::GetProperty<T>::value(ecl, kw);
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
} // namespace Details
|
||||
|
||||
/**
|
||||
* Predefined data array policies for use with class template
|
||||
* \code CompressedAccess<> \endcode.
|
||||
*/
|
||||
namespace ArrayPolicy {
|
||||
/**
|
||||
* Data array policy that extracts the array values from
|
||||
* an ECLIPSE input deck or returns a user specified
|
||||
* default value if the data vector is not present in a
|
||||
* particular input deck.
|
||||
*
|
||||
* Provides read-only access to the underlying data.
|
||||
*
|
||||
* \tparam T Array element type. Must be \c int or \c
|
||||
* double.
|
||||
*/
|
||||
template <typename T>
|
||||
class ExtractFromDeck {
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* \tparam PropertyContainer Pointer type representing
|
||||
* collection of (global) grid properties. Typically
|
||||
* \c EclipseStatePtr or \c EclipseStateConstPtr.
|
||||
* Must implement methods \c hasIntGridProperty and \c
|
||||
* getIntGridProperty if \c T is \c int, or \c
|
||||
* hasDoubleGridProperty and \c getDoubleGridProperty
|
||||
* if \c T is \c double.
|
||||
*
|
||||
* \param[in] ecl Property container.
|
||||
*
|
||||
* \param[in] kw ECLIPSE keyword from which to extract
|
||||
* data array.
|
||||
*
|
||||
* \param[in] dlft Default/fall-back data array value
|
||||
* if \c kw is not defined.
|
||||
*/
|
||||
template <class PropertyContainer>
|
||||
ExtractFromDeck(PropertyContainer& ecl,
|
||||
const std::string& kw,
|
||||
const T dflt)
|
||||
: x_ (Details::EclipsePropertyArray<T>::value(ecl, kw))
|
||||
, dflt_(dflt)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Publicly accessible data array element type.
|
||||
*/
|
||||
typedef T value_type;
|
||||
|
||||
/**
|
||||
* Index type for accessing data array.
|
||||
*/
|
||||
typedef std::size_t size_type;
|
||||
|
||||
/**
|
||||
* Read-only data array access.
|
||||
*
|
||||
* \param[in] i Array index. Assumed to identify a
|
||||
* global (uncompressed) cell.
|
||||
*
|
||||
* \return Data array element at global index \c i if
|
||||
* present in input or user specified fall-back value
|
||||
* if not.
|
||||
*/
|
||||
value_type
|
||||
operator[](const size_type i) const
|
||||
{
|
||||
if (x_) {
|
||||
return x_->iget(i);
|
||||
}
|
||||
else {
|
||||
return dflt_;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Grid property handle.
|
||||
*
|
||||
* Null if data not defined.
|
||||
*/
|
||||
std::shared_ptr< GridProperty<T> > x_;
|
||||
|
||||
/**
|
||||
* Fall-back data element value if data not defined.
|
||||
*/
|
||||
T dflt_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Data array policy that returns a single, constant user
|
||||
* specified value for every global cell.
|
||||
*
|
||||
* Provides read-only access to the underlying data.
|
||||
*
|
||||
* \tparam T Array element type.
|
||||
*/
|
||||
template <typename T>
|
||||
class Constant {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param[in] c Constant property value used for all
|
||||
* global cells.
|
||||
*/
|
||||
Constant(const T c)
|
||||
: c_(c)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Publicly accessible data array element type.
|
||||
*/
|
||||
typedef T value_type;
|
||||
|
||||
/**
|
||||
* Index type for accessing data array.
|
||||
*/
|
||||
typedef std::size_t size_type;
|
||||
|
||||
/**
|
||||
* Read-only data array access.
|
||||
*
|
||||
* \param[in] i Array index. Assumed to identify a
|
||||
* global (uncompressed) cell. Unused.
|
||||
*
|
||||
* \return User specified constant value for every
|
||||
* (global) cell.
|
||||
*/
|
||||
value_type
|
||||
operator[](const size_type i) const
|
||||
{
|
||||
static_cast<void>(i); // Suppress "unused parameter"
|
||||
|
||||
return c_;
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Constant, user specified property value.
|
||||
*/
|
||||
T c_;
|
||||
};
|
||||
} // namespace ArrayPolicy
|
||||
|
||||
/**
|
||||
* Collection of tags to help enforce semantic type checks
|
||||
* when using class \code Compressed<> \endcode.
|
||||
*/
|
||||
namespace Tag {
|
||||
/**
|
||||
* Default tag that implies no restriction.
|
||||
*/
|
||||
struct Any {};
|
||||
|
||||
/**
|
||||
* Tag that restricts usage to NTG (net-to-gross)
|
||||
* contexts.
|
||||
*/
|
||||
struct NTG : public Any {};
|
||||
} // namespace Tag
|
||||
|
||||
/**
|
||||
* Provide compressed (active cell) read-only access to
|
||||
* globally defined data array.
|
||||
*
|
||||
* \tparam DataArray Type representing an array of data
|
||||
* values, one value for each global (uncompressed) cell in a
|
||||
* model. Must implement value semantics. Typically one of
|
||||
* the array policies of name space \c ArrayPolicy. Must
|
||||
* provide public type \c value_type to infer the data element
|
||||
* type and \code operator[](i) \endcode to access the
|
||||
* property value of the \c i'th global cell.
|
||||
*
|
||||
* \tparam PropertyTag Type tag that can be used to restrict
|
||||
* applicability of the resulting \c Compressed array, e.g.,
|
||||
* to enforce net-to-gross ratios only. Default: No
|
||||
* restriction.
|
||||
*/
|
||||
template <class DataArray, class PropertyTag = Tag::Any>
|
||||
class Compressed {
|
||||
public:
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* \param[in] x Preconfigured global property value array.
|
||||
* The \c Compressed array creates a private copy of this
|
||||
* object.
|
||||
*
|
||||
* \param[in] gc Compressed-to-global cell map. Typically
|
||||
* the \c global_cell field of an \c UnstructuredGrid or
|
||||
* something very similar. If null, interpreted as
|
||||
* identity mapping, i.e., as if all cells are active.
|
||||
*/
|
||||
Compressed(const DataArray& x,
|
||||
const int* gc)
|
||||
: x_ (x)
|
||||
, gc_(gc)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Property value type.
|
||||
*/
|
||||
typedef typename DataArray::value_type value_type;
|
||||
|
||||
/**
|
||||
* Read-only data array access.
|
||||
*
|
||||
* \param[in] c Active cell index.
|
||||
*
|
||||
* \return Property value in active cell \c c.
|
||||
*/
|
||||
value_type
|
||||
operator[](const int c) const
|
||||
{
|
||||
return x_[ (gc_ == 0) ? c : gc_[c] ];
|
||||
}
|
||||
|
||||
private:
|
||||
/**
|
||||
* Global property value array.
|
||||
*
|
||||
* Value semantics to support putting \c Compressed arrays
|
||||
* into standard containers.
|
||||
*/
|
||||
DataArray x_;
|
||||
|
||||
/**
|
||||
* Compressed-to-global cell index map. \c Null if all
|
||||
* cells active.
|
||||
*/
|
||||
const int* gc_;
|
||||
};
|
||||
} // namespace GridPropertyAccess
|
||||
} // namespace Opm
|
||||
|
||||
#endif /* OPM_COMPRESSEDPROPERTYACCESS_HPP_HEADER */
|
48
tests/compressed_gridproperty.data
Normal file
48
tests/compressed_gridproperty.data
Normal file
@ -0,0 +1,48 @@
|
||||
RUNSPEC
|
||||
|
||||
DIMENS
|
||||
1 1 4
|
||||
/
|
||||
|
||||
GRID
|
||||
|
||||
COORD
|
||||
0 0 0 0 0 0
|
||||
1 0 0 1 0 0
|
||||
0 1 0 0 1 0
|
||||
1 1 0 1 1 0
|
||||
/
|
||||
|
||||
ZCORN
|
||||
0 0 0 0
|
||||
1 1 1 1
|
||||
|
||||
1 1 1 1
|
||||
2 2 2 2
|
||||
|
||||
2 2 2 2
|
||||
3 3 3 3
|
||||
|
||||
3 3 3 3
|
||||
4 4 4 4
|
||||
/
|
||||
|
||||
ACTNUM
|
||||
0 1 0 1
|
||||
/
|
||||
|
||||
NTG
|
||||
0.1 0.2 0.3 0.4
|
||||
/
|
||||
|
||||
REGIONS
|
||||
|
||||
SATNUM
|
||||
4 3 2 1
|
||||
/
|
||||
|
||||
-- Note: Dummy 'PROPS' and 'SCHEDULE' sections only
|
||||
PROPS
|
||||
SCHEDULE
|
||||
|
||||
END
|
350
tests/test_compressedpropertyaccess.cpp
Normal file
350
tests/test_compressedpropertyaccess.cpp
Normal file
@ -0,0 +1,350 @@
|
||||
/*
|
||||
Copyright 2014 SINTEF ICT, Applied Mathematics.
|
||||
Copyright 2014 Statoil ASA.
|
||||
|
||||
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 3 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/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#if HAVE_DYNAMIC_BOOST_TEST
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#endif
|
||||
|
||||
#define NVERBOSE
|
||||
|
||||
#define BOOST_TEST_MODULE CompressedPropertyTest
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/floating_point_comparison.hpp>
|
||||
|
||||
#include <opm/core/utility/CompressedPropertyAccess.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/EclipseState.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
|
||||
#include <opm/core/grid/GridManager.hpp>
|
||||
#include <opm/core/grid.h>
|
||||
|
||||
struct SetupSimple {
|
||||
SetupSimple()
|
||||
{
|
||||
Opm::ParserPtr parser(new Opm::Parser());
|
||||
deck = parser->parseFile("compressed_gridproperty.data");
|
||||
ecl.reset(new Opm::EclipseState(deck));
|
||||
}
|
||||
|
||||
Opm::DeckConstPtr deck;
|
||||
Opm::EclipseStateConstPtr ecl;
|
||||
};
|
||||
|
||||
|
||||
template <class Setup>
|
||||
struct TestFixture : public Setup
|
||||
{
|
||||
TestFixture()
|
||||
: Setup ()
|
||||
, grid (deck)
|
||||
, reltol(1.0e-10)
|
||||
{
|
||||
}
|
||||
|
||||
using Setup::deck;
|
||||
using Setup::ecl;
|
||||
|
||||
Opm::GridManager grid;
|
||||
const double reltol;
|
||||
};
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(CompressedPropertyHandling)
|
||||
|
||||
// Construct global array by extracting an "undefined" (unspecified)
|
||||
// double vector from the input deck.
|
||||
BOOST_FIXTURE_TEST_CASE(APExtractDoubleUndefined,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<double> ECLGlobalDoubleArray;
|
||||
|
||||
ECLGlobalDoubleArray multpv(ecl, "MULTPV", 1.0);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(multpv[0], 1.0, reltol);
|
||||
BOOST_REQUIRE_CLOSE(multpv[1], 1.0, reltol);
|
||||
BOOST_REQUIRE_CLOSE(multpv[2], 1.0, reltol);
|
||||
BOOST_REQUIRE_CLOSE(multpv[3], 1.0, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct global array by extracting a fully defined (specified)
|
||||
// double vector from the input deck.
|
||||
BOOST_FIXTURE_TEST_CASE(APExtractDoubleDefined,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<double> ECLGlobalDoubleArray;
|
||||
|
||||
ECLGlobalDoubleArray ntg(ecl, "NTG", 1.0);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(ntg[0], 0.1, reltol);
|
||||
BOOST_REQUIRE_CLOSE(ntg[1], 0.2, reltol);
|
||||
BOOST_REQUIRE_CLOSE(ntg[2], 0.3, reltol);
|
||||
BOOST_REQUIRE_CLOSE(ntg[3], 0.4, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct global array by extracting an undefined (unspecified)
|
||||
// integer (int) vector from the input deck.
|
||||
BOOST_FIXTURE_TEST_CASE(APExtractIntUndefined,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<int> ECLGlobalIntArray;
|
||||
|
||||
ECLGlobalIntArray imbnum(ecl, "IMBNUM", 1);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(imbnum[0], 1);
|
||||
BOOST_REQUIRE_EQUAL(imbnum[1], 1);
|
||||
BOOST_REQUIRE_EQUAL(imbnum[2], 1);
|
||||
BOOST_REQUIRE_EQUAL(imbnum[3], 1);
|
||||
}
|
||||
|
||||
|
||||
// Construct global array by extracting a fully defined (specified)
|
||||
// integer (int) vector from the input deck.
|
||||
BOOST_FIXTURE_TEST_CASE(APExtractIntDefined,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<int> ECLGlobalIntArray;
|
||||
|
||||
ECLGlobalIntArray satnum(ecl, "SATNUM", 1);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(satnum[0], 4);
|
||||
BOOST_REQUIRE_EQUAL(satnum[1], 3);
|
||||
BOOST_REQUIRE_EQUAL(satnum[2], 2);
|
||||
BOOST_REQUIRE_EQUAL(satnum[3], 1);
|
||||
}
|
||||
|
||||
|
||||
// Construct global, infinitely sized, double array by specifying a
|
||||
// single constant for all cells.
|
||||
BOOST_FIXTURE_TEST_CASE(APConstantDouble,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<double> ConstantDoubleArray;
|
||||
|
||||
const double c = 1.234e5;
|
||||
|
||||
ConstantDoubleArray x(c);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(x[ 0], c, reltol);
|
||||
BOOST_REQUIRE_CLOSE(x[ 1], c, reltol);
|
||||
BOOST_REQUIRE_CLOSE(x[ 2], c, reltol);
|
||||
BOOST_REQUIRE_CLOSE(x[10000], c, reltol); // Infinite size array
|
||||
}
|
||||
|
||||
|
||||
// Construct global, infinitely sized, integer (int) array by
|
||||
// specifying a single constant for all cells.
|
||||
BOOST_FIXTURE_TEST_CASE(APConstantInt,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<int> ConstantIntArray;
|
||||
|
||||
const int i = 12345;
|
||||
|
||||
ConstantIntArray a(i);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(a[ 0], i);
|
||||
BOOST_REQUIRE_EQUAL(a[ 1], i);
|
||||
BOOST_REQUIRE_EQUAL(a[ 2], i);
|
||||
BOOST_REQUIRE_EQUAL(a[10001], i); // Inifinite size array
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed double array based on global, undefined array
|
||||
// extracted from input deck. Default ("any") type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAExtractDoubleUndefinedAny,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<double> ECLGlobalDoubleArray;
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ECLGlobalDoubleArray> CompressedArray;
|
||||
|
||||
ECLGlobalDoubleArray multpv_glob(ecl, "MULTPV", 1.0);
|
||||
CompressedArray multpv(multpv_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(multpv[0], 1.0, reltol);
|
||||
BOOST_REQUIRE_CLOSE(multpv[1], 1.0, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed double array based on global, fully specified
|
||||
// array extracted from input deck. Type-check tag: NTG.
|
||||
BOOST_FIXTURE_TEST_CASE(CAExtractDoubleDefinedNTG,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<double> ECLGlobalDoubleArray;
|
||||
|
||||
typedef Opm::GridPropertyAccess::Tag::NTG NTG;
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ECLGlobalDoubleArray, NTG> CompressedArray;
|
||||
|
||||
ECLGlobalDoubleArray ntg_glob(ecl, "NTG", 1.0);
|
||||
CompressedArray ntg(ntg_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(ntg[0], 0.2, reltol);
|
||||
BOOST_REQUIRE_CLOSE(ntg[1], 0.4, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed integer (int) array based on global, undefined
|
||||
// (unspecified) array extracted from input deck. Default ("any")
|
||||
// type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAExtractIntUndefinedAny,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<int> ECLGlobalIntArray;
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ECLGlobalIntArray> CompressedArray;
|
||||
|
||||
ECLGlobalIntArray imbnum_glob(ecl, "IMBNUM", 1);
|
||||
CompressedArray imbnum(imbnum_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(imbnum[0], 1);
|
||||
BOOST_REQUIRE_EQUAL(imbnum[1], 1);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed integer (int) array based on global, fully
|
||||
// specified array extracted from input deck. Custom type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAExtractIntDefinedCustom,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::ExtractFromDeck<int> ECLGlobalIntArray;
|
||||
|
||||
struct RegionID : public Opm::GridPropertyAccess::Tag::Any {};
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ECLGlobalIntArray, RegionID> CompressedArray;
|
||||
|
||||
ECLGlobalIntArray satnum_glob(ecl, "SATNUM", 1);
|
||||
CompressedArray satnum(satnum_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(satnum[0], 3);
|
||||
BOOST_REQUIRE_EQUAL(satnum[1], 1);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed double array based on global constant value
|
||||
// for all cells. Default ("any") type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAConstantDoubleAny,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<double> ConstantDoubleArray;
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ConstantDoubleArray> CompressedArray;
|
||||
|
||||
const double c = 1.234e5;
|
||||
|
||||
ConstantDoubleArray x_glob(c);
|
||||
CompressedArray x(x_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(x[0], c, reltol);
|
||||
BOOST_REQUIRE_CLOSE(x[1], c, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed double array based on global constant value
|
||||
// for all cells. Custom type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAConstantDoubleCustom,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<double> ConstantDoubleArray;
|
||||
|
||||
struct MyTag : public Opm::GridPropertyAccess::Tag::Any {};
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ConstantDoubleArray, MyTag> CompressedArray;
|
||||
|
||||
const double c = 1.234e5;
|
||||
|
||||
ConstantDoubleArray x_glob(c);
|
||||
CompressedArray x(x_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_CLOSE(x[0], c, reltol);
|
||||
BOOST_REQUIRE_CLOSE(x[1], c, reltol);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed integer (int) array based on global constant
|
||||
// value for all cells. Custom type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAConstantIntAny,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<int> ConstantIntArray;
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ConstantIntArray> CompressedArray;
|
||||
|
||||
const int i = 12345;
|
||||
|
||||
ConstantIntArray x_glob(i);
|
||||
CompressedArray x(x_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(x[0], i);
|
||||
BOOST_REQUIRE_EQUAL(x[1], i);
|
||||
}
|
||||
|
||||
|
||||
// Construct compressed integer (int) array based on global constant
|
||||
// value for all cells. Custom type-check tag.
|
||||
BOOST_FIXTURE_TEST_CASE(CAConstantIntCustom,
|
||||
TestFixture<SetupSimple>)
|
||||
{
|
||||
typedef Opm::GridPropertyAccess::ArrayPolicy
|
||||
::Constant<int> ConstantIntArray;
|
||||
|
||||
struct MyTag : public Opm::GridPropertyAccess::Tag::Any {};
|
||||
|
||||
typedef Opm::GridPropertyAccess::
|
||||
Compressed<ConstantIntArray, MyTag> CompressedArray;
|
||||
|
||||
const int i = 12345;
|
||||
|
||||
ConstantIntArray x_glob(i);
|
||||
CompressedArray x(x_glob, grid.c_grid()->global_cell);
|
||||
|
||||
BOOST_REQUIRE_EQUAL(x[0], i);
|
||||
BOOST_REQUIRE_EQUAL(x[1], i);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
Loading…
Reference in New Issue
Block a user