Files
ResInsight/ApplicationLibCode/GeoMech/GeoMechDataModel/RigFemNativeStatCalc.cpp
T

173 lines
6.4 KiB
C++
Raw Normal View History

2015-05-06 16:07:30 +02:00
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
2015-05-06 16:07:30 +02:00
// 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.
//
2015-05-06 16:07:30 +02:00
// 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>
2015-05-06 16:07:30 +02:00
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RigFemNativeStatCalc.h"
2015-06-04 16:10:02 +02:00
#include "RigFemPartResultsCollection.h"
#include "RigFemScalarResultFrames.h"
2015-05-06 16:07:30 +02:00
2015-06-04 16:10:02 +02:00
#include "RigStatisticsMath.h"
#include <cmath>
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
2023-02-26 10:48:40 +01:00
RigFemNativeStatCalc::RigFemNativeStatCalc( RigFemPartResultsCollection* femResultCollection, const RigFemResultAddress& resVarAddr )
: m_resVarAddr( resVarAddr )
2015-05-07 10:11:55 +02:00
{
2015-06-04 16:10:02 +02:00
m_resultsData = femResultCollection;
2015-05-07 10:11:55 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::minMaxCellScalarValues( size_t timeStepIndex, double& min, double& max )
2015-05-07 10:11:55 +02:00
{
for ( int pIdx = 0; pIdx < m_resultsData->partCount(); ++pIdx )
2015-06-04 16:10:02 +02:00
{
2023-01-18 14:42:33 +01:00
auto frames = m_resultsData->findOrLoadScalarResult( pIdx, m_resVarAddr );
auto [stepIdx, frameIdx] = m_resultsData->stepListIndexToTimeStepAndDataFrameIndex( timeStepIndex );
const std::vector<float>& values = frames->frameData( stepIdx, frameIdx );
2015-06-04 16:10:02 +02:00
size_t i;
for ( i = 0; i < values.size(); i++ )
2015-06-04 16:10:02 +02:00
{
if ( values[i] == HUGE_VAL ) // TODO
2015-06-04 16:10:02 +02:00
{
continue;
}
if ( values[i] < min )
2015-06-04 16:10:02 +02:00
{
min = values[i];
}
if ( values[i] > max )
2015-06-04 16:10:02 +02:00
{
max = values[i];
}
}
}
2015-05-07 10:11:55 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::posNegClosestToZero( size_t timeStepIndex, double& pos, double& neg )
2015-05-07 10:11:55 +02:00
{
for ( int pIdx = 0; pIdx < m_resultsData->partCount(); ++pIdx )
2015-06-04 16:10:02 +02:00
{
2023-01-18 14:42:33 +01:00
auto frames = m_resultsData->findOrLoadScalarResult( pIdx, m_resVarAddr );
auto [stepIdx, frameIdx] = m_resultsData->stepListIndexToTimeStepAndDataFrameIndex( timeStepIndex );
const std::vector<float>& values = frames->frameData( stepIdx, frameIdx );
2015-06-04 16:10:02 +02:00
for ( size_t i = 0; i < values.size(); i++ )
2015-06-04 16:10:02 +02:00
{
if ( values[i] == HUGE_VAL )
2015-06-04 16:10:02 +02:00
{
continue;
}
if ( values[i] < pos && values[i] > 0 )
2015-06-04 16:10:02 +02:00
{
pos = values[i];
}
if ( values[i] > neg && values[i] < 0 )
2015-06-04 16:10:02 +02:00
{
neg = values[i];
}
}
}
2015-05-07 10:11:55 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::valueSumAndSampleCount( size_t timeStepIndex, double& valueSum, size_t& sampleCount )
2015-05-07 10:11:55 +02:00
{
int partCount = m_resultsData->partCount();
for ( int pIdx = 0; pIdx < partCount; ++pIdx )
{
2023-01-18 14:42:33 +01:00
auto frames = m_resultsData->findOrLoadScalarResult( pIdx, m_resVarAddr );
auto [stepIdx, frameIdx] = m_resultsData->stepListIndexToTimeStepAndDataFrameIndex( timeStepIndex );
const std::vector<float>& values = frames->frameData( stepIdx, frameIdx );
size_t undefValueCount = 0;
for ( size_t cIdx = 0; cIdx < values.size(); ++cIdx )
{
double value = values[cIdx];
if ( value == HUGE_VAL || value != value )
{
++undefValueCount;
continue;
}
valueSum += value;
}
sampleCount += values.size();
sampleCount -= undefValueCount;
}
2015-05-07 10:11:55 +02:00
}
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
2020-02-12 11:43:15 +01:00
void RigFemNativeStatCalc::addDataToHistogramCalculator( size_t timeStepIndex, RigHistogramCalculator& histogramCalculator )
2015-05-07 10:11:55 +02:00
{
int partCount = m_resultsData->partCount();
for ( int pIdx = 0; pIdx < partCount; ++pIdx )
2015-06-04 16:10:02 +02:00
{
2023-01-18 14:42:33 +01:00
auto frames = m_resultsData->findOrLoadScalarResult( pIdx, m_resVarAddr );
auto [stepIdx, frameIdx] = m_resultsData->stepListIndexToTimeStepAndDataFrameIndex( timeStepIndex );
const std::vector<float>& values = frames->frameData( stepIdx, frameIdx );
2015-05-07 10:11:55 +02:00
histogramCalculator.addData( values );
2015-06-04 16:10:02 +02:00
}
2015-05-07 10:11:55 +02:00
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::uniqueValues( size_t timeStepIndex, std::set<int>& values )
{
for ( int pIdx = 0; pIdx < m_resultsData->partCount(); ++pIdx )
{
2023-01-18 14:42:33 +01:00
auto frames = m_resultsData->findOrLoadScalarResult( pIdx, m_resVarAddr );
2023-02-26 10:48:40 +01:00
auto [stepIdx, frameIdx] = m_resultsData->stepListIndexToTimeStepAndDataFrameIndex( timeStepIndex );
2023-01-18 14:42:33 +01:00
const std::vector<float>& floatValues = frames->frameData( stepIdx, frameIdx );
for ( size_t i = 0; i < floatValues.size(); i++ )
{
values.insert( static_cast<int>( std::floor( floatValues[i] ) ) );
}
}
}
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
///
2015-05-07 10:11:55 +02:00
//--------------------------------------------------------------------------------------------------
size_t RigFemNativeStatCalc::timeStepCount()
{
2023-01-18 14:42:33 +01:00
return m_resultsData->totalSteps();
2015-05-07 10:11:55 +02:00
}