VMTK
Loading...
Searching...
No Matches
vtkvmtkMeshLambda2.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkMeshLambda2.cxx,v $
5Language: C++
6Date: $Date: 2006/07/27 08:28:36 $
7Version: $Revision: 1.1 $
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
22#include "vtkvmtkMeshLambda2.h"
23
25
26#include "vtkUnstructuredGrid.h"
27#include "vtkPointData.h"
28#include "vtkDoubleArray.h"
29#include "vtkMath.h"
30#include "vtkInformation.h"
31#include "vtkInformationVector.h"
32#include "vtkObjectFactory.h"
33#include "vtkVersion.h"
34
35
37
47
49{
50 if (this->VelocityArrayName)
51 {
52 delete[] this->VelocityArrayName;
53 this->VelocityArrayName = NULL;
54 }
55 if (this->Lambda2ArrayName)
56 {
57 delete[] this->Lambda2ArrayName;
58 this->Lambda2ArrayName = NULL;
59 }
60}
61
63 vtkInformation *vtkNotUsed(request),
64 vtkInformationVector **inputVector,
65 vtkInformationVector *outputVector)
66{
67 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
68 vtkInformation *outInfo = outputVector->GetInformationObject(0);
69
70 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
71 inInfo->Get(vtkDataObject::DATA_OBJECT()));
72 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
73 outInfo->Get(vtkDataObject::DATA_OBJECT()));
74
75 if (this->VelocityArrayName == NULL)
76 {
77 vtkErrorMacro("VelocityArrayName not specified");
78 return 1;
79 }
80
81 vtkDataArray* velocityArray = input->GetPointData()->GetArray(this->VelocityArrayName);
82
83 if (velocityArray == NULL)
84 {
85 vtkErrorMacro("VelocityArray with name specified does not exist");
86 return 1;
87 }
88
89 char gradientArrayName[] = "VelocityGradient";
90
92 gradientFilter->SetInputData(input);
93 gradientFilter->SetInputArrayName(this->VelocityArrayName);
94 gradientFilter->SetGradientArrayName(gradientArrayName);
95 gradientFilter->SetQuadratureOrder(this->QuadratureOrder);
96 gradientFilter->SetConvergenceTolerance(this->ConvergenceTolerance);
98 gradientFilter->Update();
99
100 vtkDataArray* velocityGradientArray = gradientFilter->GetOutput()->GetPointData()->GetArray(gradientArrayName);
101
102 int numberOfPoints = input->GetNumberOfPoints();
103
104 vtkDoubleArray* lambda2Array = vtkDoubleArray::New();
105 if (this->Lambda2ArrayName)
106 {
107 lambda2Array->SetName(this->Lambda2ArrayName);
108 }
109 else
110 {
111 lambda2Array->SetName("Lambda2");
112 }
113 lambda2Array->SetNumberOfComponents(1);
114 lambda2Array->SetNumberOfTuples(numberOfPoints);
115
116 double velocityGradient[9];
117 double symmetricVelocityGradient[3][3];
118 double antiSymmetricVelocityGradient[3][3];
119 double A[3][3];
120
121 int i, j, k, l;
122 for (i=0; i<numberOfPoints; i++)
123 {
124 velocityGradientArray->GetTuple(i,velocityGradient);
125 for (j=0; j<3; j++)
126 {
127 for (k=0; k<3; k++)
128 {
129 int index0 = k + j*3;
130 int index1 = j + k*3;
131 symmetricVelocityGradient[j][k] = 0.5 * (velocityGradient[index0] + velocityGradient[index1]);
132 antiSymmetricVelocityGradient[j][k] = 0.5 * (velocityGradient[index0] - velocityGradient[index1]);
133 }
134 }
135
136 for (j=0; j<3; j++)
137 {
138 for (k=0; k<3; k++)
139 {
140 A[j][k] = 0.0;
141 for (l=0; l<3; l++)
142 {
143 A[j][k] += symmetricVelocityGradient[j][l]*symmetricVelocityGradient[l][k] +
144 antiSymmetricVelocityGradient[j][l]*antiSymmetricVelocityGradient[l][k];
145 }
146 }
147 }
148
149 double eigenVectors[3][3];
150 double eigenValues[3];
151 vtkMath::Diagonalize3x3(A,eigenValues,eigenVectors);
152
153 bool done = false;
154 while (!done)
155 {
156 done = true;
157 for (j=0; j<2; j++)
158 {
159 if (eigenValues[j] > eigenValues[j+1])
160 {
161 done = false;
162 double tmp = eigenValues[j+1];
163 eigenValues[j+1] = eigenValues[j];
164 eigenValues[j] = tmp;
165 }
166 }
167 }
168 double lambda2 = eigenValues[1];
169
170 lambda2Array->SetTuple1(i,lambda2);
171 }
172
173 output->DeepCopy(input);
174 output->GetPointData()->AddArray(lambda2Array);
175
176 lambda2Array->Delete();
177
178 return 1;
179}
180
181void vtkvmtkMeshLambda2::PrintSelf(std::ostream& os, vtkIndent indent)
182{
183 this->Superclass::PrintSelf(os,indent);
184}
Compute the Lambda2 surface for a given flow field which allow for the visualization of fluid vortex ...
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(vtkvmtkMeshLambda2)