Merge pull request #1193 from akva2/move_utils_to_simulators

Move utils to simulators
This commit is contained in:
Atgeirr Flø Rasmussen 2017-12-05 08:36:54 +01:00 committed by GitHub
commit 55348d6441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 0 additions and 571 deletions

View File

@ -76,9 +76,7 @@ list (APPEND MAIN_SOURCE_FILES
opm/core/transport/reorder/TransportSolverTwophaseReorder.cpp
opm/core/transport/reorder/reordersequence.cpp
opm/core/transport/reorder/tarjan.c
opm/core/utility/Event.cpp
opm/core/utility/MonotCubicInterpolator.cpp
opm/core/utility/NullStream.cpp
opm/core/utility/VelocityInterpolation.cpp
opm/core/utility/WachspressCoord.cpp
opm/core/utility/compressedToCartesian.cpp
@ -100,7 +98,6 @@ list (APPEND TEST_SOURCE_FILES
tests/test_compressedpropertyaccess.cpp
tests/test_dgbasis.cpp
tests/test_cubic.cpp
tests/test_event.cpp
tests/test_flowdiagnostics.cpp
tests/test_nonuniformtablelinear.cpp
tests/test_parallelistlinformation.cpp
@ -275,14 +272,9 @@ list (APPEND PUBLIC_HEADER_FILES
opm/core/transport/reorder/reordersequence.h
opm/core/transport/reorder/tarjan.h
opm/core/utility/CompressedPropertyAccess.hpp
opm/core/utility/DataMap.hpp
opm/core/utility/Event.hpp
opm/core/utility/Event_impl.hpp
opm/core/utility/Factory.hpp
opm/core/utility/initHydroCarbonState.hpp
opm/core/utility/MonotCubicInterpolator.hpp
opm/core/utility/NonuniformTableLinear.hpp
opm/core/utility/NullStream.hpp
opm/core/utility/RegionMapping.hpp
opm/core/utility/RootFinders.hpp
opm/core/utility/SparseVector.hpp
@ -292,12 +284,10 @@ list (APPEND PUBLIC_HEADER_FILES
opm/core/utility/buildUniformMonotoneTable.hpp
opm/core/utility/compressedToCartesian.hpp
opm/core/utility/extractPvtTableIndex.hpp
opm/core/utility/have_boost_redef.hpp
opm/core/utility/linearInterpolation.hpp
opm/core/utility/miscUtilities.hpp
opm/core/utility/miscUtilitiesBlackoil.hpp
opm/core/utility/miscUtilities_impl.hpp
opm/core/utility/share_obj.hpp
opm/core/well_controls.h
opm/core/wells.h
opm/core/wells/InjectionSpecification.hpp

View File

@ -1,33 +0,0 @@
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
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_DATAMAP_HEADER_INCLUDED
#define OPM_DATAMAP_HEADER_INCLUDED
#include <map>
#include <string>
#include <vector>
namespace Opm
{
/// Intended to map strings (giving the output field names) to data.
typedef std::map<std::string, const std::vector<double>*> DataMap;
}
#endif

View File

@ -1,22 +0,0 @@
#include <opm/core/utility/Event.hpp>
using namespace std;
using namespace Opm;
Event&
EventSource::add (const std::function<void ()>& handler) {
// add handler to the back of the queue
handlers_.push_back (handler);
// return ourselves so we can be used in a call chain
return *this;
}
void
EventSource::signal () {
// loop through the list of handlers, and invoke every one of them
// (range-based for loops are not available until GCC 4.6)
for (auto it = handlers_.begin(); it != handlers_.end(); ++it) {
(*it) ();
}
}

View File

@ -1,98 +0,0 @@
#ifndef OPM_EVENT_HEADER_INCLUDED
#define OPM_EVENT_HEADER_INCLUDED
// Copyright (C) 2013 Uni Research AS
// This file is licensed under the GNU General Public License v3.0
#include <functional>
#include <list>
namespace Opm {
/// Interface to register interest in receiving notifications when a
/// certain event, such as the completion of a timestep, has happened.
struct Event {
/// Register a callback to receive notifications from this event.
///
/// \param[in] handler
/// Function object that will be invoked when the event happens.
///
/// \return
/// The event object itself, so that multiple additions can be chained.
///
/// \note
/// The event may happen several times, and the handler will receive
/// a notification every time.
///
/// \note
/// If a handler is added more than once, it will also be called
/// more than once.
virtual Event& add (const std::function <void ()>& handler) = 0;
/// Convenience routine to add a member function of a class as
/// an event handler.
///
/// This allows us to have all the necessary information the handler
/// needs put into an object, and then register this with the event.
template <typename T, void (T::*member)()> Event& add (T& t);
};
/// Generator of event notifications.
///
/// As more than one event is possible from an object, it is expected
/// that event servers implements this functionality by aggregation and
/// provide accessors to let clients reach the various events.
///
/// You should not provide the full EventSource interface to clients,
/// as this will allow them to signal the event themselves; rather, return
/// the registration-only parent interface.
///
/// \example
/// You can add an event to your code like this:
///
/// \code{.cpp}
/// struct Foo {
/// // accessor of the event that other can register at
/// Event& completed () { return completed_; }
///
/// // something that ultimately triggers the event
/// void action () { /* ... */ completed_.signal(); }
///
/// private:
/// EventSource completed_;
/// };
/// \endcode
///
/// It could then be accessed by the client like this:
///
/// \code{.cpp}
/// struct Bar {
/// void callMe() { /* ... */ }
/// };
/// \endcode
///
/// \code{.cpp}
/// Foo foo;
/// Bar bar;
///
/// // setup the connection between the two
/// foo.completed().add<Bar, &Bar::callMe>(bar);
///
/// // set events in motion
/// foo.action();
/// \endcode
class EventSource : public Event {
public:
virtual Event& add (const std::function <void ()>& handler);
virtual void signal ();
protected:
/// List of actual handlers that will be called
std::list <std::function <void ()> > handlers_;
};
// inline definitions
#include "Event_impl.hpp"
} /* namespace Opm */
#endif /* OPM_EVENT_HEADER_INCLUDED */

View File

@ -1,13 +0,0 @@
// Copyright (C) 2013 Uni Research AS
// This file is licensed under the GNU General Public License v3.0
#ifndef OPM_EVENT_HEADER_INCLUDED
#error Do NOT include this file directly!
#endif /* OPM_EVENT_HEADER_INCLUDED */
template <typename T, void (T::*member)()> inline Event&
Event::add (T& t) {
// wrap the member function in a std::function and add that
// notice the use of ref() to avoid invoking the copy constructor
return this->add (std::bind (member, std::ref(t)));
}

View File

@ -1,174 +0,0 @@
//===========================================================================
//
// File: Factory.hpp
//
// Created: Mon Nov 6 10:00:43 2000
//
// Author(s): Atgeirr F Rasmussen <atgeirr@sintef.no>
//
// $Date$
//
// $Revision$
//
//===========================================================================
/*
Copyright 2009, 2010 SINTEF ICT, Applied Mathematics.
Copyright 2009, 2010 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_FACTORY_HEADER
#define OPM_FACTORY_HEADER
#include <opm/common/ErrorMacros.hpp>
#include <map>
#include <memory>
namespace Opm
{
/** This is an object factory for creating objects of some type
* requested by the user, with a shared base class. The user
* need only interact with the factory through the static
* template member addCreator() and the static member function
* createObject().
*/
template<class Base>
class Factory
{
public:
/// The type of pointer returned by createObject().
typedef std::shared_ptr<Base> ProductPtr;
/// Creates a new object of the class associated with the given type string,
/// and returns a pointer to it.
/// \param type the type string of the class that the user wants to have
/// constructed.
/// \return (smart) pointer to the created object.
static ProductPtr createObject(const std::string& type)
{
return instance().doCreateObject(type);
}
/// Clones an new object of the class associated with the given type string,
/// and returns a pointer to it.
/// \param type the type string of the class that the user wants to have
/// constructed.
/// \param original (smart) pointer to object to be cloned.
/// \return (smart) pointer to the created object.
static ProductPtr cloneObject(const std::string& type,
const ProductPtr original)
{
return instance().doCloneObject(type, original);
}
/// Add a creator to the Factory.
/// After the call, the user may obtain new objects of the Derived type by
/// calling createObject() with the given type string as an argument.
/// \tparam Derived the class we want to add a creator for, must inherit
/// the class template parameter Base.
/// \param type the type string with which we want the Factory to associate
/// the class Derived.
template<class Derived>
static void addCreator(const std::string& type)
{
instance().template doAddCreator<Derived>(type);
}
private:
// The method that implements the singleton pattern,
// using the Meyers singleton technique.
static Factory& instance()
{
static Factory singleton;
return singleton;
}
// Private constructor, to keep users from creating a Factory.
Factory()
{
}
// Abstract base class for Creators.
class Creator
{
public:
virtual ProductPtr create() = 0;
virtual ProductPtr clone(ProductPtr original) = 0;
virtual ~Creator() {}
};
/// This is the concrete Creator subclass for generating Derived objects.
template<class Derived>
class ConcreteCreator: public Creator
{
public:
virtual ProductPtr create()
{
return ProductPtr(new Derived);
}
virtual ProductPtr clone(const ProductPtr original)
{
const Derived& orig = dynamic_cast<const Derived&>(*original);
return ProductPtr(new Derived(orig));
}
};
typedef std::shared_ptr<Creator> CreatorPtr;
typedef std::map<std::string, CreatorPtr> CreatorMap;
// This map contains the whole factory, i.e. all the Creators.
CreatorMap string_to_creator_;
// Actually creates the product object.
ProductPtr doCreateObject(const std::string& type)
{
typename CreatorMap::iterator it;
it = string_to_creator_.find(type);
if (it == string_to_creator_.end()) {
OPM_THROW(std::runtime_error, "Creator type " << type
<< " is not registered in the factory.");
}
return it->second->create();
}
// Actually clones the product object.
ProductPtr doCloneObject(const std::string& type,
const ProductPtr original)
{
typename CreatorMap::iterator it;
it = string_to_creator_.find(type);
if (it == string_to_creator_.end()) {
OPM_THROW(std::runtime_error, "Creator type " << type
<< " is not registered in the factory.");
}
return it->second->clone(original);
}
// Actually adds the creator.
template<class Derived>
void doAddCreator(const std::string& type)
{
CreatorPtr c(new ConcreteCreator<Derived>);
string_to_creator_[type] = c;
}
};
} // namespace Opm
#endif // OPM_FACTORY_HEADER

View File

@ -1,20 +0,0 @@
// Copyright (C) 2013 Uni Research AS
// This file is licensed under the GNU General Public License v3.0
#include <opm/core/utility/NullStream.hpp>
#include <ostream>
#include <streambuf>
// buffer that ignores everything
// see <http://forums.codeguru.com/showthread.php?460071-ostream-bit-bucket>
struct NullBuf : public std::streambuf {};
static NullBuf null_buf_impl;
// link the stream up to the black hole buffer
struct NullStream : public std::ostream {
NullStream () : std::ostream (&null_buf_impl) {}
};
// create a singleton and point the reference to it
static NullStream null_stream_impl;
std::ostream& Opm::null_stream = null_stream_impl;

View File

@ -1,30 +0,0 @@
#ifndef OPM_NULLSTREAM_HEADER_INCLUDED
#define OPM_NULLSTREAM_HEADER_INCLUDED
// Copyright (C) 2013 Uni Research AS
// This file is licensed under the GNU General Public License v3.0
#include <iosfwd>
namespace Opm {
/**
* Output stream that ignores everything written to it.
*
* Use this stream if you want to disable output without having a
* lot of conditionals in your code.
*
* Since the null stream has no state, there is no point in
* instantiating your own; simply use this reference instead.
*
* @example
* @code{.cpp}
* std::ostream& outp = (quiet ? Opm::null_stream : std::cerr);
* outp << "Hello, World!" << std::endl;
* @endcode
*/
extern std::ostream& null_stream;
} /* namespace Opm */
#endif /* OPM_NULLSTREAM_HEADER_INCLUDED */

View File

@ -1,44 +0,0 @@
/*===========================================================================
//
// File: have_boost_redef.hpp
//
// Created: 2012-07-12 11:02:22+0200
//
//==========================================================================*/
/*
Copyright 2012 SINTEF ICT, Applied Mathematics.
Copyright 2012 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/>.
*/
// Note: This file should be #include<>d after <config.h> in software
// that uses the ISTL. This is more or less a hack to work around
// Autoconfs that do not correctly process dune-istl's `ENABLE_BOOST'
// feature. We will happily remove this file if a better solution
// presents.
#ifndef OPM_HAVE_BOOST_REDEF_HPP_HEADER
#define OPM_HAVE_BOOST_REDEF_HPP_HEADER
#if defined(HAVE_BOOST)
#undef HAVE_BOOST
#define HAVE_BOOST OPM_HAVE_BOOST
#endif
#endif /* OPM_HAVE_BOOST_REDEF_HPP_HEADER */

View File

@ -1,49 +0,0 @@
/*
Copyright (c) 2013 Uni Research AS
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_SHARE_OBJ_HPP
#define OPM_SHARE_OBJ_HPP
#include <memory> // shared_ptr
namespace Opm {
/// Custom deleter that does nothing
inline void no_delete (void const *) { }
/*!
* Share pointer of a local object.
*
* Use this wrapper when an interface needs a shared_ptr, but you
* want to pass an object that has local storage (and you know
* that the shared_ptr client doesn't need it outside of the scope).
*
* \example
* \code{.cpp}
* Foo obj;
* std::shared_ptr <Foo> ptr = share_obj (obj);
* \endcode
*/
template <typename T> std::shared_ptr <T> share_obj (T& t) {
return std::shared_ptr <T> (&t, no_delete);
}
} // namespace Opm
#endif /* OPM_SHARE_OBJ_HPP */

View File

@ -1,78 +0,0 @@
/* Copyright 2013 Uni Research AS
* This file is licensed under GPL3, see http://www.opm-project.org/
*/
#include <config.h>
/* --- Boost.Test boilerplate --- */
#if HAVE_DYNAMIC_BOOST_TEST
#define BOOST_TEST_DYN_LINK
#endif
#define NVERBOSE // Suppress own messages when throw()ing
#define BOOST_TEST_MODULE EventTest
#include <boost/test/unit_test.hpp>
/* --- our own headers --- */
#include <opm/core/utility/Event.hpp>
using namespace std;
using namespace Opm;
// idiomatic implementation of generator and receiver
struct EventGenerator {
EventSource eventSource_;
Event& event () { return eventSource_; }
void action () { eventSource_.signal (); }
};
struct EventReceiver {
int numOfCalls;
EventReceiver () : numOfCalls (0) { }
void handler () { ++numOfCalls; }
private:
// make sure bind() doesn't implement copy constructor
EventReceiver (EventReceiver&);
};
// declare a generator, a receiver and connect them
struct EventFixture {
EventGenerator gen;
EventReceiver recv;
void register_handler () {
gen.event().add<EventReceiver,&EventReceiver::handler>(recv);
}
EventFixture () {
register_handler();
}
};
BOOST_FIXTURE_TEST_SUITE(EventTest, EventFixture)
BOOST_AUTO_TEST_CASE(none)
{
BOOST_REQUIRE_EQUAL (recv.numOfCalls, 0);
}
BOOST_AUTO_TEST_CASE(once)
{
gen.action();
BOOST_REQUIRE_EQUAL (recv.numOfCalls, 1);
}
BOOST_AUTO_TEST_CASE(twice)
{
gen.action();
gen.action();
BOOST_REQUIRE_EQUAL (recv.numOfCalls, 2);
}
BOOST_AUTO_TEST_CASE(reg_twice)
{
register_handler();
gen.action();
BOOST_REQUIRE_EQUAL (recv.numOfCalls, 2);
}
BOOST_AUTO_TEST_SUITE_END()