Creating a fem-results caching system

Needed specifically for statistics
Work in progress brakes build
This commit is contained in:
Jacob Støren
2015-05-06 16:07:30 +02:00
parent 746e9d402d
commit 27dcd80bfd
18 changed files with 443 additions and 107 deletions

View File

@@ -16,7 +16,12 @@ add_library( ${PROJECT_NAME}
RigGeoMechCaseData.h
RigFemPartCollection.cpp
RigFemPartCollection.h
RigFemPartResults.h
RigFemPartResults.cpp
RigFemScalarResultFrames.h
RigFemScalarResultFrames.cpp
RigFemNativeStatCalc.h
RigFemNativeStatCalc.cpp
)
target_link_libraries( ${PROJECT_NAME} LibCore )

View File

@@ -0,0 +1,23 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RigFemNativeStatCalc.h"

View File

@@ -0,0 +1,46 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
//==================================================================================================
///
//==================================================================================================
#include "RigStatisticsCalculator.h"
class RigFemScalarResultFrames;
class RigFemNativeStatCalc : public RigStatisticsCalculator
{
public:
RigFemNativeStatCalc(RigFemScalarResultFrames* cellResultsData);
virtual void minMaxCellScalarValues(size_t timeStepIndex, double& min, double& max);
virtual void posNegClosestToZero(size_t timeStepIndex, double& pos, double& neg);
virtual void valueSumAndSampleCount(double& valueSum, size_t& sampleCount);
virtual void addDataToHistogramCalculator(RigHistogramCalculator& histogramCalculator);
virtual size_t timeStepCount();
private:
RigFemScalarResultFrames* m_resultsData;
};

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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 "RigFemPartResults.h"
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFemPartResults::RigFemPartResults()
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFemPartResults::~RigFemPartResults()
{
}

View File

@@ -0,0 +1,63 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfObject.h"
#include "RigFemResultPosEnum.h"
#include <string>
#include <vector>
#include <map>
#include "RigFemScalarResultFrames.h"
//==================================================================================================
///
//==================================================================================================
class RigFemPartResults : public cvf::Object
{
public:
RigFemPartResults();
~RigFemPartResults();
void initResultStages( const std::vector<std::string>& stageNames);
RigFemScalarResultFrames* createScalarResult( size_t stageIndex,
RigFemResultPosEnum resultPosType,
const std::string& fieldName,
const std::string& componentName,
const std::vector<double>& frameTimes);
RigFemScalarResultFrames* findScalarResult( size_t stageIndex,
RigFemResultPosEnum resultPosType,
const std::string& fieldName,
const std::string& componentName);
private:
struct RigAnalysisStage
{
std::string stageName;
std::map<RigFemResultPosEnum, std::map<std::string, std::map< std::string, cvf::ref<RigFemScalarResultFrames> > > > resultSets;
};
std::vector<RigAnalysisStage> m_femAnalysisStages;
};

View File

@@ -0,0 +1,7 @@
#pragma once
enum RigFemResultPosEnum {
RIG_NODAL,
RIG_ELEMENT_NODAL,
RIG_INTEGRATION_POINT
};

View File

@@ -0,0 +1,22 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "RigFemScalarResultFrames.h"

View File

@@ -0,0 +1,47 @@
/////////////////////////////////////////////////////////////////////////////////
//
// 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.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfObject.h"
#include <vector>
//==================================================================================================
///
//==================================================================================================
class RigStatisticsDataCache;
class RigFemScalarResultFrames: public cvf::Object
{
public:
RigFemScalarResultFrames(const std::vector<double>& frameTimes);
virtual ~RigFemScalarResultFrames();
std::vector<float>& frameData(size_t frameIndex);
size_t frameCount();
RigStatisticsDataCache* statistics();
private:
std::vector< std::vector<float> > m_dataForEachFrame;
std::vector<double> m_frameTimes;
cvf::ref<RigStatisticsDataCache> m_statistics;
};

View File

