Skip to content

Commit

Permalink
Merge pull request #193 from akva2/sca_fixes
Browse files Browse the repository at this point in the history
Fixes for warnings from static code analysis
  • Loading branch information
joakim-hove committed Jun 9, 2017
2 parents 7d68753 + 25d14c3 commit 1ee6f4e
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion opm/output/data/Solution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Solution : public std::map< std::string, data::CellData > {

public:
Solution() = default;
Solution( bool si );
explicit Solution( bool si );
using Base::map;
using Base::insert;

Expand Down
11 changes: 6 additions & 5 deletions opm/output/data/Wells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace Opm {
*/

public:
Rates() = default;
enum class opt : uint32_t {
wat = (1 << 0),
oil = (1 << 1),
Expand Down Expand Up @@ -76,11 +77,11 @@ namespace Opm {

opt mask = static_cast< opt >( 0 );

double wat;
double oil;
double gas;
double polymer;
double solvent;
double wat = 0.0;
double oil = 0.0;
double gas = 0.0;
double polymer = 0.0;
double solvent = 0.0;
};

struct Completion {
Expand Down
2 changes: 1 addition & 1 deletion opm/output/eclipse/EclipseGridInspector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EclipseGridInspector
public:
/// Constructor taking a parser as argument.
/// The parser must already have read an Eclipse file.
EclipseGridInspector(Opm::Deck);
explicit EclipseGridInspector(Opm::Deck);

/// Assuming that the pillars are vertical, compute the
/// volume of the cell given by logical coordinates (i, j, k).
Expand Down
6 changes: 3 additions & 3 deletions opm/output/eclipse/RestartIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ std::vector<int> serialize_IWEL( size_t step,


std::vector< int > serialize_OPM_IWEL( const data::Wells& wells,
const std::vector< const Well* > sched_wells ) {
const std::vector< const Well* >& sched_wells ) {

const auto getctrl = [&]( const Well* w ) {
const auto itr = wells.find( w->name() );
Expand All @@ -348,7 +348,7 @@ std::vector< int > serialize_OPM_IWEL( const data::Wells& wells,

std::vector< double > serialize_OPM_XWEL( const data::Wells& wells,
int report_step,
const std::vector< const Well* > sched_wells,
const std::vector< const Well* >& sched_wells,
const Phases& phase_spec,
const EclipseGrid& grid ) {

Expand Down Expand Up @@ -537,7 +537,7 @@ void writeWell(ecl_rst_file_type* rst_file, int report_step, const EclipseState&

void checkSaveArguments(const data::Solution& cells,
const EclipseGrid& grid,
const std::map<std::string, std::vector<double>> extra_data) {
const std::map<std::string, std::vector<double>>& extra_data) {

const std::set<std::string> reserved_keys = {"LOGIHEAD", "INTEHEAD" ,"DOUBHEAD", "IWEL", "XWEL","ICON", "XCON" , "OPM_IWEL" , "OPM_XWEL", "ZWEL"};

Expand Down
2 changes: 1 addition & 1 deletion opm/output/eclipse/RestartValue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Opm {
UnitSystem::measure dim;
bool required = true;

RestartKey( UnitSystem::measure _dim)
explicit RestartKey( UnitSystem::measure _dim)
: dim(_dim)
{}

Expand Down
2 changes: 1 addition & 1 deletion opm/output/eclipse/Tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace Opm {

class Tables {
public:
Tables( const UnitSystem& units_);
explicit Tables( const UnitSystem& units_);
void fwrite( ERT::FortIO& fortio ) const;
void addPVTO( const std::vector<PvtoTable>& pvtoTables);
void addPVTG( const std::vector<PvtgTable>& pvtgTables);
Expand Down
4 changes: 2 additions & 2 deletions opm/test_util/EclFilesComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ void RegressionTest::results() {



void RegressionTest::resultsForKeyword(const std::string keyword) {
void RegressionTest::resultsForKeyword(const std::string& keyword) {
keywordValidForComparing(keyword);
const unsigned int occurrences1 = ecl_file_get_num_named_kw(ecl_file1, keyword.c_str());
const unsigned int occurrences2 = ecl_file_get_num_named_kw(ecl_file2, keyword.c_str());
Expand Down Expand Up @@ -651,7 +651,7 @@ void IntegrationTest::results() {



void IntegrationTest::resultsForKeyword(const std::string keyword) {
void IntegrationTest::resultsForKeyword(const std::string& keyword) {
std::cout << "Comparing " << keyword << "...";
keywordValidForComparing(keyword);
const unsigned int occurrences1 = ecl_file_get_num_named_kw(ecl_file1, keyword.c_str());
Expand Down
4 changes: 2 additions & 2 deletions opm/test_util/EclFilesComparator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class RegressionTest: public ECLFilesComparator {
//! \brief Calculates deviations for a specific keyword.
//! \param[in] keyword Keyword which should be compared, if this keyword is absent in one of the cases, an exception will be thrown.
//! \details This function loops through every report step and every cell and compares the values for the given keyword from the two input cases. If the absolute or relative deviation between the two values for each step exceeds both the absolute tolerance and the relative tolerance (stored in ECLFilesComparator), an exception is thrown. In addition, some keywords are marked for "disallow negative values" -- these are SGAS, SWAT and PRESSURE. An exception is thrown if a value of one of these keywords is both negative and has an absolute value larger than the absolute tolerance. If no exceptions are thrown, resultsForKeyword() uses the private member funtion printResultsForKeyword to print the average and median deviations.
void resultsForKeyword(const std::string keyword);
void resultsForKeyword(const std::string& keyword);
};


Expand Down Expand Up @@ -239,7 +239,7 @@ class IntegrationTest: public ECLFilesComparator {
* For all other occurrences \f$n\f$, the deviation value \f$\Delta\f$ is calculated the same way, but the total value \f$S\f$ is calculated relative to the initial occurrence total \f$S_0\f$:
* \f[ S = \sum_{i} |q_{n,i} - q_{0,i}| v_i. \f]
* The error ratio is \f$ E = \Delta/S\f$. */
void resultsForKeyword(const std::string keyword);
void resultsForKeyword(const std::string& keyword);
};

#endif
5 changes: 2 additions & 3 deletions opm/test_util/summaryComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ SummaryComparator::~SummaryComparator(){


Deviation SummaryComparator::calculateDeviations(double val1, double val2){
double absDev, relDev;
double absDev;
Deviation deviation;
absDev = std::abs(val1 - val2);
deviation.abs = absDev;
if (val1 != 0 || val2 != 0) {
relDev = absDev/double(std::max(std::abs(val1), std::abs(val2)));
deviation.rel = relDev;
deviation.rel = absDev/double(std::max(std::abs(val1), std::abs(val2)));
}
return deviation;
}
Expand Down
10 changes: 5 additions & 5 deletions opm/test_util/summaryIntegrationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,12 @@ void IntegrationTest::evaluateWellProductionVolume(){
void IntegrationTest::checkWithSpikes(const char* keyword){
int errorOccurrences = 0;
size_t jvar = 0 ;
bool spikePrev = false;
bool spikeCurrent = false;
Deviation deviation;

for (size_t ivar = 0; ivar < referenceVec->size(); ivar++){
int errorOccurrencesPrev = errorOccurrences;
spikePrev = spikeCurrent;
bool spikePrev = spikeCurrent;
getDeviation(ivar,jvar, deviation);
errorOccurrences += checkDeviation(deviation);
if (errorOccurrences != errorOccurrencesPrev){
Expand Down Expand Up @@ -306,6 +305,7 @@ IntegrationTest::getSpecificWellVolume(const std::vector<double>& timeVec1,
}


#if 0
bool IntegrationTest::checkUnits(const char * keyword){
const smspec_node_type * node1 = ecl_sum_get_general_var_node (ecl_sum_fileShort ,keyword);
const smspec_node_type * node2 = ecl_sum_get_general_var_node (ecl_sum_fileLong ,keyword);
Expand All @@ -314,18 +314,18 @@ bool IntegrationTest::checkUnits(const char * keyword){
}
return false;
}
#endif


double IntegrationTest::integrate(const std::vector<double>& timeVec,
const std::vector<double>& dataVec){
double totalSum = 0;
double width, height;
if(timeVec.size() != dataVec.size()){
OPM_THROW(std::runtime_error, "The size of the time vector does not match the size of the data vector.");
}
for(size_t i = 0; i < timeVec.size()-1; i++){
width = timeVec[i+1] - timeVec[i];
height = dataVec[i+1];
double width = timeVec[i+1] - timeVec[i];
double height = dataVec[i+1];
totalSum += getRectangleArea(height, width);
}
return totalSum;
Expand Down
2 changes: 2 additions & 0 deletions opm/test_util/summaryIntegrationTest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ class IntegrationTest: public SummaryComparator {
const char* currentKeyword,
std::string &greatestErrorRatio);

#if 0
//! \brief Checks whether the unit of the two data vectors is the same
//! \param[in] keyword The keyword of interest
//! \param[out] boolean True/false, depending on whether the units are equal or not
bool checkUnits(const char* keyword);
#endif
public:
//! \brief Constructor, creates an object of IntegrationTest class.
//! \param[in] basename1 Path to file1 without extension.
Expand Down
1 change: 0 additions & 1 deletion opm/test_util/summaryRegressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ void RegressionTest::getRegressionTest(){
std::vector<double> timeVec1, timeVec2;
setTimeVecs(timeVec1, timeVec2); // Sets the time vectors, they are equal for all keywords (WPOR:PROD01 etc)
setDataSets(timeVec1, timeVec2); //Figures which dataset that contains more/less values pr keyword vector.
std::vector<double> dataVec1, dataVec2, absDevVec, relDevVec;
std::cout << "Comparing " << timeVec1.size() << " steps." << std::endl;
int ivar = 0;
if(stringlist_get_size(keysShort) != stringlist_get_size(keysLong)){
Expand Down
16 changes: 8 additions & 8 deletions tests/test_Restart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ void compare( const RestartValue& fst,
}

BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData) {
std::map<std::string, RestartKey> keys {{"PRESSURE" , UnitSystem::measure::pressure},
{"SWAT" , UnitSystem::measure::identity},
{"SGAS" , UnitSystem::measure::identity},
{"TEMP" , UnitSystem::measure::temperature}};
std::map<std::string, RestartKey> keys {{"PRESSURE" , RestartKey(UnitSystem::measure::pressure)},
{"SWAT" , RestartKey(UnitSystem::measure::identity)},
{"SGAS" , RestartKey(UnitSystem::measure::identity)},
{"TEMP" , RestartKey(UnitSystem::measure::temperature)}};
ERT::TestArea testArea("test_Restart");
testArea.copyFile( "FIRST_SIM.DATA" );

Expand All @@ -401,7 +401,7 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData) {
auto state2 = second_sim( eclWriter , keys );
compare(state1, state2 , keys);

BOOST_CHECK_THROW( second_sim( eclWriter, {{"SOIL" , UnitSystem::measure::pressure}} ) , std::runtime_error );
BOOST_CHECK_THROW( second_sim( eclWriter, {{"SOIL" , RestartKey(UnitSystem::measure::pressure)}} ) , std::runtime_error );
BOOST_CHECK_THROW( second_sim( eclWriter, {{"SOIL" , { UnitSystem::measure::pressure, true}}} ) , std::runtime_error );
}

Expand Down Expand Up @@ -432,8 +432,8 @@ BOOST_AUTO_TEST_CASE(EclipseReadWriteWellStateData_double) {
this equality for the pressure. For this test we therefor only
consider the saturations which have identity unit.
*/
std::map<std::string, RestartKey> keys {{"SWAT" , UnitSystem::measure::identity},
{"SGAS" , UnitSystem::measure::identity}};
std::map<std::string, RestartKey> keys {{"SWAT" , RestartKey(UnitSystem::measure::identity)},
{"SGAS" , RestartKey(UnitSystem::measure::identity)}};

ERT::TestArea testArea("test_Restart");
testArea.copyFile( "FIRST_SIM.DATA" );
Expand Down Expand Up @@ -552,7 +552,7 @@ BOOST_AUTO_TEST_CASE(ExtraData_content) {

BOOST_CHECK_THROW( RestartIO::load( "FILE.UNRST" , 1 , {}, eclipseState, grid , {{"NOT-THIS", true}}) , std::runtime_error );
{
const auto rst_value = RestartIO::load( "FILE.UNRST" , 1 , {{"SWAT" , UnitSystem::measure::identity},
const auto rst_value = RestartIO::load( "FILE.UNRST" , 1 , {{"SWAT" , RestartKey(UnitSystem::measure::identity)},
{"NO" , {UnitSystem::measure::identity, false}}},
eclipseState, grid , {{"EXTRA", true}, {"EXTRA2", false}});
const auto pair = rst_value.extra.find( "EXTRA" );
Expand Down

0 comments on commit 1ee6f4e

Please sign in to comment.