VMTK
Loading...
Searching...
No Matches
vtkvmtkMeshWallShearRate.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkMeshWallShearRate.cxx,v $
5Language: C++
6Date: $Date: 2020/02/17 10:20:00 $
7Version: $Revision: 2.0 $
8
9 Copyright (c) Luca Antiga, David Steinman. All rights reserved.
10 See LICENSE file for details.
11
12 Portions of this code are covered under the VTK copyright.
13 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm
14 for details.
15
16 This software is distributed WITHOUT ANY WARRANTY; without even
17 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18 PURPOSE. See the above copyright notices for more information.
19
20=========================================================================*/
21
23
25
26#include "vtkUnstructuredGrid.h"
27#include "vtkPolyData.h"
28#include "vtkPointData.h"
29#include "vtkCellData.h"
30#include "vtkDoubleArray.h"
31#include "vtkMath.h"
32#include "vtkGeometryFilter.h"
33#include "vtkPolyDataNormals.h"
34#include "vtkInformation.h"
35#include "vtkInformationVector.h"
36#include "vtkObjectFactory.h"
37#include "vtkVersion.h"
38
39
41
51
53{
54 if (this->VelocityArrayName)
55 {
56 delete[] this->VelocityArrayName;
57 this->VelocityArrayName = NULL;
58 }
59 if (this->WallShearRateArrayName)
60 {
61 delete[] this->WallShearRateArrayName;
62 this->WallShearRateArrayName = NULL;
63 }
64}
65
67{
68 info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(), "vtkUnstructuredGrid");
69 return 1;
70}
71
73 vtkInformation *vtkNotUsed(request),
74 vtkInformationVector **inputVector,
75 vtkInformationVector *outputVector)
76{
77 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
78 vtkInformation *outInfo = outputVector->GetInformationObject(0);
79
80 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
81 inInfo->Get(vtkDataObject::DATA_OBJECT()));
82 vtkPolyData *output = vtkPolyData::SafeDownCast(
83 outInfo->Get(vtkDataObject::DATA_OBJECT()));
84
85 if (this->VelocityArrayName == NULL)
86 {
87 vtkErrorMacro("VelocityArrayName not specified");
88 return 1;
89 }
90
91 vtkDataArray* velocityArray = input->GetPointData()->GetArray(this->VelocityArrayName);
92
93 if (velocityArray == NULL)
94 {
95 vtkErrorMacro("VelocityArray with name specified does not exist");
96 return 1;
97 }
98
99 char gradientArrayName[] = "VelocityGradient";
100
102 gradientFilter->SetInputData(input);
103 gradientFilter->SetInputArrayName(this->VelocityArrayName);
104 gradientFilter->SetGradientArrayName(gradientArrayName);
105 gradientFilter->SetQuadratureOrder(this->QuadratureOrder);
106 gradientFilter->SetConvergenceTolerance(this->ConvergenceTolerance);
108 gradientFilter->Update();
109
110 vtkGeometryFilter* geometryFilter = vtkGeometryFilter::New();
111 geometryFilter->SetInputConnection(gradientFilter->GetOutputPort());
112 geometryFilter->Update();
113
114 // Since VTK 9.4, vtkPolyDataNormals passes pre-existing normals through
115 // unchanged instead of recomputing them; strip normals inherited from the
116 // mesh so consistently outward-oriented normals are always recomputed.
117 vtkPolyData* surfaceWithoutNormals = vtkPolyData::New();
118 surfaceWithoutNormals->ShallowCopy(geometryFilter->GetOutput());
119 surfaceWithoutNormals->GetPointData()->SetNormals(NULL);
120 surfaceWithoutNormals->GetCellData()->SetNormals(NULL);
121
122 vtkPolyDataNormals* normalsFilter = vtkPolyDataNormals::New();
123 normalsFilter->SetInputData(surfaceWithoutNormals);
124 surfaceWithoutNormals->Delete();
125 normalsFilter->AutoOrientNormalsOn();
126 normalsFilter->ConsistencyOn();
127 normalsFilter->SplittingOff();
128 normalsFilter->Update();
129
130 vtkPolyData* outputSurface = normalsFilter->GetOutput();
131
132 vtkDataArray* velocityGradientArray = outputSurface->GetPointData()->GetArray(gradientArrayName);
133 vtkDataArray* normalsArray = outputSurface->GetPointData()->GetNormals();
134
135 int numberOfPoints = outputSurface->GetNumberOfPoints();
136
137 vtkDoubleArray* wallShearRateArray = vtkDoubleArray::New();
138 if (this->WallShearRateArrayName)
139 {
140 wallShearRateArray->SetName(this->WallShearRateArrayName);
141 }
142 else
143 {
144 wallShearRateArray->SetName("WallShearRate");
145 }
146 wallShearRateArray->SetNumberOfComponents(3);
147 wallShearRateArray->SetNumberOfTuples(numberOfPoints);
148
149 double velocityGradient[9];
150 double normal[3];
151 double wallShearRate[3];
152
153 int i, j, k;
154
155 if (!this->UseFullStrainRateTensor)
156 {
157 for (i=0; i<numberOfPoints; i++)
158 {
159 velocityGradientArray->GetTuple(i,velocityGradient);
160 normalsArray->GetTuple(i,normal);
161 for (j=0; j<3; j++)
162 {
163 wallShearRate[j] = -normal[0] * velocityGradient[3*j + 0] - normal[1] * velocityGradient[3*j + 1] - normal[2] * velocityGradient[3*j + 2];
164 }
165 wallShearRateArray->SetTuple(i,wallShearRate);
166 }
167 }
168 else
169 {
170
171 /**********************************************************************
172 Calculate strain rate tensor: E = 0.5 * (\nabla u + (\nabla u)^T)
173 Calculate wall shear rate vector: tau = -2 * E*n * (1-n^T*n)
174 Reference: Matyka et al., http://dx.doi.org/10.1016/j.compfluid.2012.12.018
175 **********************************************************************/
176
177 double normalShear, shearVector[3], strainRateTensor[9];
178
179 for (i=0; i<numberOfPoints; i++)
180 {
181
182 // compute strain rate tensor
183 velocityGradientArray->GetTuple(i,velocityGradient);
184 for (j=0; j<3; j++)
185 {
186 for (k=0; k<3; k++)
187 {
188 strainRateTensor[3*j + k] = 0.5 * (velocityGradient[3*j + k] + velocityGradient[3*k + j]);
189 }
190 }
191
192 // compute shear rate vector and normal projection
193 normalsArray->GetTuple(i,normal);
194 normalShear = 0.0;
195 for (j=0; j<3; j++)
196 {
197 shearVector[j] = 0.0;
198 for (k=0; k<3; k++)
199 {
200 shearVector[j] += strainRateTensor[3*j + k] * normal[k];
201 }
202 normalShear += shearVector[j] * normal[j];
203 }
204
205 // compute wall shear rate
206 for (j=0; j<3; j++)
207 {
208 // sign due to normals pointing outwards
209 wallShearRate[j] = -2.0 * (shearVector[j] - normalShear*normal[j]);
210 }
211
212 wallShearRateArray->SetTuple(i,wallShearRate);
213 }
214 }
215
216 output->DeepCopy(outputSurface);
217 output->GetPointData()->AddArray(wallShearRateArray);
218
219 wallShearRateArray->Delete();
220 geometryFilter->Delete();
221 normalsFilter->Delete();
222
223 return 1;
224}
225
226void vtkvmtkMeshWallShearRate::PrintSelf(std::ostream& os, vtkIndent indent)
227{
228 this->Superclass::PrintSelf(os,indent);
229}
Calculates wall shear rate from velocity components in a mesh.
int FillInputPortInformation(int, vtkInformation *info) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
Compute the gradient of data stored within an unstructured grid mesh.
virtual void SetComputeIndividualPartialDerivatives(int)
virtual void SetInputArrayName(const char *)
virtual void SetGradientArrayName(const char *)
virtual void SetConvergenceTolerance(double)
static vtkvmtkUnstructuredGridGradientFilter * New()
vtkStandardNewMacro(vtkvmtkMeshWallShearRate)