TestXdmfTopologyMixed.cpp 2.41 KB
Newer Older
1 2 3 4 5 6 7 8
#include "XdmfDomain.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfReader.hpp"
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
#include "XdmfUnstructuredGrid.hpp"
#include "XdmfWriter.hpp"
9
#include <iostream>
10
#include <assert.h>
11 12 13

#include "XdmfTestCompareFiles.hpp"

14
int main(int, char **)
15 16 17 18
{

  //
  // Create a unstructured grid consisting of a quadrilateral element
19
  // and a polyline element connected to each other by a single node at
20
  // the corner of each.
21 22
  //
  shared_ptr<XdmfUnstructuredGrid> grid = XdmfUnstructuredGrid::New();
23 24 25
  grid->setName("Mixed");

  // Set Geometry
26
  double points[] = {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 2.0, 2.0, 3.0,
27 28 29
                     1.0, 4.0, 2.0, 5.0, 1.0, 6.0, 2.0};
  grid->getGeometry()->setType(XdmfGeometryType::XY());
  grid->getGeometry()->insert(0, &points[0], 18);
30

31
  // Set Topology
32
  shared_ptr<XdmfTopology> topology = grid->getTopology();
33 34 35 36 37 38
  topology->setType(XdmfTopologyType::Mixed());
  topology->pushBack(XdmfTopologyType::Quadrilateral()->getID());
  topology->pushBack(0);
  topology->pushBack(1);
  topology->pushBack(2);
  topology->pushBack(3);
39
  topology->pushBack(XdmfTopologyType::Polyline(0)->getID());
40 41 42 43 44 45 46 47
  topology->pushBack(6);
  topology->pushBack(2);
  topology->pushBack(4);
  topology->pushBack(5);
  topology->pushBack(6);
  topology->pushBack(7);
  topology->pushBack(8);

48 49
  std::cout << topology->getNumberElements() << " ?= " << 2 << std::endl;

50 51
  assert(topology->getNumberElements() == 2);

52
  shared_ptr<XdmfDomain> domain = XdmfDomain::New();
53 54
  domain->insert(grid);

55
  shared_ptr<XdmfWriter> writer =
56 57 58
    XdmfWriter::New("TestXdmfTopologyMixed1.xmf");
  domain->accept(writer);

59 60 61
  shared_ptr<XdmfReader> reader = XdmfReader::New();
  shared_ptr<XdmfDomain> readDomain =
    shared_dynamic_cast<XdmfDomain>
62 63
    (reader->read("TestXdmfTopologyMixed1.xmf"));

64
  shared_ptr<XdmfWriter> writer2 =
65 66 67
    XdmfWriter::New("TestXdmfTopologyMixed2.xmf");
  readDomain->accept(writer2);

68 69 70 71 72 73 74 75 76 77
  if (XdmfTestCompareFiles::compareFiles("TestXdmfTopologyMixed1.xmf",
                                         "TestXdmfTopologyMixed2.xmf"))
  {
    std::cout << "compared files are the same" << std::endl;
  }
  else
  {
    std::cout << "compared files are not the same" << std::endl;
  }

78 79 80 81 82
  assert(XdmfTestCompareFiles::compareFiles("TestXdmfTopologyMixed1.xmf",
                                            "TestXdmfTopologyMixed2.xmf"));

  return 0;
}