Merge pull request #2664 from joakim-hove/rst-actionx-keywords
Rst actionx keywords
This commit is contained in:
commit
8f263e637b
@ -26,6 +26,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Enums.hpp>
|
||||
#include <opm/parser/eclipse/Deck/DeckKeyword.hpp>
|
||||
|
||||
namespace Opm {
|
||||
|
||||
@ -64,6 +65,7 @@ struct RstAction {
|
||||
double min_wait;
|
||||
std::time_t start_time;
|
||||
std::vector<Condition> conditions;
|
||||
std::vector<DeckKeyword> keywords;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ namespace Opm {
|
||||
class EclipseGrid;
|
||||
class Parser;
|
||||
class Actdims;
|
||||
class Parser;
|
||||
} // namespace Opm
|
||||
|
||||
namespace Opm { namespace EclIO {
|
||||
@ -102,14 +103,16 @@ private:
|
||||
const std::vector<double>& dudg,
|
||||
const std::vector<double>& dudf);
|
||||
|
||||
void add_actions(const Actdims& actdims,
|
||||
void add_actions(const Parser& parser,
|
||||
const Actdims& actdims,
|
||||
std::time_t sim_time,
|
||||
const std::vector<std::string>& zact,
|
||||
const std::vector<int>& iact,
|
||||
const std::vector<float>& sact,
|
||||
const std::vector<std::string>& zacn,
|
||||
const std::vector<int>& iacn,
|
||||
const std::vector<double>& sacn);
|
||||
const std::vector<double>& sacn,
|
||||
const std::vector<std::string>& zlact);
|
||||
|
||||
};
|
||||
|
||||
|
@ -95,6 +95,12 @@ namespace Opm { namespace RestartIO { namespace Helpers { namespace VectorItems
|
||||
constexpr std::size_t ConditionSize = 13;
|
||||
}
|
||||
|
||||
namespace ZLACT {
|
||||
|
||||
constexpr std::size_t max_line_length = 128;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}}} // Opm::RestartIO::Helpers::VectorItems
|
||||
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
std::size_t max_line_count() const;
|
||||
std::size_t max_characters() const;
|
||||
std::size_t max_conditions() const;
|
||||
std::size_t line_size() const;
|
||||
|
||||
bool operator==(const Actdims& data) const;
|
||||
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include <opm/io/eclipse/rst/state.hpp>
|
||||
#include <opm/output/eclipse/WriteRestartHelpers.hpp>
|
||||
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
#include <opm/common/utility/String.hpp>
|
||||
#include <opm/parser/eclipse/Parser/Parser.hpp>
|
||||
#include <opm/output/eclipse/UDQDims.hpp>
|
||||
#include <opm/output/eclipse/VectorItems/connection.hpp>
|
||||
@ -276,21 +278,24 @@ std::string oper_string(Action::Logical logic) {
|
||||
}
|
||||
|
||||
|
||||
void RstState::add_actions(const Actdims& actdims,
|
||||
void RstState::add_actions(const Parser& parser,
|
||||
const Actdims& actdims,
|
||||
std::time_t sim_time,
|
||||
const std::vector<std::string>& zact,
|
||||
const std::vector<int>& iact,
|
||||
const std::vector<float>& sact,
|
||||
const std::vector<std::string>& zacn,
|
||||
const std::vector<int>& iacn,
|
||||
const std::vector<double>& sacn)
|
||||
const std::vector<double>& sacn,
|
||||
const std::vector<std::string>& zlact)
|
||||
{
|
||||
auto zact_action_size = RestartIO::Helpers::entriesPerZACT();
|
||||
auto iact_action_size = RestartIO::Helpers::entriesPerIACT();
|
||||
auto sact_action_size = RestartIO::Helpers::entriesPerSACT();
|
||||
auto zacn_action_size = RestartIO::Helpers::entriesPerZACN(actdims);
|
||||
auto iacn_action_size = RestartIO::Helpers::entriesPerIACN(actdims);
|
||||
auto sacn_action_size = RestartIO::Helpers::entriesPerSACN(actdims);
|
||||
auto zact_action_size = RestartIO::Helpers::entriesPerZACT();
|
||||
auto iact_action_size = RestartIO::Helpers::entriesPerIACT();
|
||||
auto sact_action_size = RestartIO::Helpers::entriesPerSACT();
|
||||
auto zacn_action_size = RestartIO::Helpers::entriesPerZACN(actdims);
|
||||
auto iacn_action_size = RestartIO::Helpers::entriesPerIACN(actdims);
|
||||
auto sacn_action_size = RestartIO::Helpers::entriesPerSACN(actdims);
|
||||
auto zlact_action_size = zlact.size() / this->header.num_action;
|
||||
|
||||
auto zacn_cond_size = 13;
|
||||
auto iacn_cond_size = 26;
|
||||
@ -311,6 +316,28 @@ void RstState::add_actions(const Actdims& actdims,
|
||||
const auto& max_run = iact[index * iact_action_size + 5];
|
||||
const auto& min_wait = this->unit_system.to_si(UnitSystem::measure::time, sact[index * sact_action_size + 3]);
|
||||
this->actions.emplace_back(name, max_run, min_wait, sim_time, conditions );
|
||||
|
||||
|
||||
std::string action_deck;
|
||||
auto zlact_offset = index * zlact_action_size;
|
||||
while (true) {
|
||||
std::string line;
|
||||
for (std::size_t item_index = 0; item_index < actdims.line_size(); item_index++)
|
||||
line += zlact[zlact_offset + item_index];
|
||||
|
||||
line = trim_copy(line);
|
||||
if (line.empty())
|
||||
continue;
|
||||
|
||||
if (line == "ENDACTIO")
|
||||
break;
|
||||
|
||||
action_deck += line + "\n";
|
||||
zlact_offset += actdims.line_size();
|
||||
}
|
||||
const auto& deck = parser.parseString( action_deck );
|
||||
for (auto keyword : deck)
|
||||
this->actions.back().keywords.push_back(std::move(keyword));
|
||||
}
|
||||
}
|
||||
|
||||
@ -329,7 +356,7 @@ const RstWell& RstState::get_well(const std::string& wname) const {
|
||||
|
||||
RstState RstState::load(std::shared_ptr<EclIO::RestartFileView> rstView,
|
||||
const Runspec& runspec,
|
||||
const Parser&,
|
||||
const Parser& parser,
|
||||
const ::Opm::EclipseGrid* grid)
|
||||
{
|
||||
RstState state(rstView, grid);
|
||||
@ -390,7 +417,8 @@ RstState RstState::load(std::shared_ptr<EclIO::RestartFileView> rstView,
|
||||
const auto& zacn = rstView->getKeyword<std::string>("ZACN");
|
||||
const auto& iacn = rstView->getKeyword<int>("IACN");
|
||||
const auto& sacn = rstView->getKeyword<double>("SACN");
|
||||
state.add_actions(runspec.actdims(), state.header.sim_time(), zact, iact, sact, zacn, iacn, sacn);
|
||||
const auto& zlact= rstView->getKeyword<std::string>("ZLACT");
|
||||
state.add_actions(parser, runspec.actdims(), state.header.sim_time(), zact, iact, sact, zacn, iacn, sacn, zlact);
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <fmt/format.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
@ -208,43 +209,37 @@ const std::map<logic_enum, int> logicalToIndex_17 = {
|
||||
Opm::RestartIO::Helpers::WindowedArray<
|
||||
Opm::EclIO::PaddedOutputString<8>
|
||||
>
|
||||
allocate(const std::vector<int>& actDims)
|
||||
allocate(std::size_t num_actions, std::size_t max_input_lines, const Opm::Actdims& actdims)
|
||||
{
|
||||
using WV = Opm::RestartIO::Helpers::WindowedArray<
|
||||
Opm::EclIO::PaddedOutputString<8>
|
||||
>;
|
||||
int nwin = std::max(actDims[0], 1);
|
||||
int nitPrWin = std::max(actDims[4], 1);
|
||||
return WV {
|
||||
WV::NumWindows{ static_cast<std::size_t>(nwin) },
|
||||
WV::WindowSize{ static_cast<std::size_t>(nitPrWin) }
|
||||
WV::NumWindows{ num_actions },
|
||||
WV::WindowSize{ actdims.line_size() * max_input_lines }
|
||||
};
|
||||
}
|
||||
|
||||
template <class ZLACTArray>
|
||||
void staticContrib(const Opm::Action::ActionX& actx, int noEPrZlact, ZLACTArray& zLact)
|
||||
void staticContrib(const Opm::Action::ActionX& actx, const Opm::Actdims& actdims, ZLACTArray& zLact)
|
||||
{
|
||||
std::size_t ind = 0;
|
||||
std::size_t offset = 0;
|
||||
int l_sstr = 8;
|
||||
int max_l_str = 128;
|
||||
// write out the schedule input lines
|
||||
const auto& schedule_data = actx.keyword_strings();
|
||||
for (auto z_data : schedule_data) {
|
||||
z_data = Opm::ltrim_copy(z_data);
|
||||
int n_sstr = z_data.size()/l_sstr;
|
||||
if (static_cast<int>(z_data.size()) > max_l_str) {
|
||||
std::cout << "Too long input data string (max 128 characters): " << z_data << std::endl;
|
||||
throw std::invalid_argument("Actionx: " + actx.name());
|
||||
for (auto input_line : actx.keyword_strings()) {
|
||||
input_line = Opm::trim_copy(input_line);
|
||||
if (input_line.size() > Opm::RestartIO::Helpers::VectorItems::ZLACT::max_line_length)
|
||||
throw std::invalid_argument(fmt::format("Actionx line to long for action {}", actx.name()));
|
||||
|
||||
int n_sstr = input_line.size()/l_sstr;
|
||||
for (int i = 0; i < n_sstr; i++) {
|
||||
zLact[offset + i] = input_line.substr(i*l_sstr, l_sstr);
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < n_sstr; i++) {
|
||||
zLact[ind + i] = z_data.substr(i*l_sstr, l_sstr);
|
||||
}
|
||||
//add remainder of last non-zero string
|
||||
if ((z_data.size() % l_sstr) > 0)
|
||||
zLact[ind + n_sstr] = z_data.substr(n_sstr*l_sstr);
|
||||
}
|
||||
ind += static_cast<std::size_t>(noEPrZlact);
|
||||
//add remainder of last non-zero string
|
||||
if ((input_line.size() % l_sstr) > 0)
|
||||
zLact[offset + n_sstr] = input_line.substr(n_sstr*l_sstr);
|
||||
|
||||
offset += actdims.line_size();
|
||||
}
|
||||
}
|
||||
} // zLact
|
||||
@ -562,7 +557,7 @@ AggregateActionxData( const std::vector<int>& rst_dims,
|
||||
: iACT_ (iACT::allocate(rst_dims))
|
||||
, sACT_ (sACT::allocate(rst_dims))
|
||||
, zACT_ (zACT::allocate(rst_dims))
|
||||
, zLACT_(zLACT::allocate(rst_dims))
|
||||
, zLACT_(zLACT::allocate(num_actions, sched[simStep].actions().max_input_lines(), actdims))
|
||||
, zACN_ (zACN::allocate(num_actions, actdims))
|
||||
, iACN_ (iACN::allocate(num_actions, actdims))
|
||||
, sACN_ (sACN::allocate(num_actions, actdims))
|
||||
@ -588,7 +583,7 @@ AggregateActionxData( const std::vector<int>& rst_dims,
|
||||
|
||||
{
|
||||
auto z_lact = this->zLACT_[act_ind];
|
||||
zLACT::staticContrib(action, rst_dims[8], z_lact);
|
||||
zLACT::staticContrib(action, actdims, z_lact);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -16,6 +16,7 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OPM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <cstdlib>
|
||||
|
||||
#include <opm/parser/eclipse/EclipseState/Schedule/Action/Actdims.hpp>
|
||||
#include <opm/parser/eclipse/Deck/Deck.hpp>
|
||||
@ -72,6 +73,13 @@ std::size_t Actdims::max_conditions() const {
|
||||
return this->conditions;
|
||||
}
|
||||
|
||||
std::size_t Actdims::line_size() const {
|
||||
auto [ls, rem] = std::div(this->max_characters(), 8);
|
||||
if (rem != 0)
|
||||
ls += 1;
|
||||
return ls;
|
||||
}
|
||||
|
||||
bool Actdims::operator==(const Actdims& data) const {
|
||||
return this->max_keywords() == data.max_keywords() &&
|
||||
this->max_line_count() == data.max_line_count() &&
|
||||
|
@ -74,6 +74,8 @@ ActionX::ActionX(const RestartIO::RstAction& rst_action)
|
||||
tokens.insert(tokens.end(), cond_tokens.begin(), cond_tokens.end());
|
||||
}
|
||||
this->condition = Action::AST(tokens);
|
||||
for (const auto& keyword : rst_action.keywords)
|
||||
this->addKeyword(keyword);
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <opm/io/eclipse/RestartFileView.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
@ -178,4 +179,20 @@ BOOST_AUTO_TEST_CASE(LoadActionRestartSim) {
|
||||
const auto& rst_actions = restart_sched[7].actions();
|
||||
|
||||
BOOST_CHECK_EQUAL(input_actions.ecl_size(), rst_actions.ecl_size());
|
||||
for (std::size_t iact = 0; iact < input_actions.ecl_size(); iact++) {
|
||||
const auto& input_action = input_actions[iact];
|
||||
const auto& rst_action = rst_actions[iact];
|
||||
|
||||
auto input_iter = input_action.begin();
|
||||
auto rst_iter = rst_action.begin();
|
||||
|
||||
BOOST_REQUIRE_EQUAL( std::distance(input_action.begin(), input_action.end()),
|
||||
std::distance(rst_action.begin(), rst_action.end()) );
|
||||
|
||||
while (input_iter != input_action.end()) {
|
||||
BOOST_CHECK( *input_iter == *rst_iter );
|
||||
input_iter++;
|
||||
rst_iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user