Loading...
Searching...
No Matches
UDQAssign.hpp
/*
Copyright 2018 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 UDQASSIGN_HPP_
#define UDQASSIGN_HPP_
#include <opm/input/eclipse/Schedule/UDQ/UDQEnums.hpp>
#include <opm/input/eclipse/Schedule/UDQ/UDQSet.hpp>
#include <cstddef>
#include <functional>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
namespace Opm::RestartIO {
class RstUDQ;
}
namespace Opm {
class UDQAssign
{
public:
using VString = std::vector<std::string>;
using VEnumItems = std::vector<UDQSet::EnumeratedItems>;
using WGNameMatcher = std::function<VString(const VString&)>;
using ItemMatcher = std::function<VEnumItems(const VString&)>;
UDQAssign() = default;
UDQAssign(const std::string& keyword,
const VString& selector,
double value,
std::size_t report_step);
UDQAssign(const std::string& keyword,
const VEnumItems& selector,
double value,
std::size_t report_step);
UDQAssign(const std::string& keyword,
VEnumItems&& selector,
double value,
std::size_t report_step);
UDQAssign(const std::string& keyword,
const RestartIO::RstUDQ& assignRst,
const std::size_t report_step);
static UDQAssign serializationTestObject();
const std::string& keyword() const;
UDQVarType var_type() const;
void add_record(const VString& selector,
double value,
std::size_t report_step);
void add_record(const VEnumItems& selector,
double value,
std::size_t report_step);
void add_record(VEnumItems&& selector,
double value,
std::size_t report_step);
void add_record(const RestartIO::RstUDQ& assignRst,
const std::size_t report_step);
UDQSet eval(const VEnumItems& items) const;
UDQSet eval(const VString& wells) const;
UDQSet eval() const;
UDQSet eval(const VString& wgNames, WGNameMatcher matcher) const;
UDQSet eval(const VEnumItems& items, ItemMatcher matcher) const;
std::size_t report_step() const;
bool operator==(const UDQAssign& data) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_keyword);
serializer(m_var_type);
serializer(records);
}
private:
// If the same keyword is assigned several times the different
// assignment records are assembled in one UDQAssign instance. This is
// an attempt to support restart in a situation where a full UDQ ASSIGN
// statement can be swapped with a UDQ DEFINE statement.
struct AssignRecord
{
VString input_selector{};
VEnumItems numbered_selector{};
double value{};
std::size_t report_step{};
AssignRecord() = default;
AssignRecord(const VString& selector,
const double value_arg,
const std::size_t report_step_arg)
: input_selector(selector)
, value (value_arg)
, report_step (report_step_arg)
{}
AssignRecord(const VEnumItems& selector,
const double value_arg,
const std::size_t report_step_arg)
: numbered_selector(selector)
, value (value_arg)
, report_step (report_step_arg)
{}
AssignRecord(VEnumItems&& selector,
const double value_arg,
const std::size_t report_step_arg)
: numbered_selector(std::move(selector))
, value (value_arg)
, report_step (report_step_arg)
{}
void eval(UDQSet& values) const;
void eval(WGNameMatcher matcher, UDQSet& values) const;
void eval(ItemMatcher matcher, UDQSet& values) const;
bool operator==(const AssignRecord& data) const;
template<class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->input_selector);
serializer(this->numbered_selector);
serializer(this->value);
serializer(this->report_step);
}
private:
void assignEnumeration(const VEnumItems& items, UDQSet& values) const;
};
std::string m_keyword{};
UDQVarType m_var_type{UDQVarType::NONE};
std::vector<AssignRecord> records{};
void add_well_or_group_records(const RestartIO::RstUDQ& assignRst,
const std::size_t report_step);
void add_segment_records(const RestartIO::RstUDQ& assignRst,
const std::size_t report_step);
};
} // namespace Opm
#endif // UDQASSIGN_HPP_
Opm::Serializer
Class for (de-)serializing.
Definition Serializer.hpp:94
Opm::UDQAssign::report_step
std::size_t report_step() const
Time at which this assignment happens.
Definition UDQAssign.cpp:214
Opm::UDQAssign::WGNameMatcher
std::function< VString(const VString &)> WGNameMatcher
Call-back function type for a well/group name matcher.
Definition UDQAssign.hpp:52
Opm::UDQAssign::VString
std::vector< std::string > VString
Type alias for a vector of strings. Simplifies function signatures.
Definition UDQAssign.hpp:44
Opm::UDQAssign::eval
UDQSet eval() const
Construct scalar UDQ set for a scalar UDQ assignment.
Definition UDQAssign.cpp:257
Opm::UDQAssign::keyword
const std::string & keyword() const
Name of UDQ to which this assignment applies.
Definition UDQAssign.cpp:204
Opm::UDQAssign::serializationTestObject
static UDQAssign serializationTestObject()
Create a serialisation test object.
Definition UDQAssign.cpp:138
Opm::UDQAssign::add_record
void add_record(const VString &selector, double value, std::size_t report_step)
Add new record to existing UDQ assignment.
Definition UDQAssign.cpp:151
Opm::UDQAssign::ItemMatcher
std::function< VEnumItems(const VString &)> ItemMatcher
Call-back function type for a matcher of enumerated items.
Definition UDQAssign.hpp:56
Opm::UDQAssign::eval
UDQSet eval(const VString &wells) const
Apply current assignment to a selection of named items.
Opm::UDQAssign::serializeOp
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition UDQAssign.hpp:300
Opm::UDQAssign::add_record
void add_record(const VEnumItems &selector, double value, std::size_t report_step)
Add new record to existing UDQ assignment.
Opm::UDQAssign::VEnumItems
std::vector< UDQSet::EnumeratedItems > VEnumItems
Type alias for a vector of enumerated items.
Definition UDQAssign.hpp:48
Opm::UDQAssign::var_type
UDQVarType var_type() const
Kind of UDQ to which this assignment applies.
Definition UDQAssign.cpp:209
Opm::UDQAssign::UDQAssign
UDQAssign()=default
Default constructor.
Opm::UDQAssign::operator==
bool operator==(const UDQAssign &data) const
Equality predicate.
Definition UDQAssign.cpp:312
Opm::UDQAssign::UDQAssign
UDQAssign(const std::string &keyword, const VEnumItems &selector, double value, std::size_t report_step)
Constructor.
Opm::UDQSet
Definition UDQSet.hpp:187
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30