VMTK
Loading...
Searching...
No Matches
vtkvmtkUnstructuredGridVorticityFilter.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: VMTK
4 Module: $RCSfile: vtkvmtkUnstructuredGridVorticityFilter.cxx,v $
5 Language: C++
6 Date: $Date: 2006/04/06 16:46:44 $
7 Version: $Revision: 1.7 $
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#include "vtkUnstructuredGrid.h"
24#include "vtkPointData.h"
25#include "vtkDoubleArray.h"
26#include "vtkvmtkDoubleVector.h"
28#include "vtkvmtkSparseMatrix.h"
29#include "vtkvmtkLinearSystem.h"
31#include "vtkMath.h"
32#include "vtkInformation.h"
33#include "vtkInformationVector.h"
34#include "vtkObjectFactory.h"
35
36
38
48
50{
51 if (this->VelocityArrayName)
52 {
53 delete[] this->VelocityArrayName;
54 this->VelocityArrayName = NULL;
55 }
56 if (this->VorticityArrayName)
57 {
58 delete[] this->VorticityArrayName;
59 this->VorticityArrayName = NULL;
60 }
62 {
63 delete[] this->HelicityFactorArrayName;
64 this->HelicityFactorArrayName = NULL;
65 }
66}
67
69 vtkInformation *vtkNotUsed(request),
70 vtkInformationVector **inputVector,
71 vtkInformationVector *outputVector)
72{
73 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
74 vtkInformation *outInfo = outputVector->GetInformationObject(0);
75
76 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
77 inInfo->Get(vtkDataObject::DATA_OBJECT()));
78 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
79 outInfo->Get(vtkDataObject::DATA_OBJECT()));
80
81 if (!this->VelocityArrayName)
82 {
83 vtkErrorMacro(<<"VelocityArrayName not set.");
84 return 1;
85 }
86
87 if (!this->VorticityArrayName)
88 {
89 vtkErrorMacro(<<"VorticityArrayName not set.");
90 return 1;
91 }
92
93 if (this->ComputeHelicityFactor)
94 {
95 if (!this->HelicityFactorArrayName)
96 {
97 vtkErrorMacro(<<"HelicityFactorArrayName not set.");
98 return 1;
99 }
100 }
101
102 int numberOfInputPoints = input->GetNumberOfPoints();
103
104 vtkDataArray* velocityArray = input->GetPointData()->GetArray(this->VelocityArrayName);
105
106 if (!velocityArray)
107 {
108 vtkErrorMacro("VelocityArray with name specified doesn not exist!");
109 return 0;
110 }
111
112 int numberOfInputComponents = velocityArray->GetNumberOfComponents();
113
114 if (numberOfInputComponents != 3)
115 {
116 vtkErrorMacro("VelocityArray must have 3 components!");
117 return 0;
118 }
119
120 vtkDoubleArray* vorticityArray = vtkDoubleArray::New();
121 vorticityArray->SetName(this->VorticityArrayName);
122 vorticityArray->SetNumberOfComponents(numberOfInputComponents);
123 vorticityArray->SetNumberOfTuples(numberOfInputPoints);
124
126
128 rhsVector->SetNormTypeToLInf();
129
131 solutionVector->SetNormTypeToLInf();
132
133 int i;
134 for (i=0; i<3; i++)
135 {
137 assembler->SetDataSet(input);
138 assembler->SetVelocityArrayName(this->VelocityArrayName);
139 assembler->SetMatrix(sparseMatrix);
140 assembler->SetRHSVector(rhsVector);
141 assembler->SetSolutionVector(solutionVector);
142 assembler->SetQuadratureOrder(this->QuadratureOrder);
143 assembler->SetDirection(i);
144 assembler->Build();
145
147 linearSystem->SetA(sparseMatrix);
148 linearSystem->SetB(rhsVector);
149 linearSystem->SetX(solutionVector);
150
152 solver->SetLinearSystem(linearSystem);
154 solver->SetMaximumNumberOfIterations(numberOfInputPoints);
155 solver->SetSolverTypeToCG();
157 solver->Solve();
158
159// solutionVector->CopyVariableIntoArrayComponent(vorticityArray,0,0);
160// solutionVector->CopyVariableIntoArrayComponent(vorticityArray,1,1);
161// solutionVector->CopyVariableIntoArrayComponent(vorticityArray,2,2);
162 solutionVector->CopyIntoArrayComponent(vorticityArray,i);
163
164 assembler->Delete();
165 linearSystem->Delete();
166 solver->Delete();
167 }
168
169 sparseMatrix->Delete();
170 rhsVector->Delete();
171
172 solutionVector->Delete();
173
174 output->DeepCopy(input);
175 output->GetPointData()->AddArray(vorticityArray);
176
177 if (this->ComputeHelicityFactor)
178 {
179 vtkDoubleArray* helicityFactorArray = vtkDoubleArray::New();
180 helicityFactorArray->SetName(this->HelicityFactorArrayName);
181 helicityFactorArray->SetNumberOfTuples(numberOfInputPoints);
182
183 double velocity[3], vorticity[3], velocityMagnitude, vorticityMagnitude, helicityFactor;
184 int i;
185 for (i=0; i<numberOfInputPoints; i++)
186 {
187 velocityArray->GetTuple(i,velocity);
188 vorticityArray->GetTuple(i,vorticity);
189 velocityMagnitude = vtkMath::Norm(velocity);
190 vorticityMagnitude = vtkMath::Norm(vorticity);
191 helicityFactor = 0.0;
192 if (velocityMagnitude > 0.0 && vorticityMagnitude > 0.0)
193 {
194 helicityFactor = vtkMath::Dot(velocity,vorticity) / (velocityMagnitude * vorticityMagnitude);
195 }
196 helicityFactorArray->SetValue(i,helicityFactor);
197 }
198 output->GetPointData()->AddArray(helicityFactorArray);
199 helicityFactorArray->Delete();
200 }
201
202 vorticityArray->Delete();
203
204 return 1;
205}
Serves as the base class for vectors utilized in finite-element and other PDE evaluations.
void DeepCopy(vtkvmtkDoubleVector *src)
static vtkvmtkDoubleVector * New()
void CopyIntoArrayComponent(vtkDataArray *array, int component)
virtual void SetSolutionVector(vtkvmtkDoubleVector *)
virtual void SetDataSet(vtkDataSet *)
virtual void SetRHSVector(vtkvmtkDoubleVector *)
virtual void SetMatrix(vtkvmtkSparseMatrix *)
virtual void SetQuadratureOrder(int)
virtual void SetConvergenceTolerance(double)
virtual void SetMaximumNumberOfIterations(int)
virtual void SetLinearSystem(vtkvmtkLinearSystem *)
Serves as the base container holding sparse matrix objects that represent a linear system of equation...
virtual void SetX(vtkvmtkDoubleVector *)
virtual void SetA(vtkvmtkSparseMatrix *)
virtual void SetB(vtkvmtkDoubleVector *)
static vtkvmtkLinearSystem * New()
Solve a linear system of equations using open NL.
static vtkvmtkOpenNLLinearSystemSolver * New()
Implements a row-based sparse matrix built from mesh neighborhoods or stencils, supporting basic line...
static vtkvmtkSparseMatrix * New()
Construct a vorticity based finite element calculation on a mesh.
static vtkvmtkUnstructuredGridFEVorticityAssembler * New()
virtual void SetVelocityArrayName(const char *)
Calculates vorticity from velocity in a mesh.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
vtkStandardNewMacro(vtkvmtkUnstructuredGridVorticityFilter)