2015-04-23 06:24:15 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) Statoil ASA
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
|
|
|
//
|
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RifOdbReader.h"
|
|
|
|
|
2015-04-27 03:25:04 -05:00
|
|
|
#include "RigFemPartCollection.h"
|
2015-04-23 06:24:15 -05:00
|
|
|
#include "RigFemPart.h"
|
|
|
|
|
|
|
|
#include <odb_API.h>
|
|
|
|
|
2015-04-23 08:43:11 -05:00
|
|
|
#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();
|
2015-04-23 06:24:15 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RifOdbReader::RifOdbReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
RifOdbReader::~RifOdbReader()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-27 03:25:04 -05:00
|
|
|
void readOdbFile(const std::string& fileName, RigFemPartCollection* femParts)
|
2015-04-23 06:24:15 -05:00
|
|
|
{
|
2015-04-27 03:25:04 -05:00
|
|
|
CVF_ASSERT(femParts);
|
2015-04-23 06:24:15 -05:00
|
|
|
|
|
|
|
odb_String path = fileName.c_str();
|
|
|
|
|
|
|
|
odb_Odb& odb = openOdb(path);
|
|
|
|
|
|
|
|
odb_Assembly& rootAssembly = odb.rootAssembly();
|
2015-04-23 08:43:11 -05:00
|
|
|
odb_InstanceRepository instanceRepository = odb.rootAssembly().instances();
|
|
|
|
|
|
|
|
odb_InstanceRepositoryIT iter(instanceRepository);
|
2015-04-24 08:53:50 -05:00
|
|
|
|
2015-04-23 08:43:11 -05:00
|
|
|
for (iter.first(); !iter.isDone(); iter.next())
|
|
|
|
{
|
|
|
|
odb_Instance& inst = instanceRepository[iter.currentKey()];
|
|
|
|
|
|
|
|
RigFemPart* femPart = new RigFemPart;
|
|
|
|
|
|
|
|
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();
|
2015-04-23 06:24:15 -05:00
|
|
|
|
2015-04-23 08:43:11 -05:00
|
|
|
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());
|
2015-04-23 06:24:15 -05:00
|
|
|
|
2015-04-23 08:43:11 -05:00
|
|
|
if (it == odbElmTypeToRigElmTypeMap.end()) continue;
|
2015-04-23 06:24:15 -05:00
|
|
|
|
2015-04-23 08:43:11 -05:00
|
|
|
RigElementType elmType = it->second;
|
|
|
|
int nodeCount = 0;
|
|
|
|
femPart->appendElement(elmType, odbElm.label(), odbElm.connectivity(nodeCount));
|
|
|
|
}
|
2015-04-23 06:24:15 -05:00
|
|
|
|
2015-04-27 03:25:04 -05:00
|
|
|
femPart->setElementPartId(femParts->partCount());
|
|
|
|
femParts->addFemPart(femPart);
|
2015-04-23 08:43:11 -05:00
|
|
|
}
|
2015-04-23 06:24:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-04-27 03:25:04 -05:00
|
|
|
bool RifOdbReader::readFemParts(const std::string& fileName, RigFemPartCollection* femParts)
|
2015-04-23 06:24:15 -05:00
|
|
|
{
|
|
|
|
odb_initializeAPI();
|
|
|
|
|
|
|
|
int status = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2015-04-27 03:25:04 -05:00
|
|
|
readOdbFile(fileName, femParts);
|
2015-04-23 06:24:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
odb_finalizeAPI();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
void RifOdbReader::close()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
std::vector<double> RifOdbReader::timeSteps()
|
|
|
|
{
|
|
|
|
return std::vector<double>();
|
|
|
|
}
|