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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkSPHKernel.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
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.
=========================================================================*/
#include "vtkSPHKernel.h"
#include "vtkAbstractPointLocator.h"
#include "vtkObjectFactory.h"
#include "vtkIdList.h"
#include "vtkDoubleArray.h"
#include "vtkFloatArray.h"
#include "vtkDataArray.h"
#include "vtkDataSet.h"
#include "vtkMath.h"
vtkCxxSetObjectMacro(vtkSPHKernel,CutoffArray,vtkDataArray);
vtkCxxSetObjectMacro(vtkSPHKernel,DensityArray,vtkDataArray);
vtkCxxSetObjectMacro(vtkSPHKernel,MassArray,vtkDataArray);
//----------------------------------------------------------------------------
vtkSPHKernel::vtkSPHKernel()
{
this->RequiresInitialization = true;
this->SpatialStep = 0.001;
this->Dimension = 3;
this->CutoffArray = NULL;
this->DensityArray = NULL;
this->MassArray = NULL;
}
//----------------------------------------------------------------------------
vtkSPHKernel::~vtkSPHKernel()
{
this->SetCutoffArray(NULL);
this->SetDensityArray(NULL);
this->SetMassArray(NULL);
}
//----------------------------------------------------------------------------
// At this point, the spatial step, the dimension of the kernel, the cutoff
// factor, and the sigma normalization factor should be known.
void vtkSPHKernel::
Initialize(vtkAbstractPointLocator *loc, vtkDataSet *ds, vtkPointData *attr)
{
this->Superclass::Initialize(loc, ds, attr);
// this->CutoffFactor should have been set by subclass
this->Cutoff = this->CutoffFactor * this->SpatialStep;
this->DistNorm = 1.0 / this->SpatialStep;
this->NormFactor = this->Sigma * pow(this->DistNorm,this->Dimension);
this->DefaultVolume = pow(this->SpatialStep,this->Dimension);
// See if cutoff array is provided.
if ( this->CutoffArray && this->CutoffArray->GetNumberOfComponents() == 1 )
{
this->UseCutoffArray = true;
}
else
{
this->UseCutoffArray = false;
}
// See if local mass and density information is provided
if ( this->DensityArray && this->MassArray &&
this->DensityArray->GetNumberOfComponents() == 1 &&
this->MassArray->GetNumberOfComponents() == 1 )
{
this->UseArraysForVolume = true;
}
else
{
this->UseArraysForVolume = false;
}
}
//----------------------------------------------------------------------------
// Radius around point is cutoff factor * smoothing length. That is unless
// cutoff array is provided.
vtkIdType vtkSPHKernel::
ComputeBasis(double x[3], vtkIdList *pIds, vtkIdType ptId)
{
double cutoff;
if ( this->UseCutoffArray )
{
this->CutoffArray->GetTuple(ptId,&cutoff);
}
else
{
cutoff = this->Cutoff;
}
this->Locator->FindPointsWithinRadius(cutoff, x, pIds);
return pIds->GetNumberOfIds();
}
//----------------------------------------------------------------------------
vtkIdType vtkSPHKernel::
ComputeWeights(double x[3], vtkIdList *pIds, vtkDoubleArray *weights)
{
vtkIdType numPts = pIds->GetNumberOfIds();
int i;
vtkIdType id;
double d, y[3];
weights->SetNumberOfTuples(numPts);
double *w = weights->GetPointer(0);
double KW, mass, density, volume;
// Compute SPH coefficients.
for (i=0; i<numPts; ++i)
{
id = pIds->GetId(i);
this->DataSet->GetPoint(id,y);
d = sqrt( vtkMath::Distance2BetweenPoints(x,y) );
KW = this->ComputeFunctionWeight(d*this->DistNorm);
if ( this->UseArraysForVolume )
{
this->MassArray->GetTuple(id,&mass);
this->DensityArray->GetTuple(id,&density);
volume = mass /density;
}
else
{
volume = this->DefaultVolume;
}
w[i] = this->NormFactor * KW * volume;
}//over all neighbor points
return numPts;
}
//----------------------------------------------------------------------------
vtkIdType vtkSPHKernel::
ComputeDerivWeights(double x[3], vtkIdList *pIds, vtkDoubleArray *weights,
vtkDoubleArray *gradWeights)
{
vtkIdType numPts = pIds->GetNumberOfIds();
int i;
vtkIdType id;
double d, y[3];
weights->SetNumberOfTuples(numPts);
double *w = weights->GetPointer(0);
gradWeights->SetNumberOfTuples(numPts);
double *gw = gradWeights->GetPointer(0);
double KW, GW, volume=this->DefaultVolume;
// Compute SPH coefficients for data and deriative data
for (i=0; i<numPts; ++i)
{
id = pIds->GetId(i);
this->DataSet->GetPoint(id,y);
d = sqrt( vtkMath::Distance2BetweenPoints(x,y) );
KW = this->ComputeFunctionWeight(d*this->DistNorm);
GW = this->ComputeDerivWeight(d*this->DistNorm);
w[i] = this->NormFactor * KW * volume;
gw[i] = this->NormFactor * GW * volume;
}//over all neighbor points
return numPts;
}
//----------------------------------------------------------------------------
void vtkSPHKernel::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "Spatial Step: " << this->SpatialStep << "\n";
os << indent << "Dimension: " << this->Dimension << "\n";
os << indent << "Cutoff Factor: " << this->CutoffFactor << "\n";
os << indent << "Sigma: " << this->Sigma << "\n";
os << indent << "Cutoff Array: " << this->CutoffArray<< "\n";
os << indent << "Density Array: " << this->DensityArray << "\n";
os << indent << "Mass Array: " << this->MassArray << "\n";
}
|