From 406379e54471937a9d131bd8c7f38665b66a83e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacob=20St=C3=B8ren?= Date: Fri, 12 Jun 2015 18:41:47 +0200 Subject: [PATCH] Results are now loaded pr field, and not pr component To increase speed, and to pave way for derived results. New methods in OdbReader fixed, and is now operational. Must delete obsolete stuff now. --- .../RigFemPartResultsCollection.cpp | 96 +++++++++++++++++-- .../RigFemPartResultsCollection.h | 4 +- .../GeoMech/OdbReader/RifOdbReader.cpp | 69 ++++++++----- 3 files changed, 134 insertions(+), 35 deletions(-) diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp index 56b5ab7f61..eb96f8a058 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.cpp @@ -89,7 +89,7 @@ std::map > RigFemPartResultsCollection::sc } //-------------------------------------------------------------------------------------------------- -/// +/// Will always return a valid object, but it can be empty //-------------------------------------------------------------------------------------------------- RigFemScalarResultFrames* RigFemPartResultsCollection::findOrLoadScalarResult(int partIndex, const RigFemResultAddress& resVarAddr) @@ -104,11 +104,19 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::findOrLoadScalarResult(in // Check whether a derived result is requested - + frames = calculateDerivedResult(partIndex, resVarAddr); + if (frames) return frames; // We need to read the data as bulk fields, and populate the correct scalar caches - frames = m_femPartResults[partIndex]->createScalarResult(resVarAddr); + std::vector< RigFemResultAddress> resultAddressOfComponents = this->getResAddrToComponentsToRead(resVarAddr); + // + std::vector resultsForEachComponent; + for (size_t cIdx = 0; cIdx < resultAddressOfComponents.size(); ++cIdx) + { + resultsForEachComponent.push_back(m_femPartResults[partIndex]->createScalarResult(resultAddressOfComponents[cIdx])); + } + int frameCount = this->frameCount(); for (int stepIndex = 0; stepIndex < frameCount; ++stepIndex) @@ -117,24 +125,97 @@ RigFemScalarResultFrames* RigFemPartResultsCollection::findOrLoadScalarResult(in for (int fIdx = 1; (size_t)fIdx < frameTimes.size() && fIdx < 2 ; ++fIdx) // Read only the second frame { - std::vector* frameData = &(frames->frameData(stepIndex)); + std::vector*> componentDataVectors; + for (size_t cIdx = 0; cIdx < resultsForEachComponent.size(); ++cIdx) + { + componentDataVectors.push_back(&(resultsForEachComponent[cIdx]->frameData(stepIndex))); + } + switch (resVarAddr.resultPosType) { case RIG_NODAL: - m_readerInterface->readScalarNodeField(resVarAddr.fieldName, resVarAddr.componentName, partIndex, stepIndex, fIdx, frameData); + m_readerInterface->readNodeField(resVarAddr.fieldName, partIndex, stepIndex, fIdx, &componentDataVectors); break; case RIG_ELEMENT_NODAL: - m_readerInterface->readScalarElementNodeField(resVarAddr.fieldName, resVarAddr.componentName, partIndex, stepIndex, fIdx, frameData); + m_readerInterface->readElementNodeField(resVarAddr.fieldName, partIndex, stepIndex, fIdx, &componentDataVectors); break; case RIG_INTEGRATION_POINT: - m_readerInterface->readScalarIntegrationPointField(resVarAddr.fieldName, resVarAddr.componentName, partIndex, stepIndex, fIdx, frameData); + m_readerInterface->readIntegrationPointField(resVarAddr.fieldName, partIndex, stepIndex, fIdx, &componentDataVectors); break; } } } + + // Now fetch the particular component requested, which should now exist and be read. + frames = m_femPartResults[partIndex]->findScalarResult(resVarAddr); + + if (!frames) + { + frames = m_femPartResults[partIndex]->createScalarResult(resVarAddr); // Create a dummy empty result, if the request did not specify the component. + } + return frames; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RigFemScalarResultFrames* RigFemPartResultsCollection::calculateDerivedResult(int partIndex, const RigFemResultAddress& resVarAddr) +{ + // ST[11, 22, 33, 12, 13, 23, 1, 2, 3], Gamma[1,2,3], NS[11,22,33,12,13,23, 1, 2, 3] + + if (resVarAddr.fieldName == "NS") + { + + } + return NULL; +} + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +std::vector< RigFemResultAddress> RigFemPartResultsCollection::getResAddrToComponentsToRead(const RigFemResultAddress& resVarAddr) +{ + std::map > fieldAndComponentNames; + switch (resVarAddr.resultPosType) + { + case RIG_NODAL: + fieldAndComponentNames = m_readerInterface->scalarNodeFieldAndComponentNames(); + break; + case RIG_ELEMENT_NODAL: + fieldAndComponentNames = m_readerInterface->scalarElementNodeFieldAndComponentNames(); + break; + case RIG_INTEGRATION_POINT: + fieldAndComponentNames = m_readerInterface->scalarIntegrationPointFieldAndComponentNames(); + break; + } + + std::vector< RigFemResultAddress> resAddressToComponents; + + std::map >::iterator fcIt = fieldAndComponentNames.find(resVarAddr.fieldName); + + if (fcIt != fieldAndComponentNames.end()) + { + std::vector compNames = fcIt->second; + for (size_t cIdx = 0; cIdx < compNames.size(); ++cIdx) + { + resAddressToComponents.push_back(RigFemResultAddress(resVarAddr.resultPosType, resVarAddr.fieldName, compNames[cIdx])); + } + + if (compNames.size() == 0) // This is a scalar field. Add one component named "" + { + CVF_ASSERT(resVarAddr.componentName == ""); + resAddressToComponents.push_back(resVarAddr); + } + } + + return resAddressToComponents; +} + + + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -263,4 +344,3 @@ const std::vector& RigFemPartResultsCollection::scalarValuesHistogram(co return this->statistics(resVarAddr)->cellScalarValuesHistogram(); } - diff --git a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.h b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.h index 547669f4d8..04b46983a7 100644 --- a/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.h +++ b/ApplicationCode/GeoMech/GeoMechDataModel/RigFemPartResultsCollection.h @@ -58,12 +58,14 @@ private: RigFemScalarResultFrames* findOrLoadScalarResult(int partIndex, const RigFemResultAddress& resVarAddr); + RigFemScalarResultFrames* calculateDerivedResult(int partIndex, const RigFemResultAddress& resVarAddr); + friend class RigFemNativeStatCalc; cvf::Collection m_femPartResults; cvf::ref m_readerInterface; RigStatisticsDataCache* statistics(const RigFemResultAddress& resVarAddr); - + std::vector< RigFemResultAddress> getResAddrToComponentsToRead(const RigFemResultAddress& resVarAddr); std::map > m_resultStatistics; }; diff --git a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp index 10fedeead2..efec20060b 100644 --- a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp +++ b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp @@ -612,25 +612,40 @@ odb_Instance* RifOdbReader::instance(int instanceIndex) //-------------------------------------------------------------------------------------------------- const odb_SequenceFieldBulkData& RifOdbReader::fieldBulkData(const std::string& fieldName, ResultPosition position, odb_Instance* instance, const odb_Frame& frame) { +<<<<<<< HEAD const odb_FieldOutput& fieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*instance); CVF_ASSERT(false); // This stuff must be fixed for linux #if 0 +======= + const odb_FieldOutput& mainFieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*instance); + +>>>>>>> Results are now loaded pr field, and not pr component switch (position) { + case NODAL: + return mainFieldOutput.getSubset(odb_Enum::NODAL).bulkDataBlocks(); + break; + case ELEMENT_NODAL: - fieldOutput = fieldOutput.getSubset(odb_Enum::ELEMENT_NODAL); + return mainFieldOutput.getSubset(odb_Enum::ELEMENT_NODAL).bulkDataBlocks(); break; case INTEGRATION_POINT: - fieldOutput = fieldOutput.getSubset(odb_Enum::INTEGRATION_POINT); + return mainFieldOutput.getSubset(odb_Enum::INTEGRATION_POINT).bulkDataBlocks(); break; default: + CVF_ASSERT(false); + return mainFieldOutput.getSubset(odb_Enum::NODAL).bulkDataBlocks(); break; } +<<<<<<< HEAD #endif return fieldOutput.bulkDataBlocks(); +======= + +>>>>>>> Results are now loaded pr field, and not pr component } @@ -968,19 +983,21 @@ void RifOdbReader::readNodeField(const std::string& fieldName, int partIndex, in std::map& nodeIdToIdxMap = m_nodeIdToIdxMaps[partIndex]; size_t dataSize = nodeIdToIdxMap.size(); + if (dataSize > 0) { for (int comp = 0; comp < compCount; comp++) { CVF_ASSERT((*resultValues)[comp]); - (*resultValues)[comp]->resize(dataSize); - (*resultValues)[comp]->assign(dataSize, std::numeric_limits::infinity()); + (*resultValues)[comp]->resize(dataSize, std::numeric_limits::infinity()); } } const odb_Frame& frame = stepFrame(stepIndex, frameIndex); - const odb_SequenceFieldBulkData& seqFieldBulkData = fieldBulkData(fieldName, NODAL, partInstance, frame); + const odb_FieldOutput& instanceFieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*partInstance); + const odb_FieldOutput& fieldOutput = instanceFieldOutput.getSubset(odb_Enum::NODAL); + const odb_SequenceFieldBulkData& seqFieldBulkData = fieldOutput.bulkDataBlocks(); size_t dataIndex = 0; int numBlocks = seqFieldBulkData.size(); @@ -994,11 +1011,12 @@ void RifOdbReader::readNodeField(const std::string& fieldName, int partIndex, in int* nodeLabels = bulkData.nodeLabels(); float* data = bulkDataGetter.data(); - for (int i = 0; i < numNodes; i++) + for (int nIdx = 0; nIdx < numNodes; nIdx++) { for (int comp = 0; comp < numComp; comp++) { - (*(*resultValues)[comp])[nodeIdToIdxMap[nodeLabels[i]]] = data[i*numComp + comp]; + std::vector* singleComponentValues = (*resultValues)[comp]; + (*singleComponentValues)[nodeIdToIdxMap[nodeLabels[nIdx]]] = data[nIdx*numComp + comp]; } } } @@ -1008,7 +1026,9 @@ void RifOdbReader::readNodeField(const std::string& fieldName, int partIndex, in //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RifOdbReader::readElementNodeField(const std::string& fieldName, int partIndex, int stepIndex, int frameIndex, std::vector*>* resultValues) +void RifOdbReader::readElementNodeField(const std::string& fieldName, + int partIndex, int stepIndex, int frameIndex, + std::vector*>* resultValues) { CVF_ASSERT(resultValues); @@ -1025,13 +1045,14 @@ void RifOdbReader::readElementNodeField(const std::string& fieldName, int partIn { CVF_ASSERT((*resultValues)[comp]); - (*resultValues)[comp]->resize(dataSize); - (*resultValues)[comp]->assign(dataSize, std::numeric_limits::infinity()); + (*resultValues)[comp]->resize(dataSize, std::numeric_limits::infinity()); } } const odb_Frame& frame = stepFrame(stepIndex, frameIndex); - const odb_SequenceFieldBulkData& seqFieldBulkData = fieldBulkData(fieldName, ELEMENT_NODAL, partInstance, frame); + const odb_FieldOutput& instanceFieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*partInstance); + const odb_FieldOutput& fieldOutput = instanceFieldOutput.getSubset(odb_Enum::ELEMENT_NODAL); + const odb_SequenceFieldBulkData& seqFieldBulkData = fieldOutput.bulkDataBlocks(); std::map& elementIdToIdxMap = m_elementIdToIdxMaps[partIndex]; CVF_ASSERT(elementIdToIdxMap.size() > 0); @@ -1046,25 +1067,20 @@ void RifOdbReader::readElementNodeField(const std::string& fieldName, int partIn int numValues = bulkData.length(); int numComp = bulkData.width(); int elemCount = bulkData.numberOfElements(); - int ipCount = numValues/elemCount; + int elemNodeCount = numValues/elemCount; int* elementLabels = bulkData.elementLabels(); float* data = bulkDataGetter.data(); - RigElementType eType = toRigElementType(bulkData.baseElementType()); - const int* elmNodeToIpResultMapping = localElmNodeToIntegrationPointMapping(eType); - if (!elmNodeToIpResultMapping) continue; - for (int elem = 0; elem < elemCount; elem++) { - int elementIdx = elementIdToIdxMap[elementLabels[elem*ipCount]]; - int elementResultStartDestIdx = elementIdx*ipCount; // Ikke generellt riktig ! - int elementResultStartSourceIdx = elem*ipCount*numComp; + int elementIdx = elementIdToIdxMap[elementLabels[elem*elemNodeCount]]; + int elementResultStartDestIdx = elementIdx*elemNodeCount; // Ikke generellt riktig ! + int elementResultStartSourceIdx = elem*elemNodeCount*numComp; - for (int ipIdx = 0; ipIdx < ipCount; ipIdx++) + for (int elemNode = 0; elemNode < elemNodeCount; elemNode++) { - int resultIpIdx = elmNodeToIpResultMapping[ipIdx]; - int destIdx = elementResultStartDestIdx + ipIdx; - int srcIdx = elementResultStartSourceIdx + resultIpIdx*numComp; + int destIdx = elementResultStartDestIdx + elemNode; + int srcIdx = elementResultStartSourceIdx + elemNode*numComp; for (int comp = 0; comp < numComp; comp++) { @@ -1096,13 +1112,14 @@ void RifOdbReader::readIntegrationPointField(const std::string& fieldName, int p { CVF_ASSERT((*resultValues)[comp]); - (*resultValues)[comp]->resize(dataSize); - (*resultValues)[comp]->assign(dataSize, std::numeric_limits::infinity()); + (*resultValues)[comp]->resize(dataSize, std::numeric_limits::infinity()); } } const odb_Frame& frame = stepFrame(stepIndex, frameIndex); - const odb_SequenceFieldBulkData& seqFieldBulkData = fieldBulkData(fieldName, INTEGRATION_POINT, partInstance, frame); + const odb_FieldOutput& instanceFieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*partInstance); + const odb_FieldOutput& fieldOutput = instanceFieldOutput.getSubset(odb_Enum::INTEGRATION_POINT); + const odb_SequenceFieldBulkData& seqFieldBulkData = fieldOutput.bulkDataBlocks(); std::map& elementIdToIdxMap = m_elementIdToIdxMaps[partIndex]; CVF_ASSERT(elementIdToIdxMap.size() > 0);