XdmfTopology.cpp 2.27 KB
Newer Older
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
1
/*
2
 * XdmfTopology.cpp
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
3 4 5 6 7
 *
 *  Created on: Jan 29, 2010
 *      Author: kleiter
 */

8
#include <sstream>
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
9
#include "XdmfTopology.hpp"
10
#include "XdmfTopologyType.hpp"
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
11

12 13 14 15 16 17
boost::shared_ptr<XdmfTopology> XdmfTopology::New()
{
	boost::shared_ptr<XdmfTopology> p(new XdmfTopology());
	return p;
}

18
XdmfTopology::XdmfTopology() :
19
	mDimensions(""),
20
	mType(XdmfTopologyType::NoTopologyType())
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
21 22 23 24 25 26 27
{
}

XdmfTopology::~XdmfTopology()
{
}

28
const std::string XdmfTopology::ItemTag = "Topology";
29

30 31 32 33 34 35 36 37 38 39 40
std::string XdmfTopology::getDimensions() const
{
	if(mDimensions.compare("") == 0)
	{
		std::stringstream toReturn;
		toReturn << this->getNumberElements();
		return toReturn.str();
	}
	return mDimensions;
}

41 42
std::string XdmfTopology::getItemTag() const
{
43
	return ItemTag;
44 45
}

46 47 48
std::map<std::string, std::string> XdmfTopology::getItemProperties() const
{
	std::map<std::string, std::string> topologyProperties;
49
	mType->getProperties(topologyProperties);
50
	if(mType->getCellType() != XdmfTopologyType::Structured && mType != XdmfTopologyType::Polyvertex())
51 52 53 54 55
	{
		std::stringstream numElements;
		numElements << this->getNumberElements();
		topologyProperties["Dimensions"] = numElements.str();
	}
56 57 58
	return topologyProperties;
}

59
unsigned int XdmfTopology::getNumberElements() const
60
{
61
	if(mType->getNodesPerElement() == 0)
62 63 64
	{
		return 0;
	}
65
	return this->getSize() / mType->getNodesPerElement();
66 67
}

68
boost::shared_ptr<const XdmfTopologyType> XdmfTopology::getType() const
69
{
70
	return mType;
71 72
}

73
void XdmfTopology::populateItem(const std::map<std::string, std::string> & itemProperties, std::vector<boost::shared_ptr<XdmfItem> > & childItems, const XdmfCoreReader * const reader)
74
{
75 76
	XdmfItem::populateItem(itemProperties, childItems, reader);
	mType = XdmfTopologyType::New(itemProperties);
77 78 79 80 81
	std::map<std::string, std::string>::const_iterator dimensions = itemProperties.find("Dimensions");
	if(dimensions != itemProperties.end())
	{
		mDimensions = dimensions->second;
	}
82 83 84 85 86 87 88 89
	for(std::vector<boost::shared_ptr<XdmfItem> >::const_iterator iter = childItems.begin(); iter != childItems.end(); ++iter)
	{
		if(boost::shared_ptr<XdmfArray> array = boost::shared_dynamic_cast<XdmfArray>(*iter))
		{
			this->swap(array);
		}
		// TODO: If multiple dataitems.
	}
90 91
}

92
void XdmfTopology::setType(const boost::shared_ptr<const XdmfTopologyType> type)
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
93
{
94
	mType = type;
Ken Leiter (Civ's avatar
Ken Leiter (Civ committed
95
}