-
Notifications
You must be signed in to change notification settings - Fork 0
/
vtkRotatingFrame.cpp
211 lines (170 loc) · 4.77 KB
/
vtkRotatingFrame.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*=========================================================================
Program: Visualization Toolkit
Module: vtkRotatingFrame.cpp
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// Copyright 2014-2016 Etienne Tang
#include "vtkRotatingFrame.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkPointSet.h"
#include "vtkPoints.h"
#include "vtkDoubleArray.h"
#include "vtkPointData.h"
#include "vtkMath.h"
#include <iostream>
vtkStandardNewMacro(vtkRotatingFrame)
vtkRotatingFrame::vtkRotatingFrame()
{
Omega = 5518.312216;
RelativeToAbsolute = 1;
Cv = 947.2046;
Gamma = 1.303;
Postfix = "";
}
vtkRotatingFrame::~vtkRotatingFrame()
{
}
void vtkRotatingFrame::PrintSelf(ostream& os, vtkIndent indent)
{
os << "vtkRotatingFrame\n";
}
int vtkRotatingFrame::RequestData(vtkInformation* request,
vtkInformationVector** inVector, vtkInformationVector* outVector)
{
vtkInformation* inInfo = inVector[0]->GetInformationObject(0);
if(!inInfo)
{
return 0;
}
vtkPointSet* inData = vtkPointSet::SafeDownCast(
inInfo->Get(vtkDataObject::DATA_OBJECT()));
if(!inData)
{
return 0;
}
vtkInformation* outInfo = outVector->GetInformationObject(0);
vtkPointSet* outData = vtkPointSet::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
if(!outData)
{
return 0;
}
outData->ShallowCopy(inData);
vtkDataArray* V = outData->GetPointData()->GetArray("V");
vtkDataArray* Ps = outData->GetPointData()->GetArray("Ps");
vtkDataArray* Ts = outData->GetPointData()->GetArray("Ts");
if((!V) || (V->GetNumberOfComponents() != 3))
{
std::cout << "Vecteur V non trouve" << std::endl;
return 0;
}
if((!Ps) || (Ps->GetNumberOfComponents() != 1))
{
std::cout << "Ps non trouve" << std::endl;
return 0;
}
if((!Ts) || (Ts->GetNumberOfComponents() != 1))
{
std::cout << "Ts non trouve" << std::endl;
return 0;
}
vtkPoints* pts = outData->GetPoints();
int npts = pts->GetNumberOfPoints();
vtkDoubleArray* newV = vtkDoubleArray::New();
vtkDoubleArray* newPt = vtkDoubleArray::New();
vtkDoubleArray* newTt = vtkDoubleArray::New();
vtkDoubleArray* newM = vtkDoubleArray::New();
newV->SetNumberOfComponents(3);
newPt->SetNumberOfComponents(1);
newTt->SetNumberOfComponents(1);
newM->SetNumberOfComponents(1);
newV->SetNumberOfTuples(npts);
newPt->SetNumberOfTuples(npts);
newTt->SetNumberOfTuples(npts);
newM->SetNumberOfTuples(npts);
double domega;
if(RelativeToAbsolute)
{
domega = Omega;
}
else
{
domega = -Omega;
}
double rgaz = Cv*(Gamma-1);
for(int i = 0; i < npts; i++)
{
double coords[3];
pts->GetPoint(i, coords);
double theta = atan2(coords[2], coords[1]);
double R = sqrt(coords[1]*coords[1]+coords[2]*coords[2]);
double cost = cos(theta);
double sint = sin(theta);
double tmp_V[3];
double tmp_Ts;
double tmp_Ps;
V->GetTuple(i, tmp_V);
Ts->GetTuple(i, &tmp_Ts);
Ps->GetTuple(i, &tmp_Ps);
double tmp_Vr = cost*tmp_V[1]+sint*tmp_V[2];
double tmp_Vt = -sint*tmp_V[1]+cost*tmp_V[2];
tmp_Vt += R*domega;
double tmp_newV[3];
double tmp_newPt, tmp_newTt, tmp_newM;
tmp_newV[0] = tmp_V[0];
tmp_newV[1] = cost*tmp_Vr-sint*tmp_Vt;
tmp_newV[2] = sint*tmp_Vr+cost*tmp_Vt;
double magNewV = vtkMath::Norm(tmp_newV);
tmp_newM = magNewV/sqrt(Gamma*rgaz*tmp_Ts);
tmp_newTt = tmp_Ts*(1.+0.5*(Gamma-1.)*pow(tmp_newM, 2.));
tmp_newPt = tmp_Ps*pow(1.+0.5*(Gamma-1.)*pow(tmp_newM, 2.), Gamma/(Gamma-1.));
newV->SetTuple(i, tmp_newV);
newM->SetTuple(i, &tmp_newM);
newTt->SetTuple(i, &tmp_newTt);
newPt->SetTuple(i, &tmp_newPt);
}
newV->SetName(NewName(outData, "V").c_str());
newM->SetName(NewName(outData, "M").c_str());
newTt->SetName(NewName(outData, "Tt").c_str());
newPt->SetName(NewName(outData, "Pt").c_str());
outData->GetPointData()->AddArray(newV);
outData->GetPointData()->AddArray(newM);
outData->GetPointData()->AddArray(newPt);
outData->GetPointData()->AddArray(newTt);
newV->Delete();
newM->Delete();
newTt->Delete();
newPt->Delete();
return 1;
}
std::string vtkRotatingFrame::NewName(vtkPointSet* data, const char* name)
{
std::string res = name;
if(Postfix != "")
{
res = res + "_" + Postfix;
}
else
{
if(RelativeToAbsolute)
{
res += "_abs";
}
else
{
res += "_rel";
}
if(data->GetPointData()->HasArray(res.c_str()))
{
data->GetPointData()->RemoveArray(res.c_str());
}
}
return res;
}