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

fixed test errors and added new version of XdmfError

parent 0b37c6e9
......@@ -91,7 +91,6 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
#include <XdmfDomain.hpp>
#include <XdmfGeometry.hpp>
#include <XdmfGeometryType.hpp>
#include <XdmfGraph.hpp>
#include <XdmfGrid.hpp>
#include <XdmfGridCollection.hpp>
#include <XdmfGridCollectionType.hpp>
......@@ -227,10 +226,15 @@ swig -v -c++ -python -o XdmfPython.cpp Xdmf.i
%include std_set.i
%include std_map.i
%include std_vector.i
#ifdef XDMF_BUILD_DSM
%include mpi4py/mpi4py.i
%mpi4py_typemap(Comm, MPI_Comm);
#endif
%template(XdmfMapNodeIdSet) std::set<int>;
%template(XdmfMapNodeIdMap) std::map<int, std::set<int> >;
%template(XdmfMapMap) std::map<int, std::map<int, std::set<int> > >;
......
......@@ -94,9 +94,14 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
mName = name->second;
}
else {
XdmfError::message(XdmfError::FATAL,
"'Name' not found in itemProperties in "
"XdmfAttribute::populateItem");
try {
XdmfError::message(XdmfError::FATAL,
"'Name' not found in itemProperties in "
"XdmfAttribute::populateItem");
}
catch (XdmfError e) {
throw e;
}
}
mCenter = XdmfAttributeCenter::New(itemProperties);
......
......@@ -81,9 +81,14 @@ XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperti
std::map<std::string, std::string>::const_iterator center =
itemProperties.find("Center");
if(center == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"'Center' not found in itemProperties in "
"XdmfAttributeCenter::New");
try {
XdmfError::message(XdmfError::FATAL,
"'Center' not found in itemProperties in "
"XdmfAttributeCenter::New");
}
catch (XdmfError e) {
throw e;
}
}
const std::string & centerVal = center->second;
......@@ -103,9 +108,14 @@ XdmfAttributeCenter::New(const std::map<std::string, std::string> & itemProperti
return Edge();
}
XdmfError::message(XdmfError::FATAL,
"Center not of 'Grid','Cell','Face','Edge','Node' "
"in XdmfAttributeCenter::New");
try {
XdmfError::message(XdmfError::FATAL,
"Center not of 'Grid','Cell','Face','Edge','Node' "
"in XdmfAttributeCenter::New");
}
catch (XdmfError e) {
throw e;
}
return shared_ptr<const XdmfAttributeCenter>();
}
......
......@@ -100,9 +100,14 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties
type = itemProperties.find("AttributeType");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'AttributeType' found in "
"itemProperties in XdmfAttributeType::New");
try {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'AttributeType' found in "
"itemProperties in XdmfAttributeType::New");
}
catch (XdmfError e) {
throw e;
}
}
const std::string & typeVal = type->second;
......@@ -128,10 +133,15 @@ XdmfAttributeType::New(const std::map<std::string, std::string> & itemProperties
return NoAttributeType();
}
XdmfError::message(XdmfError::FATAL,
"Type not of 'None','Scalar','Vector','Tensor', "
"'Matrix','Tensor6', or 'GlobalId' in "
"XdmfAttributeType::New");
try {
XdmfError::message(XdmfError::FATAL,
"Type not of 'None','Scalar','Vector','Tensor', "
"'Matrix','Tensor6', or 'GlobalId' in "
"XdmfAttributeType::New");
}
catch (XdmfError e) {
throw e;
}
return shared_ptr<const XdmfAttributeType>();
}
......
......@@ -44,9 +44,14 @@ public:
static shared_ptr<XdmfTopologyCurvilinear>
New(const XdmfCurvilinearGrid * const curvilinearGrid)
{
shared_ptr<XdmfTopologyCurvilinear>
p(new XdmfTopologyCurvilinear(curvilinearGrid));
return p;
try {
shared_ptr<XdmfTopologyCurvilinear>
p(new XdmfTopologyCurvilinear(curvilinearGrid));
return p;
}
catch (XdmfError e) {
throw e;
}
}
unsigned int
......@@ -69,7 +74,12 @@ public:
XdmfTopologyCurvilinear(const XdmfCurvilinearGrid * const curvilinearGrid) :
mCurvilinearGrid(curvilinearGrid)
{
this->setType(XdmfTopologyTypeCurvilinear::New(curvilinearGrid));
try {
this->setType(XdmfTopologyTypeCurvilinear::New(curvilinearGrid));
}
catch (XdmfError e) {
throw e;
}
}
const XdmfCurvilinearGrid * const mCurvilinearGrid;
......@@ -100,9 +110,14 @@ public:
return 12;
}
else {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getEdgesPerElement");
try {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getEdgesPerElement");
}
catch (XdmfError e) {
throw e;
}
}
return 0;
}
......@@ -119,9 +134,14 @@ public:
return 6;
}
else {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getFacesPerElement");
try {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getFacesPerElement");
}
catch (XdmfError e) {
throw e;
}
}
return 0;
}
......@@ -147,9 +167,14 @@ public:
collectedProperties["Type"] = "2DSMesh";
}
else {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getProperties");
try {
XdmfError::message(XdmfError::FATAL,
"Grid dimensions not 2 or 3 in "
"XdmfTopologyTypeCurvilinear::getProperties");
}
catch (XdmfError e) {
throw e;
}
}
collectedProperties["Dimensions"] = dimensions->getValuesString();
}
......
......@@ -23,6 +23,7 @@
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
#include "XdmfError.hpp"
shared_ptr<XdmfGeometry> XdmfGeometry::New()
{
......@@ -45,9 +46,14 @@ const std::string XdmfGeometry::ItemTag = "Geometry";
std::map<std::string, std::string>
XdmfGeometry::getItemProperties() const
{
std::map<std::string, std::string> geometryProperties;
mType->getProperties(geometryProperties);
return geometryProperties;
try {
std::map<std::string, std::string> geometryProperties;
mType->getProperties(geometryProperties);
return geometryProperties;
}
catch (XdmfError e) {
throw e;
}
}
std::string
......
......@@ -67,9 +67,14 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
type = itemProperties.find("GeometryType");
}
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties "
"in XdmfGeometryType::New");
try {
XdmfError::message(XdmfError::FATAL,
"Neither 'Type' nor 'GeometryType' in itemProperties "
"in XdmfGeometryType::New");
}
catch (XdmfError e) {
throw e;
}
}
const std::string & typeVal = type->second;
......@@ -83,8 +88,13 @@ XdmfGeometryType::New(const std::map<std::string, std::string> & itemProperties)
return XY();
}
XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
"in XdmfGeometryType::New");
try {
XdmfError::message(XdmfError::FATAL, "Type not 'None', 'XYZ', or 'XY' "
"in XdmfGeometryType::New");
}
catch (XdmfError e) {
throw e;
}
return shared_ptr<const XdmfGeometryType>();
}
......
......@@ -65,9 +65,14 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("CollectionType");
if(type == itemProperties.end()) {
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
try {
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not in itemProperties in "
"XdmfGridCollectionType::New");
}
catch (XdmfError e) {
throw e;
}
}
const std::string & typeVal = type->second;
......@@ -81,9 +86,14 @@ XdmfGridCollectionType::New(const std::map<std::string, std::string> & itemPrope
return Temporal();
}
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not of 'None', 'Spatial', or "
"'Temporal' in XdmfGridCollectionType::New");
try {
XdmfError::message(XdmfError::FATAL,
"'CollectionType' not of 'None', 'Spatial', or "
"'Temporal' in XdmfGridCollectionType::New");
}
catch (XdmfError e) {
throw e;
}
return shared_ptr<const XdmfGridCollectionType>();
}
......
......@@ -40,6 +40,7 @@
#include "XdmfTime.hpp"
#include "XdmfTopology.hpp"
#include "XdmfUnstructuredGrid.hpp"
#include "XdmfError.hpp"
shared_ptr<XdmfItemFactory>
XdmfItemFactory::New()
......@@ -61,169 +62,174 @@ XdmfItemFactory::createItem(const std::string & itemTag,
const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems) const
{
shared_ptr<XdmfItem> newItem =
XdmfCoreItemFactory::createItem(itemTag, itemProperties, childItems);
try {
shared_ptr<XdmfItem> newItem =
XdmfCoreItemFactory::createItem(itemTag, itemProperties, childItems);
if(newItem) {
return newItem;
}
if(newItem) {
return newItem;
}
if(itemTag.compare(XdmfAttribute::ItemTag) == 0) {
return XdmfAttribute::New();
}
else if(itemTag.compare(XdmfDomain::ItemTag) == 0) {
return XdmfDomain::New();
}
else if(itemTag.compare(XdmfGeometry::ItemTag) == 0) {
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("Type");
if(type == itemProperties.end()) {
type = itemProperties.find("GeometryType");
if(itemTag.compare(XdmfAttribute::ItemTag) == 0) {
return XdmfAttribute::New();
}
else if(itemTag.compare(XdmfDomain::ItemTag) == 0) {
return XdmfDomain::New();
}
else if(itemTag.compare(XdmfGeometry::ItemTag) == 0) {
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("Type");
if(type == itemProperties.end()) {
type = itemProperties.find("GeometryType");
}
if(type != itemProperties.end()) {
const std::string & typeVal = type->second;
if(typeVal.compare("ORIGIN_DXDY") == 0 ||
typeVal.compare("ORIGIN_DXDYDZ") == 0) {
shared_ptr<XdmfArray> origin = shared_ptr<XdmfArray>();
shared_ptr<XdmfArray> brickSize = shared_ptr<XdmfArray>();
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array =
shared_dynamic_cast<XdmfArray>(*iter)) {
if(!origin) {
origin = array;
}
else if(!brickSize) {
brickSize = array;
break;
if(type != itemProperties.end()) {
const std::string & typeVal = type->second;
if(typeVal.compare("ORIGIN_DXDY") == 0 ||
typeVal.compare("ORIGIN_DXDYDZ") == 0) {
shared_ptr<XdmfArray> origin = shared_ptr<XdmfArray>();
shared_ptr<XdmfArray> brickSize = shared_ptr<XdmfArray>();
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array =
shared_dynamic_cast<XdmfArray>(*iter)) {
if(!origin) {
origin = array;
}
else if(!brickSize) {
brickSize = array;
break;
}
}
}
if(origin && brickSize) {
return XdmfRegularGrid::New(brickSize,
shared_ptr<XdmfArray>(),
origin);
}
return shared_ptr<XdmfItem>();
}
if(origin && brickSize) {
return XdmfRegularGrid::New(brickSize,
shared_ptr<XdmfArray>(),
origin);
else if(typeVal.compare("VXVY") == 0 ||
typeVal.compare("VXVYVZ") == 0) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array =
shared_dynamic_cast<XdmfArray>(*iter)) {
coordinateValues.push_back(array);
}
}
return XdmfRectilinearGrid::New(coordinateValues);
}
return shared_ptr<XdmfItem>();
}
else if(typeVal.compare("VXVY") == 0 ||
typeVal.compare("VXVYVZ") == 0) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
return XdmfGeometry::New();
}
else if(itemTag.compare(XdmfGraph::ItemTag) == 0) {
return XdmfGraph::New(0);
}
else if(itemTag.compare(XdmfGrid::ItemTag) == 0) {
// For backwards compatibility with the old format, this tag can
// correspond to multiple XdmfItems.
std::map<std::string, std::string>::const_iterator gridType =
itemProperties.find("GridType");
if(gridType != itemProperties.end() &&
gridType->second.compare("Collection") == 0) {
return XdmfGridCollection::New();
}
else {
// Find out what kind of grid we have
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfArray> array =
shared_dynamic_cast<XdmfArray>(*iter)) {
coordinateValues.push_back(array);
if(shared_ptr<XdmfCurvilinearGrid> curvilinear =
shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
return XdmfCurvilinearGrid::New(0, 0);
}
else if(shared_ptr<XdmfRegularGrid> regularGrid =
shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
return XdmfRegularGrid::New(0, 0, 0, 0, 0, 0);
}
else if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
return XdmfRectilinearGrid::New(coordinateValues);
}
}
return XdmfRectilinearGrid::New(coordinateValues);
return XdmfUnstructuredGrid::New();
}
}
return XdmfGeometry::New();
}
else if(itemTag.compare(XdmfGraph::ItemTag) == 0) {
return XdmfGraph::New(0);
}
else if(itemTag.compare(XdmfGrid::ItemTag) == 0) {
// For backwards compatibility with the old format, this tag can
// correspond to multiple XdmfItems.
std::map<std::string, std::string>::const_iterator gridType =
itemProperties.find("GridType");
if(gridType != itemProperties.end() &&
gridType->second.compare("Collection") == 0) {
return XdmfGridCollection::New();
else if(itemTag.compare(XdmfInformation::ItemTag) == 0) {
return XdmfInformation::New();
}
else {
// Find out what kind of grid we have
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
if(shared_ptr<XdmfCurvilinearGrid> curvilinear =
shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
return XdmfCurvilinearGrid::New(0, 0);
}
else if(shared_ptr<XdmfRegularGrid> regularGrid =
shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
return XdmfRegularGrid::New(0, 0, 0, 0, 0, 0);
}
else if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
return XdmfRectilinearGrid::New(coordinateValues);
}
}
return XdmfUnstructuredGrid::New();
else if(itemTag.compare(XdmfMap::ItemTag) == 0) {
return XdmfMap::New();
}
}
else if(itemTag.compare(XdmfInformation::ItemTag) == 0) {
return XdmfInformation::New();
}
else if(itemTag.compare(XdmfMap::ItemTag) == 0) {
return XdmfMap::New();
}
else if(itemTag.compare(XdmfSet::ItemTag) == 0) {
return XdmfSet::New();
}
else if(itemTag.compare(XdmfSparseMatrix::ItemTag) == 0) {
return XdmfSparseMatrix::New(0, 0);
}
else if(itemTag.compare(XdmfTime::ItemTag) == 0) {
return XdmfTime::New();
}
else if(itemTag.compare(XdmfTopology::ItemTag) == 0) {
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("Type");
if(type == itemProperties.end()) {
type = itemProperties.find("TopologyType");
else if(itemTag.compare(XdmfSet::ItemTag) == 0) {
return XdmfSet::New();
}
else if(itemTag.compare(XdmfSparseMatrix::ItemTag) == 0) {
return XdmfSparseMatrix::New(0, 0);
}
else if(itemTag.compare(XdmfTime::ItemTag) == 0) {
return XdmfTime::New();
}
else if(itemTag.compare(XdmfTopology::ItemTag) == 0) {
std::map<std::string, std::string>::const_iterator type =
itemProperties.find("Type");
if(type == itemProperties.end()) {
type = itemProperties.find("TopologyType");
}
if(type != itemProperties.end()) {
std::string typeVal = type->second;
std::transform(typeVal.begin(),
typeVal.end(),
typeVal.begin(),
(int(*)(int))toupper);
if(typeVal.compare("2DCORECTMESH") == 0 ||
typeVal.compare("3DCORECTMESH") == 0 ||
typeVal.compare("2DSMESH") == 0 ||
typeVal.compare("3DSMESH") == 0) {
shared_ptr<XdmfArray> dimensionsArray = XdmfArray::New();
std::string dimensionsString = "";
std::map<std::string, std::string>::const_iterator dimensions =
itemProperties.find("Dimensions");
if(dimensions != itemProperties.end()) {
dimensionsString = dimensions->second;
}
boost::tokenizer<> tokens(dimensionsString);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
dimensionsArray->pushBack<unsigned int>(atoi((*iter).c_str()));
}
if(type != itemProperties.end()) {
std::string typeVal = type->second;
std::transform(typeVal.begin(),
typeVal.end(),
typeVal.begin(),
(int(*)(int))toupper);
if(typeVal.compare("2DCORECTMESH") == 0 ||
typeVal.compare("3DCORECTMESH") == 0) {
return XdmfRegularGrid::New(shared_ptr<XdmfArray>(),
dimensionsArray,
shared_ptr<XdmfArray>());
typeVal.compare("3DCORECTMESH") == 0 ||
typeVal.compare("2DSMESH") == 0 ||
typeVal.compare("3DSMESH") == 0) {
shared_ptr<XdmfArray> dimensionsArray = XdmfArray::New();
std::string dimensionsString = "";
std::map<std::string, std::string>::const_iterator dimensions =
itemProperties.find("Dimensions");
if(dimensions != itemProperties.end()) {
dimensionsString = dimensions->second;
}
boost::tokenizer<> tokens(dimensionsString);
for(boost::tokenizer<>::const_iterator iter = tokens.begin();
iter != tokens.end();
++iter) {
dimensionsArray->pushBack<unsigned int>(atoi((*iter).c_str()));
}
if(typeVal.compare("2DCORECTMESH") == 0 ||
typeVal.compare("3DCORECTMESH") == 0) {
return XdmfRegularGrid::New(shared_ptr<XdmfArray>(),
dimensionsArray,
shared_ptr<XdmfArray>());
}
else {
return XdmfCurvilinearGrid::New(dimensionsArray);
}
}
else {
return XdmfCurvilinearGrid::New(dimensionsArray);
else if(typeVal.compare("2DRECTMESH") == 0 ||
typeVal.compare("3DRECTMESH") == 0) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
return XdmfRectilinearGrid::New(coordinateValues);
}
}
else if(typeVal.compare("2DRECTMESH") == 0 ||
typeVal.compare("3DRECTMESH") == 0) {
std::vector<shared_ptr<XdmfArray> > coordinateValues;
return XdmfRectilinearGrid::New(coordinateValues);
}
}
return XdmfTopology::New();
}
return XdmfTopology::New();
return shared_ptr<XdmfItem>();
}
catch (XdmfError e) {
throw e;
}
return shared_ptr<XdmfItem>();
}
......@@ -168,15 +168,25 @@ XdmfMap::populateItem(const std::map<std::string, std::string> & itemProperties,
if(arrayVector.size() != 0) {