diff --git a/opm/parser/eclipse/CMakeLists.txt b/opm/parser/eclipse/CMakeLists.txt
index d8612d385..3358a1c27 100644
--- a/opm/parser/eclipse/CMakeLists.txt
+++ b/opm/parser/eclipse/CMakeLists.txt
@@ -48,7 +48,7 @@ Parser/ParserStringItem.cpp
set (state_source
EclipseState/Schedule/TimeMap.cpp
-EclipseState/Schedule/Schedule.cpp )
+EclipseState/Schedule/Schedule.cpp
EclipseState/Schedule/Well.cpp )
set( HEADER_FILES
@@ -79,6 +79,7 @@ Parser/ParserStringItem.hpp
EclipseState/Schedule/TimeMap.hpp
EclipseState/Schedule/Schedule.hpp
EclipseState/Schedule/Well.hpp
+EclipseState/Schedule/DynamicState.hpp
)
add_library(buildParser ${rawdeck_source} ${build_parser_source} ${deck_source})
diff --git a/opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp b/opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp
new file mode 100644
index 000000000..3cc8a416c
--- /dev/null
+++ b/opm/parser/eclipse/EclipseState/Schedule/DynamicState.hpp
@@ -0,0 +1,85 @@
+/*
+ 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 .
+*/
+
+
+#ifndef DYNAMICSTATE_HPP_
+#define DYNAMICSTATE_HPP_
+
+#include
+#include
+#include
+#include
+
+
+namespace Opm {
+
+ template
+ class DynamicState {
+ public:
+
+ DynamicState(const TimeMapConstPtr timeMap, T defaultValue) {
+ m_timeMap = timeMap;
+ m_currentValue = defaultValue;
+ }
+
+
+ T get(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_currentValue;
+
+ return m_data[index];
+ }
+
+
+ void add(size_t index , T value) {
+ if (index >= (m_timeMap->size() - 1))
+ throw std::range_error("Index value is out range - can not add elements to the last timestep.");
+
+ if (m_data.size() > 0) {
+ if (index < (m_data.size() - 1))
+ throw std::invalid_argument("Elements must be added in weakly increasing order");
+ }
+
+ {
+ size_t currentSize = m_data.size();
+ if (currentSize <= index) {
+ for (size_t i = currentSize; i <= index; i++)
+ m_data.push_back( m_currentValue );
+ }
+ }
+
+ m_data[index] = value;
+ m_currentValue = value;
+ }
+
+
+
+ private:
+ std::vector m_data;
+ TimeMapConstPtr m_timeMap;
+ T m_currentValue;
+ };
+}
+
+
+
+#endif
diff --git a/opm/parser/eclipse/EclipseState/Schedule/tests/CMakeLists.txt b/opm/parser/eclipse/EclipseState/Schedule/tests/CMakeLists.txt
index 43abd40ad..10813457a 100644
--- a/opm/parser/eclipse/EclipseState/Schedule/tests/CMakeLists.txt
+++ b/opm/parser/eclipse/EclipseState/Schedule/tests/CMakeLists.txt
@@ -6,3 +6,13 @@ add_test(NAME runTimeMapTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${
add_executable(runScheduleTests ScheduleTests.cpp)
target_link_libraries(runScheduleTests Parser ${Boost_LIBRARIES})
add_test(NAME runScheduleTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runScheduleTests )
+
+
+add_executable(runWellTests WellTests.cpp)
+target_link_libraries(runWellTests Parser ${Boost_LIBRARIES})
+add_test(NAME runWellTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runWellTests )
+
+
+add_executable(runDynamicStateTests DynamicStateTests.cpp)
+target_link_libraries(runDynamicStateTests Parser ${Boost_LIBRARIES})
+add_test(NAME runDynamicStateTests WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${EXECUTABLE_OUTPUT_PATH}/runDynamicStateTests )
diff --git a/opm/parser/eclipse/EclipseState/Schedule/tests/DynamicStateTests.cpp b/opm/parser/eclipse/EclipseState/Schedule/tests/DynamicStateTests.cpp
new file mode 100644
index 000000000..e35f76304
--- /dev/null
+++ b/opm/parser/eclipse/EclipseState/Schedule/tests/DynamicStateTests.cpp
@@ -0,0 +1,111 @@
+/*
+ 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 .
+ */
+
+#include
+#include
+#include
+
+
+#define BOOST_TEST_MODULE DynamicStateTests
+#include
+#include
+
+
+#include
+#include
+#include
+
+
+
+BOOST_AUTO_TEST_CASE(CreateDynamicTest) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 9.99);
+}
+
+
+BOOST_AUTO_TEST_CASE(DynamicStateGetOutOfRangeThrows) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 9.99);
+ BOOST_CHECK_THROW( state.get(1) , std::range_error);
+}
+
+
+BOOST_AUTO_TEST_CASE(DynamicStateGetDefault) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 137);
+ BOOST_CHECK_EQUAL( 137 , state.get(0));
+}
+
+
+BOOST_AUTO_TEST_CASE(DynamicStateSetOutOfRangeThrows) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 137);
+ for (size_t i = 0; i < 2; i++)
+ timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
+
+ BOOST_CHECK_THROW( state.add(2 , 100) , std::range_error);
+}
+
+
+BOOST_AUTO_TEST_CASE(DynamicStateSetOK) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 137);
+ for (size_t i = 0; i < 10; i++)
+ timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
+
+ state.add(2 , 23 );
+ BOOST_CHECK_EQUAL( 137 , state.get(0));
+ BOOST_CHECK_EQUAL( 137 , state.get(1));
+ BOOST_CHECK_EQUAL( 23 , state.get(2));
+ BOOST_CHECK_EQUAL( 23 , state.get(5));
+
+ state.add(2 , 17);
+ BOOST_CHECK_EQUAL( 137 , state.get(0));
+ BOOST_CHECK_EQUAL( 137 , state.get(1));
+ BOOST_CHECK_EQUAL( 17 , state.get(2));
+ BOOST_CHECK_EQUAL( 17 , state.get(5));
+
+ state.add(6 , 60);
+ BOOST_CHECK_EQUAL( 17 , state.get(2));
+ BOOST_CHECK_EQUAL( 17 , state.get(5));
+ BOOST_CHECK_EQUAL( 60 , state.get(6));
+ BOOST_CHECK_EQUAL( 60 , state.get(8));
+ BOOST_CHECK_EQUAL( 60 , state.get(9));
+}
+
+
+
+BOOST_AUTO_TEST_CASE(DynamicStateAddIndexAlreadySetThrows) {
+ boost::gregorian::date startDate( 2010 , boost::gregorian::Jan , 1);
+ Opm::TimeMapPtr timeMap(new Opm::TimeMap(startDate));
+ Opm::DynamicState state(timeMap , 137);
+ for (size_t i = 0; i < 10; i++)
+ timeMap->addTStep( boost::posix_time::hours( (i+1) * 24 ));
+
+ state.add( 5 , 60);
+ BOOST_CHECK_THROW( state.add(3 , 78) , std::invalid_argument);
+}
+
+
+