XdmfTestDataGenerator.hpp 2.48 KB
Newer Older
1
#include "XdmfAttribute.hpp"
2 3
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
4 5
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
6
#include "XdmfGeometryType.hpp"
7
#include "XdmfGridUnstructured.hpp"
8
#include "XdmfSet.hpp"
9
#include "XdmfSetType.hpp"
10
#include "XdmfTime.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
	 * Number of Sets = 1
	 *  Nodal Set = 1
25
	 * Time = 100
26
	 * Total Number of Values = 69
27
	 */
28
	static boost::shared_ptr<XdmfGridUnstructured> createHexahedron()
29
	{
30
		boost::shared_ptr<XdmfGridUnstructured> grid = XdmfGridUnstructured::New();
31 32 33 34 35
		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};
36
		grid->getGeometry()->setType(XdmfGeometryType::XYZ());
37
		grid->getGeometry()->insert(0, &points[0], 36);
38
		//grid->getGeometry()->setName("Geom 1");
39 40 41

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

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

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

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

68
		// Add Time
69 70 71
		boost::shared_ptr<XdmfTime> time = XdmfTime::New(100);
		grid->setTime(time);

72 73
		grid->insert(nodalAttribute);
		grid->insert(cellAttribute);
74
		grid->insert(nodeSet);
75 76 77 78 79
		return grid;
	}

};