TestXdmfRectilinearGrid.cpp 3.71 KB
Newer Older
1 2 3
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
4
#include "XdmfRectilinearGrid.hpp"
5 6 7
#include "XdmfReader.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
8
#include "XdmfHDF5Writer.hpp"
9
#include "XdmfWriter.hpp"
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
10
#include <iostream>
11
#include <assert.h>
12 13 14

#include "XdmfTestCompareFiles.hpp"

15
int main(int, char **)
16
{
17
  shared_ptr<XdmfArray> vx = XdmfArray::New();
18
  vx->initialize<unsigned int>(4);
19 20 21 22
  vx->insert(0, 0);
  vx->insert(1, 1);
  vx->insert(2, 2);
  vx->insert(3, 4);
23

24
  shared_ptr<XdmfArray> vy = XdmfArray::New();
25
  vy->initialize<unsigned int>(3);
26 27 28
  vy->insert(0, 0);
  vy->insert(1, 1);
  vy->insert(2, 3);
29

30
  shared_ptr<XdmfArray> vz = XdmfArray::New();
31
  vz->initialize<unsigned int>(3);
32 33 34
  vz->insert(0, 0);
  vz->insert(1, 1);
  vz->insert(2, 3);
35

36 37 38
  shared_ptr<XdmfRectilinearGrid> grid = XdmfRectilinearGrid::New(vx,
                                                                  vy,
                                                                  vz);
39

Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
40 41 42 43 44
  std::cout << grid->getDimensions()->getValuesString() << " ?= 4 3 3" << std::endl;
  std::cout << vx << " ?= " << grid->getCoordinates(0) << std::endl;
  std::cout << vy << " ?= " << grid->getCoordinates(1) << std::endl;
  std::cout << vz << " ?= " << grid->getCoordinates(2) << std::endl;

45
  assert(grid->getDimensions()->getValuesString().compare("4 3 3") == 0);
46 47 48
  assert(vx == grid->getCoordinates(0));
  assert(vy == grid->getCoordinates(1));
  assert(vz == grid->getCoordinates(2));
49

50
  // Check values under the hood
51
  shared_ptr<const XdmfTopology> topology = grid->getTopology();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
52
  std::cout << topology->getNumberElements() << " ?= " << 12 << std::endl;
53
  assert(topology->getNumberElements() == 12);
54
  shared_ptr<const XdmfTopologyType> topologyType = topology->getType();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
55
  std::cout << topologyType->getNodesPerElement() << " ?= " << 8 << std::endl;
56
  assert(topologyType->getNodesPerElement() == 8);
57

58
  shared_ptr<const XdmfGeometry> geometry = grid->getGeometry();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
59
  std::cout << geometry->getNumberPoints() << " ?= " << 36 << std::endl;
60
  assert(geometry->getNumberPoints() == 36);
61
  shared_ptr<const XdmfGeometryType> geometryType = geometry->getType();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
62
  std::cout << geometryType->getDimensions() << " ?= " << 3 << std::endl;
63
  assert(geometryType->getDimensions() == 3);
64

65
  // Input / Output
66

67
  shared_ptr<XdmfWriter> writer =
68 69
    XdmfWriter::New("TestXdmfRectilinearGrid1.xmf");
  grid->accept(writer);
70

71 72 73
  shared_ptr<XdmfReader> reader = XdmfReader::New();
  shared_ptr<XdmfRectilinearGrid> grid2 = 
    shared_dynamic_cast<XdmfRectilinearGrid>
74
    (reader->read("TestXdmfRectilinearGrid1.xmf"));
75

76
  shared_ptr<XdmfWriter> writer2 =
77 78
    XdmfWriter::New("TestXdmfRectilinearGrid2.xmf");
  grid2->accept(writer2);
79

Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
80 81 82 83 84 85 86 87 88 89
  if (XdmfTestCompareFiles::compareFiles("TestXdmfRectilinearGrid1.xmf",
                                            "TestXdmfRectilinearGrid2.xmf"))
  {
    std::cout << "compared files are equal" << std::endl;
  }
  else
  {
    std::cout << "compared files are not equal" << std::endl;
  }

90 91
  assert(XdmfTestCompareFiles::compareFiles("TestXdmfRectilinearGrid1.xmf",
                                            "TestXdmfRectilinearGrid2.xmf"));
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  // Testing 1d meshes

  shared_ptr<XdmfArray> dim1d = XdmfArray::New();
  dim1d->pushBack(4);
  dim1d->pushBack(5);
  dim1d->pushBack(6);
  dim1d->pushBack(7);

  std::vector<shared_ptr<XdmfArray> > dimvector;
  dimvector.push_back(dim1d);

  shared_ptr<XdmfRectilinearGrid> grid3 = XdmfRectilinearGrid::New(dimvector);

  shared_ptr<XdmfWriter> writer3 =
    XdmfWriter::New("TestXdmfRectilinearGrid3.xmf");

  grid3->accept(writer3);

  shared_ptr<XdmfRectilinearGrid> readgrid =
    shared_dynamic_cast<XdmfRectilinearGrid>(reader->read("TestXdmfRectilinearGrid3.xmf"));

114
  return 0;
115
}