Commit 101ba7bc authored by Andrew J. Burns (Cont's avatar Andrew J. Burns (Cont

added XdmfSubset

parent 5e38d232
......@@ -34,6 +34,7 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfItemProperty.hpp>
#include <XdmfSharedPtr.hpp>
#include <XdmfSparseMatrix.hpp>
#include <XdmfSubset.hpp>
#include <XdmfSystemUtils.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
......@@ -84,6 +85,7 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfItemProperty.hpp>
#include <XdmfSharedPtr.hpp>
#include <XdmfSparseMatrix.hpp>
#include <XdmfSubset.hpp>
#include <XdmfSystemUtils.hpp>
#include <XdmfVisitor.hpp>
#include <XdmfWriter.hpp>
......
......@@ -105,6 +105,7 @@ set(XdmfCoreSources
XdmfItem
XdmfItemProperty
XdmfSparseMatrix
XdmfSubset
XdmfSystemUtils
${CMAKE_BINARY_DIR}/XdmfVersion
XdmfVisitor
......
......@@ -33,6 +33,7 @@
#include "XdmfFunction.hpp"
#include "XdmfHDF5Controller.hpp"
#include "XdmfHeavyDataController.hpp"
#include "XdmfSubset.hpp"
#include "XdmfVisitor.hpp"
#include "XdmfError.hpp"
......@@ -564,7 +565,7 @@ XdmfArray::XdmfArray() :
mArrayPointerNumValues(0),
mName(""),
mTmpReserveSize(0),
mWriteAsFunction(false),
mReadMode(XdmfArray::Controller),
mFunction(shared_ptr<XdmfFunction>())
{
}
......@@ -695,6 +696,12 @@ XdmfArray::getName() const
return mName;
}
XdmfArray::ReadMode
XdmfArray::getReadMode() const
{
return mReadMode;
}
unsigned int
XdmfArray::getSize() const
{
......@@ -702,6 +709,12 @@ XdmfArray::getSize() const
mArray);
}
shared_ptr<XdmfSubset>
XdmfArray::getSubset()
{
return mSubset;
}
void *
XdmfArray::getValuesInternal()
{
......@@ -723,12 +736,6 @@ XdmfArray::getValuesString() const
mArray);
}
bool
XdmfArray::getWriteAsFunction()
{
return mWriteAsFunction;
}
shared_ptr<XdmfHeavyDataController>
XdmfArray::getHeavyDataController()
{
......@@ -747,16 +754,6 @@ XdmfArray::getHeavyDataController() const
}
}
void
XdmfArray::setHeavyDataController(shared_ptr<XdmfHeavyDataController> newController)
{
// Since this is replacing the previous version which was designed to
// completely replace the controller of the array
// It will clear the current controllers before adding the new one in
mHeavyDataControllers.clear();
mHeavyDataControllers.push_back(newController);
}
void
XdmfArray::initialize(const shared_ptr<const XdmfArrayType> arrayType,
const unsigned int size)
......@@ -851,8 +848,8 @@ XdmfArray::insert(const std::vector<unsigned int> startIndex,
&& valuesStartIndex.size() == numValues.size()
&& numValues.size() == valuesStride.size())
&& (numInserted.size() == startIndex.size()
&& startIndex.size() == mDimensions.size()
&& mDimensions.size() == arrayStride.size())) {
&& startIndex.size() == this->getDimensions().size()
&& this->getDimensions().size() == arrayStride.size())) {
// Pull data from values
std::vector<unsigned int > dimTotalVector;
unsigned int dimTotal = 1;
......@@ -965,8 +962,8 @@ XdmfArray::insert(const std::vector<unsigned int> startIndex,
}
}
else if (!(numInserted.size() == startIndex.size()
&& startIndex.size() == mDimensions.size()
&& mDimensions.size() == arrayStride.size())) {
&& startIndex.size() == this->getDimensions().size()
&& this->getDimensions().size() == arrayStride.size())) {
try {
XdmfError::message(XdmfError::FATAL,
"Error: Number of starts, strides, and/or values "
......@@ -1181,6 +1178,31 @@ XdmfArray::populateItem(const std::map<std::string, std::string> & itemPropertie
void
XdmfArray::read()
{
switch (mReadMode)
{
case XdmfArray::Controller:
this->readController();
break;
case XdmfArray::Function:
this->readFunction();
break;
case XdmfArray::Subset:
this->readSubset();
break;
default:
try {
XdmfError::message(XdmfError::FATAL,
"Error: Invalid Read Mode");
}
catch (XdmfError e) {
throw e;
}
}
}
void
XdmfArray::readController()
{
if(mHeavyDataControllers.size() > 1) {
this->release();
......@@ -1232,6 +1254,13 @@ XdmfArray::readFunction()
this->swap(tempArray);
}
void
XdmfArray::readSubset()
{
shared_ptr<XdmfArray> tempArray = mSubset->read();
this->swap(tempArray);
}
void
XdmfArray::release()
{
......@@ -1248,6 +1277,22 @@ XdmfArray::reserve(const unsigned int size)
mArray);
}
void
XdmfArray::setFunction(shared_ptr<XdmfFunction> newFunction)
{
mFunction = newFunction;
}
void
XdmfArray::setHeavyDataController(shared_ptr<XdmfHeavyDataController> newController)
{
// Since this is replacing the previous version which was designed to
// completely replace the controller of the array
// It will clear the current controllers before adding the new one in
mHeavyDataControllers.clear();
mHeavyDataControllers.push_back(newController);
}
void
XdmfArray::setName(const std::string & name)
{
......@@ -1255,15 +1300,15 @@ XdmfArray::setName(const std::string & name)
}
void
XdmfArray::setFunction(shared_ptr<XdmfFunction> newFunction)
XdmfArray::setReadMode(XdmfArray::ReadMode newStatus)
{
mFunction = newFunction;
mReadMode = newStatus;
}
void
XdmfArray::setWriteAsFunction(bool newStatus)
XdmfArray::setSubset(shared_ptr<XdmfSubset> newSubset)
{
mWriteAsFunction = newStatus;
mSubset = newSubset;
}
void
......
......@@ -32,6 +32,7 @@ class XdmfHeavyDataController;
#include "XdmfCore.hpp"
#include "XdmfItem.hpp"
#include "XdmfFunction.hpp"
#include "XdmfSubset.hpp"
#include <boost/shared_array.hpp>
#include <boost/variant.hpp>
......@@ -100,6 +101,12 @@ class XDMFCORE_EXPORT XdmfArray : public XdmfItem {
public:
enum ReadMode {
Controller,
Function,
Subset
};
/**
* Create a new XdmfArray.
*
......@@ -343,6 +350,41 @@ public:
*/
std::string getName() const;
/**
* Gets the method this array will be written/read.
* Possible choices are: Controller, Function, and Subset
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setFunction
* @until //#setFunction
* @skipline //#setReadMode
* @until //#setReadMode
* @skipline //#getReadMode
* @until //#getReadMode
*
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setFunction
* @until #//setFunction
* @skipline #//setReadMode
* @until #//setReadMode
* @skipline #//getReadMode
* @until #//getReadMode
*
* @return What method will be used when reading/writing the array
*/
ReadMode getReadMode() const;
/**
* Get the number of values stored in this array.
*
......@@ -368,6 +410,35 @@ public:
*/
unsigned int getSize() const;
/**
* Gets the subset that the array will pull from when reading from a subset.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setSubset
* @until //#setSubset
* @skipline //#getSubset
* @until //#getSubset
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setSubset
* @until #//setSubset
* @skipline #//getSubset
* @until #//getSubset
*
* @return The subset being pulled from
*/
shared_ptr<XdmfSubset> getSubset();
/**
* Get a copy of a single value stored in this array.
*
......@@ -533,40 +604,6 @@ public:
*/
std::string getValuesString() const;
/**
* Gets if this array will be written as a function when written to file.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setFunction
* @until //#setFunction
* @skipline //#setWriteAsFunction
* @until //#setWriteAsFunction
* @skipline //#getWriteAsFunction
* @until //#getWriteAsFunction
*
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setFunction
* @until #//setFunction
* @skipline #//setWriteAsFunction
* @until #//setWriteAsFunction
* @skipline #//getWriteAsFunction
* @until #//getWriteAsFunction
*
* @return Whether the array will be written as a function
*/
bool getWriteAsFunction();
/**
* Initialize the array to a specific size.
*
......@@ -983,6 +1020,37 @@ public:
*/
void read();
/**
* Reads data from the attached controllers to the internal data storage.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#getHeavyDataController
* @until //#getHeavyDataController
* @skipline //#setHeavyDataController
* @until //#setHeavyDataController
* @skipline //#readController
* @until //#readController
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//getHeavyDataController
* @until #//getHeavyDataController
* @skipline #//setHeavyDataController
* @until #//setHeavyDataController
* @skipline #//readController
* @until #//readController
*/
void readController();
/**
* Accumulates the data via the function associated with the array and
* swaps the data with the data currently in the array.
......@@ -1012,6 +1080,33 @@ public:
*/
void readFunction();
/**
* Reads the data pointed to by the subset into the array.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setSubset
* @until //#setSubset
* @skipline //#readSubset
* @until //#readSubset
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setSubset
* @until #//setSubset
* @skipline #//readSubset
* @until #//readSubset
*/
void readSubset();
/**
* Release all data currently held in memory.
*
......@@ -1186,6 +1281,62 @@ public:
*/
void setName(const std::string & name);
/**
* Sets the method this array will be written/read.
* Possible choices are: Controller, Function, and Subset
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setFunction
* @until //#setFunction
* @skipline //#setReadMode
* @until //#setReadMode
*
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setFunction
* @until #//setFunction
* @skipline #//setReadMode
* @until #//setReadMode
*
* @param newStatus The method that the array will be read/written
*/
void setReadMode(ReadMode newStatus = XdmfArray::Controller);
/**
* Sets the subset that the array will pull from when reading from a subset.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setSubset
* @until //#setSubset
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setSubset
* @until #//setSubset
*
* @param newSubset The subset to pull data from on read
*/
void setSubset(shared_ptr<XdmfSubset> newSubset);
/**
* Sets the values of this array to the values stored in the
* arrayPointer array. No copy is made. Modifications to the array
......@@ -1280,36 +1431,6 @@ public:
template<typename T>
void setValuesInternal(const shared_ptr<std::vector<T> > array);
/**
* Sets whether the array will be written as a function when written to file.
*
* Example of use:
*
* C++
*
* @dontinclude ExampleXdmfArray.cpp
* @skipline //#initialization
* @until //#initialization
* @skipline //#setFunction
* @until //#setFunction
* @skipline //#setWriteAsFunction
* @until //#setWriteAsFunction
*
*
* Python
*
* @dontinclude XdmfExampleArray.py
* @skipline #//initialization
* @until #//initialization
* @skipline #//setFunction
* @until #//setFunction
* @skipline #//setWriteAsFunction
* @until #//setWriteAsFunction
*
* @param newStatus Whether the array will be set to be written as a function
*/
void setWriteAsFunction(bool newStatus = false);
/**
* Exchange the contents of the vector with the contents of this
* array. No copy is made. The internal arrays are swapped.
......@@ -1458,8 +1579,9 @@ private:
std::vector<unsigned int> mDimensions;
std::string mName;
unsigned int mTmpReserveSize;
bool mWriteAsFunction;
ReadMode mReadMode;
shared_ptr<XdmfFunction> mFunction;
shared_ptr<XdmfSubset> mSubset;
};
......
......@@ -718,6 +718,8 @@ XdmfArray::resize(const unsigned int numValues,
numValues,
value),
mArray);
std::vector<unsigned int> newDimensions;
newDimensions.push_back(numValues);
}
template<typename T>
......
......@@ -32,6 +32,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#include <XdmfItemProperty.hpp>
#include <XdmfSharedPtr.hpp>
#include <XdmfSparseMatrix.hpp>
#include <XdmfSubset.hpp>
#include <XdmfSystemUtils.hpp>
#include <XdmfVersion.hpp>
#include <XdmfVisitor.hpp>
......@@ -61,6 +62,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#include <XdmfItemProperty.hpp>
#include <XdmfSharedPtr.hpp>
#include <XdmfSparseMatrix.hpp>
#include <XdmfSubset.hpp>
#include <XdmfSystemUtils.hpp>
#include <XdmfVersion.hpp>
#include <XdmfVisitor.hpp>
......@@ -166,6 +168,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
#ifdef SWIGPYTHON
/*This converts XdmfErrors to Python RuntimeErrors*/
%exception
{
try
......@@ -350,6 +353,8 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
/*trying to transfer python functions*/
/*note, accessing private members is impossible from swig.*/
/*class to wrap python functions to be compatible with the XdmfFunction code*/
class PythonFunction : public XdmfFunction::XdmfFunctionInternal {
public:
static shared_ptr<PythonFunction>
......@@ -393,6 +398,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
PyObject * mInternalFunction;
};
/*class to wrap python functions to be compatible with the XdmfFunction Operation code*/
class PythonOperation : public XdmfFunction::XdmfOperationInternal {
public:
static shared_ptr<PythonOperation>
......@@ -490,6 +496,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%shared_ptr(XdmfItem)
%shared_ptr(XdmfItemProperty)
%shared_ptr(XdmfSparseMatrix)
%shared_ptr(XdmfSubset)
%shared_ptr(XdmfVisitor)
%shared_ptr(XdmfWriter)
......@@ -510,6 +517,7 @@ swig -v -c++ -python -o XdmfCorePython.cpp XdmfCore.i
%include XdmfFunction.hpp
%include XdmfHeavyDataController.hpp
%include XdmfHeavyDataWriter.hpp
%include XdmfSubset.hpp
%include XdmfCoreItemFactory.hpp
%include XdmfCoreReader.hpp
......
......@@ -24,6 +24,7 @@
#include "XdmfArray.hpp"
#include "XdmfCoreItemFactory.hpp"
#include "XdmfError.hpp"
#include <boost/tokenizer.hpp>
XdmfCoreItemFactory::XdmfCoreItemFactory()
{
......@@ -97,7 +98,7 @@ XdmfCoreItemFactory::createItem(const std::string & itemTag,
// The properties and children aren't really needed
// to generate the object, but the factory still requires them.
std::vector<shared_ptr<XdmfItem> > newArrayChildren;
shared_ptr<XdmfArray> returnArray = XdmfArray::New();
shared_ptr<XdmfArray> returnArray = shared_ptr<XdmfArray>();
// This should generate an item that corresponds to the tag provided
// the casting ensures that it is a subtype of array
......@@ -110,13 +111,85 @@ XdmfCoreItemFactory::createItem(const std::string & itemTag,
returnArray->insert(0, parsedArray, 0, parsedArray->getSize());
returnArray->setFunction(XdmfFunction::New(expressionToParse,
variableCollection));
returnArray->setReadMode(XdmfArray::Function);
return returnArray;
}
else {
parsedArray->setFunction(XdmfFunction::New(expressionToParse,
variableCollection));
parsedArray->setReadMode(XdmfArray::Function);
return parsedArray;
}
}
else if(itemTag.compare(XdmfSubset::ItemTag) == 0) {
//TODO
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("ConstructedType");
std::string arraySubType;
if(type == itemProperties.end()) {
// If no type is specified an array is generated
arraySubType = XdmfArray::ItemTag;
}
else {
arraySubType = type->second;
}
std::vector<shared_ptr<XdmfItem> > newArrayChildren;
shared_ptr<XdmfArray> returnArray = shared_ptr<XdmfArray>();
returnArray = shared_dynamic_cast<XdmfArray>(createItem(
arraySubType,
itemProperties,
newArrayChildren));
std::vector<unsigned int> startVector;
std::vector<unsigned int> strideVector;
std::vector<unsigned int> dimensionVector;
shared_ptr<XdmfArray> referenceArray;
std::map<std::string, std::string>::const_iterator starts =
itemProperties.find("SubsetStarts");
boost::tokenizer<> tokens(starts->second);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
startVector.push_back(atoi((*iter).c_str()));
}
std::map<std::string, std::string>::const_iterator strides =
itemProperties.find("SubsetStrides");
boost::tokenizer<> stridetokens(strides->second);
for(boost::tokenizer<>::const_iterator iter = stridetokens.begin();
iter != stridetokens.end();
++iter) {
strideVector.push_back(atoi((*iter).c_str()));
}
std::map<std::string, std::string>::const_iterator dimensions =
itemProperties.find("SubsetDimensions");
boost::tokenizer<> dimtokens(dimensions->second);
for(boost::tokenizer<>::const_iterator iter = dimtokens.begin();
iter != dimtokens.end();
++iter) {
dimensionVector.push_back(atoi((*iter).c_str()));
}
referenceArray = shared_dynamic_cast<XdmfArray>(childItems[0]);
shared_ptr<XdmfSubset> newSubset = XdmfSubset::New(referenceArray,
startVector,
strideVector,
dimensionVector);
returnArray->setSubset(newSubset);
returnArray->setReadMode(XdmfArray::Subset);
return returnArray;
}
return shared_ptr<XdmfItem>();
}
......@@ -66,7 +66,7 @@
#include "H5FDpublic.h"
#ifndef H5_HAVE_PARALLEL
#pragma Error : The H5FDdsm virtual File Driver for HDF5 can only be compiled against an HDF5 library with parallel IO support
#pragma Error : The XdmfDSM virtual File Driver for HDF5 can only be compiled against an HDF5 library with parallel IO support
#endif
#define XDMF_DSM_NOTIFY_NONE 0x0000
......
......@@ -115,7 +115,8 @@ public:
static const std::string ItemTag;
/*
* Adds a specified function to the list of functions used while evaluating strings
* Adds a specified function to the list of functions used while
* evaluating strings
*
* Example of Use:
*
......@@ -149,11 +150,13 @@ public:
* with the given string
* @return The total number of functions currently usable
*/
static int addFunction(std::string name,
shared_ptr<XdmfArray>(*functionref)(std::vector<shared_ptr<XdmfArray> >));
static int
addFunction(std::string name,
shared_ptr<XdmfArray>(*functionref)(std::vector<shared_ptr<XdmfArray> >));
/**
* Adds a specified function to the list of functions used while evaluating strings.
* Adds a specified function to the list of functions used while
* evaluating strings.
* This version allows for custom wrapping.
*
* Example of use:
......@@ -178,8 +181,9 @@ public:
* associated with the given string
* @return The total number of functions currently usable
*/
static int addFunction(std::string name,
shared_ptr<XdmfFunctionInternal> newFunction);
static int
addFunction(std::string name,
shared_ptr<XdmfFunctionInternal> newFunction);
/**
* Adds an operation to the list of viable operators.
......@@ -218,10 +222,11 @@ public:
* the higher the value the earlier it is evaluated
* @return The number of viable operations
*/
static int addOperation(char newoperator,
shared_ptr<XdmfArray>(*functionref)(shared_ptr<XdmfArray>,
shared_ptr<XdmfArray>),
int priority);
static int
addOperation(char newoperator,
shared_ptr<XdmfArray>(*functionref)(shared_ptr<XdmfArray>,
shared_ptr<XdmfArray>),
int priority);
/**
* Adds an operation to the list of viable operators.
......@@ -251,9 +256,10 @@ public:
* the higher the value the earlier it is evaluated
* @return The number of viable operations
*/