diff --git a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp index 83f9089292..7be562598b 100644 --- a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp +++ b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.cpp @@ -95,13 +95,14 @@ void RifOdbReader::close() } -void readOdbFile(const std::string& fileName, RigFemPartCollection* femParts) +void RifOdbReader::readOdbFile(const std::string& fileName, RigFemPartCollection* femParts) { CVF_ASSERT(femParts); odb_String path = fileName.c_str(); odb_Odb& odb = openOdb(path); + m_odb = &odb; odb_Assembly& rootAssembly = odb.rootAssembly(); odb_InstanceRepository instanceRepository = odb.rootAssembly().instances(); @@ -243,7 +244,7 @@ bool RifOdbReader::readFemParts(const std::string& fileName, RigFemPartCollectio try { - readOdbFile(fileName, femParts); + this->readOdbFile(fileName, femParts); } catch (const nex_Exception& nex) @@ -509,37 +510,3 @@ void RifOdbReader::readDisplacements(int partIndex, int stepIndex, int frameInde } } - -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool RifOdbReader::openFile(const std::string& fileName) -{ - close(); - CVF_ASSERT(m_odb == NULL); - - if (!sm_odbAPIInitialized) - { - initializeOdbAPI(); - } - - odb_String path = fileName.c_str(); - - try - { - m_odb = &openOdb(path); - } - - catch (const nex_Exception& nex) - { - fprintf(stderr, "%s\n", nex.UserReport().CStr()); - fprintf(stderr, "ODB Application exited with error(s)\n"); - } - - catch (...) - { - fprintf(stderr, "ODB Application exited with error(s)\n"); - } - - return true; -} diff --git a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h index 3f84bc643c..038ab4d231 100644 --- a/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h +++ b/ApplicationCode/GeoMech/OdbReader/RifOdbReader.h @@ -53,16 +53,15 @@ public: 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); - bool openFile(const std::string& fileName); - private: void close(); size_t resultItemCount(const std::string& fieldName, int stepIndex, int frameIndex) const; odb_Frame stepFrame(int stepIndex, int frameIndex) const; int componentIndex(const std::string& fieldName, const std::string& componentName) const; + void readOdbFile(const std::string& fileName, RigFemPartCollection* femParts); - static void initializeOdbAPI(); - static void finalizeOdbAPI(); + static void initializeOdbAPI(); + static void finalizeOdbAPI(); private: odb_Odb* m_odb; diff --git a/ApplicationCode/GeoMech/OdbReader_UnitTests/RifOdbReader-Test.cpp b/ApplicationCode/GeoMech/OdbReader_UnitTests/RifOdbReader-Test.cpp index 2f5f1c9d1a..6147116965 100644 --- a/ApplicationCode/GeoMech/OdbReader_UnitTests/RifOdbReader-Test.cpp +++ b/ApplicationCode/GeoMech/OdbReader_UnitTests/RifOdbReader-Test.cpp @@ -34,13 +34,21 @@ TEST(OdbReaderTest, BasicTests) cvf::ref reader = new RifOdbReader; cvf::ref femCase = new RigGeoMechCaseData; cvf::ref femData = femCase->femParts(); + reader->readFemParts(TEST_FILE, femData.p()); + EXPECT_EQ(1, femData->partCount()); EXPECT_EQ(4320, femData->part(0)->elementCount()); EXPECT_EQ(HEX8, femData->part(0)->elementType(0)); + std::map > scalarNodeFieldsMap = reader->scalarNodeFieldAndComponentNames(); + EXPECT_EQ(3, scalarNodeFieldsMap.size()); + + cvf::ref femCase2 = new RigGeoMechCaseData; + cvf::ref femData2 = femCase->femParts(); + cvf::ref reader2 = new RifOdbReader; - EXPECT_EQ(true, reader2->openFile(TEST_FILE)); + EXPECT_EQ(true, reader2->readFemParts(TEST_FILE, femData2.p())); EXPECT_EQ(true, reader2->stepNames().size() == 1); std::vector steps = reader2->stepNames(); @@ -48,7 +56,7 @@ TEST(OdbReaderTest, BasicTests) EXPECT_EQ(2, reader2->frameTimes(0).size()); EXPECT_EQ(1.0, reader2->frameTimes(0)[1]); - std::map > scalarNodeFieldsMap = reader2->scalarNodeFieldAndComponentNames(); + scalarNodeFieldsMap = reader2->scalarNodeFieldAndComponentNames(); EXPECT_EQ(3, scalarNodeFieldsMap.size()); std::map > scalarElementNodeFieldsMap = reader2->scalarElementNodeFieldAndComponentNames(); @@ -61,8 +69,11 @@ TEST(OdbReaderTest, BasicTests) reader2->readScalarNodeField("U", "U2", 0, 0, 1, &displacementValues); EXPECT_EQ(5168, displacementValues.size()); + reader = NULL; + std::vector displacements; reader2->readDisplacements(0, 0, 1, &displacements); + reader2 = NULL; EXPECT_EQ(5168, displacements.size()); EXPECT_FLOAT_EQ(0.047638997, displacements[1].y()); }