Commit 8a8501c5 authored by Jerry Clarke's avatar Jerry Clarke
Browse files

Fix some anomalies and add Epsilon to XdmfTime for comparisons

parent c2cfe131
......@@ -943,6 +943,8 @@ class XdmfTime(XdmfElement):
def SetTimeFromParent(*args): return _Xdmf.XdmfTime_SetTimeFromParent(*args)
def Evaluate(*args): return _Xdmf.XdmfTime_Evaluate(*args)
def IsValid(*args): return _Xdmf.XdmfTime_IsValid(*args)
def SetEpsilon(*args): return _Xdmf.XdmfTime_SetEpsilon(*args)
def GetEpsilon(*args): return _Xdmf.XdmfTime_GetEpsilon(*args)
XdmfTime_swigregister = _Xdmf.XdmfTime_swigregister
XdmfTime_swigregister(XdmfTime)
......
......@@ -364,9 +364,10 @@ XdmfInt64
XdmfDataDesc::GetNumberOfElements( void ) {
hsize_t i, Dimensions[ XDMF_MAX_DIMENSION ];
XdmfInt64 Nelements = 0;
XdmfInt32 rank = H5Sget_simple_extent_ndims(this->DataSpace );
XdmfInt32 rank;
this->Rank = rank;
if(this->DataSpace == H5I_BADID) return(0);
this->Rank = rank = H5Sget_simple_extent_ndims(this->DataSpace );
H5Sget_simple_extent_dims( this->DataSpace, Dimensions, NULL );
if(rank) {
Nelements = this->Dimension[0] = Dimensions[0];
......
......@@ -322,6 +322,7 @@ if( this->GridType & XDMF_GRID_MASK){
this->Children[i] = new XdmfGrid;
if(this->Children[i]->SetDOM(this->DOM) == XDMF_FAIL) return(XDMF_FAIL);
if(this->Children[i]->SetElement(node) == XDMF_FAIL) return(XDMF_FAIL);
// cout << "Calling update info for child " << i << endl;
if(this->Children[i]->UpdateInformation() == XDMF_FAIL) return(XDMF_FAIL);
if(this->Time->GetTimeType() != XDMF_TIME_UNSET){
if(this->Children[i]->GetTime()->SetTimeFromParent(this->Time, i) != XDMF_SUCCESS) return(XDMF_FAIL);
......@@ -380,7 +381,7 @@ if( this->GridType & XDMF_GRID_MASK){
di->SetElement(select);
di->UpdateInformation();
di->Update();
// cout << "UpdateInfo - Select Cells : " << di->GetArray()->GetValues() << endl;
// cout << "UpdateInfo - Select Cells : " << di->GetArray()->GetValues() << endl;
shape = this->Topology->GetShapeDesc();
shape->CopyShape(di->GetDataDesc());
delete di;
......@@ -391,6 +392,17 @@ if( this->GridType & XDMF_GRID_MASK){
// return(XDMF_SUCCESS);
}else{
// Handle Uniform Grid
// cout << "Update Uniform Grid" << endl;
anElement = this->DOM->FindElement("Time", 0, this->Element);
if(anElement){
if(this->Time->SetDOM( this->DOM ) == XDMF_FAIL) return(XDMF_FAIL);
if(this->Time->SetElement(anElement) == XDMF_FAIL) return(XDMF_FAIL);
Status = this->Time->UpdateInformation();
if( Status == XDMF_FAIL ){
XdmfErrorMessage("Error Reading Time");
return( XDMF_FAIL );
}
}
anElement = this->DOM->FindElement("Topology", 0, this->Element);
if(anElement){
if(this->Topology->SetDOM( this->DOM ) == XDMF_FAIL) return(XDMF_FAIL);
......@@ -559,7 +571,7 @@ XdmfGrid::IsUniform(){
}
XdmfInt32
XdmfGrid::FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Range, XdmfInt32 Append){
XdmfGrid::FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Epsilon, XdmfInt32 Append){
XdmfInt64 i, n, index = 0, nchild;
nchild = this->GetNumberOfChildren();
......@@ -572,8 +584,8 @@ XdmfGrid::FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Ra
ArrayToFill->SetNumberOfElements(nchild);
}
for(i=0 ; i < this->GetNumberOfChildren() ; i++){
// cout << "IsValid(" << i << ") = " << this->GetChild(i)->GetTime()->IsValid(Time, Range) << endl;
if(this->GetChild(i)->GetTime()->IsValid(Time, Range)){
// cout << "IsValid(" << i << ") = " << this->GetChild(i)->GetTime()->IsValid(Time) << endl;
if(this->GetChild(i)->GetTime()->IsValid(Time)){
ArrayToFill->SetValueFromInt64(index, i);
index++;
}
......
......@@ -270,7 +270,7 @@ public:
XdmfInt32 FindGridsInTimeRange(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax, XdmfArray *ArrayToFill);
//! Return indexes of first level children that are valid at a time
XdmfInt32 FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Range = 0.0, XdmfInt32 Append=0);
XdmfInt32 FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Epsilon = 0.0, XdmfInt32 Append=0);
protected:
......
......@@ -23651,46 +23651,6 @@ fail:
 
 
SWIGINTERN PyObject *_wrap_XdmfTime_IsValid__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
XdmfTime *arg1 = (XdmfTime *) 0 ;
XdmfTime *arg2 = (XdmfTime *) 0 ;
XdmfFloat64 arg3 ;
XdmfInt32 result;
void *argp1 = 0 ;
int res1 = 0 ;
void *argp2 = 0 ;
int res2 = 0 ;
double val3 ;
int ecode3 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
PyObject * obj2 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OOO:XdmfTime_IsValid",&obj0,&obj1,&obj2)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_XdmfTime, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "XdmfTime_IsValid" "', argument " "1"" of type '" "XdmfTime *""'");
}
arg1 = reinterpret_cast< XdmfTime * >(argp1);
res2 = SWIG_ConvertPtr(obj1, &argp2,SWIGTYPE_p_XdmfTime, 0 | 0 );
if (!SWIG_IsOK(res2)) {
SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "XdmfTime_IsValid" "', argument " "2"" of type '" "XdmfTime *""'");
}
arg2 = reinterpret_cast< XdmfTime * >(argp2);
ecode3 = SWIG_AsVal_double(obj2, &val3);
if (!SWIG_IsOK(ecode3)) {
SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "XdmfTime_IsValid" "', argument " "3"" of type '" "XdmfFloat64""'");
}
arg3 = static_cast< XdmfFloat64 >(val3);
result = (XdmfInt32)(arg1)->IsValid(arg2,arg3);
resultobj = SWIG_From_int(static_cast< int >(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_XdmfTime_IsValid__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
XdmfTime *arg1 = (XdmfTime *) 0 ;
XdmfTime *arg2 = (XdmfTime *) 0 ;
......@@ -23721,7 +23681,7 @@ fail:
}
 
 
SWIGINTERN PyObject *_wrap_XdmfTime_IsValid__SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
SWIGINTERN PyObject *_wrap_XdmfTime_IsValid__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
XdmfTime *arg1 = (XdmfTime *) 0 ;
XdmfFloat64 arg2 ;
......@@ -23781,27 +23741,7 @@ SWIGINTERN PyObject *_wrap_XdmfTime_IsValid(PyObject *self, PyObject *args) {
int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_XdmfTime, 0);
_v = SWIG_CheckState(res);
if (_v) {
return _wrap_XdmfTime_IsValid__SWIG_1(self, args);
}
}
}
if (argc == 3) {
int _v;
void *vptr = 0;
int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_XdmfTime, 0);
_v = SWIG_CheckState(res);
if (_v) {
void *vptr = 0;
int res = SWIG_ConvertPtr(argv[1], &vptr, SWIGTYPE_p_XdmfTime, 0);
_v = SWIG_CheckState(res);
if (_v) {
{
int res = SWIG_AsVal_double(argv[2], NULL);
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_XdmfTime_IsValid__SWIG_0(self, args);
}
return _wrap_XdmfTime_IsValid__SWIG_0(self, args);
}
}
}
......@@ -23821,14 +23761,67 @@ SWIGINTERN PyObject *_wrap_XdmfTime_IsValid(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_XdmfTime_IsValid__SWIG_2(self, args);
return _wrap_XdmfTime_IsValid__SWIG_1(self, args);
}
}
}
}
fail:
SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'XdmfTime_IsValid'.\n Possible C/C++ prototypes are:\n IsValid(XdmfTime *,XdmfFloat64)\n IsValid(XdmfTime *)\n IsValid(XdmfFloat64,XdmfFloat64)\n");
SWIG_SetErrorMsg(PyExc_NotImplementedError,"Wrong number of arguments for overloaded function 'XdmfTime_IsValid'.\n Possible C/C++ prototypes are:\n IsValid(XdmfTime *)\n IsValid(XdmfFloat64,XdmfFloat64)\n");
return NULL;
}
SWIGINTERN PyObject *_wrap_XdmfTime_SetEpsilon(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
XdmfTime *arg1 = (XdmfTime *) 0 ;
XdmfFloat64 arg2 ;
XdmfInt32 result;
void *argp1 = 0 ;
int res1 = 0 ;
double val2 ;
int ecode2 = 0 ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"OO:XdmfTime_SetEpsilon",&obj0,&obj1)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_XdmfTime, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "XdmfTime_SetEpsilon" "', argument " "1"" of type '" "XdmfTime *""'");
}
arg1 = reinterpret_cast< XdmfTime * >(argp1);
ecode2 = SWIG_AsVal_double(obj1, &val2);
if (!SWIG_IsOK(ecode2)) {
SWIG_exception_fail(SWIG_ArgError(ecode2), "in method '" "XdmfTime_SetEpsilon" "', argument " "2"" of type '" "XdmfFloat64""'");
}
arg2 = static_cast< XdmfFloat64 >(val2);
result = (XdmfInt32)(arg1)->SetEpsilon(arg2);
resultobj = SWIG_From_int(static_cast< int >(result));
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_XdmfTime_GetEpsilon(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0;
XdmfTime *arg1 = (XdmfTime *) 0 ;
XdmfFloat64 result;
void *argp1 = 0 ;
int res1 = 0 ;
PyObject * obj0 = 0 ;
if (!PyArg_ParseTuple(args,(char *)"O:XdmfTime_GetEpsilon",&obj0)) SWIG_fail;
res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_XdmfTime, 0 | 0 );
if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "XdmfTime_GetEpsilon" "', argument " "1"" of type '" "XdmfTime *""'");
}
arg1 = reinterpret_cast< XdmfTime * >(argp1);
result = (XdmfFloat64)(arg1)->GetEpsilon();
resultobj = SWIG_From_double(static_cast< double >(result));
return resultobj;
fail:
return NULL;
}
 
