mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-09 23:16:00 -06:00
Got elements and nodes from odb in the unit test
This commit is contained in:
parent
4737807b7b
commit
6dad519f30
@ -35,3 +35,31 @@ RigFemPart::~RigFemPart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigFemPart::preAllocateElementStorage(int elementCount)
|
||||
{
|
||||
m_elementId.reserve(elementCount);
|
||||
m_elementTypes.reserve(elementCount);
|
||||
m_elementConnectivityStartIndices.reserve(elementCount);
|
||||
|
||||
m_allAlementConnectivities.reserve(elementCount*8);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RigFemPart::appendElement(RigElementType elmType, int id, const int* connectivities)
|
||||
{
|
||||
m_elementId.push_back(id);
|
||||
m_elementTypes.push_back(elmType);
|
||||
m_elementConnectivityStartIndices.push_back(m_allAlementConnectivities.size());
|
||||
|
||||
int nodeCount = elmentNodeCount(elmType);
|
||||
for (int lnIdx = 0; lnIdx < nodeCount; ++lnIdx)
|
||||
{
|
||||
m_allAlementConnectivities.push_back(connectivities[lnIdx]);
|
||||
}
|
||||
}
|
||||
|
@ -38,13 +38,13 @@ class RigFemPart : public cvf::Object
|
||||
public:
|
||||
RigFemPart();
|
||||
virtual ~RigFemPart();
|
||||
|
||||
int appendElement(RigElementType elmType, int id, const int* connectivities);
|
||||
void preAllocateElementStorage(int elementCount);
|
||||
void appendElement(RigElementType elmType, int id, const int* connectivities);
|
||||
|
||||
size_t elementCount() const { return m_elementId.size(); }
|
||||
|
||||
int elmId(size_t index) const { return m_elementId[index]; }
|
||||
RigElementType elmentType(size_t index) const { return m_elementTypes[index]; }
|
||||
RigElementType elementType(size_t index) const { return m_elementTypes[index]; }
|
||||
const int* connectivities(size_t index) const { return &m_allAlementConnectivities[m_elementConnectivityStartIndices[index]];}
|
||||
|
||||
RigFemPartNodes& nodes() {return m_nodes;}
|
||||
|
@ -18,22 +18,24 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
#include <assert.h>
|
||||
|
||||
enum RigElementType
|
||||
{
|
||||
HEX8
|
||||
HEX8,
|
||||
CAX4
|
||||
};
|
||||
|
||||
static const int elmentNodeCount(RigElementType elmType)
|
||||
{
|
||||
static int elementTypeCounts[1] = {8};
|
||||
static int elementTypeCounts[2] = {8,4};
|
||||
|
||||
return elementTypeCounts[elmType];
|
||||
}
|
||||
|
||||
static const int elmentFaceCount(RigElementType elmType)
|
||||
{
|
||||
const static int elementFaceCounts[1] = {6};
|
||||
const static int elementFaceCounts[2] = {6, 1};
|
||||
|
||||
return elementFaceCounts[elmType];
|
||||
}
|
||||
@ -51,7 +53,22 @@ static const int elmentFaceCount(RigElementType elmType)
|
||||
static const int* elementLocalFaceIndices(RigElementType elmType, int faceIdx, int* faceNodeCount)
|
||||
{
|
||||
static const int HEX8_Faces[6][4] = { {1, 2, 6, 5 }, {0,4,7,3}, {3,7,6,2}, {0,1,5,4}, {4,5,6,7} ,{0,3,2,1} };
|
||||
static const int CAX4_Faces[4] = {0, 1, 2, 3 };
|
||||
|
||||
(*faceNodeCount) = 4;
|
||||
return HEX8_Faces[faceIdx];
|
||||
switch (elmType)
|
||||
{
|
||||
case HEX8:
|
||||
(*faceNodeCount) = 4;
|
||||
return HEX8_Faces[faceIdx];
|
||||
break;
|
||||
case CAX4:
|
||||
(*faceNodeCount) = 4;
|
||||
return CAX4_Faces;
|
||||
break;
|
||||
default:
|
||||
assert(false); // Element type not supported
|
||||
break;
|
||||
}
|
||||
|
||||
return CAX4_Faces;
|
||||
}
|
@ -24,6 +24,18 @@
|
||||
|
||||
#include <odb_API.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
std::map<std::string, RigElementType> initFemTypeMap()
|
||||
{
|
||||
std::map<std::string, RigElementType> typeMap;
|
||||
typeMap["C3D8R"] = HEX8;
|
||||
typeMap["CAX4"] = CAX4;
|
||||
|
||||
return typeMap;
|
||||
}
|
||||
|
||||
static std::map<std::string, RigElementType> odbElmTypeToRigElmTypeMap = initFemTypeMap();
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -50,13 +62,48 @@ void readOdbFile(const std::string& fileName, RigGeoMechCaseData* geoMechCase)
|
||||
odb_Odb& odb = openOdb(path);
|
||||
|
||||
odb_Assembly& rootAssembly = odb.rootAssembly();
|
||||
odb_InstanceRepository instanceRepository = odb.rootAssembly().instances();
|
||||
|
||||
RigFemPart* part = new RigFemPart;
|
||||
odb_InstanceRepositoryIT iter(instanceRepository);
|
||||
for (iter.first(); !iter.isDone(); iter.next())
|
||||
{
|
||||
odb_Instance& inst = instanceRepository[iter.currentKey()];
|
||||
|
||||
const odb_SequenceNode& nodes = rootAssembly.nodes();
|
||||
RigFemPart* femPart = new RigFemPart;
|
||||
|
||||
const odb_SequenceElement& elements = rootAssembly.elements();
|
||||
const odb_SequenceNode& odbNodes = inst.nodes();
|
||||
|
||||
int nodeCount = odbNodes.size();
|
||||
femPart->nodes().nodeIds.resize(nodeCount);
|
||||
femPart->nodes().coordinates.resize(nodeCount);
|
||||
|
||||
for (int nIdx = 0; nIdx < nodeCount; ++nIdx)
|
||||
{
|
||||
const odb_Node odbNode = odbNodes.node(nIdx);
|
||||
femPart->nodes().nodeIds[nIdx] = odbNode.label();
|
||||
const float * pos = odbNode.coordinates();
|
||||
femPart->nodes().coordinates[nIdx].set(pos[0], pos[1], pos[2]);
|
||||
}
|
||||
|
||||
const odb_SequenceElement& elements = inst.elements();
|
||||
|
||||
int elmCount = elements.size();
|
||||
femPart->preAllocateElementStorage(elmCount);
|
||||
std::map<std::string, RigElementType>::const_iterator it;
|
||||
for (int elmIdx = 0; elmIdx < elmCount; ++elmIdx)
|
||||
{
|
||||
const odb_Element odbElm = elements.element(elmIdx);
|
||||
it = odbElmTypeToRigElmTypeMap.find(odbElm.type().cStr());
|
||||
|
||||
if (it == odbElmTypeToRigElmTypeMap.end()) continue;
|
||||
|
||||
RigElementType elmType = it->second;
|
||||
int nodeCount = 0;
|
||||
femPart->appendElement(elmType, odbElm.label(), odbElm.connectivity(nodeCount));
|
||||
}
|
||||
|
||||
geoMechCase->addFemPart(femPart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -28,7 +28,11 @@ TEST(OdbReaderTest, BasicTests)
|
||||
{
|
||||
cvf::ref<RifOdbReader> reader = new RifOdbReader;
|
||||
cvf::ref<RigGeoMechCaseData> femData = new RigGeoMechCaseData;
|
||||
reader->open("testfile.odb", femData.p());
|
||||
reader->open("C:\\pfRoot\\jjsOnJacobpcCsdep\\User\\Sigurd\\OdbApiExperiments\\viewer_tutorial.odb", femData.p());
|
||||
|
||||
EXPECT_EQ(1, femData->partCount());
|
||||
EXPECT_EQ(140, femData->part(0)->elementCount());
|
||||
EXPECT_EQ(CAX4, femData->part(0)->elementType(0));
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user