opm-common
EclRegressionTest.hpp
1 /*
2  Copyright 2019 Equinor 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 ECLREGRESSIONTEST_HPP
21 #define ECLREGRESSIONTEST_HPP
22 
23 #include "EclFilesComparator.hpp"
24 
25 #include <opm/io/eclipse/EclIOdata.hpp>
26 
27 namespace Opm { namespace EclIO {
28  class EGrid;
29 }}
30 
31 namespace EIOD = Opm::EclIO;
32 
33 
42 public:
49  ECLRegressionTest(const std::string& basename1, const std::string& basename2,
50  double absToleranceArg, double relToleranceArg):
51  ECLFilesComparator(basename1, basename2, absToleranceArg, relToleranceArg) {}
52 
54 
56  void setOnlyLastReportNumber(bool onlyLastSequenceArg) {
57  this->onlyLastSequence = onlyLastSequenceArg;
58  }
59 
60  int countDev() { return deviations.size(); }
61 
62 
63  void setReportStepOnly(bool reportStepOnlyArg) {
64  this->reportStepOnly = reportStepOnlyArg;
65  }
66 
67  // Accept extra keywords: If this switch is set to true the comparison
68  // will ignore extra keywords which are only present
69  // in the new simulation.
70  void setAcceptExtraKeywords(bool acceptExtraKeywordsArg) {
71  this->acceptExtraKeywords = acceptExtraKeywordsArg;
72  }
73 
74  //Accept extra keywords in both simulations and compare only the keywords available in both runs
75  void setAcceptExtraKeywordsBoth(bool acceptExtraKeywordsArg) {
76  this->acceptExtraKeywordsBoth = acceptExtraKeywordsArg;
77  }
78 
79  void setIntegrationTest(bool inregrationTestArg) {
80  this->integrationTest = inregrationTestArg;
81  }
82 
83  void setPrintKeywordOnly(bool printArg) {
84  this->printKeywordOnly = printArg;
85  }
86 
87  void compareSpecificKeyword(std::string keyword) {
88  this->specificKeyword = std::move(keyword);
89  }
90  void compareSpesificRstReportStepNumber(int seqn) {
91  this->specificSequence = seqn;
92  }
93 
94  void setLoadBaseRunData(bool loadArg) {
95  this->loadBaseRunData = loadArg;
96  }
97 
98  void loadGrids();
99  void printDeviationReport();
100 
101  void gridCompare();
102 
103  void results_rst();
104  void results_init();
105  void results_smry();
106  void results_rsm();
107  void results_rft();
108 
109 private:
110  bool checkFileName(const std::string& rootName, const std::string& extension, std::string& filename);
111 
112  // Prints results stored in absDeviation and relDeviation.
113  void printResultsForKeyword(const std::string& keyword) const;
114  void printComparisonForKeywordLists(const std::vector<std::string>& arrayList1,
115  const std::vector<std::string>& arrayList2) const;
116 
117  void printComparisonForKeywordLists(const std::vector<std::string>& arrayList1,
118  const std::vector<std::string>& arrayList2,
119  const std::vector<EIOD::eclArrType>& arrayType1,
120  const std::vector<EIOD::eclArrType>& arrayType2) const;
121 
122  void printMissingKeywords(const std::vector<std::string>& arrayList1,
123  const std::vector<std::string>& arrayList2) const;
124 
125  void compareKeywords(const std::vector<std::string>& keywords1,
126  const std::vector<std::string>& keywords2,
127  const std::string& reference);
128 
129  void checkSpecificKeyword(std::vector<std::string>& keywords1,
130  std::vector<std::string>& keywords2,
131  std::vector<EIOD::eclArrType>& arrayType1,
132  std::vector<EIOD::eclArrType>& arrayType2,
133  const std::string& reference);
134 
135  template <typename T>
136  void compareVectors(const std::vector<T>& t1, const std::vector<T>& t2,
137  const std::string& keyword, const std::string& reference);
138 
139  template <typename T>
140  void compareFloatingPointVectors(const std::vector<T>& t1, const std::vector<T> &t2,
141  const std::string& keyword, const std::string& reference);
142 
143  // deviationsForCell throws an exception if both the absolute deviation AND the relative deviation
144  // are larger than absTolerance and relTolerance, respectively. In addition,
145  // if allowNegativeValues is passed as false, an exception will be thrown when the absolute value
146  // of a negative value exceeds absTolerance. If no exceptions are thrown, the absolute and relative deviations are added to absDeviation and relDeviation.
147  // void deviationsForCell(double val1, double val2, const std::string& keyword, const std::string reference, size_t kw_size, size_t cell, bool allowNegativeValues = true);
148 
149  void deviationsForCell(double val1, double val2, const std::string& keyword,
150  const std::string& reference, size_t kw_size, size_t cell,
151  bool allowNegativeValues, bool useStrictTol);
152 
153  template <typename T>
154  void deviationsForNonFloatingPoints(T val1, T val2, const std::string& keyword,
155  const std::string& reference,
156  size_t kw_size, size_t cell);
157 
158  // These vectors store absolute and relative deviations, respecively. Note that they are whiped clean for every new keyword comparison.
159  std::vector<double> absDeviation, relDeviation;
160 
161  // Keywords which should not contain negative values, i.e. uses allowNegativeValues = false in deviationsForCell():
162  const std::vector<std::string> keywordDisallowNegatives = {};//{"SGAS", "SWAT", "PRESSURE"};
163 
164  double strictAbsTol = 1e-6;
165  double strictRelTol = 1e-6;
166 
167  // keywords that triggers strict tolerances
168  const std::vector<std::string> keywordsStrictTol = {"COORD", "ZCORN", "PORV", "DEPTH", "DX", "DY", "DZ", "PERMX", "PERMY", "PERMZ", "NTG",
169  "TRANX", "TRANY", "TRANZ", "TRANNNC", "SGRP", "SCON", "DOUBHEAD"
170  };
171  // keywords that should not be compared
172  const std::vector<std::string> keywordsBlackList = {"TCPU", "ELAPSED", "TCPUDAY", "TCPUTS", "TELAPLIN", "TCPUH", "TCPUHT", "TCPUSCH", "TCPUTSH", "TCPUTSHT", "TELAPDAY", "TELAPTS"};
173  const std::vector<std::string> keywordsBlackListExtraRestart = {"MLINEARS", "MSUMLINS", "MSUMNEWT", "NEWTON", "NLINEARS", "NLINSMAX", "NLINSMIN"};
174 
175  bool reportStepOnly = false;
176 
177  // Only compare last occurrence
178  bool onlyLastSequence = false;
179 
180  bool integrationTest = false;
181 
182  bool printKeywordOnly = false;
183 
184  bool loadBaseRunData = false;
185 
186  // specific keyword to be compared
187  std::string specificKeyword;
188 
189  // specific restart sequence to be compared
190  int specificSequence = -1;
191 
192  // Accept extra keywords in the restart file of the 'new' simulation.
193  bool acceptExtraKeywords = false;
194  bool acceptExtraKeywordsBoth = false;
195 
196  Opm::EclIO::EGrid* grid1 = nullptr;
197  Opm::EclIO::EGrid* grid2 = nullptr;
198 };
199 
200 #endif
A class for executing a regression test for two ECLIPSE files.
Definition: EclRegressionTest.hpp:41
This class implements a small container which holds the transmissibility mulitpliers for all the face...
Definition: Exceptions.hpp:30
ECLRegressionTest(const std::string &basename1, const std::string &basename2, double absToleranceArg, double relToleranceArg)
Sets up the regression test.
Definition: EclRegressionTest.hpp:49
void setOnlyLastReportNumber(bool onlyLastSequenceArg)
Option to only compare last occurrence.
Definition: EclRegressionTest.hpp:56
Definition: EclipseGrid.hpp:43
Definition: EGrid.hpp:32
Definition: EclFilesComparator.hpp:34