1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
#include "vtkAMRInterpolatedVelocityField.h"
#include "vtkObjectFactory.h"
#include "vtkUniformGrid.h"
#include "vtkOverlappingAMR.h"
#include <cassert>
//----------------------------------------------------------------------------
namespace
{
bool Inside(double q[3], double gbounds[6])
{
if ((q[0] < gbounds[0]) || (q[0] > gbounds[1]) ||
(q[1] < gbounds[2]) || (q[1] > gbounds[3]) ||
(q[2] < gbounds[4]) || (q[2] > gbounds[5]))
{
return false;
}
else
{
return true;
}
}
bool FindInLevel(double q[3], vtkOverlappingAMR *amrds, int level, unsigned int& gridId)
{
for(unsigned int i = 0; i < amrds->GetNumberOfDataSets(level); i++ )
{
double gbounds[6];
amrds->GetBounds(level,i,gbounds);
bool inside = Inside(q,gbounds);
if(inside)
{
gridId = i;
return true;
}
}
return false;
}
};
bool vtkAMRInterpolatedVelocityField::FindGrid(double q[3],vtkOverlappingAMR *amrds,
unsigned int& level, unsigned int& gridId)
{
if (!FindInLevel(q, amrds, 0,gridId))
{
return false;
}
unsigned int maxLevels = amrds->GetNumberOfLevels();
for(level=0; level<maxLevels;level++)
{
unsigned int n;
unsigned int *children = amrds->GetChildren(level, gridId,n);
if (children == NULL)
{
break;
}
unsigned int i;
for (i = 0; i < n; i++)
{
double bb[6];
amrds->GetBounds(level+1, children[i],bb);
if(Inside(q,bb))
{
gridId = children[i];
break;
}
}
if(i>=n)
{
break;
}
}
return true;
}
vtkStandardNewMacro(vtkAMRInterpolatedVelocityField);
vtkAMRInterpolatedVelocityField::vtkAMRInterpolatedVelocityField()
{
this->Weights = new double[8];
this->AmrDataSet = NULL;
this->LastLevel= this->LastId=-1;
}
vtkAMRInterpolatedVelocityField::~vtkAMRInterpolatedVelocityField()
{
delete [] this->Weights;
this->Weights = NULL;
}
void vtkAMRInterpolatedVelocityField::PrintSelf( ostream & os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
}
void vtkAMRInterpolatedVelocityField::SetAMRData(vtkOverlappingAMR* amrds)
{
this->AmrDataSet = amrds;
}
int vtkAMRInterpolatedVelocityField::FunctionValues( double * x, double * f )
{
if(this->LastDataSet &&
this->FunctionValues(this->LastDataSet,x,f))
{
return 1;
}
//Either we do not know which data set it is, or existing LastDataSet does not contain x
//In any case, set LastDataSet to NULL and try to find a new one
this->LastDataSet = NULL;
this->LastCellId = -1;
this->LastLevel = -1;
this->LastId = -1;
unsigned int level, gridId;
if(!FindGrid(x,this->AmrDataSet,level,gridId))
{
return 0;
}
this->LastLevel = level;
this->LastId = gridId;
vtkDataSet* ds = this->AmrDataSet->GetDataSet(level,gridId);
if(!ds)
{
return 0;
}
if(!this->FunctionValues(ds,x,f))
{
return 0;
}
this->LastDataSet = ds;
return 1;
}
bool vtkAMRInterpolatedVelocityField::SetLastDataSet(int level, int id)
{
this->LastLevel = level;
this->LastId = id;
this->LastDataSet = this->AmrDataSet->GetDataSet(level,id);
return this->LastDataSet!=NULL;
}
void vtkAMRInterpolatedVelocityField::SetLastCellId(vtkIdType, int )
{
vtkWarningMacro("Calling SetLastCellId has no effect")
}
bool vtkAMRInterpolatedVelocityField::GetLastDataSetLocation(unsigned int& level, unsigned int& id)
{
if(this->LastLevel<0)
{
return false;
}
level = static_cast<unsigned int>( this->LastLevel );
id = static_cast<unsigned int> ( this->LastId );
return true;
}
|