Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions src/databases/Xdmf/avtXdmfFileFormat.C
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ avtXdmfFileFormat::avtXdmfFileFormat(const char *fname) :
this->Stride[0] = this->Stride[1] = this->Stride[2] = 1;

firstGrid = "/Xdmf/Domain/Grid";
numGrids = 0;
numTopLevelGrids = 0;

// Modifications:
// Eric Brugger, Wed Jan 12 14:52:54 PST 2011
Expand All @@ -96,6 +96,9 @@ avtXdmfFileFormat::avtXdmfFileFormat(const char *fname) :
// type is spatial) and in the case of a tree. I also had it set the
// time in the case of a single time state.

XdmfXmlNode domainElement = dom->FindElementByPath("/Xdmf/Domain");
int domainGridCount = dom->FindNumberOfElements("Grid", domainElement);

XdmfXmlNode gridElement = dom->FindElementByPath("/Xdmf/Domain/Grid");
XdmfGrid grid;
grid.SetDOM(dom);
Expand Down Expand Up @@ -133,24 +136,24 @@ avtXdmfFileFormat::avtXdmfFileFormat(const char *fname) :
if (getTimeFromChild)
timesteps.push_back(childGrid.GetTime()->GetValue());
}
numGrids = 1;
numTopLevelGrids = 1;
}
else if(grid.GetCollectionType() == XDMF_GRID_COLLECTION_SPATIAL ||
grid.GetCollectionType() == XDMF_GRID_COLLECTION_UNSET)
{
numGrids = 1;
numTopLevelGrids = domainGridCount;
timesteps.push_back(grid.GetTime()->GetValue());
}
}
else if (grid.GetGridType() == XDMF_GRID_TREE)
{
numGrids = 1;
numTopLevelGrids = domainGridCount;
timesteps.push_back(grid.GetTime()->GetValue());
}
else
{
// Just throw an empty time in here because we only have one timestep
numGrids = dom->FindNumberOfElements("Grid", dom->FindElementByPath("/Xdmf/Domain"));
numTopLevelGrids = domainGridCount;
timesteps.push_back(grid.GetTime()->GetValue());
}

