mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-10 15:36:09 -06:00
Cleaned up odb interface.
Cleaned up interface. openFile() must be called before getting metadata, results, or geometry. Running unit tests for only one reader instance for the test file.
This commit is contained in:
parent
20a8527607
commit
eb30a51e54
@ -41,7 +41,7 @@ public:
|
||||
RifGeoMechReaderInterface();
|
||||
virtual ~RifGeoMechReaderInterface();
|
||||
|
||||
virtual bool readFemParts(const std::string& fileName, RigFemPartCollection* geoMechCase) = 0;
|
||||
virtual bool readFemParts(RigFemPartCollection* geoMechCase) = 0;
|
||||
virtual std::vector<std::string> stepNames() = 0;
|
||||
virtual std::vector<double> frameTimes(int stepIndex) = 0;
|
||||
|
||||
|
@ -94,18 +94,106 @@ void RifOdbReader::close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RifOdbReader::readOdbFile(const std::string& fileName, RigFemPartCollection* femParts)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOdbReader::openFile(const std::string& fileName)
|
||||
{
|
||||
CVF_ASSERT(femParts);
|
||||
close();
|
||||
CVF_ASSERT(m_odb == NULL);
|
||||
|
||||
if (!sm_odbAPIInitialized)
|
||||
{
|
||||
initializeOdbAPI();
|
||||
}
|
||||
|
||||
odb_String path = fileName.c_str();
|
||||
|
||||
odb_Odb& odb = openOdb(path);
|
||||
m_odb = &odb;
|
||||
try
|
||||
{
|
||||
m_odb = &openOdb(path, true);
|
||||
}
|
||||
|
||||
odb_Assembly& rootAssembly = odb.rootAssembly();
|
||||
odb_InstanceRepository instanceRepository = odb.rootAssembly().instances();
|
||||
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;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, std::vector<std::string> > scalarFieldAndComponentNames(odb_Odb* odb, odb_Enum::odb_ResultPositionEnum resultPosition)
|
||||
{
|
||||
CVF_ASSERT(odb != NULL);
|
||||
|
||||
std::map<std::string, std::vector<std::string> > resultNamesMap;
|
||||
|
||||
odb_StepRepository stepRepository = odb->steps();
|
||||
odb_StepRepositoryIT sIter(stepRepository);
|
||||
for (sIter.first(); !sIter.isDone(); sIter.next())
|
||||
{
|
||||
odb_SequenceFrame& stepFrames = stepRepository[sIter.currentKey()].frames();
|
||||
|
||||
int numFrames = stepFrames.size();
|
||||
for (int f = 0; f < numFrames; f++)
|
||||
{
|
||||
odb_Frame frame = stepFrames.constGet(f);
|
||||
|
||||
odb_FieldOutputRepository& fieldCon = frame.fieldOutputs();
|
||||
odb_FieldOutputRepositoryIT fieldConIT(fieldCon);
|
||||
for (fieldConIT.first(); !fieldConIT.isDone(); fieldConIT.next())
|
||||
{
|
||||
odb_FieldOutput& field = fieldCon[fieldConIT.currentKey()];
|
||||
|
||||
odb_SequenceFieldLocation fieldLocations = field.locations();
|
||||
for (int loc = 0; loc < fieldLocations.size(); loc++)
|
||||
{
|
||||
const odb_FieldLocation& fieldLocation = fieldLocations.constGet(loc);
|
||||
if (fieldLocation.position() == resultPosition || resultPosition == odb_Enum::odb_ResultPositionEnum::UNDEFINED_POSITION)
|
||||
{
|
||||
std::string fieldName = field.name().CStr();
|
||||
odb_SequenceString components = field.componentLabels();
|
||||
|
||||
std::vector<std::string> compVec;
|
||||
|
||||
int numComp = components.size();
|
||||
for (int comp = 0; comp < numComp; comp++)
|
||||
{
|
||||
compVec.push_back(components[comp].CStr());
|
||||
}
|
||||
|
||||
resultNamesMap.insert(std::make_pair(fieldName, compVec));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultNamesMap;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOdbReader::readFemParts(RigFemPartCollection* femParts)
|
||||
{
|
||||
CVF_ASSERT(femParts);
|
||||
CVF_ASSERT(m_odb != NULL);
|
||||
|
||||
odb_Assembly& rootAssembly = m_odb->rootAssembly();
|
||||
odb_InstanceRepository instanceRepository = m_odb->rootAssembly().instances();
|
||||
|
||||
odb_InstanceRepositoryIT iter(instanceRepository);
|
||||
|
||||
@ -174,91 +262,6 @@ void RifOdbReader::readOdbFile(const std::string& fileName, RigFemPartCollection
|
||||
femPart->setElementPartId(femParts->partCount());
|
||||
femParts->addFemPart(femPart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::map<std::string, std::vector<std::string> > scalarFieldAndComponentNames(odb_Odb* odb, odb_Enum::odb_ResultPositionEnum resultPosition)
|
||||
{
|
||||
CVF_ASSERT(odb != NULL);
|
||||
|
||||
std::map<std::string, std::vector<std::string> > resultNamesMap;
|
||||
|
||||
odb_StepRepository stepRepository = odb->steps();
|
||||
odb_StepRepositoryIT sIter(stepRepository);
|
||||
for (sIter.first(); !sIter.isDone(); sIter.next())
|
||||
{
|
||||
odb_SequenceFrame& stepFrames = stepRepository[sIter.currentKey()].frames();
|
||||
|
||||
int numFrames = stepFrames.size();
|
||||
for (int f = 0; f < numFrames; f++)
|
||||
{
|
||||
odb_Frame frame = stepFrames.constGet(f);
|
||||
|
||||
odb_FieldOutputRepository& fieldCon = frame.fieldOutputs();
|
||||
odb_FieldOutputRepositoryIT fieldConIT(fieldCon);
|
||||
for (fieldConIT.first(); !fieldConIT.isDone(); fieldConIT.next())
|
||||
{
|
||||
odb_FieldOutput& field = fieldCon[fieldConIT.currentKey()];
|
||||
|
||||
odb_SequenceFieldLocation fieldLocations = field.locations();
|
||||
for (int loc = 0; loc < fieldLocations.size(); loc++)
|
||||
{
|
||||
const odb_FieldLocation& fieldLocation = fieldLocations.constGet(loc);
|
||||
if (fieldLocation.position() == resultPosition || resultPosition == odb_Enum::odb_ResultPositionEnum::UNDEFINED_POSITION)
|
||||
{
|
||||
std::string fieldName = field.name().CStr();
|
||||
odb_SequenceString components = field.componentLabels();
|
||||
|
||||
std::vector<std::string> compVec;
|
||||
|
||||
int numComp = components.size();
|
||||
for (int comp = 0; comp < numComp; comp++)
|
||||
{
|
||||
compVec.push_back(components[comp].CStr());
|
||||
}
|
||||
|
||||
resultNamesMap.insert(std::make_pair(fieldName, compVec));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resultNamesMap;
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RifOdbReader::readFemParts(const std::string& fileName, RigFemPartCollection* femParts)
|
||||
{
|
||||
initializeOdbAPI();
|
||||
|
||||
int status = 0;
|
||||
|
||||
try
|
||||
{
|
||||
this->readOdbFile(fileName, femParts);
|
||||
}
|
||||
|
||||
catch (const nex_Exception& nex)
|
||||
{
|
||||
status = 1;
|
||||
fprintf(stderr, "%s\n", nex.UserReport().CStr());
|
||||
fprintf(stderr, "ODB Application exited with error(s)\n");
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
status = 1;
|
||||
fprintf(stderr, "ODB Application exited with error(s)\n");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -40,7 +40,9 @@ public:
|
||||
RifOdbReader();
|
||||
virtual ~RifOdbReader();
|
||||
|
||||
virtual bool readFemParts(const std::string& fileName, RigFemPartCollection* geoMechCase);
|
||||
bool openFile(const std::string& fileName);
|
||||
|
||||
virtual bool readFemParts(RigFemPartCollection* geoMechCase);
|
||||
virtual std::vector<std::string> stepNames();
|
||||
virtual std::vector<double> frameTimes(int stepIndex);
|
||||
|
||||
@ -58,7 +60,6 @@ private:
|
||||
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();
|
||||
|
@ -35,45 +35,35 @@ TEST(OdbReaderTest, BasicTests)
|
||||
cvf::ref<RigGeoMechCaseData> femCase = new RigGeoMechCaseData;
|
||||
cvf::ref<RigFemPartCollection> femData = femCase->femParts();
|
||||
|
||||
reader->readFemParts(TEST_FILE, femData.p());
|
||||
reader->openFile(TEST_FILE);
|
||||
reader->readFemParts(femData.p());
|
||||
|
||||
EXPECT_EQ(1, femData->partCount());
|
||||
EXPECT_EQ(4320, femData->part(0)->elementCount());
|
||||
EXPECT_EQ(HEX8, femData->part(0)->elementType(0));
|
||||
|
||||
EXPECT_EQ(true, reader->stepNames().size() == 1);
|
||||
|
||||
std::vector<std::string> steps = reader->stepNames();
|
||||
EXPECT_EQ(true, steps.at(0).find("Date_20100930") >= 0);
|
||||
EXPECT_EQ(2, reader->frameTimes(0).size());
|
||||
EXPECT_EQ(1.0, reader->frameTimes(0)[1]);
|
||||
|
||||
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->readFemParts(TEST_FILE, femData2.p()));
|
||||
EXPECT_EQ(true, reader2->stepNames().size() == 1);
|
||||
|
||||
std::vector<std::string> steps = reader2->stepNames();
|
||||
EXPECT_EQ(true, steps.at(0).find("Date_20100930") >= 0);
|
||||
EXPECT_EQ(2, reader2->frameTimes(0).size());
|
||||
EXPECT_EQ(1.0, reader2->frameTimes(0)[1]);
|
||||
|
||||
scalarNodeFieldsMap = reader2->scalarNodeFieldAndComponentNames();
|
||||
EXPECT_EQ(3, scalarNodeFieldsMap.size());
|
||||
|
||||
std::map<std::string, std::vector<std::string> > scalarElementNodeFieldsMap = reader2->scalarElementNodeFieldAndComponentNames();
|
||||
std::map<std::string, std::vector<std::string> > scalarElementNodeFieldsMap = reader->scalarElementNodeFieldAndComponentNames();
|
||||
EXPECT_EQ(0, scalarElementNodeFieldsMap.size());
|
||||
|
||||
std::map<std::string, std::vector<std::string> > scalarIntegrationPointFieldsMap = reader2->scalarIntegrationPointFieldAndComponentNames();
|
||||
std::map<std::string, std::vector<std::string> > scalarIntegrationPointFieldsMap = reader->scalarIntegrationPointFieldAndComponentNames();
|
||||
EXPECT_EQ(6, scalarIntegrationPointFieldsMap.size());
|
||||
|
||||
std::vector<float> displacementValues;
|
||||
reader2->readScalarNodeField("U", "U2", 0, 0, 1, &displacementValues);
|
||||
reader->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;
|
||||
reader->readDisplacements(0, 0, 1, &displacements);
|
||||
EXPECT_EQ(5168, displacements.size());
|
||||
EXPECT_FLOAT_EQ(0.047638997, displacements[1].y());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user