Commit c2cfe131 authored by Jerry Clarke's avatar Jerry Clarke
Browse files

Re-implement XdmfTime::Evaluate() and XdmfGrid::FindGridsInTimeRange()

parent 05d523d1
......@@ -899,6 +899,8 @@ class XdmfGrid(XdmfElement):
def UpdateInformation(*args): return _Xdmf.XdmfGrid_UpdateInformation(*args)
def Update(*args): return _Xdmf.XdmfGrid_Update(*args)
def GetChild(*args): return _Xdmf.XdmfGrid_GetChild(*args)
def FindGridsInTimeRange(*args): return _Xdmf.XdmfGrid_FindGridsInTimeRange(*args)
def FindGridsAtTime(*args): return _Xdmf.XdmfGrid_FindGridsAtTime(*args)
XdmfGrid_swigregister = _Xdmf.XdmfGrid_swigregister
XdmfGrid_swigregister(XdmfGrid)
......@@ -940,6 +942,7 @@ class XdmfTime(XdmfElement):
def SetFunction(*args): return _Xdmf.XdmfTime_SetFunction(*args)
def SetTimeFromParent(*args): return _Xdmf.XdmfTime_SetTimeFromParent(*args)
def Evaluate(*args): return _Xdmf.XdmfTime_Evaluate(*args)
def IsValid(*args): return _Xdmf.XdmfTime_IsValid(*args)
XdmfTime_swigregister = _Xdmf.XdmfTime_swigregister
XdmfTime_swigregister(XdmfTime)
......
......@@ -557,3 +557,56 @@ XdmfGrid::IsUniform(){
if(this->GridType & XDMF_GRID_MASK) return(XDMF_FALSE);
return(XDMF_TRUE);
}
XdmfInt32
XdmfGrid::FindGridsAtTime(XdmfTime *Time, XdmfArray *ArrayToFill, XdmfFloat64 Range, XdmfInt32 Append){
XdmfInt64 i, n, index = 0, nchild;
nchild = this->GetNumberOfChildren();
if(!nchild) return(XDMF_FALSE);
if(Append){
index = ArrayToFill->GetNumberOfElements();
ArrayToFill->SetNumberOfElements(index + nchild);
}else{
index = 0;
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)){
ArrayToFill->SetValueFromInt64(index, i);
index++;
}
}
if(index){
// Squeeze
ArrayToFill->SetNumberOfElements(index);
}else{
return(XDMF_FAIL);
}
return(XDMF_SUCCESS);
}
XdmfInt32
XdmfGrid::FindGridsInTimeRange(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax, XdmfArray *ArrayToFill){
XdmfInt64 i, n, index = 0, nchild;
nchild = this->GetNumberOfChildren();
if(!nchild) return(XDMF_FALSE);
ArrayToFill->SetNumberType(XDMF_INT64_TYPE);
ArrayToFill->SetNumberOfElements(nchild);
for(i=0 ; i < nchild ; i++){
// cout << "IsValid(" << i << ") = " << this->GetChild(i)->GetTime()->IsValid(TimeMin, TimeMax) << endl;
if(this->GetChild(i)->GetTime()->IsValid(TimeMin, TimeMax)){
ArrayToFill->SetValueFromInt64(index, i);
index++;
}
}
if(index){
// Squeeze
ArrayToFill->SetNumberOfElements(index);
}else{
return(XDMF_FAIL);
}
return(XDMF_SUCCESS);
}
......@@ -31,6 +31,7 @@
class XdmfGeometry;
class XdmfTopology;
class XdmfAttribute;
class XdmfArray;
class XdmfTime;
#define XDMF_GRID_UNIFORM 0x00000 // Type xor XDMF_GRID_MASK = XdmfTopology Type
......@@ -265,6 +266,12 @@ public:
//! Get one of the child Grids from a Collection or Tree
XdmfGrid *GetChild(XdmfInt32 Index);
//! Return indexes of first level children that are valid at a time
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);
protected:
XdmfGeometry *Geometry;
......
This diff is collapsed.
......@@ -151,7 +151,7 @@ XdmfInt32 XdmfTime::Build(){
}
XdmfInt32
XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Append){
XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Descend, XdmfInt32 Append){
XdmfInt64 i, n, nelements;
XdmfTime *gt;
......@@ -198,9 +198,11 @@ XdmfTime::Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill, XdmfInt32 Append){
break;
}
}
for(i=0 ; i < Grid->GetNumberOfChildren() ; i++){
if(Descend){
for(i=0 ; i < Grid->GetNumberOfChildren() ; i++){
// Append children's times
if(this->Evaluate(Grid->GetChild(i), ArrayToFill, 1) != XDMF_SUCCESS) return(XDMF_FAIL);
if(this->Evaluate(Grid->GetChild(i), ArrayToFill, Descend, 1) != XDMF_SUCCESS) return(XDMF_FAIL);
}
}
if(this->TimeType == XDMF_TIME_RANGE) {
XdmfFloat64 minval, maxval;
......@@ -275,3 +277,88 @@ XdmfTime::GetTimeTypeAsString(void){
return("Single");
}
}
XdmfInt32
XdmfTime::IsValid(XdmfTime *TimeSpec, XdmfFloat64 Range){
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;
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;
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;
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;
break;
default :
return(XDMF_FALSE);
}
return(this->IsValid(minval, maxval));
}
XdmfInt32
XdmfTime::IsValid(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax){
switch(this->TimeType){
case XDMF_TIME_SINGLE :
// cout << "TimeMin, TimeMax, this->GetValue() = " << TimeMin << "," << TimeMax << "," << this->GetValue() << endl;
if((this->GetValue() >= TimeMin) && (this->GetValue() <= TimeMax)){
// cout << "Time Test Passed" << endl;
return(XDMF_TRUE);
}else{
// cout << "Time Test Failed" << endl;
}
break;
case XDMF_TIME_LIST :
if(!this->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
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;
if(!this->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
if((this->Array->GetValueAsFloat64(0) >= TimeMin) && (this->Array->GetValueAsFloat64(1) <= TimeMax)) return(XDMF_TRUE);
break;
case XDMF_TIME_HYPERSLAB :
if(!this->Array){
XdmfErrorMessage("XdmfTime has no Array");
return(XDMF_FALSE);
}
if((this->Array->GetValueAsFloat64(0) >= TimeMin) &&
((this->Array->GetValueAsFloat64(1) * (this->Array->GetValueAsFloat64(2) - 1)) <= TimeMax)) return(XDMF_TRUE);
break;
default :
return(XDMF_FALSE);
}
return(XDMF_FALSE);
}
......@@ -101,7 +101,11 @@ public:
//! Set Time From Parent Information
XdmfInt32 SetTimeFromParent(XdmfTime *ParentTime, XdmfInt64 Index);
//! Fills in the sets of times that a particular grid is valid.
XdmfInt32 Evaluate(XdmfGrid *Grid, XdmfArray *ArrayToFill = NULL, XdmfInt32 Append = 0);
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);
//! Is Time within Range
XdmfInt32 IsValid(XdmfFloat64 TimeMin, XdmfFloat64 TimeMax);
protected:
XdmfInt32 TimeType;
XdmfFloat64 Value;
......
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