Expand Down Expand Up @@ -480,7 +483,7 @@ void avtXdmfFileFormat::FreeUpResources(void)
XdmfAttribute * avtXdmfFileFormat::GetAttributeFromName(XdmfGrid * grid, const char * attributeName)
{
std::string name = attributeName;
if (numGrids > 1) {
if (numTopLevelGrids > 1) {
name = name.substr(name.rfind("/") + 1, name.length());
}

Expand Down Expand Up @@ -1294,7 +1297,7 @@ void avtXdmfFileFormat::GetTimes(std::vector<double> & times)
vtkDataArray *
avtXdmfFileFormat::GetVar(int timestate, int domain, const char *varname)
{
if (numGrids > 1) {
if (numTopLevelGrids > 1) {
std::string gridName = varname;
gridName = gridName.substr(0, gridName.rfind("/"));
this->SetCurrentGrid(timestate, gridName.c_str());
Expand Down Expand Up @@ -1348,7 +1351,7 @@ vtkDataArray *
avtXdmfFileFormat::GetVectorVar(int timestate, int domain, const char *varname)
{

if (numGrids > 1) {
if (numTopLevelGrids > 1) {
std::string gridName = varname;
gridName = gridName.substr(0, gridName.rfind("/"));
this->SetCurrentGrid(timestate, gridName.c_str());
Expand Down Expand Up @@ -1608,9 +1611,9 @@ bool avtXdmfFileFormat::GetWholeExtent(XdmfGrid* grid, int extents[6])

void avtXdmfFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState)
{
for(int i=0; i<numGrids; ++i)
for(int i=0; i<numTopLevelGrids; ++i)
{
XdmfGrid * grid = this->GetGrid(timeState + i);
XdmfGrid * grid = this->GetGrid(numTopLevelGrids > 1 ? i : timeState);
grid->UpdateInformation();

int nblocks = 1;
Expand Down Expand Up @@ -1683,7 +1686,7 @@ void avtXdmfFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int ti
}

std::stringstream attributeName;
if (numGrids > 1) {
if (numTopLevelGrids > 1) {
attributeName << grid->GetName() << "/";
}
attributeName << attribute->GetName();
Expand Down
2 changes: 1 addition & 1 deletion src/databases/Xdmf/avtXdmfFileFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class avtXdmfFileFormat: public avtMTMDFileFormat
XdmfGrid * currentGrid;
XdmfDOM *dom;
int Stride[3];
int numGrids;
int numTopLevelGrids;
std::vector<double> timesteps;
std::map<std::string, std::string> curveToGridMap;

Expand Down
79 changes: 79 additions & 0 deletions src/test/tests/databases/xdmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# Modifications:
#
# ----------------------------------------------------------------------------
import os

RequiredDatabasePlugin("Xdmf")

def test0(datapath):
Expand Down Expand Up @@ -446,6 +448,82 @@ def test9(datapath):
DeleteAllPlots()
CloseDatabase(pjoin(datapath,"uniform_unit_cube.xmf"))

def test10():
TestSection("Top-level spatial collections with different fields")
db = os.path.abspath("top_level_spatial_collections.xmf")
with open(db, "w") as f:
f.write("""<?xml version="1.0"?>
<Xdmf Version="3.0">
<Domain>
<Grid Name="Barrier" GridType="Collection" CollectionType="Spatial">
<Time Value="0"/>
<Grid Name="Barrier::rank_0" GridType="Uniform">
<Topology TopologyType="Tetrahedron" Dimensions="1">
<DataItem Dimensions="4" NumberType="Int" Precision="4" Format="XML">
0 1 2 3
</DataItem>
</Topology>
<Geometry GeometryType="XYZ">
<DataItem Dimensions="12" NumberType="Float" Precision="8" Format="XML">
0 0 0 1 0 0 0 1 0 0 0 1
</DataItem>
</Geometry>
<Attribute Name="barrier_only" AttributeType="Scalar" Center="Cell">
<DataItem Dimensions="1" NumberType="Float" Precision="8" Format="XML">
7
</DataItem>
</Attribute>
</Grid>
</Grid>
<Grid Name="Channel" GridType="Collection" CollectionType="Spatial">
<Time Value="0"/>
<Grid Name="Channel::rank_0" GridType="Uniform">
<Topology TopologyType="Tetrahedron" Dimensions="1">
<DataItem Dimensions="4" NumberType="Int" Precision="4" Format="XML">
0 1 2 3
</DataItem>
</Topology>
<Geometry GeometryType="XYZ">
<DataItem Dimensions="12" NumberType="Float" Precision="8" Format="XML">
2 0 0 3 0 0 2 1 0 2 0 1
</DataItem>
</Geometry>
<Attribute Name="phaseVolumeFraction_oil" AttributeType="Scalar" Center="Cell">
<DataItem Dimensions="1" NumberType="Float" Precision="8" Format="XML">
0.25
</DataItem>
</Attribute>
</Grid>
</Grid>
</Domain>
</Xdmf>
""")

md = GetMetaData(db)
meshNames = sorted([md.GetMeshes(i).name for i in range(md.GetNumMeshes())])
scalars = {}
for i in range(md.GetNumScalars()):
smd = md.GetScalars(i)
scalars[smd.name] = smd.meshName

TestValueEQ("xdmf_top_level_spatial_meshes", meshNames, ["Barrier", "Channel"])
TestValueEQ("xdmf_top_level_spatial_barrier_var",
scalars.get("Barrier/barrier_only"), "Barrier")
TestValueEQ("xdmf_top_level_spatial_channel_var",
scalars.get("Channel/phaseVolumeFraction_oil"), "Channel")
TestValueEQ("xdmf_top_level_spatial_no_cross_var",
"Barrier/phaseVolumeFraction_oil" in scalars, False)

OpenDatabase(db)
AddPlot("Pseudocolor", "Channel/phaseVolumeFraction_oil")
DrawPlots()
Query("MinMax")
q = GetQueryOutputObject()
TestValueEQ("xdmf_top_level_spatial_channel_min", q["min"], 0.25)
TestValueEQ("xdmf_top_level_spatial_channel_max", q["max"], 0.25)
DeleteAllPlots()
CloseDatabase(db)

def main():
datapath = data_path("xdmf_test_data")
test0(datapath)
Expand All @@ -459,6 +537,7 @@ def main():
test7(datapath)
test8(datapath)
test9(datapath)
test10()

main()
Exit()
Expand Down