XdmfTestDataGenerator.hpp 2.42 KB
Newer Older
1
#include "XdmfAttribute.hpp"
2 3
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
4 5 6
#include "XdmfArray.hpp"
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
7
#include "XdmfGeometryType.hpp"
8
#include "XdmfGrid.hpp"
9
#include "XdmfSet.hpp"
10
#include "XdmfSetType.hpp"
11
#include "XdmfTopology.hpp"
12
#include "XdmfTopologyType.hpp"
13 14 15 16 17 18 19 20 21 22

class XdmfTestDataGenerator {
public:

	/**
	 * Number of Cells = 2
	 * Number of Points = 12
	 * Number of Attributes = 2
	 * 	Cell Attributes = 1
	 * 	Nodal Attributes = 1
23 24 25
	 * Number of Sets = 1
	 *  Nodal Set = 1
	 * Total Number of Values = 69
26 27 28 29 30 31 32 33 34
	 */
	static boost::shared_ptr<XdmfGrid> createHexahedron()
	{
		boost::shared_ptr<XdmfGrid> grid = XdmfGrid::New();
		grid->setName("Hexahedron");

		// Set Geometry
		double points[] = {0.1, 0.1, 1.1, 1.1, 0.1, 1.1, 3.1, 0.1, 2.1, 0.1, 1.1, 1.1, 1.1, 1.1, 1.1, 3.1, 2.1, 2.1,
				0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1, 0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1};
35
		grid->getGeometry()->setType(XdmfGeometryType::XYZ());
36
		grid->getGeometry()->getArray()->copyValues(0, &points[0], 36);
37
		grid->getGeometry()->getArray()->setName("Geom 1");
38 39 40

		// Set Topology
		int connectivity[] = {0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10};
41
		grid->getTopology()->setType(XdmfTopologyType::Hexahedron());
42 43 44 45 46 47
		grid->getTopology()->getArray()->copyValues(0, &connectivity[0], 16);

		// 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");
48 49
		nodalAttribute->setType(XdmfAttributeType::Scalar());
		nodalAttribute->setCenter(XdmfAttributeCenter::Node());
50 51 52 53 54 55
		nodalAttribute->getArray()->copyValues(0, &nodeValues[0], 12);

		// Add Cell Attribute
		boost::shared_ptr<XdmfAttribute> cellAttribute = XdmfAttribute::New();
		int cellValues[] = {100, 200};
		cellAttribute->setName("Cell Attribute");
56 57
		cellAttribute->setType(XdmfAttributeType::Scalar());
		cellAttribute->setCenter(XdmfAttributeCenter::Cell());
58 59
		cellAttribute->getArray()->copyValues(0, &cellValues[0], 2);

60 61 62 63 64 65 66
		// Add Node Set
		boost::shared_ptr<XdmfSet> nodeSet = XdmfSet::New();
		int nodeIds[] = {0, 1, 2};
		nodeSet->setName("Node Set");
		nodeSet->setSetType(XdmfSetType::Node());
		nodeSet->getArray()->copyValues(0, &nodeIds[0], 3);

67 68
		grid->insert(nodalAttribute);
		grid->insert(cellAttribute);
69
		grid->insert(nodeSet);
70 71 72 73 74
		return grid;
	}

};