opm-common
Keywords.hpp
1 /*
2  Copyright 2020 Equinor AS.
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 OPM_KEYWORDS_HPP
21 #define OPM_KEYWORDS_HPP
22 
23 #include <optional>
24 #include <string>
25 
26 namespace Opm {
27 namespace Fieldprops {
28 namespace keywords {
29 
30 template <typename T>
31 struct keyword_info {
32  std::optional<std::string> unit = std::nullopt;
33  std::optional<T> scalar_init = std::nullopt;
34  bool multiplier = false;
35  bool top = false;
40  bool global = false;
44  bool local_in_schedule = true;
45 
46  // For FieldProps-related keywords, each grid cell can have multiple values.
47  // This occurs specifically during compositional simulations, where the number
48  // of values depends on the number of compositions. In other simulations, num_value is typically one.
49  // The 'mutable' keyword allows num_value to be updated at a later stage when parsing relevant keywords.
50  mutable std::size_t num_value = 1;
51 
52 
53  bool operator==(const keyword_info& other) const {
54  return this->unit == other.unit &&
55  this->scalar_init == other.scalar_init &&
56  this->multiplier == other.multiplier &&
57  this->top == other.top &&
58  this->global == other.global &&
59  this->num_value == other.num_value;
60  }
61 
62  keyword_info<T>& init(T init_value) {
63  this->scalar_init = init_value;
64  return *this;
65  }
66 
67  keyword_info<T>& unit_string(const std::string& unit_string) {
68  this->unit = unit_string;
69  return *this;
70  }
71 
72  keyword_info<T>& distribute_top(bool dtop) {
73  this->top = dtop;
74  return *this;
75  }
76 
77  keyword_info<T>& mult(bool m) {
78  this->multiplier = m;
79  return *this;
80  }
81 
82  keyword_info<T>& global_kw(bool g) {
83  this->global = g;
84  if(g)
85  this->local_in_schedule = false;
86  return *this;
87  }
88 
89  keyword_info<T>& global_kw_until_edit() {
90  this->global = true;
91  this->local_in_schedule = true;
92  return *this;
93  }
94  const keyword_info<T>& num_value_per_cell(const std::size_t n) const {
95  if (n > 0) {
96  this->num_value = n;
97  }
98  return *this;
99  }
100 };
101 
102 } // end namespace Keywords
103 } // end namespace Fieldprops
104 } //end namespace Opm
105 
106 #endif //OPM_KEYWORDS_HPP
bool global
Whether a keyword is global.
Definition: Keywords.hpp:40
bool local_in_schedule
Supply global storage but remove it once the SCHEDULE is executed.
Definition: Keywords.hpp:44
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: Keywords.hpp:31