/* Copyright 2015 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 namespace Opm { SCHEDULESection::SCHEDULESection(DeckConstPtr deck) : Section(deck, "SCHEDULE") { populateDeckTimeSteps(); } DeckTimeStepConstPtr SCHEDULESection::getDeckTimeStep(size_t timestep) const { if (timestep < m_decktimesteps.size()) { return m_decktimesteps[timestep]; } else { throw std::out_of_range("No DeckTimeStep in ScheduleSection for timestep " + std::to_string(timestep)); } } void SCHEDULESection::populateDeckTimeSteps() { DeckTimeStepPtr currentTimeStep = std::make_shared(); for (auto iter = begin(); iter != end(); ++iter) { //Loop keywords in schedule section auto keyword = *iter; if (keyword->name() == "TSTEP") { DeckItemPtr items = keyword->getDataRecord()->getDataItem(); for (size_t item_iter = 0; item_iter < items->size(); ++item_iter) { m_decktimesteps.push_back(currentTimeStep); currentTimeStep = std::make_shared(); } } else if (keyword->name() == "DATES") { for (auto record_iter = keyword->begin(); record_iter != keyword->end(); ++record_iter ) { m_decktimesteps.push_back(currentTimeStep); currentTimeStep = std::make_shared(); } } else { currentTimeStep->addKeyword(keyword); } } //push last step m_decktimesteps.push_back(currentTimeStep); } }