diff --git a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp index 5bce05f209..b842db98b4 100644 --- a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp +++ b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp @@ -39,6 +39,8 @@ #include + + size_t RifOdbReader::sm_instanceCount = 0; //-------------------------------------------------------------------------------------------------- @@ -195,11 +197,11 @@ bool RifOdbReader::buildMetaData() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::map< RifOdbReader::ResPos, std::map > > RifOdbReader::resultsMetaData(odb_Odb* odb) +std::map< RifOdbReader::RifOdbResultKey, std::vector > RifOdbReader::resultsMetaData(odb_Odb* odb) { CVF_ASSERT(odb != NULL); - std::map< ResPos, std::map > > resultsMap; + std::map< RifOdbResultKey, std::vector > resultsMap; const odb_StepRepository& stepRepository = odb->steps(); odb_StepRepositoryIT stepIt(stepRepository); @@ -239,16 +241,16 @@ std::map< RifOdbReader::ResPos, std::map > switch (fieldLocation.position()) { case odb_Enum::NODAL: - resultsMap[NODAL][fieldName] = compVec; + resultsMap[RifOdbResultKey(RifOdbResultKey::NODAL, fieldName)] = compVec; break; case odb_Enum::ELEMENT_NODAL: - resultsMap[ELEMENT_NODAL][fieldName] = compVec; + resultsMap[RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName)] = compVec; break; case odb_Enum::INTEGRATION_POINT: - resultsMap[INTEGRATION_POINT][fieldName] = compVec; - resultsMap[ELEMENT_NODAL][fieldName] = compVec; + resultsMap[RifOdbResultKey(RifOdbResultKey::INTEGRATION_POINT, fieldName)] = compVec; + resultsMap[RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName)] = compVec; break; default: @@ -416,7 +418,7 @@ std::vector RifOdbReader::frameTimes(int stepIndex) //-------------------------------------------------------------------------------------------------- std::map > RifOdbReader::scalarNodeFieldAndComponentNames() { - return fieldAndComponentNames(NODAL); + return fieldAndComponentNames(RifOdbResultKey::NODAL); } @@ -425,7 +427,7 @@ std::map > RifOdbReader::scalarNodeFieldAn //-------------------------------------------------------------------------------------------------- std::map > RifOdbReader::scalarElementNodeFieldAndComponentNames() { - return fieldAndComponentNames(ELEMENT_NODAL); + return fieldAndComponentNames(RifOdbResultKey::ELEMENT_NODAL); } @@ -434,7 +436,7 @@ std::map > RifOdbReader::scalarElementNode //-------------------------------------------------------------------------------------------------- std::map > RifOdbReader::scalarIntegrationPointFieldAndComponentNames() { - return fieldAndComponentNames(INTEGRATION_POINT); + return fieldAndComponentNames(RifOdbResultKey::INTEGRATION_POINT); } @@ -507,9 +509,9 @@ size_t RifOdbReader::resultItemCount(const std::string& fieldName, int partIndex //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -int RifOdbReader::componentIndex(ResPos position, const std::string& fieldName, const std::string& componentName) const +int RifOdbReader::componentIndex(const RifOdbResultKey& result, const std::string& componentName) const { - std::vector compNames = componentNames(position, fieldName); + std::vector compNames = componentNames(result); for (size_t i = 0; i < compNames.size(); i++) { @@ -526,18 +528,14 @@ int RifOdbReader::componentIndex(ResPos position, const std::string& fieldName, //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::vector RifOdbReader::componentNames(ResPos position, const std::string& fieldName) const +std::vector RifOdbReader::componentNames(const RifOdbResultKey& result) const { std::vector compNames; - std::map< ResPos, std::map > >::const_iterator posMapIt = m_resultsMetaData.find(position); - if (posMapIt != m_resultsMetaData.end()) + std::map< RifOdbResultKey, std::vector >::const_iterator resMapIt = m_resultsMetaData.find(result); + if (resMapIt != m_resultsMetaData.end()) { - std::map >::const_iterator fieldNameMapIt = posMapIt->second.find(fieldName); - if (fieldNameMapIt != posMapIt->second.end()) - { - compNames = fieldNameMapIt->second; - } + compNames = resMapIt->second; } return compNames; @@ -547,14 +545,25 @@ std::vector RifOdbReader::componentNames(ResPos position, const std //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -std::map > RifOdbReader::fieldAndComponentNames(ResPos position) +std::map > RifOdbReader::fieldAndComponentNames(RifOdbResultKey::ResultPosition position) { if (m_resultsMetaData.empty()) { buildMetaData(); } - return m_resultsMetaData[position]; + std::map > fieldsAndComponents; + + std::map< RifOdbResultKey, std::vector >::const_iterator resMapIt; + for (resMapIt = m_resultsMetaData.begin(); resMapIt != m_resultsMetaData.end(); resMapIt++) + { + if (resMapIt->first.resultPostion == position) + { + fieldsAndComponents[resMapIt->first.fieldName] = resMapIt->second; + } + } + + return fieldsAndComponents; } @@ -575,7 +584,7 @@ void RifOdbReader::readScalarNodeField(const std::string& fieldName, const std:: resultValues->resize(dataSize); resultValues->assign(dataSize, std::numeric_limits::infinity()); - int compIndex = componentIndex(NODAL, fieldName, componentName); + int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::NODAL, fieldName), componentName); CVF_ASSERT(compIndex >= 0); const odb_Frame& frame = stepFrame(stepIndex, frameIndex); @@ -622,8 +631,8 @@ void RifOdbReader::readScalarElementNodeField(const std::string& fieldName, cons resultValues->assign(dataSize, std::numeric_limits::infinity()); } - int compIndex = componentIndex(ELEMENT_NODAL, fieldName, componentName); - CVF_ASSERT(compIndex >= 0); + int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::ELEMENT_NODAL, fieldName), componentName); + CVF_ASSERT(compIndex >= 0); const odb_Frame& frame = stepFrame(stepIndex, frameIndex); const odb_FieldOutput& instanceFieldOutput = frame.fieldOutputs()[fieldName.c_str()].getSubset(*partInstance); @@ -680,7 +689,7 @@ void RifOdbReader::readScalarIntegrationPointField(const std::string& fieldName, resultValues->assign(dataSize, std::numeric_limits::infinity()); } - int compIndex = componentIndex(INTEGRATION_POINT, fieldName, componentName); + int compIndex = componentIndex(RifOdbResultKey(RifOdbResultKey::INTEGRATION_POINT, fieldName), componentName); CVF_ASSERT(compIndex >= 0); const odb_Frame& frame = stepFrame(stepIndex, frameIndex); diff --git a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h index b68f489cd5..6a58188e46 100644 --- a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h +++ b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h @@ -29,7 +29,6 @@ class odb_Odb; class odb_Frame; class odb_Instance; - //================================================================================================== // // Data interface base class @@ -37,50 +36,67 @@ class odb_Instance; //================================================================================================== class RifOdbReader : public RifGeoMechReaderInterface { - public: RifOdbReader(); virtual ~RifOdbReader(); - virtual bool openFile(const std::string& fileName, std::string* errorMessage = 0); + virtual bool openFile(const std::string& fileName, std::string* errorMessage = 0); - virtual bool readFemParts(RigFemPartCollection* geoMechCase); - virtual std::vector stepNames(); - virtual std::vector frameTimes(int stepIndex); + virtual bool readFemParts(RigFemPartCollection* geoMechCase); + virtual std::vector stepNames(); + virtual std::vector frameTimes(int stepIndex); - virtual std::map > scalarNodeFieldAndComponentNames(); - virtual std::map > scalarElementNodeFieldAndComponentNames(); - virtual std::map > scalarIntegrationPointFieldAndComponentNames(); + virtual std::map > scalarNodeFieldAndComponentNames(); + virtual std::map > scalarElementNodeFieldAndComponentNames(); + virtual std::map > scalarIntegrationPointFieldAndComponentNames(); - virtual void readScalarNodeField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); - virtual void readScalarElementNodeField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); - virtual void readScalarIntegrationPointField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); - virtual void readDisplacements(int partIndex, int stepIndex, int frameIndex, std::vector* displacements); + virtual void readScalarNodeField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); + virtual void readScalarElementNodeField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); + virtual void readScalarIntegrationPointField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector* resultValues); + virtual void readDisplacements(int partIndex, int stepIndex, int frameIndex, std::vector* displacements); private: - - enum ResPos + class RifOdbResultKey { - NODAL, - ELEMENT_NODAL, - INTEGRATION_POINT + public: + enum ResultPosition + { + NODAL, + ELEMENT_NODAL, + INTEGRATION_POINT + }; + + RifOdbResultKey(ResultPosition aResultPostion, const std::string& aFieldName) + : resultPostion(aResultPostion), fieldName(aFieldName) {}; + + ResultPosition resultPostion; + std::string fieldName; + + bool operator< (const RifOdbResultKey& other) const + { + if (resultPostion != other.resultPostion) + { + return (resultPostion < other.resultPostion); + } + + return (fieldName < other.fieldName); + } }; - bool buildMetaData(); - void close(); - size_t resultItemCount(const std::string& fieldName, int partIndex, int stepIndex, int frameIndex); - const odb_Frame& stepFrame(int stepIndex, int frameIndex) const; - odb_Instance* instance(int instanceIndex); - int componentIndex(ResPos position, const std::string& fieldName, const std::string& componentName) const; - std::vector componentNames(ResPos position, const std::string& fieldName) const; - std::map > fieldAndComponentNames(ResPos position); - std::map< RifOdbReader::ResPos, std::map > > resultsMetaData(odb_Odb* odb); + bool buildMetaData(); + void close(); + size_t resultItemCount(const std::string& fieldName, int partIndex, int stepIndex, int frameIndex); + const odb_Frame& stepFrame(int stepIndex, int frameIndex) const; + odb_Instance* instance(int instanceIndex); + int componentIndex(const RifOdbResultKey& result, const std::string& componentName) const; + std::vector componentNames(const RifOdbResultKey& result) const; + std::map< std::string, std::vector > fieldAndComponentNames(RifOdbResultKey::ResultPosition position); + std::map< RifOdbResultKey, std::vector > resultsMetaData(odb_Odb* odb); private: - odb_Odb* m_odb; - std::map< ResPos, std::map > > m_resultsMetaData; - std::vector< std::map > m_nodeIdToIdxMaps; - std::vector< std::map > m_elementIdToIdxMaps; - + odb_Odb* m_odb; + std::map< RifOdbResultKey, std::vector > m_resultsMetaData; + std::vector< std::map > m_nodeIdToIdxMaps; + std::vector< std::map > m_elementIdToIdxMaps; static size_t sm_instanceCount; };