@@ -18,13 +18,19 @@
/////////////////////////////////////////////////////////////////////////////////
#include "RigGeoMechCaseData.h"
#include "RigFemPartCollection.h"
#include "RifGeoMechReaderInterface.h"
#ifdef USE_ODB_API
#include "RifOdbReader.h"
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigGeoMechCaseData::RigGeoMechCaseData()
RigGeoMechCaseData::RigGeoMechCaseData(const std::string& fileName)
{
m_femParts = new RigFemPartCollection();
m_geoMechCaseFileName = fileName;
}
//--------------------------------------------------------------------------------------------------
@@ -50,3 +56,92 @@ const RigFemPartCollection* RigGeoMechCaseData::femParts() const
{
return m_femParts.p();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RigGeoMechCaseData::openAndReadFemParts()
{
#ifdef USE_ODB_API
m_readerInterface = new RifOdbReader;
#endif
if (m_readerInterface.notNull() && m_readerInterface->openFile(m_geoMechCaseFileName))
{
m_femParts = new RigFemPartCollection();
if (m_readerInterface->readFemParts(m_femParts.p()))
{
// Initialize results containers
m_femPartResults.resize(m_femParts->partCount());
std::vector<std::string> stepNames = m_readerInterface->stepNames();
for (int pIdx = 0; pIdx < m_femPartResults.size(); ++pIdx)
{
m_femPartResults[pIdx]->initResultStages(stepNames);
}
return true;
}
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::map<std::string, std::vector<std::string> > RigGeoMechCaseData::scalarFieldAndComponentNames(RigFemResultPosEnum resPos)
{
std::map<std::string, std::vector<std::string> > fieldCompNames;
if (m_readerInterface.notNull())
{
if (resPos == RIG_NODAL)
{
fieldCompNames = m_readerInterface->scalarNodeFieldAndComponentNames();
}
else if (resPos == RIG_ELEMENT_NODAL)
{
fieldCompNames = m_readerInterface->scalarElementNodeFieldAndComponentNames();
}
else if (resPos == RIG_INTEGRATION_POINT)
{
fieldCompNames = m_readerInterface->scalarIntegrationPointFieldAndComponentNames();
}
}
return fieldCompNames;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RigFemScalarResultFrames* RigGeoMechCaseData::findOrLoadScalarResult(size_t partIndex, size_t stepIndex,
RigFemResultPosEnum resultPosType,
const std::string& fieldName,
const std::string& componentName)
{
CVF_ASSERT(partIndex < m_femParts->partCount());
RigFemScalarResultFrames* frames = m_femPartResults[partIndex]->findScalarResult(stepIndex, resultPosType, fieldName, componentName);
if (frames) return frames;
std::vector<double > frameTimes = m_readerInterface->frameTimes(stepIndex);
frames = m_femPartResults[partIndex]->createScalarResult( stepIndex, resultPosType, fieldName, componentName, frameTimes);
for (size_t fIdx = 0; fIdx < frameTimes.size(); ++fIdx)
{
std::vector<float>* frameData = &(frames->frameData(fIdx));
switch (resultPosType)
{
case RIG_NODAL:
m_readerInterface->readScalarNodeField(fieldName, componentName, partIndex, stepIndex, fIdx, frameData);
break;
case RIG_ELEMENT_NODAL:
//m_readerInterface->readScalarElementNodeField(fieldName, componentName, partIndex, stepIndex, fIdx, frameData);
break;
case RIG_INTEGRATION_POINT:
//m_readerInterface->readScalarIntegrationPointField(fieldName, componentName, partIndex, stepIndex, fIdx, frameData);
break;
}
}
}

View File

@@ -18,22 +18,41 @@
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include "cvfObject.h"
#include <string>
#include <map>
#include <vector>
#include "RigFemResultPosEnum.h"
#include "cvfCollection.h"
#include "RigFemPartResults.h"
#include "RigFemPartCollection.h"
class RifGeoMechReaderInterface;
class RigFemPartCollection;
class RigFemScalarResultFrames;
class RigGeoMechCaseData: public cvf::Object
{
public:
RigGeoMechCaseData();
RigGeoMechCaseData(const std::string& fileName);
~RigGeoMechCaseData();
RigFemPartCollection* femParts();
const RigFemPartCollection* femParts() const;
bool openAndReadFemParts();
RigFemPartCollection* femParts();
const RigFemPartCollection* femParts() const;
std::map<std::string, std::vector<std::string> > scalarFieldAndComponentNames(RigFemResultPosEnum resPos);
std::vector<std::string> stepNames();
RigFemScalarResultFrames* findOrLoadScalarResult(size_t partIndex,
size_t stepIndex,
RigFemResultPosEnum resultPosType,
const std::string& fieldName,
const std::string& componentName);
private:
cvf::ref<RigFemPartCollection> m_femParts;
std::string m_geoMechCaseFileName;
cvf::ref<RigFemPartCollection> m_femParts;
cvf::Collection<RigFemPartResults> m_femPartResults;
cvf::ref<RifGeoMechReaderInterface> m_readerInterface;
};

View File

@@ -0,0 +1,7 @@
#pragma once
enum RigFemResultPosEnum {
NODAL,
ELEMENT_NODAL,
INTEGRATION_POINT
};

View File

@@ -43,6 +43,7 @@ public:
cvf::ref<cvf::DrawableGeo> createOutlineMeshDrawable(double creaseAngle);
const std::vector<size_t>& quadVerticesToNodeIdxMapping() const { return m_quadVerticesToNodeIdx;}
const std::vector<size_t>& quadVerticesToGlobalElmNodeIdx() const { return m_quadVerticesToGlobalElmNodeIdx;}
private:
static cvf::ref<cvf::UIntArray>

View File

@@ -47,6 +47,8 @@
#include "cvfStructGrid.h"
#include "cvfUniform.h"
#include "RifGeoMechReaderInterface.h"
#include "RigGeomechCaseData.h"
#include "RigFemScalarResultFrames.h"
//--------------------------------------------------------------------------------------------------
@@ -219,20 +221,33 @@ void RivFemPartPartMgr::updateCellResultColor(size_t timeStepIndex, RimGeoMechRe
{
const cvf::ScalarMapper* mapper = cellResultSlot->legendConfig()->scalarMapper();
RifGeoMechReaderInterface* reader = cellResultSlot->resultReaderInterface();
std::vector<float> resultValues;
reader->readScalarNodeField(cellResultSlot->resultFieldName().toStdString(),
cellResultSlot->resultComponentName().toStdString(),
m_gridIdx, 0, timeStepIndex, &resultValues);
const std::vector<size_t>& vxToResultMapping = m_surfaceGenerator.quadVerticesToNodeIdxMapping();
m_surfaceFacesTextureCoords->resize(vxToResultMapping.size());
RigGeoMechCaseData* caseData = cellResultSlot->ownerCaseData();
if (!caseData) return;
RigFemScalarResultFrames* scalarResults = caseData->findOrLoadScalarResult(m_gridIdx, 0, cellResultSlot->resultPositionType(), cellResultSlot->resultFieldName().toStdString(), cellResultSlot->resultComponentName().toStdString());
std::vector<float>& resultValues = scalarResults->frameData(timeStepIndex);
const std::vector<size_t>* vxToResultMapping = NULL;
if (cellResultSlot->resultPositionType() == RIG_NODAL)
{
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToNodeIdxMapping());
}
else if ( cellResultSlot->resultPositionType() == RIG_ELEMENT_NODAL
|| cellResultSlot->resultPositionType() == RIG_INTEGRATION_POINT)
{
vxToResultMapping = &(m_surfaceGenerator.quadVerticesToNodeIdxMapping());
}
m_surfaceFacesTextureCoords->resize(vxToResultMapping->size());
cvf::Vec2f* rawPtr = m_surfaceFacesTextureCoords->ptr();
#pragma omp parallel for schedule(dynamic)
for (int vxIdx = 0; vxIdx < vxToResultMapping.size(); ++vxIdx)
for (int vxIdx = 0; vxIdx < vxToResultMapping->size(); ++vxIdx)
{
float resultValue = resultValues[vxToResultMapping[vxIdx]];
float resultValue = resultValues[(*vxToResultMapping)[vxIdx]];
if (resultValue == HUGE_VAL || resultValue != resultValue) // a != a is true for NAN's
{
rawPtr[vxIdx][1] = 1.0f;