TestXdmfVisitor.cpp 1.8 KB
Newer Older
1
#include "XdmfAttribute.hpp"
2
#include "XdmfDataItem.hpp"
3 4
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
5 6 7 8 9
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"

int main(int argc, char* argv[])
{
10 11
	boost::shared_ptr<XdmfVisitor> visitor3 = XdmfVisitor::New();
	boost::shared_ptr<XdmfGrid> grid = XdmfGrid::New();
12

13
	grid->setName("test");
14 15

	// Set Geometry
16
	int points[] = {0, 0, 1, 1, 0, 1, 3, 0, 2, 0, 1, 1, 1, 1, 1, 3, 2, 2,
17
			0, 0, -1, 1, 0, -1, 3, 0, -2, 0, 1, -1, 1, 1, -1, 3, 2, -2};
18
	grid->getGeometry()->setNumberPoints(12);
19
	grid->getGeometry()->setGeometryType(XdmfGeometryType::XYZ());
20
	grid->getGeometry()->setData(points);
21 22

	// Set Topology
23
	int connectivity[] = {0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10};
24
	grid->getTopology()->setNumberElements(2);
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	grid->getTopology()->setTopologyType(XdmfTopologyType::Hexahedron());
	grid->getTopology()->setData(connectivity);

	// Add Node Attribute
	boost::shared_ptr<XdmfAttribute> nodalAttribute = XdmfAttribute::New();
	int nodeValues[] = {100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600, 700};
	nodalAttribute->setName("Nodal Attribute");
	nodalAttribute->setNumberValues(12);
	nodalAttribute->setAttributeType(XdmfAttributeType::Scalar());
	nodalAttribute->setAttributeCenter(XdmfAttributeCenter::Node());
	nodalAttribute->setData(nodeValues);

	// Add Cell Attribute
	boost::shared_ptr<XdmfAttribute> cellAttribute = XdmfAttribute::New();
	int cellValues[] = {100, 200};
	cellAttribute->setName("Cell Attribute");
	cellAttribute->setNumberValues(2);
	cellAttribute->setAttributeType(XdmfAttributeType::Scalar());
	cellAttribute->setAttributeCenter(XdmfAttributeCenter::Cell());
	cellAttribute->setData(cellValues);

	grid->insert(nodalAttribute);
	grid->insert(cellAttribute);
48 49 50
	grid->write(visitor3);
	std::cout << visitor3->printSelf() << std::endl;

51 52
	return 0;
}