My Project
Loading...
Searching...
No Matches
DeckItem.hpp
1/*
2 Copyright 2013 Statoil 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 DECKITEM_HPP
21#define DECKITEM_HPP
22
23#include <string>
24#include <vector>
25#include <iosfwd>
26
27#include <opm/input/eclipse/Units/Dimension.hpp>
28#include <opm/input/eclipse/Utility/Typetools.hpp>
29#include <opm/input/eclipse/Deck/UDAValue.hpp>
30#include <opm/input/eclipse/Deck/value_status.hpp>
31
32
33namespace Opm {
34 class DeckOutput;
35
36 class DeckItem {
37 public:
38
39 DeckItem() = default;
40 DeckItem( const std::string&, int);
41 DeckItem( const std::string&, RawString);
42 DeckItem( const std::string&, std::string);
43 DeckItem( const std::string&, double) = delete;
44 DeckItem( const std::string&, UDAValue) = delete;
45 DeckItem( const std::string&, UDAValue, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
46 DeckItem( const std::string&, double, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
47
48 static DeckItem serializationTestObject();
49 DeckItem emptyStructuralCopy() const;
50
51 const std::string& name() const;
52
53 // return true if the default value was used for a given data point
54 bool defaultApplied( size_t ) const;
55
56 // Return true if the item has a value for the current index;
57 // does not differentiate between default values from the
58 // config and values which have been set in the deck.
59 bool hasValue( size_t ) const;
60
61 // if the number returned by this method is less than what is semantically
62 // expected (e.g. size() is less than the number of cells in the grid for
63 // keywords like e.g. SGL), then the remaining values are defaulted. The deck
64 // creates the defaulted items if all their sizes are fully specified by the
65 // keyword, though...
66
67 size_t data_size() const;
68
69 template<typename T>
70 T get( size_t index ) const;
71
72
73 double getSIDouble( size_t ) const;
74 std::string getTrimmedString( size_t ) const;
75
76 template< typename T > const std::vector< T >& getData() const;
77 const std::vector< double >& getSIDoubleData() const;
78 const std::vector<value::status>& getValueStatus() const;
79 const std::vector<Dimension>& getActiveDimensions() const
80 {
81 return this->active_dimensions;
82 }
83
84 template< typename T>
85 void shrink_to_fit();
86
87
88 void push_back( UDAValue );
89 void push_back( int );
90 void push_back( double );
91 void push_back( std::string );
92 void push_back( RawString );
93 void push_back( UDAValue, size_t );
94 void push_back( int, size_t );
95 void push_back( double, size_t );
96 void push_back( std::string, size_t );
97 void push_backDefault( UDAValue, std::size_t n = 1 );
98 void push_backDefault( int, std::size_t n = 1 );
99 void push_backDefault( double, std::size_t n = 1 );
100 void push_backDefault( std::string, std::size_t n = 1 );
101 void push_backDefault( RawString, std::size_t n = 1 );
102 // trying to access the data of a "dummy default item" will raise an exception
103
104 template <typename T>
105 void push_backDummyDefault( std::size_t n = 1 );
106
107 type_tag getType() const;
108
109 void write(DeckOutput& writer) const;
110 friend std::ostream& operator<<(std::ostream& os, const DeckItem& item);
111
112
113 /*
114 The comparison can be adjusted with the cmp_default and
115 cmp_numeric flags. If cmp_default is set to true the
116 comparison will take the defaulted status of the items into
117 account, i.e. two items will compare differently if one is
118 defaulted and the other has the default value explicitly
119 set. The default behaviour is cmp_default == false -
120 irrespective of whether they have been set explicitly or
121 have been defaulted.
122 */
123 bool equal(const DeckItem& other, bool cmp_default, bool cmp_numeric) const;
124
125 /*
126 The operator== is implemented based on the equal( ) method,
127 with the arguments cmp_default=false and cmp_numeric=true.
128 */
129 bool operator==(const DeckItem& other) const;
130 bool operator!=(const DeckItem& other) const;
131 static bool to_bool(std::string string_value);
132
133 bool is_uda() { return (type == get_type< UDAValue >()); };
134 bool is_double() { return type == get_type< double >(); };
135 bool is_int() { return type == get_type< int >() ; };
136 bool is_string() { return type == get_type< std::string >(); };
137 bool is_raw_string() { return type == get_type< RawString >(); };
138
139 UDAValue& get_uda() { return uval[0]; };
140
141 template<class Serializer>
142 void serializeOp(Serializer& serializer)
143 {
144 serializer(dval);
145 serializer(ival);
146 serializer(sval);
147 serializer(rsval);
148 serializer(uval);
149 serializer(type);
150 serializer(item_name);
151 serializer(value_status);
152 serializer(raw_data);
153 serializer(active_dimensions);
154 serializer(default_dimensions);
155 }
156
157 void reserve_additionalRawString(std::size_t);
158
159 private:
160 mutable std::vector< double > dval;
161 std::vector< int > ival;
162 std::vector< std::string > sval;
163 std::vector< RawString > rsval;
164 std::vector< UDAValue > uval;
165
166 type_tag type = type_tag::unknown;
167
168 std::string item_name;
169 std::vector<value::status> value_status;
170 /*
171 To save space we mutate the dval object in place when asking for SI
172 data; the current state of of the dval member is tracked with the
173 raw_data bool member.
174 */
175 mutable bool raw_data = true;
176 std::vector< Dimension > active_dimensions;
177 std::vector< Dimension > default_dimensions;
178
179 template< typename T > std::vector< T >& value_ref();
180 template< typename T > const std::vector< T >& value_ref() const;
181 template< typename T > void push( T );
182 template< typename T > void push( T, size_t );
183 template< typename T > void push_default( T, std::size_t n );
184 template< typename T > void write_vector(DeckOutput& writer, const std::vector<T>& data) const;
185 };
186}
187#endif /* DECKITEM_HPP */
188
Definition DeckItem.hpp:36
Definition DeckOutput.hpp:29
Definition Typetools.hpp:40
Class for (de-)serializing.
Definition Serializer.hpp:94
Definition UDAValue.hpp:31
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30