Loading...
Searching...
No Matches
State.hpp
/*
Copyright 2020 Equinor 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 ACTION_STATE_HPP
#define ACTION_STATE_HPP
#include <cstddef>
#include <ctime>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace Opm::RestartIO {
struct RstState;
} // namespace Opm::RestartIO
namespace Opm::Action {
class ActionX;
class Actions;
class PyAction;
class Result;
} // namespace Opm::Action
namespace Opm::Action {
class State
{
public:
class MatchSet
{
public:
bool hasWell(const std::string& well) const;
static MatchSet serializationTestObject();
bool operator==(const MatchSet& that) const;
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->wells_);
}
friend class State;
private:
std::vector<std::string> wells_{};
};
void add_run(const ActionX& action, std::time_t sim_time, const Result& result);
void add_run(const PyAction& action, bool result);
std::size_t run_count(const ActionX& action) const;
std::time_t run_time(const ActionX& action) const;
const MatchSet* result(const std::string& action) const;
std::optional<bool> python_result(const std::string& action) const;
void load_rst(const Actions& action_config,
const RestartIO::RstState& rst_state);
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->run_state);
serializer(this->last_result);
serializer(this->m_python_result);
}
static State serializationTestObject();
bool operator==(const State& other) const;
private:
struct RunState
{
RunState() = default;
explicit RunState(const std::time_t sim_time)
: run_count(1)
, last_run(sim_time)
{}
void add_run(const std::time_t sim_time)
{
this->last_run = sim_time;
this->run_count += 1;
}
static RunState serializationTestObject()
{
RunState rs;
rs.run_count = 100;
rs.last_run = 123456;
return rs;
}
bool operator==(const RunState& other) const
{
return (this->run_count == other.run_count)
&& (this->last_run == other.last_run);
}
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->run_count);
serializer(this->last_run);
}
std::size_t run_count{};
std::time_t last_run{};
};
using ActionID = std::pair<std::string, std::size_t>;
std::map<ActionID, RunState> run_state{};
std::map<std::string, MatchSet> last_result{};
std::map<std::string, bool> m_python_result{};
};
} // namespace Opm::Action
#endif // ACTION_STATE_HPP
Opm::Action::ActionX
Definition ActionX.hpp:72
Opm::Action::Actions
Container of action keywords.
Definition Actions.hpp:44
Opm::Action::PyAction
Definition PyAction.hpp:40
Opm::Action::Result
Class Action::Result holds the boolean result of a ACTIONX condition like.
Definition ActionResult.hpp:69
Opm::Action::State::MatchSet
Matching entities from a successfully triggered ActionX object.
Definition State.hpp:55
Opm::Action::State::MatchSet::operator==
bool operator==(const MatchSet &that) const
Equality predicate.
Definition State.cpp:68
Opm::Action::State::MatchSet::serializationTestObject
static MatchSet serializationTestObject()
Create a serialisation test object.
Definition State.cpp:57
Opm::Action::State::MatchSet::serializeOp
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition State.hpp:83
Opm::Action::State::MatchSet::hasWell
bool hasWell(const std::string &well) const
Whether or not a particular well exists in the set of matching entities.
Definition State.cpp:49
Opm::Action::State
Management information about the current run's ACTION system, especially concerning the number of tim...
Definition State.hpp:51
Opm::Action::State::add_run
void add_run(const ActionX &action, std::time_t sim_time, const Result &result)
Record ActionX Run.
Definition State.cpp:95
Opm::Action::State::run_count
std::size_t run_count(const ActionX &action) const
Retrieve number of times an action has run.
Definition State.cpp:75
Opm::Action::State::run_time
std::time_t run_time(const ActionX &action) const
Retrieve timestamp of the last time an action ran.
Definition State.cpp:83
Opm::Action::State::result
const MatchSet * result(const std::string &action) const
Retrieve set of matching entities from the last time an action ran.
Definition State.cpp:125
Opm::Action::State::serializeOp
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition State.hpp:160
Opm::Action::State::load_rst
void load_rst(const Actions &action_config, const RestartIO::RstState &rst_state)
Load action state from restart file.
Definition State.cpp:147
Opm::Action::State::serializationTestObject
static State serializationTestObject()
Create a serialisation test object.
Definition State.cpp:169
Opm::Action::State::python_result
std::optional< bool > python_result(const std::string &action) const
Query for the result of running a PyAction.
Definition State.cpp:134
Opm::Action::State::operator==
bool operator==(const State &other) const
Equality predicate.
Definition State.cpp:161
Opm::Serializer
Class for (de-)serializing.
Definition Serializer.hpp:94
Opm::RestartIO::RstState
Definition state.hpp:57