TestXdmfTopologyConverter.cpp 2.55 KB
Newer Older
1 2
#include <math.h>
#include "XdmfArray.hpp"
3
#include "XdmfArrayType.hpp"
4 5 6 7 8
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyConverter.hpp"
#include "XdmfTopologyType.hpp"
9
#include "XdmfUnstructuredGrid.hpp"
10 11
#include "XdmfWriter.hpp"

12
int main(int, char *)
13
{
14
  shared_ptr<XdmfTopologyConverter> converter =
15
    XdmfTopologyConverter::New();
16

17
  // Create Hexahedron Grid
18
  shared_ptr<XdmfUnstructuredGrid> hexGrid =
19 20 21 22 23 24 25 26 27 28
    XdmfUnstructuredGrid::New();
  double hexPoints[24] = {0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0,
                          1, 1, 1, 1, 0, 1, 1};
  hexGrid->getGeometry()->setType(XdmfGeometryType::XYZ());
  hexGrid->getGeometry()->resize<double>(24, 0);
  hexGrid->getGeometry()->insert(0, hexPoints, 24);
  unsigned int hexConn[8] = {0, 1, 2, 3, 4, 5, 6, 7};
  hexGrid->getTopology()->setType(XdmfTopologyType::Hexahedron());
  hexGrid->getTopology()->resize<unsigned int>(8, 0);
  hexGrid->getTopology()->insert(0, hexConn, 8);
29

30 31 32
  /*
   * Hexahedron to Hexahedron_64
   */
33
  shared_ptr<XdmfUnstructuredGrid> hex64Grid =
34
    converter->convert(hexGrid, XdmfTopologyType::Hexahedron_64());
35

36 37 38 39 40 41 42 43
  assert(hex64Grid->getGeometry()->getType() == XdmfGeometryType::XYZ());
  assert(hex64Grid->getGeometry()->getNumberPoints() == 64);
  assert(hex64Grid->getTopology()->getType() ==
         XdmfTopologyType::Hexahedron_64());
  assert(hex64Grid->getTopology()->getNumberElements() == 1);
  for(unsigned int i=0; i<64; ++i) {
    assert(i == hex64Grid->getTopology()->getValue<unsigned int>(i));
  }
44

45 46 47
  /*
   * Hexahedron to Hexahedron_125
   */
48
  shared_ptr<XdmfUnstructuredGrid> hex125Grid =
49
    converter->convert(hexGrid, XdmfTopologyType::Hexahedron_125());
50

51 52 53 54 55 56 57 58
  assert(hex125Grid->getGeometry()->getType() == XdmfGeometryType::XYZ());
  assert(hex125Grid->getGeometry()->getNumberPoints() == 125);
  assert(hex125Grid->getTopology()->getType() ==
         XdmfTopologyType::Hexahedron_125());
  assert(hex125Grid->getTopology()->getNumberElements() == 1);
  for(unsigned int i=0; i<125; ++i) {
    assert(i == hex125Grid->getTopology()->getValue<unsigned int>(i));
  }
59

60 61 62
  /*
   * Hexahedron_64 to Hexahedron
   */
63
  shared_ptr<XdmfUnstructuredGrid> newHexGrid =
64 65 66 67 68 69 70
    converter->convert(hex64Grid, XdmfTopologyType::Hexahedron());
  assert(newHexGrid->getGeometry()->getType() == XdmfGeometryType::XYZ());
  assert(newHexGrid->getGeometry()->getNumberPoints() == 64);
  assert(newHexGrid->getTopology()->getType() ==
         XdmfTopologyType::Hexahedron());
  assert(newHexGrid->getTopology()->getNumberElements() == 27);
  return 0;
71
}