Commit 75334303 authored by Michal Habera's avatar Michal Habera

Make ItemType, ElementFamily and ElementDegree simpler

parent 78bd1000
......@@ -21,46 +21,53 @@
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttribute.hpp"
#include "XdmfAttributeCenter.hpp"
#include "XdmfAttributeType.hpp"
#include "XdmfError.hpp"
//-----------------------------------------------------------------------------
shared_ptr<XdmfAttribute>
XdmfAttribute::New()
{
shared_ptr<XdmfAttribute> p(new XdmfAttribute());
return p;
}
//-----------------------------------------------------------------------------
XdmfAttribute::XdmfAttribute() :
mCenter(XdmfAttributeCenter::Grid()),
mName(""),
mType(XdmfAttributeType::NoAttributeType())
mType(XdmfAttributeType::NoAttributeType()),
mItemType(""),
mElementDegree(0),
mElementFamily("")
{
}
//-----------------------------------------------------------------------------
XdmfAttribute::XdmfAttribute(XdmfAttribute & refAttribute) :
XdmfArray(refAttribute),
mCenter(refAttribute.mCenter),
mName(refAttribute.mName),
mType(refAttribute.mType)
mType(refAttribute.mType),
mItemType(refAttribute.mItemType),
mElementDegree(refAttribute.mElementDegree),
mElementFamily(refAttribute.mElementFamily)
{
}
//-----------------------------------------------------------------------------
XdmfAttribute::~XdmfAttribute()
{
}
//-----------------------------------------------------------------------------
const std::string XdmfAttribute::ItemTag = "Attribute";
//-----------------------------------------------------------------------------
shared_ptr<const XdmfAttributeCenter>
XdmfAttribute::getCenter() const
{
return mCenter;
}
//-----------------------------------------------------------------------------
std::map<std::string, std::string>
XdmfAttribute::getItemProperties() const
{
......@@ -68,31 +75,51 @@ XdmfAttribute::getItemProperties() const
attributeProperties.insert(std::make_pair("Name", mName));
mType->getProperties(attributeProperties);
mCenter->getProperties(attributeProperties);
attributeProperties.insert(std::make_pair("ItemType", mItemType));
attributeProperties.insert(std::make_pair("ElementDegree",
std::to_string(mElementDegree)));
attributeProperties.insert(std::make_pair("ElementFamily", mElementFamily));
return attributeProperties;
}
//-----------------------------------------------------------------------------
std::string
XdmfAttribute::getItemTag() const
{
return ItemTag;
}
//-----------------------------------------------------------------------------
std::string
XdmfAttribute::getName() const
{
return mName;
}
//-----------------------------------------------------------------------------
shared_ptr<const XdmfAttributeType>
XdmfAttribute::getType() const
{
return mType;
}
//-----------------------------------------------------------------------------
std::string XdmfAttribute::getItemType() const
{
return mItemType;
}
//-----------------------------------------------------------------------------
unsigned int XdmfAttribute::getElementDegree() const
{
return mElementDegree;
}
//-----------------------------------------------------------------------------
std::string XdmfAttribute::getElementFamily() const
{
return mElementFamily;
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
XdmfAttribute::populateItem(
const std::map<std::string, std::string> & itemProperties,
const std::vector<shared_ptr<XdmfItem> > & childItems,
const XdmfCoreReader * const reader)
{
XdmfItem::populateItem(itemProperties, childItems, reader);
......@@ -109,7 +136,26 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
mCenter = XdmfAttributeCenter::New(itemProperties);
mType = XdmfAttributeType::New(itemProperties);
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
std::map<std::string, std::string>::const_iterator element_degree =
itemProperties.find("ElementDegree");
if(element_degree != itemProperties.end()) {
mElementDegree = std::stoi(element_degree->second);
}
std::map<std::string, std::string>::const_iterator element_family =
itemProperties.find("ElementFamily");
if(element_family != itemProperties.end()) {
mElementFamily = element_family->second;
}
std::map<std::string, std::string>::const_iterator item_type =
itemProperties.find("ItemType");
if(item_type != itemProperties.end()) {
mItemType = item_type->second;
}
for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
childItems.begin();
iter != childItems.end();
++iter) {
......@@ -123,30 +169,51 @@ XdmfAttribute::populateItem(const std::map<std::string, std::string> & itemPrope
}
}
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setCenter(const shared_ptr<const XdmfAttributeCenter> center)
{
mCenter = center;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setName(const std::string & name)
{
mName = name;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setType(const shared_ptr<const XdmfAttributeType> type)
{
mType = type;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setItemType(std::string type)
{
mItemType = type;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setElementDegree(unsigned int degree)
{
mElementDegree = degree;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
void
XdmfAttribute::setElementFamily(std::string family)
{
mElementFamily = family;
this->setIsChanged(true);
}
//-----------------------------------------------------------------------------
// C Wrappers
//-----------------------------------------------------------------------------
XDMFATTRIBUTE * XdmfAttributeNew()
{
try
......@@ -160,7 +227,7 @@ XDMFATTRIBUTE * XdmfAttributeNew()
return (XDMFATTRIBUTE *)((void *)(new XdmfAttribute(*generatedAttribute.get())));
}
}
//-----------------------------------------------------------------------------
int XdmfAttributeGetCenter(XDMFATTRIBUTE * attribute)
{
if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Grid()) {
......@@ -178,11 +245,15 @@ int XdmfAttributeGetCenter(XDMFATTRIBUTE * attribute)
else if (((XdmfAttribute *)attribute)->getCenter() == XdmfAttributeCenter::Node()) {
return XDMF_ATTRIBUTE_CENTER_NODE;
}
else if (((XdmfAttribute *)attribute)->getCenter() ==
XdmfAttributeCenter::Other()) {
return XDMF_ATTRIBUTE_CENTER_OTHER;
}
else {
return -1;
}
}
//-----------------------------------------------------------------------------
int XdmfAttributeGetType(XDMFATTRIBUTE * attribute)
{
if (((XdmfAttribute *)attribute)->getType() == XdmfAttributeType::Scalar()) {
......@@ -210,7 +281,7 @@ int XdmfAttributeGetType(XDMFATTRIBUTE * attribute)
return -1;
}
}
//-----------------------------------------------------------------------------
void XdmfAttributeSetCenter(XDMFATTRIBUTE * attribute, int center, int * status)
{
XDMF_ERROR_WRAP_START(status)
......@@ -237,7 +308,7 @@ void XdmfAttributeSetCenter(XDMFATTRIBUTE * attribute, int center, int * status)
}
XDMF_ERROR_WRAP_END(status)
}
//-----------------------------------------------------------------------------
void XdmfAttributeSetType(XDMFATTRIBUTE * attribute, int type, int * status)
{
XDMF_ERROR_WRAP_START(status)
......@@ -270,6 +341,6 @@ void XdmfAttributeSetType(XDMFATTRIBUTE * attribute, int type, int * status)
}
XDMF_ERROR_WRAP_END(status)
}
//-----------------------------------------------------------------------------
XDMF_ITEM_C_CHILD_WRAPPER(XdmfAttribute, XDMFATTRIBUTE)
XDMF_ARRAY_C_CHILD_WRAPPER(XdmfAttribute, XDMFATTRIBUTE)
......@@ -163,6 +163,27 @@ public:
*/
shared_ptr<const XdmfAttributeType> getType() const;
/**
* Get the ItemType associated with this attribute.
*
* @return ItemType of the attribute.
*/
std::string getItemType() const;
/**
* Get the ElementFamily associated with this attribute.
*
* @return ElementFamily of the attribute.
*/
std::string getElementFamily() const;
/**
* Get the ElementDegree associated with this attribute.
*
* @return ElementDegree of the attribute.
*/
unsigned int getElementDegree() const;
/**
* Set the XdmfAttributeCenter associated with this attribute.
*
......@@ -238,6 +259,27 @@ public:
*/
void setType(const shared_ptr<const XdmfAttributeType> type);
/**
* Set the ItemType associated with this attribute.
*
* @param type ItemType to set.
*/
void setItemType(std::string type);
/**
* Set the ElementFamily associated with this attribute.
*
* @param type ElementFamily to set.
*/
void setElementFamily(std::string type);
/**
* Set the ElementDegree associated with this attribute.
*
* @param type ElementDegree to set.
*/
void setElementDegree(unsigned int degree);
XdmfAttribute(XdmfAttribute &);
protected:
......@@ -257,6 +299,10 @@ private:
shared_ptr<const XdmfAttributeCenter> mCenter;
std::string mName;
shared_ptr<const XdmfAttributeType> mType;
std::string mItemType;
unsigned int mElementDegree;
std::string mElementFamily;
};
#endif
......
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfAttributeItemType.hpp */
/* */
/* */
/* Author: */
/* Michal Habera */
/* habera<at>karlin.mff.cuni.cz */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*****************************************************************************/
#include <utility>
#include "XdmfAttributeItemType.hpp"
#include "XdmfError.hpp"
//-----------------------------------------------------------------------------
std::map<std::string, shared_ptr<const XdmfAttributeItemType>(*)()>
XdmfAttributeItemType::mAttributeDefinitions;
//-----------------------------------------------------------------------------
// Supported XdmfAttributeItemType
shared_ptr<const XdmfAttributeItemType>
XdmfAttributeItemType::NoAttributeItemType()
{
static shared_ptr<const XdmfAttributeItemType>
p(new XdmfAttributeItemType("None"));
return p;
}
//-----------------------------------------------------------------------------
shared_ptr<const XdmfAttributeItemType>
XdmfAttributeItemType::FiniteElementFunction()
{
static shared_ptr<const XdmfAttributeItemType>
p(new XdmfAttributeItemType("FiniteElementFunction"));
return p;
}
//-----------------------------------------------------------------------------
void XdmfAttributeItemType::InitTypes()
{
mAttributeDefinitions["NONE"] = NoAttributeItemType;
mAttributeDefinitions["FINITE_ELEMENT_FUNCTION"] = FiniteElementFunction;
}
//-----------------------------------------------------------------------------
XdmfAttributeItemType::XdmfAttributeItemType(const std::string & name) :
mName(name)
{
}
//-----------------------------------------------------------------------------
XdmfAttributeItemType::~XdmfAttributeItemType()
{
}
//-----------------------------------------------------------------------------
shared_ptr<const XdmfAttributeItemType> XdmfAttributeItemType::New(
const std::map<std::string, std::string> &itemProperties)
{
InitTypes();
std::map<std::string, std::string>::const_iterator item_type =
itemProperties.find("ItemType");
const std::string & typeVal = ConvertToUpper(type->second);
std::map<std::string,
shared_ptr<const XdmfAttributeItemType>(*)()>::const_iterator
returnType = mAttributeDefinitions.find(typeVal);
if (returnType == mAttributeDefinitions.end()) {
XdmfError::message(XdmfError::FATAL,
"ItemType not of 'None','FiniteElementFunction' in "
"XdmfAttributeItemType::New");
}
else {
return (*(returnType->second))();
}
// unreachable
return shared_ptr<const XdmfAttributeItemType>();
}
//-----------------------------------------------------------------------------
void XdmfAttributeItemType::getProperties(
std::map<std::string, std::string>& collectedProperties) const
{
collectedProperties.insert(std::make_pair("ItemType", mName));
}
//-----------------------------------------------------------------------------
// C Wrappers
//-----------------------------------------------------------------------------
int XdmfAttributeItemTypeFiniteElementFunction()
{
return XDMF_ATTRIBUTE_ITEM_TYPE_FINITE_ELEMENT_FUNCTION;
}
\ No newline at end of file
/*****************************************************************************/
/* XDMF */
/* eXtensible Data Model and Format */
/* */
/* Id : XdmfAttributeItemType.hpp */
/* */
/* */
/* Author: */
/* Michal Habera */
/* habera<at>karlin.mff.cuni.cz */
/* */
/* This software is distributed WITHOUT ANY WARRANTY; without */
/* even the implied warranty of MERCHANTABILITY or FITNESS */
/* FOR A PARTICULAR PURPOSE. See the above copyright notice */
/* for more information. */
/* */
/*****************************************************************************/
#ifndef XDMFATTRIBUTEITEMTYPE_HPP_
#define XDMFATTRIBUTEITEMTYPE_HPP_
// C Compatible Includes
#include "Xdmf.hpp"
#ifdef __cplusplus
#include "XdmfItemProperty.hpp"
/**
* @brief Property describing the type of values an XdmfAttribute
* contains.
*
* XdmfAttributeItemType is a specific property of XdmfAttribute
* used to specify what type of values XdmfAttribute contains.
* Unlike XdmfAttributeType, this property does not specify rank
* of values (scalar, vector, tensor, etc) but more general
* framework is allowed. For example, FiniteElementFunction
* defines how to interpret content of Attribute as a finite
* element function.
*
* Xdmf supports the following attribute item types:
* FiniteElementFunction
*/
class XDMF_EXPORT XdmfAttributeItemType : public XdmfItemProperty
{
public:
virtual ~XdmfAttributeItemType();
friend class XdmfAttribute;
// Supported Xdmf Attribute Types
static shared_ptr<const XdmfAttributeType> NoAttributeItemType();
static shared_ptr<const XdmfAttributeItemType> FiniteElementFunction();
void
getProperties(std::map<std::string, std::string> & collectedProperties) const;
protected:
/**
* Protected constructor for XdmfAttributeItemType. The constructor is
* protected because all attribute types supported by Xdmf should be
* accessed through more specific static methods that construct
* XdmfAttributeItemTypes - i.e.
* XdmfAttributeItemType::FiniteElementFunction().
*
* @param name The name of the XdmfAttributeItemType to construct.
*/
XdmfAttributeItemType(const std::string & name);
static std::map<std::string, shared_ptr<const XdmfAttributeItemType>(*)()>
mAttributeDefinitions;
static void InitTypes();
private:
XdmfAttributeItemType(const XdmfAttributeItemType &); // Not implemented.
void operator=(const XdmfAttributeItemType &); // Not implemented.
static shared_ptr<const XdmfAttributeItemType>
New(const std::map<std::string, std::string> & itemProperties);
std::string mName;
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
// C wrappers go here
#define XDMF_ATTRIBUTE_ITEM_TYPE_FINITE_ELEMENT_FUNCTION 300
#define XDMF_ATTRIBUTE_ITEM_TYPE_NOTYPE 301
XDMF_EXPORT int XdmfAttributeItemTypeFiniteElementFunction();
XDMF_EXPORT int XdmfAttributeItemTypeNoAttributeItemType();
#ifdef __cplusplus
}
#endif
#endif // XDMFATTRIBUTEITEMTYPE_HPP_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment