TestXdmfReader.cpp 1.66 KB
Newer Older
1
#include "XdmfDomain.hpp"
2 3 4
#include "XdmfReader.hpp"
#include "XdmfWriter.hpp"

5
#include "XdmfTestCompareFiles.hpp"
6 7
#include "XdmfTestDataGenerator.hpp"

8
int main(int, char **)
9
{
10
  shared_ptr<XdmfWriter> writer = XdmfWriter::New("TestXdmfReader1.xmf");
11 12
  writer->setLightDataLimit(10);

13
  shared_ptr<XdmfUnstructuredGrid> grid1 =
14
    XdmfTestDataGenerator::createHexahedron();
15
  shared_ptr<XdmfUnstructuredGrid> grid2 =
16 17
    XdmfTestDataGenerator::createHexahedron();

18
  shared_ptr<XdmfDomain> domain = XdmfDomain::New();
19 20 21 22
  domain->insert(grid1);
  domain->insert(grid2);
  domain->accept(writer);

23 24 25
  shared_ptr<XdmfReader> reader = XdmfReader::New();
  shared_ptr<XdmfDomain> readDomain =
    shared_dynamic_cast<XdmfDomain>(reader->read("TestXdmfReader1.xmf"));
26

27
  shared_ptr<XdmfWriter> writer2 = XdmfWriter::New("TestXdmfReader2.xmf");
28 29 30 31 32 33
  writer2->setMode(XdmfWriter::DistributedHeavyData);
  readDomain->accept(writer2);

  assert(XdmfTestCompareFiles::compareFiles("TestXdmfReader1.xmf",
                                            "TestXdmfReader2.xmf"));

34
  std::vector<shared_ptr<XdmfItem> > readItems =
35 36
    reader->read("TestXdmfReader1.xmf", "/Xdmf/Domain/Grid[1]");
  assert(readItems.size() == 1);
37 38
  shared_ptr<XdmfUnstructuredGrid> readGrid =
    shared_dynamic_cast<XdmfUnstructuredGrid>(readItems[0]);
39 40
  assert(readGrid->getName().compare("Hexahedron") == 0);

41
  std::vector<shared_ptr<XdmfItem> > readItems2 =
42
    reader->read("TestXdmfReader1.xmf", "//Attribute");
Kenneth Leiter's avatar
Kenneth Leiter committed
43
  assert(readItems2.size() == 6);
44 45
  shared_ptr<XdmfAttribute> readAttribute =
    shared_dynamic_cast<XdmfAttribute>(readItems2[0]);
Kenneth Leiter's avatar
Kenneth Leiter committed
46
  assert(readAttribute->getName().compare("Nodal Attribute") == 0);
47

48
  return 0;
49
}