My Project
Loading...
Searching...
No Matches
DatumDepth.hpp
1// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2// vi: set et ts=4 sw=4 sts=4:
3/*
4 Copyright 2024 Equinor ASA.
5
6 This file is part of the Open Porous Media project (OPM).
7
8 OPM is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 OPM is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with OPM. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22#ifndef DATUM_DEPTH_HPP_INCLUDED
23#define DATUM_DEPTH_HPP_INCLUDED
24
25#include <cassert>
26#include <string>
27#include <string_view>
28#include <variant>
29#include <vector>
30
35
36namespace Opm {
37 class SOLUTIONSection;
38} // namespace Opm
39
40namespace Opm {
41
44 class DatumDepth
45 {
46 public:
48 DatumDepth() = default;
49
53 explicit DatumDepth(const SOLUTIONSection& soln);
54
57 static DatumDepth serializationTestObjectZero();
58
62 static DatumDepth serializationTestObjectGlobal();
63
67 static DatumDepth serializationTestObjectDefaultRegion();
68
72 static DatumDepth serializationTestObjectUserDefined();
73
81 double operator()(const int region) const
82 {
83 return (*this)("FIPNUM", region);
84 }
85
94 double operator()(std::string_view rset, const int region) const
95 {
96 return std::visit([rset, region](const auto& datumDepthImpl)
97 { return datumDepthImpl(rset, region); }, this->datum_);
98 }
99
106 bool operator==(const DatumDepth& that) const
107 {
108 return this->datum_ == that.datum_;
109 }
110
116 template <class Serializer>
117 void serializeOp(Serializer& serializer)
118 {
119 serializer(this->datum_);
120 }
121
122 private:
124 class Zero
125 {
126 public:
137 double operator()([[maybe_unused]] std::string_view rset,
138 [[maybe_unused]] const int region) const
139 {
140 return 0.0;
141 }
142
144 static Zero serializationTestObject() { return {}; }
145
147 bool operator==(const Zero&) const { return true; }
148
155 template <class Serializer>
156 void serializeOp([[maybe_unused]] Serializer& serializer)
157 {} // Nothing to do
158 };
159
161 class Global
162 {
163 public:
165 Global() = default;
166
170 explicit Global(const SOLUTIONSection& soln);
171
180 double operator()([[maybe_unused]] std::string_view rset,
181 [[maybe_unused]] const int region) const
182 {
183 return this->depth_;
184 }
185
187 static Global serializationTestObject();
188
195 bool operator==(const Global& that) const
196 {
197 return this->depth_ == that.depth_;
198 }
199
206 template <class Serializer>
207 void serializeOp(Serializer& serializer)
208 {
209 serializer(this->depth_);
210 }
211
212 private:
215 double depth_{};
216 };
217
219 class DefaultRegion
220 {
221 public:
223 DefaultRegion() = default;
224
228 explicit DefaultRegion(const SOLUTIONSection& soln);
229
231 static DefaultRegion serializationTestObject();
232
241 double operator()([[maybe_unused]] std::string_view rset,
242 const int region) const
243 {
244 assert (! this->depth_.empty());
245
246 // Note: depth_.back() is intentional for region >= size().
247 // If the input supplies fewer depth values than there are
248 // regions, then the remaining regions implicitly have the
249 // same datum depth as the last fully specified region.
250 return (region < static_cast<int>(this->depth_.size()))
251 ? this->depth_[region] : this->depth_.back();
252 }
253
260 bool operator==(const DefaultRegion& that) const
261 {
262 return this->depth_ == that.depth_;
263 }
264
271 template <class Serializer>
272 void serializeOp(Serializer& serializer)
273 {
274 serializer(this->depth_);
275 }
276
277 private:
280 std::vector<double> depth_{};
281 };
282
284 class UserDefined
285 {
286 public:
288 UserDefined() = default;
289
293 explicit UserDefined(const SOLUTIONSection& soln);
294
296 static UserDefined serializationTestObject();
297
306 double operator()(std::string_view rset, const int region) const;
307
314 bool operator==(const UserDefined& that) const
315 {
316 return (this->rsetNames_ == that.rsetNames_)
317 && (this->rsetStart_ == that.rsetStart_)
318 && (this->depth_ == that.depth_)
319 && (this->default_ == that.default_)
320 && (this->rsetIndex_ == that.rsetIndex_)
321 ;
322 }
323
330 template <class Serializer>
331 void serializeOp(Serializer& serializer)
332 {
333 serializer(this->rsetNames_);
334 serializer(this->rsetStart_);
335 serializer(this->depth_);
336 serializer(this->default_);
337 serializer(this->rsetIndex_);
338 }
339
340 private:
343 std::vector<std::string> rsetNames_{};
344
346 std::vector<std::vector<double>::size_type> rsetStart_{};
347
350 std::vector<double> depth_{};
351
354 std::vector<double> default_{};
355
358 std::vector<std::vector<std::string>::size_type> rsetIndex_{};
359
377 double depthValue(std::string_view rset,
378 std::vector<double>::const_iterator begin,
379 std::vector<double>::const_iterator end,
380 std::vector<double>::difference_type ix) const;
381 };
382
384 std::variant<Zero, Global, DefaultRegion, UserDefined> datum_{};
385 };
386
387} // namespace Opm
388
389#endif // DATUM_DEPTH_HPP_INCLUDED
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition Exceptions.hpp:30