TestXdmfVisitor.cpp 1.91 KB
Newer Older
1
#include "XdmfAttribute.hpp"
2
#include "XdmfDataItem.hpp"
Kenneth Leiter's avatar
Kenneth Leiter committed
3
#include "XdmfDomain.hpp"
4 5
#include "XdmfGeometry.hpp"
#include "XdmfGrid.hpp"
6 7 8 9 10
#include "XdmfTopology.hpp"
#include "XdmfVisitor.hpp"

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

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

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

	// Set Topology
24
	int connectivity[] = {0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10};
25
	grid->getTopology()->setNumberElements(2);
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
	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);
Kenneth Leiter's avatar
Kenneth Leiter committed
49 50 51 52 53

	boost::shared_ptr<XdmfDomain> domain = XdmfDomain::New();
	domain->insert(grid);
	domain->write(visitor3);

54 55
	std::cout << visitor3->printSelf() << std::endl;

56 57
	return 0;
}