Bugfix: Get pointer to data after adding data to std vector

When SOIL is created, a new dataset is appended to a std vector. Pointer
to SWAT and SGAS data must be aquired AFTER the new dataset is added.
Adding data to a vector can trigger reallocation of data.
This commit is contained in:
Magne Sjaastad 2014-04-25 14:36:34 +02:00
parent 3608c36291
commit 585f034799

View File

@ -56,7 +56,7 @@ CAF_PDM_SOURCE_INIT(RimReservoirCellResultsStorage, "ReservoirCellResultStorage"
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimReservoirCellResultsStorage::RimReservoirCellResultsStorage() RimReservoirCellResultsStorage::RimReservoirCellResultsStorage()
: m_cellResults(NULL), : m_cellResults(NULL),
m_ownerMainGrid(NULL) m_ownerMainGrid(NULL)
{ {
CAF_PDM_InitObject("Cacher", "", "", ""); CAF_PDM_InitObject("Cacher", "", "", "");
@ -136,7 +136,7 @@ void RimReservoirCellResultsStorage::setupBeforeSave()
// If there is no data, we do not store anything for the current result variable // If there is no data, we do not store anything for the current result variable
// (Even not the metadata, of cause) // (Even not the metadata, of cause)
size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size(); size_t timestepCount = m_cellResults->cellScalarResults(resInfo[rIdx].m_gridScalarResultIndex).size();
if (timestepCount && resInfo[rIdx].m_needsToBeStored) if (timestepCount && resInfo[rIdx].m_needsToBeStored)
{ {
progInfo.setProgressDescription(resInfo[rIdx].m_resultName); progInfo.setProgressDescription(resInfo[rIdx].m_resultName);
@ -251,7 +251,7 @@ size_t RimReservoirCellResultsStorage::findOrLoadScalarResultForTimeStep(RimDefi
if (soilScalarResultIndex == cvf::UNDEFINED_SIZE_T) if (soilScalarResultIndex == cvf::UNDEFINED_SIZE_T)
{ {
computeSOILForTimeStep(timeStepIndex); computeSOILForTimeStep(timeStepIndex);
soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName); soilScalarResultIndex = m_cellResults->findScalarResultIndex(type, resultName);
return soilScalarResultIndex; return soilScalarResultIndex;
} }
@ -419,32 +419,22 @@ void RimReservoirCellResultsStorage::computeSOILForTimeStep(size_t timeStepIndex
size_t soilResultValueCount = 0; size_t soilResultValueCount = 0;
size_t soilTimeStepCount = 0; size_t soilTimeStepCount = 0;
std::vector<double>* swatForTimeStep = NULL;
std::vector<double>* sgasForTimeStep = NULL;
if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T) if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T)
{ {
swatForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSWAT, timeStepIndex)); std::vector<double>& swatForTimeStep = m_cellResults->cellScalarResults(scalarIndexSWAT, timeStepIndex);
if (swatForTimeStep->size() == 0) if (swatForTimeStep.size() > 0)
{ {
swatForTimeStep = NULL; soilResultValueCount = swatForTimeStep.size();
}
else
{
soilResultValueCount = swatForTimeStep->size();
soilTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepDates.size(); soilTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSWAT].m_timeStepDates.size();
} }
} }
if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T) if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T)
{ {
sgasForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSGAS, timeStepIndex)); std::vector<double>& sgasForTimeStep = m_cellResults->cellScalarResults(scalarIndexSGAS, timeStepIndex);
if (sgasForTimeStep->size() == 0) if (sgasForTimeStep.size() > 0)
{ {
sgasForTimeStep = NULL; soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep.size());
}
else
{
soilResultValueCount = qMax(soilResultValueCount, sgasForTimeStep->size());
size_t sgasTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSGAS].m_timeStepDates.size(); size_t sgasTimeStepCount = m_cellResults->infoForEachResultIndex()[scalarIndexSGAS].m_timeStepDates.size();
soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount); soilTimeStepCount = qMax(soilTimeStepCount, sgasTimeStepCount);
@ -468,6 +458,28 @@ void RimReservoirCellResultsStorage::computeSOILForTimeStep(size_t timeStepIndex
} }
} }
std::vector<double>* swatForTimeStep = NULL;
std::vector<double>* sgasForTimeStep = NULL;
if (scalarIndexSWAT != cvf::UNDEFINED_SIZE_T)
{
swatForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSWAT, timeStepIndex));
if (swatForTimeStep->size() == 0)
{
swatForTimeStep = NULL;
}
}
if (scalarIndexSGAS != cvf::UNDEFINED_SIZE_T)
{
sgasForTimeStep = &(m_cellResults->cellScalarResults(scalarIndexSGAS, timeStepIndex));
if (sgasForTimeStep->size() == 0)
{
sgasForTimeStep = NULL;
}
}
std::vector<double>& soilForTimeStep = m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIndex); std::vector<double>& soilForTimeStep = m_cellResults->cellScalarResults(soilResultGridIndex, timeStepIndex);
#pragma omp parallel for #pragma omp parallel for
@ -514,7 +526,7 @@ void RimReservoirCellResultsStorage::computeDepthRelatedResults()
if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T) if (depthResultGridIndex == cvf::UNDEFINED_SIZE_T)
{ {
depthResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", false, resultValueCount); depthResultGridIndex = m_cellResults->addStaticScalarResult(RimDefines::STATIC_NATIVE, "DEPTH", false, resultValueCount);
computeDepth = true; computeDepth = true;
} }
@ -694,7 +706,7 @@ void RimReservoirCellResultsStorage::setCellResults(RigCaseCellResultsData* cell
for (size_t tsIdx = 0; tsIdx < resInfo->m_timeStepDates().size(); ++tsIdx) for (size_t tsIdx = 0; tsIdx < resInfo->m_timeStepDates().size(); ++tsIdx)
{ {
std::vector<double>* data = NULL; std::vector<double>* data = NULL;
data = &(m_cellResults->cellScalarResults(rIdx, tsIdx)); data = &(m_cellResults->cellScalarResults(rIdx, tsIdx));
quint64 cellCount = 0; quint64 cellCount = 0;
@ -760,4 +772,4 @@ RimReservoirCellResultsStorageEntryInfo::RimReservoirCellResultsStorageEntryInfo
RimReservoirCellResultsStorageEntryInfo::~RimReservoirCellResultsStorageEntryInfo() RimReservoirCellResultsStorageEntryInfo::~RimReservoirCellResultsStorageEntryInfo()
{ {
} }