Refactor: extract EnsembleParameter into separate file.

This commit is contained in:
Kristian Bendiksen
2021-05-31 11:00:23 +02:00
parent fb301ef3ab
commit f31aecf507
24 changed files with 331 additions and 265 deletions

View File

@@ -88,6 +88,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigTracerPoint.h
${CMAKE_CURRENT_LIST_DIR}/RigTracer.h
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanModelTools.h
${CMAKE_CURRENT_LIST_DIR}/RigSlice2D.h
${CMAKE_CURRENT_LIST_DIR}/RigEnsembleParameter.h
)
@@ -173,6 +174,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RigTracerPoint.cpp
${CMAKE_CURRENT_LIST_DIR}/RigTracer.cpp
${CMAKE_CURRENT_LIST_DIR}/RigStimPlanModelTools.cpp
${CMAKE_CURRENT_LIST_DIR}/RigSlice2D.cpp
${CMAKE_CURRENT_LIST_DIR}/RigEnsembleParameter.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,108 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2017- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RigEnsembleParameter.h"
#include <algorithm>
#include <cmath>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
double RigEnsembleParameter::stdDeviation() const
{
double N = static_cast<double>( values.size() );
if ( N > 1 && isNumeric() )
{
double sumValues = 0.0;
double sumValuesSquared = 0.0;
for ( const QVariant& variant : values )
{
double value = variant.toDouble();
sumValues += value;
sumValuesSquared += value * value;
}
return std::sqrt( ( N * sumValuesSquared - sumValues * sumValues ) / ( N * ( N - 1.0 ) ) );
}
return 0.0;
}
//--------------------------------------------------------------------------------------------------
/// Standard deviation normalized by max absolute value of min/max values.
/// Produces values between 0.0 and sqrt(2.0).
//--------------------------------------------------------------------------------------------------
double RigEnsembleParameter::normalizedStdDeviation() const
{
const double eps = 1.0e-4;
double maxAbs = std::max( std::fabs( maxValue ), std::fabs( minValue ) );
if ( maxAbs < eps )
{
return 0.0;
}
double normalisedStdDev = stdDeviation() / maxAbs;
if ( normalisedStdDev < eps )
{
return 0.0;
}
return normalisedStdDev;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigEnsembleParameter::operator<( const RigEnsembleParameter& other ) const
{
if ( this->variationBin != other.variationBin )
{
return this->variationBin > other.variationBin; // Larger first
}
return this->name < other.name;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RigEnsembleParameter::uiName() const
{
QString stem = name;
QString variationString;
if ( isNumeric() )
{
switch ( variationBin )
{
case NO_VARIATION:
variationString = QString( " (No variation)" );
break;
case LOW_VARIATION:
variationString = QString( " (Low variation)" );
break;
case MEDIUM_VARIATION:
variationString = QString( " (Medium variation)" );
break;
case HIGH_VARIATION:
variationString = QString( " (High variation)" );
break;
}
}
return QString( "%1%2" ).arg( stem ).arg( variationString );
}

View File

@@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2016- Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RiaDefines.h"
#include <QString>
#include <QVariant>
#include <utility>
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RigEnsembleParameter
{
public:
enum Type
{
TYPE_NONE,
TYPE_NUMERIC,
TYPE_TEXT
};
enum Bins
{
NO_VARIATION = -1,
LOW_VARIATION = 0,
MEDIUM_VARIATION,
HIGH_VARIATION,
NR_OF_VARIATION_BINS
};
QString uiName() const;
QString name;
Type type;
std::vector<QVariant> values;
double minValue;
double maxValue;
int variationBin;
RigEnsembleParameter()
: type( TYPE_NONE )
, minValue( std::numeric_limits<double>::infinity() )
, maxValue( -std::numeric_limits<double>::infinity() )
, variationBin( static_cast<int>( MEDIUM_VARIATION ) )
{
}
bool isValid() const { return !name.isEmpty() && type != TYPE_NONE; }
bool isNumeric() const { return type == TYPE_NUMERIC; }
bool isText() const { return type == TYPE_TEXT; }
double normalizedStdDeviation() const;
bool operator<( const RigEnsembleParameter& other ) const;
private:
double stdDeviation() const;
};