XdmfTestDataGenerator.hpp 3.06 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
  /**
   * Number of Cells = 2
   * Number of Points = 12
   * Number of Attributes = 2
   *   Cell Attributes = 1
   *   Nodal Attributes = 1
Kenneth Leiter's avatar
Kenneth Leiter committed
23
   *   Grid Attributes = 1
24 25 26
   * Number of Sets = 1
   *   Nodal Set = 1
   * Time = 100
Kenneth Leiter's avatar
Kenneth Leiter committed
27
   * Total Number of Values = 71
28
   */
29
  static shared_ptr<XdmfUnstructuredGrid> createHexahedron()
30
  {
31
    shared_ptr<XdmfUnstructuredGrid> grid = XdmfUnstructuredGrid::New();
32
    grid->setName("Hexahedron");
33

34 35 36 37 38 39 40 41
    // 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");
42

43 44 45 46
    // 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);
47

48
    // Add Node Attribute
49
    shared_ptr<XdmfAttribute> nodalAttribute = XdmfAttribute::New();
50 51 52 53 54 55
    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);
56

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

Kenneth Leiter's avatar
Kenneth Leiter committed
65 66 67 68 69 70 71 72 73 74
    // Add Grid Attribute
    shared_ptr<XdmfAttribute> gridAttribute = XdmfAttribute::New();
    std::string gridValues[] = {"foo", "bar"};
    //int gridValues[] = {1, 2};
    gridAttribute->setName("Grid Attribute");
    gridAttribute->setType(XdmfAttributeType::Vector());
    gridAttribute->setCenter(XdmfAttributeCenter::Grid());
    gridAttribute->insert(0, &gridValues[0], 2);


75
    // Add Node Set
76
    shared_ptr<XdmfSet> nodeSet = XdmfSet::New();
77 78 79 80
    int nodeIds[] = {0, 1, 2};
    nodeSet->setName("Node Set");
    nodeSet->setType(XdmfSetType::Node());
    nodeSet->insert(0, &nodeIds[0], 3);
81

82
    // Add Time
83
    shared_ptr<XdmfTime> time = XdmfTime::New(100);
84
    grid->setTime(time);
85

86 87
    grid->insert(nodalAttribute);
    grid->insert(cellAttribute);
Kenneth Leiter's avatar
Kenneth Leiter committed
88
    grid->insert(gridAttribute);
89 90 91
    grid->insert(nodeSet);
    return grid;
  }
92 93 94

};