Commit 39341263 authored by pugmire's avatar pugmire
Browse files

bug fixes, improve support, add complex variables.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@23138 18c085ea-50e0-402c-830e-de6fd14e8384
parent 9982ee70
This diff is collapsed.
......@@ -63,11 +63,7 @@ extern "C"
extern void adios_read_bp_reset_dimension_order (const ADIOS_FILE *fp, int is_fortran);
}
class ADIOSVar;
class ADIOSScalar;
class ADIOSAttr;
class vtkDataArray;
class vtkFloatArray;
class vtkPoints;
// ****************************************************************************
......@@ -95,8 +91,6 @@ class vtkPoints;
class ADIOSFileObject
{
public:
typedef std::map<std::string, ADIOSVar>::const_iterator varIter;
ADIOSFileObject(const char *fname);
ADIOSFileObject(const std::string &fname);
virtual ~ADIOSFileObject();
......@@ -108,255 +102,68 @@ class ADIOSFileObject
int NumTimeSteps();
void GetCycles(std::vector<int> &cycles);
//Attributes
bool GetIntAttr(const std::string &nm, int &val);
bool GetDoubleAttr(const std::string &nm, double &val);
bool GetStringAttr(const std::string &nm, std::string &val);
//Scalars.
bool GetIntScalar(const std::string &nm, int &val);
bool GetDoubleScalar(const std::string &nm, double &val);
bool GetStringScalar(const std::string &nm, std::string &val);
//Coordinates.
bool ReadCoordinates(const std::string &nm,
int ts,
vtkPoints **pts);
//Variables.
bool ReadVariable(const std::string &nm,
int ts,
int dom,
vtkDataArray **array);
bool ReadVariable(const std::string &nm,
int ts,
int dom,
vtkFloatArray **array);
std::map<std::string, ADIOSVar> variables;
std::map<std::string, ADIOSScalar> scalars;
std::map<std::string, ADIOSAttr> attributes;
void SetResetDimensionOrder() {resetDimensionOrder = true;}
void UnsetResetDimensionOrder() {resetDimensionOrder = false;}
protected:
std::string fileName;
ADIOS_FILE *fp;
int numTimeSteps;
bool resetDimensionOrder;
void ResetDimensionOrder() {adios_read_bp_reset_dimension_order(fp, 0);}
static vtkPoints *AllocatePoints(ADIOS_DATATYPES &t);
static vtkDataArray *AllocateArray(ADIOS_DATATYPES &t);
};
// ****************************************************************************
// Class: ADIOSVar
//
// Purpose:
// Wrapper around ADIOS variable.
//
// Programmer: Dave Pugmire
// Creation: Wed Feb 10 16:15:32 EST 2010
//
// ****************************************************************************
class ADIOSVar
{
public:
ADIOSVar();
ADIOSVar(const std::string &nm, ADIOS_VARINFO *avi);
~ADIOSVar() {}
void GetReadArrays(int ts, uint64_t *s, uint64_t *c, int *ntuples);
ADIOS_DATATYPES type;
int dim, varIdx, nTimeSteps;
uint64_t start[3], count[3], global[3];
std::string name;
double extents[2];
};
// ****************************************************************************
// Class: ADIOSScalar
//
// Purpose:
// Wrapper around ADIOS scalar.
//
// Programmer: Dave Pugmire
// Creation: Tue Mar 9 12:40:15 EST 2010
//
// ****************************************************************************
class ADIOSScalar
{
public:
ADIOSScalar() {Set("", adios_unknown, NULL);}
ADIOSScalar(const std::string &nm, ADIOS_VARINFO *avi)
vtkPoints *ReadCoordinates(const std::string &nm, int ts, int dim, int nPts);
bool ReadScalarData(const std::string &nm, int ts, vtkDataArray **arr)
{
Set(nm, avi->type, avi->value);
return ReadScalarData(nm, ts, (ADIOS_SELECTION*)NULL, arr);
}
bool ReadScalarData(const std::string &nm, int ts, int block, vtkDataArray **arr);
bool ReadScalarData(const std::string &nm, int ts, ADIOS_SELECTION *sel, vtkDataArray **arr);
~ADIOSScalar()
{
if(ptr)
free(ptr);
ptr = NULL;
sz = 0;
}
std::string Name() const {return name;}
bool IsInt() const {return type == adios_integer;}
bool IsFloat() const {return type == adios_real;}
bool IsDouble() const {return type == adios_double;}
bool IsString() const {return type == adios_string;}
int AsInt() const
{
int v;
memcpy(&v,ptr,sizeof(int));
return v;
}
float AsFloat() const
{
float v;
memcpy(&v,ptr,sizeof(float));
return v;
}
double AsDouble() const
//Handle complex variables.
bool ReadComplexData(const std::string &nm, int ts, ADIOS_SELECTION *sel, vtkDataArray **arr, int idx);
bool ReadComplexRealData(const std::string &nm, int ts, vtkDataArray **arr)
{
double v;
memcpy(&v,ptr,sizeof(double));
return v;
return ReadComplexData(nm, ts, (ADIOS_SELECTION*)NULL, arr, 0);
}
std::string AsString() const
bool ReadComplexRealData(const std::string &nm, int ts, ADIOS_SELECTION *sel, vtkDataArray **arr)
{
std::string v = (char *)ptr;
return v;
return ReadComplexData(nm, ts, sel, arr, 0);
}
ADIOSScalar& operator=(const ADIOSScalar &s)
bool ReadComplexImagData(const std::string &nm, int ts, vtkDataArray **arr)
{
name = s.name;
sz = s.sz;
type = s.type;
ptr = new unsigned char[sz];
memcpy(ptr, s.ptr, sz);
return ReadComplexData(nm, ts, (ADIOS_SELECTION*)NULL, arr, 1);
}
protected:
std::string name;
size_t sz;
void *ptr;
ADIOS_DATATYPES type;
void Set(const std::string &nm, ADIOS_DATATYPES t, void *p)
bool ReadComplexImagData(const std::string &nm, int ts, ADIOS_SELECTION *sel, vtkDataArray **arr)
{
name = nm;
type = t;
ptr = NULL;
sz = 0;
if (t != adios_unknown)
sz = adios_type_size(t, p);
if (sz > 0)
{
ptr = malloc(sz);
memcpy(ptr, p, sz);
}
return ReadComplexData(nm, ts, sel, arr, 1);
}
};
// ****************************************************************************
// Class: ADIOSAttr
//
// Purpose:
// Wrapper around ADIOS attribute.
//
// Programmer: Dave Pugmire
// Creation: Tue Mar 9 12:40:15 EST 2010
//
// ****************************************************************************
class ADIOSAttr : public ADIOSScalar
{
public:
ADIOSAttr() {Set("", adios_unknown, NULL);}
ADIOSAttr(const std::string &nm, ADIOS_DATATYPES t, void *p)
{
Set(nm, t, p);
}
};
// ****************************************************************************
// Class: operator<<
//
// Purpose:
// Stream output for ADIOSVar
//
// Programmer: Dave Pugmire
// Creation: Tue Mar 9 12:40:15 EST 2010
//
// ****************************************************************************
inline std::ostream& operator<<(std::ostream& out, const ADIOSVar &v)
{
out<<"ADIOSVar: "<<v.name<<endl;
out<<" dim= "<<v.dim<<" type= "<<v.type<<" idx= "<<v.varIdx<<" nTime= "<<v.nTimeSteps<<endl;
out<<" global= ["<<v.global[0]<<" "<<v.global[1]<<" "<<v.global[2]<<"]"<<endl;
out<<" start= ["<<v.start[0]<<" "<<v.start[1]<<" "<<v.start[2]<<"]"<<endl;
out<<" count= ["<<v.count[0]<<" "<<v.count[1]<<" "<<v.count[2]<<"]"<<endl;
return out;
}
//Attributes
bool GetAttr(const std::string &nm, int &val);
bool GetAttr(const std::string &nm, double &val);
bool GetAttr(const std::string &nm, std::string &val);
//Scalars.
bool GetScalar(const std::string &nm, int &val);
bool GetScalar(const std::string &nm, double &val);
bool GetScalar(const std::string &nm, std::string &val);
ADIOS_MESH * GetMeshInfo(ADIOS_VARINFO *avi);
// ****************************************************************************
// Class: operator<<
//
// Purpose:
// Stream output for ADIOSScalar
//
// Programmer: Dave Pugmire
// Creation: Tue Mar 9 12:40:15 EST 2010
//
// ****************************************************************************
std::map<std::string, ADIOS_VARINFO*> variables, scalars;
std::map<std::string, int> attributes;
inline std::ostream& operator<<(std::ostream& out, const ADIOSScalar &s)
{
out<<"ADIOSScalar: "<<s.Name()<<" value= ";
if (s.IsInt()) out<<s.AsInt();
else if (s.IsFloat()) out<<s.AsFloat();
else if (s.IsDouble()) out<<s.AsDouble();
else if (s.IsString()) out<<s.AsString();
out<<endl;
return out;
}
void SetResetDimensionOrder() {resetDimensionOrder = true;}
void UnsetResetDimensionOrder() {resetDimensionOrder = false;}
// ****************************************************************************
// Class: operator<<
//
// Purpose:
// Stream output for ADIOSAttr
//
// Programmer: Dave Pugmire
// Creation: Tue Mar 9 12:40:15 EST 2010
//
// ****************************************************************************
protected:
std::string fileName;
inline std::ostream& operator<<(std::ostream& out, const ADIOSAttr &s)
{
out<<"ADIOSAttr: "<<s.Name()<<" value= ";
if (s.IsInt()) out<<s.AsInt()<<" type=INT";
else if (s.IsFloat()) out<<s.AsFloat()<<" type=FLOAT";
else if (s.IsDouble()) out<<s.AsDouble()<<" type=DOUBLE";
else if (s.IsString()) out<<"'"<<s.AsString()<<"' type=STRING";
out<<endl;
return out;
}
ADIOS_FILE *fp;
int numTimeSteps;
bool resetDimensionOrder;
ADIOS_SELECTION *CreateSelection(ADIOS_VARINFO *avi) {return CreateSelection(avi,-1);}
ADIOS_SELECTION *CreateSelection(ADIOS_VARINFO *avi, int block);
bool ReadScalarData(ADIOS_VARINFO *avi, int ts, ADIOS_SELECTION *sel, vtkDataArray **arr);
vtkDataArray *AllocateScalarArray(ADIOS_VARINFO *avi, ADIOS_SELECTION *sel);
vtkDataArray *AllocateTypedArray(ADIOS_VARINFO *avi);
void ResetDimensionOrder() {adios_read_bp_reset_dimension_order(fp, 0);}
static bool SupportedVariable(ADIOS_VARINFO *avi);
};
#endif
This diff is collapsed.
......@@ -52,7 +52,6 @@ class ADIOSFileObject;
class avtFileFormatInterface;
class vtkRectilinearGrid;
// ****************************************************************************
// Class: avtADIOSBasicFileFormat
//
......@@ -92,7 +91,7 @@ class avtADIOSBasicFileFormat : public avtMTMDFileFormat
// If you know the times and cycle numbers, overload this function.
// Otherwise, VisIt will make up some reasonable ones for you.
//
virtual void GetCycles(std::vector<int> &);
virtual void GetCycles(std::vector<int> &);
virtual int GetNTimesteps(void);
......@@ -106,40 +105,61 @@ class avtADIOSBasicFileFormat : public avtMTMDFileFormat
protected:
ADIOSFileObject *fileObj;
bool initialized;
std::map<std::string, std::string> complexVarMap;
void Initialize();
std::string GenerateMeshName(const ADIOSVar &v);
void DoDomainDecomposition();
std::string GenerateMeshName(const ADIOS_VARINFO *avi);
class block
{
public:
block() {start[0]=start[1]=start[2]=0; count[0]=count[1]=count[2]=0;}
block(int n, ADIOS_VARBLOCK &b)
{
for (int i = 0; i < n; i++)
{
start[i] = b.start[i];
count[i] = b.count[i];
}
for (int i = n; i < 3; i++)
start[i] = count[i] = 0;
}
uint64_t start[3], count[3];
};
class meshInfo
{
public:
meshInfo()
meshInfo() {dim=0; dims[0]=dims[1]=dims[2]=0;}
meshInfo(ADIOS_VARINFO *avi)
{
start[0] = start[1] = start[2] = 0;
count[0] = count[1] = count[2] = 0;
global[0] = global[1] = global[2] = 0;
dim = 0;
dim = avi->ndim;
for (int i = 0; i < 3; i++)
if (i < dim) dims[i] = avi->dims[i];
else dims[i] = 0;
for (int i = 0; i < avi->sum_nblocks; i++)
blocks.push_back(block(dim, avi->blockinfo[i]));
}
~meshInfo() {}
int dim;
uint64_t start[3], count[3], global[3];
std::string name;
uint64_t dims[3];
std::vector<block> blocks;
};
std::map<std::string, meshInfo> meshes;
vtkRectilinearGrid *CreateUniformGrid(const uint64_t *start,
const uint64_t *count);
vtkRectilinearGrid *CreateUniformGrid(meshInfo &mi, int ts, int dom);
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *, int);
static void ComputeStartCount(uint64_t *globalDims,
int dim,
uint64_t *start,
uint64_t *count);
bool GetDomBounds(int nBlocks, int dim, uint64_t *dims,
uint64_t *sIn, uint64_t *cIn,
uint64_t *sOut, uint64_t *cOut, bool *gFlags);
void AddGhostZones(vtkRectilinearGrid *grid, bool *g);
};
#endif
......@@ -74,19 +74,18 @@
// Dave Pugmire, Tue Mar 9 12:40:15 EST 2010
// Added XGC reader.
//
// Dave Pugmire, Wed Apr 9 13:39:04 EDT 2014
// Added specFM and schema readers.
//
//
// ****************************************************************************
avtFileFormatInterface *
ADIOS_CreateFileFormatInterface(const char * const *list, int nList, int nBlock)
{
avtFileFormatInterface *ffi = NULL;
//ffi = avtSpecFEMFileFormat::CreateInterface(list, nList, nBlock);
//ffi = avtXGCFileFormat::CreateInterface(list, nList, nBlock);
//ffi = avtADIOSSchemaFileFormat::CreateInterface(list, nList, nBlock);
//return ffi;
if(list != NULL || nList > 0)
if (list != NULL || nList > 0)
{
// Determine the type of reader that we want to use.
int flavor = -1;
......@@ -132,9 +131,11 @@ ADIOS_CreateFileFormatInterface(const char * const *list, int nList, int nBlock)
case 1:
ffi = avtXGCFileFormat::CreateInterface(list, nList, nBlock);
break;
/*
case 2:
ffi = avtPixieFileFormat::CreateInterface(list, nList, nBlock);
break;
*/
case 3:
ffi = avtSpecFEMFileFormat::CreateInterface(list, nList, nBlock);
break;
......
......@@ -79,10 +79,6 @@ extern "C"
using namespace std;
static vtkDataArray *AllocateArray(ADIOS_DATATYPES &t, int nt, int nc=1);
static int NumberOfVertices(ADIOS_CELL_TYPE &ct);
static int GetCellType(ADIOS_CELL_TYPE &ct);
// ****************************************************************************
// Method: avtADIOSSchemaFileFormat::Identify
//
......@@ -161,8 +157,7 @@ avtADIOSSchemaFileFormat::CreateInterface(const char *const *list,
avtADIOSSchemaFileFormat::avtADIOSSchemaFileFormat(const char *nm)
: avtMTMDFileFormat(nm)
{
fp = NULL;
filename = nm;
fileObj = new ADIOSFileObject(nm);
initialized = false;
numTimes = 0;
}
......@@ -187,9 +182,9 @@ avtADIOSSchemaFileFormat::~avtADIOSSchemaFileFormat()
vars.clear();
varMeshes.clear();
if (fp)
adios_read_close(fp);
fp = NULL;
if (fileObj)
delete fileObj;
fileObj = NULL;
}
......@@ -333,7 +328,8 @@ avtADIOSSchemaFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int
avtMeshMetaData *mesh = new avtMeshMetaData;
mesh->name = am->name;
mesh->meshType = AVT_UNSTRUCTURED_MESH;
mesh->numBlocks = PAR_Size();
//mesh->meshType = AVT_POINT_MESH;
mesh->numBlocks = 1;
mesh->blockOrigin = 0;
mesh->spatialDimension = am->unstructured->nspaces;
mesh->topologicalDimension = am->unstructured->nspaces;
......@@ -341,23 +337,25 @@ avtADIOSSchemaFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int
}
}
map<string, ADIOS_VARINFO *>::const_iterator vit;
for (vit = vars.begin(); vit != vars.end(); vit++)
std::map<std::string, ADIOS_VARINFO*>::const_iterator v;
for (v = fileObj->variables.begin(); v != fileObj->variables.end(); v++)
{
string varNm = vit->first;
ADIOS_VARINFO *avi = vit->second;
string meshNm = varMeshes.find(varNm)->second;
ADIOS_MESH *m = meshes.find(meshNm)->second;
string varNm = v->first;
ADIOS_VARINFO *avi = v->second;
ADIOS_MESH *am = fileObj->GetMeshInfo(avi);
if (am == NULL)
continue;
avtScalarMetaData *smd = new avtScalarMetaData();
smd->name = varNm;
if (smd->name[0] == '/')
{
smd->originalName = smd->name;
smd->name = string(&smd->name[1]);
}
smd->meshName = meshNm;
smd->meshName = am->name;
if (avi->meshinfo->centering == point)
smd->centering = AVT_NODECENT;
else
......@@ -440,17 +438,8 @@ vtkDataArray *
avtADIOSSchemaFileFormat::GetVar(int timestate, int domain, const char *varname)
{
Initialize();
ADIOS_VARINFO *avi = vars.find(varname)->second;
int sz = 1;
for (int i = 0; i < avi->ndim; i++)
sz *= avi->dims[i];
//cout<<"GetVar "<<varname<<" sz= "<<sz<<" mesh= "<<varMeshes.find(varname)->second<<endl;
vtkDataArray *arr = AllocateArray(avi->type, sz);
ReadData(avi, timestate, arr->GetVoidPointer(0));
vtkDataArray *arr = NULL;
fileObj->ReadScalarData(varname, timestate, &arr);
return arr;
}
......@@ -502,35 +491,26 @@ avtADIOSSchemaFileFormat::GetVectorVar(int timestate, int domain, const char *va
void
avtADIOSSchemaFileFormat::Initialize()
{
if (!fileObj->Open())
EXCEPTION0(ImproperUseException);
if (initialized)
return;
#ifdef PARALLEL
fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, (MPI_Comm)VISIT_MPI_COMM);
#else
MPI_Comm comm_dummy = 0;
fp = adios_read_open_file(filename.c_str(), ADIOS_READ_METHOD_BP, comm_dummy);
#endif
//Read vars.
bool firstIter = true;
for (int i = 0; i < fp->nvars; i++)
std::map<std::string, ADIOS_VARINFO*>::iterator vi;
for (vi = fileObj->variables.begin(); vi != fileObj->variables.end(); ++vi)
{
//cout<<i<<" "<<fp->var_namelist[i]<<endl;
ADIOS_VARINFO *avi = adios_inq_var_byid(fp, i);
if (adios_inq_var_meshinfo(fp, avi) != 0)
continue;
ADIOS_VARINFO *avi = vi->second;
if (avi->meshinfo == NULL)
continue;
//cout<<"GET MESH, id= "<<avi->meshinfo->meshid<<endl;
ADIOS_MESH *am = adios_inq_mesh_byid(fp, avi->meshinfo->meshid);
ADIOS_MESH *am = fileObj->GetMeshInfo(avi);
if (am == NULL)
continue;
adios_inq_var_blockinfo(fp, avi);
if (meshes.find(am->name) == meshes.end())
meshes[am->name] = am;
vars[fp->var_namelist[i]] = avi;
varMeshes[fp->var_namelist[i]] = am->name;
if (firstIter)
{
numTimes = avi->nsteps;
......@@ -541,34 +521,23 @@ avtADIOSSchemaFileFormat::Initialize()
if (numTimes != avi->nsteps)
EXCEPTION1(InvalidVariableException, "Variable inconsitency");