move some infrastructure to opm-material

These classes are only used by opm-material and its downstreams. The
reason for doing moving it there is that this allows more freedom in
reorganizing the lower-level OPM modules (i.e., opm-common,
opm-parser, opm-output) while still avoiding a hard dependency of the
thermodynamic and numerical framework modules on the ECL file parsing
libraries.
This commit is contained in:
Andreas Lauser 2018-02-01 15:40:52 +01:00
parent 7d5aa79922
commit 038841a2ef
6 changed files with 0 additions and 723 deletions

View File

@ -38,7 +38,6 @@ list (APPEND MAIN_SOURCE_FILES
list (APPEND TEST_SOURCE_FILES
tests/test_cmp.cpp
tests/test_ConditionalStorage.cpp
tests/test_cubic.cpp
tests/test_messagelimiter.cpp
tests/test_nonuniformtablelinear.cpp
@ -63,12 +62,8 @@ list (APPEND PROGRAM_SOURCE_FILES
list( APPEND PUBLIC_HEADER_FILES
opm/common/utility/ConditionalStorage.hpp
opm/common/ErrorMacros.hpp
opm/common/Exceptions.hpp
opm/common/utility/ResetLocale.hpp
opm/common/Unused.hpp
opm/common/Valgrind.hpp
opm/common/data/SimulationDataContainer.hpp
opm/common/OpmLog/CounterLog.hpp
opm/common/OpmLog/EclipsePRTLog.hpp

View File

@ -1,43 +0,0 @@
// -*- 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 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/>.
*/
/*!
* \file
* \brief Provides the OPM_UNUSED macro
*
* This macro can be used to mark variables as "potentially unused" which suppresses some
* bogus compiler warnings. If the compiler does not support this, the macro is a no-op.
*/
#ifndef OPM_UNUSED_HH
#define OPM_UNUSED_HH
#ifndef HAS_ATTRIBUTE_UNUSED
#define OPM_UNUSED
#else
#define OPM_UNUSED __attribute__((unused))
#endif
#ifdef NDEBUG
#define OPM_DEBUG_UNUSED
#define OPM_OPTIM_UNUSED OPM_UNUSED
#else
#define OPM_DEBUG_UNUSED OPM_UNUSED
#define OPM_OPTIM_UNUSED
#endif
#endif

View File

@ -1,311 +0,0 @@
// -*- 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.
*/
/*!
* \file
* \brief Some templates to wrap the valgrind client request macros
*/
#ifndef OPM_VALGRIND_HPP
#define OPM_VALGRIND_HPP
#include <opm/common/Unused.hpp>
#if HAVE_VALGRIND
#include <valgrind/memcheck.h>
#endif
#if HAVE_VALGRIND
#define OPM_VALGRIND_OPTIM_UNUSED OPM_OPTIM_UNUSED
#else
#define OPM_VALGRIND_OPTIM_UNUSED OPM_UNUSED
#endif
namespace Opm {
namespace Valgrind {
/*!
* \ingroup Valgrind
* \brief Returns whether the program is running under Valgrind or not.
*/
inline bool IsRunning()
{
#if !defined NDEBUG && HAVE_VALGRIND
return RUNNING_ON_VALGRIND;
#else
return false;
#endif
}
/*!
* \ingroup Valgrind
* \brief Make valgrind complain if any of the memory occupied by an object
* is undefined.
*
* Please note that this does not check whether the destinations of an
* object's pointers or references are defined. Also, for performance
* reasons the compiler might insert "padding bytes" between within
* the objects which leads to false positives.
*
* Example:
*
* \code
* int i;
* Valgrind::CheckDefined(i); // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which ought to be checked
*
* \param value the object which valgrind should check
*
* \return true iff there are no undefined bytes in the memory
* occupied by the object.
*/
template <class T>
inline bool CheckDefined(const T& value OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
auto tmp = VALGRIND_CHECK_MEM_IS_DEFINED(&value, sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
/*!
* \ingroup Valgrind
* \brief Make valgrind complain if any of the memory occupied by an object
* is not addressable.
*
* Example:
*
* \code
* int* i = NULL;
* Valgrind::CheckAddressable(*i); // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which ought to be checked
*
* \param value the object which valgrind should check
*
* \return true iff there are no unadressable bytes in the memory
* occupied by the object.
*/
template <class T>
inline bool CheckAddressable(const T& value OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
auto tmp = VALGRIND_CHECK_MEM_IS_ADDRESSABLE(&value, sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
/*!
* \ingroup Valgrind
* \brief Make valgrind complain if any of the the memory occupied
* by a C-style array objects is undefined.
*
* Please note that this does not check whether the destinations of an
* object's pointers or references are defined. Also, for performance
* reasons the compiler might insert "padding bytes" between within
* the objects which leads to false positives.
*
* Example:
*
* \code
* int i[2];
* Valgrind::CheckDefined(i, 2); // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which ought to be checked
*
* \param value Pointer to the first object of the array.
* \param size The size of the array in number of objects
*
* \return true iff there are no undefined bytes in the memory
* occupied by the array.
*/
template <class T>
inline bool CheckDefined(const T* value OPM_VALGRIND_OPTIM_UNUSED, int size OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
auto tmp = VALGRIND_CHECK_MEM_IS_DEFINED(value, size*sizeof(T));
return tmp == 0;
#else
return true;
#endif
}
/*!
* \ingroup Valgrind
* \brief Make the memory on which an object resides undefined in
* valgrind runs.
*
* Example:
*
* \code
* int i = 0;
* Valgrind::SetUndefined(i);
* Valgrind::CheckDefined(i); // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which ought to be set to undefined
*
* \param value The object which's memory valgrind should be told is undefined
*/
template <class T>
inline void SetUndefined(const T &value OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_UNDEFINED(&value, sizeof(T));
#endif
}
/*!
* \ingroup Valgrind
* \brief Make the memory on which an array of object resides
* undefined in valgrind runs.
*
* Example:
*
* \code
* int i[3] = {0, 1, 3};
* Valgrind::SetUndefined(&i[1], 2);
* Valgrind::CheckDefined(i, 3); // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which ought to be set to undefined
*
* \param value Pointer to the first object of the array.
* \param size The size of the array in number of objects
*/
template <class T>
inline void SetUndefined(const T* value OPM_VALGRIND_OPTIM_UNUSED, int size OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_UNDEFINED(value, size*sizeof(T));
#endif
}
/*!
* \ingroup Valgrind
* \brief Make the memory on which an object resides defined.
*
* Example:
*
* \code
* int i;
* Valgrind::SetDefined(i);
* Valgrind::CheckDefined(i); // Valgrind does not complain!
* \endcode
*
* \tparam T The type of the object which valgrind should consider as defined
*
* \param value The object which's memory valgrind should consider as defined
*/
template <class T>
inline void SetDefined(const T& value OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_DEFINED(&value, sizeof(T));
#endif
}
/*!
* \ingroup Valgrind
* \brief Make the memory on which a C-style array of objects resides
* defined.
*
* Example:
*
* \code
* int i[3];
* Valgrind::SetDefined(i, 3);
* Valgrind::CheckDefined(i, 3); // Valgrind does not complain!
* \endcode
*
* \tparam T The type of the object which valgrind should consider as defined
*
* \param value Pointer to the first object of the array.
* \param n The size of the array in number of objects
*/
template <class T>
inline void SetDefined(const T *value OPM_VALGRIND_OPTIM_UNUSED, int n OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_DEFINED(value, n*sizeof(T));
#endif
}
/*!
* \ingroup Valgrind
* \brief Make valgrind complain if an object's memory is accessed.
*
* Example:
*
* \code
* int i = 1;
* Valgrind::SetNoAccess(i);
* int j = i; // Valgrind complains!
* \endcode
*
* \tparam T The type of the object which valgrind should complain if accessed
*
* \param value The object which's memory valgrind should complain if accessed
*/
template <class T>
inline void SetNoAccess(const T &value OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_NOACCESS(&value, sizeof(T));
#endif
}
/*!
* \ingroup Valgrind
* \brief Make valgrind complain if the memory of a C-style array of
* objects is accessed.
*
* Example:
*
* \code
* int i[3] = {0, 1, 2};
* Valgrind::SetNoAccess(i, 2);
* int j = i[1]; // Valgrind complains!
* \endcode
*
* \param value Pointer to the first object of the array.
* \param size The size of the array in number of objects
*/
template <class T>
inline void SetNoAccess(const T *value OPM_VALGRIND_OPTIM_UNUSED, int size OPM_VALGRIND_OPTIM_UNUSED)
{
#if !defined NDEBUG && HAVE_VALGRIND
VALGRIND_MAKE_MEM_NOACCESS(value, size*sizeof(T));
#endif
}
}} // namespace Valgrind, Opm
#endif

View File

@ -1,167 +0,0 @@
// -*- 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.
*/
/*!
* \file
*
* \copydoc Opm::ConditionalStorage
*/
#ifndef OPM_CONDITIONAL_STORAGE_HH
#define OPM_CONDITIONAL_STORAGE_HH
#include <opm/common/ErrorMacros.hpp>
#include <opm/common/Exceptions.hpp>
#include <opm/common/Unused.hpp>
#include <utility>
namespace Opm {
/*!
* \ingroup Common
*
* \brief A simple class which only stores a given member attribute if a boolean
* condition is true
*
* If the condition is false, nothing is stored and an exception is thrown when trying to
* access the object.
*/
template <bool cond, class T>
class ConditionalStorage
{
public:
typedef T type;
static constexpr bool condition = cond;
ConditionalStorage()
{}
ConditionalStorage(const T& v)
: data_(v)
{}
ConditionalStorage(T&& v)
: data_(std::move(v))
{}
template <class ...Args>
ConditionalStorage(Args... args)
: data_(args...)
{}
ConditionalStorage(const ConditionalStorage& t)
: data_(t.data_)
{};
ConditionalStorage(ConditionalStorage&& t)
: data_(std::move(t.data_))
{};
ConditionalStorage& operator=(const ConditionalStorage& v)
{
data_ = v.data_;
return *this;
}
ConditionalStorage& operator=(ConditionalStorage&& v)
{
data_ = std::move(v.data_);
return *this;
}
const T& operator*() const
{ return data_; }
T& operator*()
{ return data_; }
const T* operator->() const
{ return &data_; }
T* operator->()
{ return &data_; }
private:
T data_;
};
template <class T>
class ConditionalStorage<false, T>
{
public:
typedef T type;
static constexpr bool condition = false;
ConditionalStorage()
{
// ensure that T has a default constructor without actually calling it
if (false) {
T OPM_UNUSED dummy; // <- if the compiler bails out here, T does not have a default constructor
}
}
ConditionalStorage(const T& v)
{
// ensure that T has a default constructor without actually calling it
if (false) {
T OPM_UNUSED dummy(v); // <- if the compiler bails out here, T does not have a copy constructor
}
}
ConditionalStorage(const ConditionalStorage &)
{
// copying an empty conditional storage object does not do anything.
};
template <class ...Args>
ConditionalStorage(Args... args)
{
// ensure that the arguments are valid without actually calling the constructor
// of T
if (false) {
T OPM_UNUSED dummy(args...); // <- if the compiler bails out here, T does not have the requested constructor
}
}
ConditionalStorage& operator=(const ConditionalStorage&)
{
// ensure that the stored object can actually be assined to but not actually do
// anything
if (false) {
T *dummy;
(*dummy) = (*dummy); // <- if the compiler bails out here, T does not have an assignment operator
}
return *this;
}
const T& operator*() const
{ OPM_THROW(std::logic_error, "data member deactivated"); }
T& operator*()
{ OPM_THROW(std::logic_error, "data member deactivated"); }
const T* operator->() const
{ OPM_THROW(std::logic_error, "data member deactivated"); }
T* operator->()
{ OPM_THROW(std::logic_error, "data member deactivated"); }
};
} // namespace Opm
#endif

View File

@ -1,62 +0,0 @@
// -*- 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 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/>.
*/
/*!
* \file
* \brief Provides a free function to reset the localization settings
*
* Under some circumstances, some environments seem to set a locale which they do not
* install. In turn this leads to std::runtime_errror being thrown by some parts of Boost
* (for some versions) which causes unsolicited program aborts.
*
* This issue asside, it looks pretty weird if the e.g. the number format is inconsistent
* with the language used by rest of the simulation.
*/
#ifndef OPM_RESET_LOCALE_HH
#define OPM_RESET_LOCALE_HH
#include <stdlib.h>
namespace Opm {
inline void resetLocale()
{
#ifndef WIN32
// this probably only works for POSIX compatible operating systems. for all others,
// unsetting a few environment variables should not hurt, though.
unsetenv("LC_ALL");
unsetenv("LANG");
unsetenv("LANGUAGE");
unsetenv("LC_ADDRESS");
unsetenv("LC_COLLATE");
unsetenv("LC_CTYPE");
unsetenv("LC_IDENTIFICATION");
unsetenv("LC_MEASUREMENT");
unsetenv("LC_MESSAGES");
unsetenv("LC_MONETARY");
unsetenv("LC_NAME");
unsetenv("LC_NUMERIC");
unsetenv("LC_PAPER");
unsetenv("LC_TELEPHONE");
unsetenv("LC_TIME");
#endif // !WIN32
}
} // namespace Opm
#endif

View File

@ -1,135 +0,0 @@
// -*- 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.
*/
/*!
* \file
*
* \brief This is a simple test that illustrates how to use the Opm::ConditionalStorage
* class.
*/
#include "config.h"
#include <opm/common/Unused.hpp>
#include <opm/common/utility/ConditionalStorage.hpp>
#include <string>
#include <cstdlib>
#include <type_traits>
template <bool foo>
class EnsureCompileTimeConstant
{};
class IAmAnIslandLeaveMeAlone
{
public:
IAmAnIslandLeaveMeAlone(int, int)
{}
IAmAnIslandLeaveMeAlone& operator=(const IAmAnIslandLeaveMeAlone&) = delete;
};
int main()
{
{
typedef Opm::ConditionalStorage<true, std::string> ConditionalTrueString;
ConditionalTrueString foo; // default constructor
ConditionalTrueString bar("hello"); // construct using arguments
ConditionalTrueString baz(bar); // copy constructor
EnsureCompileTimeConstant<ConditionalTrueString::condition> hello OPM_UNUSED;
if (!std::is_same<typename ConditionalTrueString::type, std::string>::value)
// something went wrong with the exported type
std::abort();
if (ConditionalTrueString::condition != true)
// the condition is not exported correctly
std::abort();
if (*bar != "hello")
// value constructor did not work
std::abort();
if (*bar != *baz)
// copy constructor did not work
std::abort();
if (foo->size() != 0)
// default constructor did not work
std::abort();
// the assignment operator for the "wrapper" object should work
foo = baz;
if (*foo != *baz)
// assignment operator did not work
std::abort();
}
{
typedef Opm::ConditionalStorage<false, std::string> ConditionalFalseString;
ConditionalFalseString foo; // default constructor
ConditionalFalseString bar("hello"); // construct by value
ConditionalFalseString OPM_UNUSED baz(bar); // copy constructor
EnsureCompileTimeConstant<ConditionalFalseString::condition> hello OPM_UNUSED;
if (!std::is_same<typename ConditionalFalseString::type, std::string>::value)
// something went wrong with the exported type
std::abort();
if (ConditionalFalseString::condition != false)
// the condition is not exported correctly
std::abort();
// the assignment operator for the "wrapper" object should always work
baz = foo;
try {
*bar;
// this is supposed to throw an std::logic_error
std::abort();
}
catch (std::logic_error &) {}
try {
foo->size();
// this is supposed to throw an std::logic_error
std::abort();
}
catch (std::logic_error &) {}
}
{
typedef Opm::ConditionalStorage<true, IAmAnIslandLeaveMeAlone> ConditionalTrueIsland;
ConditionalTrueIsland OPM_UNUSED foo(1, 2);
// ConditionalTrueIsland OPM_UNUSED bar; // compiler fails because of missing default ctor
}
{
typedef Opm::ConditionalStorage<false, IAmAnIslandLeaveMeAlone> ConditionalFalseIsland;
ConditionalFalseIsland OPM_UNUSED foo(1, 2);
// ConditionalFalseIsland OPM_UNUSED bar; // compiler fails because of missing default ctor
}
return 0;
}