......@@ -24332,6 +24325,8 @@ static PyMethodDef SwigMethods[] = {
{ (char *)"XdmfTime_SetTimeFromParent", _wrap_XdmfTime_SetTimeFromParent, METH_VARARGS, NULL},
{ (char *)"XdmfTime_Evaluate", _wrap_XdmfTime_Evaluate, METH_VARARGS, NULL},
{ (char *)"XdmfTime_IsValid", _wrap_XdmfTime_IsValid, METH_VARARGS, NULL},
{ (char *)"XdmfTime_SetEpsilon", _wrap_XdmfTime_SetEpsilon, METH_VARARGS, NULL},
{ (char *)"XdmfTime_GetEpsilon", _wrap_XdmfTime_GetEpsilon, METH_VARARGS, NULL},
{ (char *)"XdmfTime_swigregister", XdmfTime_swigregister, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL }
};
......
......@@ -33,6 +33,7 @@ XdmfTime::XdmfTime() {
this->SetElementName("Time");
this->Value = 0.0;
this->Array = NULL;
this->Epsilon = 1e-7;
this->DataItem = new XdmfDataItem;
this->TimeType = XDMF_TIME_UNSET;
this->Function = NULL;
......@@ -162,6 +163,7 @@ XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Descend, Xd
if(Append){
nelements = ArrayToFill->GetNumberOfElements();
}else{
ArrayToFill->SetNumberType(XDMF_FLOAT64_TYPE);
nelements = 0;
}
gt = Grid->GetTime();
......@@ -171,7 +173,6 @@ XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Descend, Xd
nelements += 1;
ArrayToFill->SetNumberOfElements(nelements);
ArrayToFill->SetValueFromFloat64(nelements - 1, gt->GetValue());
// cout << "Setting val " << nelements - 1 << " = " << gt->GetValue() << endl;
break;
case XDMF_TIME_RANGE :
case XDMF_TIME_LIST :
......@@ -195,8 +196,11 @@ XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Descend, Xd
// cout << "Array = " << ArrayToFill->GetValues() << endl;
break;
default :
if(!Descend) return(XDMF_FAIL);
break;
}
}else{
XdmfErrorMessage("Grid has no XdmfTime");
}
if(Descend){
for(i=0 ; i < Grid->GetNumberOfChildren() ; i++){
......@@ -279,39 +283,39 @@ XdmfTime::GetTimeTypeAsString(void){
}
XdmfInt32
XdmfTime::IsValid(XdmfTime *TimeSpec, XdmfFloat64 Range){
XdmfTime::IsValid(XdmfTime *TimeSpec){
XdmfFloat64 minval, maxval;
// cout << "this->TimeType = " << this->GetTimeTypeAsString() << endl;
// cout << "TimeSpec->TimeType = " << TimeSpec->GetTimeTypeAsString() << endl;
switch(TimeSpec->TimeType){
case XDMF_TIME_SINGLE :
minval = TimeSpec->GetValue() - Range;
maxval = TimeSpec->GetValue() + Range;
minval = TimeSpec->GetValue();
maxval = TimeSpec->GetValue();
break;
case XDMF_TIME_LIST :
if(!TimeSpec->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
minval = TimeSpec->Array->GetMinAsFloat64() - Range;
maxval = TimeSpec->Array->GetMaxAsFloat64() + Range;
minval = TimeSpec->Array->GetMinAsFloat64();
maxval = TimeSpec->Array->GetMaxAsFloat64();
break;
case XDMF_TIME_RANGE :
if(!TimeSpec->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
minval = TimeSpec->Array->GetValueAsFloat64(0) - Range;
maxval = TimeSpec->Array->GetValueAsFloat64(1) + Range;
minval = TimeSpec->Array->GetValueAsFloat64(0);
maxval = TimeSpec->Array->GetValueAsFloat64(1);
break;
case XDMF_TIME_HYPERSLAB :
if(!TimeSpec->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
minval = TimeSpec->Array->GetValueAsFloat64(0) - Range;
maxval = (TimeSpec->Array->GetValueAsFloat64(1) * (TimeSpec->Array->GetValueAsFloat64(2) - 1)) + Range;
minval = TimeSpec->Array->GetValueAsFloat64(0);
maxval = (TimeSpec->Array->GetValueAsFloat64(1) * (TimeSpec->Array->GetValueAsFloat64(2) - 1));
break;
default :
return(XDMF_FALSE);
......@@ -321,6 +325,8 @@ XdmfTime::IsValid(XdmfTime *TimeSpec, XdmfFloat64 Range){
XdmfInt32
XdmfTime::IsValid(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax){
TimeMin -= this->Epsilon;
TimeMax += this->Epsilon;
switch(this->TimeType){
case XDMF_TIME_SINGLE :
// cout << "TimeMin, TimeMax, this->GetValue() = " << TimeMin << "," << TimeMax << "," << this->GetValue() << endl;
......@@ -339,10 +345,10 @@ XdmfTime::IsValid(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax){
if((this->Array->GetMinAsFloat64() >= TimeMin) && (this->Array->GetMaxAsFloat64() <= TimeMax)) return(XDMF_TRUE);
break;
case XDMF_TIME_RANGE :
// cout << "TimeMin, TimeMax, minmaxrange = " << TimeMin << "," << TimeMax <<
// "," << this->Array->GetValueAsFloat64(0) <<
// "," << this->Array->GetValueAsFloat64(1) <<
// endl;
// cout << "TimeMin, TimeMax, minmaxrange = " << TimeMin << "," << TimeMax <<
// "," << this->Array->GetValueAsFloat64(0) <<
// "," << this->Array->GetValueAsFloat64(1) <<
// endl;
if(!this->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
......
......@@ -103,12 +103,17 @@ public:
//! Fills in the sets of times that a particular grid is valid.
XdmfInt32 Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill = NULL, XdmfInt32 Descend = 0, XdmfInt32 Append = 0);
//! Is Time Valid at Specified Value
XdmfInt32 IsValid(XdmfTime *TimeSpec, XdmfFloat64 Range = 0.0);
XdmfInt32 IsValid(XdmfTime *TimeSpec);
//! Is Time within Range
XdmfInt32 IsValid(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax);
//! Set the Epsilon used for Floating Point comparison (1e-7)
XdmfSetValueMacro(Epsilon, XdmfFloat64);
//! Get the Epsilon used for Floating Point comparison (1e-7)
XdmfGetValueMacro(Epsilon, XdmfFloat64);
protected:
XdmfInt32 TimeType;
XdmfFloat64 Value;
XdmfFloat64 Epsilon;
XdmfArray *Array;
XdmfDataItem *DataItem;
XdmfString Function;
......
Supports Markdown
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