XdmfTestDataGenerator.hpp 2.62 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 "XdmfSet.hpp"
8
#include "XdmfSetType.hpp"
9
#include "XdmfTime.hpp"
10
#include "XdmfTopology.hpp"
11
#include "XdmfTopologyType.hpp"
12
#include "XdmfUnstructuredGrid.hpp"
13 14 15 16

class XdmfTestDataGenerator {
public:

17 18 19 20 21 22 23 24 25 26 27
  /**
   * Number of Cells = 2
   * Number of Points = 12
   * Number of Attributes = 2
   *   Cell Attributes = 1
   *   Nodal Attributes = 1
   * Number of Sets = 1
   *   Nodal Set = 1
   * Time = 100
   * Total Number of Values = 69
   */
28
  static shared_ptr<XdmfUnstructuredGrid> createHexahedron()
29
  {
30
    shared_ptr<XdmfUnstructuredGrid> grid = XdmfUnstructuredGrid::New();
31
    grid->setName("Hexahedron");
32

33 34 35 36 37 38 39 40
    // 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};
    grid->getGeometry()->setType(XdmfGeometryType::XYZ());
    grid->getGeometry()->insert(0, &points[0], 36);
    //grid->getGeometry()->setName("Geom 1");
41

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

47
    // Add Node Attribute
48
    shared_ptr<XdmfAttribute> nodalAttribute = XdmfAttribute::New();
49 50 51 52 53 54
    int nodeValues[] = {100, 200, 300, 300, 400, 500, 300, 400, 500, 500, 600,
                        700};
    nodalAttribute->setName("Nodal Attribute");
    nodalAttribute->setType(XdmfAttributeType::Scalar());
    nodalAttribute->setCenter(XdmfAttributeCenter::Node());
    nodalAttribute->insert(0, &nodeValues[0], 12);
55

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

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

71
    // Add Time
72
    shared_ptr<XdmfTime> time = XdmfTime::New(100);
73
    grid->setTime(time);
74

75 76 77 78 79
    grid->insert(nodalAttribute);
    grid->insert(cellAttribute);
    grid->insert(nodeSet);
    return grid;
  }
80 81 82

};