UDQConfig.hpp
Go to the documentation of this file.
1/*
2 Copyright 2019 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef UDQINPUT_HPP_
21#define UDQINPUT_HPP_
22
23#include <string>
24#include <unordered_map>
25#include <map>
26#include <unordered_set>
27
35
36
37namespace Opm {
38
39 class DeckRecord;
40 class Deck;
41 class UDQConfig {
42 public:
43 UDQConfig() = default;
44 explicit UDQConfig(const Deck& deck);
45 explicit UDQConfig(const UDQParams& params);
46
48
49 const std::string& unit(const std::string& key) const;
50 bool has_unit(const std::string& keyword) const;
51 bool has_keyword(const std::string& keyword) const;
52 void add_record(const DeckRecord& record);
53
55 void add_assign(const std::string& quantity, const std::vector<std::string>& selector, double value);
56 void add_define(const std::string& quantity, const std::vector<std::string>& expression);
57
58 std::vector<UDQDefine> definitions() const;
59 std::vector<UDQDefine> definitions(UDQVarType var_type) const;
60 std::vector<UDQInput> input() const;
61
62 // The size() method will return the number of active DEFINE and ASSIGN
63 // statements; this will correspond to the length of the vector returned
64 // from input().
65 size_t size() const;
66
68
69 std::vector<UDQAssign> assignments() const;
70 std::vector<UDQAssign> assignments(UDQVarType var_type) const;
71 const UDQParams& params() const;
73
74 bool operator==(const UDQConfig& config) const;
75
76 template<class Serializer>
77 void serializeOp(Serializer& serializer)
78 {
79 udq_params.serializeOp(serializer);
80 serializer.map(m_definitions);
81 serializer.map(m_assignments);
82 serializer(units);
83 input_index.serializeOp(serializer);
84 serializer.template map<decltype(type_count),false>(type_count);
85 // The UDQFunction table is constant up to udq_params.
86 // So we can just construct a new instance here.
87 if (!serializer.isSerializing())
88 udqft = UDQFunctionTable(udq_params);
89 }
90
91 private:
92 void add_node(const std::string& quantity, UDQAction action);
93
94 UDQParams udq_params;
95 UDQFunctionTable udqft;
96
97
98 /*
99 The choices of datastructures are strongly motivated by the
100 constraints imposed by the Eclipse formatted restart files; for
101 writing restart files it is essential to keep meticolous control over
102 the ordering of the keywords. In this class the ordering is mainly
103 maintained by the input_index map which keeps track of the insert
104 order of each keyword, and whether the keyword is currently DEFINE'ed
105 or ASSIGN'ed.
106 */
107 std::unordered_map<std::string, UDQDefine> m_definitions;
108 std::unordered_map<std::string, UDQAssign> m_assignments;
109 std::unordered_map<std::string, std::string> units;
110
112 std::map<UDQVarType, std::size_t> type_count;
113 };
114}
115
116
117
118#endif
const char *const string
Definition: cJSON.h:170
Definition: Deck.hpp:115
Definition: DeckRecord.hpp:32
Definition: OrderedMap.hpp:32
Definition: Serializer.hpp:38
Definition: UDQConfig.hpp:41
std::vector< UDQDefine > definitions(UDQVarType var_type) const
const UDQParams & params() const
void add_record(const DeckRecord &record)
void serializeOp(Serializer &serializer)
Definition: UDQConfig.hpp:77
size_t size() const
UDQConfig()=default
static UDQConfig serializeObject()
void add_unit(const std::string &keyword, const std::string &unit)
bool has_keyword(const std::string &keyword) const
std::vector< UDQDefine > definitions() const
std::vector< UDQAssign > assignments() const
UDQConfig(const Deck &deck)
UDQConfig(const UDQParams &params)
bool has_unit(const std::string &keyword) const
const UDQInput operator[](const std::string &keyword) const
void add_assign(const std::string &quantity, const std::vector< std::string > &selector, double value)
void add_define(const std::string &quantity, const std::vector< std::string > &expression)
std::vector< UDQAssign > assignments(UDQVarType var_type) const
const std::string & unit(const std::string &key) const
std::vector< UDQInput > input() const
bool operator==(const UDQConfig &config) const
const UDQFunctionTable & function_table() const
Definition: UDQFunctionTable.hpp:31
Definition: UDQInput.hpp:79
Definition: UDQParams.hpp:31
void serializeOp(Serializer &serializer)
Definition: UDQParams.hpp:51
UDAKeyword keyword(UDAControl control)
Definition: A.hpp:4
UDQVarType
Definition: UDQEnums.hpp:59
UDQAction
Definition: UDQEnums.hpp:129
T value(details::expression_node< T > *n)
Definition: exprtk.hpp:12955