VMTK
Loading...
Searching...
No Matches
vtkvmtkMeshVelocityStatistics.cxx
Go to the documentation of this file.
1/*=========================================================================
2
3Program: VMTK
4Module: $RCSfile: vtkvmtkMeshVelocityStatistics.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
24#include "vtkUnstructuredGrid.h"
25#include "vtkPointData.h"
26#include "vtkCellData.h"
27#include "vtkDoubleArray.h"
28#include "vtkMath.h"
29#include "vtkInformation.h"
30#include "vtkInformationVector.h"
31#include "vtkObjectFactory.h"
32
33
35
40
42{
43 if (this->VelocityArrayIds)
44 {
45 this->VelocityArrayIds->Delete();
46 this->VelocityArrayIds = NULL;
47 }
48}
49
51 vtkInformation *vtkNotUsed(request),
52 vtkInformationVector **inputVector,
53 vtkInformationVector *outputVector)
54{
55 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
56 vtkInformation *outInfo = outputVector->GetInformationObject(0);
57
58 vtkUnstructuredGrid *input = vtkUnstructuredGrid::SafeDownCast(
59 inInfo->Get(vtkDataObject::DATA_OBJECT()));
60 vtkUnstructuredGrid *output = vtkUnstructuredGrid::SafeDownCast(
61 outInfo->Get(vtkDataObject::DATA_OBJECT()));
62
63 output->CopyStructure(input);
64 output->GetPointData()->PassData(input->GetPointData());
65 output->GetCellData()->PassData(input->GetCellData());
66
67 vtkPointData* inputPointData = input->GetPointData();
68
69 if (this->VelocityArrayIds == NULL)
70 {
71 vtkErrorMacro("No VelocityArrayIds specified");
72 return 1;
73 }
74
75 int numberOfArrayIds = this->VelocityArrayIds->GetNumberOfIds();
76
77 if (numberOfArrayIds < 2)
78 {
79 vtkWarningMacro("Only 1 VelocityArrayIds specified. No point in computing statistics.");
80 return 1;
81 }
82
83 int i;
84 for (i=0; i<numberOfArrayIds; i++)
85 {
86 if (inputPointData->GetArray(this->VelocityArrayIds->GetId(i)) == NULL)
87 {
88 vtkErrorMacro("Id in VelocityArrayIds is not a PointData array.");
89 return 1;
90 }
91 }
92
93 int numberOfPoints = input->GetNumberOfPoints();
94
95 vtkDoubleArray* avgVelocityArray = vtkDoubleArray::New();
96 avgVelocityArray->SetName("AVGVelocity");
97 avgVelocityArray->SetNumberOfComponents(3);
98 avgVelocityArray->SetNumberOfTuples(numberOfPoints);
99 avgVelocityArray->FillComponent(0,0.0);
100 avgVelocityArray->FillComponent(1,0.0);
101 avgVelocityArray->FillComponent(2,0.0);
102
103 vtkDoubleArray* rmsVelocityArray = vtkDoubleArray::New();
104 rmsVelocityArray->SetName("RMSVelocity");
105 rmsVelocityArray->SetNumberOfComponents(3);
106 rmsVelocityArray->SetNumberOfTuples(numberOfPoints);
107 rmsVelocityArray->FillComponent(0,0.0);
108 rmsVelocityArray->FillComponent(1,0.0);
109 rmsVelocityArray->FillComponent(2,0.0);
110
111 double avgVelocity[3], rmsVelocity[3], velocity[3];
112
113 double weight = 1.0 / double(numberOfArrayIds);
114
115 int j;
116 for (i=0; i<numberOfPoints; i++)
117 {
118 for (j=0; j<numberOfArrayIds; j++)
119 {
120 vtkDataArray* velocityArray = inputPointData->GetArray(this->VelocityArrayIds->GetId(j));
121 avgVelocityArray->GetTuple(i,avgVelocity);
122 velocityArray->GetTuple(i,velocity);
123 avgVelocity[0] += weight * velocity[0];
124 avgVelocity[1] += weight * velocity[1];
125 avgVelocity[2] += weight * velocity[2];
126 avgVelocityArray->SetTuple(i,avgVelocity);
127 }
128 }
129
130 for (i=0; i<numberOfPoints; i++)
131 {
132 for (j=0; j<numberOfArrayIds; j++)
133 {
134 vtkDataArray* velocityArray = inputPointData->GetArray(this->VelocityArrayIds->GetId(j));
135 rmsVelocityArray->GetTuple(i,rmsVelocity);
136 avgVelocityArray->GetTuple(i,avgVelocity);
137 velocityArray->GetTuple(i,velocity);
138 rmsVelocity[0] += weight * (velocity[0] - avgVelocity[0]) * (velocity[0] - avgVelocity[0]);
139 rmsVelocity[1] += weight * (velocity[1] - avgVelocity[1]) * (velocity[1] - avgVelocity[1]);
140 rmsVelocity[2] += weight * (velocity[2] - avgVelocity[2]) * (velocity[2] - avgVelocity[2]);
141 rmsVelocityArray->SetTuple(i,rmsVelocity);
142 }
143 }
144
145 for (i=0; i<numberOfPoints; i++)
146 {
147 rmsVelocityArray->GetTuple(i,rmsVelocity);
148 rmsVelocity[0] = sqrt(rmsVelocity[0]);
149 rmsVelocity[1] = sqrt(rmsVelocity[1]);
150 rmsVelocity[2] = sqrt(rmsVelocity[2]);
151 rmsVelocityArray->SetTuple(i,rmsVelocity);
152 }
153
154 output->GetPointData()->AddArray(avgVelocityArray);
155 output->GetPointData()->AddArray(rmsVelocityArray);
156
157 avgVelocityArray->Delete();
158 rmsVelocityArray->Delete();
159
160 return 1;
161}
162
163void vtkvmtkMeshVelocityStatistics::PrintSelf(std::ostream& os, vtkIndent indent)
164{
165 this->Superclass::PrintSelf(os,indent);
166}
Calculates average and RMS velocity statistics.
virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *) override
void PrintSelf(std::ostream &os, vtkIndent indent) override
vtkStandardNewMacro(vtkvmtkMeshVelocityStatistics)