opm-common
SummaryConfig.hpp
1 /*
2  Copyright 2015 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 OPM_SUMMARY_CONFIG_HPP
21 #define OPM_SUMMARY_CONFIG_HPP
22 
23 #include <opm/io/eclipse/SummaryNode.hpp>
24 
25 #include <opm/common/OpmLog/KeywordLocation.hpp>
26 
27 #include <opm/input/eclipse/EclipseState/Grid/GridDims.hpp>
28 
29 #include <array>
30 #include <cstddef>
31 #include <functional>
32 #include <limits>
33 #include <optional>
34 #include <set>
35 #include <string>
36 #include <unordered_set>
37 #include <vector>
38 
39 namespace Opm {
40  class AquiferConfig;
41  class Deck;
42  class EclipseState;
43  class ErrorGuard;
44  class FieldPropsManager;
45  class ParseContext;
46  class Schedule;
47 } // namespace Opm
48 
49 namespace Opm {
50 
57  {
58  public:
60  using Category = Opm::EclIO::SummaryNode::Category;
61 
63  using Type = Opm::EclIO::SummaryNode::Type;
64 
69  SummaryConfigNode() = default;
70 
79  explicit SummaryConfigNode(std::string keyword,
80  const Category cat,
81  KeywordLocation loc_arg);
82 
85 
93 
100  SummaryConfigNode& namedEntity(std::string name);
101 
108  SummaryConfigNode& number(const int num);
109 
116  SummaryConfigNode& isUserDefined(const bool userDefined);
117 
123  SummaryConfigNode& fip_region(const std::string& fip_region);
124 
126  const std::string& keyword() const { return this->keyword_; }
127 
129  Category category() const { return this->category_; }
130 
132  Type type() const { return this->type_; }
133 
135  const std::string& namedEntity() const { return this->name_; }
136 
138  int number() const { return this->number_; }
139 
141  bool isUserDefined() const { return this->userDefined_; }
142 
144  const std::string& fip_region() const { return *this->fip_region_ ; }
145 
147  const std::optional<std::string>& lgr_name() const
148  { return this->lgr_name_; }
149 
153  SummaryConfigNode& lgr_name(const std::string& name)
154  { this->lgr_name_ = name; return *this; }
155 
157  std::string uniqueNodeKey() const;
158 
162  const KeywordLocation& location() const { return this->loc; }
163 
165  operator EclIO::SummaryNode() const
166  {
167  auto lgr = this->lgr_name_.has_value()
168  ? std::optional<EclIO::lgr_info>{ EclIO::lgr_info{ *this->lgr_name_, {} } }
169  : std::optional<EclIO::lgr_info>{};
170 
171  return {
172  /* keyword = */ this->keyword_,
173  /* category = */ this->category_,
174  /* type = */ this->type_,
175  /* wgname = */ this->name_,
176  /* number = */ this->number_,
177  /* fip_region = */ this->fip_region_,
178  /* lgr = */ std::move(lgr)
179  };
180  }
181 
187  template<class Serializer>
188  void serializeOp(Serializer& serializer)
189  {
190  serializer(keyword_);
191  serializer(category_);
192  serializer(loc);
193  serializer(type_);
194  serializer(name_);
195  serializer(number_);
196  serializer(fip_region_);
197  serializer(userDefined_);
198  serializer(lgr_name_);
199  }
200 
201  private:
203  std::string keyword_{};
204 
206  Category category_{};
207 
209  Type type_{ Type::Undefined };
210 
212  std::string name_{};
213 
218  int number_{std::numeric_limits<int>::min()};
219 
221  std::optional<std::string> fip_region_{};
222 
224  bool userDefined_{false};
225 
229  KeywordLocation loc{};
230 
233  std::optional<std::string> lgr_name_{};
234 
235  };
236 
243  SummaryConfigNode::Category parseKeywordCategory(const std::string& keyword);
244 
251  SummaryConfigNode::Type parseKeywordType(std::string keyword);
252 
260  bool operator==(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs);
261 
269  bool operator<(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs);
270 
278  inline bool operator!=(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs)
279  {
280  return ! (lhs == rhs);
281  }
282 
290  inline bool operator<=(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs)
291  {
292  return ! (rhs < lhs);
293  }
294 
302  inline bool operator>(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs)
303  {
304  return rhs < lhs;
305  }
306 
314  inline bool operator>=(const SummaryConfigNode& lhs, const SummaryConfigNode& rhs)
315  {
316  return ! (lhs < rhs);
317  }
318 
321  {
322  public:
325  using keyword_list = std::vector<SummaryConfigNode>;
326 
328  SummaryConfig() = default;
329 
358  SummaryConfig(const Deck& deck,
359  const Schedule& schedule,
360  const FieldPropsManager& field_props,
361  const AquiferConfig& aquiferConfig,
362  const ParseContext& parseContext,
363  ErrorGuard& errors);
364 
399  template <typename T>
400  SummaryConfig(const Deck& deck,
401  const Schedule& schedule,
402  const FieldPropsManager& field_props,
403  const AquiferConfig& aquiferConfig,
404  const ParseContext& parseContext,
405  T&& errors);
406 
430  SummaryConfig(const Deck& deck,
431  const Schedule& schedule,
432  const FieldPropsManager& field_props,
433  const AquiferConfig& aquiferConfig);
434 
446  const std::set<std::string>& shortKwds,
447  const std::set<std::string>& smryKwds);
448 
451 
455  auto begin() const { return this->m_keywords.begin(); }
456 
460  auto end() const { return this->m_keywords.end(); }
461 
463  std::size_t size() const { return this->m_keywords.size(); }
464 
467  {
468  return this->extraFracturingVectors_;
469  }
470 
476  SummaryConfig& merge(const SummaryConfig& other);
477 
488 
509  registerRequisiteUDQorActionSummaryKeys(const std::vector<std::string>& extraKeys,
510  const EclipseState& es,
511  const Schedule& sched);
512 
521  bool hasKeyword(const std::string& keyword) const;
522 
533  bool match(const std::string& keywordPattern) const;
534 
544  keyword_list keywords(const std::string& keywordPattern) const;
545 
552  bool hasSummaryKey(const std::string& key) const;
553 
562  bool require3DField(const std::string& keyword) const;
563 
565  std::set<std::string> fip_regions() const;
566 
568  std::set<std::string> fip_regions_interreg_flow() const;
569 
576  bool operator==(const SummaryConfig& data) const;
577 
583  template<class Serializer>
584  void serializeOp(Serializer& serializer)
585  {
586  serializer(this->m_keywords);
587  serializer(this->extraFracturingVectors_);
588  serializer(this->short_keywords);
589  serializer(this->summary_keywords);
590  serializer(this->noSumLgr_);
591  }
592 
595  bool createRunSummary() const
596  { return runSummaryConfig.create; }
597 
599  bool noSumLgr() const { return this->noSumLgr_; }
600 
607  const SummaryConfigNode& operator[](std::size_t index) const;
608 
647  SummaryConfig(const Deck& deck,
648  const Schedule& schedule,
649  const FieldPropsManager& field_props,
650  const AquiferConfig& aquiferConfig,
651  const ParseContext& parseContext,
652  ErrorGuard& errors,
653  std::function<GridDims(const std::string&)> gridDims);
654 
655  private:
657  keyword_list m_keywords{};
658 
661  keyword_list extraFracturingVectors_{};
662 
668  std::set<std::string> short_keywords{};
669 
671  std::set<std::string> summary_keywords{};
672 
674  struct {
677  bool create { false };
678 
682  bool narrow { false };
683 
688  bool separate { true };
689  } runSummaryConfig{};
690 
693  bool noSumLgr_ { false };
694 
703  void handleProcessingInstruction(const std::string& keyword);
704  };
705 
706 } // namespace Opm
707 
708 #endif // OPM_SUMMARY_CONFIG_HPP
SummaryConfig()=default
Default constructor.
bool narrow
Whether or not to output the .RSM file in "narrow" format.
Definition: SummaryConfig.hpp:682
std::vector< SummaryConfigNode > keyword_list
Convenience type alias for a linear sequence of summary vector definitions.
Definition: SummaryConfig.hpp:325
bool createRunSummary() const
Whether or not to create a human-readable .RSM file at the end of the simulation run.
Definition: SummaryConfig.hpp:595
std::size_t size() const
Number of summary vectors in current collection.
Definition: SummaryConfig.hpp:463
bool isUserDefined() const
Retrieve summary vector&#39;s UDQ flag.
Definition: SummaryConfig.hpp:141
Definition: KeywordLocation.hpp:27
Opm::EclIO::SummaryNode::Type Type
Summary vector type (rates, cumulative, pressure, &c)
Definition: SummaryConfig.hpp:63
int number() const
Retrieve summary vector&#39;s associated numeric ID.
Definition: SummaryConfig.hpp:138
Definition: Schedule.hpp:102
const std::string & fip_region() const
Retrieve summary vector&#39;s associated region.
Definition: SummaryConfig.hpp:144
bool operator==(const SummaryConfig &data) const
Equality predicate.
Collection of run&#39;s summary vectors.
Definition: SummaryConfig.hpp:320
bool operator<=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Less-than-or-equal comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:290
Definition: FieldPropsManager.hpp:42
const std::string & keyword() const
Retrieve summary vector name.
Definition: SummaryConfig.hpp:126
SummaryConfigNode::Category parseKeywordCategory(const std::string &keyword)
Infer summary vector level from keyword name.
Definition of a single summary vector.
Definition: SummaryConfig.hpp:56
const std::optional< std::string > & lgr_name() const
Retrieve LGR name for this summary vector.
Definition: SummaryConfig.hpp:147
bool operator>(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:302
std::set< std::string > fip_regions() const
Named region sets needed across all known region level vectors.
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
Definition: SummaryNode.hpp:31
bool hasKeyword(const std::string &keyword) const
Query existence of summary vector name.
bool hasSummaryKey(const std::string &key) const
Query existence of fully qualified summary vector key.
Definition: EclipseState.hpp:66
Definition: AquiferConfig.hpp:73
bool operator>=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Greater-than-or-equal comparison operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:314
bool operator<(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Canonical comparison operator for SummaryConfigNode objects.
SummaryConfigNode::Type parseKeywordType(std::string keyword)
Infer summary vector type from keyword name.
std::string uniqueNodeKey() const
Retrieve a unique distinguishing identifier for this summary vector.
SummaryConfigNode()=default
Default constructor.
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition: SummaryConfig.hpp:188
SummaryConfigNode & parameterType(const Type type)
Assign vector type.
bool require3DField(const std::string &keyword) const
Query whether or not a 3D dynamic property is needed to evaluate some/all summary vectors...
const SummaryConfigNode & operator[](std::size_t index) const
Retrieve summary vector definition from linear index.
keyword_list registerRequisiteUDQorActionSummaryKeys(const std::vector< std::string > &extraKeys, const EclipseState &es, const Schedule &sched)
Form definitions from vectors used in UDQs and ACTIONX.
static SummaryConfig serializationTestObject()
Create a serialisation test object.
bool create
Whether or not to create a human-readable .RSM file at the end of the simulation run.
Definition: SummaryConfig.hpp:677
Type type() const
Retrieve summary vector&#39;s type.
Definition: SummaryConfig.hpp:132
bool noSumLgr() const
Whether or not to suppress the ROOT.LGR local-grid summary file.
Definition: SummaryConfig.hpp:599
Control parser behaviour in failure conditions.
Definition: ParseContext.hpp:114
auto end() const
One past the end of the sequence of summary vector definitions.
Definition: SummaryConfig.hpp:460
SummaryConfigNode & lgr_name(const std::string &name)
Assign LGR name for this summary vector.
Definition: SummaryConfig.hpp:153
Category category() const
Retrieve summary vector&#39;s level.
Definition: SummaryConfig.hpp:129
const KeywordLocation & location() const
Retrieve summary keyword location in input.
Definition: SummaryConfig.hpp:162
Definition: GridDims.hpp:30
Definition: SummaryNode.hpp:36
const keyword_list & extraFracturingVectors() const
Partially defined summary vectors relating to fracturing processes.
Definition: SummaryConfig.hpp:466
keyword_list keywords(const std::string &keywordPattern) const
Retrieve all vector definitions matching a vector name pattern.
Definition: Deck.hpp:46
SummaryConfig & merge(const SummaryConfig &other)
Incorporate other vector collection into current.
const std::string & namedEntity() const
Retrieve summary vector&#39;s named entity.
Definition: SummaryConfig.hpp:135
Opm::EclIO::SummaryNode::Category Category
Summary vector level (field, well, region, &c).
Definition: SummaryConfig.hpp:60
std::set< std::string > fip_regions_interreg_flow() const
Named region sets needed across all known inter-region vectors.
bool separate
Whether or not to create a separate .RSM file instead of placing the run summary at the end of the ...
Definition: SummaryConfig.hpp:688
Class for (de-)serializing.
Definition: Serializer.hpp:95
bool match(const std::string &keywordPattern) const
Query existence of summary vector name with pattern matching.
auto begin() const
Beginning of sequence of summary vector definitions.
Definition: SummaryConfig.hpp:455
bool operator!=(const SummaryConfigNode &lhs, const SummaryConfigNode &rhs)
Inequality operator for SummaryConfigNode objects.
Definition: SummaryConfig.hpp:278
Definition: ErrorGuard.hpp:30
static SummaryConfigNode serializationTestObject()
Create a serialisation test object.
void serializeOp(Serializer &serializer)
Convert between byte array and object representation.
Definition: SummaryConfig.hpp:584