Commit f45699a2 authored by Kenneth Leiter's avatar Kenneth Leiter

BUG: Fix bug in implementation of Polyline topology type.

Polyline requires nodes per element to be provided in order to allow
for non contiguous polyline structures. Modified polyline constructor to
accept nodes per element as a parameter. Modify I/O to read value correctly.
parent 5fe29ae7
......@@ -89,7 +89,7 @@ XdmfTopology::getNumberElements() const
numberElements += numberPolyvertexElements;
index += numberPolyvertexElements + 2;
}
else if(topologyType == XdmfTopologyType::Polyline() ||
else if(topologyType == XdmfTopologyType::Polyline(0) ||
topologyType == XdmfTopologyType::Polygon(0)) {
const unsigned int numberNodes =
this->getValue<unsigned int>(index + 1);
......
......@@ -44,10 +44,18 @@ XdmfTopologyType::Polyvertex()
}
shared_ptr<const XdmfTopologyType>
XdmfTopologyType::Polyline()
XdmfTopologyType::Polyline(const unsigned int nodesPerElement)
{
static shared_ptr<const XdmfTopologyType>
p(new XdmfTopologyType(1, "Polyline", Linear, 0x2));
static std::map<unsigned int, shared_ptr<const XdmfTopologyType> >
previousTypes;
std::map<unsigned int, shared_ptr<const XdmfTopologyType> >::const_iterator
type = previousTypes.find(nodesPerElement);
if(type != previousTypes.end()) {
return type->second;
}
shared_ptr<const XdmfTopologyType>
p(new XdmfTopologyType(nodesPerElement, "Polyline", Linear, 0x2));
previousTypes[nodesPerElement] = p;
return p;
}
......@@ -252,8 +260,8 @@ XdmfTopologyType::New(const unsigned int id)
else if(id == XdmfTopologyType::Polyvertex()->getID()) {
return XdmfTopologyType::Polyvertex();
}
else if(id == XdmfTopologyType::Polyline()->getID()) {
return XdmfTopologyType::Polyline();
else if(id == XdmfTopologyType::Polyline(0)->getID()) {
return XdmfTopologyType::Polyline(0);
}
else if(id == XdmfTopologyType::Polygon(0)->getID()) {
return XdmfTopologyType::Polygon(0);
......@@ -366,13 +374,20 @@ XdmfTopologyType::New(const std::map<std::string, std::string> & itemProperties)
return Polyvertex();
}
else if(typeVal.compare("POLYLINE") == 0) {
return Polyline();
if(nodesPerElement != itemProperties.end()) {
return Polyline(atoi(nodesPerElement->second.c_str()));
}
XdmfError::message(XdmfError::FATAL,
"'NodesPerElement' not in itemProperties and type "
"'POLYLINE' selected in XdmfTopologyType::New");
}
else if(typeVal.compare("POLYGON") == 0) {
if(nodesPerElement != itemProperties.end()) {
return Polygon(atoi(nodesPerElement->second.c_str()));
}
XdmfError::message(XdmfError::FATAL, "'NodesPerElement' not in itemProperties and type 'POLYGON' selected in XdmfTopologyType::New");
XdmfError::message(XdmfError::FATAL,
"'NodesPerElement' not in itemProperties and type "
"'POLYGON' selected in XdmfTopologyType::New");
}
else if(typeVal.compare("TRIANGLE") == 0) {
return Triangle();
......@@ -467,7 +482,7 @@ void
XdmfTopologyType::getProperties(std::map<std::string, std::string> & collectedProperties) const
{
collectedProperties["Type"] = this->getName();
if(mName.compare("Polygon") == 0) {
if(mName.compare("Polygon") == 0 || mName.compare("Polyline") == 0) {
std::stringstream nodesPerElement;
nodesPerElement << mNodesPerElement;
collectedProperties["NodesPerElement"] = nodesPerElement.str();
......
......@@ -87,7 +87,8 @@ public:
*/
static shared_ptr<const XdmfTopologyType> NoTopologyType();
static shared_ptr<const XdmfTopologyType> Polyvertex();
static shared_ptr<const XdmfTopologyType> Polyline();
static shared_ptr<const XdmfTopologyType>
Polyline(const unsigned int nodesPerElement);
static shared_ptr<const XdmfTopologyType>
Polygon(const unsigned int nodesPerElement);
static shared_ptr<const XdmfTopologyType> Triangle();
......
......@@ -55,7 +55,7 @@ int main(int, char **)
grid0->getGeometry()->setType(XdmfGeometryType::XYZ());
double points0[] = {-1, 0, 0, 0, 0, 0};
grid0->getGeometry()->insert(0, &points0[0], 6);
grid0->getTopology()->setType(XdmfTopologyType::Polyline());
grid0->getTopology()->setType(XdmfTopologyType::Polyline(2));
unsigned int connectivity0[] = {0, 1};
grid0->getTopology()->insert(0, &connectivity0[0], 2);
shared_ptr<XdmfAttribute> globalNodeIds0 = XdmfAttribute::New();
......@@ -70,7 +70,7 @@ int main(int, char **)
grid1->getGeometry()->setType(XdmfGeometryType::XYZ());
double points1[] = {0, 0, 0, 1, 0, 0};
grid1->getGeometry()->insert(0, &points1[0], 6);
grid1->getTopology()->setType(XdmfTopologyType::Polyline());
grid1->getTopology()->setType(XdmfTopologyType::Polyline(2));
unsigned int connectivity1[] = {0, 1};
grid1->getTopology()->insert(0, &connectivity1[0], 2);
shared_ptr<XdmfAttribute> globalNodeIds1 = XdmfAttribute::New();
......
......@@ -34,7 +34,7 @@ int main(int, char **)
topology->pushBack(1);
topology->pushBack(2);
topology->pushBack(3);
topology->pushBack(XdmfTopologyType::Polyline()->getID());
topology->pushBack(XdmfTopologyType::Polyline(0)->getID());
topology->pushBack(6);
topology->pushBack(2);
topology->pushBack(4);
......
......@@ -50,7 +50,7 @@ if __name__ == "__main__":
xtt1 = XdmfTopologyType.Polyvertex()
xtt2 = XdmfTopologyType.Polyvertex()
xtt3 = XdmfTopologyType.Polyline()
xtt3 = XdmfTopologyType.Polyline(0)
print "XdmfTopologyType True Check"
assert xtt1 == xtt2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment