VMTK
Loading...
Searching...
No Matches
vtkvmtkMeshVorticity.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkMeshVorticity.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
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
46
48{
49 if (this->VelocityArrayName)
50 {
51 delete[] this->VelocityArrayName;
52 this->VelocityArrayName = NULL;
53 }
54 if (this->VorticityArrayName)
55 {
56 delete[] this->VorticityArrayName;
57 this->VorticityArrayName = NULL;
58 }
59}
60
62 vtkInformation *vtkNotUsed(request),
63 vtkInformationVector **inputVector,
64 vtkInformationVector *outputVector)
65{
66 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
67 vtkInformation *outInfo = outputVector->GetInformationObject(0);
68
69 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
70 inInfo->Get(vtkDataObject::DATA_OBJECT()));
71 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
72 outInfo->Get(vtkDataObject::DATA_OBJECT()));
73
74 if (this->VelocityArrayName == NULL)
75 {
76 vtkErrorMacro("VelocityArrayName not specified");
77 return 1;
78 }
79
80 vtkDataArray* velocityArray = input->GetPointData()->GetArray(this->VelocityArrayName);
81
82 if (velocityArray == NULL)
83 {
84 vtkErrorMacro("VelocityArray with name specified does not exist");
85 return 1;
86 }
87
88 char gradientArrayName[] = "VelocityGradient";
89
91 gradientFilter->SetInputData(input);
92 gradientFilter->SetInputArrayName(this->VelocityArrayName);
93 gradientFilter->SetGradientArrayName(gradientArrayName);
94 gradientFilter->SetQuadratureOrder(this->QuadratureOrder);
95 gradientFilter->SetConvergenceTolerance(this->ConvergenceTolerance);
97 gradientFilter->Update();
98
99 vtkDataArray* velocityGradientArray = gradientFilter->GetOutput()->GetPointData()->GetArray(gradientArrayName);
100
101 int numberOfPoints = input->GetNumberOfPoints();
102
103 vtkDoubleArray* vorticityArray = vtkDoubleArray::New();
104 if (this->VorticityArrayName)
105 {
106 vorticityArray->SetName(this->VorticityArrayName);
107 }
108 else
109 {
110 vorticityArray->SetName("Vorticity");
111 }
112 vorticityArray->SetNumberOfComponents(3);
113 vorticityArray->SetNumberOfTuples(numberOfPoints);
114
115 double velocityGradient[9];
116 double vorticity[3];
117
118 int i;
119 for (i=0; i<numberOfPoints; i++)
120 {
121 velocityGradientArray->GetTuple(i,velocityGradient);
122 vorticity[0] = velocityGradient[7] - velocityGradient[5];
123 vorticity[1] = velocityGradient[2] - velocityGradient[6];
124 vorticity[2] = velocityGradient[3] - velocityGradient[1];
125 vorticityArray->SetTuple(i,vorticity);
126 }
127
128 output->DeepCopy(input);
129 output->GetPointData()->AddArray(vorticityArray);
130
131 vorticityArray->Delete();
132
133 return 1;
134}
135
136void vtkvmtkMeshVorticity::PrintSelf(std::ostream& os, vtkIndent indent)
137{
138 this->Superclass::PrintSelf(os,indent);
139}
Calculates vorticity from velocity gradients in a mesh.
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(vtkvmtkMeshVorticity)