My Project
UDQParams.hpp
1 /*
2  Copyright 2018 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_UDQ_PARAMS_HPP
21 #define OPM_UDQ_PARAMS_HPP
22 
23 #include <chrono>
24 #include <random>
25 
26 namespace Opm {
27 
28  class Deck;
29 
30  class UDQParams
31  {
32  public:
33  explicit UDQParams(const Deck& deck);
34  UDQParams();
35 
36  static UDQParams serializeObject();
37 
38  bool reseed() const;
39  int rand_seed() const noexcept;
40  void reseedRNG(int seed);
41  double range() const noexcept;
42  double undefinedValue() const noexcept;
43  double cmpEpsilon() const noexcept;
44 
45  std::mt19937& sim_rng();
46  std::mt19937& true_rng();
47 
48  bool operator==(const UDQParams& data) const;
49 
50  template<class Serializer>
51  void serializeOp(Serializer& serializer)
52  {
53  serializer(reseed_rng);
54  serializer(random_seed);
55  serializer(value_range);
56  serializer(undefined_value);
57  serializer(cmp_eps);
58 
59  if (!serializer.isSerializing()) {
60  auto now = std::chrono::high_resolution_clock::now();
61  auto ns = std::chrono::duration_cast<std::chrono::nanoseconds>(now.time_since_epoch());
62  this->m_true_rng.seed( ns.count() );
63  this->m_sim_rng.seed( this->random_seed );
64  }
65  }
66 
67  private:
68  bool reseed_rng;
69  int random_seed;
70  double value_range;
71  double undefined_value;
72  double cmp_eps;
73 
74  std::mt19937 m_sim_rng; // The sim_rng is seeded deterministiaclly at simulation start.
75  std::mt19937 m_true_rng; // The true_rng is seeded with a "true" random seed; this rng can be reset with reseedRNG()
76  };
77 }
78 
79 #endif
Definition: Deck.hpp:63
Definition: Serializer.hpp:38
Definition: UDQParams.hpp:31
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:29