Skip to content
Snippets Groups Projects
Commit 2669937a authored by Nicolas Vuaille's avatar Nicolas Vuaille
Browse files

Add a RelativeMode

parent 15f2b117
No related branches found
No related tags found
No related merge requests found
## Relative Mode for vtkTemporalArrayOperatorFilter
The vtkTemporalArrayOperatorFilter now has a `RelativeMode`, where it uses `UPDATE_TIME_STEP` time as first value alongside to a `TimeStepShift` shifted value, instead of two static time steps.
### Behavior Breaking Change
This filter was inconsistent on which input mesh and arrays were forwarded to output: Composite data used first input, while non composite used second.
The forwarded data is now the one given by `FirstTimeStepIndex` when `RelativeMode` is off or by `UPDATE_TIME_STEP` otherwise, as Composite used to do.
### Build Breaking Change
The protected variable members where moved to private. From inherited classes, please use Getter/Setter instead.
......@@ -108,11 +108,41 @@ int vtkTemporalArrayOperatorFilter::RequestInformation(vtkInformation* vtkNotUse
}
double* inputTimes = inputInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
double meshTime = inputTimes[this->FirstTimeStepIndex];
double outTime[1] = { meshTime };
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), outTime, 1);
double timeRange[2] = { meshTime, meshTime };
double timeRange[2] = { inputTimes[0], inputTimes[this->NumberTimeSteps - 1] };
if (this->RelativeMode)
{
int absoluteShift = std::abs(this->TimeStepShift);
if (absoluteShift >= this->NumberTimeSteps)
{
vtkErrorMacro(
<< "Shift is too big: second timestep is always out of range. Absolute max is "
<< this->NumberTimeSteps);
return 0;
}
int outNumberTimeSteps = this->NumberTimeSteps - absoluteShift;
if (this->TimeStepShift < 0)
{
// skip first timesteps
timeRange[0] = inputTimes[absoluteShift];
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), &inputTimes[absoluteShift],
outNumberTimeSteps);
}
else
{
// skip last timesteps
outInfo->Set(
vtkStreamingDemandDrivenPipeline::TIME_STEPS(), inputTimes, outNumberTimeSteps);
timeRange[1] = inputTimes[outNumberTimeSteps - 1];
}
}
else
{
double meshTime = inputTimes[this->FirstTimeStepIndex];
double outTime[1] = { meshTime };
timeRange[0] = meshTime;
timeRange[1] = meshTime;
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), outTime, 1);
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2);
}
else
......@@ -124,23 +154,52 @@ int vtkTemporalArrayOperatorFilter::RequestInformation(vtkInformation* vtkNotUse
return 1;
}
//------------------------------------------------------------------------------
void vtkTemporalArrayOperatorFilter::GetTimeStepsToUse(int timeSteps[2])
{
if (this->RelativeMode)
{
vtkInformation* outInfo = this->GetOutputInformation(0);
double requestedTime = 0;
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
requestedTime = outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP());
}
vtkInformation* inputInfo = this->GetInputInformation();
double* inputTime = inputInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
assert(inputTime);
for (int step = 0; step < this->NumberTimeSteps && inputTime[step] <= requestedTime; step++)
{
timeSteps[0] = step;
}
timeSteps[1] = timeSteps[0] + this->TimeStepShift;
}
else
{
timeSteps[0] = this->FirstTimeStepIndex;
timeSteps[1] = this->SecondTimeStepIndex;
}
}
//------------------------------------------------------------------------------
int vtkTemporalArrayOperatorFilter::RequestUpdateExtent(vtkInformation* vtkNotUsed(request),
vtkInformationVector** inputInfoVector, vtkInformationVector* outputInfoVector)
{
if (this->FirstTimeStepIndex < 0 || this->SecondTimeStepIndex < 0 ||
this->FirstTimeStepIndex >= this->NumberTimeSteps ||
this->SecondTimeStepIndex >= this->NumberTimeSteps)
int timeSteps[2];
this->GetTimeStepsToUse(timeSteps);
if (timeSteps[0] < 0 || timeSteps[1] < 0 || timeSteps[0] >= this->NumberTimeSteps ||
timeSteps[1] >= this->NumberTimeSteps)
{
vtkErrorMacro(<< "Specified timesteps (" << this->FirstTimeStepIndex << " and "
<< this->SecondTimeStepIndex
vtkErrorMacro(<< "Specified timesteps (" << timeSteps[0] << " and " << timeSteps[1] << ") "
<< "are outside the range of"
" available time steps ("
<< this->NumberTimeSteps << ")");
return 0;
}
if (this->FirstTimeStepIndex == this->SecondTimeStepIndex)
if (timeSteps[0] == timeSteps[1])
{
vtkWarningMacro(<< "First and second time steps are the same.");
}
......@@ -150,17 +209,13 @@ int vtkTemporalArrayOperatorFilter::RequestUpdateExtent(vtkInformation* vtkNotUs
if (outputInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()))
{
vtkInformation* inputInfo = inputInfoVector[0]->GetInformationObject(0);
// Get the available input times
double* inputTime = inputInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS());
if (inputTime)
{
// Request the two time steps upstream
double inputUpdateTimes[2] = { inputTime[this->FirstTimeStepIndex],
inputTime[this->SecondTimeStepIndex] };
assert(inputTime);
inputInfo->Set(vtkMultiTimeStepAlgorithm::UPDATE_TIME_STEPS(), inputUpdateTimes, 2);
}
double inputUpdateTimes[2] = { inputTime[timeSteps[0]], inputTime[timeSteps[1]] };
inputInfo->Set(vtkMultiTimeStepAlgorithm::UPDATE_TIME_STEPS(), inputUpdateTimes, 2);
}
return 1;
}
......
......@@ -68,6 +68,36 @@ public:
vtkGetStringMacro(OutputArrayNameSuffix);
///@}
///@{
/**
* Set / Get relative mode.
* When relative mode is true, this filter operates between the timestep requested
* by the pipeline and a shifted timestep.
* When relative mode is false absolute timesteps are used as set by SetFirstTimeStepIndex and
* SetSecondTimeStepIndex. In that case current pipeline time request is ignored.
*
* Default is false.
*
* @see SetTimeStepShift
*/
vtkSetMacro(RelativeMode, bool);
vtkGetMacro(RelativeMode, bool);
vtkBooleanMacro(RelativeMode, bool);
///}
///@{
/**
* Set / Get the timestep shift.
* When RelativeMode is true, TimeStepShift is used to get the second
* timestep to use, relatively to pipeline time.
* Default is -1 (uses previous timestep)
*
* @see SetRelativeMode
*/
vtkSetMacro(TimeStepShift, int);
vtkGetMacro(TimeStepShift, int);
/// @}
protected:
vtkTemporalArrayOperatorFilter();
~vtkTemporalArrayOperatorFilter() override;
......@@ -95,11 +125,21 @@ private:
*/
std::string GetOperatorAsString();
/**
* Compute first and second timesteps.
* If RelativeMode is false, simply set First and SecondTimeStepIndex
* If RelativeMode is true, use input and output information associated to TimeStepShfit.
*/
void GetTimeStepsToUse(int timeSteps[2]);
int Operator = OperatorType::ADD;
int FirstTimeStepIndex = 0;
int SecondTimeStepIndex = 0;
int NumberTimeSteps = 0;
char* OutputArrayNameSuffix = nullptr;
bool RelativeMode = false;
int TimeStepShift = -1;
};
VTK_ABI_NAMESPACE_END
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment