Updates will be applied on October 27th between 12pm - 12:45pm EDT (UTC-0400). Gitlab may be slow during the maintenance window.

Commit 895f33c5 authored by Kenneth Leiter's avatar Kenneth Leiter
Browse files

ENH: Add methods in Fortran interface to reuse previously added data.

Output of Xdmf data in Fortran can now take advantage of xpointer functionality.
Calling any AddPrevious or SetPrevious methods will reuse previously
added Xdmf structure so that when it is written to disk xincludes can be
utilized rather than rewriting identical structure multiple times.  These
methods take an id which is returned in Add or Set calls.

Modified TestXdmfFortran.f90 to utilize new functionality.
parent 7bcbfe72
......@@ -241,7 +241,7 @@ XdmfFortran::~XdmfFortran()
{
}
void
int
XdmfFortran::addAttribute(const char * const name,
const int attributeCenter,
const int attributeType,
......@@ -302,6 +302,10 @@ XdmfFortran::addAttribute(const char * const name,
values);
mAttributes.push_back(currAttribute);
const int id = mPreviousAttributes.size();
mPreviousAttributes.push_back(currAttribute);
return id;
}
void
......@@ -335,7 +339,6 @@ void
XdmfFortran::addGridCollection(const char * const name,
const int gridCollectionType)
{
const shared_ptr<XdmfGridCollection> gridCollection =
XdmfGridCollection::New();
gridCollection->setName(name);
......@@ -359,10 +362,9 @@ XdmfFortran::addGridCollection(const char * const name,
mGridCollections);
mGridCollections.push(gridCollection);
}
void
int
XdmfFortran::addInformation(const char * const key,
const char * const value)
{
......@@ -371,6 +373,28 @@ XdmfFortran::addInformation(const char * const key,
information->setValue(value);
mInformations.push_back(information);
const int id = mPreviousInformations.size();
mPreviousInformations.push_back(information);
return id;
}
void
XdmfFortran::addPreviousAttribute(const int attributeId)
{
if(attributeId >= mPreviousAttributes.size()) {
XdmfError::message(XdmfError::FATAL, "Invalid attribute id");
}
mAttributes.push_back(mPreviousAttributes[attributeId]);
}
void
XdmfFortran::addPreviousInformation(const int informationId)
{
if(informationId >= mPreviousInformations.size()) {
XdmfError::message(XdmfError::FATAL, "Invalid information id");
}
mInformations.push_back(mPreviousInformations[informationId]);
}
void
......@@ -381,7 +405,7 @@ XdmfFortran::closeGridCollection()
}
}
void
int
XdmfFortran::setGeometry(const int geometryType,
const unsigned int numValues,
const int arrayType,
......@@ -405,6 +429,28 @@ XdmfFortran::setGeometry(const int geometryType,
numValues,
arrayType,
pointValues);
const int id = mPreviousGeometries.size();
mPreviousGeometries.push_back(mGeometry);
return id;
}
void
XdmfFortran::setPreviousGeometry(const int geometryId)
{
if(geometryId >= mPreviousGeometries.size()) {
XdmfError::message(XdmfError::FATAL, "Invalid geometry id");
}
mGeometry = mPreviousGeometries[geometryId];
}
void
XdmfFortran::setPreviousTopology(const int topologyId)
{
if(topologyId >= mPreviousTopologies.size()) {
XdmfError::message(XdmfError::FATAL, "Invalid topology id");
}
mTopology = mPreviousTopologies[topologyId];
}
void
......@@ -414,7 +460,7 @@ XdmfFortran::setTime(const double time)
mTime->setValue(time);
}
void
int
XdmfFortran::setTopology(const int topologyType,
const unsigned int numValues,
const int arrayType,
......@@ -517,7 +563,11 @@ XdmfFortran::setTopology(const int topologyType,
writeToArray(mTopology,
numValues,
arrayType,
connectivityValues);
connectivityValues);
const int id = mPreviousTopologies.size();
mPreviousTopologies.push_back(mTopology);
return id;
}
void
......@@ -549,7 +599,7 @@ extern "C"
delete xdmfFortran;
}
void
int
XdmfAddAttribute(long * pointer,
char * const name,
int * attributeCenter,
......@@ -559,12 +609,12 @@ extern "C"
void * values)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->addAttribute(name,
*attributeCenter,
*attributeType,
*numValues,
*arrayType,
values);
return xdmfFortran->addAttribute(name,
*attributeCenter,
*attributeType,
*numValues,
*arrayType,
values);
}
void
......@@ -585,13 +635,29 @@ extern "C"
*gridCollectionType);
}
void
int
XdmfAddInformation(long * pointer,
char * key,
char * value)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->addInformation(key, value);
return xdmfFortran->addInformation(key, value);
}
void
XdmfAddPreviousAttribute(long * pointer,
int * attributeId)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->addPreviousAttribute(*attributeId);
}
void
XdmfAddPreviousInformation(long * pointer,
int * informationId)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->addPreviousInformation(*informationId);
}
void
......@@ -601,7 +667,7 @@ extern "C"
xdmfFortran->closeGridCollection();
}
void
int
XdmfSetGeometry(long * pointer,
int * geometryType,
int * numValues,
......@@ -610,10 +676,26 @@ extern "C"
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->setGeometry(*geometryType,
*numValues,
*arrayType,
pointValues);
return xdmfFortran->setGeometry(*geometryType,
*numValues,
*arrayType,
pointValues);
}
void
XdmfSetPreviousGeometry(long * pointer,
int * geometryId)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->setPreviousGeometry(*geometryId);
}
void
XdmfSetPreviousTopology(long * pointer,
int * topologyId)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->setPreviousTopology(*topologyId);
}
void
......@@ -624,7 +706,7 @@ extern "C"
xdmfFortran->setTime(*time);
}
void
int
XdmfSetTopology(long * pointer,
int * topologyType,
int * numValues,
......@@ -632,10 +714,10 @@ extern "C"
void * connectivityValues)
{
XdmfFortran * xdmfFortran = reinterpret_cast<XdmfFortran *>(*pointer);
xdmfFortran->setTopology(*topologyType,
*numValues,
*arrayType,
connectivityValues);
return xdmfFortran->setTopology(*topologyType,
*numValues,
*arrayType,
connectivityValues);
}
void
......
......@@ -33,6 +33,7 @@ class XdmfGridCollection;
class XdmfInformation;
class XdmfTime;
class XdmfTopology;
class XdmfUnstructuredGrid;
//Includes
#include <stack>
......@@ -127,8 +128,12 @@ class XdmfTopology;
#define XdmfAddGrid xdmfaddgrid_
#define XdmfAddGridCollection xdmfaddgridcollection_
#define XdmfAddInformation xdmfaddinformation_
#define XdmfAddPreviousAttribute xdmfaddpreviousattribute_
#define XdmfAddPreviousInformation xdmfaddpreviousinformation_
#define XdmfCloseGridCollection xdmfclosegridcollection_
#define XdmfSetGeometry xdmfsetgeometry_
#define XdmfSetPreviousGeometry xdmfsetpreviousgeometry_
#define XdmfSetPreviousTopology xdmfsetprevioustopology_
#define XdmfSetTime xdmfsettime_
#define XdmfSetTopology xdmfsettopology_
#define XdmfWrite xdmfwrite_
......@@ -163,13 +168,15 @@ public:
* @param numValues number of attribute values to copy.
* @param arrayType type of attribute values.
* @param values array of attribute values.
*
* @return int providing id to fortran if reusing.
*/
void addAttribute(const char * const name,
const int attributeCenter,
const int attributeType,
const unsigned int numValues,
const int arrayType,
const void * const values);
int addAttribute(const char * const name,
const int attributeCenter,
const int attributeType,
const unsigned int numValues,
const int arrayType,
const void * const values);
/**
* Add grid to domain or collection. Inserts geometry, topology,
......@@ -198,9 +205,30 @@ public:
* create.
* @param value string containing the value of the information to
* create.
*
* @return int providing id to fortran if reusing.
*/
int addInformation(const char * const key,
const char * const value);
/**
* Add an attribute that will be inserted into the next grid or grid
* collection. This will reuse a previously added attribute so that
* xpointers can be used when writing to file (reducing file size).
*
* @param attributeId, returned from a previous addAttribute().
*/
void addPreviousAttribute(const int attributeId);
/**
* Add an information that will be inserted into the next grid or grid
* collection. This will reuse a previously added information so that
* xpointers can be used when writing to file (reducing file size).
*
* @param informationId, returned from a previous addInformation().
*/
void addInformation(const char * const key,
const char * const value);
void addPreviousInformation(const int informationId);
/**
* Closes grid collection. No additional grids or collections can be
......@@ -215,11 +243,31 @@ public:
* @param numValues number of point values to copy.
* @param arrayType type of point values.
* @param pointValues array of point values.
*
* @return int providing id to fortran if reusing.
*/
void setGeometry(const int geometryType,
const unsigned int numValues,
const int arrayType,
const void * const pointValues);
int setGeometry(const int geometryType,
const unsigned int numValues,
const int arrayType,
const void * const pointValues);
/**
* Set the geometry (point data) that will be added to the next grid.
* This will reuse a previously set geometry so that xpointers can be
* used when writing to file (reducing file size);
*
* @param geometryId, returned from previous setGeometry()
*/
void setPreviousGeometry(const int geometryId);
/**
* Set the topology (connectivity data) that will be added to the
* next grid. This will reuse a previously set topology so that
* xpointers can be used when writing to file (reducing file size);
*
* @param topologyId, returned from previous setTopology()
*/
void setPreviousTopology(const int topologyId);
/**
* Set the time that will be added to the next grid or grid
......@@ -237,11 +285,13 @@ public:
* @param numValues number of connectivity values to copy.
* @param arrayType type of connectivity values.
* @param connectivityValues array of connectivity values.
*
* @return int providing id to fortran if reusing.
*/
void setTopology(const int topologyType,
const unsigned int numValues,
const int arrayType,
const void * const connectivityValues);
int setTopology(const int topologyType,
const unsigned int numValues,
const int arrayType,
const void * const connectivityValues);
/**
* Write constructed file to disk.
......@@ -261,6 +311,13 @@ private:
std::stack<shared_ptr<XdmfGridCollection> > mGridCollections;
std::vector<shared_ptr<XdmfInformation> > mInformations;
std::vector<shared_ptr<XdmfAttribute> > mPreviousAttributes;
std::vector<shared_ptr<XdmfGeometry> > mPreviousGeometries;
std::vector<shared_ptr<XdmfInformation> > mPreviousInformations;
std::vector<shared_ptr<XdmfTopology> > mPreviousTopologies;
};
#endif /* XDMFFORTRAN_HPP_ */
......@@ -17,6 +17,7 @@ PROGRAM XdmfFortranExample
REAL*4 myPoints(3,3,4)
INTEGER myConnections(8,2)
REAL*8 myCellAttribute(2), myNodeAttribute(3,4), myTime
INTEGER nodeAttributeId, cellAttributeId, xdmfaddattribute
filename = 'my_output'//CHAR(0)
......@@ -100,10 +101,10 @@ PROGRAM XdmfFortranExample
XDMF_ARRAY_TYPE_INT32, myConnections)
CALL XDMFSETGEOMETRY(obj, XDMF_GEOMETRY_TYPE_XYZ, 36, &
XDMF_ARRAY_TYPE_FLOAT32, myPoints)
CALL XDMFADDATTRIBUTE(obj, 'NodeValues'//CHAR(0), &
nodeAttributeId = XDMFADDATTRIBUTE(obj, 'NodeValues'//CHAR(0), &
XDMF_ATTRIBUTE_CENTER_NODE, XDMF_ATTRIBUTE_TYPE_SCALAR, 12, &
XDMF_ARRAY_TYPE_FLOAT64, myNodeAttribute)
CALL XDMFADDATTRIBUTE(obj, 'CellValues'//CHAR(0), &
cellAttributeId = XDMFADDATTRIBUTE(obj, 'CellValues'//CHAR(0), &
XDMF_ATTRIBUTE_CENTER_CELL, XDMF_ATTRIBUTE_TYPE_SCALAR, 2, &
XDMF_ARRAY_TYPE_FLOAT64, myCellAttribute)
CALL XDMFADDINFORMATION(obj, 'Key'//CHAR(0), 'Value'//CHAR(0))
......@@ -112,6 +113,7 @@ PROGRAM XdmfFortranExample
myTime = 2.0
CALL XDMFSETTIME(obj, myTime)
CALL XDMFADDPREVIOUSATTRIBUTE(obj, cellAttributeId)
CALL XDMFADDGRID(obj, 'Identical'//CHAR(0))
CALL XDMFCLOSEGRIDCOLLECTION(obj)
CALL XDMFWRITE(obj, filename)
......
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