summaryComparator.hpp
1 /*
2  Copyright 2016 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 it under
7  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 SUMMARYCOMPARATOR_HPP
21 #define SUMMARYCOMPARATOR_HPP
22 
23 #include <iostream>
24 #include <iomanip>
25 #include <vector>
26 #include <algorithm>
27 #include <string>
28 
29 
30 // helper macro to handle error throws or not
31 #define HANDLE_ERROR(type, message) \
32  { \
33  if (throwOnError) \
34  OPM_THROW(type, message); \
35  else \
36  std::cerr << message << std::endl; \
37  }
38 
39 
41 struct stringlist_struct;
42 typedef struct stringlist_struct stringlist_type;
43 
45 struct ecl_sum_struct;
46 typedef struct ecl_sum_struct ecl_sum_type;
47 
48 
50 struct Deviation {
51  double abs = 0;
52  double rel = 0;
53 };
54 
55 
57  private:
58  double absoluteTolerance = 0;
59  double relativeTolerance = 0;
60  protected:
61  ecl_sum_type * ecl_sum1 = nullptr;
62  ecl_sum_type * ecl_sum2 = nullptr;
63  ecl_sum_type * ecl_sum_fileShort = nullptr;
64  ecl_sum_type * ecl_sum_fileLong = nullptr;
65  stringlist_type* keys1 = nullptr;
66  stringlist_type* keys2 = nullptr;
67  stringlist_type * keysShort = nullptr;
68  stringlist_type * keysLong = nullptr;
69  const std::vector<double> * referenceVec = nullptr;
70  const std::vector<double> * referenceDataVec = nullptr;
71  const std::vector<double> * checkVec = nullptr;
72  const std::vector<double> * checkDataVec = nullptr;
73  bool printKeyword = false;
74  bool printSpecificKeyword = false;
75  bool throwOnError = true;
76 
82  void getDeviation(size_t refIndex, size_t &checkIndex, Deviation &dev);
83 
88  void setDataSets(const std::vector<double>& timeVec1,
89  const std::vector<double>& timeVec2);
90 
94  void setTimeVecs(std::vector<double> &timeVec1,std::vector<double> &timeVec2);
95 
100  void getDataVecs(std::vector<double> &dataVec1,
101  std::vector<double> &dataVec2, const char* keyword);
102 
109  void chooseReference(const std::vector<double> &timeVec1,
110  const std::vector<double> &timeVec2,
111  const std::vector<double> &dataVec1,
112  const std::vector<double> &dataVec2);
113 
115  double getRelTolerance(){return this->relativeTolerance;}
116 
118  double getAbsTolerance(){return this->absoluteTolerance;}
119 
123  const char* getUnit(const char* keyword);
124 
126  void printUnits();
127 
130  void printKeywords();
131 
134  void printDataOfSpecificKeyword(const std::vector<double>& timeVec1,
135  const std::vector<double>& timeVec2,
136  const char* keyword);
137 
138  public:
145  SummaryComparator(const char* basename1, const char* basename2, double absoluteTolerance, double relativeTolerance);
146 
150 
156  static Deviation calculateDeviations( double val1, double val2);
157 
161  void setPrintKeywords(bool boolean){this->printKeyword = boolean;}
162 
166  void setPrintSpecificKeyword(bool boolean){this->printSpecificKeyword = boolean;}
167 
172 
174  static double unitStep(double value){return value;}
175 
177  void throwOnErrors(bool dothrow) { throwOnError = dothrow; }
178 };
179 
180 #endif
~SummaryComparator()
Destructor.
Definition: summaryComparator.cpp:53
bool printSpecificKeyword
Boolean value for choosing whether to print the vectors of a keyword or not.
Definition: summaryComparator.hpp:74
void getDeviation(size_t refIndex, size_t &checkIndex, Deviation &dev)
Calculate deviation between two data values and stores it in a Deviation struct.
Definition: summaryComparator.cpp:133
static double unitStep(double value)
Unit step function.
Definition: summaryComparator.hpp:174
double getAbsTolerance()
Returns the absolute tolerance.
Definition: summaryComparator.hpp:118
const char * getUnit(const char *keyword)
Returns the unit of the values of a keyword.
Definition: summaryComparator.cpp:169
void setPrintKeywords(bool boolean)
Sets the private member variable printKeywords.
Definition: summaryComparator.hpp:161
double getRelTolerance()
Returns the relative tolerance.
Definition: summaryComparator.hpp:115
ecl_sum_type * ecl_sum_fileShort
For keeping track of the file with most/fewest timesteps.
Definition: summaryComparator.hpp:63
void printKeywords()
Prints the keywords of the files.
Definition: summaryComparator.cpp:174
void setPrintSpecificKeyword(bool boolean)
Sets the private member variable printSpecificKeyword.
Definition: summaryComparator.hpp:166
const std::vector< double > * referenceVec
For storing the values of each time step for the file containing the fewer time steps.
Definition: summaryComparator.hpp:69
double rel
Relative deviation.
Definition: EclFilesComparator.hpp:41
Deviation struct.
Definition: EclFilesComparator.hpp:39
double abs
Absolute deviation.
Definition: EclFilesComparator.hpp:40
void throwOnErrors(bool dothrow)
Set whether to throw on errors or not.
Definition: summaryComparator.hpp:177
void printUnits()
Prints the units of the files.
Definition: summaryComparator.cpp:158
ecl_sum_type * ecl_sum1
Struct that contains file1.
Definition: summaryComparator.hpp:61
stringlist_type * keys2
For storing all the keywords of file2.
Definition: summaryComparator.hpp:66
bool throwOnError
Throw on first error.
Definition: summaryComparator.hpp:75
Definition: summaryComparator.hpp:56
ecl_sum_type * ecl_sum2
Struct that contains file2.
Definition: summaryComparator.hpp:62
stringlist_type * keysShort
For keeping track of the file with most/fewest keywords.
Definition: summaryComparator.hpp:67
void setTimeVecs(std::vector< double > &timeVec1, std::vector< double > &timeVec2)
Reads in the time values of each time step.
Definition: summaryComparator.cpp:73
static Deviation calculateDeviations(double val1, double val2)
Calculates the deviation between two values.
Definition: summaryComparator.cpp:61
stringlist_type * keysLong
For keeping track of the file with most/fewest keywords.
Definition: summaryComparator.hpp:68
bool printKeyword
Boolean value for choosing whether to print the keywords or not.
Definition: summaryComparator.hpp:73
ecl_sum_type * ecl_sum_fileLong
For keeping track of the file with most/fewest timesteps.
Definition: summaryComparator.hpp:64
void setDataSets(const std::vector< double > &timeVec1, const std::vector< double > &timeVec2)
Figure out which data file contains the most / less timesteps and assign member variable pointers acc...
Definition: summaryComparator.cpp:101
void chooseReference(const std::vector< double > &timeVec1, const std::vector< double > &timeVec2, const std::vector< double > &dataVec1, const std::vector< double > &dataVec2)
Sets one data set as a basis and the other as values to check against.
Definition: summaryComparator.cpp:114
const std::vector< double > * checkDataVec
For storing the data values corresponding to each time step for the file containing the more time ste...
Definition: summaryComparator.hpp:72
void getDataVecs(std::vector< double > &dataVec1, std::vector< double > &dataVec2, const char *keyword)
Read the data for one specific keyword into two separate vectors.
Definition: summaryComparator.cpp:86
const std::vector< double > * referenceDataVec
For storing the data corresponding to each time step for the file containing the fewer time steps...
Definition: summaryComparator.hpp:70
void printDataOfSpecificKeyword(const std::vector< double > &timeVec1, const std::vector< double > &timeVec2, const char *keyword)
Prints the summary vectors from the two files.
Definition: summaryComparator.cpp:200
stringlist_type * keys1
For storing all the keywords of file1.
Definition: summaryComparator.hpp:65
SummaryComparator(const char *basename1, const char *basename2, double absoluteTolerance, double relativeTolerance)
Creates an SummaryComparator class object.
Definition: summaryComparator.cpp:28
const std::vector< double > * checkVec
For storing the values of each time step for the file containing the more time steps.
Definition: summaryComparator.hpp:71