Commit e09cc800 authored by mdurant's avatar mdurant

Improving determination of topological dimensionality for structured, uniform,...

Improving determination of topological dimensionality for structured, uniform, and rectilinear meshes.  Also fixes a bug whereby we had a buffer overflow if the data file contained a 1-d variable with more values than nodes in the corresponding mesh.  Finally, tweaked some debugging statements

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@16209 18c085ea-50e0-402c-830e-de6fd14e8384
parent 25d702e0
......@@ -21,9 +21,8 @@
VsH5Dataset::VsH5Dataset(VsRegistry* r, VsH5Object* parentObject, std::string datasetName, hid_t id):
VsH5Object(r, parentObject, datasetName, id){
dataType = H5Tget_native_type(H5Dget_type(id), H5T_DIR_DEFAULT);
loadDims();
registry->add(this);
......
......@@ -23,6 +23,7 @@
VsMesh::VsMesh(VsH5Object* object):VsRegistryObject(object->registry) {
numSpatialDims = -1;
numTopologicalDims = -1;
indexOrder = VsSchema::compMinorCKey;
if (!object) {
......@@ -63,13 +64,18 @@ void VsMesh::write() {
<< getFullName() << " "
<< "Kind: " << getKind() << " "
<< "Index Order: " << indexOrder << " "
<< "NumSpatialDims: " << numSpatialDims << std::endl;
<< "NumSpatialDims: " << numSpatialDims << " "
<< "NumTopologicalDims: " << numTopologicalDims << std::endl;
}
size_t VsMesh::getNumSpatialDims() {
return numSpatialDims;
}
size_t VsMesh::getNumTopologicalDims() {
return numTopologicalDims;
}
std::string VsMesh::getPath() {
return h5Object->getPath();
}
......
......@@ -48,6 +48,8 @@ public:
std::string getIndexOrder();
virtual std::string getKind() = 0;
size_t getNumSpatialDims();
size_t getNumTopologicalDims();
VsH5Attribute* getAttribute(std::string name);
static VsMesh* buildObject(VsH5Dataset* dataset);
static VsMesh* buildObject(VsH5Group* group);
......@@ -68,6 +70,13 @@ protected:
/** The spatial dimensionality */
size_t numSpatialDims;
/** The topological dimensionality
* Note: will always be <= the spatial dimensionality
* (i.e. can have lower-dimension object in a higher dimension
* but not vice versa)
*/
size_t numTopologicalDims;
/** Index order (Fortran vs C style) */
std::string indexOrder;
......
......@@ -11,6 +11,7 @@
#include "VsH5Group.h"
#include "VsH5Attribute.h"
#include "VsLog.h"
#include "VsUtils.h"
#include <string>
......@@ -99,7 +100,52 @@ bool VsRectilinearMesh::initialize() {
}
}
VsLog::errorLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
//Calculate topological dims
numTopologicalDims = 0;
std::vector<int> axis0Dims = axis0->getDims();
if (axis0Dims.size() != 1) {
VsLog::errorLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Expected 1-d dataset for Axis 0, actually have " <<axis0Dims.size() <<std::endl;
numTopologicalDims = numSpatialDims;
} else {
if (axis0Dims[0] > 1) {
numTopologicalDims++;
}
//Check axis 1 (if it exists)
if (axis1) {
std::vector<int> axis1Dims = axis1->getDims();
if (axis1Dims.size() != 1) {
VsLog::errorLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Expected 1-d dataset for Axis 1, actually have " <<axis1Dims.size() <<std::endl;
numTopologicalDims = numSpatialDims;
} else {
if (axis1Dims[0] > 1) {
numTopologicalDims++;
}
//Check axis 1 (if it exists)
if (axis2) {
std::vector<int> axis2Dims = axis2->getDims();
if (axis2Dims.size() != 1) {
VsLog::errorLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Expected 1-d dataset for Axis 2, actually have " <<axis2Dims.size() <<std::endl;
numTopologicalDims = numSpatialDims;
} else {
if (axis2Dims[0] > 1) {
numTopologicalDims++;
}
}
} //end if axis2
}
} //end if axis1
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Rectilinear Mesh " <<getShortName() <<" has num topological dims = "
<< numTopologicalDims << std::endl;
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Mesh has num spatial dims = "
<< numSpatialDims << std::endl;
......@@ -132,7 +178,7 @@ std::string VsRectilinearMesh::getAxisDatasetName(int axisNumber) {
if (axisNameAtt) {
axisNameAtt->getStringValue(&axisName);
if (!axisName.empty()) {
return axisName;
return makeCanonicalName(getFullName(), axisName);
}
}
......@@ -150,7 +196,7 @@ std::string VsRectilinearMesh::getAxisDatasetName(int axisNumber) {
}
//axisName
return axisName;
return makeCanonicalName(getFullName(), axisName);
}
......
......@@ -75,16 +75,34 @@ bool VsStructuredMesh::initialize()
<< "an array of size [numPoints] but with no spatial dimension. "
<< "Whereas the normal dimensions would be [numPoints][spatialDim] "
<< "As such, assume the spatial dimenson is 1." << std::endl;
numTopologicalDims = 1;
numSpatialDims = 1;
}
else
{
if( isCompMinor() )
if( isCompMinor() ) {
numSpatialDims = dims[dims.size()-1];
else
numTopologicalDims = 0;
for (int i = 0; i < (dims.size() - 1); i++) {
if (dims[i] > 1) {
numTopologicalDims++;
}
}
}
else {
numSpatialDims = dims[0];
numTopologicalDims = 0;
for (int i = 1; i < dims.size(); i++) {
if (dims[i] > 1) {
numTopologicalDims++;
}
}
}
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Structured mesh " << getShortName() << " has topological dimensionality = "
<< numTopologicalDims << std::endl;
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Mesh has num spatial dims = " << numSpatialDims
......
......@@ -93,7 +93,18 @@ bool VsUniformMesh::initialize()
return false;
}
int numTopologyDims = dims.size();
//Num topological dims is equal to the count of dims
//that are > 1
numTopologicalDims = 0;
for (int i = 0; i < dims.size(); i++) {
if (dims[i] > 1) {
numTopologicalDims++;
}
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Uniform mesh " <<getShortName() << " has topological dimensionality "
<< numTopologicalDims <<std::endl;
// Lowerbounds is required
lowerBoundsAtt = getAttribute(VsSchema::Uniform::lowerBounds);
......@@ -158,8 +169,6 @@ bool VsUniformMesh::initialize()
return false;
}
numSpatialDims = dVals.size();
// Now get the upper bounds spatial dimension.
err = upperBoundsAtt->getDoubleVectorValue(&dVals);
......
......@@ -320,10 +320,14 @@ bool VsUnstructuredMesh::initialize() {
{
numPoints = pointsDataset->getDims()[0];
numSpatialDims = pointsDataset->getDims()[1];
//guess that topological == spatial
numTopologicalDims = numSpatialDims;
}
else
{
numSpatialDims = pointsDataset->getDims()[0];
//guess that topological == spatial
numTopologicalDims = numSpatialDims;
numPoints = pointsDataset->getDims()[1];
}
}
......@@ -350,17 +354,24 @@ bool VsUnstructuredMesh::initialize() {
//spatial dimensionality = number of vspoints datasets
numSpatialDims = 1;
numTopologicalDims = 1;
if (points1) {
if (points2) {
numSpatialDims = 3;
numTopologicalDims = 3;
} else {
numSpatialDims = 2;
numTopologicalDims = 2;
}
}
numPoints = points0->getDims()[0];
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Unstructured mesh " <<getShortName() <<" has num topological dims = "
<< numTopologicalDims <<std::endl;
if( isPointMesh() )
{
numCells = numPoints;
......
......@@ -104,8 +104,7 @@ avtVsFileFormat::avtVsFileFormat(const char* filename,
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "entering" << std::endl;
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "VizSchema Revision #742" << std::endl;
if (readOpts != NULL) {
for (int i=0; i<readOpts->GetNumberOfOptions(); ++i) {
......@@ -563,7 +562,7 @@ vtkDataSet* avtVsFileFormat::getUniformMesh(VsUniformMesh* uniformMesh,
throw std::out_of_range(msg.str().c_str());
}
size_t numTopologicalDims = numCells.size();
size_t numTopologicalDims = uniformMesh->getNumTopologicalDims();
if (numTopologicalDims > 3) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
......@@ -766,9 +765,7 @@ avtVsFileFormat::getRectilinearMesh(VsRectilinearMesh* rectilinearMesh,
throw std::out_of_range(msg.str().c_str());
}
// The numTopologicalDims and numSpatialDims are the same for
// rectilinear grids.
size_t numTopologicalDims = numNodes.size();
size_t numTopologicalDims = rectilinearMesh->getNumTopologicalDims();
if (numTopologicalDims > 3) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
......@@ -1038,7 +1035,7 @@ vtkDataSet* avtVsFileFormat::getStructuredMesh(VsStructuredMesh* structuredMesh,
// The numTopologicalDims and numSpatialDims can be different for
// structured grids.
size_t numTopologicalDims = numNodes.size();
size_t numTopologicalDims = structuredMesh->getNumTopologicalDims();
if (numTopologicalDims > 3) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
......@@ -2247,24 +2244,51 @@ vtkDataSet* avtVsFileFormat::getCurve(int domain, const std::string& requestedNa
nPts = varMeta->getDims()[1];
}
// Cross-reference against the number of points in the mesh
int nPtsInOutput = nPts;
std::vector<int> meshDims;
meshMeta->getMeshDataDims(meshDims);
int nPtsInMesh = meshDims[0];
if (varMeta->isZonal()) {
if (nPts != (nPtsInMesh - 1)) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "ERROR - mesh and var dimensionalities don't match." <<std::endl;
//Use the lower of the two values
if (nPts > (nPtsInMesh - 1)) {
nPtsInOutput = nPtsInMesh - 1;
}
}
} else if (nPts != nPtsInMesh) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "ERROR - mesh and var dimensionalities don't match." <<std::endl;
//Use the lower of the two values
if (nPts > nPtsInMesh) {
nPtsInOutput = nPtsInMesh;
}
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Variable has " << nPts << " points." << std::endl;
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Mesh has " << nPtsInMesh << " points." << std::endl;
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Output will have " << nPtsInOutput << " points." << std::endl;
// Create 1-D RectilinearGrid
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Building Rectilinear grid." << std::endl;
vtkFloatArray* vals = vtkFloatArray::New();
vals->SetNumberOfComponents(1);
vals->SetNumberOfTuples(nPts);
vals->SetNumberOfTuples(nPtsInOutput);
vals->SetName(name.c_str());
vtkRectilinearGrid* rg = vtkVisItUtility::Create1DRGrid(nPts, VTK_FLOAT);
vtkRectilinearGrid* rg = vtkVisItUtility::Create1DRGrid(nPtsInOutput, VTK_FLOAT);
rg->GetPointData()->SetScalars(vals);
vtkFloatArray* xc = vtkFloatArray::SafeDownCast(rg->GetXCoordinates());
vtkDataArray* meshXCoord = meshData->GetXCoordinates();
for (int i = 0; i < nPts; i++) {
for (int i = 0; i < nPtsInOutput; i++) {
double* var_i = varData->GetTuple(i);
double* mesh_i = meshXCoord->GetTuple(i);
xc->SetValue(i, mesh_i[0]);
......@@ -3230,7 +3254,6 @@ void avtVsFileFormat::RegisterMeshes(avtDatabaseMetaData* md)
<< "Adding uniform mesh " << *it << "." << std::endl;
meshType = AVT_RECTILINEAR_MESH;
topologicalDims = 3;
// Add in the logical bounds of the mesh.
static_cast<VsUniformMesh*>(meta)->getNumMeshDims(dims);
......@@ -3248,7 +3271,6 @@ void avtVsFileFormat::RegisterMeshes(avtDatabaseMetaData* md)
<< "spatialDims = " << spatialDims << "." << std::endl;
meshType = AVT_RECTILINEAR_MESH;
topologicalDims = 3;
// Add in the logical bounds of the mesh.
static_cast<VsRectilinearMesh*>(meta)->getNumMeshDims(dims);
......@@ -3265,7 +3287,6 @@ void avtVsFileFormat::RegisterMeshes(avtDatabaseMetaData* md)
<< "Adding structured mesh " << *it << "." << std::endl;
meshType = AVT_CURVILINEAR_MESH;
topologicalDims = 3;
// Add in the logical bounds of the mesh.
static_cast<VsRectilinearMesh*>(meta)->getNumMeshDims(dims);
......@@ -3348,8 +3369,23 @@ void avtVsFileFormat::RegisterMeshes(avtDatabaseMetaData* md)
continue;
}
int topologicalDims = meta->getNumTopologicalDims();
if( meshType != AVT_UNKNOWN_MESH )
{
//Add a note for this interesting case. It is legal, but since it's a new feature
//we want to keep an eye on it
if (topologicalDims > spatialDims) {
VsLog::errorLog() <<__CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<<"ERROR - num topological dims (" << topologicalDims
<<") > num spatial dims (" << spatialDims <<")" <<std::endl;
topologicalDims = spatialDims;
} else if (spatialDims != topologicalDims) {
VsLog::debugLog() <<__CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<<"Interesting - num topological dims (" << topologicalDims
<<") != num spatial dims (" << spatialDims <<")" <<std::endl;
}
avtMeshMetaData* vmd =
new avtMeshMetaData(it->c_str(), 1, 1, 1, 0,
spatialDims, topologicalDims, meshType);
......@@ -3617,6 +3653,7 @@ void avtVsFileFormat::RegisterVarsWithMesh(avtDatabaseMetaData* md)
continue;
}
// This loop registers all VARIABLES
// SS: we need all components so going to lastDim here.
// for (size_t i = 0; i < lastDim-vm->numSpatialDims; ++i) {
for (size_t i = 0; i < lastDim; ++i) {
......@@ -3639,14 +3676,20 @@ void avtVsFileFormat::RegisterVarsWithMesh(avtDatabaseMetaData* md)
}
}
// add var mesh
// This loop registers all of the MESHES
// Add in the logical bounds of the mesh.
int numCells = vMeta->getNumPoints();
int bounds[3] = {numCells,0,0};
int spatialDims = vMeta->getNumSpatialDims();
if (spatialDims == 1) {
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<<"Found 1-d var with mesh, artificially elevating it to 2-d." <<std::endl;
spatialDims = 2;
}
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Adding point mesh for this variable." << std::endl;
avtMeshMetaData* vmd = new avtMeshMetaData(it->c_str(),
1, 1, 1, 0, vMeta->getNumSpatialDims(), 0, AVT_POINT_MESH);
1, 1, 1, 0, spatialDims, 0, AVT_POINT_MESH);
vmd->SetBounds( bounds );
// vmd->SetNumberCells( numCells );
setAxisLabels(vmd);
......@@ -3826,7 +3869,6 @@ void avtVsFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData* md)
// NOTE that we can't decompose domains if we have MD meshes
// So it's one or the other
std::vector<std::string> names;
#ifdef VIZSCHEMA_DECOMPOSE_DOMAINS
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
......@@ -3871,7 +3913,8 @@ void avtVsFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData* md)
md->Add(mmd);
}
UpdateCyclesAndTimes(md);
//VsLog::debugLog() <<"Calling UpdateCyclesAndTimes for file: " <<dataFileName <<std::endl;
//UpdateCyclesAndTimes(md);
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "Exiting normally." << std::endl;
......@@ -3966,20 +4009,20 @@ bool avtVsFileFormat::ReturnsValidCycle()
int avtVsFileFormat::GetCycle()
{
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "entering" << std::endl;
<< "entering for file " <<dataFileName << std::endl;
LoadData();
if (registry->hasCycle())
{
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "This file supplies cycle: "
<< "The file " <<dataFileName <<" supplies cycle: "
<< registry->getCycle() << std::endl;
return registry->getCycle();
}
else
{
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "This file does not supply cycle. "
<< "The file " <<dataFileName <<" does not supply cycle. "
<< "Returning INVALID_CYCLE." << std::endl;
return INVALID_CYCLE;
......@@ -4041,14 +4084,14 @@ double avtVsFileFormat::GetTime()
if (registry->hasTime())
{
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "This file supplies time: "
<< "The file " <<dataFileName <<" supplies time: "
<<registry->getTime() << std::endl;
return registry->getTime();
}
else
{
VsLog::debugLog() << __CLASS__ << __FUNCTION__ << " " << __LINE__ << " "
<< "This file does not supply time. "
<< "The file " <<dataFileName <<" does not supply time. "
<< "Returning INVALID_TIME." << std::endl;
return INVALID_TIME;
}
......
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