Loading...
Searching...
No Matches
NameOrder.hpp
/*
Copyright 2021 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 NAME_ORDER_HPP
#define NAME_ORDER_HPP
#include <cstddef>
#include <initializer_list>
#include <optional>
#include <string>
#include <unordered_map>
#include <vector>
namespace Opm {
// The purpose of this small class is to ensure that well and group name
// always come in the order they are defined in the deck.
class NameOrder
{
public:
NameOrder() = default;
explicit NameOrder(std::initializer_list<std::string> names);
explicit NameOrder(const std::vector<std::string>& names);
void add(const std::string& name);
std::vector<std::string> sort(std::vector<std::string> names) const;
const std::vector<std::string>& names() const;
bool has(const std::string& wname) const;
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(m_index_map);
serializer(m_name_list);
}
static NameOrder serializationTestObject();
const std::string& operator[](std::size_t index) const;
bool operator==(const NameOrder& other) const;
auto begin() const { return this->m_name_list.begin(); }
auto end() const { return this->m_name_list.end(); }
auto size() const { return this->m_name_list.size(); }
private:
std::unordered_map<std::string, std::size_t> m_index_map;
std::vector<std::string> m_name_list;
};
class GroupOrder
{
public:
GroupOrder() = default;
explicit GroupOrder(std::size_t max_groups);
static GroupOrder serializationTestObject();
void add(const std::string& name);
const std::vector<std::string>& names() const
{
return this->name_list_;
}
std::vector<std::string> names(const std::string& pattern) const;
bool has(const std::string& gname) const;
bool anyGroupMatches(const std::string& pattern) const;
std::vector<std::optional<std::string>> restart_groups() const;
bool operator==(const GroupOrder& other) const;
auto begin() const { return this->name_list_.begin(); }
auto end() const { return this->name_list_.end(); }
template <class Serializer>
void serializeOp(Serializer& serializer)
{
serializer(this->name_list_);
serializer(this->max_groups_);
}
private:
std::size_t max_groups_{};
std::vector<std::string> name_list_{};
};
} // namespace Opm
#endif // NAME_ORDER_HPP
Opm::GroupOrder
Collection of group names with built-in ordering.
Definition NameOrder.hpp:69
Opm::GroupOrder::GroupOrder
GroupOrder()=default
Default constructor.
Opm::GroupOrder::begin
auto begin() const
Start of group name sequence.
Definition NameOrder.hpp:143
Opm::GroupOrder::serializationTestObject
static GroupOrder serializationTestObject()
Create a serialisation test object.
Definition NameOrder.cpp:109
Opm::GroupOrder::anyGroupMatches
bool anyGroupMatches(const std::string &pattern) const
Group name existence predicate.
Definition NameOrder.cpp:134
Opm::GroupOrder::add
void add(const std::string &name)
Add a group name to ordered collection.
Definition NameOrder.cpp:119
Opm::GroupOrder::has
bool has(const std::string &gname) const
Group name existence predicate.
Definition NameOrder.cpp:128
Opm::GroupOrder::serializeOp
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition NameOrder.hpp:154
Opm::GroupOrder::end
auto end() const
End of group name sequence.
Definition NameOrder.hpp:146
Opm::GroupOrder::operator==
bool operator==(const GroupOrder &other) const
Equality predicate.
Definition NameOrder.cpp:182
Opm::GroupOrder::names
const std::vector< std::string > & names() const
Retrieve current list of group names.
Definition NameOrder.hpp:94
Opm::GroupOrder::restart_groups
std::vector< std::optional< std::string > > restart_groups() const
Retrieve sequence of group names ordered appropriately for restart file output.
Definition NameOrder.cpp:170
Opm::Serializer
Class for (de-)serializing.
Definition Serializer.hpp:94
Opm
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30