Files
ResInsight/ApplicationCode/GeoMech/GeoMechDataModel/RigFemNativeStatCalc.cpp
Jacob Støren 00796b3fb4 3D view info box is up to speed.
This completes #291 feature wise
Statistics is now pr result address and not pr. Part-result Address
2015-06-04 16:25:27 +02:00

154 lines
5.2 KiB
C++

/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2015- Statoil ASA
// Copyright (C) 2015- Ceetron Solutions AS
//
// 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 "RigFemNativeStatCalc.h"
#include "RigFemScalarResultFrames.h"
#include "RigFemPartResultsCollection.h"
#include <math.h>
#include "RigStatisticsMath.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFemNativeStatCalc::RigFemNativeStatCalc(RigFemPartResultsCollection* femResultCollection, const RigFemResultAddress& resVarAddr)
: m_resVarAddr(resVarAddr)
{
m_resultsData = femResultCollection;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max)
{
for (int pIdx = 0; pIdx < static_cast<int>(m_resultsData->m_femPartResults.size()); ++pIdx)
{
const std::vector<float>& values = m_resultsData->resultValues(m_resVarAddr, pIdx, (int)timeStepIndex);
size_t i;
for (i = 0; i < values.size(); i++)
{
if (values[i] == HUGE_VAL) // TODO
{
continue;
}
if (values[i] < min)
{
min = values[i];
}
if (values[i] > max)
{
max = values[i];
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg)
{
for (int pIdx = 0; pIdx < static_cast<int>(m_resultsData->m_femPartResults.size()); ++pIdx)
{
const std::vector<float>& values = m_resultsData->resultValues(m_resVarAddr, pIdx, (int)timeStepIndex);
for (size_t i = 0; i < values.size(); i++)
{
if (values[i] == HUGE_VAL)
{
continue;
}
if (values[i] < pos && values[i] > 0)
{
pos = values[i];
}
if (values[i] > neg && values[i] < 0)
{
neg = values[i];
}
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::valueSumAndSampleCount(double& valueSum, size_t& sampleCount)
{
int timestepCount = (int)(this->timeStepCount());
int partCount = static_cast<int>(m_resultsData->m_femPartResults.size());
for (int pIdx = 0; pIdx < partCount; ++pIdx)
{
for (int tIdx = 0; tIdx < timestepCount; tIdx++)
{
const std::vector<float>& values = m_resultsData->resultValues(m_resVarAddr, pIdx, tIdx);
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;
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RigFemNativeStatCalc::addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator)
{
int timestepCount = (int)(this->timeStepCount());
int partCount = static_cast<int>(m_resultsData->m_femPartResults.size());
for (int pIdx = 0; pIdx < partCount; ++pIdx)
{
for (int tIdx = 0; tIdx < timestepCount; tIdx++)
{
const std::vector<float>& values = m_resultsData->resultValues(m_resVarAddr, pIdx, tIdx);
histogramCalculator.addData(values);
}
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
size_t RigFemNativeStatCalc::timeStepCount()
{
return m_resultsData->frameCount();
}