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 <memory>
26#include <iosfwd>
27
28#include <opm/input/eclipse/Units/Dimension.hpp>
29#include <opm/input/eclipse/Utility/Typetools.hpp>
30#include <opm/input/eclipse/Deck/UDAValue.hpp>
31#include <opm/input/eclipse/Deck/value_status.hpp>
32
33
34namespace Opm {
35 class DeckOutput;
36
37 class DeckItem {
38 public:
39
40 DeckItem() = default;
41 DeckItem( const std::string&, int);
42 DeckItem( const std::string&, RawString);
43 DeckItem( const std::string&, std::string);
44 DeckItem( const std::string&, double) = delete;
45 DeckItem( const std::string&, UDAValue) = delete;
46 DeckItem( const std::string&, UDAValue, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
47 DeckItem( const std::string&, double, const std::vector<Dimension>& active_dim, const std::vector<Dimension>& default_dim);
48
49 static DeckItem serializationTestObject();
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
80 template< typename T>
81 void shrink_to_fit();
82
83
84 void push_back( UDAValue );
85 void push_back( int );
86 void push_back( double );
87 void push_back( std::string );
88 void push_back( RawString );
89 void push_back( UDAValue, size_t );
90 void push_back( int, size_t );
91 void push_back( double, size_t );
92 void push_back( std::string, size_t );
93 void push_backDefault( UDAValue, std::size_t n = 1 );
94 void push_backDefault( int, std::size_t n = 1 );
95 void push_backDefault( double, std::size_t n = 1 );
96 void push_backDefault( std::string, std::size_t n = 1 );
97 void push_backDefault( RawString, std::size_t n = 1 );
98 // trying to access the data of a "dummy default item" will raise an exception
99
100 template <typename T>
101 void push_backDummyDefault( std::size_t n = 1 );
102
103 type_tag getType() const;
104
105 void write(DeckOutput& writer) const;
106 friend std::ostream& operator<<(std::ostream& os, const DeckItem& item);
107
108
109 /*
110 The comparison can be adjusted with the cmp_default and
111 cmp_numeric flags. If cmp_default is set to true the
112 comparison will take the defaulted status of the items into
113 account, i.e. two items will compare differently if one is
114 defaulted and the other has the default value explicitly
115 set. The default behaviour is cmp_default == false -
116 irrespective of whether they have been set explicitly or
117 have been defaulted.
118 */
119 bool equal(const DeckItem& other, bool cmp_default, bool cmp_numeric) const;
120
121 /*
122 The operator== is implemented based on the equal( ) method,
123 with the arguments cmp_default=false and cmp_numeric=true.
124 */
125 bool operator==(const DeckItem& other) const;
126 bool operator!=(const DeckItem& other) const;
127 static bool to_bool(std::string string_value);
128
129 bool is_uda() { return (type == get_type< UDAValue >()); };
130 bool is_double() { return type == get_type< double >(); };
131 bool is_int() { return type == get_type< int >() ; };
132 bool is_string() { return type == get_type< std::string >(); };
133 bool is_raw_string() { return type == get_type< RawString >(); };
134
135 UDAValue& get_uda() { return uval[0]; };
136
137 template<class Serializer>
138 void serializeOp(Serializer& serializer)
139 {
140 serializer(dval);
141 serializer(ival);
142 serializer(sval);
143 serializer(rsval);
144 serializer(uval);
145 serializer(type);
146 serializer(item_name);
147 serializer(value_status);
148 serializer(raw_data);
149 serializer(active_dimensions);
150 serializer(default_dimensions);
151 }
152
153 void reserve_additionalRawString(std::size_t);
154 private:
155 mutable std::vector< double > dval;
156 std::vector< int > ival;
157 std::vector< std::string > sval;
158 std::vector< RawString > rsval;
159 std::vector< UDAValue > uval;
160
161 type_tag type = type_tag::unknown;
162
163 std::string item_name;
164 std::vector<value::status> value_status;
165 /*
166 To save space we mutate the dval object in place when asking for SI
167 data; the current state of of the dval member is tracked with the
168 raw_data bool member.
169 */
170 mutable bool raw_data = true;
171 std::vector< Dimension > active_dimensions;
172 std::vector< Dimension > default_dimensions;
173
174 template< typename T > std::vector< T >& value_ref();
175 template< typename T > const std::vector< T >& value_ref() const;
176 template< typename T > void push( T );
177 template< typename T > void push( T, size_t );
178 template< typename T > void push_default( T, std::size_t n );
179 template< typename T > void write_vector(DeckOutput& writer, const std::vector<T>& data) const;
180 };
181}
182#endif /* DECKITEM_HPP */
183
Definition DeckItem.hpp:37
Definition DeckOutput.hpp:29
Definition Typetools.hpp:37
Class for (de-)serializing.
Definition Serializer.hpp:84
Definition UDAValue.hpp:32
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30