TestXdmfSubset.cpp 3.67 KB
Newer Older
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
1 2 3 4 5 6 7 8
#include "XdmfArray.hpp"
#include "XdmfArrayType.hpp"
#include "XdmfSubset.hpp"
#include "XdmfAttribute.hpp"
#include "XdmfWriter.hpp"
#include "XdmfReader.hpp"
#include <map>
#include <iostream>
9
#include <assert.h>
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

int main(int, char **)
{
	shared_ptr<XdmfArray> referenceArray = XdmfArray::New();

	for (unsigned int i = 0; i < 27; ++i)
	{
		referenceArray->pushBack(i);
	}

	std::vector<unsigned int> initDimensions;
	initDimensions.push_back(3);
	initDimensions.push_back(3);
	initDimensions.push_back(3);

	referenceArray->resize(initDimensions, 0);

	std::vector<unsigned int> newStarts;
	newStarts.push_back(0);
	newStarts.push_back(0);
	newStarts.push_back(0);
	std::vector<unsigned int> newStrides;
	newStrides.push_back(2);
	newStrides.push_back(2);
	newStrides.push_back(2);
	std::vector<unsigned int> newDimensions;
	newDimensions.push_back(2);
	newDimensions.push_back(2);
	newDimensions.push_back(2);

	shared_ptr<XdmfSubset> testSubset = XdmfSubset::New(referenceArray,
                                                            newStarts,
                                                            newStrides,
                                                            newDimensions);

	shared_ptr<XdmfAttribute> subsetHolder = XdmfAttribute::New();

47
	subsetHolder->setReference(testSubset);
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
48

49
	subsetHolder->setReadMode(XdmfArray::Reference);
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
50 51 52 53 54 55 56 57 58 59



	shared_ptr<XdmfWriter> subsetWriter = XdmfWriter::New("subset.xmf");

	subsetHolder->accept(subsetWriter);




60
	subsetHolder->readReference();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
61 62 63 64 65 66 67

	std::cout << subsetHolder->getValuesString() << std::endl;

	shared_ptr<XdmfReader> subsetReader = XdmfReader::New();

	shared_ptr<XdmfItem> readItem = subsetReader->read("subset.xmf");

68 69
        std::cout << readItem->getItemTag() << " ?= Attribute" << std::endl;

Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
70 71 72 73
	assert(readItem->getItemTag().compare("Attribute") == 0);

	shared_ptr<XdmfAttribute> readSubsetHolder = shared_dynamic_cast<XdmfAttribute>(readItem);

74
	readSubsetHolder->readReference();
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
75

76
	std::cout << shared_dynamic_cast<XdmfSubset>(readSubsetHolder->getReference())->getReferenceArray()->getValuesString() << std::endl;
Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
77 78 79 80 81

	std::cout << readSubsetHolder->getValuesString() << std::endl;

	assert(readSubsetHolder->getValuesString().compare(subsetHolder->getValuesString()) == 0);

82
	shared_ptr<XdmfArray> referenceArray2 = XdmfArray::New();
83

84 85 86 87
	for (unsigned int i = 10; i < 37; ++i)
	{
		referenceArray2->pushBack(i);
	}
88

89
	referenceArray2->resize(initDimensions, 0);
90 91 92

        testSubset->setReferenceArray(referenceArray2);

93
	std::string changedSubsetOutput = testSubset->read()->getValuesString();
94

95
	std::cout << "after changing reference Array: " << changedSubsetOutput << std::endl;
96

97
	assert(changedSubsetOutput.compare("10 12 16 18 28 30 34 36") == 0);
98

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130


        shared_ptr<XdmfArray> subsetHolder2 = XdmfArray::New();

        subsetHolder2->setReference(testSubset);

        subsetHolder2->setReadMode(XdmfArray::Reference);

        subsetHolder2->accept(subsetWriter);

        subsetHolder2->readReference();

        std::cout << subsetHolder2->getValuesString() << std::endl;

        readItem = subsetReader->read("subset.xmf");

        std::cout << readItem->getItemTag() << " ?= DataItem" << std::endl;

        assert(readItem->getItemTag().compare("DataItem") == 0);

        shared_ptr<XdmfArray> readSubsetHolder2 = shared_dynamic_cast<XdmfArray>(readItem);

        readSubsetHolder2->readReference();

        std::cout <<
          shared_dynamic_cast<XdmfSubset>(readSubsetHolder2->getReference())->getReferenceArray()->getValuesString() 
          << std::endl;

        std::cout << readSubsetHolder2->getValuesString() << std::endl;

        assert(readSubsetHolder2->getValuesString().compare(subsetHolder2->getValuesString()) == 0);

Andrew J. Burns (Cont's avatar
Andrew J. Burns (Cont committed
131 132
	return 0;
}