commit
4178257b17
@ -189,6 +189,7 @@ EclipseState/Schedule/WellPolymerProperties.hpp
|
||||
EclipseState/Schedule/WellSet.hpp
|
||||
EclipseState/Schedule/Group.hpp
|
||||
EclipseState/Schedule/DynamicState.hpp
|
||||
EclipseState/Schedule/DynamicVector.hpp
|
||||
EclipseState/Schedule/Completion.hpp
|
||||
EclipseState/Schedule/CompletionSet.hpp
|
||||
EclipseState/Schedule/ScheduleEnums.hpp
|
||||
|
93
opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp
Normal file
93
opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
Copyright 2013 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 DYNAMICVECTOR_HPP_
|
||||
#define DYNAMICVECTOR_HPP_
|
||||
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <boost/date_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
/*
|
||||
The DynamicVector<T> class is a thin wrapper around
|
||||
std::vector<T> with the following twists:
|
||||
|
||||
- The vector is bound to a TimeMap instance.
|
||||
|
||||
- The operator[] supports arbitrary assignment - the vector
|
||||
will grow as needed, however it will *not* grow beyond the
|
||||
length of the TimeMap.
|
||||
|
||||
- The vector is created with a default value which will be
|
||||
used to 'fill in the holes' when growing; and that value
|
||||
will also be returned if you ask for values beyond the end
|
||||
of the vector.
|
||||
*/
|
||||
|
||||
template <class T>
|
||||
class DynamicVector {
|
||||
public:
|
||||
|
||||
|
||||
DynamicVector(const TimeMapConstPtr timeMap, T defaultValue) {
|
||||
m_timeMap = timeMap;
|
||||
m_defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
|
||||
const T& operator[](size_t index) const {
|
||||
if (index >= m_timeMap->size())
|
||||
throw std::range_error("Index value is out range.");
|
||||
|
||||
if (index < m_data.size())
|
||||
return m_data[index];
|
||||
else
|
||||
return m_defaultValue;
|
||||
}
|
||||
|
||||
|
||||
T& operator[](size_t index) {
|
||||
if (index >= m_timeMap->size())
|
||||
throw std::range_error("Index value is out range.");
|
||||
|
||||
if (index >= m_data.size())
|
||||
m_data.resize( index + 1 , m_defaultValue);
|
||||
|
||||
return m_data[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::vector<T> m_data;
|
||||
TimeMapConstPtr m_timeMap;
|
||||
T m_defaultValue;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -22,26 +22,22 @@
|
||||
|
||||
namespace Opm {
|
||||
|
||||
Events::Events() {
|
||||
Events::Events(std::shared_ptr<const TimeMap> timeMap)
|
||||
: m_events( DynamicVector<uint64_t>( timeMap , 0 ) )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Events::hasEvent(ScheduleEvents::Events event, size_t reportStep) const {
|
||||
if (reportStep < m_events.size()) {
|
||||
uint64_t eventSum = m_events[reportStep];
|
||||
if (eventSum & event)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else
|
||||
uint64_t eventSum = m_events[reportStep];
|
||||
if (eventSum & event)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Events::addEvent(ScheduleEvents::Events event, size_t reportStep) {
|
||||
if (m_events.size() <= reportStep)
|
||||
m_events.resize( 2 * reportStep + 1 );
|
||||
|
||||
m_events[reportStep] |= event;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp>
|
||||
|
||||
namespace Opm
|
||||
{
|
||||
namespace ScheduleEvents {
|
||||
@ -84,11 +86,11 @@ namespace Opm
|
||||
|
||||
class Events {
|
||||
public:
|
||||
Events();
|
||||
Events(std::shared_ptr<const TimeMap> timeMap);
|
||||
void addEvent(ScheduleEvents::Events event, size_t reportStep);
|
||||
bool hasEvent(ScheduleEvents::Events event, size_t reportStep) const;
|
||||
private:
|
||||
std::vector<uint64_t> m_events;
|
||||
DynamicVector<uint64_t> m_events;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ namespace Opm {
|
||||
initializeNOSIM(deck);
|
||||
createTimeMap(deck);
|
||||
m_tuning.reset(new Tuning(m_timeMap));
|
||||
m_events.reset(new Events(m_timeMap));
|
||||
addGroup( "FIELD", 0 );
|
||||
initRootGroupTreeNode(getTimeMap());
|
||||
initOilVaporization(getTimeMap());
|
||||
@ -306,7 +307,7 @@ namespace Opm {
|
||||
|
||||
if (needNewTree) {
|
||||
m_rootGroupTree->update(currentStep, newTree);
|
||||
m_events.addEvent( ScheduleEvents::GROUP_CHANGE , currentStep);
|
||||
m_events->addEvent( ScheduleEvents::GROUP_CHANGE , currentStep);
|
||||
}
|
||||
}
|
||||
|
||||
@ -411,8 +412,8 @@ namespace Opm {
|
||||
}
|
||||
updateWellStatus( well , currentStep , status );
|
||||
if (well->setProductionProperties(currentStep, properties))
|
||||
m_events.addEvent( ScheduleEvents::PRODUCTION_UPDATE , currentStep);
|
||||
|
||||
m_events->addEvent( ScheduleEvents::PRODUCTION_UPDATE , currentStep);
|
||||
|
||||
if ( !well->getAllowCrossFlow() && !isPredictionMode && (properties.OilRate + properties.WaterRate + properties.GasRate) == 0 ) {
|
||||
|
||||
std::string msg =
|
||||
@ -421,14 +422,13 @@ namespace Opm {
|
||||
OpmLog::addMessage(Log::MessageType::Info , Log::prefixMessage(Log::MessageType::Info, msg));
|
||||
updateWellStatus(well, currentStep, WellCommon::StatusEnum::SHUT );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Schedule::updateWellStatus(std::shared_ptr<Well> well, size_t reportStep , WellCommon::StatusEnum status) {
|
||||
if (well->setStatus( reportStep , status ))
|
||||
m_events.addEvent( ScheduleEvents::WELL_STATUS_CHANGE , reportStep );
|
||||
m_events->addEvent( ScheduleEvents::WELL_STATUS_CHANGE , reportStep );
|
||||
}
|
||||
|
||||
|
||||
@ -587,7 +587,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
if (well->setInjectionProperties(currentStep, properties))
|
||||
m_events.addEvent( ScheduleEvents::INJECTION_UPDATE , currentStep );
|
||||
m_events->addEvent( ScheduleEvents::INJECTION_UPDATE , currentStep );
|
||||
|
||||
if ( ! well->getAllowCrossFlow() && (properties.surfaceInjectionRate == 0) ) {
|
||||
std::string msg =
|
||||
@ -678,7 +678,7 @@ namespace Opm {
|
||||
properties.predictionMode = false;
|
||||
|
||||
if (well->setInjectionProperties(currentStep, properties))
|
||||
m_events.addEvent( ScheduleEvents::INJECTION_UPDATE , currentStep );
|
||||
m_events->addEvent( ScheduleEvents::INJECTION_UPDATE , currentStep );
|
||||
|
||||
if ( ! well->getAllowCrossFlow() && (injectionRate == 0) ) {
|
||||
std::string msg =
|
||||
@ -687,7 +687,6 @@ namespace Opm {
|
||||
OpmLog::addMessage(Log::MessageType::Info , Log::prefixMessage(Log::MessageType::Info, msg));
|
||||
updateWellStatus(well, currentStep, WellCommon::StatusEnum::SHUT );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -771,7 +770,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
well->addCompletionSet(currentStep, newCompletionSet);
|
||||
m_events.addEvent(ScheduleEvents::COMPLETION_CHANGE, currentStep);
|
||||
m_events->addEvent(ScheduleEvents::COMPLETION_CHANGE, currentStep);
|
||||
if (newCompletionSet->allCompletionsShut())
|
||||
updateWellStatus( well , currentStep , WellCommon::StatusEnum::SHUT);
|
||||
|
||||
@ -1224,7 +1223,7 @@ namespace Opm {
|
||||
WellPtr well = getWell(wellName);
|
||||
well->addCompletions(currentStep, iter->second);
|
||||
}
|
||||
m_events.addEvent(ScheduleEvents::COMPLETION_CHANGE, currentStep);
|
||||
m_events->addEvent(ScheduleEvents::COMPLETION_CHANGE, currentStep);
|
||||
}
|
||||
|
||||
void Schedule::handleWGRUPCON(DeckKeywordConstPtr keyword, size_t currentStep) {
|
||||
@ -1371,7 +1370,7 @@ namespace Opm {
|
||||
|
||||
well = std::make_shared<Well>(wellName, m_grid , headI, headJ, refDepth, preferredPhase, m_timeMap , timeStep, wellCompletionOrder, allowCrossFlow);
|
||||
m_wells.insert( wellName , well);
|
||||
m_events.addEvent( ScheduleEvents::NEW_WELL , timeStep );
|
||||
m_events->addEvent( ScheduleEvents::NEW_WELL , timeStep );
|
||||
}
|
||||
|
||||
size_t Schedule::numWells() const {
|
||||
@ -1451,7 +1450,7 @@ namespace Opm {
|
||||
}
|
||||
GroupPtr group(new Group(groupName, m_timeMap , timeStep));
|
||||
m_groups[ groupName ] = group;
|
||||
m_events.addEvent( ScheduleEvents::NEW_GROUP , timeStep );
|
||||
m_events->addEvent( ScheduleEvents::NEW_GROUP , timeStep );
|
||||
}
|
||||
|
||||
size_t Schedule::numGroups() const {
|
||||
@ -1552,7 +1551,7 @@ namespace Opm {
|
||||
}
|
||||
|
||||
const Events& Schedule::getEvents() const {
|
||||
return m_events;
|
||||
return *m_events;
|
||||
}
|
||||
|
||||
OilVaporizationPropertiesConstPtr Schedule::getOilVaporizationProperties(size_t timestep){
|
||||
|
@ -82,7 +82,7 @@ namespace Opm
|
||||
std::map<std::string , GroupPtr> m_groups;
|
||||
std::shared_ptr<DynamicState<GroupTreePtr> > m_rootGroupTree;
|
||||
std::shared_ptr<DynamicState<OilVaporizationPropertiesPtr> > m_oilvaporizationproperties;
|
||||
Events m_events;
|
||||
std::shared_ptr<Events> m_events;
|
||||
TuningPtr m_tuning;
|
||||
bool nosim;
|
||||
|
||||
|
@ -4,7 +4,7 @@ foreach(tapp TimeMapTest ScheduleTests WellTests
|
||||
CompletionTests CompletionSetTests
|
||||
DynamicStateTests GroupTreeNodeTests
|
||||
GroupTreeTests TuningTests EventTests
|
||||
WellSolventTests)
|
||||
WellSolventTests DynamicVectorTests)
|
||||
opm_add_test(run${tapp} SOURCES ${tapp}.cpp
|
||||
LIBRARIES opmparser ${Boost_LIBRARIES})
|
||||
endforeach()
|
||||
|
@ -0,0 +1,70 @@
|
||||
/*
|
||||
Copyright 2013 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 <stdexcept>
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
|
||||
#define BOOST_TEST_MODULE DynamicVectorTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Well.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/DynamicVector.hpp>
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateDynamicTest) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMapPtr timeMap(new Opm::TimeMap(boost::posix_time::ptime(startDate)));
|
||||
Opm::DynamicVector<double> vector(timeMap , 9.99);
|
||||
|
||||
BOOST_CHECK_EQUAL( vector[0] , 9.99 );
|
||||
BOOST_CHECK_THROW( vector[1] , std::range_error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(DynamicVectorSet) {
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMapPtr timeMap(new Opm::TimeMap(boost::posix_time::ptime(startDate)));
|
||||
Opm::DynamicVector<int> state(timeMap , 137);
|
||||
for (size_t i = 0; i < 4; i++)
|
||||
timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
|
||||
|
||||
BOOST_CHECK_EQUAL( 137 , state[0] );
|
||||
BOOST_CHECK_EQUAL( 137 , state[1] );
|
||||
BOOST_CHECK_EQUAL( 137 , state[2] );
|
||||
BOOST_CHECK_EQUAL( 137 , state[3] );
|
||||
BOOST_CHECK_EQUAL( 137 , state[4] );
|
||||
|
||||
state[2] = 99;
|
||||
BOOST_CHECK_EQUAL( 137 , state[1] );
|
||||
BOOST_CHECK_EQUAL( 99 , state[2] );
|
||||
BOOST_CHECK_EQUAL( 137 , state[3] );
|
||||
|
||||
state[0] = 88;
|
||||
BOOST_CHECK_EQUAL( 88 , state[0]);
|
||||
BOOST_CHECK_THROW( state[5] = 99 , std::range_error);
|
||||
}
|
||||
|
@ -21,14 +21,21 @@
|
||||
#include <iostream>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#define BOOST_TEST_MODULE CompletionSetTests
|
||||
#define BOOST_TEST_MODULE EventTests
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/TimeMap.hpp>
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Events.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(CreateEmpty) {
|
||||
Opm::Events events;
|
||||
boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
|
||||
Opm::TimeMapPtr timeMap(new Opm::TimeMap(boost::posix_time::ptime(startDate)));
|
||||
Opm::DynamicVector<double> vector(timeMap , 9.99);
|
||||
Opm::Events events( timeMap );
|
||||
|
||||
for (size_t i = 0; i < 11; i++)
|
||||
timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
|
||||
|
||||
BOOST_CHECK_EQUAL( false , events.hasEvent(Opm::ScheduleEvents::NEW_WELL , 10));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user