Commit 50470ad0 authored by Andrew Bauer's avatar Andrew Bauer
Browse files

Formatting cleanup which shouldn't affect the code.

I also changed the test that was failing to the proper result
even though the test isn't fixed yet.

Change-Id: I49a9fa27b0fa17005fd41212986839f513d06b3a
parent a00ef388
......@@ -467,9 +467,10 @@ int vtkParticleTracerBase::InitializeInterpolator()
this->AllFixedGeometry = this->AllFixedGeometry && static_dataset;
// add the dataset to the interpolator
this->Interpolator->SetDataSetAtTime(index++, T, this->GetCacheDataTime(T), inp, static_dataset);
if (!this->DataReferenceT[T]) {
if (!this->DataReferenceT[T])
{
this->DataReferenceT[T] = inp;
}
}
//
numValidInputBlocks[T]++;
}
......@@ -641,7 +642,7 @@ void vtkParticleTracerBase::TestParticles(vtkParticleTracerBaseNamespace::Partic
//---------------------------------------------------------------------------
void vtkParticleTracerBase::AssignSeedsToProcessors( double time,
vtkDataSet *source, int sourceID, int ptId,
ParticleVector &LocalSeedPoints, int &LocalAssignedCount)
ParticleVector &localSeedPoints, int &localAssignedCount)
{
ParticleVector candidates;
//
......@@ -676,25 +677,24 @@ void vtkParticleTracerBase::AssignSeedsToProcessors( double time,
//
// Gather all Seeds to all processors for classification
//
this->TestParticles(candidates, LocalSeedPoints, LocalAssignedCount);
int TotalAssigned = LocalAssignedCount; (void)TotalAssigned;
this->TestParticles(candidates, localSeedPoints, localAssignedCount);
// Assign unique identifiers taking into account uneven distribution
// across processes and seeds which were rejected
this->AssignUniqueIds(LocalSeedPoints);
this->AssignUniqueIds(localSeedPoints);
//
}
//---------------------------------------------------------------------------
void vtkParticleTracerBase::AssignUniqueIds(
vtkParticleTracerBaseNamespace::ParticleVector &LocalSeedPoints)
vtkParticleTracerBaseNamespace::ParticleVector &localSeedPoints)
{
vtkIdType ParticleCountOffset = 0;
vtkIdType numParticles = LocalSeedPoints.size();
vtkIdType particleCountOffset = 0;
vtkIdType numParticles = localSeedPoints.size();
for (vtkIdType i=0; i<numParticles; i++)
{
LocalSeedPoints[i].UniqueParticleId =
this->UniqueIdCounter + ParticleCountOffset + i;
localSeedPoints[i].UniqueParticleId =
this->UniqueIdCounter + particleCountOffset + i;
}
this->UniqueIdCounter += numParticles;
}
......@@ -1284,7 +1284,10 @@ bool vtkParticleTracerBase::ComputeDomainExitLocation(
// We found an intersection on the edge of the cell.
// Shift it by a small amount to ensure that it crosses over the edge
// into the adjoining cell.
for (int i=0; i<3; i++) intersection[i] = pos[i] + (t+0.01)*(p2[i]-pos[i]);
for (int i=0; i<3; i++)
{
intersection[i] = pos[i] + (t+0.01)*(p2[i]-pos[i]);
}
// intersection stored, compute T for intersection
intersection[3] = pos[3] + (t+0.01)*(p2[3]-pos[3]);
return 1;
......
......@@ -7,11 +7,11 @@
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
=========================================================================*/
#include "vtkTemporalInterpolatedVelocityField.h"
#include "vtkDataArray.h"
......@@ -59,25 +59,30 @@ void vtkTemporalInterpolatedVelocityField::SetDataSetAtTime(int I, int N, double
{
this->times[N] = T;
if ((this->times[1]-this->times[0])>0)
{
{
this->ScaleCoeff = 1.0/(this->times[1]-this->times[0]);
}
if (N==0) {
}
if (N==0)
{
this->ivf[N]->SetDataSet(I, dataset, staticdataset, NULL);
}
}
// when the datasets for the second time set are added, set the static flag
if (N==1) {
if (N==1)
{
bool is_static = staticdataset && this->ivf[0]->CacheList[I].StaticDataSet;
if ((unsigned int)I>=this->StaticDataSets.size()) {
if (static_cast<size_t>(I)>=this->StaticDataSets.size())
{
this->StaticDataSets.resize(I+1,is_static);
}
if (is_static) {
}
if (is_static)
{
this->ivf[N]->SetDataSet(I, dataset, staticdataset, this->ivf[0]->CacheList[I].BSPTree);
}
else {
}
else
{
this->ivf[N]->SetDataSet(I, dataset, staticdataset, NULL);
}
}
}
}
//---------------------------------------------------------------------------
bool vtkTemporalInterpolatedVelocityField::IsStatic(int datasetIndex)
......@@ -99,15 +104,23 @@ void vtkTemporalInterpolatedVelocityField::ClearCache()
//---------------------------------------------------------------------------
void vtkTemporalInterpolatedVelocityField::SetCachedCellIds(vtkIdType id[2], int ds[2])
{
if (id[0]!=-1) {
if (id[0]!=-1)
{
this->ivf[0]->SetLastCellInfo(id[0], ds[0]);
}
else this->ivf[0]->SetLastCellInfo(-1, 0);
}
else
{
this->ivf[0]->SetLastCellInfo(-1, 0);
}
//
if (id[1]!=-1) {
if (id[1]!=-1)
{
this->ivf[1]->SetLastCellInfo(id[1], ds[1]);
}
else this->ivf[1]->SetLastCellInfo(-1, 0);
}
else
{
this->ivf[1]->SetLastCellInfo(-1, 0);
}
}
//---------------------------------------------------------------------------
bool vtkTemporalInterpolatedVelocityField::GetCachedCellIds(vtkIdType id[2], int ds[2])
......@@ -122,27 +135,30 @@ bool vtkTemporalInterpolatedVelocityField::GetCachedCellIds(vtkIdType id[2], int
//---------------------------------------------------------------------------
void vtkTemporalInterpolatedVelocityField::AdvanceOneTimeStep()
{
for (unsigned int i=0; i<this->ivf[0]->CacheList.size(); i++) {
if (this->IsStatic(i)) {
for (unsigned int i=0; i<this->ivf[0]->CacheList.size(); i++)
{
if (this->IsStatic(i))
{
this->ivf[0]->ClearLastCellInfo();
this->ivf[1]->ClearLastCellInfo();
}
else {
}
else
{
this->ivf[0] = this->ivf[1];
this->ivf[1] = vtkSmartPointer<vtkCachingInterpolatedVelocityField>::New();
}
}
}
}
//---------------------------------------------------------------------------
void vtkTemporalInterpolatedVelocityField::ShowCacheResults()
{
vtkErrorMacro(<< ")\n"
<< "T0 - (cell hit : " << this->ivf[0]->CellCacheHit
<< " (dataset hit : " << this->ivf[0]->DataSetCacheHit-this->ivf[0]->CellCacheHit
<< " (miss : " << this->ivf[0]->CacheMiss << ")\n"
<< "T1 - (cell hit : " << this->ivf[1]->CellCacheHit
<< " (dataset hit : " << this->ivf[1]->DataSetCacheHit-this->ivf[1]->CellCacheHit
<< " (miss : " << this->ivf[1]->CacheMiss);
<< "T0 - (cell hit : " << this->ivf[0]->CellCacheHit
<< " (dataset hit : " << this->ivf[0]->DataSetCacheHit-this->ivf[0]->CellCacheHit
<< " (miss : " << this->ivf[0]->CacheMiss << ")\n"
<< "T1 - (cell hit : " << this->ivf[1]->CellCacheHit
<< " (dataset hit : " << this->ivf[1]->DataSetCacheHit-this->ivf[1]->CellCacheHit
<< " (miss : " << this->ivf[1]->CacheMiss);
}
//---------------------------------------------------------------------------
static double vtkTIVFWeightTolerance = 1E-3;
......@@ -151,75 +167,101 @@ int vtkTemporalInterpolatedVelocityField::TestPoint(double* x)
{
this->CurrentWeight = (x[3]-this->times[0])*this->ScaleCoeff;
this->OneMinusWeight = 1.0 - this->CurrentWeight;
if (this->CurrentWeight<(0.0+vtkTIVFWeightTolerance)) this->CurrentWeight = 0.0;
if (this->CurrentWeight>(1.0-vtkTIVFWeightTolerance)) this->CurrentWeight = 1.0;
if (this->CurrentWeight<(0.0+vtkTIVFWeightTolerance))
{
this->CurrentWeight = 0.0;
}
if (this->CurrentWeight>(1.0-vtkTIVFWeightTolerance))
{
this->CurrentWeight = 1.0;
}
//
// are we inside dataset at T0
//
if (this->ivf[0]->FunctionValues(x, vals1)) {
if (this->ivf[0]->FunctionValues(x, vals1))
{
// if we are inside at T0 and static, we must be inside at T1
if (this->IsStatic(this->ivf[0]->LastCacheIndex)) {
if (this->IsStatic(this->ivf[0]->LastCacheIndex))
{
// compute using weights from dataset 0 and vectors from dataset 1
this->ivf[1]->SetLastCellInfo(this->ivf[0]->LastCellId, this->ivf[0]->LastCacheIndex);
this->ivf[0]->FastCompute(this->ivf[1]->Cache, vals2);
for (int i=0; i<this->NumFuncs; i++) {
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = this->OneMinusWeight*vals1[i] + this->CurrentWeight*vals2[i];
}
}
return ID_INSIDE_ALL;
}
}
// dynamic, we need to test at T1
if (!this->ivf[1]->FunctionValues(x, vals2)) {
if (!this->ivf[1]->FunctionValues(x, vals2))
{
// inside at T0, but outside at T1, return velocity for T0
for (int i=0; i<this->NumFuncs; i++) {
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = vals1[i];
}
}
return ID_OUTSIDE_T1;
}
}
// both valid, compute correct value
for (int i=0; i<this->NumFuncs; i++) {
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = this->OneMinusWeight*vals1[i] + this->CurrentWeight*vals2[i];
}
}
return ID_INSIDE_ALL;
}
}
// Outside at T0, either abort or use T1
else {
else
{
// if we are outside at T0 and static, we must be outside at T1
if (this->IsStatic(this->ivf[0]->LastCacheIndex)) {
if (this->IsStatic(this->ivf[0]->LastCacheIndex))
{
return ID_OUTSIDE_ALL;
}
}
// we are dynamic, so test T1
if (this->ivf[1]->FunctionValues(x, vals2)) {
if (this->ivf[1]->FunctionValues(x, vals2))
{
// inside at T1, but outside at T0, return velocity for T1
for (int i=0; i<this->NumFuncs; i++) {
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = vals2[i];
}
}
return ID_OUTSIDE_T0;
}
}
// failed both, so exit
return ID_OUTSIDE_ALL;
}
}
}
//---------------------------------------------------------------------------
// Evaluate u,v,w at x,y,z,t
int vtkTemporalInterpolatedVelocityField::QuickTestPoint(double* x)
{
// if outside, return 0
if (!this->ivf[0]->InsideTest(x)) return 0;
if (!this->ivf[0]->InsideTest(x))
{
return 0;
}
// if inside and static dataset hit, skip next test
if (!this->IsStatic(this->ivf[0]->LastCacheIndex)) {
if (!this->ivf[1]->InsideTest(x)) return 0;
}
if (!this->IsStatic(this->ivf[0]->LastCacheIndex))
{
if (!this->ivf[1]->InsideTest(x))
{
return 0;
}
}
return 1;
}
//---------------------------------------------------------------------------
// Evaluate u,v,w at x,y,z,t
int vtkTemporalInterpolatedVelocityField::FunctionValues(double* x, double* u)
{
if (this->TestPoint(x)==ID_OUTSIDE_ALL) return 0;
//
for (int i=0; i<this->NumFuncs; i++) {
if (this->TestPoint(x)==ID_OUTSIDE_ALL)
{
return 0;
}
for (int i=0; i<this->NumFuncs; i++)
{
u[i] = this->LastGoodVelocity[i];
}
}
return 1;
}
//---------------------------------------------------------------------------
......@@ -228,33 +270,45 @@ int vtkTemporalInterpolatedVelocityField::FunctionValuesAtT(int T, double* x, do
//
// Try velocity at T0
//
if (T==0) {
if (!this->ivf[0]->FunctionValues(x, vals1)) return 0;
for (int i=0; i<this->NumFuncs; i++) {
if (T==0)
{
if (!this->ivf[0]->FunctionValues(x, vals1))
{
return 0;
}
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = u[i] = vals1[i];
}
if (this->IsStatic(this->ivf[0]->LastCacheIndex)) {
}
if (this->IsStatic(this->ivf[0]->LastCacheIndex))
{
this->ivf[1]->SetLastCellInfo(this->ivf[0]->LastCellId, this->ivf[0]->LastCacheIndex);
}
}
}
//
// Try velocity at T1
//
else if (T==1) {
if (!this->ivf[1]->FunctionValues(x, vals2)) return 0;
for (int i=0; i<this->NumFuncs; i++) {
else if (T==1)
{
if (!this->ivf[1]->FunctionValues(x, vals2))
{
return 0;
}
for (int i=0; i<this->NumFuncs; i++)
{
this->LastGoodVelocity[i] = u[i] = vals2[i];
}
if (this->IsStatic(this->ivf[1]->LastCacheIndex)) {
}
if (this->IsStatic(this->ivf[1]->LastCacheIndex))
{
this->ivf[0]->SetLastCellInfo(this->ivf[1]->LastCellId, this->ivf[1]->LastCacheIndex);
}
}
}
return 1;
}
//---------------------------------------------------------------------------
bool vtkTemporalInterpolatedVelocityField::InterpolatePoint(
vtkPointData *outPD1, vtkPointData *outPD2,
vtkIdType outIndex)
vtkPointData *outPD1, vtkPointData *outPD2,
vtkIdType outIndex)
{
bool ok1 = this->ivf[0]->InterpolatePoint(outPD1, outIndex);
bool ok2 = this->ivf[1]->InterpolatePoint(outPD2, outIndex);
......@@ -265,7 +319,10 @@ bool vtkTemporalInterpolatedVelocityField::InterpolatePoint(
int T, vtkPointData *outPD1, vtkIdType outIndex)
{
// force use of correct weights/etc if static as only T0 are valid
if (T==1 && this->IsStatic(this->ivf[T]->LastCacheIndex)) T=0;
if (T==1 && this->IsStatic(this->ivf[T]->LastCacheIndex))
{
T=0;
}
//
return this->ivf[T]->InterpolatePoint(outPD1, outIndex);
}
......@@ -275,18 +332,21 @@ bool vtkTemporalInterpolatedVelocityField::GetVorticityData(
vtkGenericCell *&cell, vtkDoubleArray *cellVectors)
{
// force use of correct weights/etc if static as only T0 are valid
if (T==1 && this->IsStatic(this->ivf[T]->LastCacheIndex)) T=0;
if (T==1 && this->IsStatic(this->ivf[T]->LastCacheIndex))
{
T=0;
}
//
if (this->ivf[T]->GetLastWeights(weights) &&
this->ivf[T]->GetLastLocalCoordinates(pcoords) &&
(cell=this->ivf[T]->GetLastCell()) )
{
{
vtkDataSet *ds = this->ivf[T]->Cache->DataSet;
vtkPointData *pd = ds->GetPointData();
vtkDataArray *da = pd->GetVectors(this->ivf[T]->GetVectorsSelection());
da->GetTuples(cell->PointIds, cellVectors);
return 1;
}
}
return 0;
}
//---------------------------------------------------------------------------
......@@ -295,9 +355,9 @@ void vtkTemporalInterpolatedVelocityField::PrintSelf(ostream& os, vtkIndent inde
this->Superclass::PrintSelf(os, indent);
os << indent << "LastGoodVelocity: "
<< this->LastGoodVelocity[0] << ", "
<< this->LastGoodVelocity[1] << ", "
<< this->LastGoodVelocity[2] << endl;
<< this->LastGoodVelocity[0] << ", "
<< this->LastGoodVelocity[1] << ", "
<< this->LastGoodVelocity[2] << endl;
os << indent << "CurrentWeight: " << this->CurrentWeight << endl;
}
//---------------------------------------------------------------------------
......@@ -12,30 +12,29 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPParticleTracer.h"
#include "vtkPParticlePathFilter.h"
#include "vtkPStreaklineFilter.h"
#include "vtkMPIController.h"
#include "vtkIdList.h"
#include "vtkPoints.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPolyDataMapper.h"
#include "vtkCellArray.h"
#include "vtkAlgorithm.h"
#include "vtkCellArray.h"
#include "vtkFloatArray.h"
#include "vtkIdList.h"
#include "vtkImageData.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkImageData.h"
#include "vtkMPIController.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkPolyDataMapper.h"
#include "vtkPParticlePathFilter.h"
#include "vtkPParticleTracer.h"
#include "vtkPStreaklineFilter.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include <vector>
#define PRINT(x) cout<<"("<<Rank<<")"<<x<<endl;
#define EXPECT(a,msg)\
if(!(a)) { \
cerr<<"Line "<<__LINE__<<":"<<msg<<endl;\
#define EXPECT(expected,actual,msg,so) \
if(!(expected == actual)) { \
vtkGenericWarningMacro(<<msg<< " Expecting a value of " << expected << \
" but getting a value of " << actual << " for static option of " << so); \
return EXIT_FAILURE;\
}
......@@ -113,19 +112,19 @@ protected:
this->TimeSteps.push_back(i);
}
Extent[0] = 0;
Extent[1] = 1;
Extent[2] = 0;
Extent[3] = 1;
Extent[4] = 0;
Extent[5] = 1;
BoundingBox[0]=0;
BoundingBox[1]=1;
BoundingBox[2]=0;
BoundingBox[3]=1;
BoundingBox[4]=0;
BoundingBox[5]=1;
this->Extent[0] = 0;
this->Extent[1] = 1;
this->Extent[2] = 0;
this->Extent[3] = 1;
this->Extent[4] = 0;
this->Extent[5] = 1;
this->BoundingBox[0]=0;
this->BoundingBox[1]=1;
this->BoundingBox[2]=0;
this->BoundingBox[3]=1;
this->BoundingBox[4]=0;
this->BoundingBox[5]=1;
}
......@@ -175,7 +174,7 @@ protected:
range,2);
outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
&TimeSteps[0], static_cast<int>(TimeSteps.size()));
&this->TimeSteps[0], static_cast<int>(this->TimeSteps.size()));
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), this->Extent,6);
......@@ -219,7 +218,7 @@ protected:
return 0 ;
}
vtkDataArray* outArray = vtkDataArray::SafeDownCast(vtkAbstractArray::CreateArray(VTK_FLOAT));
vtkFloatArray* outArray = vtkFloatArray::New();
outArray->SetName("Gradients");
outArray->SetNumberOfComponents(3);
outArray->SetNumberOfTuples(outImage->GetNumberOfPoints());
......@@ -263,7 +262,7 @@ protected:
outPtr += stepZ;
}
vtkDataArray* outArray1 = vtkDataArray::SafeDownCast(vtkAbstractArray::CreateArray(VTK_FLOAT));
vtkFloatArray* outArray1 = vtkFloatArray::New();
outArray1->SetName("Test");
outArray1->SetNumberOfComponents(1);
outArray1->SetNumberOfTuples(outImage->GetNumberOfPoints());
......@@ -289,14 +288,8 @@ private:
vtkStandardNewMacro(TestTimeSource);
int TestPParticleTracer(vtkMPIController* c)
int TestPParticleTracer(vtkMPIController* c, int staticOption)
{
int NumProcs = c->GetNumberOfProcesses();
int Rank = c->GetLocalProcessId();
vtkNew<TestTimeSource> imageSource;
int size(5);
imageSource->SetExtent(0,size-1,0,1,0,size-1);
......@@ -310,6 +303,8 @@ int TestPParticleTracer(vtkMPIController* c)
ps->SetPoints(points.GetPointer());
vtkNew<vtkPParticleTracer> filter;
filter->SetStaticMesh(staticOption);
filter->SetStaticSeeds(staticOption);
filter->SetInputConnection(0,imageSource->GetOutputPort());
filter->SetInputData(1,ps.GetPointer());
filter->SetStartTime(0.0);
......@@ -334,8 +329,8 @@ int TestPParticleTracer(vtkMPIController* c)
vtkSmartPointer<vtkPolyDataMapper> traceMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
traceMapper->SetInputConnection(filter->GetOutputPort());
traceMapper->SetPiece(Rank);
traceMapper->SetNumberOfPieces(NumProcs);
traceMapper->SetPiece(c->GetLocalProcessId());
traceMapper->SetNumberOfPieces(c->GetNumberOfProcesses());
traceMapper->Update();
vtkPolyData* out = filter->GetOutput();
......@@ -344,23 +339,20 @@ int TestPParticleTracer(vtkMPIController* c)
numTraced+= pts->GetNumberOfPoints();
}
if(Rank==0)
if(c->GetLocalProcessId()==0)
{
EXPECT(numTraced==5,"wrong number of points traced: "<<numTraced);
EXPECT(5, numTraced, "PParticleTracer: wrong number of points.", staticOption);
}