Fixing assert due to m_odb not set

There still are troubles closing two instances accessing same file.
This commit is contained in:
Jacob Støren 2015-04-30 16:35:21 +02:00
parent 791a25e6e9
commit 4e9f91274c
3 changed files with 19 additions and 42 deletions

View File

@ -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;
}

View File

@ -53,16 +53,15 @@ public:
virtual void readScalarIntegrationPointField(const std::string& fieldName, const std::string& componmentName, int partIndex, int stepIndex, int frameIndex, std::vector<float>* resultValues);
virtual void readDisplacements(int partIndex, int stepIndex, int frameIndex, std::vector<cvf::Vec3f>* 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;

View File

@ -34,13 +34,21 @@ TEST(OdbReaderTest, BasicTests)
cvf::ref<RifOdbReader> reader = new RifOdbReader;
cvf::ref<RigGeoMechCaseData> femCase = new RigGeoMechCaseData;
cvf::ref<RigFemPartCollection> 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<std::string, std::vector<std::string> > scalarNodeFieldsMap = reader->scalarNodeFieldAndComponentNames();
EXPECT_EQ(3, scalarNodeFieldsMap.size());
cvf::ref<RigGeoMechCaseData> femCase2 = new RigGeoMechCaseData;
cvf::ref<RigFemPartCollection> femData2 = femCase->femParts();
cvf::ref<RifOdbReader> 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<std::string> 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<std::string, std::vector<std::string> > scalarNodeFieldsMap = reader2->scalarNodeFieldAndComponentNames();
scalarNodeFieldsMap = reader2->scalarNodeFieldAndComponentNames();
EXPECT_EQ(3, scalarNodeFieldsMap.size());
std::map<std::string, std::vector<std::string> > 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<cvf::Vec3f> displacements;
reader2->readDisplacements(0, 0, 1, &displacements);
reader2 = NULL;
EXPECT_EQ(5168, displacements.size());
EXPECT_FLOAT_EQ(0.047638997, displacements[1].y());
}