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

full C++ examples added to documentation

parent f709ab4a
......@@ -65,8 +65,57 @@
* constructors in the XDMF API are protected, ensuring that only
* shared pointers can be created. These pointers are freed
* automatically by the shared pointer reference counting mechanism.
*
* C++ Examples:
*
* \subpage cppwrite "C++ Example of Xdmf Creation"
*
* \subpage cppread "C++ Example of Reading Xdmf"
*
* \subpage cppedit "C++ Example of Reading and Modifying Xdmf"
*
* Python Examples:
*
* \subpage pywrite "Python Example of Xdmf Creation"
*
* \subpage pyread "Python Example of Reading Xdmf"
*
* \subpage pyedit "Python Example of Reading and Modifying Xdmf"
*
*/
/*!
* \page cppwrite Example of Xdmf Creation
* \include ExampleXdmfWrite.cpp
*/
/*!
* \page cppread Example of Reading Xdmf
* \include ExampleXdmfRead.cpp
*/
/*!
* \page cppedit Example of Reading and Modifying
* \include ExampleXdmfEdit.cpp
*/
/*!
* \page pywrite Example of Xdmf Creation
* \include XdmfExampleWrite.py
*/
/*!
* \page pyread Example of Reading Xdmf
* \include XdmfExampleRead.py
*/
/*!
* \page pyedit Example of Reading and Modifying
* \include XdmfExampleEdit.py
*/
/* Keep all our Win32 Conversions here */
#ifdef _WIN32
/* Used to export/import from the dlls */
......
......@@ -54,7 +54,7 @@ public:
*
* @code {.cpp}
* shared_ptr<XdmfAttribute> exampleAttribute = XdmfAttribute::New();
* #endcode
* @endcode
*
* Python
*
......
......@@ -192,16 +192,16 @@ public:
* //(2, 4, 6)
* //(3, 5, 5)
* //(3, 6, 4)
* std::map<int, std::map<int, int> > taskIDMap = exampleMap->getMap();
* std::map<int, std::map<int, std::set<int> > > taskIDMap = exampleMap->getMap();
* //taskIDMap now contains the same tuples as exampleMap
* std::map<int, std::map<int, int> >::iterator taskWalker = taskIDMap.begin();
* std::map<int, std::map<int, std::set<int> > >::iterator taskWalker = taskIDMap.begin();
* int taskIDValue = (*taskWalker).first;
* //taskIDValue is now equal to 1, because that is the first taskID listed
* std::map<int, int> nodeIDMap = taskIDMap[1];
* std::map<int, std::set<int> > nodeIDMap = taskIDMap[1];
* //nodeIDMap now contains the following tuples because it retrieved the tuples associated with taskID 1
* //(1, 9)
* //(2, 8)
* std::map<int, int>::iterator mapWalker = nodeIDMap.begin();
* std::map<int, std::set<int> >::iterator mapWalker = nodeIDMap.begin();
* int localNodeValue = (*mapWalker).first;
* //localNodeValue is now equal to 1, because it is the first entry in the first tuple in the set
* std::set<int> remoteNodeSet = exampleMap[1];
......@@ -303,11 +303,11 @@ public:
* //(2, 4, 6)
* //(3, 5, 5)
* //(3, 6, 4)
* std::map<int, int> nodeIDMap = exampleMap->getRemoteNodeIds(1);
* std::map<int, std::set<int> > nodeIDMap = exampleMap->getRemoteNodeIds(1);
* //nodeIDMap now contains the following tuples because it retrieved the tuples associated with taskID 1
* //(1, 9)
* //(2, 8)
* std::map<int, int>::iterator mapWalker = nodeIDMap.begin();
* std::map<int, std::set<int> >::iterator mapWalker = nodeIDMap.begin();
* int localNodeValue = (*mapWalker).first;
* //localNodeValue is now equal to 1, because it is the first entry in the first tuple in the set
* std::set<int> remoteNodeSet = exampleMap[1];
......@@ -569,25 +569,36 @@ public:
*
* @code {.cpp}
* shared_ptr<XdmfMap> exampleMap = XdmfMap::New();
* //First create several std::map<int, int>
* std::map<int, int> nodeMap;
* nodeMap.insert(pair<int, int>(2,3));
* nodeMap.insert(pair<int, int>(2,6));
* nodeMap.insert(pair<int, int>(2,8));
* nodeMap.insert(pair<int, int>(3,3));
* nodeMap.insert(pair<int, int>(4,7));
* nodeMap.insert(pair<int, int>(4,9));
* std::map<int, int> nodeMap2;
* nodeMap.insert(pair<int, int>(5,3));
* nodeMap.insert(pair<int, int>(5,6));
* nodeMap.insert(pair<int, int>(5,8));
* nodeMap.insert(pair<int, int>(7,3));
* nodeMap.insert(pair<int, int>(9,7));
* nodeMap.insert(pair<int, int>(9,9));
* //Then create a std::map<int, std::map<int, int> >
* std::map<int, std::map<int, int> > taskMap;
* taskMap.insert(pair<int, std::map<int, int> >(1, nodeMap);
* taskMap.insert(pair<int, std::map<int, int> >(2, nodeMap2);
* //First create a std::map<int, std::set<int> >
* std::map<int, std::map<int, std::set<int> > > taskMap;
* std::map<int, std::set<int> > nodeMap;
* std::set<int> remoteIDset;
* remoteIDset.insert(3);
* remoteIDset.insert(6);
* remoteIDset.insert(8);
* nodeMap.insert(pair<int, std::set<int> >(2, remoteIDset));
* remoteIDset.clear();
* remoteIDset.insert(3);
* nodeMap.insert(pair<int, std::set<int> >(3, remoteIDset));
* remoteIDset.clear();
* remoteIDset.insert(7);
* remoteIDset.insert(9);
* nodeMap.insert(pair<int, std::set<int> >(4, remoteIDset));
* taskMap.insert(pair<int, std::map<int, std::set<int> > >(1, nodeMap);
* nodeMap.clear();
* remoteIDset.clear();
* remoteIDset.insert(3);
* remoteIDset.insert(6);
* remoteIDset.insert(8);
* nodeMap.insert(pair<int, std::set<int> >(5, remoteIDset));
* remoteIDset.clear();
* remoteIDset.insert(3);
* nodeMap.insert(pair<int, std::set<int> >(7, remoteIDset));
* remoteIDset.clear();
* remoteIDset.insert(7);
* remoteIDset.insert(9);
* nodeMap.insert(pair<int, std::set<int> >(9, remoteIDset));
* taskMap.insert(pair<int, std::map<int, std::set<int> > >(2, nodeMap);
* //then the result is set to the XdmfMap
* exampleMap->setMap(taskMap);
* //This fills the XdmfMap with the following tuples
......
......@@ -127,14 +127,14 @@ public:
*
* C++
*
* @code {.cpp}
* @code{.cpp}
* //Assuming that exampleArray is a shared pointer to an XdmfArray object
* exampleArray->clear();
* @endcode
*
* Python
*
* @code {.py}
* @code{.py}
* '''
* Assuming that exampleArray is a shared pointer to an XdmfArray object
* '''
......
......@@ -201,7 +201,7 @@ public:
* '''
* "Your New Key" is now the key for infoExample
* '''
* @endocode
* @endcode
*
* @param key a string containing the key to set.
*/
......
This diff is collapsed.
......@@ -43,6 +43,9 @@ class XdmfHeavyDataWriter;
* written to disk. Heavy data is written to a heavy data format using
* an XdmfHeavyDataWriter and light data is written to XML.
*
* An infinite loop is possible if an XdmfItem somehow ends up as its own child,
* either directly or by way of another Xdmf Item.
*
* By default, the XdmfWriter writes all heavy data to a single heavy
* data file specified by the XdmfHeavyDataWriter. If a dataset is
* encountered that resides in a different heavy data file on disk,
......
......@@ -638,7 +638,7 @@ EXAMPLE_PATTERNS =
# commands irrespective of the value of the RECURSIVE tag.
# Possible values are YES and NO. If left blank NO is used.
EXAMPLE_RECURSIVE = NO
EXAMPLE_RECURSIVE = YES
# The IMAGE_PATH tag can be used to specify one or more files or
# directories that contain image that are included in the documentation (see
......
#include "XdmfAttribute.hpp"
#include "XdmfAttributeType.hpp"
#include "XdmfAttributeCenter.hpp"
int main(int, char **)
{
shared_ptr<XdmfAttribute> exampleAttribute = XdmfAttribute::New();
exampleAttribute->setCenter(XdmfAttributeCenter::Node());
std::string newName = "New Name";
exampleAttribute->setName(newName);
exampleAttribute->setType(XdmfAttributeType::Node());
shared_ptr<const XdmfAttributeCenter> exampleCenter = exampleAttribute->getCenter();
std::string exampleName = exampleAttribute->getName();
shared_ptr<const XdmfAttributeType> exampleType = exampleAttribute->getType();
return 0;
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
from Xdmf import *
if __name__ == "__main__":
primaryDomain = XdmfDomain.New()
domaininfo = XdmfInformation.New("Domain", "This is the primary data structure in Xdmf")
domaininfoinfo = XdmfInformation.New("Information", "Information can have information")
domaininfo.insert(domaininfoinfo)
primaryDomain.insert(domaininfo)
gridHolder = XdmfGridCollection.New()
gridHolder.setType(XdmfGridCollectionType.Spatial())
holderInfo = XdmfInformation.New("Grid Collection 1", "This is the main grid collection")
gridHolder.insert(holderInfo)
gridHolder.setName("GridCollection Example")
ungrid = XdmfUnstructuredGrid.New()
ungrid.setName("Unstructured Grid Example")
untime = XdmfTime.New(5.0)
untimeinfo = XdmfInformation.New("Time", "This is the time for the Unstructured Grid")
untime.insert(untimeinfo)
ungrid.setTime(untime)
unglobalID = XdmfAttribute.New()
unglobalID.setType(XdmfAttributeType.GlobalId())
unglobalID.setCenter(XdmfAttributeCenter.Node())
unglobalID.setName("Global Node Equivalencies")
task1globalnodes = [1, 4, 5, 7, 3, 6]
unglobalID.insertAsInt32(0, task1globalnodes)
unglobalIDinfo = XdmfInformation.New("Global Nodes", "This is the global nodes that accociate with the local nodes")
ungrid.insert(unglobalID)
unset = XdmfSet.New()
unsetinfo = XdmfInformation.New("Data Set", "This is a set of arbitrary data")
unset.insert(unsetinfo)
unset.setName("Unstructured Grid's Set")
unset.setType(XdmfSetType.Node())
unsetattribute = XdmfAttribute.New()
unsetattribute.setType(XdmfAttributeType.Scalar())
unsetattribute.setCenter(XdmfAttributeCenter.Node())
unsetattribute.setName("The Set's attribute")
unsetattribdata = [1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]
unsetattribute.insertAsFloat64(0, unsetattribdata)
unset.insert(unsetattribute)
unsetdata = [5.1, 4.2, 3.3, 2.4, 1.5]
unset.insertAsFloat64(0, unsetdata)
ungrid.insert(unset)
ungeometry = XdmfGeometry.New()
ungeometry.setType(XdmfGeometryType.XYZ())
ungeometry.setName("Unstructured Geometry")
ungeopoints = [0.1, 0.1, 1.1, 1.1, 0.1, 1.1, 3.1, 0.1, 2.1, 0.1, 1.1, 1.1, 1.1,
1.1, 1.1, 3.1, 2.1, 2.1, 0.1, 0.1, -1.1, 1.1, 0.1, -1.1, 3.1,
0.1, -2.1, 0.1, 1.1, -1.1, 1.1, 1.1, -1.1, 3.1, 2.1, -2.1]
ungeometry.insertAsFloat64(0, ungeopoints)
ungeometryinfo = XdmfInformation.New("Geometry", "This is the geometry associated with the unstructured grid")
ungeometry.insert(ungeometryinfo)
ungrid.setGeometry(ungeometry)
untopology = XdmfTopology.New()
untopology.setType(XdmfTopologyType.Hexahedron())
untopology.setName("Unstructured Topology")
untopovalues = [0, 1, 7, 6, 3, 4, 10, 9, 1, 2, 8, 7, 4, 5, 11, 10]
untopology.insertAsInt32(0, untopovalues)
untopologyinfo = XdmfInformation.New("Topology", "This is the topology associated with the unstructured grid")
ungrid.setTopology(untopology)
curvdimensions = XdmfArray.New()
curvdimensions.pushBackAsInt32(12)
curvdimensions.pushBackAsInt32(12)
curvdimensions.pushBackAsInt32(12)
curvgrid = XdmfCurvilinearGrid.New(curvdimensions)
curvgrid.setName("Curvilinear Grid Example")
curvgridinfo = XdmfInformation.New("Curvilinear Grid", "This is an example curvilinear grid")
curvgrid.insert(curvgridinfo)
curvtime = XdmfTime.New(5.0)
curvtimeinfo = XdmfInformation.New("Time", "The Time of the Curvilinear Grid")
curvtime.insert(curvtimeinfo)
curvgrid.setTime(curvtime)
curvglobalID = XdmfAttribute.New()
curvglobalID.setType(XdmfAttributeType.GlobalId())
curvglobalID.setCenter(XdmfAttributeCenter.Node())
curvglobalID.setName("Global Node Equivalencies")
task2globalnodes = [7, 3, 8, 2, 5, 1]
curvglobalID.insertAsInt32(0, task1globalnodes)
curvglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that accociate with the local nodes")
curvglobalID.insert(curvglobalIDinfo)
curvgrid.insert(curvglobalID)
curvgeometry = XdmfGeometry.New()
curvgeometry.setType(XdmfGeometryType.XYZ())
curvgeometry.setName("Curvilinear Geometry")
curvgeopoints = [1.1, 1.1, 2.1, 2.1, 1.1, 2.1, 4.1, 1.1, 3.1, 1.1, 2.1, 2.1, 2.1,
2.1, 2.1, 4.1, 3.1, 3.1, 1.1, 1.1, 0.1, 2.1, 1.1, 0.1, 4.1,
1.1, -1.1, 1.1, 2.1, 0.1, 1.1, 2.1, -0.1, 4.1, 3.1, -1.1]
curvgeometry.insertAsFloat64(0, curvgeopoints)
curvgeometryinfo = XdmfInformation.New("Geometry", "The geometry of the curvilinear grid")
curvgeometry.insert(curvgeometryinfo)
curvgrid.setGeometry(curvgeometry)
rectXcoordinates = [1.1, 1.1, 2.1, 2.1, 1.1, 2.1, 4.1, 1.1, 3.1, 1.1, 2.1, 2.1]
rectYcoordinates = [2.1, 2.1, 2.1, 4.1, 3.1, 3.1, 1.1, 1.1, 0.1, 2.1, 1.1, 0.1]
rectZcoordinates = [4.1, 1.1, -1.1, 1.1, 2.1, 0.1, 1.1, 2.1, -0.1, 4.1, 3.1, -1.1]
rectXarray = XdmfArray.New()
rectXarray.insertAsFloat64(0, rectXcoordinates)
rectYarray = XdmfArray.New()
rectYarray.insertAsFloat64(0, rectYcoordinates)
rectZarray = XdmfArray.New()
rectZarray.insertAsFloat64(0, rectZcoordinates)
coordinatecontainer = ArrayVector()
coordinatecontainer.push_back(rectXarray)
coordinatecontainer.push_back(rectYarray)
coordinatecontainer.push_back(rectZarray)
rectgrid = XdmfRectilinearGrid.New(coordinatecontainer)
rectgrid.setName("Rectilinear Grid Example")
rectgridinfo = XdmfInformation.New("Rectilinear Grid", "This is an example of a rectilinear grid")
rectglobalID = XdmfAttribute.New()
rectglobalID.setType(XdmfAttributeType.GlobalId())
rectglobalID.setCenter(XdmfAttributeCenter.Node())
rectglobalID.setName("Global Node Equivalencies")
task3globalnodes = [2, 7, 9, 0, 8, 6]
rectglobalID.insertAsInt32(0, task3globalnodes)
rectglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that associate with the local nodes")
rectglobalID.insert(rectglobalIDinfo)
recttime = XdmfTime.New(5.0)
recttimeinfo = XdmfInformation.New("Time", "The time of the rectiliniear grid")
recttime.insert(recttimeinfo)
rectgrid.setTime(recttime)
rectgrid.insert(rectglobalID)
regbrick = XdmfArray.New()
regbrickvals = [10, 10, 10]
regbrick.insertAsFloat64(0, regbrickvals)
regdimensions = XdmfArray.New()
regdimensionvals = [5, 5, 5]
regdimensions.insertAsInt32(0, regdimensionvals)
regorigin = XdmfArray.New()
regoriginvals = [0, 0, 0]
regorigin.insertAsFloat64(0, regoriginvals)
reggrid = XdmfRegularGrid.New(regbrick, regdimensions, regorigin)
reggrid.setName("Regular Grid Example")
reggridinfo = XdmfInformation.New("Regular Grid", "This is an example of a regular grid")
regtime = XdmfTime.New(5.0)
regtimeinfo = XdmfInformation.New("Time", "This is the time for the regular grid")
reggrid.setTime(regtime)
regglobalID = XdmfAttribute.New()
regglobalID.setType(XdmfAttributeType.GlobalId())
regglobalID.setCenter(XdmfAttributeCenter.Node())
regglobalID.setName("Global Node Equivalencies")
task4globalnodes = [3, 6, 1, 4, 2, 5, 9]
regglobalID.insertAsInt32(0, task4globalnodes)
regglobalIDinfo = XdmfInformation.New("Global Node Equivalencies", "These are the global nodes that associate with the local nodes")
reggrid.insert(regglobalID)
nodeholder = AttributeVector()
nodeholder.push_back(unglobalID)
nodeholder.push_back(curvglobalID)
nodeholder.push_back(rectglobalID)
nodeholder.push_back(regglobalID)
mapcollection = XdmfMap.New(nodeholder)
ungrid.insert(mapcollection[0])
curvgrid.insert(mapcollection[1])
rectgrid.insert(mapcollection[2])
reggrid.insert(mapcollection[3])
'''
the version of XdmfMap.New used here returns a number of maps equal to the number of attributes it was provided with.
'''
for insertedmap in mapcollection:
gridHolder.insert(insertedmap)
gridHolder.insert(ungrid)
gridHolder.insert(curvgrid)
gridHolder.insert(rectgrid)
gridHolder.insert(reggrid)
secondaryHolder = XdmfGridCollection.New()
secondaryHolder.setName("Secondary grid collection")
gridHolder.insert(secondaryHolder)
'''
grid collections can be placed inside other grid collections
'''
primaryDomain.insert(gridHolder)
'''
grids can be inserted into the domain in the same way as the grid collection
'''
primaryDomain.insert(ungrid)
primaryDomain.insert(curvgrid)
primaryDomain.insert(rectgrid)
primaryDomain.insert(reggrid)
exampleHeavyWriter = XdmfHDF5Writer.New("testoutput.h5")
exampleWriter = XdmfWriter.New("testoutput.xmf", exampleHeavyWriter)
primaryDomain.accept(exampleWriter)
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